Commit Graph

107 Commits

Author SHA1 Message Date
Alexander Couzens 8dfc24cb47 gprs_ns2: drop prefix of all internal exposed function
All functions which are exposed by gprs_ns2_internal.h should not contain
the public prefix gprs_. Internal function should only contain ns2_ prefix.

Change-Id: Icecc5a918902cd10efac72bbac20780d39aab272
2021-01-25 16:09:23 +01:00
Alexander Couzens ba5a9927b6 gprs_ns2: drop GPRS_ prefix of gprs_ns2_cs
gprs_ns2_cs is a privat enum while GPRS_ should only used
for public enums.

Change-Id: I79be92ca716366c2e07ea061c08d95bea817a8c7
2021-01-25 16:03:23 +01:00
Alexander Couzens ba6345310f gprs_ns2: always pass a tp to gprs_ns2_vc_rx
In preparation of checking the NSEI/NSVCI in ns2_vc_rx. It
makes the function less error prone as the *tp is always defined.

Change-Id: I3cd6ed20cdc1390075669e1d0101154c51f3997f
2021-01-25 15:34:39 +01:00
Harald Welte f294974e05 ns2: Unify logging context via log macros
Let's avoid open-coding the printing of log context and rather rely on
log macros to prefix each log line with the relevant context.  This
helps log readability, log post processing whether by grep or more
sophisticated tools.

Change-Id: I946c0e77686d91efc5afb62031e1ac1033a9a586
2021-01-20 16:42:33 +00:00
Harald Welte 3221f878ee ns2: delay NS_AFF_CAUSE_RECOVERY until NS-VC for data + sig are unblocked
Right now we end up in situations where only a NS-VC for data (BVCI != 0)
becomes unblocked, but the BSSGP and/or user application code is
notified that the NSE has recovered.

In the case of osmo-gbproxy, this will trigger a BVC-RESET on the
BVCI=0, but that obviously only works if the sig_weight > 0...

Closes: OS#4956
Change-Id: I933ee3969c052394d61ec6cf8c7c21d17957d9ab
2021-01-18 16:11:33 +01:00
Harald Welte 603f404e41 gprs_ns2: Give NS-VC FSMs a proper name/identifier
Log output without a proper identifier is mostly useless.

Change-Id: Id9d5b0684584d03685900c6298fe70246793de14
Closes: OS#4876
2021-01-18 14:07:48 +00:00
Alexander Couzens d1cd650dd8 gprs_ns2: flag then NSE as dead in nse_free()
The transfer cap call in ns2_prim_status_ind() asserts if
NSE is in an invalid state (nse is either alive or has NSVCS).

Change-Id: I535b3e5dd7240d19dd685652173775b250f5cc2d
2021-01-18 10:47:47 +01:00
Alexander Couzens 05ac4e52b9 gprs_ns2: check if persistent nsei or nsvc exists when creating dynamic NSE
When receiving a NS Reset over an unknown NSVC the NS code would create
a dynamic NSE. If the NSEI or NSVCI is already configured to a
persistant NSE/NSVC the packet should be ignored.

Related: SYS#5208
Change-Id: I855911e7d364f2e5b08ea05857747aa63fcf1cd3
2021-01-17 16:11:36 +01:00
Daniel Willmann bb8990582f ns2: Add sanity check
Prevent memory corruption or segfaults by asserting that NSE and bind
link layer match. A mismatch should never happen and might cause the
bind to access invalid memory when sending because nsvc->priv doesn't
match what it expects.

Change-Id: I7ca4cd1c5dac8b5e44ffc4825b9373b2d04911ab
Related: OS#4948
2021-01-16 19:47:32 +01:00
Alexander Couzens 1c8785dd81 gprs_ns2: set transfer cap in NS Status primitive
Related: SYS#5153 OS#4835
Change-Id: Ia1046db9e0d50855bff9de670b612ffc57af9995
2021-01-05 14:24:03 +00:00
Alexander Couzens 8a2a1a4959 gprs_ns2: rework frame relay load distribution function
For frame relay the traffic will be even distributed across
all NS-VCs. Do not differentiate between signalling and
data traffic.

