Commit Graph

2658 Commits

Author SHA1 Message Date
Alexander Couzens a6096ad367 gprs_ns2: fix check of MTU changes for frame relay
The frame relay needs 2 byte for data packets.

Related: OS#5192
Change-Id: I02d4e81896a473aeb79ea2f2983e12324244048f
2021-07-02 17:38:02 +02:00
Alexander Couzens db7b2ab36b gprs_ns2: fix crash when changing the MTU
When the MTU changes for any fr device, all
NSE will recalculate their MTU. If any NSE is alive,
libosmocore will crash.

Related: OS#5192
Change-Id: I31ba5cefea7bbb0b74060d6664b42c58815ee2a1
2021-07-02 17:38:02 +02:00
Pau Espin d9825c0a2c bts_feature: Introduce feature to confiure dyn ts as sdcch8
This feature signals support to configure Osmocom Dynamic Timeslot type
as SDCCH8, on top of historically supported TCH/H and TCH/F.
The idea is that when unneeded, the TS is configured as PDCH, and as
soon as there's need for an SDCCH and there's none available, the TS is
dynamically reconfigured to SDCCH8. Once all logical channels in the
dynamic TS are released and hence becomes free, the BSC will reconfigure
it to PDCH.

Related: SYS#5309
Change-Id: Ifc0ca8916bd3e93e5a60a7dd7391d2588fdb5532
2021-06-30 13:15:02 +02:00
Pau Espin 45dc9d00fe Rename osmo dyn ts enums
They will gain support to be activated as SDCCH/8 soon too. Since new
name would start to be too large, use a more generic naming for it.

Related: OS#5309
Change-Id: I56dcfe4d17899630b17f80145c3ced72f1e91e68
2021-06-30 13:14:08 +02:00
Neels Hofmeyr 26e53b181c add fixme: enforce 8 byte length of Kc
Change-Id: I57efb0a24cb71b365189eccb5088b130fad15093
2021-06-29 22:35:03 +02:00
Daniel Willmann c7f547f897 ns2: Ignore NSVC with data_weight 0 for data
Change-Id: If0c2bee285f85110771326e07b513fc3e3f9d3f0
Fixes: OS#5189
2021-06-29 13:18:42 +02:00
Vadim Yanitskiy 1c2a329f85 bts_features: add feature for BCCH carrier power reduction mode
Change-Id: I69283b3f35988fc7a1a1dcf1a1ad3b67f08ec716
Related: SYS#4919
2021-06-25 19:34:52 +02:00
Neels Hofmeyr e4378b7e38 gsm0808: add Kc128 to Handover Request
Change-Id: Ieb6e43eef9e57281d54d4b7c63664668df5aef3e
2021-06-25 08:19:04 +00:00
Alexander Couzens 8138c53a32 gprs_ns2_vc_fsm: reset the ALIVE response time when stopping test
Prevent showing a response time when the NSVC has failed.

Related: OS#5089
Change-Id: I5435077d35ff1ae3d743ea1b1b8ace7f0fb913cf
2021-06-25 08:12:39 +00:00
Alexander Couzens e09deb6355 gprs_ns2: fix missing notify towards the NSE when NSVC become blocked
The NSE wasn't notified when a NSVC went into the BLOCKED state from
an UNBLOCKED state.

Related: OS#5182
Change-Id: I09634e414e9bb966e6b5809b7de1b59fbabd413d
2021-06-25 08:12:39 +00:00
Alexander Couzens d5cd8c61cb gprs_ns2: use llist_add_tail to keep order
When configuring multiple NSE/BINDs the order of the configuration
should be keeped.

Related: OS#5181
Change-Id: Ibbc03f0780b49543b5bd97ee059f11cfd6c2a126
2021-06-25 08:12:39 +00:00
Neels Hofmeyr 4a9756c17a add Kc128 to gsm0808 Create Ciphering Command
Prepare for A5/4 support in osmo-msc.

Add new function gsm0808_create_cipher2() which takes a struct as
argument instead of individual fields. This is akin to e.g.
gsm0808_create_handover_request() below in the file, and allows
backwards compatibly extending the argument list without needing a new
function signature every time.

Add struct gsm0808_cipher_mode_command, as argument list for
gsm0808_create_cipher2(), with kc128 included.

Encode the Kc128 IE in gsm0808_create_cipher2().

Implement gsm0808_create_cipher() by calling gsm0808_create_cipher2().

Change-Id: Ib3906085e0c6e5a496a9f755f0f786238a86ca34
2021-06-21 00:36:46 +02:00
Philipp Maier eabc6fd4b1 vty: make function cmd_range_match() public
Certain control interface commands also may require to verfy a range in
their verify function. cmd_range_match() from the VTY does exactly that
and the range can be specified as string, the same way as we would
specify it in the VTY.

Change-Id: I53fc207677f52b1dc748b01d58424839cdba807c
related: SYS#5369
2021-06-18 12:31:01 +00:00
Neels Hofmeyr ac49bda4d4 osmo_select_shutdown_request(): allow finishing pending writes on SIGTERM
Allow telling osmo_select_main* to only service pending writes (shutdown
mode). Introduce API fuctions to indicate a shutdown request, and find
out whether shutdown is complete.

Some osmo programs have a curious sleep of few seconds upon receiving
SIGTERM. The idea presumably was to finish off pending writes before
halting the program. But a sleep() on program exit is annoying,
especially when there usually are no pending writes, and when osmo-bsc
is launched numerous times for tests.

Change-Id: Ib94d4316924103459577087c2214188679db2227
2021-06-18 12:22:44 +00:00
Daniel Willmann 8158882b54 stats_vty: Improve generation of osmo counters
Use section for all counter headings, the idea is that the generated doc
is included below a chapter describing the implemented counters which
can optionally describe individual items.

If not osmo_counters are present simply omit the whole section to tidy
up the manual. Those are deprecated anyway and not used in the osmo-*
projects that I checked.

Change-Id: I126b39cb9458e0f62efa338967e07151a0eece0f
Related: SYS#5005, OS#4523
2021-06-16 20:39:06 +00:00
Philipp Maier b6fd8edae9 control_cmd: fix typo
Change-Id: I9deaee42aeb0ab0549cc7c4f180ad9c216b9df39
2021-06-16 20:31:58 +00:00
Pau Espin d1b0716242 ctrl: Support recovering from short write
osmo_wqueue has support for it, so simply handle it correctly in the
callback (updating buffer and returning -EAGAIN).

Related: OS#5169
Change-Id: I6cbc7ec6ae6832e61cddf4402332ba09b142a7d4
2021-06-15 16:29:44 +00:00
Pau Espin f5b8ed14a9 ctrl: Pre-calculate required size before allocating msgb
This commit fixes crash when response is more than ~4096 chars.
Furthermore, we now allocate only the required memory, not 4096 for all
messages, which usually don't require it.
Test needs to be adapted since it assumed there was more available space
at the end of the msgb.

Related: OS#5169
Change-Id: I0b8f370f7b08736207f9efed13a0663b5e482824
2021-06-15 16:29:44 +00:00
Alexander Couzens 68ab9c4193 gprs_ns2_sns: bss: set gss->family
gss->family (and gss->ip) was never set.
So IPv6 should have never worked.

Fixes: e769f5226b ("gprs_ns2_sns: rework IP-SNS initial remote")
Related: OS#5036
Change-Id: I4e39dc5c7f766a7040645ceb62afdf6a9cfad00f
2021-06-13 18:31:51 +00:00
Alexander Couzens 077ce5ac94 gprs_ns2_sns: replace ns2_sns_type with address family
Reduces the code as the conversion between address family (bind)
and ns2_sns_type is not needed anymore.

Related: OS#5036
Change-Id: I1bcdd43af34c926d4b88491d00669422c299bef7
2021-06-13 18:31:51 +00:00
Alexander Couzens 019da4b082 gprs_ns2_sns: refactor nss_weight_sum_data -> ip46_weight_sum_data
Allow to use ip46_weight_sum_data for local endpoints as well.

