Commit Graph

4008 Commits

Author SHA1 Message Date
Pau Espin 74dddefcc7 logging: gsmtap: Store TID instead of PID in pkt hdr
This allows differentiating threads withing an application, while still
keeping same numbering for single-threaded application (since first
thread ID is always the same as the process group ID).

Related: OS#5027
Change-Id: I33da02524fc064e133b2b762af7060139c4cfd81
2021-02-17 18:55:46 +01:00
Pau Espin 2f765f02af logging: gsmtap: Fix fill PID field not stored in network byte order
Recent commit filling this field forgot to convert it to network byte
order.

Related: OS#5027
Fixes: bb149ecda2
Change-Id: I50857f35cb28138fa6f28100afeaa00f492f303a
2021-02-17 18:51:25 +01:00
Pau Espin 88e4058fc4 Introduce osmo_gettid() API
This API wraps conventional gettid() linux-specific API, which even in
Linux itself is sometimes not properly supported/announced.

This API also allows future porting to other platforms if needed, and so
far falls back to getpid() if no gettid(9 can be found.

Code ported from osmo-trx.git, see commit 7a07de1efd4eb7cc11c33d3ad25cb2df70aa1ef1.

Related: OS#5027
Change-Id: Id7534beeb22fcd50813dab76dd68818e2ff87ec2
2021-02-17 18:24:17 +01:00
Philipp Maier ca770ae77e gsm_08_58, gsm_44_004: add struct for l1 information
Libosmocore currently does not offer any structs to encode and decode
the l1 information on RSL level and the sacch l1 header on the air
interface level. Both structs are identical but the field order in the
first octet is reversed.

Change-Id: I23c1890b89d5a0574eb05dace9f64cc59d6f6df7
2021-02-16 21:42:04 +01:00
Pau Espin bb149ecda2 logging: gsmtap: Fill PID field for each message
It was recently discovered that PID field in gsmtap log messages was
always set to 0. Before this patch, the field was never being set.

The approach of this patch is to record the PID of process one, in
order to avoid calling getpid() syscall on each
log line to be sent. The counterpart of this optimization is that
eventual fork() calls would still keep the old incorrect value, but I
think nobody can safely assume that fork() is possible once all this
kind of infrastructure has already been configured (fork() should only
be done really at the start of the program before any osmocom foo is
initialized, or to immediatelly call exec()).

Related: OS#5027
Change-Id: I7db00d1810f0860166bffa0bda8566caa82e06a9
2021-02-16 17:24:48 +01:00
Alexander Couzens 4f1128fcbd gprs_ns2: inform the NS user (BSSGP) about the MTU of a NSE
The BSSGP layer needs to know the MTU of the NS UNIDATA payload.
The MTU can be 0 if the NSE doesn't contain any NSVC.
Every status indication will contain the mtu value.
The MTU in the status indication contains the maximum transfer
unit of a BSSGP message. From NS side the maximum SDU.

Related: OS#4889
Change-Id: I5016b295db6185ec131d83089cf6c806e34ef1b6
2021-02-16 16:29:47 +01:00
Pau Espin 524898504a gsm: Fix encoding of gsm0808_cell_id_list2 with CGI-PS types
CGI-PS type doesn't exist in GSM 08.08 Cell Id lists. That type of cell
id is osmocom-specific and used internally. In here CGI-PS is
automatically converted to CGI (since the later is an extension of this
one).

The encode/decode_cell_id_u are left intact (comment added) since those
can still be used (and are used by RIM code) to encode/decode TS 48.018
Cell Identifiers.

Related: SYS#4909
Change-Id: Id74f4577c397c1ba696f00395858311bd82cb2c8
2021-02-15 16:42:46 +01:00
Pau Espin 85a0f1143d gsm0808_utils: Move static function further up in file
It's a static internal function, so it makes sense to have it at start
of its related section.
It will be used by other functions in follow up patches.

Change-Id: I60f61f8f7bb6543feb068bdcee76d3b752565c95
2021-02-15 16:25:35 +01:00
Pau Espin 20b763d0af gsm: Support converting to cgi-ps in gsm0808_cell_id_from_cgi()
This is not really used nowadays, but added for completeness in case
someone wants to use it.

Change-Id: I1361b044bd897d04133cda6fd62c16852700b17a
2021-02-15 16:18:26 +01:00
Pau Espin 1bd495a787 comsetic: gsm0808_test: Fix trailing whitespace
Change-Id: I7f48e292fefe555939129f4000303e630a12cc50
2021-02-15 16:16:41 +01:00
Alexander Couzens 23aec35750 gprs_ns2_sns: fix typo in doxygen comment
Fixes: 5bef2cc4bd ("ns2: Improve/extend doxygen comments for new ns2 implementation")
Change-Id: I21b51791aa149d9a5b13169d1cf8c2857c55774a
2021-02-15 10:59:10 +00:00
Alexander Couzens e052c411e2 gprs_ns2: fix comment of alive NS-VC
There is no active NS-VCs only alive or dead.

Change-Id: Idb5d2ae4a99a472e38601ff841b8046ecf89d1bc
2021-02-15 10:40:54 +00:00
Harald Welte 094226866b BVC FSM: Treat overlapping BVC-RESET as implicit ACK
If the BSS (or SGSN) has sent a BVC-RESET PDU for a BVCI to the SGSN (or
BSS) and is awaiting a BVC-RESET- ACK PDU in response, but instead
receives a BVC-RESET PDU indicating the same BVCI, then this shall be
interpreted as a BVC-RESET ACK PDU and the T2 timer shall be stopped.

Related: OS#4974
Change-Id: I4d15733f9f205cb563b66ef9e41dc8df50151900
2021-02-15 10:06:55 +00:00
Alexander Couzens f46ebcd3ae gprs_ns2_vc_fsm: remove debug line of the alive_timer
The log line sneaked in when fixing the alive ms

Fixes: ab0e8646c4 ("gprs_ns2_vc_fsm: use CLOCK_MONOTONIC for alive elapsed timer")
Change-Id: Iffe367b240f47c39232bbc26991c19752a1c75ad
2021-02-15 03:45:35 +01:00
Pau Espin Pedrol 288f9b2486 gsm: Fix bitfield order in dtap_header
This bitfield was added later and all osmocom code still uses the old
field contain 1 byte "link_id". There's only one known user of the new
bitfield which only uses it to log the SAPI name in osmocom, so no
logical breakage is expected with this change (other than fixing a log
line).

While at it, fix a typo in comment describing related enum.

Related: SYS#4909
Fixes: 392f607f2d
Change-Id: I84866f03ee642aa7f1da273c93a16a38234cfa67
2021-02-13 08:05:30 +00:00
Daniel Willmann 4e5cdad658 bssgp_bvc_fsm: Consistent naming
bssgp_bvc_get_features_* are fsm "methods" and the name should indicate
that just lika all other function names in bssgp_bvc_fsm.h

Change-Id: I30fbbe36cdabf9635eaf4dfb1e93c8ce0f667b39
2021-02-12 22:27:56 +01:00
Daniel Willmann fa632b8e80 bssgp2_enc_status: Truncate STATUS message to maximum PDU length
Related: OS#4889
Change-Id: Ic39d918c56399ceb0431299ce938e3bf276f678a
2021-02-12 14:19:20 +00:00
Daniel Willmann 1ff86f7cec bssgp_bvc_fsm: Set/get maximum BSSGP PDU length
Add functions to get/set the maximum supported BSSGP PDU size by the NS
layer.

IPv4 and IPv6 should not matter since we can just enable IP
fragmentation and send NS PDUs up to 2**16 + bytes. Frame relay does not
support fragmentation and this is the reason we need to be aware of the
maximum PDU size. Luckily with 1600 bytes the MTU in frame relay can hold a
regular IP packet including NS/BSSGP overhead.

On the NS layer this corresponds to the size of an NS SDU in NS-UNITDATA
(3GPP TS 48.016 Ch. 9.2.10)

Change-Id: I9bb82ead27366b7370c9ff968e03ca2113ec11f0
Related: OS#4889
2021-02-12 14:19:20 +00:00
Daniel Willmann ae9899561c tests/gb: Add more complex osmo-ns-dummy.cfg
write config will not print out any configuration for bind/nse unless we
configure some. This way we can catch more issues with incompatible
configs such as https://gerrit.osmocom.org/c/libosmocore/+/22878

Change-Id: Iad422ee013c82a6cb96af8ce4eb3af8b0936a4c9
Related: OS#4887
2021-02-12 12:50:02 +01:00
Daniel Willmann 64db6366fd ns2: Fix incompatible VTY configs when writing config
It seems like we still don't have NS2 VTY tests running in libosmocore
so this only got caught once osmo-sgsn/osmo-gbproxy builds failed.

Change-Id: Id3cd407b05457a4703ee38c4b1b1b65800bbd30e
Related: OS#4887
2021-02-12 12:25:30 +01:00
Alexander Couzens b7921738be gprs_ns2_vty: use strcmp() instead of strncmp()
Otherwise substring wouldn't be detected.
E.g. local vs local2

Change-Id: I183b5176a1d8a295b7551ad186b3565adeb3d5e7
2021-02-12 08:57:34 +00:00
Alexander Couzens fa4121de2f gprs_ns2_vc_fsm: reset the alive elapsed timeout everytime
The alive elapsed timeout was only set once on the start of the
test procedure but not every time an ALIVE PDU was sent.

Fixes: OS#4997
Change-Id: I029696dfff21919f97ac4c33cdd82162b5ab1555
2021-02-12 08:57:29 +00:00
Alexander Couzens ab0e8646c4 gprs_ns2_vc_fsm: use CLOCK_MONOTONIC for alive elapsed timer
gettimeofday can jump and the comment says it should not be used for elapsed timer.

Related: OS#4997
Change-Id: I41989d8f9f82f4d1f7b97f11577653699365c8ae
2021-02-12 08:57:24 +00:00
Alexander Couzens c470476923 gprs_ns2: add signalling & data weights for UDP binds
Allow to assign a signalling and data weight to UDP binds.
Those weights will be used when doing dynamic configuration over
IP-SNS.
This is only the first part which only uses the assigned weights
when doing a new SNS configuration.
The outgoing change weight procedure will be supported in a later patch
when the SNS fsm supports outgoing procedures.

Related: SYS#5354
Change-Id: I5133e4229377d44772a9af28628a2bc420fea34b
2021-02-12 03:34:32 +01:00
Harald Welte 855155c6ae ns2_fr: Fix heap-use-after-free in error recovery path
<0026> gprs_ns2_fr.c:515 BIND(hdlcnet1) Can not create AF_PACKET socket. Are you root or have CAP_NET_RAW?
=================================================================
==3872359==ERROR: AddressSanitizer: heap-use-after-free on address 0x6130000030c0 at pc 0x7fef120aa92e bp 0x7ffebf6b5c20 sp 0x7ffebf6b5c18
READ of size 8 at 0x6130000030c0 thread T0
    #0 0x7fef120aa92d in osmo_fr_link_free (/usr/local/lib/libosmogb.so.11+0x16992d)
    #1 0x7fef1205105a in free_bind (/usr/local/lib/libosmogb.so.11+0x11005a)

Change-Id: I23c0f1697edd5734085fa18b0a2f253c0f206c53
2021-02-11 16:07:46 +01:00
Harald Welte ce6e4b79b8 ns2_fr: Fix null pointer deref in error path
The followign happens if osmo-gbproxy is started without CAP_NET_RAW:

<0026> gprs_ns2_fr.c:515 BIND(hdlcnet1) Can not create AF_PACKET socket. Are you root or have CAP_NET_RAW?
gprs_ns2_fr.c:176:2: runtime error: member access within null pointer of type 'struct msgb' AddressSanitizer:DEADLYSIGNAL

the second line is free_bind() iterating overr the backlog while
destroying the not-yet-fully-initialized bind.

Let's make sure the backlog llist_head is always initialized properly.

Change-Id: I4d2fa50955c5897cd469fee68d4ddc65a9f5688f
2021-02-11 16:07:45 +01:00
Harald Welte cc2e112e9a README.md: Use https everywhere
Change-Id: I06d28ea1f5decffbd89f8439fae948e022bf3fe3
2021-02-11 11:57:13 +01:00
Pau Espin Pedrol c31809faf3 cosmetic: Move comment one line below in append_gprs_cell_opt
Move it above the place where the bit is set, since the bit represents
whether Extension Information is available, not whether R99 is
available.

Change-Id: Ice592acc50a24efd7fe4cf1a91f1d48fd74f38d8
2021-02-10 15:04:22 +00:00
Alexander Couzens 3e2e4a017a gprs_ns2_vty: fix memory leak of vty_binds
They never got freed, only removed from the vty_bind queue.

Change-Id: I100897c32dc152f9acbb322782fae49b1f0bc030
2021-02-09 16:48:03 +01:00
Alexander Couzens 5fa431ccd5 gprs_ns2: rename vty-command ip-sns -> ip-sns-remote
In prepration to introduce more commands e.g. ip-sns-bind rename the ip-sns-remote

Related: SYS#5354
Change-Id: Ida979f3b9daa5f7280a629441e4006a7635653b0
2021-02-09 16:48:03 +01:00
Alexander Couzens 790a963fa2 gprs_ns2_sns: reset the N of timeout when entering a new state
Otherwise retries are splitted between the states.

Related: OS#5355
Change-Id: Iefde0c89965f0be899d6d1f096480f6fc79a92be
2021-02-09 16:46:16 +01:00
Alexander Couzens 3df5886c57 gprs_ns2_sns: add timeout to ST_CONFIG_SGSN
The state CONFIG_SGSN must be also protected by the timeout Tsns-prov.

Related: OS#5355
Change-Id: I2700c1ad40ebe30658e9937d86a4861b0b59d6b6
2021-02-09 16:46:16 +01:00
Alexander Couzens be7cecc753 gprs_ns2_sns: rework tracking of NS-VC unblocked/alive state
The SNS must know when all NS-VC have failed. Further more
there might be a corner case when the SNS configuration succeeds but
no NS-VC comes up afterwards.

Related: OS#5355
Change-Id: Ie72da9adeefe0c2850d49a9208b2d0a4556f9101
2021-02-09 15:42:01 +00:00
Harald Welte 9811f498d4 ns2: Don't try to add packets to the backlog on real errors
When writing to the AF_PACKET socket, we have to distinguish the
pseudo-errors like -ENOBUFS (where we do want to add to the backlog)
from real errors like -ENETDOWN, -EMSGSIZE, ... where we don't want
to add the failed packet to the backlog.

Change-Id: Ibbb6805da0f118466c4c91e458e62b63b84cb794
2021-02-08 18:36:21 +01:00
Harald Welte 6972aedb51 ns2: improve backlog handling on interface up/down
This patch improves the behavior of the newly-added backlog in
situations where the interface goes up/down.

* don't add new packets to the backlog while if_running == false
* flush the backlog on both ifup and ifdown events

Change-Id: Ib35d099526544fe2cff64566fd56147a906adab9
2021-02-08 18:36:21 +01:00
Harald Welte 93740619af ns2: Don't queue Q.933 LMI messages; only store most recent ones
There's not really any point in storing multiple LMI messages,
and then transmitting them in inverse order, as the existing code
does.  Instead, we shall store only the last (failed) LMI message
and try to transmit that at highest priority, before any NS messages
in the actual queue.

Change-Id: I5407a76a34d7e687966fe1a915febf3a87256593
2021-02-08 18:36:21 +01:00
Harald Welte b339cbb3ef ns2: Name NSVC FSM events consistently
Reading a log line like this:

<0026> gprs_ns2_vc_fsm.c:808 GPRS-NS2-VC(FR-hdlcnet1-DLCI16-NSE02001-NSVC00001)[0x6120000024a0]{UNBLOCKED}: Received Event RESET

is very ambiguous. Does it mean we received a NS-RESET message? Does it
mean the FSM was instructed to send a NS-RESET? ...

Let's make sure the human-readable names give a very clear indication
of what exactly is happening.

Change-Id: I8b7615b3eca04212831163ff0ea4aea35069cd0e
2021-02-08 18:36:21 +01:00
Pau Espin 15b5acb332 Fix struct bitfields on big endian systems
Changes done by contrib/struct_endianess.py.

Change-Id: Ia9cb1ef2ba2bfff9ef713c7d1cf388931dae1c46
2021-02-08 17:23:25 +00:00
Vadim Yanitskiy 53aff13af4 tlv: clarify documentation for msgb_tv{16,32}_put()
Change-Id: Ie439822e0587012e108f67ba4e73771dc684b95b
2021-02-06 16:09:13 +00:00
Vadim Yanitskiy d397a53cfc tlv: add msgb_tv32_put(), similar to msgb_tv16_put()
Change-Id: I11301b20038aa5d90d46d968f7eda3d53b560022
2021-02-06 16:07:54 +00:00
Vadim Yanitskiy e3d32d574e bssgp_bvc_fsm: check return value of osmo_fsm_register()
Change-Id: I0ade2e476a035bb44b2f135ece4552d015852274
Fixes: CID#215717
2021-02-05 20:10:16 +01:00
Vadim Yanitskiy 1c4fc227d9 gsm0808: use msgb_tv16_put() and osmo_store32be()
This API makes the code simpler and easier to read.

Change-Id: Ibe9eaaa2a9344ba798631b8f115ad248f0a2f76b
2021-02-05 20:10:16 +01:00
Harald Welte f3dc0f94c3 frame_relay; Fix Q.933 async STATUS at DLC creation
Fix the encoding of the asynchronous Q.933 STATUS message
we send at DLC creation time.

Change-Id: Id1460ffa6266be85f44579c447421eed12481b02
Closes: OS#5010
2021-02-05 11:10:48 +01:00
Harald Welte 8373c05a35 gb: frame_relay: Detect link outage on "last receive seq nr == 0"
this is a bit of a hack.  Q.933 explicitly forbids either side from ever
sending a sequence number of '0'.  Values start from '1' and are modulo 256,
but '0' is always skipped.  So if the peer is sending us a "last received
sequence number of '0' it means it has not yet received any packets from us,
which in turn can only mean that it has just been restarted.  Let's treat
this as "service affecting condition" and notify upper layers.  This helps
particularly in recovering from rapidly re-starting peers, where the Q.933
nor NS have time to actually detect the connection was lost.

Change-Id: I960a7b17f2550cb49a7b9d72ed87cd271bb64122
Related: OS#4974
2021-02-04 19:28:02 +01:00
Harald Welte cfe0ed63fa gb: frame_relay: Factor-out function to set link as dead
Change-Id: I624b6a1175cf7d59173dfff02d6197bb644b9072
2021-02-04 19:28:02 +01:00
Philipp Maier d11a5d5b9a gsm48: add compare function for struct gprs_ra_id
Comparing struct gprs_ra_id using memcmp can be error prone, so lets add
a compare function to compare two struct gprs_ra_id values reliably.

Change-Id: I4d7558c04d9d01761516526086be5104bb2eeada
Related: SYS#5103
2021-02-04 15:17:41 +01:00
Harald Welte 700822b305 Enable systemd-journald log target in debian + rpm packaging
Given that all the distributions we support are shipping systemd
anyway, this will not really introduce any additional runtime package
dependencies.

Change-Id: Ib3af918cd4cc8d0ca6d228a0f2c8338534374d46
2021-02-03 14:56:17 +01:00
Harald Welte 433005c87c initial support for static userspace probes via systemtap
This adds a --enable-systemtap configure option, which will then
add static tracepoints to the generated libosmocore binary.

At this point, only two tracepoints are supported: log_start
and log_done.  They can be used to trace the amount of time
a libosmocore-using application spends in potentiall blocking calls to
log to stderr or to files.

Related: OS#4311
Change-Id: I7e1ab664241deb524c9582cbd1bec31af46c747e
2021-02-03 13:55:40 +00:00
Alexander Couzens dc43f7d3c7 gprs_ns2_frgre: check iph/ip6h before passing them to rx functions
With IPv4 and IPv6 support it's not guaranteed that iph/ip6h is valid.

Related CID#214288

Change-Id: If9015906917e3ad11d14b84c29d64f28a3158144
2021-02-03 14:37:54 +01:00
Alexander Couzens 47ed2a6b4a gprs_ns2_frgre: set a correct gre pointer for ipv6
Also fixes a nullpointer deref because iph is NULL on IPv6

Related: CID#216555
Change-Id: I2ff868a7bba6151a2202df774ff022c02b8c34cb
2021-02-03 14:37:54 +01:00