Commit Graph

3831 Commits

Author SHA1 Message Date
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
Vadim Yanitskiy c8158ecfc4 protocol/gsm_08_58.h: add Osmocom specific EWMA AVG algo
Change-Id: Ib436fd8b81afdb06c6d936f6839f847a705d00e2
Related: SYS#4918
2020-12-15 09:52:42 +00:00
Vadim Yanitskiy a346c45ceb protocol/gsm_08_58.h: add ip.access Power Control structures
Change-Id: I9430bcb79c269efb4f9527f565cf4e12e4444940
Related: SYS#4918
2020-12-15 09:52:42 +00:00
Pau Espin Pedrol 0f619de715 gsm: append_eutran_neib_cell: Fix SI2quater EARFCN list
Commit bd6e7a9f2d did the initial porting
of rest_octet APIs from osmo-bsc, but introduced a bug when moving
bts->e_offset to a generic pointer independent of bts structure.
As a result, using this API from osmo-bsc makes gsm0408 unit test fail
due to bad encoding of several EARFCNs in si2quater.

Fixes: bd6e7a9f2d
Change-Id: I2bf5635b8536b11d69774d17ac1908019633e3af
2020-12-14 17:58:23 +01:00
Pau Espin Pedrol c4286ad056 si2quater: fix budget calculation for multiple EARFCNs
In rest_octets.c append_earfcn(), the unconditional bits added are 40, not 25.
Removing only 25 bits from the budget resulted in malformed SI2quater starting
with 4 configured EARFCNs, by adding more EARFCNs than fit in 20 bits.

These malformed SI2quater were also expected in gsm0408_test.c. Update the
expected SI2quater to what is being generated now. This patch passes the ttcn3
testing added in I45382f88686ca60e68569e93569fc4cfb63a0e0d, which provides some
confidence that the coding expected in gsm0408_test.c is now correct.

This commit is a cherry-pick of osmo-bsc.git 6589f7c3a8dfdaaf66dda3afa6bbb1118ec825f9

Change-Id: Icc1ece39ad162d09720e104c5cbc12b07d6771a8
Related: OS#4652
2020-12-14 17:19:30 +01:00
Pau Espin Pedrol 30bf0e6745 gsm: si13: Fix encode of EGPRS_PACKET_CHANNEL_REQUEST
Cherry-pick from osmo-bsc.git e981f17200bf3a5d5114f46d9f7515fd10b96dbb

Change-Id: I0aae385a427205cc73f60feca161e38608e608d8
2020-12-14 17:13:47 +01:00
Pau Espin Pedrol 908224c1a4 rest_octets: add Serving Cell Priority Parameters
When we add an EARFCN to to the SI2quater struct we do not add Serving
Cell Priority Parameters. This essentially causes to MS to ignore the
EARFCN because it is still undefined under which conditions the MS
should change to LTE.

This is a cherry-pick from osmo-bsc.git 295c965c063a8c431507191f6aef1ef78b720685

Related: SYS#4510
Change-Id: If9134759e9bc4ae0920800972632fd8c5dc9c2d9
2020-12-14 17:11:21 +01: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 0e61716881 bssgp: Remove newly added log line warning about NOOP
osmo-pcu unit tests fail ue to this new log line. Let's rather simply
leave a comment there, since anyway known apps will be migrating soon
the new APIs.

Fixes: fde19ed579
Change-Id: Ib9bf528db08f7aaa4adaf7b6a320679a4f11a53d
2020-12-10 13:39:44 +01:00
Harald Welte 1fcfce86cb bssgp_bvc_fsm: Add basic BVC flow control rx/tx support
The FSM doesn't actually implement the flow control logic,
it only decodes / dispatches and encodes messages.

Related: OS#4891
Change-Id: Ie59be6761177c43456898be9148727f15861a622
2020-12-09 22:57:53 +01:00
Harald Welte 4394bb9629 bssgp2: Encoding + Decoding functions for BVC and MS flow control
Change-Id: I9c89bb1c03550930c07aad7ff8f67129ee7a6320
Related: OS#4891
2020-12-09 22:56:07 +01:00
Harald Welte 4c0e1a1f4c logging: Assing different 8bit colors to built-in subsystems
The 16 ANSI colors we started to use for OpenBSC in 2008 were
sufficient for those few sub-systems that occurred in the BSC/NITB.