Related: OS#5036
Change-Id: I75d88f3da89ad13e34a3fd5ae72bd967d81f4abc
2021-06-13 18:31:25 +00:00
Alexander Couzens 6231055645 gprs_ns2_sns: refactor ip4_weight_sum/ip6_weight_sum
Use the new introduced struct ns2_sns_elems instead of
the elems seperate.

Related: OS#5036
Change-Id: I0956ab6085554210569188f52cae121e32fca19b
2021-06-13 18:31:25 +00:00
Alexander Couzens cc56ddcdd0 gprs_ns2_sns: add check for duplicates to add_ip6_elem()
The ip4 version already checks for duplicates.

Related: OS#5036
Change-Id: I4a1528ea3427946ce465085919b2b522d3cedd07
2021-06-13 18:31:25 +00:00
Pau Espin 42bb125df1 bts_feature: Introduce feature to speak to PCU
This feature provides the BSC with information on whether the BTS talks
the IPAC_PROTO_EXT_PCU osmocom extension over the underlying IPA
multiplex of the OML link.

Related: SYS#5303
Change-Id: Id62421f7f5540875ac877a187757f2cf0556bd02
2021-06-11 16:36:29 +00:00
Michael Iedema a667d85a92 ns2: use same name in ctr_group as stat_item_group
Change-Id: I7d2dcb6c7ddf72a0d06ff19f5d0e3dc740bd19ff
2021-06-10 12:57:04 +00:00
Eric Wild c3fa007610 kdf: add key derivation functions
generic sha code from git://w1.fi/hostap.git commit
5ea93947ca67ba83529798b806a15b247cdb2e93 which also happens
to be the source of our milenage code.

Related: SYS#5324
Change-Id: Ibf2e49edada944d91ceba62bd0d6b6ce69261fcd
2021-06-08 02:38:15 +02:00
Vadim Yanitskiy e9fd81a5c3 stats_vty: also show rate counter group name (if present)
Change-Id: I358f52e81a85f041fc21960634d04d18e7883dd5
2021-06-07 14:18:45 +00:00
Alexander Couzens d3507e851e gprs_ns2_sns: move gss->remote specific check out of add_ip4_elem/add_ip6_elem
Allow to use the add_ip4_elem also with local elemens.

Related: OS#5036
Change-Id: Ib48dfd7567467e60c5af2348924ece5cc6124206
2021-06-07 12:39:47 +00:00
Alexander Couzens c2ba25e436 gprs_ns2_sns: use struct ns2_sns_elems in add/update/remove remote_elems
Prepare to use the function also with local elems.

Related: OS#5036
Change-Id: I7db43c8dbd5bd7e7b07a7d629d2615bfa18623db
2021-06-07 12:39:47 +00:00
Alexander Couzens d2c6c49724 gprs_ns2_sns: refactor ns2_clear_ipv46_entries_local to use new elems functions
Related: OS#5036
Change-Id: I7225f7a4215842f0ea601ce6d9d38220f98f808d
2021-06-07 12:39:47 +00:00
Alexander Couzens 7112867151 gprs_ns2_sns: refactor local and remote entries into a struct
The IPv4/IPv6 elemens are the same for local and remote.
Refactor the entries into a struct to use function to manipulate
them with a single function.

Related: OS#5036
Change-Id: I05e053a9eb3328655502dfe2981c8f402104e292
2021-06-07 12:39:47 +00:00
Alexander Couzens 31d52e156f gprs_ns2_sns: bss: improve validation of configuration
Some combination of IPv4 and IPv6 result in incomplete
combination.
E.g. IPv6 binds, but only IPv4 endpoints and vice versa.

Related: OS#5036
Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
2021-06-07 12:39:47 +00:00
Alexander Couzens 6608ce9525 gprs_ns2_sns: move selection of the next bind into own function
It will be also used by del_bind() when removing an active bind

Related: OS#5036
Change-Id: Ic39f0e5474ecc055d9a1b6a7b30777574d8b741d
2021-06-07 12:39:47 +00:00
Pau Espin 05047b7f27 ns2: Use NSVC bufid in stats report
Use the new stats API to set a meaningful name for its stats group too,
so that they are easily to identify when reported.

Example on VTY "show stats":
"""
NSVC Peer Statistics (0)('UDP-NSE01800-NSVC01800'):
 ALIVE response time        :        0 ms
NS Bind Statistics:
 Transmit backlog length:        0 packets
"""

Example reporting to statsd:
"""
my-stats-reporter-prefix.ns.nsvc.UDP-NSE01800-NSVC01800.alive.delay:0|g
"""

Related: SYS#5456
Change-Id: I4c696c615ba3416f8524d0797ce06c0ecd3a18f2
2021-06-05 15:46:27 +00:00
Pau Espin 09f075fad6 stat,rate_ctr: Allow setting group name and use it at report time
This patch adds a new field "name" to the rate_ctr and osmo_stat_item_group
structs, together with an API to set it. This new field allows for easy
identification of specific group instances when several of them exists,
rather than using a sometimes random/increasing index value.

If set, this name (string) is used instead of the index by the stats
reporter.

The name, if set, is also printed during "show stats" VTY commands.

It's up to the user or application to set up unique or meaningful names
to fullfill one's needs.

WARNING: this commit breaks ABI and possibly creates unexpected behavior
when run with non-rebuilt apps which use the modified structs directly
to get the coutners, or if use the static inline API rate_ctr_inc2().
Existing users of these structs should migrate to use new APIs
introduced in follow-up commits instead of accessing the field directly.

Related: SYS#5456
Change-Id: I0dc510783dd9ae8436dae8005a7b3330e80d36f3
2021-06-05 15:46:27 +00:00
Alexander Couzens d794806719 gprs_ns2: rework id strings of nsvcs
Ensure all nsvcs ids are unique as UDP ids might not be unique when
multiple NSVCs connect to the same remote endpoint (multiple binds).
Change the format of all ids to look similiar.
FR: NSE11-NSVC23-FR-fr0-DLCI13.
UDP: NSE11-NSVC-UDP-10.0.0.1:23000-192.168.1.1:24000
UDP: NSE11-NSVC23-UDP-10.0.0.1:23000-192.168.1.1:24000
UDP: NSE11-NSVC66-UDP-[fd01::1]:23000-[fd03::2]:24000

Change-Id: I618e263e73fcc64d4e46b57aa3a2cb2783837907
2021-06-05 15:46:13 +00:00
Vadim Yanitskiy 7d68959b0c fsm: cosmetic: fix weird spacing in osmo_fsm_inst_alloc()
Change-Id: I199085e717c6ebdc9061a0c9fa9a96bfbc11a74a
2021-06-04 20:07:10 +00:00
Pau Espin 7b894a7de0 Use new stat item/ctr getter APIs
Generated with spatch:
"""
@@
expression E1, E2;
@@
- &E2->ctr[E1]
+ rate_ctr_group_get_ctr(E2, E1)
"""

"""
@@
expression E1, E2, E3;
@@
- E2->items[E1]
+ osmo_stat_item_group_get_item(E2, E1)
"""

Change-Id: I41297a8df68e28dfc6016330ac82b0ed5dd0ebc1
2021-06-04 18:19:37 +02:00
Pau Espin 5fe3de5313 stat,rate_ctr: Introduce new API to get counter at given index
Having this API and forcing apps to use it will allow easily adding new
members to the group structure without having so much impact in users of
this struct.

Related: SYS#5456
Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
2021-06-01 21:06:55 +00:00
Harald Welte 20199da02d sim: Add osim_card_{reset,close}() API
This is required to reset and close a card under software control
after opening it with osim_card_open()

Change-Id: Ie9ec66db4d54fdb1331f4ae05ca3ca4274912e9d
2021-06-01 20:29:17 +02:00
Pau Espin 6c7ac6abcd range_enc_determine_range(): Don't dereference array on size=0
cherry-picked from osmo-bsc.git d4c391eab03ce768d7eaf483368d9cda4f9668df

