Commit Graph

44 Commits

Author SHA1 Message Date
Harald Welte 2cc1d4d7df frame_relay: Add status call-backs for link + DLC status changes
Change-Id: Iec19db4e48642c3fcb0aa11fa7787b8323fd0e5a
Related: Os#4999
2021-02-02 11:37:48 +00: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 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 5e0ef6f958 ns2: Properly report packet drops in FR code
When the FR code decides to drop a packet (ENOBUFS from the AF_PACKET
socket for non-signaling packet), let's report that back via the
frame_relay code into the generic NS2 code.

This way the generic NS2 code always knows if a packet was actually
successfully  transmitted, or if it was dropped for some reason.

Change-Id: I4bb517fd04af69dbe6da628b132d57994ab3e5a4
2021-01-31 12:34:36 +01:00
Harald Welte d06128d17d ns2: Work around AF_PACKET socket ENOBUFS problems
AF_PACKET sockets cannot be written-to using select(), as they
will always return "writable" but then still fail with ENOBUFS.

This also means that we cannot use osmo_wqueue() as it assumes
that a writable socket can actually be written to.

As there's no way to figure out when exactly we can again perform
a successful write, we have no other option but to start a timer
and re-try at a later time.

We will scale that timer based on the estimated duration of transmission
for the just-failed PDU on the line rate of a 31TS E1 Line.

Furthermore, with this patch, we stop queueing anything but signaling
traffic (NS-BVCI=0) or Q.933 LMI.  User data (NS-BVCI != 0) will
instead be dropped in order to avoid buffer-bloat.

Change-Id: I4f79a246236c94175ceffa5f3f556c8931c6bc62
Closes: OS#4995
2021-01-31 12:34:36 +01:00
Harald Welte f0073d7045 ns2: Log ERROR if we cannot transmit a packet due to ENOBUFS
Related: OS#4995
Change-Id: I2ba64e96c60e23d2e6c8ecdcab0b52b3833f092c
2021-01-30 20:09:35 +01:00
Harald Welte 335c550fab ns2: Use proper return value from write_queue callback function
write_queue expects a -errno value on error, not '-1'.

Change-Id: I93c858facfe7e1c533df8dccc4502a574686bc8a
Related: OS#4995
2021-01-30 17:59:51 +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
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
Alexander Couzens ea37724b3c gprs_ns2: allow to use free_vc() with NULL
Usually talloc_free() and other free functions in osmocom allows
to be called with NULL which is then ignored.

Change-Id: If7b0c6916a29d4611d0a40c388414076eb83e6b5
2021-01-19 19:33:41 +01:00
Alexander Couzens 55bc86931e gprs_ns2: add assert on most bind calls
Add a OSMO_ASSERT to all bind calls which doesn't
check if the bind is from the expected type.
The only exception is rx and tx functions (hot path).

Change-Id: Ia4f8932263c60618c7f0dfc32d50ba5a8d57602b
2021-01-19 19:33:41 +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
Harald Welte 509047ba5d gprs_ns2_fr: reduce duplication between gprs_ns2_fr_connect / connect2
gprs_sn2_fr_connect2() is the same as gprs_ns2_fr_connect() with
the lookup-and-create-on-demand of the NSE first.

Rather than copy+paste, they should simply invoke each other.

Change-Id: If835bf138f213e7f58205018e7efe3ecb772c624
2021-01-18 14:07:48 +00:00
Vadim Yanitskiy 222e844718 gprs_ns2_fr: fix resource leaks due to early return in set_ifupdown()
Change-Id: Ie52bf8ac6d62e7f2d760294bf2fe90119cc96b4b
Related: CID#215869
2021-01-05 15:21:39 +00: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 fdea03b408 gprs_ns2: fr: check the device state before changing state
Reduce the required capabilities if the device is already
set up.

