Commit Graph

2633 Commits

Author SHA1 Message Date
Harald Welte 78d7367c90 logging: Attempt a synchronous, non-blocking write first (file, stderr)
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-10-26 17:16:50 +02:00
Harald Welte a0b57d0688 logging: Avoid memcpy from stack to msgb in _file_output()
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-10-26 17:16:50 +02:00
Harald Welte b72867f0e6 logging: Change stderr + file target to use non-blocking write
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-10-26 17:16:47 +02:00
Pau Espin 1573add472 logging: Change LLAPD category color to purple-like one
Previous dark shiny blue one is really difficult to read on the
terminal. Let's change it for some purpleish color which is far easier
to read.

Change-Id: Ia5c0860dd8d756bb24eb8972f94590bfba5bc865
2021-10-15 18:25:06 +00:00
Alexander Couzens 4ef56c0e2d ns2: correct parse a BLOCK PDU which was received over a different NSVC
BLOCK PDU can be send over a different NSVC than the NSVC.
E.g. informing a NSVC got blocked in case of a lower-layer failure.

Change-Id: I483e3a1d3b8c43bbb0cc6185b7f7f772bcb264bf
2021-10-15 13:39:31 +00:00
Alexander Couzens 58be42749e ns2: don't forward an invalid RESET PDU to the FSM
When receiving an invalid RESET (e.g. wrong NSEI or NSVCI) do not
forward the PDU to the NSVC fsm. Answer it with correct NSEI & NSVCI,
log the PDU, then ignore it.

Fixes: OS#5258
Change-Id: I6e562def9c5a1e4534d42884215272b1e66d26c2
2021-10-15 13:39:31 +00:00
Alexander Couzens f8635c7e6f ns2: improve log line when receving a PDU with wrong NSE
Change-Id: I072510461fb426fa62ca20c5103764b0efd25f82
2021-10-15 13:39:31 +00:00
Vadim Yanitskiy c549719088 utils: introduce osmo_talloc_replace_string_fmt()
Change-Id: I6b84fa0525555a98c531fc558e5dc1298fec00c1
2021-10-13 14:03:26 +03:00
Alexander Couzens 69cc4b613b ns2: correct parse a STATUS PDU which was received over a different NSVC
STATUS PDU can be send over a different NSVC than the NSVC which
generated the STATUS PDU. E.g. informing a NSVC got blocked in case of a lower-layer failure.

Change-Id: I5c9e9de10c669c1226da67bb9e2663c5cfe828a8
2021-10-08 05:43:57 +00:00
Alexander Couzens d802f9ae6e ns2: message: allow to pass a foreign NSVCI to STATUS PDU
To answer correct on a BLOCK PDU with a different NSVCI, the
STATUS PDU needs also a NSVCI parameter.

Change-Id: I373eb48697097cdfa45748a091c11f7b3f0345fa
2021-10-08 05:43:46 +00:00
Alexander Couzens cc1621e476 ns2: fsm: add comment don't answer on a STATUS with a STATUS
Change-Id: Ib8f700f9193a96a7bada3b0293dcecf6a05d6efc
2021-10-08 05:43:46 +00:00
Alexander Couzens a2b846be2f ns2: ensure the NSVC is in the correct mode for NSVC UNKNOWN/NSVC BLOCKED cause codes
Those cause codes are only valid for BLOCK/RESET NSVCs.

Change-Id: I560f1c8c2826befd03641bebffe156ac070061c2
2021-10-08 05:43:46 +00:00
Alexander Couzens 67cfc5dc9a ns2: message: BLOCK/BLOCK ACK allow to use a given NSVCI instead of using the nsvc nsvci
The BLOCK and BLOCK ACK PDUs can be send over a working NSVC to inform
the NSE that a NSVC is blocked.

Change-Id: I6189229fdc1f054e86811bc60cb7646e1f758a78
2021-10-08 05:43:46 +00:00
Eric Wild 8ae40cbb91 gsmtap: allow 127.0.0.x local listeners
Even if not bound to a IF they just exist and work as expected, and make
distinguishing traffic for local setups easy.

Change-Id: I1043dfd8075f14481011f43db45c943e9320413c
2021-10-06 13:01:26 +00:00
Vadim Yanitskiy 6dce2cbc1e utils: remove misleading comments for osmo_hexdump[_nospc]_c()
The buffer is allocated dynamically on heap, so there is no such
limitation of 4096 bytes / 1365 characters.

Change-Id: I960dd6a53123fd4209ef6e61dcd0d22e4005e397
2021-10-04 12:37:51 +00:00
Neels Hofmeyr 34907fe6e1 revisit some calls of strtol(), stroul(), strtoull()
Replace some with atoi(), where the VTY has already validated correct
range of the argument.

Replace others with the new osmo_str_to_int() or osmo_str_to_int64()
functions, possibly covering more detection of invalid number strings.

Leave those strtol() callers that depend on endptr to provide the next
string token.

Related: SYS#5542
Change-Id: I0ebb06e751c28f7d1cdf328de29cd227a2449391
2021-10-04 11:24:59 +00:00
Vadim Yanitskiy 6b60d52abf fix rsl_chan_nr_str_{buf,c}(): enlarge the buffer size
20 bytes is not enough for some VAMOS specific channel number values,
so the resulting string representation gets truncated by snprintf():

  expected: "VAMOS TCH/H(0) on TS4\0"
  actual:   "VAMOS TCH/H(0) on T\0"