Change-Id: Iae058c35506bc25c9f4790889b89ac46aea664b6
Fixes: Coverity CID#182710 (osmo-bsc.git)
2021-06-01 14:04:20 +02:00
Neels Hofmeyr 208c5b643f fixup for gsm48_chan_mode_to_non_vamos()
When modifying chan modes, I first thought rather always fail if there
is no equivalent mode.

That is true for gsm48_chan_mode_to_vamos(), but for a change to
non-VAMOS, rather return the unchanged mode for non-VAMOS modes, so that
gsm48_chan_mode_to_non_vamos(GSM_CMODE_SIGN) works without failure.

This makes more convenient checking, e.g. in osmo-bsc's lchan_fsm.c
making sure that a non-VAMOS lchan has a non-VAMOS chan_mode, for all
types of lchans.

Change-Id: Ibf20f04d167e0e0599012ff530bc17ba8c8ab562
2021-05-29 23:45:22 +00:00
Vadim Yanitskiy fc02ff459a gsm_08_58.h: add Osmocom specific Bm/Lm CBITs for VAMOS
Change-Id: If33c1695922d110c0d2c60d5c0136caf2587194e
Related: SYS#4895, OS#4941, SYS#5315, OS#4940
2021-05-26 21:18:11 +02:00
Vadim Yanitskiy 57850ae188 rsl: make rsl_dec_chan_nr() more readable, use RSL_CHAN_NR_MASK
Change-Id: I1650e3b02e79461e42499268fa8ed30bff667489
2021-05-26 21:02:06 +02:00
Alexander Couzens 15596899a3 gprs_ns2: vty: fix removing a bind from a SNS
Return 0 after removing a bind. Otherwise the vty would return a
wrong error to the user.

Change-Id: I088c18abafc82ae7bd7b8c487ad9e9b448c42ba9
2021-05-23 10:32:40 +00:00
Alexander Couzens a35c296b6b gprs_ns2: sns: fix del bind()
When the bind to be removed is not the last entry, it would
remove the wrong SNS bind resulting in use-after-free memory.

Change-Id: I79062d404ebba9d5c8f7f209bebde146fa08c71f
2021-05-23 10:32:40 +00:00
Neels Hofmeyr dd6f13636e add RSL_IE_OSMO_TRAINING_SEQUENCE
This IE is explained in the Abis manual in osmo-bts commit
Ie583bd5969fdb45f772af198033e58d7c4077306
http://git.osmocom.org/osmo-bts/commit/?id=823cd529649b667af20bfa4e383255a8ed5931f1

Change-Id: I573c26b1431ee789e42f6fa620947b003c384dc0
2021-05-19 18:34:33 +02:00
Pau Espin 645aec8237 vty: Introduce API vty_read_config_filep
This new API doesn't use host_config_set(), and allows passing a FILE*
from any source, not only a filesystem path.

Related: SYS#5369
Change-Id: I720ac04386261628c0798a1bfcaa91e2490a86c3
2021-05-18 14:56:52 +02:00
Pau Espin ebb6c1fc4d vty: Implement missing public API host_config_file()
The API was defined in the header file but not implemented.

Change-Id: I69de9864fa7cd421557b9fc630beefea6d90b4cc
2021-05-17 18:54:23 +02:00
Harald Welte 24980baac9 osmo_sock_*_ofd(): Mark OSMO_FD_WRITE on non-blocking connect()
When we perform a non-blocking connect, the completion of the connect
will be signaled by marking the fd as WRITE-able.  So we should
automatically set OSMO_FD_WRITE to make sure the user gets notified
on completion.

Change-Id: I22964c5d5da849abcd97a900bd86ab5b4ada05da
2021-05-08 10:40:13 +00:00
Pau Espin a5af04477e gb: Fix missing exporting symbol bssgp_encode_rim_pdu
The symbol was not in the list of exported symbols.

Change-Id: I4c3792c3b22989571548e40aa4fbf26912e699df
2021-05-06 20:28:27 +02:00
Pau Espin adef546ff9 Revert "gb: Fix naming and export symbol bssgp_enc_rim_pdu"
This reverts commit 43ad616e4b.

 _enc_ functions are for some ies while the _encode_ and _decode_ are
for the full pdu.  so the old name is correct.

Change-Id: Ib0b4a6fd7f8c96e4647a373541e3cccb324c6a11
2021-05-06 18:28:12 +00:00
Vadim Yanitskiy f466a1592f gsm/abis_nm: add missing NM_OC_IPAC_* value-string entries
Change-Id: I2181af229e8e7da12d716c176ab9230f09e29eef
2021-05-06 16:32:29 +00:00
Pau Espin 43ad616e4b gb: Fix naming and export symbol bssgp_enc_rim_pdu
The symbol was not in the list of exported symbols.
Take the chance that it was not used anywhere outside libosmocore to
rename it in order to follow similar naming as other existing APIs.

Change-Id: I534db7d8bc5ceb19a2a6866f07d5f5c70e456c5c
2021-05-06 17:56:47 +02:00
Pau Espin a488639e42 osmo_timer_pending: Make arg const
Change-Id: I250c25c3ac61ac364335f81d8ba50cb32fd6976e
2021-04-29 20:14:51 +00:00
Harald Welte 5782fec9ff ns2: change the 'priority' setting name to 'socket-priority'
This has been changed based on feedback from Pau Espin in osmo-mgw,
and for consistency we also adjust it here.  No backwards compat
needed as it was just introduced yesterday.

Change-Id: I88989dc17c8996609b895c43012f8cca98aa81dc
2021-04-29 21:29:48 +02:00
Harald Welte a545842609 ipa_ccm_make_id_resp: Make it work at all
This could never possibly have worked.  When iterating over the
different IEs to encode, we must of course use the tag of the current
iterator item, and not the hard-coded value of the second tag in the
list.

Change-Id: I148799c5bdb95f70118691c1150330ebac4fdf21
2021-04-29 19:59:12 +02:00
Harald Welte b189b5f29c Fix ipa_ccm_make_id_resp_from_req to work at all
The parser was so horribly broken, it could not ever have possibly
worked.

Change-Id: Ibed0ff7f8d36504ef783f2653c9982d4e25e874f
2021-04-29 19:59:09 +02:00
Harald Welte 539272dd8e Fix ipa_ccm_make_id_resp_from_req
In 2018, I4723361e1094b358310541a7dc4c5c921c778a15 introuced a
check against an integer unterflow.  However, the fheck got the
logic wrong, with the result of breaking the function completely:
It would always only detect the first tag within the IPA request
and then take the branch that assumes an integer underflow.

Change-Id: I344975d0bda565ff196a1c0c69305cd349b98a19
2021-04-29 19:55:43 +02:00
Harald Welte d99e4eee2b ns2: Allow setting the socket priority for a UDP bind
Change-Id: Ifdfa086ce1c8d62b256abb3454b70cf53da9dcdb
2021-04-29 19:55:34 +02:00
Harald Welte 915caf75e2 gprs_ns: Fix another DSCP vs. TOS mistake in old NS code
DSCP is a 6-bit value stored in the upper 8 bit of what was used to
be known as TOS.  Let's use the newly introduced OSMO_SOCK_F_DSCP()
to prevent having to worry about this in higher level code.

Change-Id: I6b9848fd0752d99d3df5346313618d5847d64fb8
Related: OS#5136
2021-04-29 15:54:59 +02:00
Harald Welte 485b3f7c85 ns2: migrate from osmo_sock_set_dscp() to OSMO_SOCK_F_DSCP()
The latter is much more compact than the former.

Change-Id: I2a24c0cbb17fad8ed84297267dcd63730efbc014
2021-04-29 15:54:59 +02:00
Harald Welte f8a4e133d5 gprs_ns2_frgre: Ensure DSCP is sin premitted value range
gors_ns2_udp has this check, but gprs_ns2_frgre was missing it.

