Commit Graph

3885 Commits

Author SHA1 Message Date
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
Harald Welte 855155c6ae ns2_fr: Fix heap-use-after-free in error recovery path
<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-11 16:07:46 +01:00
Harald Welte ce6e4b79b8 ns2_fr: Fix null pointer deref in error path
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-11 16:07:45 +01:00
Harald Welte cc2e112e9a README.md: Use https everywhere
Change-Id: I06d28ea1f5decffbd89f8439fae948e022bf3fe3
2021-02-11 11:57:13 +01:00
Pau Espin Pedrol c31809faf3 cosmetic: Move comment one line below in append_gprs_cell_opt
Move it above the place where the bit is set, since the bit represents
whether Extension Information is available, not whether R99 is
available.

Change-Id: Ice592acc50a24efd7fe4cf1a91f1d48fd74f38d8
2021-02-10 15:04:22 +00:00
Alexander Couzens 3e2e4a017a gprs_ns2_vty: fix memory leak of vty_binds
They never got freed, only removed from the vty_bind queue.

Change-Id: I100897c32dc152f9acbb322782fae49b1f0bc030
2021-02-09 16:48:03 +01:00
Alexander Couzens 5fa431ccd5 gprs_ns2: rename vty-command ip-sns -> ip-sns-remote
In prepration to introduce more commands e.g. ip-sns-bind rename the ip-sns-remote

Related: SYS#5354
Change-Id: Ida979f3b9daa5f7280a629441e4006a7635653b0
2021-02-09 16:48:03 +01:00
Alexander Couzens 790a963fa2 gprs_ns2_sns: reset the N of timeout when entering a new state
Otherwise retries are splitted between the states.

Related: OS#5355
Change-Id: Iefde0c89965f0be899d6d1f096480f6fc79a92be
2021-02-09 16:46:16 +01:00
Alexander Couzens 3df5886c57 gprs_ns2_sns: add timeout to ST_CONFIG_SGSN
The state CONFIG_SGSN must be also protected by the timeout Tsns-prov.

Related: OS#5355
Change-Id: I2700c1ad40ebe30658e9937d86a4861b0b59d6b6
2021-02-09 16:46:16 +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
Harald Welte 9811f498d4 ns2: Don't try to add packets to the backlog on real errors
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-08 18:36:21 +01:00
Harald Welte 6972aedb51 ns2: improve backlog handling on interface up/down
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-08 18:36:21 +01:00
Harald Welte 93740619af ns2: Don't queue Q.933 LMI messages; only store most recent ones
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-08 18:36:21 +01:00
Harald Welte b339cbb3ef ns2: Name NSVC FSM events consistently
Reading a log line like this:

<0026> gprs_ns2_vc_fsm.c:808 GPRS-NS2-VC(FR-hdlcnet1-DLCI16-NSE02001-NSVC00001)[0x6120000024a0]{UNBLOCKED}: Received Event RESET

is very ambiguous. Does it mean we received a NS-RESET message? Does it
mean the FSM was instructed to send a NS-RESET? ...

Let's make sure the human-readable names give a very clear indication
of what exactly is happening.

Change-Id: I8b7615b3eca04212831163ff0ea4aea35069cd0e
2021-02-08 18:36:21 +01:00
Pau Espin 15b5acb332 Fix struct bitfields on big endian systems
Changes done by contrib/struct_endianess.py.

Change-Id: Ia9cb1ef2ba2bfff9ef713c7d1cf388931dae1c46
2021-02-08 17:23:25 +00:00
Vadim Yanitskiy 53aff13af4 tlv: clarify documentation for msgb_tv{16,32}_put()
Change-Id: Ie439822e0587012e108f67ba4e73771dc684b95b
2021-02-06 16:09:13 +00:00
Vadim Yanitskiy d397a53cfc tlv: add msgb_tv32_put(), similar to msgb_tv16_put()
Change-Id: I11301b20038aa5d90d46d968f7eda3d53b560022
2021-02-06 16:07:54 +00:00
Vadim Yanitskiy e3d32d574e bssgp_bvc_fsm: check return value of osmo_fsm_register()
Change-Id: I0ade2e476a035bb44b2f135ece4552d015852274
Fixes: CID#215717
2021-02-05 20:10:16 +01:00
Vadim Yanitskiy 1c4fc227d9 gsm0808: use msgb_tv16_put() and osmo_store32be()
This API makes the code simpler and easier to read.

Change-Id: Ibe9eaaa2a9344ba798631b8f115ad248f0a2f76b
2021-02-05 20:10:16 +01:00
Harald Welte f3dc0f94c3 frame_relay; Fix Q.933 async STATUS at DLC creation
Fix the encoding of the asynchronous Q.933 STATUS message
we send at DLC creation time.

Change-Id: Id1460ffa6266be85f44579c447421eed12481b02
Closes: OS#5010
2021-02-05 11:10:48 +01:00
Harald Welte 8373c05a35 gb: frame_relay: Detect link outage on "last receive seq nr == 0"
this is a bit of a hack.  Q.933 explicitly forbids either side from ever
sending a sequence number of '0'.  Values start from '1' and are modulo 256,
but '0' is always skipped.  So if the peer is sending us a "last received
sequence number of '0' it means it has not yet received any packets from us,
which in turn can only mean that it has just been restarted.  Let's treat
this as "service affecting condition" and notify upper layers.  This helps
particularly in recovering from rapidly re-starting peers, where the Q.933
nor NS have time to actually detect the connection was lost.