Let's enlarge the buffers to 32 bytes.

Change-Id: I68d839f4ab742cf56de34e7e22572a1163aec2da
2021-10-01 15:47:05 +06:00
Neels Hofmeyr 6a5940740a refactor stat_item: report only changed values
Change the functionality of skipping unchanged values: instead of
looking up whether new values have been set on a stat item, rather
remember the last reported value and skip reporting identical values.

stats_test.c shows that previously, a stat item reported a value of 10
again, even though the previous report had already sent a value of 10.
That's just because the value 10 was explicitly set again, internally.

From a perspective of preserving all data points, it could make sense to
send consecutive identical values. But since we already collapse all
data points per reporting period into a max, that is pointless.

Related: SYS#5542
Change-Id: I8f4cf34dfed17e0879716fa2cbeee137c158978b
2021-09-30 18:33:43 +00:00
Neels Hofmeyr e90c7176be refactor stat_item: get rid of FIFO and "skipped" error
Intead of attempting to store all distinct values of a reporting period,
just store min, max, last as well as a sum and N of each reporting
period.

This gets rid of error messages like

  DLSTATS ERROR stat_item.c:285 num_bts:oml_connected: 44 stats values skipped

while at the same time more accurately reporting the max value for each
reporting period. (So far stats_item only reports the max value; keep
that part unchanged, as shown in stats_test.c.)

With the other so far unused values (min, sum), we are ready to also
report the minimum value as well as an average value per reporting
period in the future, if/when our stats reporter allows for it.

Store the complete record of the previous reporting period. So far we
only compare the 'max' value, but like this we are ready to also see
changes in min, last and average value between reporting periods.

This patch breaks API by removing:
- struct members osmo_stats_item.stats_next_id, .last_offs and .values[]
- struct osmo_stats_item_value
- osmo_stat_item_get_next()
- osmo_stat_item_discard()
- osmo_stat_item_discard_all()
and by making struct osmo_stats_item opaque.
In libosmocore, we do have a policy of never breaking API. But since the
above should never be accessed by users of the osmo_stats_item API -- or
if they are, would no longer yield useful results, we decided to make an
exception in this case. The alternative would be to introduce a new
osmo_stats_item2 API and maintaining an unused legacy osmo_stats_item
forever, but we decided that the effort is not worth it. There are no
known users of the removed items.

Related: SYS#5542
Change-Id: I137992a5479fc39bbceb6c6c2af9c227bd33b39b
2021-09-30 18:33:43 +00:00
Pau Espin 50e6f06658 gsm: Mark gsm0858_rsl_ul_meas_enc() pointer param const
Change-Id: I9b2704250d8a3f6c6fc6cd2a5136b1408c8ed965
2021-09-28 11:32:00 +02:00
Alexander Couzens ca5ce0d849 ns2: nsvc: add a uptime/downtime to track the last state change
To show adminstrator the last state change of a nsvc add a timestamp and
show it on the vty

> show ns nsei 1234
NSEI 01234: UDP, DEAD since 0d 0h 1m 42s
[...]
  4 NS-VC:
   UNBLOCKED DYNAMIC sig_weight=1 data_weight=1 udp)[127.0.0.1]:22000<>[127.0.0.1]:23001 ALIVE since 0d 0h 0m 1s
   UNBLOCKED DYNAMIC sig_weight=2 data_weight=2 udp)[127.0.0.1]:22000<>[127.0.0.1]:23000 ALIVE since 0d 0h 0m 1s
   UNBLOCKED DYNAMIC sig_weight=2 data_weight=2 udp)[127.0.0.1]:22001<>[127.0.0.1]:23000 ALIVE since 0d 0h 0m 1s
   UNBLOCKED DYNAMIC sig_weight=1 data_weight=1 udp)[127.0.0.1]:22001<>[127.0.0.1]:23001 ALIVE since 0d 0h 0m 1s

Related: OS#5028
Change-Id: Ie3a039a209869295afa5feda39297cee81fedf22
2021-09-23 13:12:34 +02:00
Alexander Couzens 2c64c257c8 ns2: nse: add a uptime/downtime to track the last state change
To show adminstrator the last state change of a nse add a timestamp and
show it on the vty

> show ns nse 1234

NSEI 01234: UDP, ALIVE since 0d 0h 0m 16s
 FSM Instance Name: 'GPRS-NS2-SNS-SGSN(NSE01234-SNS)[0x6120000012a0]', ID: 'NSE01234-SNS'
  Log-Level: 'DEBUG', State: 'CONFIGURED'
  Timer: 4
 Maximum number of remote  NS-VCs: 8, IPv4 Endpoints: 2, IPv6 Endpoints: 0
 [...]

Related: OS#5028
Change-Id: I8143080a3c5c9a55d37dfad44ba2ac6561daa216
2021-09-23 13:12:34 +02:00
Alexander Couzens 06929166de vty: add vty_out_uptime() print the uptime to the vty
vty_out_uptime() calculates the time difference to a given timespec
and print it in a human readable format (days, hours,
minutes, seconds) to the vty.

Related: OS#5028
Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793
2021-09-23 13:12:34 +02:00
Harald Welte d075e3ae23 base64: reformat using Lindent to conform to our coding style
Change-Id: I2286fa0d2cba7c11359bb48329135dfcd0d8a948
2021-09-21 19:57:56 +00:00
Harald Welte 292f9e7014 base64: Migrate over to osmocom
This containts the osmocom changes to the mbedtls base64 code
merged in the previous commit.

