Commit Graph

1599 Commits

Author SHA1 Message Date
Vadim Yanitskiy e59e839dd9 core/utils.h: add OSMO_LIKELY / OSMO_UNLIKELY macros
These macros are built on top of the __builtin_expect() function [1],
which provides the compiler with branch prediction information.

Similar macros exist in the Linux kernel: likely() / unlikely().

[1] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

Change-Id: I0b029654ba050f079eed4a0574a3fa8019677067
2022-02-08 12:48:28 +06:00
Neels Hofmeyr cf7f7924d2 add osmo_sockaddr_from/to_octets()
Shorthand for the INET/INET6 switch() to get/put the addr part, useful
for encoding and decoding message buffers.

Related: OS#5599
Change-Id: Ie9e33bfac525c59c30714663d2bfcc62ec9eeb81
2022-02-07 22:13:20 +01:00
Neels Hofmeyr 1633735e9b add osmo_quote_str_buf3, osmo_escape_str_buf3
There already are osmo_quote_str_buf() and osmo_quote_str_buf2(), same
for _escape_, but none of them return the snprintf() like string length.
A private function does, publish this in the API.

The returned chars_needed is required to accurately allocate sufficient
size in string functions that call osmo_quote_str/osmo_escape_str. I am
adding such in osmo-upf.git.

Related: SYS#5599
Change-Id: I05d75a40599e3133da099a11e8babaaad0e9493a
2022-02-07 22:10:29 +01:00
Neels Hofmeyr 09d6574a45 add osmo_sockaddr_to_str_c(), osmo_sockaddr_to_str_buf2()
To easily log and print a sockaddr using OTC_SELECT, add
osmo_sockaddr_to_str_c().

Implement osmo_sockaddr_to_str_buf2() using osmo_strbuf, so that we can
return the chars_needed which osmo_sockaddr_to_str_c() uses.

From previous osmo_sockaddr_to_str_buf(), call
osmo_sockaddr_to_str_buf2() and return NULL if the buf_len was
insufficient, to mimick previous behavior. This makes it more
consistently returning NULL for insufficient buf_len, as shown in the
tweak that is needed in socket_test.c. Before osmo_sockaddr_to_str_buf()
would return a truncated port number, now it's all or NULL.

I will use osmo_sockaddr_to_str_c() in the new osmo-upf implementation.

Related: SYS#5599
Change-Id: I12771bf8a021e6785217b1faad03c09ec1cfef0e
2022-01-31 15:03:53 +00:00
Philipp Maier 4c44d46308 logging: log to stderr when logging is not initialized
When the logging framework is not initialized we get an error:

"ERROR: osmo_log_info == NULL! You must call log_init() before
using logging in ..."

There are sometimes situations where some code tries to log before
logging was initialied. This is a problem because the actual log
line with the debug info we need is covered up by the error message
from the logging framework.

Lets introduce a fallback logging function that is called when the
the logging framework is not available. This function can just use
fprintf to output to stderr.

Change-Id: I9b1b0988e02322e3e44fd4ceea3e1bc2d4df3c45
2022-01-25 17:49:20 +01:00
Neels Hofmeyr 1d1ab74fdf ports.h: add osmo-pfcp-tool ports
Related: SYS#5599
Change-Id: I8a5f437d934b9bda11ea593b50bd18c7d5d71ce9
2022-01-21 00:55:51 +01:00
Neels Hofmeyr 13fa00e183 PFCP: add DLPFCP and osmo-upf port numbers
Related: SYS#5599
Change-Id: I0a46b147ec6a76d909df28136cfd2b764b2c75ea
2022-01-21 00:55:51 +01:00
Harald Welte e6fb890b98 log_taget_find() should use enum log_target_type, not int
This has shown up in -Wsign-compare

Change-Id: I2f5ba81aa0328db7db29f49f26de4cea3f522789
2022-01-09 12:04:22 +01:00
Harald Welte 7d6166a0e3 utils: Fix -Wsign-compare warnings
Change-Id: I8b1118ca519b0a419a42eab8b7d4ba9e26a0bab5
2022-01-09 12:04:19 +01:00
Harald Welte c85aaed3fb bitvec: Fix -Wsign-compare warnings
Change-Id: I34f65cda83bcd7050bd0cc0fb9e5cb5d33a09086
2022-01-09 12:04:16 +01:00
Pau Espin 604eaba2c3 iuup: Submit RNL-STATUS-Initialization.ind upon rx of Init
This allows init-passive users to get the configured sizes for the RFCIs
and other similar information once engotiated with the peer.