Over time, most sub-systems did not get colors anymore.  Let's
change that and assign more or less random colors from the 8bit
color palette.

Change-Id: Ia8c0f91a61fbca0441faf66b3f368f45f886187c
2020-12-09 22:56:07 +01:00
Harald Welte 17a892ff2b gb: Add beginnings of a new BSSGP implementation
Similar to ns2 superseding ns, we now also intoduce a next generation
of BSSGP related code to libosmogb.  However, this is not aiming to
be a full implementation yet, but simply those parts that we currently
need from the revamped osmo-gbproxy.

The gprs_bssgp2.[ch] differs in two ways from the old code:
* it separates message encoding from message transmission
* it supports more recent specs / IEs

bssgp_bvc_fsm.c is a genric implementation of the BSSGP BVC
RESET/BLOCK/UNBLOCK logic with support for both PTP and signaling,
both on the SGSN side and the BSS side.

Change-Id: Icbe8e4f03b68fd73b8eae95f6f6cccd4fa9af95a
2020-12-09 22:56:01 +01:00
Harald Welte fde19ed579 logging: Introduce DLBSSGP logging constant
Historically, BSSGP uses a non-constant, user-configurable integer
varieable for the logging sub-system.  Let's replace this with a
statically-allocated library logging constant.

This is required if we want to use the subsystem number in e.g.
static initialized for osmo_fsm.log_subsys.

Change-Id: I506190aae9217c0956e4b5764d1a0c0772268e93
2020-12-09 22:50:01 +01:00
Alexander Couzens 45a25a3222 gprs_ns2_sns: correct dynamic calculation
The wrong argument was used to multiply by 4. However it was still
compliant because the SNS code would always supports 16 NSVCs.
Use the correct multiplier.

Fixes: ttnc3 pcu sns test cases
Fixes: 42ad549152 ("gprs_ns2_sns: dynamic calculate the maximum NS-VCs")

Change-Id: I58d706c6fffb4237b90b37cade4dc00c6aba6ac9
2020-12-09 16:13:42 +00:00
Harald Welte dec201a606 tlv.h: Add msgb_tvlv_put_{16,32}be()
Those routines are very useful when puzzling together BSSGP messages
with 16-bit and 32bit sized IEs.

Change-Id: I033f9a708c9d7ffad91336178231dc66233e1693
2020-12-08 21:37:45 +01:00
Harald Welte a6f896232e gsm_08_18.h: Add #defines for [extended] feature bits
Change-Id: I7743cb901988c8fddd91127cfdca6e54b3d44ea8
2020-12-08 12:27:38 +00:00
Harald Welte 8f82528bf7 bssgp: Add osmo_tlv_prot_def for BSSGP
Change-Id: I7e4226463f3c935134b5c2c737696fbfd1dd5815
2020-12-08 12:27:38 +00:00
Harald Welte 30a9294306 tlv: Introduce enum with error codes for TLV parser functions
Change-Id: I0b352792089c5c0c714712d2ea237beb92e1d73f
2020-12-08 12:27:38 +00:00
Harald Welte 9510992c53 Introduce 'osmo_tlv_prot' abstraction for validation of TLV protocols
This extends our existing TLV parser with the ability to
* validate that mandatory IEs of a given message are present
* validate that all present IEs are of required minimum length

Introducing this generic layer will help us to reduce open-coded
imperative verification across virtually all the protocols we
implement, as well as add validation to those protocols where we
don't properly perform related input validation yet.

Change-Id: If1e1d9adfa141ca86001dbd62a6a339f9bf9a912
2020-12-08 12:27:38 +00:00
Harald Welte e24a5b559c ns2: Accept NS-UNBLOCK-ACK in UNBLOCKED state
if we transition to UNBLOCKED as a result of a locally-generated
unblock action, then of course we will receive an inbound UNBLOCK-ACK.

Let's avoid error log messages and confusign the peer with NS-STATUS
in this case:

DLNS DEBUG GPRS-NS2-VC(FR-hdlcnet3-DLCI18-NSEI2001-NSVCI3)[0x612000001720]{UNBLOCKED}: Received Event UNBLOCK_ACK (gprs_ns2_vc_fsm.c:692)
DLNS ERROR GPRS-NS2-VC(FR-hdlcnet3-DLCI18-NSEI2001-NSVCI3)[0x612000001720]{UNBLOCKED}: Event UNBLOCK_ACK not permitted (gprs_ns2_vc_fsm.c:692)