Change-Id: I82c1bf5f827c8def370dbcb80b146e9e4184c4a3
2021-09-21 19:57:56 +00:00
Harald Welte c757239fd3 copy base64 implementation from mbedtls
Using mbedtls commit f9c599cd8ac9d00c484d4f5b027e18c6af4f9fdf before
they re-licensed to Apache 2.0, so we have a GPL-v2-or-later bsae64
implementation and avoid having code under a different license in the
tree.

This code is the unmodified import, so we can record any local changes
compared to the original version.

Change-Id: I39a9d3ab98257d21b9439b00528c744efa372c14
2021-09-21 19:57:56 +00:00
Neels Hofmeyr 049fd5ccc0 stat_item: cosmetic: s/desc/group_desc in osmo_stat_item_group_alloc()
There also is an osmo_stat_item_desc, so the name 'desc' makes it hard
to read the code / the upcoming refactoring patches. It is an
osmo_stat_item_group_desc, so call it group_desc.

Related: SYS#5542
Change-Id: I07bc011450549a44ebf043e7d8a70718ddfd900e
2021-09-20 13:04:54 +00:00
Neels Hofmeyr a16b50c5e8 CTRL: expose stat_item groups on CTRL
Expose all stat items as RO variables of the form

  stat_item.last.group_name.N.item_name
  stat_item.last.group_name.by_name.idx_name.item_name

For (possibly contrived) example:

  stat_item.last.trunk.0.endpoints:used
  stat_item.last.trunk.by_name.virtual-0.endpoints:used

Include the 'last' token to ease future extension, like 'max'.
Put this token in the beginning, similarly to rate_ctr variables, which
begin with 'per_sec', 'per_hour', ...

Related: SYS#5542
Related: I178dcf4516606aa561d47b06061b8a416d3c40cf (osmo-ttcn3-hacks)
Related: Ic1b35b7406547f92818afe399a2383d154576409 (osmo-ttcn3-hacks)
Change-Id: Idace66b37492fe96b2f2e133a69cac7960ca279c
2021-09-14 10:28:05 +02:00
Neels Hofmeyr 7fcfefbcf7 add osmo_stat_item_get_group_by_name_idxname()
Add "missing" API for looking up a stat_item_group by its index-name.
A subsequent patch, which adds stat_items to the CTRL interface, will
use this to look up stat item groups by object name.

In stat item groups, there are group names, having a number of indexes
denoting different objects. An object can have, besides the index, also
a name that is equivalent to the index.

Apologies for the weird function name, it's still the best one I
could come up with: "group_by_name" refers to the group name, and
"idxname" refers to the name that the object index is associated with.

We already have osmo_stat_item_get_group_by_name_idx().
Other contestants for name of this new function were:

- osmo_stat_item_get_group_by_name_name()
  because there is a "name" instead of "idx", but I find it confusing.

- osmo_stat_item_get_group_by_name_idx_name()
  but I find that the last "name" should be closer to the "idx".

Related: SYS#5542
Change-Id: Ia1a77a1e4657ba624dd4f4bf7ad274e7751d0141
2021-09-14 10:28:02 +02:00
Neels Hofmeyr 47773344fb utils: add osmo_str_to_int() and osmo_str_to_int64()
Properly converting a string to an integer while validating against all
possible errors is not trivial. It is a recurring theme in code review,
and there are places in osmo code that do it wrong.
End this by providing a simple API, if for nothing else then as an
example of how to use strol() / strtoul() / strtoll() / strtoull()
in an airtight way.

A subsequent patch, adding stat items to the CTRL interface, uses this
to properly validate indexes in CTRL variables and convert them to int.

Related: SYS#5542
Change-Id: I4dac826aab00bc1780a5258b6b55d34ce7d50c60
2021-09-12 21:24:50 +02:00
Eric Wild 11a58a1b34 vty: allow flushing
It was so far sufficient to wait for the buffers to drain at some
random point in time, but this is not always the case, sometimes it is
important that the output is flushed immediately.

Change-Id: If984b9ad2eba9f400bc29a7aa8825e241fd1d2a9
2021-09-10 14:50:26 +02:00
Alexander Couzens a7a757f2ee gprs_ns2: nsvc: react on STATUS PDUs with cause code NSVC UNKNOWN/NSVC BLOCKED
A STATUS PDU with cause code NSVC UNKNOWN/NSVC BLOCKED informs the other
side about a state mismatch between the side.

Change-Id: Ib6a2424f3027a30f14ef0a9fc2230e6aae9a2a04
2021-09-07 20:46:04 +02:00
Alexander Couzens e7873336a2 gprs_ns2: fix a white space
Change-Id: I2207d13ae451ce49482625fac43b6ab1c0f215e8
2021-09-07 20:46:04 +02:00
Alexander Couzens eec4f608b5 gprs_ns2: fix NS STATUS validation
The wrong TLVs were used.

Change-Id: I01339d93469285cc5340500717ab2b696284e12a
2021-09-07 20:46:04 +02:00
Alexander Couzens 9cd9f6d53f ns2: fix a crash when receiving a SIZE while configured
The ns2_vc_force_unconfigured() needs to be protected otherwise it would free
gss->nsvc which will be used later. It further would run into another
SNS failure which is wrong too.