Change-Id: I6c060941db335a7a6a555ac8d1b9269fa8fb2023
2020-12-26 18:43:08 +01:00
Alexander Couzens 3c22f91bad gprs_ns2: don't pass the return code of reject_status_msg
When reject_stats_msg() fails the code can't do anything about it.
Stick to the original failure code and log it

Change-Id: I105363957e59c41a68835b7a9830c048dba73e93
2020-12-20 15:34:53 +00:00
Alexander Couzens 12e5e6bd78 gprs_ns2: improve handling of TLV errors on new nsvcs
The specification says the PDU should be ignored if the PDU type is
unknown.

Change-Id: I2992d06b37ed122b7ff315d4852e86acc936800b
2020-12-20 15:34:49 +00:00
Alexander Couzens bac5b0153b gprs_ns2: on ns2_create_vc parse the tlv before using it
reject_status_msg require a parsed tlv. Otherwise an
uninitialized tlv is passed.

Change-Id: I82cab518966b8b49c3522ff5f7b6f82d1027a526
2020-12-15 11:56:29 +00:00
Alexander Couzens 90ee963570 gprs_ns2_sns: introduce SNS Size/Config retries
According to 3GPP Size and Config procedure can
have retries in case the timeout of the procedure runs out.

Change-Id: I00e9023a6e7adc6ad48f4016fcaef189ac8b353e
2020-12-15 11:46:45 +00:00
Alexander Couzens e769f5226b gprs_ns2_sns: rework IP-SNS initial remote
The IP-SNS requires at least one initial remote address of the SGSN.
However it should be multiple initial remote address instead of a single
in case the interface might fail.
Rework the SNS to support multiple initial remote addresses.

Change-Id: I71cdbfb53e361e6112fed5e2712236d797ef3ab2
2020-12-15 11:46:45 +00:00
Alexander Couzens 4755879fbe gprs_ns2: add gprs_ns2_free_nsvcs() to free all NS-VC of a NSE
Change-Id: I909443b540dbf75146297f1d7f94940690be6c0d
2020-12-15 11:46:45 +00:00
Alexander Couzens aaa55a663e gprs_ns2: add member name to bind
Every bind will have a unique name. Add a name argument
to all bind creating functions and require them to be unique.

This is an API break but there wasn't yet a release with NS2.

Change-Id: I8f1d66b7b3b12da12db8b5e6bd08c1beff085b3e
2020-12-15 11:46:45 +00:00
Alexander Couzens 93ad499832 gprs_ns2: move allocation of the SNS fsm into create_nse
The allocation of the SNS fsm can be done in create_nse
because the dialect is now known at that time.

Change-Id: I64e1f3dcc63d38e65bb486c9ac08d4032b7ad222
2020-12-15 11:46:45 +00:00
Alexander Couzens d923cff170 gprs_ns2: introduce NS dialects
A NS dialect describes how the NS Entity interacts with
different virtual circuits. E.g. ipaccess use reset/block on udp
and is a dynamic connection.
A single NS Entity can only support one dialect. This can be later
used to protect a NS Entity against dynamic NS virtual circuits of a
different type.

It further allows a bind to support multiple dialects at the same time.

Change-Id: Ia118bb6f994845d84db09de7a94856f5ca573404
2020-12-15 11:46:45 +00:00
Harald Welte 798efea27e gprs_ns2: Use TLVP_PRES_LEN instead of TLVP_PRESENT
With TLVP_PRESENT we only check if a given TLV/IE is present,
but don't verify that it's length matches our expectation.  This can
lead to out-of-bounds reads, so let's always use TLVP_PRES_LEN.