Change-Id: Icc4d960ddad82e3ebbf571d8ff9f24854b52a946
2020-12-08 12:27:38 +00:00
Philipp Maier b73a3ded04 gprs_bssgp_util: complete bssgp_pdu_strings
The value strings for the BSSGP lack some items, lets make it complete.

Change-Id: I94956ca12df7f7ba912da05397b3fb39956277f7
Related: SYS#5103
2020-12-07 20:55:52 +01:00
Alexander Couzens e78207f16b gprs_ns2_sns: fix whitespaces and superflous comment
Change-Id: Ica0033c88cad71827ad843e92ccd54663426de23
2020-12-07 13:13:06 +00:00
Alexander Couzens db1c3fb114 gprs_ns2_sns: add missing S() to allow GPRS_SNS_EV_NO_NSVC happen
The event GPRS_SNS_EV_NO_NSVC was never dispatched because the
S() was missing to convert it into a bitmask.

Change-Id: I4af01293ff0ba8629e1426b1ba92f72f0520c7f0
2020-12-07 13:13:06 +00:00
Alexander Couzens 42ad549152 gprs_ns2_sns: dynamic calculate the maximum NS-VCs
The previous hard-coded value could be not enough if the user configures
too many local binds. Allow at least 8 NS-VCs. In case the user
configures too many binds (> 2) increase the maximum NS-VCs to allow
the SGSN to have 4 redundant connections.

Change-Id: Iae859dc504716fd6f705e72db5fc293b4b3298e7
2020-12-07 13:13:06 +00:00
Alexander Couzens e03d863e1f gprs_ns2_sns: add missing transistion UNCONFIGURED -> SIZE
The SNS FSM can go into the SIZE state when all NS-VC are failing.
This is the case if the network connection to the SGSN got interrupted.

Change-Id: I7e7da9451458505c1c2d73836dd916aee7704fda
2020-12-07 13:13:06 +00:00
Pau Espin Pedrol d41800c7ec gb: Import mnl.h iif --enable-libmnl
Change-Id: Ic0100493a9256e9c30a4bbb92be404270a8b9393
2020-12-07 13:35:24 +01:00
Pau Espin Pedrol 896a9bb2ed Include mnl.h iif --enable-libmnl
Change-Id: I06016e3a6e90b09b76634a00081d0d40a8e2f94b
2020-12-07 13:24:30 +01:00
Harald Welte 7fc88b3248 log2.h: Avoid redefining __always_inline
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h:10:0: error: "__always_inline" redefined [-Werror]
 #define __always_inline               inline __attribute__((always_inline))
/usr/include/x86_64-linux-gnu/sys/cdefs.h:311:0: note: this is the location of the previous definition
 # define __always_inline __inline __attribute__ ((__always_inline__))

Change-Id: I738d2a72f835a29e30b8ba20456e5c4c9aa844c9
2020-12-06 15:45:52 +01:00
Harald Welte c172d9fe8d log2.h: Use uintXX_t instead of kernel specific types
Change-Id: Ieb872551bdbe514f2c77f9aeb2b9ee42f6573909
2020-12-06 15:14:35 +01:00
Harald Welte 622cda3802 hash/log2: Add generic implementations of fls() and fls64()
When importing the hashtable code in I8ef73a62fe9846ce45058eb21cf999dd3eed5741
I didn't import actual implementations of the fls() and fls64()
implementations, as at least gcc-10 was smart enough to detect
we only use it on constant types and hence the computation can happen
at build time via const_ilog2()

However, in our jenkins build verification' this doesn't appear to
happen, as we get below errors:

/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h: In function ‘__ilog2_u32’:
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h:20:9: error: implicit declaration of function ‘fls’ [-Werror=implicit-function-declaration]
  return fls(n) - 1;
         ^~~
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h: In function ‘__ilog2_u64’:
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h:28:9: error: implicit declaration of function ‘fls64’ [-Werror=implicit-function-declaration]
  return fls64(n) - 1;
         ^~~~~

Let's provide some generic implementations for this case.  If needed
one could also introduce architecture-specific assembly implementations
like in the Linux kernel, but so far we managed to keep libosmocore free
of any assembly tweaks.

