AgeCommit message (Collapse)AuthorFilesLines
2021-02-03WIP: add rate_ctr_group to log_targetlaforge/usdtHarald Welte3-3/+45
This way we account for the number of dropped log messages at write_queue overflow. However, log targets have no numerical ID and hence we're not able to extract them in a reasonable manner. Related: OS#4311 Change-Id: I89b696311b823267e05d6a3e85b92c1784b220ed
2021-02-03logging: Attempt a synchronous, non-blocking write first (file, stderr)Harald Welte1-17/+30
In the old days, we performed synchronous, blocking writes to the log file or stderr. This was replaced by code that turned all log file/stderr writes into non-blocking writes behind a write_queue. This patch now introduces a further optimization: If we currently don't have any log messages pending in the write queue, we are not back-logged and assume we have a fair chance of writing the log message right now, synchronously. So we try that first, and only enqueue the log message if the write fails (no bytes or insufficient number of bytes written). This way we should get the best of both worlds: No delay/re-ordering (and lower select syscall load) for the "normal" case (benefits of the old synchronous writes) while at the same time never risking to block on log output. Related: OS#4311 Change-Id: I08469a7e4be9bc5bbd39140457bb582f4a0b1703
2021-02-03logging: Avoid memcpy from stack to msgb in _file_output()Harald Welte1-18/+43
For file and stderr output, the existing code always generates the log string on a stack buffer, and then (in case of non-blocking write via write_queue) copies it over to a msgb. Let's optimize this by turning _file_output() into a raw_output callback which first allocates the msgb and then format-prints directly to that msgb instaed of stack + memcpy. This has the disadvantage that we don't know how long the buffer has to be in order to print the entire string to it. As a result we always have to allocate a 4k-sized buffer (plus msgb overhead). The write_queue length for log file output has been decreased from 1024 entries to 156 entries in order to stay within the same memory requirements for each log target memory pool (about 648 kBytes). Related: OS#4311 Change-Id: I0d10b0199576d2e7ff6421a6dba19ae5ffafd946
2021-02-03logging: Change stderr + file target to use non-blocking writeHarald Welte4-21/+313
So far, we used blocking, buffered fwrite() to write to stderr and file targets. This causes problems if there are [slow] consumers causing delays, such as gnome-terminal (when the program is started interactively) or systemd/journald (where we observe 64..128ms blocks on stderr). This patch introduces stderr/file based logging via write_queue and osmo_select_main(), i.e. switch from glibc-buffered, blocking to internally buffered, non-blocking writes. * when osmo_stderr_target is created via application.c, we create it in blocking stream mode for backwards compatibility, particularly for [smaller] programs that don't use osmo_select_main() * when the VTY code encounters 'log stderr' or 'log file FILENAME', we switch that respective target to non-blocking write-queue mode, as this means the application is in fact using osmo_select_main() * The config file can now state 'log stderr blocking-io' or 'log file FILENAME blocking-io' to explicitly enforce using blocking stream based I/O * The application can at any time use API functions to switch either way Closes: OS#4311 Change-Id: Ia58fd78535c41b3da3aeb7733aadc785ace610da
2021-02-03Enable systemd-journald log target in debian + rpm packagingHarald Welte3-2/+4
Given that all the distributions we support are shipping systemd anyway, this will not really introduce any additional runtime package dependencies. Change-Id: Ib3af918cd4cc8d0ca6d228a0f2c8338534374d46
2021-02-03initial support for static userspace probes via systemtapHarald Welte7-1/+103
This adds a --enable-systemtap configure option, which will then add static tracepoints to the generated libosmocore binary. At this point, only two tracepoints are supported: log_start and log_done. They can be used to trace the amount of time a libosmocore-using application spends in potentiall blocking calls to log to stderr or to files. Related: OS#4311 Change-Id: I7e1ab664241deb524c9582cbd1bec31af46c747e
2021-02-03gprs_ns2_frgre: check iph/ip6h before passing them to rx functionsAlexander Couzens1-2/+8
With IPv4 and IPv6 support it's not guaranteed that iph/ip6h is valid. Related CID#214288 Change-Id: If9015906917e3ad11d14b84c29d64f28a3158144
2021-02-03gprs_ns2_frgre: set a correct gre pointer for ipv6Alexander Couzens1-1/+5
Also fixes a nullpointer deref because iph is NULL on IPv6 Related: CID#216555 Change-Id: I2ff868a7bba6151a2202df774ff022c02b8c34cb
2021-02-03frame_relay: fix NULL pointer derefAlexander Couzens1-0/+1
Related: CID#215530 Change-Id: Ic58394ab44ee555a0c5dee2b07fa1054093fbcf0
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 Couzens3-9/+15
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-03gprs_ns2_vc_fsm: rename ST_ALIVE -> ST_RECOVERINGAlexander Couzens1-17/+17
ST_ALIVE isn't quite clear. This state means this NS-VC is still dead. ST_ALIVE is used for NS-VC with vc_mode ALIVE (e.g. UDP NS-VC). It's the first state when the remote hasn't yet answered or when the NS-VC lost ALIVEs. Related: OS#4958 Change-Id: I0b29e8ce6444546d90bde68b1f957f1013238784
2021-02-03gprs_ns2_vc_fsm: reset ALIVE N counter when restarting the test procedure.Alexander Couzens1-0/+1
Otherwise a NS-VC would flap between ALIVE and UNBLOCKED state. Related: OS#4959 Change-Id: Id98629bd65f92103e0e571ec388c58b02cb2ccb5
2021-02-02gprs_ns2: prevent division by zero in load_sharingAlexander Couzens1-1/+8
Check if the NSE is alive before passing UNITDATA to the load sharing. Change-Id: I0e2a59bec9b72f74eb64510a2e1ad60486694a55 Fixes: OS#4996
2021-02-02osmo-ns-dummy: Add "mirror-mode" to mirror back any received packetsHarald Welte2-10/+44
Change-Id: If57bfdeb390d88d1ea058f7a9ce0403e64a5beda
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-02ns2: Stop test procedure when going into unconfigured stateHarald Welte1-0/+7
When we're unconfigured and not yet started, we should not transmit NS-ALIVE. Change-Id: Ida3685e42a753899f1bf177eefcc23352ec7440d Related: OS#4999
2021-02-02ns2: Don't automatically re-start FSM at FORCE_UNCONFIGUREDHarald Welte2-1/+1
There are use cases in which the NS-VC FSM should go back to unconfigured _without_ being re-started immediately. Let's permit the caller to do that. Change-Id: I31fe695a83d38ea1f10f5444e840633d7fa68442
2021-02-02frame_relay: cosmetic: Unify log syntax when discarding Rx packetsHarald Welte1-2/+2
Change-Id: I09d035e38b41be9d6ac5e16da7fb113286c77d29
2021-02-02frame_relay: Discard received messages for DLC not yet activeHarald Welte1-7/+10
If we receive messages for a DLC which has not yet reported as being available by Q.933 LMI, drop the incoming message. Otherwise we would dispatch it to the user, and the user wants to respond - but then we reject the transmission due to the inactive DLC. Change-Id: Ia4a045fdf165b526f429f4617e0fdc76036480bd Related: OS#4999
2021-02-02frame_relay: Add status call-backs for link + DLC status changesHarald Welte3-16/+40
Change-Id: Iec19db4e48642c3fcb0aa11fa7787b8323fd0e5a Related: Os#4999
2021-02-01gsm_7bit_encode_n(): fix integer overflow in gsm_septets2octets()Vadim Yanitskiy5-15/+20
Using 'uint8_t' for the length argument is definitely a bad idea. Because of this, packing more than 255 septets would not work as expected. Deprecate the old function and use 'size_t' instead. Change-Id: Ib1aac538afeb0a5c76a1df472d555139a496e12e
2021-02-01gsm_7bit_encode_n(): test encoding of more than 250 septetsVadim Yanitskiy2-0/+70
As can be seen, this unit test reveals problems with encoding of more than 250 septets using gsm_7bit_encode_n(). The problem is that some API functions use type 'uint8_t' for the length, so we basically suffer from integer overflows. Change-Id: I723300578d5ab0c7b94cf49c14d962b2dbf47740
2021-02-01frame_relay: Send "Fuil Status" ENQUIRY after link recoversHarald Welte1-1/+5
If we are the 'user' side of FR and a link has just recovered, we should ensure the next STATUS is for "full status". This way we learn about the present DLCs as quickly as possible, saving up to 10 seconds of further delay in link recovery. Related: OS#4999 Change-Id: I6f905a18a7d130a3c02b4a3e7a2a2dc24afc0ea1
2021-02-01sim: fix gcc 4.9.2 + -std=gnu11 errorOliver Smith1-1/+1
Remove "(const struct osim_card_sw)" infront of OSIM_CARD_SW_LAST, so debian 8's gcc 4.9.2 doesn't fail anymore with the following error each time the macro is used: card_fs_sim.c:105:1: error: initializer element is not constant I verified with docker that there aren't any other build errors with gcc 4.9.2. Fixes: OS#4991 Change-Id: I9d3abbf9812dc09201eff0e9f7542cddedb6848b
2021-02-01ns2: cosmetic: fix indent levelsHarald Welte1-4/+4
Change-Id: Ifcb0d5ddf824cd876de91afca1021aeb4f6c3e8b
2021-02-01ns2: Print NS-STATUS.ind primitives to the logHarald Welte1-3/+10
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-01ns2: Fix typos in commentsHarald Welte1-5/+5
Change-Id: I155fd697e229621561f7d00204421ac941101d77
2021-02-01ns2: Introduce a per-bind stat_item group with backlog lengthHarald Welte4-1/+37
The backlog length indicates the instantaneous length of the backlog. Change-Id: I1c55b4619b1221d7e607ace58649323407faf86b
2021-02-01ns2: Rename nsi->rate_ctr_idx to nsi->nsvc_rate_ctr_idxHarald Welte2-4/+4
We will soon get another of those indexes. Change-Id: I68a2ef3b48097f524831dd04821824b21d6d1e18
2021-02-01ns2: Memory allocation failures are ENOMEM, not ENOSPCHarald Welte4-5/+5
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 Welte6-83/+66
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: Add a rate_ctr for each NS-UNBLOCKHarald Welte3-0/+5
We have one for BLOCK, so let's also add one for UNBLOCK. Change-Id: I693109b7bc4d72b6803b40aae15327389aa37c69
2021-01-31ns2: Implement more rate countersHarald Welte1-1/+5
The counters had all been lost in the ns -> ns2 configuration, let's try to implement some more of them: LOST_ALIVE, BLOCKED, LOST_RESET. Change-Id: I75d8637bd142722fdf9a162a2369aa9cdc980a57
2021-01-31ns2: count number of dropped packets / bytes on transmitHarald Welte3-3/+17
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-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: Increment Rx and Tx byte / packet countersHarald Welte2-0/+6
Change-Id: If5e93f69cddbc8962cbbae38c07b504dd9b1ecd1
2021-01-31ns2: encapsulate calls to nsvc->bind->send_vc()Harald Welte1-12/+17
Don't call the function pointer of the underlying transport directly, as we many still want to do some common processing, such as statistics counting (see follow-up patches). Change-Id: I8d14c7b8d3aacc2bed033072d7934dbd6aab41df
2021-01-31ns2: Use named array initializers to avoid mistakesHarald Welte3-30/+27
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-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-30osmo-ns-dummy: Add simple NS traffic generatorHarald Welte3-1/+312
This adds a simple NS traffic generator that can be used to perform load testing on NS links, particularly those with limited bandwidth such as frame-relay E1 lines. Related: OS#4995 Change-Id: Iad3b694c85962dbbc6b4a27a0ed5bc841add464f
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-29gprs_bssgp: agregate RIM related code in gprs_bssgp_rim.cPhilipp Maier6-293/+307
gprs_bssgp and gprs_bssgp_util.c also contains code related to send and receive RIM PDUs via BSSGP and also code to encode and decode RAN INFORMATION PDUs. Lets move this to gprs_bssgp_rim.c Change-Id: Icda279452962b06e552cb1361d2a27b7dc8a6b04 Related: SYS#5103
2021-01-29gsm: bts_features: Introduce BTS_FEAT_CCNPau Espin Pedrol2-0/+2
This feature is used by BSC to gain knowledge on whether a given BTS supports GPRS Cell Change Notification (CCN) related procedures on PDCH, and as a result enable or not by default the CCN_ACTIVE bit in SI13 to announce the support it is allowed to use the feature. Related: SYS#4909 Change-Id: I61991266b95d0c13d51b47906cc07846e9cf1390
2021-01-29gsm: Fix wrong length in SI13 GPRS Cell Options IEPau Espin Pedrol1-2/+2
Older commit adding the 2 bits for Rel-4 extension forgot to increase the length field (see TS 44.060 Table 12.24.1) Fixes: 946bb95af1838fcf026587c51a6ad36e34e202c3 Change-Id: I20efb4403cdf6c5bc717502a7075630044142f17
2021-01-29cosmetic: fix typo in commentPau Espin Pedrol1-1/+1
Change-Id: I787cca5a032c57202a86dab18e1790ef3ad1509a
2021-01-29ctrl_connection: Initialize write_queue.bfd.fd to -1 during allocationPau Espin Pedrol1-0/+1
Otherwise fd is set to 0 by default, let's avoid accidentally closing it if something goes wrong. Change-Id: I98f744d2880fbb883719cdf1d3eb31f2b22a13b6
2021-01-29ns2: Fix assert when removing a bind listenDaniel Willmann1-1/+1
Change-Id: I3edd1e838f7516d9224045710047419039aa0ec0 Fixes: OS#4977
2021-01-28gprs_ns2: correct vty config writeAlexander Couzens1-16/+26
The vty configuration was wrong when any other node was in between the vty configuration (e.g. gb or ss7). The vty code doesn't have a relation between parent and child node. It wasn't detected because this only happened in the sgsn. The pcu doesn't have any binds defined. Change-Id: I8a3d67d41baca36b4d1a951a574cd41e556355c5