Commit Graph

68 Commits

Author SHA1 Message Date
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
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
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
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 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
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
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 c962a2efc3 gprs_ns2: Add comments explaining the nsvc->sns_only field
Change-Id: I16009a1b03d8027de2be56b7d5013b755c9550fd
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 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
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 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
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 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 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 04647e169e cosmetic: ssn: some more comments
Change-Id: I87f76ab19d834d96a268b0d47b9dfe2424151d63
2021-03-04 09:09:13 +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 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
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 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
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
Alexander Couzens 138b96f21c gprs_ns2: refactor: ensure all enums have GPRS_NS2_
All public enum should have the prefix GPRS_NS2_.

API change which must be synchronized with osmo-pcu,
osmo-gbproxy, osmo-sgsn.

Change-Id: I548ff12f7277cbb7e1a630a3dc02b738ce89be72
2021-01-28 11:56:37 +00:00
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
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 1262c4f18e ns2: Properly indent VTY output
If multiple objects are printed in the VTY, only the first line of each
object should be on the first character of the line, all others should
be indented.  With  this patch the "snow ns entities" output becomes
much more readable:

OsmoGbProxy> show ns entities
NSEI 00102: UDP, DEAD
 FSM Instance Name: 'GPRS-NS2-SNS-BSS(NSE00102-SNS)[0x6120000018a0]', ID: 'NSE00102-SNS'
  Log-Level: 'DEBUG', State: 'SIZE'
  Timer: 1
 Maximum number of remote  NS-VCs: 8, IPv4 Endpoints: 4, IPv6 Endpoints: 0
 NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[127.0.0.1]:23000<>[127.0.0.11]:8888
NSEI 00101: UDP, DEAD
 FSM Instance Name: 'GPRS-NS2-SNS-BSS(NSE00101-SNS)[0x6120000015a0]', ID: 'NSE00101-SNS'
  Log-Level: 'DEBUG', State: 'SIZE'
  Timer: 1
 Maximum number of remote  NS-VCs: 8, IPv4 Endpoints: 4, IPv6 Endpoints: 0
 NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[127.0.0.1]:23000<>[127.0.0.10]:7777

Change-Id: Id1b4c80a6caef410076a68b4301adaa01ba7e57a
2021-01-20 14:59:03 +00:00
Alexander Couzens 7a7b20b770 gprs_ns2_sns: clear local and remote entries when SNS failed
The local and remote entries should be cleared on SNS Size.
Further it can be cleared when SNS failed (e.g. all NSVC become dead)
so VTY doesn't show old entries before entering SNS Size.

Related: OS#4949
Change-Id: Ie4db81acdd5f8ddf1a1f5dc7645d1144545d9c73
2021-01-18 10:47:33 +01:00
Daniel Willmann cf8371ad4d Refactor ns2_nsvc_create_ip*
Move code common in ipv4/6 into a separate function and call that
function.

Change-Id: I076d53bee2e67e1cb3ad6ee5cd05c63ebe3359fb
Related: OS#4948
2021-01-17 08:32:51 +01:00
Daniel Willmann 967e2c1868 NS2: Fix bind selection of SNS NSVCs
The SNS code ignored the link type of the bind and just bound to every
bind it could find. This resulted in a segfault when an SNS NSVC tries
to send its UDP messages though frame relay.

Fixes: OS#4948
Change-Id: Ibb832a39876362d094cce635192f7b4f84dc2b10
2021-01-14 18:09:44 +00:00
Vadim Yanitskiy d8b7003df7 gprs_ns2_sns: always check rc of osmo_sockaddr_str_from_sockaddr()
Writing a configuration that will be rejected by the VTY parser
is not the best solution, but still better than printing values
from previous iterations or the stack garbage.  In any case,
this is unlikely to happen, just making Coverity happy.

Change-Id: I26644fe544c82c90767ec1a9709918474bd1be53
Fixes: CID#215852
2021-01-05 15:21:39 +00:00
Alexander Couzens a367d0863f gprs_ns2: sns: add log message when size/config retries exhausted
Change-Id: I5f7c04b364807418f5ba22132fc889b46d66aed0
2020-12-23 06:32:29 +01:00
Alexander Couzens cc65a25818 gprs_ns2: sns: don't send duplicated packets on retries
When all retries are exhausted it should change the state and not
send out a packet.

Change-Id: Ie33df4a12298882bc46633200486dc34c6e34d8e
2020-12-23 06:32:29 +01:00
Alexander Couzens 3ad73368be gprs_ns2: sns: correct log message when no nsvcs available
The log message should only shown if a reselection will be triggered.

Change-Id: I96b280a927aba6ac09ce88aedfcf469243c4dffe
2020-12-23 06:32:29 +01:00
Alexander Couzens 412bc3494d gprs_ns2: add new vty2
Change-Id: I163279cf57e84198dc8c53e1c109f5a9474670e9
2020-12-22 16:36:19 +01: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 81ae0aa67f gprs_ns2_sns: use different binds for the initial connection
In case the first bind is not working the SNS would never build a
succesful connection to the SGSN. Iterate over all binds by
using an offset.
Instead of tracking the binds use an offset instead of a direct pointer.
This might result in skipping the order of the next bind.

Change-Id: I4a0a0608dac6ad8b5769ada2a14ca23f61eb0bcb
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