Change-Id: I9bb9c6bdfe81fa6f02b11a02550ac9a54d3bfeaf
2021-04-29 15:54:59 +02:00
Harald Welte 628f534817 gprs_ns2: Fix yet another DSCP vs. TOS mix-up
This is a follow-up to I64fee56b04d0ecd128bf661699d5071817ea96ec,
due to code duplication there was another code path that manually set
the IP_TOS socekt option that I missed in the first patch.

Related: OS#5136
Change-Id: I4bb22d0f67984077706b694eb7e75327b41b6fcf
2021-04-29 09:02:25 +00:00
Neels Hofmeyr 87fa1caf4b fix default_timeout type of osmo_tdef_fsm_inst_state_chg default_timeout
The api doc indicates the possibility to pass -1, and calling
osmo_tdef_get() actually casts the arg to a signed long. To end the
confusion, change default_timeout from unsigned long to long.

Change-Id: I51b9172603984839448346c9836e43c8c802fcf8
2021-04-28 18:31:31 +00:00
Harald Welte 903e670c54 socket: IPv6 support for osmo_sock_set_dscp()
IPv6 has the analogous to DSCP: The "traffic class" field.

See https://tools.ietf.org/html/draft-itojun-ipv6-tclass-api-03

Change-Id: Ib31b977f67d60aa7f30ca4ab6eceba3d1d5eeee1
Related: SYS#5427
2021-04-28 14:39:19 +02:00
Harald Welte c545ff6f3e socket: QoS support for all our socket init functions
Every socket function that can be passed a 'flags' argument now
supports the following two additional macros that can be or-ed in
with the flags:
* OSMO_SOCK_F_DSCP(x) -- specify the IP DSCP of the socket
* OSMO_SOCK_F_PRIO(x) -- specify the priority of the socket

The existing osmo_sock_set_{dscp,priority}() functions are useful,
but  you cannot call them in between the socket creation and the
connect() operation when using our socket helpers.  This means that
the first packet sent will have the default DSCP/priority, and only
later packets would have the desired values.

When using the functionality introduced by this patch, we can ensure
that even the very first packet of e.g. a TCP or SCTP connect()
will have the correct DSCP/priority applied.

Change-Id: If22988735fe05e51226c6b091a5348dcf1208cdf
Related: SYS#5427
2021-04-28 13:15:20 +02:00
Harald Welte faf6b70b0e socket: reduce code duplication, introduce socket_helper_tail()
Common bits shared by various functions (currently setting
non-blocking) should not be copy+pasted around.

Change-Id: I95056940ddc26b65f63eedaeaab6882edaef6317
2021-04-28 13:15:20 +02:00
Harald Welte ecc0bd8d42 socket: Introduce osmo_sock_set_priority() helper function
In some situations we want to set the SO_PRIORITY socket option
to determine the in-kernel priority of packets generated by this
socket.

Change-Id: I89abffcd125e6d073338a5c6437b9433220e1823
Related: SYS#5427
2021-04-27 22:25:13 +02:00
Harald Welte c96d716606 ns2: Fix setting the DSCP value.
DSCP is a 6-bit value (0..63) stored in the upper 6 bits of what was
formerly known as TOS bits.  We must
* make sure the user can only specify 0..63
* shift the value by two bits when using the IP_TOS socket option

We achieve the latter by using the recently-added osmo_sock_set_dscp()
helper.

Change-Id: I64fee56b04d0ecd128bf661699d5071817ea96ec
Closes: OS#5136
2021-04-27 21:57:52 +02:00
Harald Welte ce53e03dc9 socket: Introduce osmo_sock_set_dscp() to set socket DSCP value
At least on Linux, sockets have a IP_TOS socket option that can be
configured to set the TOS.  However, TOS (of RFC791) was replaced
by the DSCP (of RFC2474) in 1998.

As the DCSP bits are only the upper 6 bits of the TOS bits, let's
introduce a helper to get, mask and set the DSCP values in the TOS
bits.

Related: OS#5136, SYS#5427
Change-Id: Ia4ba389a5b7e3e9d5f17a742a900d6fd68c08e40
2021-04-27 21:53:32 +02:00
Harald Welte 069967be86 ns2: Dump frame relay state to VTY during "show ns"
When doing a "show ns", let's also dump the state of the frame
relay network, with all its links and DLCs (if any).

Change-Id: I798af3e97dc014b6e0fcde86560a1809852f7510
Related: OS#4877
2021-04-25 21:09:23 +02:00
Harald Welte 47cc55ceac frame_relay: Export osmo_fr_network_free()
The function already existed, it was just not declared and not
exported.

Change-Id: I3f2a7e2fd1a4eda6bbed8510cf82951d73bb3f84
2021-04-25 21:09:23 +02:00
Harald Welte a912d192f1 sim: Remove 'printf' from library code
Those were really meant as an early debugging aid and should not
have survived this long.

Change-Id: I4e9a80ced15686734d4485c232c5936f566cfd76
2021-04-25 21:09:23 +02:00
Harald Welte 22117a7164 sim: Obtain card ATR when opening the card
Change-Id: I42e387535c40f371b06f384af0ca5dc1e42ed00e
2021-04-25 21:09:23 +02:00
Neels Hofmeyr a0f2b21c6d gsm48_mr_cfg_from_gsm0808_sc_cfg(): drop bitmask without effect
GSM0808_SC_CFG_AMR_4_75_5_90_7_40_12_20 has value 0x0002, so the
'& 0xff' had exactly no effect.

Change-Id: Ia25ac20539e8ac70fb5f70c1191bd58825151c68
2021-04-22 18:49:44 +00:00
Pau Espin cde47795d1 gsm0808: Introduce gsm0808_old_bss_to_new_bss_info_att_tlvdef
Introduce TLV attribute definition for "Old BSS to New BSS Information"
container.

Related: SYS#5337
Change-Id: I0e55e947b6fef6dad0cf1a6c16b781bef4cc76c5
2021-04-21 19:02:31 +02:00
Neels Hofmeyr 4b44ac4012 RR: add missing Extended TSC Set IE
Defined in 48.018 10.5.2.82.
This will be used by Channel Mode Modify for VAMOS.

Related: SYS#4895 SYS#5315
Change-Id: I9bad6e7121af43dfa9706635e58279ce672a4e14
2021-04-20 02:43:40 +02:00
Neels Hofmeyr a9da9f7640 RR: add VAMOS channel modes
Also add functions to convert between VAMOS and non-VAMOS speech modes.

Related: SYS#4895 SYS#5315
Change-Id: Ie0ea592da5610ae70290106d004e549cf3212a89
2021-04-20 02:42:42 +02:00
Pau Espin 49766ab1b6 cosmetic: fix typo in comment
Change-Id: I43cb7b88a4e867836a67928e361253ce0f02a329
2021-04-19 12:14:36 +02:00
Pau Espin 1b625cb134 gsm: Support Sending Last EUTRAN PLMN Id in Handover Required
Related: SYS#5337
Change-Id: I6280ce1abc283f1491bc6f391b2dd952df33a16b
2021-04-19 10:55:43 +02:00
Alexander Couzens 27a5592205 gprs_ns2: add functions for SNS add/del/change-weight messages
Related: OS#5036
Change-Id: Ib9492e213e82c18c7dcce6ba7d64e897b4c74796
2021-04-18 06:38:34 +00:00
Alexander Couzens 0a7c5eea22 gprs_ns2: SNS: allow transition missing transition GPRS_SNS_ST_UNCONFIGURED
A transistion from GPRS_SNS_ST_UNCONFIGURED -> GPRS_SNS_ST_UNCONFIGURED.