Change-Id: Ifa4898eb66c8d949618edd47961b7a0330ed35b5
2020-12-06 14:40:55 +01:00
Harald Welte c22e002890 gsm_08_18.h: Add some PDU definitions still missing
In I7da8b25c9a89a7e3ae6c1680ba838e136d7d5293 I seem to have failed
to realize that 3GPP TS 48.018 v15.0.0.0 Table 11.3.26 continues
on yet another page.  Let's add those missing PDU types definitions.

Change-Id: I9173c35240ff78048b2b76a1155d90467ef16b2d
2020-12-06 12:56:29 +01:00
Harald Welte 77530b4619 Use explicit type-casting in hlist_del() for C++ compatibility
/usr/local/include/osmocom/core/linuxlist.h:479:12: error: invalid conversion from ‘void*’ to ‘hlist_node*’ [-fpermissive]
  479 |  n->next = LLIST_POISON1;

Fixes: I8ef73a62fe9846ce45058eb21cf999dd3eed5741
Change-Id: I75b0a5fe097562007c53987d8d41811e9f35798d
2020-12-05 20:16:51 +01:00
Vadim Yanitskiy 59e13e4d25 core/linuxlist: do not use 'new' as a parameter name
'new' is a reserved keyword in C++, so including this header from
a C++ project (like osmo-pcu) breaks compilation.  Let's rename
it in the same way as it's already done in this file: add '_'.

Change-Id: I7f7d9143edca75ce932601386a8766b0a62c0e24
Fixes: I8ef73a62fe9846ce45058eb21cf999dd3eed5741
2020-12-05 15:07:51 +01:00
Harald Welte 7101ca2751 Add hlist and hashtable from Linux kernel
For more than a decade we've used the linuxlist.h for double-linked
lists.  Let's also add the hlist (double-linked lists with single
pointer sized head, and the hashtable that builds on top of it.

This reflects the versions included in Linux 5.8 with some modifications
to make them build in userspace (remove RCU versions, adjust for
userspace include files and types, convert to doxygen).

Change-Id: I8ef73a62fe9846ce45058eb21cf999dd3eed5741
2020-12-05 11:39:42 +01:00
Harald Welte e3b20edec5 bssgp: Fix typo in BSSGP Message Type enum
Change-Id: I63941f8b38485e569f56ba5065c2c00232703028
2020-12-04 18:20:15 +00:00
Harald Welte 61e9de8f15 bssgp: Update bssgp_pdu_strings with Release 15
In I7da8b25c9a89a7e3ae6c1680ba838e136d7d5293 we introduced the enum
values for all the new BSSGP message types up to Release 15.  Let's
also add value_strings for them here.

Change-Id: Ia108ba0d5f1f2c9d46f0c0bd11cd93104b9d62ea
2020-12-04 18:20:15 +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
Harald Welte 2d9ce71fcb bssgp: 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: I56e8b31ce51602d2681e3db501c48f84bfe7e438
2020-12-04 18:20:15 +00:00
Daniel Willmann 89106524a0 ns2: Fix argv index in logging filter VTY commands
Change-Id: I8adaf8094ef028b2d580e918532d6712d2ebbc2c
Related: SYS#5232
2020-12-04 16:52:11 +00: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 26fc9136b0 mnl: Use mnl_socket_open() insatead of mnl_socket_open2()
mnl_socket_open2 is not yet available on e.g. Debian 8.  Furthermore,
osmo_fd_register() will set the CLOEXEC flag on every file descriptor
anyway, so there is no benefit from using mnl_socket_open2() at all.

Change-Id: I0b37ffa148ff0c0a22281b490820353f5fef00eb
2020-12-04 10:29:07 +01:00
Harald Welte d8e59b208c libosmogb: Add missing LIBMNL_CFLAGS
In Change-Id I779556991bfc88b7751b2be17bb81c329cfb9e01 we introduced
the use of libmnl via osmo_mnl to libosmogb.  Howver, we didn't add
LIBMNL_CFLAGS in Makefile.am, which now (rightfully) fails on some
distributions like the SuSE family of distributions.

Let's fix this.

Change-Id: Ib8740e8fd677026efb9dad5d5fe6b95147fb3c23
2020-12-04 10:17:21 +01: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