Change-Id: If14b9e3fcd5d139457b10d06517302168091d8d8
2021-09-07 20:46:04 +02:00
Alexander Couzens f27fbf65b7 ns2: nsvc: reject UNITDATA when the remote BLOCK'ed
When the remote initiated the BLOCK the nsvc would still accept UNITDATA
over this nsvc.

Change-Id: I3ed4aa105a84e448082d3028fe844aae7720426b
2021-09-07 20:46:04 +02:00
Alexander Couzens 3178e30206 gprs_ns2: ensure the incoming NSVC is also the outgoing NSVC
Previous the SNS NSVC (the NSVC used for all SNS traffic) was never changed except
when the choosen NSVC went dead or got freed.
When receiving a SNS SIZE PDU over a different NSVC than the current SNS
NSVC the answer would be transmitted to a different port.

Change-Id: I36cd9488b8bca5cb99dae5cf50a55ee282e0557b
2021-09-04 01:31:18 +02:00
Alexander Couzens 1adfd23290 gprs_ns2_sns: ensure the SNS fsm behave correct when no signalling NSVCs are present
When no remaining signalling NSVCs are available the SNS must be
restarted (BSS) or go into unconfigured state (SGSN).

Change-Id: I95e6bbb7a418d647a8426804879571597ae06ff8
2021-09-04 01:26:28 +02:00
Alexander Couzens 8a612de92b gprs_ns2: improve reselection protection
Change-Id: I375a7639fb8e0f92fd67bb4176bd6219978aa428
2021-09-04 01:26:28 +02:00
Alexander Couzens b0874cdf97 gprs_ns2: add correct filename/linenr to sns failed log message
Change-Id: I117eaf8340fca50cb14392a3f05ea8feac1af3ed
2021-09-04 01:26:28 +02:00
Alexander Couzens 616a949456 gprs_ns2: calculate the nse->*_sums before notifing the sns fsm
The sns fsm needs these information to determine if there is a signalling nsvc left

Change-Id: I7b115921780bd1ae895d8b9d0d4aec3e1cbaaf58
2021-09-04 01:26:28 +02:00
Alexander Couzens c2fec69baa gprs_ns2: also prevent recursive events when SGSN side cleans up
When cleaning up the SGSN side (e.g. receiving a SNS SIZE PDU) the
clean up will result in a use-after-free bug when the SGSN side is still
alive.

Change-Id: I0f57dd0577d1fc7bd270f58e15f6f22eb130ef59
2021-09-04 01:25:32 +02:00
Alexander Couzens db07a44988 gprs_ns2_sns: implement outbound SNS DEL procedures
When removing a bind the remote side needs to be
informed via the SNS DELETE procedure.

Related: OS#5036
Change-Id: I53cd54dfd262c70c425c3f13dad3b29526daa523
2021-09-04 01:10:16 +02:00
Alexander Couzens 9cd39ac6ac gprs_ns2_sns: implement outbound SNS ADD procedures
When adding a bind, the remote side needs to be
informed via the SNS ADD procedure.

Related: OS#5036
Change-Id: I71c33200bd1f0307ceb943ee958db5ebe3623d36
2021-09-04 00:00:48 +02:00
Alexander Couzens 1f3193d344 gprs_ns2_sns: implement local change weight procedure
When changing the bind ip-sns weight, initiate a
SNS CHANGE WEIGHT procedure to inform the other side.

Related: OS#5036
Change-Id: Icec4dabb46bc198f68f91bfe09ba279fbe68d454
2021-09-04 00:00:48 +02:00
Alexander Couzens f074659520 gprs_ns2: don't use llist_for_each when freeing an element
The problem are recursive execution because a free generates an event which could
allow the use to free a nsvcs while the llist_for_each() is still running.

Change-Id: I902557fb6e56e6588728a46e43a9cbe3215d5c68
2021-09-04 00:00:48 +02:00
Alexander Couzens 4bfcce6c54 gprs_ns2: gprs_ns2_free_bind() should remove itself before removing nsvcs
When removing NSVCs before removing the bind from the SNS list, the removing NSVCs could
trigger a creation of a new NSVC on the same bind ending in a
while(true) loop.

Change-Id: I6f497348f75fb479427d8a4c23313e33fbc62036
2021-09-04 00:00:48 +02:00
Alexander Couzens 83f06cea0a gprs_ns2: use an event to free the nsvscs when using SNS
Otherwise there could be recursive loop when free'ing NSVCs which
in the end create an event which the SNS want to free the NSVCs a
second time

Change-Id: Ie99ba5fe8a84519fe8a8c0abdf875606715ab7f6
2021-09-04 00:00:48 +02:00
Alexander Couzens a27078266a gprs_ns2_sns: rework sns clean up
Move the cleanup into it's own state. Also changing the
SGSN unconfigured state which won't be triggered when a
SIZE is received.

Change-Id: I2639345fdf3cd300a934238d676c543065ceaa8b
2021-09-04 00:00:48 +02:00
Alexander Couzens 175eb7be1b gprs_ns2: move sns_event into internal.h to direct emit events
When other parts of ns2 requires to emit an event to the SNS fsm it would
need a proxy function because the events are private to the
SNS file. To circumvent creating multiple proxy function make the events
available via a header file.

Change-Id: I8e3fae4367c112b5a71bffb33c302d903855cddc
2021-09-04 00:00:48 +02:00
Pau Espin 51933840ff gsm_08_58.h: Extend IPA Power Control Params IEs to pass C/I params
This commit adds new Osmocom specific IEs required to pass C/I related
Power Control Parameters osmo-bsc => osmo-bts to be used by the MS Power
Control Loop being implemented.

