Commit Graph

107 Commits

Author SHA1 Message Date
Daniel Willmann 3236fdffd6 ns2: Add VTY option to change the max write queue size for UDP
Ensure that existing binds are updated as well.
In some cases the default max length of the osmo_io txqueue could be too
small. Set it to 128 by default and add a VTY option to change it for
an NSI (program-wide).

Change-Id: I993b87fd6b83b3981f5e293f70b931075afec715
Related: SYS#6550
2023-08-30 09:18:35 +00:00
Daniel Willmann 334cf8759f ns2: Avoid use-after-free when SGSN-side non-persistent SNS-NSE fails
alive_timeout_handler() changes the state to RECOVERING which calls
ns2_st_alive_onenter()->ns2_nse_notify_unblocked(unblocked=false)->
ns2_sns_notify_alive(unblocked=false)

When all (signalling) NSVCs have failed and gss->role is SGSN and not
persistent sns_failed() calls gprs_ns2_free_nse() which talloc_free()s
the nse before returning.

The next line in ns2_nse_notify_unblocked() tries to read nse->alive which then causes the
use-after-free.

Change-Id: I0486a77fd3e21fd3904bd19e4e0225ffbf654935
Related: OS#5302
2021-11-11 16:50:01 +01:00
Alexander Couzens d802f9ae6e ns2: message: allow to pass a foreign NSVCI to STATUS PDU
To answer correct on a BLOCK PDU with a different NSVCI, the
STATUS PDU needs also a NSVCI parameter.

Change-Id: I373eb48697097cdfa45748a091c11f7b3f0345fa
2021-10-08 05:43:46 +00:00
Alexander Couzens ca5ce0d849 ns2: nsvc: add a uptime/downtime to track the last state change
To show adminstrator the last state change of a nsvc add a timestamp and
show it on the vty

> show ns nsei 1234
NSEI 01234: UDP, DEAD since 0d 0h 1m 42s
[...]
  4 NS-VC:
   UNBLOCKED DYNAMIC sig_weight=1 data_weight=1 udp)[127.0.0.1]:22000<>[127.0.0.1]:23001 ALIVE since 0d 0h 0m 1s
   UNBLOCKED DYNAMIC sig_weight=2 data_weight=2 udp)[127.0.0.1]:22000<>[127.0.0.1]:23000 ALIVE since 0d 0h 0m 1s
   UNBLOCKED DYNAMIC sig_weight=2 data_weight=2 udp)[127.0.0.1]:22001<>[127.0.0.1]:23000 ALIVE since 0d 0h 0m 1s
   UNBLOCKED DYNAMIC sig_weight=1 data_weight=1 udp)[127.0.0.1]:22001<>[127.0.0.1]:23001 ALIVE since 0d 0h 0m 1s

Related: OS#5028
Change-Id: Ie3a039a209869295afa5feda39297cee81fedf22
2021-09-23 13:12:34 +02:00
Alexander Couzens 2c64c257c8 ns2: nse: add a uptime/downtime to track the last state change
To show adminstrator the last state change of a nse add a timestamp and
show it on the vty

> show ns nse 1234

NSEI 01234: UDP, ALIVE since 0d 0h 0m 16s
 FSM Instance Name: 'GPRS-NS2-SNS-SGSN(NSE01234-SNS)[0x6120000012a0]', ID: 'NSE01234-SNS'
  Log-Level: 'DEBUG', State: 'CONFIGURED'
  Timer: 4
 Maximum number of remote  NS-VCs: 8, IPv4 Endpoints: 2, IPv6 Endpoints: 0
 [...]

Related: OS#5028
Change-Id: I8143080a3c5c9a55d37dfad44ba2ac6561daa216
2021-09-23 13:12:34 +02:00
Alexander Couzens 616a949456 gprs_ns2: calculate the nse->*_sums before notifing the sns fsm
The sns fsm needs these information to determine if there is a signalling nsvc left

Change-Id: I7b115921780bd1ae895d8b9d0d4aec3e1cbaaf58
2021-09-04 01:26:28 +02:00
Alexander Couzens 1f3193d344 gprs_ns2_sns: implement local change weight procedure
When changing the bind ip-sns weight, initiate a
SNS CHANGE WEIGHT procedure to inform the other side.

Related: OS#5036
Change-Id: Icec4dabb46bc198f68f91bfe09ba279fbe68d454
2021-09-04 00:00:48 +02:00
Alexander Couzens f074659520 gprs_ns2: don't use llist_for_each when freeing an element
The problem are recursive execution because a free generates an event which could
allow the use to free a nsvcs while the llist_for_each() is still running.

Change-Id: I902557fb6e56e6588728a46e43a9cbe3215d5c68
2021-09-04 00:00:48 +02:00
Alexander Couzens 4bfcce6c54 gprs_ns2: gprs_ns2_free_bind() should remove itself before removing nsvcs
When removing NSVCs before removing the bind from the SNS list, the removing NSVCs could
trigger a creation of a new NSVC on the same bind ending in a
while(true) loop.

Change-Id: I6f497348f75fb479427d8a4c23313e33fbc62036
2021-09-04 00:00:48 +02:00
Alexander Couzens 83f06cea0a gprs_ns2: use an event to free the nsvscs when using SNS
Otherwise there could be recursive loop when free'ing NSVCs which
in the end create an event which the SNS want to free the NSVCs a
second time