Realted: OS#1937
Change-Id: I63ee780b4aa162ea097410b234e73984000c0965
2022-01-07 13:02:56 +00:00
Philipp Maier ec5b42c8ce stats_tcp: use a default batch size of 5 instead of 1
The configuration defaults for the socket statistics are currently set
to a batch size of 1. This means that only one socket per timer
expiration is scanned. This rate is probably a bit low. To speed things
up a bit we should set the default to 5. Scanning 5 sockets at a time is
still in the affordable range.

Change-Id: I87abc74c00377191f7940c5b8f19d932618fc019
Related: SYS#5701
2022-01-05 20:32:07 +00:00
Sylvain Munaut d5974e9155 conv: Fix the traceback for tail biting codes
When picking the end state, looking only at the path metric
is highly suboptimal because in a tail biting code, we _know_ that
whatever treillis path is correct, it must start and end at the same
state. So we only consider path meeting that condition. We know any
path that doesn't isn't the right one. We only fallback to only
path metric if no path met that condition.

Fixes OS#4508

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I87e51d3880c0fe7bf3d6cd08fd46517a424a230c
2022-01-05 20:24:49 +00:00
Vadim Yanitskiy 2f4186a3d2 VTY: implement 'no log gsmtap [HOSTNAME]' command
Change-Id: I9a4efa1e35cbc22cea06a64a15a369522c32d3c4
2022-01-05 09:51:34 +00:00
Philipp Maier b1ef8f5f69 select: gather statistics for TCP connections
osmocom applications are deployed in a variety of different situations.
Dependung on the medium that interconnects the network components
unexpected behaviour may occur. To debug problems with the
interconnection between network components it might help to monitor the
health of the related TCP connections.

Change-Id: I1416f95aff2adcf13689646b7574845de169fa3d
Related: SYS#5701
2021-12-23 14:52:15 +00:00
Harald Welte 9fe1f9fb0b Introduce CRC and FSM for IuUP (user plane) as used in 3G RTP data
Only support for SMpSDU mode is introduced in this commit.

Not supported explicit list:
- Transparent mode
- ATM/AAL2 based Transport layer
- GTP-U based Transport Layer
- Iu Rate Control procedure
- Time Alignment procedure

APIs are provided to allocate the primitives properly inside the related
msgb. This way primitives can be placed in the headroom, leaving the
data part of the msgb for the IuUP payload, hence allowing re-use of the
msgb and 0 copy of IuUP payload when forwarding data over RNL<->TNL.
Since RNL and TNL primitives relu struct osmo_prim_header, which is not
packed, they cannot be set to packed, and hence proper memory alignment
in the msgb must be done to avoid misaligned accesses (Asan errors about
it otherwise).

Related: SYS#5516
Change-Id: Ibe356fa7b1abaca0091e368db8478e79c09c6cb0
2021-12-22 14:58:31 +01:00
Pau Espin 28c438845f include/: Adapt some headers to match contrib/struct_endianess.py format
This way the related files are not changed when running the script to
generate struct fields for big endian systems.

Change-Id: I830e0961331a73f8dceb1a5a1c879798541752fd
2021-12-22 13:57:48 +01:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Eric Wild 63e1b2b024 logging: make LIBOSMOCORE_NO_LOGGING work as expected
The macro introduced in d02090bba5 was not
enough: the actual logging macros are being used, i.e. by the fsm, so
wrap those as well, and provide a flag to disable this at build time.

Change-Id: Ia4c78abe5f198139f96ffa289998855be2477585
2021-12-09 15:25:53 +00:00
Eric Wild d02090bba5 logging: allow disabling macros using a new define: LIBOSMOCORE_NO_LOGGING
This was previously unconditionally defined, so embedded targets were
unable to get rid of the log macros and functions.

Change-Id: I589f93d98a6bc5cf6221c56e2fe3f27bfdd200e8
2021-11-26 09:23:24 +00:00
Harald Welte 9e34f08d0b gsmtap: Add gsmtap_sendmsg_free() as alternative to gsmtap_sendmsg()
gsmtap_sendmsg() places the burden of freeing the msgb in case of
erroneous return codes on the caller.  A review of existing users
shows that this is overly optimistic and many calls get it wrong,
opening up memory leaks.

Let's add a new function gsmtap_sendmsg_free() which behaves like
gsmtap_sendmsg() but always takes ownership: Either it is sent + freed,
or it is just freed.