Change-Id: I960a7b17f2550cb49a7b9d72ed87cd271bb64122
Related: OS#4974
2021-02-04 19:28:02 +01:00
Harald Welte cfe0ed63fa gb: frame_relay: Factor-out function to set link as dead
Change-Id: I624b6a1175cf7d59173dfff02d6197bb644b9072
2021-02-04 19:28:02 +01:00
Philipp Maier d11a5d5b9a gsm48: add compare function for struct gprs_ra_id
Comparing struct gprs_ra_id using memcmp can be error prone, so lets add
a compare function to compare two struct gprs_ra_id values reliably.

Change-Id: I4d7558c04d9d01761516526086be5104bb2eeada
Related: SYS#5103
2021-02-04 15:17:41 +01:00
Harald Welte 700822b305 Enable systemd-journald log target in debian + rpm packaging
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-03 14:56:17 +01:00
Harald Welte 433005c87c initial support for static userspace probes via systemtap
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-03 13:55:40 +00:00
Alexander Couzens dc43f7d3c7 gprs_ns2_frgre: check iph/ip6h before passing them to rx functions
With IPv4 and IPv6 support it's not guaranteed that iph/ip6h is valid.

Related CID#214288

Change-Id: If9015906917e3ad11d14b84c29d64f28a3158144
2021-02-03 14:37:54 +01:00
Alexander Couzens 47ed2a6b4a gprs_ns2_frgre: set a correct gre pointer for ipv6
Also fixes a nullpointer deref because iph is NULL on IPv6

Related: CID#216555
Change-Id: I2ff868a7bba6151a2202df774ff022c02b8c34cb
2021-02-03 14:37:54 +01:00
Alexander Couzens ca3550a261 frame_relay: fix NULL pointer deref
Related: CID#215530
Change-Id: Ic58394ab44ee555a0c5dee2b07fa1054093fbcf0
2021-02-03 14:37:54 +01:00
Alexander Couzens 24d9e80911 gprs_ns2_fr: free_bind(): first do the NULL check before using members
Change-Id: I80f72ada15b477d735bf5aee36a5d67e80eb0136
2021-02-03 14:37:54 +01:00
Alexander Couzens c80a874932 gprs_ns2: unify the handling of **result when bind already present.
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-03 14:37:54 +01:00
Alexander Couzens d3e31102fb gprs_ns2_vc_fsm: rename ST_ALIVE -> ST_RECOVERING
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-03 14:37:41 +01:00
Alexander Couzens 2f8f7b62b3 gprs_ns2_vc_fsm: reset ALIVE N counter when restarting the test procedure.
Otherwise a NS-VC would flap between ALIVE and UNBLOCKED state.

Related: OS#4959
Change-Id: Id98629bd65f92103e0e571ec388c58b02cb2ccb5
2021-02-03 11:08:00 +01: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 9bbb703a95 osmo-ns-dummy: Add "mirror-mode" to mirror back any received packets
Change-Id: If57bfdeb390d88d1ea058f7a9ce0403e64a5beda
2021-02-02 11:37:48 +00:00
Harald Welte 9d28ce5fd3 ns2: Don't start sending NS-RESET until FR DLC is available
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-02 11:37:48 +00:00
Harald Welte 6a9ec42a95 ns2: Stop test procedure when going into unconfigured state
When we're unconfigured and not yet started, we should not transmit
NS-ALIVE.

Change-Id: Ida3685e42a753899f1bf177eefcc23352ec7440d
Related: OS#4999
2021-02-02 11:37:48 +00:00
Harald Welte 7fe8d71fee ns2: Don't automatically re-start FSM at FORCE_UNCONFIGURED
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-02 11:37:48 +00:00
Harald Welte d6cec24fa1 frame_relay: cosmetic: Unify log syntax when discarding Rx packets
Change-Id: I09d035e38b41be9d6ac5e16da7fb113286c77d29
2021-02-02 11:37:48 +00:00
Harald Welte 36c5e2b3e0 frame_relay: Discard received messages for DLC not yet active
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-02 11:37:48 +00:00
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
Vadim Yanitskiy 943133cad8 gsm_7bit_encode_n(): fix integer overflow in gsm_septets2octets()
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-01 17:47:54 +00:00
Vadim Yanitskiy 44ac4f6c92 gsm_7bit_encode_n(): test encoding of more than 250 septets
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-01 16:14:55 +00:00
Harald Welte 2319014f7e frame_relay: Send "Fuil Status" ENQUIRY after link recovers
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-01 14:30:53 +00:00
Oliver Smith af916f1c7b sim: fix gcc 4.9.2 + -std=gnu11 error
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-01 09:19:34 +00:00
Harald Welte d083576064 ns2: cosmetic: fix indent levels
Change-Id: Ifcb0d5ddf824cd876de91afca1021aeb4f6c3e8b
2021-02-01 09:43:13 +01: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 a3f7323288 ns2: Fix typos in comments
Change-Id: I155fd697e229621561f7d00204421ac941101d77
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