Related: SYS#4917
Change-Id: Iffef0611430ad6c90606149c398d80158633bbca
2021-09-03 15:32:50 +00:00
Philipp Maier 58f76d8b90 bts_features: Add new feature to indicate support for temporary overpower
To indicate to the BSC that a BTS supports temporary overpower of
SACCH/FACCH channels a new feature BTS_FEAT_ACCH_TOP is added.

Change-Id: I62fbfc30acd5d67b20727b75a8f256e6b5d31e06
Related: SYS#5319
2021-08-31 19:54:28 +00:00
Philipp Maier 0e44a7203c rsl: add new RSL IE to signal temporary overpower
To transfer the temporary overpower value from the BSC to the BTS, a new
RSL IE (RSL_IE_OSMO_TOP_ACCH_CAP) is added.

Change-Id: I31c5be4bceb9140d63ab8e2f197f0acc68699426
Related: SYS#5319
2021-08-31 19:54:28 +00:00
Philipp Maier cfea39ba13 gsm0503_coding: use ahs tables when encoding ahs codec id
The encoder function gsm0503_tch_ahs_encode uses gsm0503_afs_ic_ubit
when encoding the CMR or FT (depends on the frame number). This is not
correct. It should use gsm0503_ahs_ic_ubit instead.

Change-Id: Id250b2102ac79ff222bd3ad9d1abc4b60abdd12b
Related: SYS#5549
2021-08-31 16:05:20 +02:00
Neels Hofmeyr 923cb84270 vty 'stats reset': do not reset stat_items
Exempt all stat_item statistics from 'stats reset'. Only reset rate_ctr
statistics to zero.

The rate_ctr statistics have an implicit time scale, counting occurences
per time unit. For them it makes sense to reset all ratings and start
from zero, for example in a test suite (e.g. our TTCN3 BSC_Tests).

In contrast, stat_item statistics count number of objects or nr of
specific object stati at any given time, and they do not deteriorate
over time. Many stat items depend on increment/decrement to be sane.

For example, in osmo-bsc, if the nr of connected BTS is 3, that does not
make sense to be reset to zero. There are still 3 BTS connected, only
the stat_item would suddenly reflect zero. From then on, it'd be wrong.

All stat_items are by definition wrong after a 'stats reset'.
- Those that depend on increment/decrement will be wrong until the
  program exits, and
- those that are set to absolute values will be wrong up until the next
  value is set. That could be seconds or hours later, depending.

Related: SYS#5542
Change-Id: If2134768b1076e7af189276c45f2a09a4944303e
2021-08-23 21:22:16 +02:00
Oliver Smith 11da4a4abd stats: send real last value if no new values come
Background:
* Individual values can be added to osmo_stat_item.values at any time.
* Stats are reported at a fixed interval (see vty 'stats interval'),
  e.g. every 10 seconds.
* In order to report a new stat value, we use the maximum of all
  osmo_stat_item.values added since the last report.
* By default, we do not send new stat values if they did not change
  (see vty 'config-stats' -> 'flush-period' default of 0).

Fix the following bug:
* If 'flush-period' is 0, and no new osmo_stat_item.values are coming
  in, the last value that gets reported is not necessarily the last
  entry in osmo_stat_item.values.
* For attached reporters (statsd), it could then be that the given stat
  stays at the wrong value for a long stretch of time (think of several
  hours/days/forever).

Explanation of how the test shows that it is fixed:
* stats get reported (value is irrelevant)
* osmo_stat_item gets a new value: 20
* osmo_stat_item gets a new value: 10
* stats get reported (value: 20, the maximum of both new values)
* osmo_stat_item gets no new values
* stats get reported (value: 10, this is new because of the bug fix,
  the real last value in osmo_stat_item, different from the 20 sent
  earlier, without the fix it would not send anything here and the last
  sent value would be 20)
* osmo_stat_item gets no new values
* stats get reported (nothing gets sent, since the real last value was
  already sent and 'flush-period' is 0)

Fixes: OS#5215
Change-Id: Ibeefd0e3d1dbe4be454ff05a21df4848b2abfabe
2021-08-20 14:04:54 +00:00
Alexander Couzens 41589a3e7a gprs_ns2: add recursive anchor to protect against double free
When free'ing a NSE/NSVC/BIND ensure there can't be a double
free by using a free anchor in the struct.

Recursive free's can happen when the NS user reacts on an event
(e.g. GPRS_NS2_AFF_CAUSE_VC_FAILURE) and calls the free().
Or when the user free's a NSVC when the NSE uses SNS as configuration,
the fsm tries to free it again.

Change-Id: If9823aadaa936e136aa43e88cee925ddd5974841
2021-08-13 09:55:51 +00:00
Alexander Couzens 1c40525f44 gprs_ns2_sns: free the NSE if the SIZE PDU is not valid
The SGSN fsm should be freed when becoming invalid instead of going
into the unconfigured state. The unconfigured states should be only used
when creating the NSE (on the SGSN side).

Change-Id: Ife889091ecba4180a90743deb786767008fe863d
2021-08-13 09:55:51 +00:00
Alexander Couzens 652ab4da5f gprs_ns2_sns: refactor SNS failures into a function
The SNS fsm is similar for BSS and SGSN.
Terminate the SGSN failures by freeing the NSE.