Change-Id: I4c438bc82ea6a48243db568f96a234adf784dc0b
2020-12-04 18:20:15 +00:00
Daniel Willmann 751977be6f ns2: Add log filtering by NSE/NSEI, fix NSVC filter on receive
NSVC filtering was only implemented on sending messages, this also adds
log_set_context() calls to  ns2_recv_vc()
Filtering by NSE is implemented similar to NSVC.

Change-Id: I63c0e85f82f5d08c5a6f535da94b8648498439d2
Related: SYS#5232
2020-12-03 15:14:18 +01:00
Alexander Couzens d87a2f14e6 gprs_ns2: use switch() case instead of multiple if in ns2_create_vc()
Improve readibilty and allows it to extend for future ns2 vty changes

Change-Id: I8bd9c75fb04169a166b7a3f5e13a5902250cfd0e
2020-12-03 06:15:09 +01:00
Alexander Couzens 036bf140c9 gprs_ns2: fix typo in comment
Change-Id: Ic0653ce7de8d2d64bd7cf10e148b07da8cbeb0a2
2020-12-03 06:15:09 +01:00
Harald Welte 6188e004d2 gprs_ns2: Don't return an empty string in case of unknown LL
Change-Id: Id2c689ab83ada18a5cb6d70ded31aacaa701f99c
2020-12-01 18:01:43 +01:00
Harald Welte 37322bc714 gprs-ns2: Fix stringification of NS/FR NSVCI
Before this commit, gprs_ns2_ll_str_buf() would always return an empty
string.

Change-Id: I6ec07f58fa5cbb7ec4be967b2c72ae75935e4f75
2020-12-01 18:01:43 +01:00
Harald Welte a24e7ee3bd gprs_ns2: Introduce gprs_ns2_lltype_str() for link layer name
Change-Id: I4b257c09d9d3c97d6da04240c7a74a95c7c93675
2020-11-30 13:30:14 +00:00
Alexander Couzens 10e991b224 ns2: remove obsolete type GPRS_NS2_LL_E1
There is already frame relay type GRPS_NS2_LL_FR
to support frame relay.

Change-Id: Iabb4608d91ccb32a07cad67519166dabfba76612
2020-11-24 03:53:22 +01:00
Alexander Couzens aac9016570 ns2: move link layer type into NSE
Even it was in theory possible to mix NS-VC ll types within
a NSE. This is an unrealistic configuration.
Further more to select the correct load sharing mechanism
the NSE must know the correct link layer.

Change-Id: I18dfd40a2429cd61b7c4a3dad5f226c64296f7d8
2020-11-24 03:53:22 +01:00
Alexander Couzens 24a14ac80c ns2: move LL into public api
Also fix prefix. GPRS_NS -> GPRS_NS2.
In preparation to move LL into upper layer.

Change-Id: I3b5e0d51ce69b095095e5160ca0cf0d4534db1b8
2020-11-24 03:53:22 +01:00
Alexander Couzens fc3dd1fb14 ns2: implement link sharing selector
Change-Id: I212fa1a65e8c16cf1e525d1962d5689446c7e49e
2020-11-24 03:53:22 +01:00
Alexander Couzens 841817ec52 ns2: add support for frame relay
Add support for frame relay over dahdi hdlc device.
It's supporting lmi by q933 and supports both
SGSN and BSS.

Change-Id: Id3b49f93d33c271f77cd9c9db03cde6b727a4d30
2020-11-24 03:53:22 +01:00
Alexander Couzens 0ab028c84e ns2: fixup gprs_ns2_prim_strs
The gprs_ns2_prim_strs was merged to early. The renaming
in the last gerrit patchset wasn't done correct.

Change-Id: Ie8e1e003d70af48f2d647b2c2701d4fc0f17e307
2020-11-09 11:07:17 +00:00
Daniel Willmann 15c09a81e9 ns2: Send NSVC representation in NS_AFF_CAUSE_VC_* status indication
NS_AFF_CAUSE_VC_* failure and recovery should indicate the NSVC in
question. Use the string representation reported by gprs_ns2_ll_str()
for that.