Related: OS#5036
Change-Id: I125e7e5a08ea6aff6e0308a18b5c0a6d0392ad32
2021-04-18 06:38:34 +00:00
Pau Espin d110529972 cosmetic: tlv_parser: fix typo in func description
Change-Id: I27f28376a88f00d86a0f65595f61f6026f7e0fd4
2021-04-14 17:21:02 +02:00
Alexander Couzens 79a3a84b15 gprs_ns2: fix nsvc block and unblock vty command
e7dfeac8dc introduced a regression in the block/unblock check
as it was using the priv->initiate_block instead of priv->om_blocked.
The initiate_block tracks who is responsible to unblock the NSVC.

Fixes: e7dfeac8dc ("gprs_ns2_vty: print a response to vty `nsvc <nsvci> (block|unblock|reset)")
Change-Id: I516faea223e30b120a297faed10636daa554be8a
2021-04-13 12:38:44 +02:00
Vadim Yanitskiy 4b46b7eb53 vty/logging: logp: properly handle library specific sub-systems
The library specific sub-systems are kind of special, because their
position in the 'osmo_log_info' may vary depending on the number of
application specific sub-systems.  This is why their associated
constant values (like DLGLOBAL) are negative, and this is what
the LOGP() macro expects as the first argument.

Before this change, invoking 'logp' command with any library
specific logging sub-system would result in getting messages
printed with the fall-back DLGLOBAL sub-systems.

Change-Id: If86563e169fe1243adfa7b09c9d65d9f88c8a99e
2021-04-12 12:15:17 +00:00
Neels Hofmeyr 47c7b4fc24 add osmo_bts_features_names: short BTS feature strings
This will be used by osmo-bts-omldummy to parse features strings from
the cmdline.

Note that osmo_bts_feature_name() already exists to return the longer
descriptive value_strings from osmo_bts_features_descs (_descs!).
Luckily that misses the plural 'features' in the name, so that I can
still add a properly named osmo_bts_features_name() function that only
returns the name, matching the common pattern used in osmocom code.

Related: SYS#4895
Change-Id: I699cd27512887d64d824be680303e70fff3677c1
2021-04-09 00:10:44 +02:00
Oliver Smith d4393608a4 stats: have_value is a bool, not int
Change-Id: Id92c63f4e54ec1bf3411205be1bd268e1d184b03
2021-04-07 18:39:05 +00:00
Oliver Smith 2623fca8ad stats: log error when missing stats values (v2)
Related: SYS#4877
Change-Id: I5140d967c2f1d36dadf93b03e52b9bbd42e2a3a6
2021-04-07 18:38:54 +00:00
Oliver Smith 6140194347 stat_item: make value ids item specific
Fix counting of values missed because of FIFO overflow in
osmo_stat_item_get_next(), by assigning a new item value id effectively
as item->value[n + 1].id = item->value[n].id + 1, instead of increasing
a global_value_id that is shared between all items and groups. With
global_value_id, the count of values missed was wrong for one item, as
soon as a new value was added to another item.