Change-Id: I1896f6c3ddb4f98ca261139c1cc77aa8f1558c6f
2021-08-13 09:55:51 +00:00
Alexander Couzens 20ed591036 gprs_ns2_udp: don't start the NSVC fsm for SNS
The SNS code will always create NSVC on it's own. The only case
when the SNS dialect allows dynamic NSE/NSVC is on the SGSN side when accepting
dynamic NSE and receiving the first SNS SIZE. In this case the NSVC FSM must not be started yet.
Prevents sending NS_ALIVE before the SNS configuration has been
finished.

Change-Id: I86275c99432262b3c19c1ded9a77090b74303bc8
2021-08-13 09:55:51 +00:00
Oliver Smith 053ad96600 vty: clear screen with ^L
Use ANSI escape characters to clear the screen with ^L, like it works
in typical Linux shells. I always found it slightly inconvenient that
this didn't work in the VTY.

Change-Id: Ie2356cd92f39b4dc28b5c20bbe4557fb0d972747
2021-07-27 12:38:28 +00:00
Pau Espin 26a42c0783 gb/bssgp: Abort clearly if backward-compat API is used in wrong way
Some tests under osmo-pcu (TbfTest) were caught accessning NULL pointer
bssgp_nsi in bssgp_tx_llc_discarded triggered by timeout while stepping
slowly with the debugger.

It seems that test is not properly using neither the old nor the new
API. Let's catch such cases easily.

Change-Id: I3ea42755c4bfd29e4a01ad57f186f28d58ab466a
2021-07-26 14:39:46 +02:00
Pau Espin f26490b07b cosmetic: gb/gprs_ns.c: fix trailing whitespace
Change-Id: I842efdb93c9b480d5ab35c78b0bc60697262874a
2021-07-26 14:35:23 +02:00
Oliver Smith 95a03e54ef vty: show uptime: use timespecsub
Related: OS#4609
Change-Id: If94795b3cd74040c49bdcbed8c410bf6e950afff
2021-07-19 09:01:15 +02:00
Pau Espin 6fe865daae Make gcc 11.1.0 false positivies happy
After my system's gcc was upgraded, I get false positivies in a couple
places. Let's initialize those to make gcc happy.