NS_AFF_CAUSE_VC_RECOVERY was never sent so do that on unblock as well.

Change-Id: Iad6f0dc4565a46868cbbe17c361dcd473006c83d
Related: SYS#4998
2020-11-06 11:41:16 +01:00
Daniel Willmann f128654c7f ns2: Add gprs_ns2_nsvc_state_name() to get the current state of a VC
Change-Id: I4c4c5b9142d7240ed452218e263ba12e2b70d1a0
Related: SYS#4998
2020-11-06 10:23:44 +00:00
Alexander Couzens cce8828238 libosmocore: change the memory management of NS2
Until now NS2 always free'd it's own memory. Even when the msg
was sent as primitive to the upper layer.
Change the memory ownership when sending a primitive to the upper layer.
The upper layer has to free the msg buffer.

Merge together with: I180433735bfbb3375c41318d7a7709d5845199ba (osmo-pcu)

Change-Id: Id844d7acbcab102a7dc472d608a5e97a748ecb43
2020-11-03 22:37:45 +00:00
Alexander Couzens b3b837c5e8 gprs_ns2: convert gprs_ns2_cause_str into an static inline
Be consistent with other implementation of get_value_string() in
libosomocore.

Change-Id: Ic79757df8683e0461c04f7ef9279e4fe645eb821
2020-10-27 14:49:03 +00:00
Alexander Couzens 2498f1db9d ns2: add value strings for ns2_affecting_cause_prim_str & ns2_prim_str
Change-Id: Ibf610fbd929dddc4a4e235152447caff522d4eb2
2020-10-27 15:24:47 +01:00
Alexander Couzens 8ebc1acbaa gprs_ns2: Partial revert 48f63867 allow to create NS_ALIVE NSVC
NS_ALIVE can't create new NS-VC. Those NS-VC can be only created
by SNS or by vty.
Also fixes a crash because the TLV parser tried to retrieve NSEI TLV
which doesn't exist on NS_ALIVE PDUs.

Related: OS#4792
Change-Id: I16b9d7b2eb7544a83ce871d894887c4b30605b34
2020-10-12 14:15:50 +00:00
Alexander Couzens 6cb5d5f2e0 gprs_ns2: add gprs_ns2_nse_foreach_nsvc()
Allow to loop over all NSVC within a NSE via a callback

Change-Id: I5a2bb95d05d06d909347e2fb084a446ead888cb3
2020-10-12 15:54:21 +02:00
Alexander Couzens c4229a458c gprs_ns2: rename gprs_ns2_ip_vc_sockaddr -> gprs_ns2_ip_vc_remote
It's more clear which part of the address is returned.
In preparation to add a gprs_ns2_ip_vc_local.

Change-Id: I6110ff573362961c713a990da7ef3f3dbedf6c57
2020-10-12 15:54:21 +02:00
Alexander Couzens 9a4cf275b2 gprs_ns2: const the return value of gprs_ns2_ip_vc_sockaddr / gprs_ns2_ip_bind_sockaddr
The sockaddr should not be changed.
free and create the bind/nsvc if the address should be changed.

Change-Id: I371ac2361b569e36722b02fc9cd82ec8da2fa9e3
2020-10-12 13:08:42 +00:00
Alexander Couzens 4b6c8afcb2 gprs_ns2: add gprs_ns2_free_nses() to free all NS-E
Allow users to clean up most of the state (e.g. the PCU).

Change-Id: Ia00753a64b7622a0864341f51ea49b6963543755
2020-10-12 13:08:42 +00:00
Alexander Couzens 896fcd5c80 gprs_ns2: add gprs_ns2_free_binds() to free all binds
Allow users to clean up all binds (e.g. the PCU).