This partially reverts b27b352e ("stats: Use a global index for stat
item values") from 2015, right after stats was added to libosmocore. It
was supposed to make multiple readers (reporters) possible, which could
read independently from stat_item (and later added comments explain it
like that). But this remained unused, stats has implemented multiple
reporters by reading all stat_items once and sending the same data to
all enabled reporters. The patch caused last_value_index in struct
osmo_stat_item to always remain at -1.

Replace this unused last_value_index with stats_next_id, so stats can
store the item-specific next_id in the struct again. It appears that
stats is the only direct user of osmo_stat_item, but if there are
others, they can bring their own item-specific next_id: functions in
stat_item.c still accept a next_id argument.

Related: OS#5088
Change-Id: Ie65dcdf52c8fc3d916e20d7f0455f6223be6b64f
2021-04-07 18:38:54 +00:00
Vadim Yanitskiy 2d1a9fabcc vty/logging: ensure consistent '%' prefix for warnings
Change-Id: I2b2bab61e46668c3b4b0ccad88d02b6d00a83544
2021-04-07 16:33:18 +00:00
Vadim Yanitskiy ad34465349 vty/logging: use consistent quiting in warning messages
Change-Id: Ifded63a38caac26e174fc6cb69dead7bc83db344
2021-04-07 16:33:18 +00:00
Alexander Couzens e7dfeac8dc gprs_ns2_vty: print a response to vty `nsvc <nsvci> (block|unblock|reset)
The vty wasn't printing anything to the user if it was a success or not

Change-Id: Idbb83ea319bbdc94177febdd66e79c49fce7fdd2
2021-04-07 16:25:35 +00:00
Alexander Couzens 53e7009049 gprs_ns2: sns: remove the initial SNS NSVC if it's not part
A SNS configuration can be done over a NSVC, however this initial NSVC doesn't
need to be part of the configuration.
Those NSVC need to be removed when the configuration is done.
This wrong behaviour can be seen in the vty `show ns` on

NSEI 00001: UDP, ALIVE
 FSM Instance Name: 'GPRS-NS2-SNS-BSS(NSE00001-SNS)[0x55c72c09b420]', ID: 'NSE00001-SNS'
  Log-Level: 'DEBUG', State: 'CONFIGURED'
 Maximum number of remote  NS-VCs: 8192, IPv4 Endpoints: 8192, IPv6 Endpoints: 8192
 Local IPv4 Endpoints:
  10.0.0.1:23000, Signalling Weight: 1, Data Weight: 1
 Remote IPv4 Endpoints:
  10.0.2.2:23000, Signalling Weight: 1, Data Weight: 0
  10.0.2.2:23001, Signalling Weight: 0, Data Weight: 1
  3 NS-VC:
   NSVCI none: UNBLOCKED DYNAMIC data_weight=1 sig_weight=0 udp)[10.0.0.1]:23000<>[10.0.2.2]:23000
   NSVCI none: UNBLOCKED DYNAMIC data_weight=0 sig_weight=1 udp)[10.0.0.1]:23000<>[10.0.2.2]:23001
   NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[10.0.0.1]:23000<>[10.0.2.2]:8888

The UNCONFIGURED NSVC should not be present in when SNS is in CONFIGURED.

Related: SYS#5416
Change-Id: I4045ac6c033ae084743b17a16eef4fcff76589b9
2021-04-07 16:12:34 +02:00
Alexander Couzens cdb2baaa0c gprs_ns2: sns: ensure the sns->alive state is correct
The SNS fsms also track the NSE however since the NSVC
starts now in ALIVE for SNS the SNS must check when synchronize
the alive state when entering the ST_CONFIGURED.

Related: SYS#5416
Change-Id: Ib6a1cc1fd84959e69c07b72ef780642205d2cd18
2021-04-06 14:30:19 +00:00
Alexander Couzens 5b72247dde gprs_ns2: nsvc_fsm: reorder notification st_alive_on_enter()
The start_procedure() can't be called after ns2_nse_notify_unblocked()
because ns2_nse_notify_unblocked() might free the nsvc.
Otherwise the fsm will do use-after-free on the NSVC memory.

Related: SYS#5416
Change-Id: If97dfd123eefd71fc6c3fe886a243a21784aeeb4
2021-04-06 14:30:19 +00:00
Oliver Smith 43686dacd6 stat_item: add comment with struct overview
Related: OS#5088
Change-Id: Ic63a5884da778938197c658c5f478c23a85a4587
2021-04-06 11:27:34 +02:00
Oliver Smith d3490bc442 stat_item: make next_id argument name consistent
Let osmo_stat_item_get_next, osmo_stat_item_discard,
osmo_stat_item_discard_all consistently refer to their next_id arg as
such (and not idx or next_idx). It refers to an ID (item->values[i].id),
not an index (item->values[i]), and it is always the next one, never the
current one.

Do the same change for _index/_idx variables in stats.c, which are used
as arguments to these functions. Replace rd_ with next_id_ in
stats_test.c, too.

Related: OS#5088
Change-Id: I5dd566b08dff7174d1790f49abd2d6ac020e120e
2021-04-06 11:27:34 +02:00
Alexander Couzens 8bd63b667e gprs_ns2: vty: remove a white space in `show binds`
Change-Id: Ia3579ec5599f5f5c58eebab03f1ed9e17f171177
2021-03-31 06:00:44 +00:00
Alexander Couzens 7619ed4304 gprs_ns2: fix memory leaks when receiving SNS or invalid packets
Change-Id: I8834d3f092e6cbe4f527e95e1eebd8133a386207
2021-03-29 21:26:46 +00:00
Harald Welte c2fbbd7307 gprs_ns2_sns: Fix memory leak when creating ip[46]_local arrays
Prior to this patch, we would unconditionally allocate new memory
for the local SNS IP endpoints.   This results in a memory leak
on every SNS-SIZE procedure.

Let's move to talloc_realloc() which recycles any previously allocated
memory.

Change-Id: I12cb670e087c6d6190f3f5bf8483ea62008ae06f
2021-03-29 10:20:08 +02:00
Neels Hofmeyr 158bc795e5 add BTS_FEAT_VAMOS
Change-Id: Ic3bd1b8075f76d1f35499faa68fad70698ee9a00
2021-03-27 17:14:57 +01:00
Harald Welte 3053bbb3f3 gprs_ns2_sns: Don't create NS-VCs for binds outside the NSE
We may very well have any number of binds configured, but which
are not part of the current NSE.  When creating the "full mesh" of
NS-VCs after SNS-CONFIG, we must only iterate over those binds that
are part of the NSE (or 'ipa-sns-default bind' in cae of SGSN role),
but not over all the other binds that may exist in the system.

Closes: OS#5092
Change-Id: Ida361fa02ad1d86844d54c8f0664c996ed28e30a
2021-03-24 16:18:15 +00:00
Harald Welte e8c6106c2e gprs_ns2_sns: remove code duplication in create_missing_nsvcs()
Change-Id: I78d79c3bc92f0c0bebbbbe639b8406c4b188582f
2021-03-24 16:18:15 +00:00
Alexander Couzens 27e5873c8d gprs_ns2: add vty command `nsvc <nsvci> reset`
Change-Id: I436dd0367e83548acfc8f8e36ae4707496a252d9
2021-03-24 15:42:45 +00:00
Alexander Couzens 1dd9cbf45e gprs_ns2: dump_nsvc: correct indention
As both `show ns entities` and `show ns binds` looking similiar
correct the indention.

Change-Id: I55794188bec7e62f0341188dbf23ac04006974fe
2021-03-24 15:42:45 +00:00
Alexander Couzens 0ea4a4e0c4 gprs_ns2_vty: make the `show ns entities` and `show ns binds` look similiar
`show ns binds` prints a count of NSVCs. Add the same line
to `show ns entities`.

Change-Id: I15c58a1c0fe94dda728afb29e7e5ca41e3fa8966
2021-03-24 15:42:45 +00:00
Alexander Couzens 3e539ed127 gprs_ns2_vty: hide dynamic NSE information when ask for persistant only
dump_nse() should only print persistant NSE when persistant_only
argument is set. A NSE can be persistant or dynamic configured.
Depending on the NSE all NS-VC must be the same as the NSE.

Change-Id: Ibd2c6962eda39a850ab61cf347063934378d2fdc
2021-03-24 15:42:45 +00:00
Alexander Couzens 75b6188974 gprs_ns2: always use the same method to print NSVCs
The binds also print a list of associated NSVC when
dumping the bind.
However the binds using their own representation of
printing the NSVC which is different to `show ns entities`.
Use the same function to print NS-VC.

Before:
  NSVCI 00000: udp)[127.0.0.1]:23000<>[127.0.0.1]:22000
After:
  NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[127.0.0.1]:23000<>[127.0.0.1]:22000

Change-Id: If31ec6c1c07dc134ab1ddeb915bc89747c7be048
2021-03-24 15:42:45 +00:00
Alexander Couzens 6cf65d9d81 gprs_ns2: rework logging of Rx and Tx NS PDU
Introduce 2 new logging sub systems for signal and unit data.
Unify log messages so all log messages look similiar.
Log also Rx PDUs. Ensure dropped Tx packets (BLOCK/RESET on SNS)
contain *Tx*.

Change-Id: I34b8fde2955ecc010d1dcd9512e1bba9211e2c0d
2021-03-24 15:42:45 +00:00
Harald Welte 2d807b6c7d gprs_ns2_sns: Compute local endpoints before using them
This fixes some bug introduced in Change-Id I1638f04ba45fef3ba0b237948dff6022267141fb

Related: OS#3373

Change-Id: Ic0873e63f1f046b674c7898480ff070a18a7abc7
2021-03-24 01:58:52 +01:00
Harald Welte 5e4083166a gprs_ns2: Actually start Tns-test after SNS-CONFIG creates NS-VC
the previous commit fixed the state transition, but also caused
neither Tns-alive nor Tns-test to run

Change-Id: I07ea3fd5cec3d4acf4051930a1a3c746d6fd597c
2021-03-24 01:04:21 +01:00
Harald Welte c51ddf27b4 gprs_ns2_vc_fsm: In IP-SNS/ALIVE mode, initial state is ALIVE/UNBLOCKED
Only when the ALIVE procedure fails, we mark a NS-VC as RECOVERING.

Change-Id: Ieb860827c2149306b135c0e6c8b3cd3bbb78851e
2021-03-24 01:04:21 +01:00
Harald Welte c962a2efc3 gprs_ns2: Add comments explaining the nsvc->sns_only field
Change-Id: I16009a1b03d8027de2be56b7d5013b755c9550fd
2021-03-24 00:30:23 +01:00
Harald Welte d164ef80f9 gprs_ns2_sns: Allow VTY configuration of default binds for IP-SNS
In the IP-SNS SGSN role, we need to inform the BSS of our local
IP endpoints.  For statically configured NSEs, those are explicitly
stated on a per-NSE level.

For dynamically created IP-SNS NSEs, we are adding a new VTY
command, using which the administrator can configure which binds
should be advertised as IP endpoints to such BSS.

Change-Id: Id01c29b07e9203c9305f2129361a4f5aaefa2c52
Related: OS#3373
2021-03-24 00:30:23 +01:00
Harald Welte fe0266e8d8 gprs_ns2: dynamic NS-VC + NSE creation for IP-SNS in SGSN role
Related: OS#3373
Change-Id: Ie10bb3531fae2e651da04f965d964de6eb1e7a97
2021-03-24 00:30:23 +01:00
Harald Welte 42e3646a98 gprs_ns2_vty: Permit VTY configuration of bind->accept_sns
Related: OS#3373
Change-Id: Ifb52cd245b10bf47d42d57d167d6d6c02b12ee12
2021-03-24 00:30:23 +01:00
Harald Welte 01fa6a3ef3 gprs_ns2_sns: Implement checks during processing of inbound SNS-SIZE
As per 3GPP TS 48.016 section 6.2.4.1, we need to perform some
consistency checks during the SNS-SIZE procedure.  Let's implement them.

Change-Id: I1638f04ba45fef3ba0b237948dff6022267141fb
Related: OS#3373
2021-03-24 00:30:23 +01:00
Harald Welte 24f4df5c46 gprs_ns2_sns: Assume the SGSN has a very large number of max. NSVC
It is the SGSN's job to ensure sufficient NS-VC capacity.  As the SGSN
doesn't tell the BSS, we should not make assumptions of only 4.

Change-Id: I41f493643cf51d7853959ab9c7bbc0ffae4e1f4b
2021-03-24 00:30:22 +01:00
Harald Welte 4e41acc1ad gprs_ns2_sns: SNS-SIZE contains the actual number of local endpoints
The SNS-SIZE sent from BSS to SGSN contains the actual number of local
IP endpoints on the BSS side, and not the maximum number of remote IP
endpoints supported.

Change-Id: I62a8bca4a3f7c47bcb9f292b045fa867d8877a09
2021-03-24 00:30:22 +01:00
Harald Welte a2c5af5547 gprs_ns2_sns: Verify mandatory IE presence in incoming SNS-SIZE
Change-Id: I40571e313c3332d8cead8fb4aa9768d0d083804d
2021-03-24 00:30:22 +01:00
Harald Welte 46eb7643c9 gprs_ns2_sns: Don't clear remote IP endpoints in SGSN role
In BSS role, we can clear local + remote endpoints when sending
SNS-CONFIG, as we are first.

In SGSN role, we must not clear remote endpoints when sending
SNS-CONFIG, as we are last, and the BSS has just previously told
us its IP endpoints in the BSS-originated SNS-CONFIG.

Change-Id: I58549707ac5a3a0aae5f9348ed76f16c09ad3e46
Related: OS#3373
2021-03-24 00:30:22 +01:00
Harald Welte 579699bc2d gprs_ns2_vty: Allow creating NSE in sgsn-role
Change-Id: I694fa6c80d04d13cb1afaae93a9ae43b6dfd2207
Related: OS#3373
2021-03-24 00:30:22 +01:00
Harald Welte 5b034fbab0 gprs_ns2: Introduce gprs_ns2_create_nse2() for SGSN side SNS
gprs_ns2_create_nse() doesn't allow the caller to specify if the
BSS or the SGSN role of IP-SNS shall be implemented.  Add
gprs_ns2_create_nse2() to fix that.

Change-Id: I6db8c36f7c69b592d7d0fbcf323804f7e9912be2
Related: OS#3373
2021-03-24 00:25:56 +01:00
Harald Welte 694dad502a gprs_ns2_sns: Rename BSS-side states to include 'bss' in name
Clearly separate those states that only occur on the BSS side from
those of the SGSN side (which already have a prefix)

Change-Id: Iebc97637063b2676abff4a7dce50272d9b4e336b
Related: OS#3373
2021-03-23 15:22:16 +01:00
Harald Welte f61a9150a9 gprs_ns2_sns: Add some more OSMO_ASSERT about BSS role
Some functions are only to be called when operating in BSS role,
let's enforce that by sprinkling some OSMO_ASSERT() around.

Related: OS#3373
Change-Id: I20d1bd8df62e0bb84696e291756e2d96acf49246
2021-03-23 11:57:16 +01:00
Harald Welte 4f1274614e gprs_ns2_sns: Support for SGSN-side IP-SNS
This adds the core functionality of implementing the SGSN-side of IP-SNS
inside a new FSM.  The SGSN-side FSM shares states, events, structures
and code with the BSS-side whenever possible.

Note that this commit does not yet use the SGSN-side FSM, that is part
of subsequent commits.

Closes: OS#3373
Change-Id: I780413ffacd9cb71f64cc38057aae781eeb59b2b
2021-03-23 11:57:16 +01:00
Oliver Smith a7eb735b8d Revert "stats: log error when missing stats values"
This reverts commit d290439b4a, which
caused "stats values skipped" messages to appear even if they were not
skipped. Revert for now, replace with a proper version in the future.

Related: SYS#4877
Change-Id: Ib43bd53188a4d31d771feb921ea14abe1a3ec877
2021-03-19 16:47:52 +01:00
Oliver Smith d290439b4a stats: log error when missing stats values
Let the user know when the stats were not consumed fast enough for the
given FIFO length.

Related: SYS#4877
Change-Id: If0e8ab55103007693101538fb6ea310075217774
2021-03-17 17:52:37 +01:00
Harald Welte 9e37bf4bbc gprs_ns2_sns: Split allstate action in generic and BSS-specific part
Related: OS#3373
Change-Id: Icd40bd76df12795b4efcaf5865c6cf00da145f94
2021-03-10 12:23:09 +00:00
Harald Welte 06d9bf910b gprs_ns2: Encapsulate setting NSE dialect
Setting the NSE dialect possibly involves the creating (or destruction)
of a IP-SNS FSM.  Encapsulate that, rather than having every caller
re-implement that.

Change-Id: I24fdc26fbcfda039bd58ea166f4d5c2fd1801da1
2021-03-10 12:23:09 +00:00
Harald Welte c1c7e4a830 gprs_ns2_sns: Unify handling of SNS-CONFIG for IPv4 + IPv6
Related: OS#3373
Change-Id: I49e5ca4a09bc772ef5a0cd5c2a76c8b200e56d1b
2021-03-10 12:23:09 +00:00
Daniel Willmann 2aa527bd99 stats: Ensure that each osmo_stat_item only reports once per interval
We should never report multiple values for a metric. It is confusing for
the log reporter and wrong for statsd. Statsd will record only one value,
but will it be the first, last, ...?
This can happen if an osmo_stat_item changes more than once within the
same reporting interval.

With this patch only one aggregate value is sent to the log reporters.
The value reported is the maximum during this interval. Other
aggregations could be possible (min, last), but reporting a (useful)
average is not because the values don't include a timestamp and most
osmo_stat_items change at unregular intervals.

Change-Id: I366ab1c66f4ae6363111ea4e41b66b7d5bcade9c
Related: SYS#4877
2021-03-09 14:08:15 +01:00
Harald Welte 24920e2c97 gprs_ns2_sns: refactor ns2_sns_st_size_onenter()
Let's move computing of the local IP endpoints to a separate function,
so it can not only be used when entering the SNS_SIZE state. Preparation
for SGSN-side IP-SNS.

Change-Id: I5d7ce419135a8ef538cf9abcb76a49049ed7d5f9
Related: OS#3373
2021-03-05 17:08:03 +01:00
Harald Welte 2230a91711 gprs_ns2_vty: Clarify VTY help string wording
Change-Id: I7d70f8cc811c2f4aabf9fc00e4e612dfc4b031d3
2021-03-05 17:08:00 +01:00
Harald Welte 502845ec17 gprs_ns2_sns: Remove TODO (spec agrees, the correct cause code is used)
Change-Id: I6c431ba9e30d19425bf1cc1cc4d081949058610b
2021-03-05 17:06:54 +01:00
Harald Welte 05992873a7 gprs_ns2_sns: Implement error log in case no binds found for NSE
Change-Id: I66ce4b429ad2597343b48210fdcbc95a1f34cbcd
2021-03-05 17:06:54 +01:00
Harald Welte 7d0daac1ce gprs_ns2: Pass peer/remote sockaddr argument to ns2_create_vc()
This is a preparation towards auto-creating SNS NS-VCs in SGSN role

Related: OS#3373
Change-Id: Idf92712079cd9b7e4ff2cf8df314b372d63e6e52
2021-03-04 13:35:14 +01:00
Harald Welte a39b2592a0 gprs_ns2: Remove any references to DNS; we use DLNS in NS2.
Related: OS#5058
Change-Id: I1f047e022a029d5f982deae0b30fec9e5a00d1ac
2021-03-04 13:35:14 +01:00
Harald Welte b9f23878bb gprs_ns2_sns: Dispatch inbound SNS-ACK to FSM
We don't really handle inbound SNS-ACK yet (as we don't originate
SNS ADD/DEL/CHGWEIGHT procedures yet).  However, the message
receive code should already dispatch those events to the FSM,
just like we do for the (equally unimplemented) handling of inbound
SNS-SIZE which is already dispatched to the FSM.

Change-Id: If6d5f96d85e6f05534fe49376f4473d912535ad4
2021-03-04 13:35:14 +01:00
Harald Welte 22274dfeb5 gprs_ns2: Log all transmitted SNS messages
We already have similar log statements for all NS-{RESET,BLOCK,UNBLOCK,...}
and it's confusing that even a debug-level NS log file doesn't show
transmitting SNS messages at all.

Change-Id: I0d31c3911d3acd6ac7296c370e920d53412d8289
2021-03-04 13:35:14 +01:00
Harald Welte 04647e169e cosmetic: ssn: some more comments
Change-Id: I87f76ab19d834d96a268b0d47b9dfe2424151d63
2021-03-04 09:09:13 +00:00
Alexander Couzens 3255668afb gprs_ns2: don't OSMO_ASSERT() while freeing NS-VC.
When freeing the NS-VC there are cases when the NSE is still alive.
This means that gprs_ns2_free_nsvc() calls  ns2_prim_status_ind(),
which in turn calls ns2_count_transfer_cap().  The latter must deal
with such a situation rather than OSMO_ASSERT()

Change-Id: I4f32dee705c9886717339fe7cce5b4cd8d2c18f7
2021-03-03 07:50:00 +00:00
Alexander Couzens 5baa141315 gprs_bssgp: use BVCI_SIGNALLING/BVCI_PTM instead of 0/1
Makes more understandable and clear what's meant in the code.

Related: OS#3879
Change-Id: I9d0545fac0af0dcc1783040a376a9b8e65a92699
2021-03-01 19:44:02 +00:00
Alexander Couzens 7819ff6959 gprs_bssgp: add support for SGSN oriented RESET
To support SGSN oriented RESET introduce a role flag to
track what's running the gprs_bssgp (local side).

Related: OS#3879
Change-Id: Ibcbaffa94cbdc4296a8a7c372304ac11d50d9559
2021-03-01 19:44:02 +00:00
Pau Espin Pedrol f286fdc87e Bump version: 1.4.0.535-e387-dirty → 1.5.0
Change-Id: I3bc0826c0000be4d76235ed6b5be86d216ea2e4d
2021-02-23 14:03:31 +01:00
Harald Welte fcbf3470b9 CBSP: Fix encoding of warning period
The warning period encoding was wrong, resulting in way too short
warning periods being encoded than intended/specified by the caller.

Change-Id: Idf3cae48a6ab45550d7bbd937bb49a0e1a4e8aed
2021-02-22 10:06:12 +01:00
Harald Welte 48f22b0e87 CBSP: fix encoding/decoding of keep-alive repetition period
Even though the value is only between 0..120s, they didn't encode
it 1:1 in the uint8_t, but 3GPP chose to use the same encoding
as for the warning period (which has a much larger range).

Let's fix this in our implementation.

Before this patch, osmo-cbc wanted to send 30s keep-alive repetition
period, but a spec-compliant receiver actually decoded this as 80s.

Change-Id: I04baa6b6b99b092fa0512b3b6138a363c7f3a13d
2021-02-22 09:58:00 +01:00
Harald Welte 3217d5187f support for stats static userspace probes via systemtap
We currently only have probes for the logging sub-system.

This patch adds two tracepoints for tracing the performance
impact of statistics reporting: stat_start and stat_done.

They can be used to trace the amount of time a libosmocore-using
application spends in reporting/exporting statistics.  This includes
both the CPU time for encoding the statistics, as well as the system
calls for sending them.

Change-Id: I7208c45f6d051505dd2435305c67b4d26c0b1dd2
Related: OS#4311
Related: SYS#4877
2021-02-22 09:58:00 +01:00
Alexander Couzens 2665388e26 gprs_ns2: free_nse: free the SNS fsm early
If the SNS fsm isn't freed early, the SNS code will re-create a NSVC
when calling free_nsvc().
Fixes libasan heap-use-after-free.

Change-Id: If350df1d8d6dcea5715dd23b8bd1d684098cdb1f
2021-02-19 12:57:23 +01:00
Pau Espin 662d10dcda logging: Allow prefixing thread ID to each log line
Related: OS#5032
Change-Id: I38fc93ab0182b4edbd639c7ed0f31ce51964ee18
2021-02-19 11:21:46 +00:00
Alexander Couzens 7bb39e368d gprs_ns2: ensure no duplicate UDP NSVC can be created
Change-Id: I58a95817e2730bbbaa851a43a5b072d1de2db037
2021-02-19 10:41:50 +00:00
Alexander Couzens b2de546a5c gprs_ns2: add value_string for GPRS_NS2_AFF_CAUSE_SNS_NO_ENDPOINTS
Change-Id: I7c9245be248cb8697a370f80021612c14efa5cbb
2021-02-19 10:41:50 +00:00
Alexander Couzens ce646c2371 gprs_ns2_message: tx_status: move all cause dependent code into the switch/case
Change-Id: I8f1e0962c6f5f0c7287990bb7608d0cc9b86dfdb
2021-02-19 10:41:50 +00:00
Alexander Couzens cf1fa6351b gprs_ns2: truncate the NS_STATUS to the MTU
A NS Status can contain the original NS message which might result
in a NS PDU which exceeds the MTU of the NS-VC.
Truncate the original message to the maximum possible.
Based on truncate BSSGP status message.

Related: OS#4889
Change-Id: I35d8f8bf0eae890f4db56423da0b23b638d24311
2021-02-19 10:41:50 +00:00
Alexander Couzens 3de1cb0d72 gprs_ns2_fr: pass MTU changes to the NSE
When the MTU of the frame relay device changes, update the bind
and notify all NSEs.

Related: OS#4889
Change-Id: I946f7655c9526ffd98dabdce219c6a419b71e00c
2021-02-19 10:41:50 +00:00
Alexander Couzens 67725e2920 gprs_ns2_sns: rename fsm events to include RX or REQ prefix
An event which originates by a received PDU is prefixed by RX.
An event which originates by code gets a REQ prefix.

Fixes: OS#5014
Change-Id: Ia8a6378cdca19b086e89058b1cc055f45c0bba7b
2021-02-19 10:41:50 +00:00
Alexander Couzens 6df1160873 gprs_ns2: make gprs_ns2_recv_prim() always take msgb ownership
Have a clear ownership of the msgb to prevent any leaks.

Related: OS#5022
Change-Id: I67e70561e7aae4d4556a02f03a8af6c2daf5ff9c
2021-02-19 10:41:50 +00:00
Alexander Couzens 9e81a32286 gprs_ns2: fix typo in function name ns2_load_sharing_modulo
It's a modulo operation, not modulo*r*.

Change-Id: I0345f2bcac9c57cf7efe8ff27fda4d049e04d5cc
2021-02-19 10:41:50 +00:00
Alexander Couzens d8a8d98053 gprs_ns2: implement a simple load sharing for UDP
Implement the load sharing based on modulo of the LSP. As long the gprs_ns2 doesn't
support the resource distribution function (48.016 § 4.4a) this simple
approach is good enought.

Fixes: OS#4836
Change-Id: I8c2fe5d647694886ac600470fca6ea5d5d210a85
2021-02-19 10:41:50 +00:00
Alexander Couzens bf5d0dbdec gprs_ns2_vty: add optional argument signalling and data weights to `nsvc udp`
A static configured UDP NSVC can have signalling and data weights

Related: SYS#5354
Change-Id: Id363937c64e786c55e3136401ebdb44052415e0f
2021-02-19 10:41:50 +00:00
Alexander Couzens 6b9d232421 gprs_ns2: rework IP-SNS binds
Introduce a `ip-sns-bind BINDID` vty command within a `nse` vty object.
The ip-sns-bind defines the binds which will be used by the dynamic
configuration with IP-SNS.
This is only the first part which only uses the binds when doing a
new SNS configuration.
The outgoing add procedure will be supported in a later patch
when the SNS fsm supports outgoing procedures.

This is a behaviour change of the API and must be synchronized with
the osmo-pcu. Otherwise SNS won't work with osmo-pcu.

Related: SYS#5354
Change-Id: I9ab8092bf286e7d90e92f5702a5404425e959c84
2021-02-19 10:41:50 +00:00
Pau Espin Pedrol d7a209bce9 gsm: Introduce API osmo_gsm48_rest_octets_si13_decode
Related: SYS#5358
Change-Id: I74fb0a3afc1ac4aadbfc609b882d929401f790eb
2021-02-18 00:54:33 +00:00
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
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
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
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 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
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 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