"""
/git/libosmocore/src/socket.c: In function ‘osmo_sock_init’:
/git/libosmocore/src/socket.c:958:25: error: ‘sfd’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  958 |                         close(sfd);
      |                         ^~~~~~~~~~

/git/libosmocore/src/gsm/gsm48.c: In function ‘osmo_mobile_identity_decode’:
/git/libosmocore/src/gsm/gsm48.c:690:20: error: ‘str_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  690 |         if (rc < 1 || rc >= str_size) {
      |             ~~~~~~~^~~~~~~~~~~~~~~~~
/git/libosmocore/src/gsm/gsm48.c:679:22: error: ‘str’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  679 |                 rc = osmo_bcd2str(str, str_size, mi_data, 1, 1 + nibbles_len, allow_hex);
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

Change-Id: I8aacfbc21e23f63a65e8baee3fd536a1fe1bdd8a
2021-07-16 16:01:30 +00:00
Oliver Smith 8a482fd0a8 vty: add "shutdown"
Kill programs with SIGTERM with the new vty command, as it would happen
with "systemctl stop".

I've considered running the select shutdown logic too in order to ensure
that pending OSMO_FD_WRITE requests are serviced. But as noted in
review, it's better to ensure that the regular SIGTERM code path works
as expected and call that instead of introducing an alternative code
path.

Closes: OS#4609
Change-Id: I3596a35b0f4a24e49484ec3f24a98e4d4f583e1e
2021-07-15 12:51:44 +02:00
Oliver Smith 0c78bc628e vty: add "show pid"
Related: OS#4609
Change-Id: Ib636050afc1eed134f450f2f1cdd3b51153b0160
2021-07-15 12:51:44 +02:00
Oliver Smith d243c2ad73 vty: add "show uptime"
Related: OS#4609
Change-Id: Ic7d9d5d3c8a9abd06a7e626aed7679f68406040c
2021-07-15 12:50:24 +02:00
Alexander Couzens a140d44a4f gprs_ns2: ensure the NSE becomes dead when FR link went down
The FR code is using force unconfigured to change the state of the NSVC
when the FR link goes down. The force unconfigured state didn't
notified the NSE when changing into this state.

Related: SYS#5533
Change-Id: I4d7bbbbce26f7cde99eebe96995c50b1e812e5bd
2021-07-13 07:43:06 +00:00
Daniel Willmann efa64f9429 Aggregate NSVC stats inside the NSE
Change-Id: Ifa3c85ec52bda14596e9d7a8705baa1fd4ee2010
Related: OS#4998
2021-07-09 20:35:00 +02:00
Neels Hofmeyr 5aa421f7c1 fix api doc of osmo_identifier_sanitize_buf()
The implementation cleary replaces sep_chars instead of keeping them.
Adjust the doc to clarify that.

It seems to me that the intention was to *allow* sep_chars instead of
replacing them, especially when looking at sep_chars of
osmo_separated_identifiers_valid(). But we're stuck with that now.

Change-Id: Ia842a7eeb46b49ee364be55c1194e463ebcaf392
2021-07-09 11:52:17 +00:00
Alexander Couzens 5e040bf1f1 gprs_ns2_vty: dump_nsvc: change output depending on NSVCI
If the NSVCI is valid, there is no signalling or data weight defined (internally this is 1).
For NSVC with NSVCI don't print the signalling or data weight.
For NSVC without NSVCI, don't print NSVCI at all.

Related: OS#5180
Change-Id: Iaadc806a9136436468e2b02eb0bc1f4570a10ecc
2021-07-06 09:50:23 +00:00
Alexander Couzens 6ba77a3770 gprs_ns2: fix wrong format string in Tx Size logline
Don't use %u for integer.

Change-Id: I324836ec4943c97f0dbc16ade697c468eba02b35
2021-07-06 09:50:00 +00:00
Alexander Couzens 56287d26fe gprs_ns2: use gprs_ns2_free_bind() to clean up a bind
gprs_ns2_free_bind() takes care of all required steps to clean up a bind.
The driver->free_bind() operation only cleans up the driver internal state
but not NSVCs and other generic things.
Fixes a crash when free'ing a bind from the vty which has active NSVCs.

Related: OS#5195
Change-Id: I0a2ad22905bcacb929b9b5f5b034af0da3081826
2021-07-06 11:21:30 +02:00
Alexander Couzens 31cf166511 gprs_ns2: correct mtu value in the log line
The log line should describe what's reported towards the NS user
and not the NSE MTU itself

Related: OS#5192
Change-Id: I3f5445a1ba8c89c4023ff48be15a80569a128528
2021-07-02 17:38:12 +02:00
Alexander Couzens a6096ad367 gprs_ns2: fix check of MTU changes for frame relay
The frame relay needs 2 byte for data packets.

Related: OS#5192
Change-Id: I02d4e81896a473aeb79ea2f2983e12324244048f
2021-07-02 17:38:02 +02:00
Alexander Couzens db7b2ab36b gprs_ns2: fix crash when changing the MTU
When the MTU changes for any fr device, all
NSE will recalculate their MTU. If any NSE is alive,
libosmocore will crash.

Related: OS#5192
Change-Id: I31ba5cefea7bbb0b74060d6664b42c58815ee2a1
2021-07-02 17:38:02 +02:00
Pau Espin d9825c0a2c bts_feature: Introduce feature to confiure dyn ts as sdcch8
This feature signals support to configure Osmocom Dynamic Timeslot type
as SDCCH8, on top of historically supported TCH/H and TCH/F.
The idea is that when unneeded, the TS is configured as PDCH, and as
soon as there's need for an SDCCH and there's none available, the TS is
dynamically reconfigured to SDCCH8. Once all logical channels in the
dynamic TS are released and hence becomes free, the BSC will reconfigure
it to PDCH.

Related: SYS#5309
Change-Id: Ifc0ca8916bd3e93e5a60a7dd7391d2588fdb5532
2021-06-30 13:15:02 +02:00
Pau Espin 45dc9d00fe Rename osmo dyn ts enums
They will gain support to be activated as SDCCH/8 soon too. Since new
name would start to be too large, use a more generic naming for it.

Related: OS#5309
Change-Id: I56dcfe4d17899630b17f80145c3ced72f1e91e68
2021-06-30 13:14:08 +02:00
Neels Hofmeyr 26e53b181c add fixme: enforce 8 byte length of Kc
Change-Id: I57efb0a24cb71b365189eccb5088b130fad15093
2021-06-29 22:35:03 +02:00
Daniel Willmann c7f547f897 ns2: Ignore NSVC with data_weight 0 for data
Change-Id: If0c2bee285f85110771326e07b513fc3e3f9d3f0
Fixes: OS#5189
2021-06-29 13:18:42 +02:00
Vadim Yanitskiy 1c2a329f85 bts_features: add feature for BCCH carrier power reduction mode
Change-Id: I69283b3f35988fc7a1a1dcf1a1ad3b67f08ec716
Related: SYS#4919
2021-06-25 19:34:52 +02:00
Neels Hofmeyr e4378b7e38 gsm0808: add Kc128 to Handover Request
Change-Id: Ieb6e43eef9e57281d54d4b7c63664668df5aef3e
2021-06-25 08:19:04 +00:00
Alexander Couzens 8138c53a32 gprs_ns2_vc_fsm: reset the ALIVE response time when stopping test
Prevent showing a response time when the NSVC has failed.

Related: OS#5089
Change-Id: I5435077d35ff1ae3d743ea1b1b8ace7f0fb913cf
2021-06-25 08:12:39 +00:00
Alexander Couzens e09deb6355 gprs_ns2: fix missing notify towards the NSE when NSVC become blocked
The NSE wasn't notified when a NSVC went into the BLOCKED state from
an UNBLOCKED state.

Related: OS#5182
Change-Id: I09634e414e9bb966e6b5809b7de1b59fbabd413d
2021-06-25 08:12:39 +00:00
Alexander Couzens d5cd8c61cb gprs_ns2: use llist_add_tail to keep order
When configuring multiple NSE/BINDs the order of the configuration
should be keeped.

Related: OS#5181
Change-Id: Ibbc03f0780b49543b5bd97ee059f11cfd6c2a126
2021-06-25 08:12:39 +00:00
Neels Hofmeyr 4a9756c17a add Kc128 to gsm0808 Create Ciphering Command
Prepare for A5/4 support in osmo-msc.

Add new function gsm0808_create_cipher2() which takes a struct as
argument instead of individual fields. This is akin to e.g.
gsm0808_create_handover_request() below in the file, and allows
backwards compatibly extending the argument list without needing a new
function signature every time.

Add struct gsm0808_cipher_mode_command, as argument list for
gsm0808_create_cipher2(), with kc128 included.

Encode the Kc128 IE in gsm0808_create_cipher2().

Implement gsm0808_create_cipher() by calling gsm0808_create_cipher2().

Change-Id: Ib3906085e0c6e5a496a9f755f0f786238a86ca34
2021-06-21 00:36:46 +02:00
Philipp Maier eabc6fd4b1 vty: make function cmd_range_match() public
Certain control interface commands also may require to verfy a range in
their verify function. cmd_range_match() from the VTY does exactly that
and the range can be specified as string, the same way as we would
specify it in the VTY.

Change-Id: I53fc207677f52b1dc748b01d58424839cdba807c
related: SYS#5369
2021-06-18 12:31:01 +00:00
Neels Hofmeyr ac49bda4d4 osmo_select_shutdown_request(): allow finishing pending writes on SIGTERM
Allow telling osmo_select_main* to only service pending writes (shutdown
mode). Introduce API fuctions to indicate a shutdown request, and find
out whether shutdown is complete.

Some osmo programs have a curious sleep of few seconds upon receiving
SIGTERM. The idea presumably was to finish off pending writes before
halting the program. But a sleep() on program exit is annoying,
especially when there usually are no pending writes, and when osmo-bsc
is launched numerous times for tests.

Change-Id: Ib94d4316924103459577087c2214188679db2227
2021-06-18 12:22:44 +00:00
Daniel Willmann 8158882b54 stats_vty: Improve generation of osmo counters
Use section for all counter headings, the idea is that the generated doc
is included below a chapter describing the implemented counters which
can optionally describe individual items.

If not osmo_counters are present simply omit the whole section to tidy
up the manual. Those are deprecated anyway and not used in the osmo-*
projects that I checked.

Change-Id: I126b39cb9458e0f62efa338967e07151a0eece0f
Related: SYS#5005, OS#4523
2021-06-16 20:39:06 +00:00
Philipp Maier b6fd8edae9 control_cmd: fix typo
Change-Id: I9deaee42aeb0ab0549cc7c4f180ad9c216b9df39
2021-06-16 20:31:58 +00:00
Pau Espin d1b0716242 ctrl: Support recovering from short write
osmo_wqueue has support for it, so simply handle it correctly in the
callback (updating buffer and returning -EAGAIN).

Related: OS#5169
Change-Id: I6cbc7ec6ae6832e61cddf4402332ba09b142a7d4
2021-06-15 16:29:44 +00:00
Pau Espin f5b8ed14a9 ctrl: Pre-calculate required size before allocating msgb
This commit fixes crash when response is more than ~4096 chars.
Furthermore, we now allocate only the required memory, not 4096 for all
messages, which usually don't require it.
Test needs to be adapted since it assumed there was more available space
at the end of the msgb.

Related: OS#5169
Change-Id: I0b8f370f7b08736207f9efed13a0663b5e482824
2021-06-15 16:29:44 +00:00
Alexander Couzens 68ab9c4193 gprs_ns2_sns: bss: set gss->family
gss->family (and gss->ip) was never set.
So IPv6 should have never worked.

Fixes: e769f5226b ("gprs_ns2_sns: rework IP-SNS initial remote")
Related: OS#5036
Change-Id: I4e39dc5c7f766a7040645ceb62afdf6a9cfad00f
2021-06-13 18:31:51 +00:00
Alexander Couzens 077ce5ac94 gprs_ns2_sns: replace ns2_sns_type with address family
Reduces the code as the conversion between address family (bind)
and ns2_sns_type is not needed anymore.

Related: OS#5036
Change-Id: I1bcdd43af34c926d4b88491d00669422c299bef7
2021-06-13 18:31:51 +00:00
Alexander Couzens 019da4b082 gprs_ns2_sns: refactor nss_weight_sum_data -> ip46_weight_sum_data
Allow to use ip46_weight_sum_data for local endpoints as well.

Related: OS#5036
Change-Id: I75d88f3da89ad13e34a3fd5ae72bd967d81f4abc
2021-06-13 18:31:25 +00:00
Alexander Couzens 6231055645 gprs_ns2_sns: refactor ip4_weight_sum/ip6_weight_sum
Use the new introduced struct ns2_sns_elems instead of
the elems seperate.

Related: OS#5036
Change-Id: I0956ab6085554210569188f52cae121e32fca19b
2021-06-13 18:31:25 +00:00
Alexander Couzens cc56ddcdd0 gprs_ns2_sns: add check for duplicates to add_ip6_elem()
The ip4 version already checks for duplicates.

Related: OS#5036
Change-Id: I4a1528ea3427946ce465085919b2b522d3cedd07
2021-06-13 18:31:25 +00:00
Pau Espin 42bb125df1 bts_feature: Introduce feature to speak to PCU
This feature provides the BSC with information on whether the BTS talks
the IPAC_PROTO_EXT_PCU osmocom extension over the underlying IPA
multiplex of the OML link.

Related: SYS#5303
Change-Id: Id62421f7f5540875ac877a187757f2cf0556bd02
2021-06-11 16:36:29 +00:00
Michael Iedema a667d85a92 ns2: use same name in ctr_group as stat_item_group
Change-Id: I7d2dcb6c7ddf72a0d06ff19f5d0e3dc740bd19ff
2021-06-10 12:57:04 +00:00