Change-Id: Ie99ba5fe8a84519fe8a8c0abdf875606715ab7f6
2021-09-04 00:00:48 +02:00
Alexander Couzens 41589a3e7a gprs_ns2: add recursive anchor to protect against double free
When free'ing a NSE/NSVC/BIND ensure there can't be a double
free by using a free anchor in the struct.

Recursive free's can happen when the NS user reacts on an event
(e.g. GPRS_NS2_AFF_CAUSE_VC_FAILURE) and calls the free().
Or when the user free's a NSVC when the NSE uses SNS as configuration,
the fsm tries to free it again.

Change-Id: If9823aadaa936e136aa43e88cee925ddd5974841
2021-08-13 09:55:51 +00:00
Daniel Willmann efa64f9429 Aggregate NSVC stats inside the NSE
Change-Id: Ifa3c85ec52bda14596e9d7a8705baa1fd4ee2010
Related: OS#4998
2021-07-09 20:35:00 +02:00
Alexander Couzens 31cf166511 gprs_ns2: correct mtu value in the log line
The log line should describe what's reported towards the NS user
and not the NSE MTU itself

Related: OS#5192
Change-Id: I3f5445a1ba8c89c4023ff48be15a80569a128528
2021-07-02 17:38:12 +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
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
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
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
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
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
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
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
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 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 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 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 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
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 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
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 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 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 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
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 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 265a5ebac8 gprs_ns2: prevent division by zero in load_sharing
Check if the NSE is alive before passing UNITDATA to the load sharing.

Change-Id: I0e2a59bec9b72f74eb64510a2e1ad60486694a55
Fixes: OS#4996
2021-02-02 11:39:30 +00:00
Harald Welte 8669043fe9 ns2: Print NS-STATUS.ind primitives to the log
Log the NS-STATUS primitives from within the library, so we don't have
to keep related code in each and every application.

Change-Id: I368883acfc8ea76529befcd429bf8f2445a60a94
2021-02-01 09:39:29 +01:00
Harald Welte 76346079e8 ns2: Introduce a per-bind stat_item group with backlog length
The backlog length indicates the instantaneous length of the backlog.

Change-Id: I1c55b4619b1221d7e607ace58649323407faf86b
2021-02-01 09:39:29 +01:00
Harald Welte 97ccbf71b3 ns2: Rename nsi->rate_ctr_idx to nsi->nsvc_rate_ctr_idx
We will soon get another of those indexes.

Change-Id: I68a2ef3b48097f524831dd04821824b21d6d1e18
2021-02-01 09:39:29 +01:00
Harald Welte bdfb8b9104 ns2: Memory allocation failures are ENOMEM, not ENOSPC
ENOSPC is used with non-volatile (disk) storage, while ENOMEM is
customarily used for RAM allocation failures.

Change-Id: Ia4c16d8278dc30c7cc69169b18428cda5272738d
2021-02-01 09:39:29 +01:00
Harald Welte c3aa8f903a ns2: Move to one common/shared ns2_bind_alloc()
Avoid code duplication between three different drivers by sharing
the "core" of the bind initialization in a new, shared ns2_bind_alloc().

Change-Id: I535fc68e94fcd695de827dd922706adc1c5a2cb7
2021-02-01 09:39:29 +01:00
Harald Welte b40bf8ba3b ns2: Add a rate_ctr for each NS-UNBLOCK
We have one for BLOCK, so let's also add one for UNBLOCK.

Change-Id: I693109b7bc4d72b6803b40aae15327389aa37c69
2021-01-31 12:34:36 +01:00
Harald Welte f22ae5af5f ns2: count number of dropped packets / bytes on transmit
Differentiate between successfully transmitted packets/bytes,
and pacets/bytes that were dropped (i.e. overflow of net-device)

OsmoNSdummy# show ns nsvc 1001 stats
 NSVCI 01001: UNBLOCKED PERSIST data_weight=1 sig_weight=1 fr)netif: hdlc1 dlci: 1001
  NSVC Peer Statistics:
   Packets at NS Level  ( In):       36 (0/s 8/m 32/h 0/d)
   Packets at NS Level  (Out):    23344 (170/s 20556/m 13119/h 0/d)
   Dropped Packets      (Out):    30692 (230/s 27056/m 17221/h 0/d)
   Bytes at NS Level    ( In):      262 (0/s 24/m 250/h 0/d)
   Bytes at NS Level    (Out): 32741312 (238680/s 28849400/m 18391024/h 0/d)
   Dropped Bytes        (Out): 43014628 (322920/s 37986624/m 24101344/h 0/d)

Change-Id: If21906ff5379038f7be10cf48c68d1f756dd7c1e
2021-01-31 12:34:36 +01:00
Harald Welte e5f55f73bd ns2: Increment Rx and Tx byte / packet counters
Change-Id: If5e93f69cddbc8962cbbae38c07b504dd9b1ecd1
2021-01-31 12:34:36 +01:00
Harald Welte 3d5eaee726 ns2: Use named array initializers to avoid mistakes
It's always a bad idea to have an array of descriptions that's indexed
by an enum, without using named initializers.  It's too easy to get
inconsistencies.

Change-Id: Id0ebd2a202a465ca0298f4245f1fb5c495235fc8
2021-01-31 12:34:36 +01:00
Alexander Couzens 2e1a3a982a gprs_ns2: remove api call gprs_ns2_dynamic_create_nse
The call was only introduced as workaround for the first implementation
of vty. There is no need for this anymore. The configuration can
just add "accept-ipaccess" to the bind to allow creation of dynamic
ipaccess NSE.

Change-Id: Ie924ead6da17657f3da334068c8ada82c8845495
2021-01-28 13:54:32 +01: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