aboutsummaryrefslogtreecommitdiffstats
path: root/src/gb/gprs_ns2_fr.c
AgeCommit message (Collapse)AuthorFilesLines
2023-05-16ns2: Count transmitted/dropped in each layer implementationPau Espin Pedrol1-1/+11
This allows better control on how the counters are ticked. For instance, since nowadays the writing in ns2_udp is done asyncrhonously, most probable failures occur at a later point and not when returning to the caller. Change-Id: I8109cee07f157ebf1806f82a071f58de3a2dcc9c
2023-02-02gprs_ns2_fr: use osmo_netdev to monitor and operate network devicePau Espin Pedrol1-134/+38
As a result libosmogb doesn't depend directly on libmnl anymore, but through libosmocore. Change-Id: Ib0e499e09c50135a5c4a361332d6120f660a1a45
2022-10-19doc: correct typo in ticket referenceMax1-1/+1
The OS#4993 has nothing to do with AF_PACKET/ENOBUFS, the proper ticket is OS#4995 as referenced later in the same file. Change-Id: Icf13b351dc74508fc312c535d68b13b7ce9b7e1e
2021-11-11frame_relay, gprs_ns2_fr: Fix log messages, remove unused structDaniel Willmann1-7/+2
Fix typo and remove any reference to GRE from gprs_ns2_fr.c. GRE code is in gprs_ns2_frgre.c Change-Id: I51c756f3c9d918552591bf87861cb4799721ac37
2021-07-02gprs_ns2: fix check of MTU changes for frame relayAlexander Couzens1-3/+7
The frame relay needs 2 byte for data packets. Related: OS#5192 Change-Id: I02d4e81896a473aeb79ea2f2983e12324244048f
2021-06-05gprs_ns2: rework id strings of nsvcsAlexander Couzens1-2/+3
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-04Use new stat item/ctr getter APIsPau Espin Pedrol1-3/+3
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-03-24gprs_ns2: always use the same method to print NSVCsAlexander Couzens1-2/+2
The binds also print a list of associated NSVC when dumping the bind. However the binds using their own representation of printing the NSVC which is different to `show ns entities`. Use the same function to print NS-VC. Before: NSVCI 00000: udp)[127.0.0.1]:23000<>[127.0.0.1]:22000 After: NSVCI none: UNCONFIGURED DYNAMIC data_weight=1 sig_weight=1 udp)[127.0.0.1]:23000<>[127.0.0.1]:22000 Change-Id: If31ec6c1c07dc134ab1ddeb915bc89747c7be048
2021-02-19gprs_ns2_fr: pass MTU changes to the NSEAlexander Couzens1-2/+29
When the MTU of the frame relay device changes, update the bind and notify all NSEs. Related: OS#4889 Change-Id: I946f7655c9526ffd98dabdce219c6a419b71e00c
2021-02-16gprs_ns2: inform the NS user (BSSGP) about the MTU of a NSEAlexander Couzens1-0/+1
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-11ns2_fr: Fix heap-use-after-free in error recovery pathHarald Welte1-0/+1
<0026> gprs_ns2_fr.c:515 BIND(hdlcnet1) Can not create AF_PACKET socket. Are you root or have CAP_NET_RAW? ================================================================= ==3872359==ERROR: AddressSanitizer: heap-use-after-free on address 0x6130000030c0 at pc 0x7fef120aa92e bp 0x7ffebf6b5c20 sp 0x7ffebf6b5c18 READ of size 8 at 0x6130000030c0 thread T0 #0 0x7fef120aa92d in osmo_fr_link_free (/usr/local/lib/libosmogb.so.11+0x16992d) #1 0x7fef1205105a in free_bind (/usr/local/lib/libosmogb.so.11+0x11005a) Change-Id: I23c0f1697edd5734085fa18b0a2f253c0f206c53
2021-02-11ns2_fr: Fix null pointer deref in error pathHarald Welte1-1/+1
The followign happens if osmo-gbproxy is started without CAP_NET_RAW: <0026> gprs_ns2_fr.c:515 BIND(hdlcnet1) Can not create AF_PACKET socket. Are you root or have CAP_NET_RAW? gprs_ns2_fr.c:176:2: runtime error: member access within null pointer of type 'struct msgb' AddressSanitizer:DEADLYSIGNAL the second line is free_bind() iterating overr the backlog while destroying the not-yet-fully-initialized bind. Let's make sure the backlog llist_head is always initialized properly. Change-Id: I4d2fa50955c5897cd469fee68d4ddc65a9f5688f
2021-02-08ns2: Don't try to add packets to the backlog on real errorsHarald Welte1-1/+5
When writing to the AF_PACKET socket, we have to distinguish the pseudo-errors like -ENOBUFS (where we do want to add to the backlog) from real errors like -ENETDOWN, -EMSGSIZE, ... where we don't want to add the failed packet to the backlog. Change-Id: Ibbb6805da0f118466c4c91e458e62b63b84cb794
2021-02-08ns2: improve backlog handling on interface up/downHarald Welte1-9/+35
This patch improves the behavior of the newly-added backlog in situations where the interface goes up/down. * don't add new packets to the backlog while if_running == false * flush the backlog on both ifup and ifdown events Change-Id: Ib35d099526544fe2cff64566fd56147a906adab9
2021-02-08ns2: Don't queue Q.933 LMI messages; only store most recent onesHarald Welte1-3/+18
There's not really any point in storing multiple LMI messages, and then transmitting them in inverse order, as the existing code does. Instead, we shall store only the last (failed) LMI message and try to transmit that at highest priority, before any NS messages in the actual queue. Change-Id: I5407a76a34d7e687966fe1a915febf3a87256593
2021-02-03gprs_ns2_fr: free_bind(): first do the NULL check before using membersAlexander Couzens1-1/+1
Change-Id: I80f72ada15b477d735bf5aee36a5d67e80eb0136
2021-02-03gprs_ns2: unify the handling of **result when bind already present.Alexander Couzens1-3/+7
All bind function should work in the same way. Also fixing a null pointer assignment if no **result is giving. Change-Id: Idd0c2190d2af39804c18c4786a997079db9a4330
2021-02-02ns2: Don't start sending NS-RESET until FR DLC is availableHarald Welte1-2/+12
There's no point in sending NS-RESET (or any other) messages to the underlying FR layer if the FR DLC has not been marked as available/active yet. Change-Id: Id4e7565ba166ca1d12f8800c643d9f2bc4d66873 Closes: OS#4999
2021-02-02frame_relay: Add status call-backs for link + DLC status changesHarald Welte1-2/+2
Change-Id: Iec19db4e48642c3fcb0aa11fa7787b8323fd0e5a Related: Os#4999
2021-02-01ns2: Introduce a per-bind stat_item group with backlog lengthHarald Welte1-0/+4
The backlog length indicates the instantaneous length of the backlog. Change-Id: I1c55b4619b1221d7e607ace58649323407faf86b
2021-02-01ns2: Memory allocation failures are ENOMEM, not ENOSPCHarald Welte1-1/+1
ENOSPC is used with non-volatile (disk) storage, while ENOMEM is customarily used for RAM allocation failures. Change-Id: Ia4c16d8278dc30c7cc69169b18428cda5272738d
2021-02-01ns2: Move to one common/shared ns2_bind_alloc()Harald Welte1-28/+10
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-01-31ns2: Properly report packet drops in FR codeHarald Welte1-6/+7
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-31ns2: Work around AF_PACKET socket ENOBUFS problemsHarald Welte1-25/+166
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-30ns2: Log ERROR if we cannot transmit a packet due to ENOBUFSHarald Welte1-3/+7
Related: OS#4995 Change-Id: I2ba64e96c60e23d2e6c8ecdcab0b52b3833f092c
2021-01-30ns2: Use proper return value from write_queue callback functionHarald Welte1-1/+6
write_queue expects a -errno value on error, not '-1'. Change-Id: I93c858facfe7e1c533df8dccc4502a574686bc8a Related: OS#4995
2021-01-28gprs_ns2: refactor: ensure all enums have GPRS_NS2_Alexander Couzens1-2/+2
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-25gprs_ns2: drop prefix of all internal exposed functionAlexander Couzens1-1/+1
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-20ns2: Unify logging context via log macrosHarald Welte1-26/+24
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-19gprs_ns2: allow to use free_vc() with NULLAlexander Couzens1-1/+2
Usually talloc_free() and other free functions in osmocom allows to be called with NULL which is then ignored. Change-Id: If7b0c6916a29d4611d0a40c388414076eb83e6b5
2021-01-19gprs_ns2: add assert on most bind callsAlexander Couzens1-1/+10
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-18gprs_ns2: Give NS-VC FSMs a proper name/identifierHarald Welte1-1/+5
Log output without a proper identifier is mostly useless. Change-Id: Id9d5b0684584d03685900c6298fe70246793de14 Closes: OS#4876
2021-01-18gprs_ns2_fr: reduce duplication between gprs_ns2_fr_connect / connect2Harald Welte1-18/+1
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-05gprs_ns2_fr: fix resource leaks due to early return in set_ifupdown()Vadim Yanitskiy1-2/+6
Change-Id: Ie52bf8ac6d62e7f2d760294bf2fe90119cc96b4b Related: CID#215869
2021-01-05gprs_ns2: set transfer cap in NS Status primitiveAlexander Couzens1-0/+2
Related: SYS#5153 OS#4835 Change-Id: Ia1046db9e0d50855bff9de670b612ffc57af9995
2020-12-29gprs_ns2: fr: check the device state before changing stateAlexander Couzens1-0/+7
Reduce the required capabilities if the device is already set up. Change-Id: I72eb2567078758694c648a493324b212461ee735
2020-12-27gprs_ns2_fr: setup_device: allow to setup a new dahdi deviceAlexander Couzens1-4/+6
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-21gprs_ns2_fr: Use OSMO_STRLCPY_ARRAY() where possibleHarald Welte1-2/+2
Change-Id: I8ce461ecc36a81a4221336e82a36a69f49f89a0a
2020-12-21gprs_ns2_fr: Avoid stringop-truncation warningHarald Welte1-1/+1
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-20gprs_ns2: fr: setup the device to correct FR/LMI settingsAlexander Couzens1-4/+110
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-20gprs_ns2: fr: implement a write queueAlexander Couzens1-29/+19
Related: SYS#5228 Change-Id: Id6eba04d5fb744f791b333c168729bbbd28cabd9
2020-12-18fix strncpy bug in gprs_ns2_fr_bind()Neels Hofmeyr1-1/+1
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-18gprs_ns2_fr.c: compiler error: replace strncpy() with OSMO_STRLCPY_ARRAY()Neels Hofmeyr1-2/+1
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 841817ec52186029ca01f0c082ed84f2dc5ffcc5 ns2: add support for frame relay Change-Id Id3b49f93d33c271f77cd9c9db03cde6b727a4d30 Change-Id: I494a6fb7ccd7938a39e8956f73ec4282da38d7fb
2020-12-18gprs_ns2: fr: fix crash when frame relay interface doesn't existsAlexander Couzens1-2/+2
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-15gprs_ns2: add gprs_ns2_fr_bind_role() to retrieve the fr roleAlexander Couzens1-0/+15
Change-Id: I277b805e588ba68536789b4a64a428ea0b31728a
2020-12-15gprs_ns2: make nsvc argument constAlexander Couzens1-1/+1
The nsvc isn't change. It can be const Change-Id: Ie5052f02781d7fdc639456c6f02515a927cee1f3
2020-12-15gprs_ns2: rework gprs_ns2_fr_connect*()Alexander Couzens1-0/+39
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-15gprs_ns2: add member name to bindAlexander Couzens1-2/+18
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-15gprs_ns2: introduce NS dialectsAlexander Couzens1-3/+2
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-10gprs_ns2_fr: use ETH_P_HDLC instead of ETH_P_ALLHarald Welte1-1/+1
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