Change-Id: I106b09f2a49bf24ce0e8d11fd4d4ee93e9cafdf5
Related: OS#5329
2021-11-25 15:52:26 +01:00
Neels Hofmeyr 25c9741445 add osmo_time_cc, moved from osmo-bsc
Related: SYS#4878
Related: Ica9f908a1a30f334a24c59471affa11225117e12 (osmo-bsc)
Change-Id: Iabb17a08e6e1a86f168cdb008fba05ecd4776bdd
2021-11-15 09:06:03 +00:00
Alexander Couzens 6b5a533f4d include: add enum for UTRAN cipher
Change-Id: I4b9baff2c2fbd0e339fc769cc69cce58d3a72cdf
2021-11-11 09:02:24 +00:00
Vadim Yanitskiy bfc8377398 stats: allow configuring reporter's name in the VTY
This allows configuring more than one reporter of the given type.

Change-Id: Ia815c24dc974648985539913012b3b074ea317a9
Related: SYS#5713
2021-11-09 04:35:07 +03:00
Vadim Yanitskiy 190b6efafd gsm/protocol/gsm_04_08.h: add gsm48_meas_res_is_valid()
Change-Id: Iae2bd508a08c4b5093d36e514c22218763e11edf
2021-11-04 17:45:52 +03:00
Vadim Yanitskiy 36c69ed256 gsm/protocol/gsm_44_004.h: fix missing include of 'endian.h'
Without this header, both OSMO_IS_{BIG,LITTLE}_ENDIAN macros are
not defined, and thus the 'struct gsm_sacch_l1_hdr' is empty.

Change-Id: I2c14a1b898fdb743191dab0e6be157ce916e8161
2021-10-29 20:26:20 +03:00
Vadim Yanitskiy 7044d20863 Revert "Prevent GCR encoder/decoder functions from being used directly"
We need this API for communicating GCR over the MNCC and SIP.

Change-Id: I06babb959fdc82f4e82d92260131d60c98b0abd2
Related: OS#5164
2021-10-29 05:47:09 +00: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
Vadim Yanitskiy 8db64ee810 gsm_08_58: extend struct abis_rsl_osmo_temp_ovp_acch_cap
This change adds new [bit-]fields in order to allow:

  * selectively enabling SACCH and/or FACCH,
  * setting the RxQual (BER) threshold.

Change-Id: Ia28293a12de0af71f55e701fb65c46e905dae217
Related: SYS#5319
2021-10-21 21:11:28 +03:00
Pau Espin 0a9430ee48 {ctrl,vty}/ports.h: Allocate ports for osmo-hnodeb
Change-Id: I6514d040d88d145a321075911368645868e6280e
2021-10-21 12:53:33 +02:00
Vadim Yanitskiy c549719088 utils: introduce osmo_talloc_replace_string_fmt()
Change-Id: I6b84fa0525555a98c531fc558e5dc1298fec00c1
2021-10-13 14:03:26 +03:00
Neels Hofmeyr 137efc9b18 cosmetic: get rid of 3 deprecation warnings
Some deprecated functions are still used in libosmocore .c code. Use
OSMO_DEPRECATED_OUTSIDE() to get rid of those "resident warnings".

Change-Id: I6e79acc87be37ac1aaec900e737e41450b46826a
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
Keith Whyte 3f43134b6b GPRS: Add PDP_TYPE_N_IETF_IPv4v6
Change-Id: I1f82f9d8fc13dcc4474760329bd74ae9685b9031
2021-09-29 21:05:20 +02:00
Pau Espin 4e3b594e93 cosmetic: gsm: meas_rep.h: Fix typo in comment
Change-Id: I35c47a69ad1e9a75de6cc82c44a87828ebbb7189
2021-09-28 11:32:44 +02: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 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 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
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 e67edfdec2 gsm_08_58: fix sourcecode formatting
Change-Id: Ia58c25441911d6f872a8ec5664c71e56ad895f97
2021-08-31 19:54:28 +00:00
Philipp Maier 55ce87da69 gsm_08_58: fix sourcecode formatting
struct abis_rsl_osmo_rep_acch_cap has an indentation level that is too
deep.

Change-Id: Ie15feac75d1aa4fe5e5e237b14119addf09e5d77
2021-08-31 19:54:28 +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
Pau Espin 9da16b5bbc cosmetic: Fix missing space in comment
Change-Id: If0940a2e1c66c3498f5e3d6ac641029290955175
2021-08-26 15:25:16 +02:00