Change-Id: Ic8f6f8aca10da23a18fab8870be7806065a34b47
2020-10-12 13:08:42 +00:00
Alexander Couzens 05e7f7dd99 gprs_ns2: add gprs_ns2_nse_nsei() to get the nsei of a nse
Change-Id: I5f67e6a9bf4cb322bd169061fee0a528012ed54d
2020-10-12 13:08:42 +00:00
Alexander Couzens bb0a53ba40 gprs_ns2: fix empty prefix in TLV Parse error
Those messages were printed without any prefix because
LOGPC was used. LOGPC means continue a log line.
This must happened while copying this part of code over
from ns1 where has been a LOGP in this function.

Related: OS#4792
Change-Id: I2672ea0e34d19ea6172cb3458b8ff98d9700b2d0
2020-10-12 10:54:46 +00:00
Alexander Couzens 3531504d52 gprs_ns2: gprs_ns2_free(): add missing talloc_free
It clean up all the space except the nsi itself.

Change-Id: Ia3fbe5d679d0af75b2b0db020f1eb082d629cf50
2020-10-10 03:28:17 +02:00
Vadim Yanitskiy a07f25e3ba gprs_ns2: make struct osmo_sockaddr pointers const
Using the 'const' qualifier allows the compiler to spot some
programming errors and further optimize the code.

Change-Id: I0df6a00ac1830bd64a10b9336b827e113fa772bb
2020-10-09 15:24:09 +00:00
Harald Welte 36be9d890e gprs_ns2: Fix parsing of SNS-{ADD,DEL,CHANGE_WEIGHT}
Change-Id: I94c12986f8255e4373b13b1a8fae3df08004ad96
Related: OS#4791
2020-10-09 16:12:01 +02:00
Alexander Couzens da0a285612 ns2: status ind: add additional flags (first and persistent)
Both flags are required to allow the NS user to sent BVC RESET for persistent NSE.
On persistent NSE with persistent NS alive configuration (no RESET/UNBLOCK/BLOCK) the
PCU can't detect if the SGSN has restartet or crashed.

Change-Id: Iaad7b53d44338e5dd81dc2202f23bdcb715af804
2020-10-03 07:19:48 +00:00
Alexander Couzens bf95f0fb2e ns2: refactor ns2_prim_status_ind()
Replace parameters nsi + nsei with a single nse pointer.

Change-Id: I35f6381110ba7ba1e013f21120e971362bdff55b
2020-10-03 07:17:54 +00:00
Alexander Couzens ffd49d0757 ns2: ns2_recv_vc: remove unused parameter nsi
Change-Id: I0dbc079e83d37de01a4260442363ed5fdcd51d28
2020-09-25 09:45:24 +00:00
Alexander Couzens 38b19e88bb ns2: refactor nsvc_by_ functions
gprs_ns2_nsvc_by_sockaddr_nsei is doing the lookup within a NSE.
gprs_ns2_nsvc_by_sockaddr_bind is doing the lookup within a bind.
Make both function look similiar and take similiar arguments.

Change-Id: Ia499fc279013668abe7348e578a0768f7d16faf9
2020-09-25 09:45:24 +00:00
Harald Welte 92ad029e1a ns2: Use NULL and not '0' when returning a NULL-Pointer
Change-Id: I9458e6dcf8133fbcfbc89437e58aad049a6d432b
2020-09-18 23:14:36 +02:00
Harald Welte 5bef2cc4bd ns2: Improve/extend doxygen comments for new ns2 implementation
I was reading through the code and noticed many functions not
documented yet, or with incomplete documentation. Change that.

Change-Id: I85a2419604a9fd9ff3c4828a7463e222652f77bf
2020-09-18 23:14:36 +02:00
Alexander Couzens 48f6386717 libgb/ns: allow to create NS_ALIVE NSVC
Change-Id: I562c3ac4a8baaa2c97852bbd6a5a10ba1f144004
2020-09-15 13:55:24 +02:00
Alexander Couzens 6a161497cf Gb: add a second NS implementation
Reimplement NS with FSM.

Change-Id: I3525beef205588dfab9d3880a34115f1a2676e48
2020-09-15 11:54:41 +00:00