Change-Id: I72eb2567078758694c648a493324b212461ee735
2020-12-29 22:41:41 +00:00
Alexander Couzens 8c33d4a485 gprs_ns2_fr: setup_device: allow to setup a new dahdi device
When a dahdi device hasn't been set up yet, ioctl IF_GET_PROTO fails
with invalid argument.
Also fix the device check to skip ioctl's if the device is also in the
correct state.

Change-Id: I398d056546e35465a2944e1b4a86a8c93b3e5f7a
2020-12-27 19:59:52 +00:00
Harald Welte b8de188b54 gprs_ns2_fr: Use OSMO_STRLCPY_ARRAY() where possible
Change-Id: I8ce461ecc36a81a4221336e82a36a69f49f89a0a
2020-12-21 11:41:55 +00:00
Harald Welte 7f01b68671 gprs_ns2_fr: Avoid stringop-truncation warning
gprs_ns2_fr.c:448:2: error: ‘strncpy’ specified bound 16 equals destination size [-Werror=stringop-truncation]
  448 |  strncpy(req.ifr_name, netif, IFNAMSIZ);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: Ied9fd1bea091075fad266258da39e674d10d4dcb
2020-12-21 12:41:03 +01:00
Alexander Couzens 5c96f5dbc6 gprs_ns2: fr: setup the device to correct FR/LMI settings
A hdlc can be used in different modes. Also a FR device can be used
with lmi and certain settings as without it.
ns2 will use FR with no lmi in the kernel.

Related: SYS#5169
Change-Id: I04786d2b864860b08c2e1afdb199470f4b80cc3b
2020-12-20 17:16:44 +01:00
Alexander Couzens 60021a46ce gprs_ns2: fr: implement a write queue
Related: SYS#5228
Change-Id: Id6eba04d5fb744f791b333c168729bbbd28cabd9
2020-12-20 17:14:04 +01:00
Neels Hofmeyr 8fef761d14 fix strncpy bug in gprs_ns2_fr_bind()
This use of strncpy() fails to account for the terminating nul
character. Use OSMO_STRLCPY_ARRAY() instead.

(Interestingly my compiler doesn't complain about this one, though it
failed on another similar use of strncpy().)

Change-Id: Id53e940c7a39ab154966548f4173a179c5bc9151
2020-12-18 11:12:16 +00:00
Neels Hofmeyr 475a0acc64 gprs_ns2_fr.c: compiler error: replace strncpy() with OSMO_STRLCPY_ARRAY()
My gcc (Debian 8.3.0-6) 8.3.0 refuses to build this strncpy() use: it
issues the buffer length as n and thus potentially fails to account for
the terminating nul. The line after that fixes the problem, so it's not
an actual bug. Anyway, we have a policy to never use strncpy(), and have
osmo_strlcpy() and OSMO_STRLCPY_ARRAY() for this.

This strncpy() was introduced last month during first addition of
gprs_ns2_fr.c:

    commit 841817ec52
    ns2: add support for frame relay
    Change-Id Id3b49f93d33c271f77cd9c9db03cde6b727a4d30

Change-Id: I494a6fb7ccd7938a39e8956f73ec4282da38d7fb
2020-12-18 11:12:16 +00:00
Alexander Couzens 6f89c770c7 gprs_ns2: fr: fix crash when frame relay interface doesn't exists
When a frame relay interface doesn't exist gprs_ns2_fr_bind() would
detect this but still return a success.

Change-Id: I815b6ef5c3df780ac94461a05975a2b70898b01e
2020-12-18 10:52:37 +00:00
Alexander Couzens c782cec663 gprs_ns2: add gprs_ns2_fr_bind_role() to retrieve the fr role
Change-Id: I277b805e588ba68536789b4a64a428ea0b31728a
2020-12-15 11:46:45 +00:00
Alexander Couzens 22c26e0610 gprs_ns2: make nsvc argument const
The nsvc isn't change. It can be const

Change-Id: Ie5052f02781d7fdc639456c6f02515a927cee1f3
2020-12-15 11:46:45 +00:00
Alexander Couzens ebcbd726ee gprs_ns2: rework gprs_ns2_fr_connect*()
Add gprs_ns2_fr_connect2() and change gprs_ns2_fr_connect() to
be similar to gprs_ns2_ip_connect() and gprs_ns2_connect2().

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

Change-Id: I4e1374b0e979b3293302c5ed46a91a58f3a5a916
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 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 5bea72e1e0 gprs_ns2_fr: use ETH_P_HDLC instead of ETH_P_ALL
When opening the socket, use ETH_P_HLDC to restrict the socket to
packet received on HLDC interfaces.  This avoids packets from random
other (ethernet, ...) interfaces to appear before we can bind()
it to the actual hdlc-net-device we're interested in.

We still are racing against other HLDC net-devices, but those have
lower PPS and throughput ratese as 1G/10G or even higher speed ethernet
devices that might exist on the same machine.

Change-Id: I6a556e6e2d012c17a2777cc8b30fed0f318db178
2020-12-10 22:08:02 +01:00
Harald Welte 41b188b90b gprs_ns2_fr: guard against race between socket(AF_PACKET) and bind()
An AF_PACKET socket will immediately receive packets of _all_ interfaces
until it is bound to one specific interface.  This introduces a race
condition between the socket() and the bind() syscall.

Let's use the ifindex passed for each packet in recvmsg() to drop
any packets received for other interfaces.

Change-Id: I8f708ba4f9b7f76525acce17b24a8f7b125a1c1c
Related: SYS#5245
2020-12-10 22:01:33 +01:00
Harald Welte 4ed0f4e994 gprs_ns2_fr.c: Skip extraneous FIONBIO
The socket is marked non-blocking inside osmo_fd_register(), there
is no need to do it twice.

Change-Id: I2068ce8280357b14970d01e5c86de5c59c933650
2020-12-10 22:01:33 +01:00
Pau Espin Pedrol d41800c7ec gb: Import mnl.h iif --enable-libmnl
Change-Id: Ic0100493a9256e9c30a4bbb92be404270a8b9393
2020-12-07 13:35:24 +01:00
Harald Welte a59e6dbee3 gprs_ns2_fr: remove include <linux/if.h>
It's not needed because net/if.h already include
the required parts. Furthermore the linux/if.h generates
a compiler error in combination with net/if.h on older systems
(e.g. debian jessie)

Change-Id: I53650e9c55bb9dd98ba60269025e72673e9f82c1
2020-12-04 10:30:43 +01:00
Harald Welte 56f08a377c gprs_ns2_fr: Monitor the kernel net-device link state
We use the newly-introduced libmnl integration of libosmocore in order
to receive netlink events from the kernel on link state changes.

If one of "our" interfaces changed link state, we report this in the log
and also store it within the "bind".

Change-Id: I779556991bfc88b7751b2be17bb81c329cfb9e01
2020-12-02 21:04:51 +00:00
Alexander Couzens b7fc3a0a6d gprs_ns2_fr: remove include <linux/if.h>
It's not needed because net/if.h already include
the required parts. Furthermore the linux/if.h generates
a compiler error in combination with net/if.h on older systems
(e.g. debian jessie)

Change-Id: Iccf931207d8bea19969fbfc4225f622a1a709972
2020-12-02 20:49:48 +00:00
Harald Welte 96ec84a035 gprs_ns_vty: Unify display of NSVCI on VTY in 'show ns entities'
Change-Id: I2915b47a5fc4ed9ac16f611c9e9f71dc0955426a
2020-12-01 18:01:43 +01:00
Harald Welte 48bd76cbc0 gprs_ns2_fr: Print Frame Relay 'role' in VTY
Change-Id: I23182e5d952fd28a0bbfa76a4fc94d8e03b7a65d
2020-12-01 18:01:43 +01:00
Harald Welte b6b82da56c frame_relay: Fix error path on ioctl() failure
We don't want to pass -EINVAL as file descriptor into the bind() call.

Closes: CID#215529
Change-Id: Ic4d411c0ade6867c4fe2c01eb3368e6420158724
2020-11-30 13:29:33 +00: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 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