Commit Graph

308 Commits

Author SHA1 Message Date
Pau Espin 98c75ef273 stream: Unset fd value after close() before calling closed_cb()
The fd is not valid anymore after close() call, so let's set it to a
clearly invalid value, to avoid confusion on closed_cb() users
attempting to use the fd get info about the socket at that time.

Change-Id: I82d9bdfb38cf5e9f689eca0d9a4c19ddd5541af7
2022-09-13 12:47:33 +02:00
Pau Espin 2087d61c21 stream: Fix typos in log messages
Change-Id: I9e49e222c254c89d182402501024badfd3bf9d9c
2022-09-12 12:44:03 +02:00
Pau Espin 98cc81bc98 osmux: osmux_xfrm_input_close_circuit(): Log circuit not found
Change-Id: I486b81d15b4d9d6abd08fbd73ca460bae22586a9
2022-09-12 12:04:25 +02:00
Pau Espin 95d57c1803 osmux: Allow the user to alloc msgbs used to provide generated RTP packets
This is useful for users of the API which need to keep forwarding the
msgb to lower layers which may need prepending a new header to the msgb,
like osmo-bts with l1sap.

Related: SYS#5987
Change-Id: I632654221826340423e1e97b0f8ed9a2baf6c6c3
2022-09-12 12:04:20 +02:00
Pau Espin 3b0991e80f osmux: Allocate struct osmux_out_handle through API
Until now, the osmux_out_handle was allocated by the client, and passed
to the API to initialize it. This makes it really hard to improve the
implementation without breaking the ABI.

Let's break the ABI now one last time (hopefully) by allocating the
struct through an API. With only this change, the already built users
(osmo-mgw, openbsc) can still work fine, since there's no change on the
struct osmux_out_handle. However, they will somehow break next time the
struct is changed until they are ported to the same API (easy to do).

Related: OS#5987
Change-Id: Ie8df581f375c9a183a7af60b431561bda82f6e34
2022-09-02 11:29:05 +02:00
Pau Espin 75ae80da03 osmux: Move osmux_xfrm_output_set_tx_cb() further down to the xfrm_output section
Change-Id: I46628d1f712e9c5c56c306e27c34ff45731c0172
2022-09-02 11:20:04 +02:00
Pau Espin 51fa5ad16e osmux: Drop long time deprecated APIs
Those APIs where deprecated 4 years ago (end of Aug 2018), and they have
not been used since around that time. Hence it can be considered safe to
drop them, since they only make the whole code more complex to
understand.

API osmux_xfrm_output_init() is left since openbsc.git is still using
it.

Related: OS#5987
Change-Id: Icbdd364a8161a8113dbf1406716946f684d0a853
2022-09-02 11:19:55 +02:00
Max a69baa9184 Properly handle send() return code
Change-Id: If9b80e855b740254d5414ea50b4ce594855da8e9
2022-08-21 21:46:46 +07:00
Max f7bea130e6 Log more details in osmo_stream_srv_write()
Log error code and amount of data:
both are handy for debugging apps using the library.

Change-Id: I580c00f3b5ade05ecb20a92ce4ece2854334a41f
2022-08-21 20:01:50 +07:00
Pau Espin c8241421bc rtp: Avoid memcpy(len=0)
Change-Id: I7618c6509b67465d21271ea632bccc8cf11e4852
2022-08-11 20:31:18 +02:00
Pau Espin dcae6dd99d stream: getsockopt ret socklen_t is unsigned
Found out by following gcc warning:
"""
libosmo-netif/src/stream.c:147:11: warning: argument to variable-length array may be too large due to conversion from ‘int’ to ‘unsigned int’ [-Wvla-larger-than=]
  147 |   uint8_t buf[sctp_sockopt_event_subscribe_size];
      |           ^~~
"""

Change-Id: I181ae5c0480788fc96abd2bb1edf003244884c8f
2022-07-18 18:18:16 +02:00
Pau Espin 0f067d8809 stream: assert params are not NULL in send/recv functions
Change-Id: Ie9e67396973128aba87b584be1a36e2a94dd0998
2022-07-05 18:26:53 +02:00
Pau Espin 841fe23f9f rtp: Delay rtph ptr assign after validating length
Make coverity happy, since this seems to spread as a tainted error
further below.

Related: Coverity CID#273000
Change-Id: I5d457183043d4c902f473b828815b9c62a01d47d
2022-06-29 18:11:21 +02:00
Pau Espin bea94d8edf Bump version: 1.1.0.14-d1ab-dirty → 1.2.0
Change-Id: I5809e5c85af66db6174a182a936891fa6e1104c1
2022-06-28 18:09:49 +02:00
Philipp Maier d24a436bc7 amr: cosmetic: fix grammer in comment
Change-Id: I01ad26986d925acdcdb3760f89b8a85dccdc3d5b
2022-02-15 14:35:36 +01:00
Pau Espin 2687d8fb72 amr: Fix length check in bwe<->iuup converters
The check was wrong for format types containing extra bits not aligned
to byte boundaries, such as FT7 (AMR Code 12.20, 244 bits, 31 bytes).

if the source has 1-6 extra bits, they can be fit with one less byte
when shifting 10 bits to the left.

Change-Id: I0552d727585886d25f613e64ca815fb6dcd53f25
2022-01-05 20:29:57 +01:00
Pau Espin cee23a7c6f amr: Fix FormatType from parsing BWE AMR header
The proper order is CMR(4)+F(1)+FT(4)+Q(1).

Hence, FT is 3 least significant bits of first byte and 1 most
significant bit of secont byte.

Change-Id: I66f39d3b9a608f07c202e7a5084a8537e9978a94
2022-01-05 18:38:06 +01:00
Alexander Couzens acce44d40f amr: Introduce APIs to convert BE to IuUP/IuFP format
These APIs allow for easy re-formatting of received AMR to forward
between regular RTP and IuUP.

Related: OS#1937
Change-Id: Id2bd32d5f2060abe581730996dc4251381bf7d4f
2022-01-04 14:50:51 +01:00
Alexander Couzens f2c1d4c328 amr: don't rely on pad bits to be zero
Change-Id: I354fbbcbaf7ff7e7d498b22c175a57a79b6b8856
2021-12-31 00:31:32 +01:00
Pau Espin e59472a50a prim: return last error code
Closes: Coverity CID#242768
Change-Id: Ic0f8b313ab9a8de597d8bb6db76e9883bc6009a0
2021-12-16 12:55:46 +01:00
Pau Espin 82a52f6a7d prim: Add internal CTL SAPI to negotiate SAP versions
This commits adds a generic mechanism for applications to validate
support for SAPs and specific versions of them.

A new special SAPI is introduced to manage inbound control messages for
the protocol.
In that SAPI a new primitive HELLO.req/.cnf is added to negotiate
support for versions of any given SAP.
The idea is that the client upon connecting submits a HELLO.req(SAP,
VER) for each SAP it plans to use, including the version of the special
CTL SAPI itself (preferrably to be checked first).
Upon receiving such a message, osmo_prim_srv handles it using a special
path, which ends up calling the user provided rx_sapi_version_cb(SAP,
VER). In there, the user can either:
* Accept the version (return same VER value)
* Reject the requested version but propose another candidate version
  (return some positive VER value other than received VER). In this
  case, the client can decide whether to request another VER or close the
  connection.
* Reject the proposed version and close the connection.

Change-Id: I0c2d92cfdb5433e3caab51d712fd947d51eeef23
2021-12-09 20:21:33 +01:00
Pau Espin 4b6ce34083 Introduce osmo_prim_srv APIs
This new module allows easy exchange of osmo_prim based data types over
IPC communication (UD socket supported only so far), by replacing the
osmo_prim_hdr struct with a serialized header when submitting/receiving
it from the IPC socket.

This patch introduces the server side of the UD socket, but the client
side can easily be introduced in the same file whenever needed.

Related: SYS#5516
Change-Id: I7cab15ac092e45a256c4f0bab11b3962df861044
2021-12-09 16:59:29 +01:00
Pau Espin b2b5f1c6bf stream: Add support for AF_UNIX sockets
Change-Id: I5237a8121be05a9a31a39ca38a6a139062f258c4
2021-12-09 13:47:41 +01:00
Pau Espin 4cf31f187a stream: Factor out sctp_recvmg long code chunk
This makes it easier to follow the general path selection based on
protocol type. It will also make it easier when we add new paths based
on socket domain.

Change-Id: Ia3e0f4407e00a2dac9ee885fe1cc1cb4b463898a
2021-12-01 14:52:47 +01:00
Pau Espin d4a1107586 Introduce sctp.h to provide SCTP related functionalities
These value_strings are taken from existing private ones in
libosmo-sccp.git osmo_ss7.c, and are moved here in order to be
reused by other projects, such as osmo-hnodeb.

Change-Id: Ica6f01851fb94e31f4ef097494bb1b8a95597ba6
2021-11-23 14:18:40 +01:00
Pau Espin 5967fa0058 Bump version: 1.0.0.14-3e65-dirty → 1.1.0
Change-Id: I8e3be883113444251f5008c407e9f722d0dcd422
2021-02-23 16:47:37 +01:00
Harald Welte 637025b2f7 migrate to osmo_fd_{read,write}_{enable,disable}()
Change-Id: Ia8ffcbc61883a4e1615c101dbd3307771ae33974
Depends: libosmocore.git Change-Id Idb89ba7bc7c129a6304a76900d17f47daf54d17d
2021-02-11 15:40:54 +01:00
Harald Welte bd775e4adb cosmetic: Fix whitespace (use tab instead of 8x space)
Change-Id: I2b8d80fb771336d4d2c4a9ea1749935bdf14a37b
2020-10-21 14:03:29 +02:00
Harald Welte eb96eb7d68 Use osmo_fd_setup() wherever applicable
Change-Id: Ifb90e00036cc51ef02f3cf4dda1ff7dcd1f8a5b5
2020-10-18 23:12:20 +02:00
Vadim Yanitskiy a38b83f395 stream: add missing Doxygen \return statements to non-void functions
Change-Id: I693939946497ad08f45cab238a56ceee29578056
2020-09-02 11:39:19 +07:00
Pau Espin 97a293e46a stream: Fix log of IPv6 during accept()
Change-Id: Ib13db8d135138059a70d18a8bba14e53c6514fa7
2020-08-24 12:05:30 +02:00
Pau Espin ef6ae62c6e stream: Support creating sockets with IPv6 addresses
In the case of SCTP, an association supports now containing both IPv4
and v6 addresses.

Depends: libosmocore.git Change-Id I36d8ab85d92bba4d6adb83bc1875eb61094ed2ef
Change-Id: Ie6bb17a9af6ca21d5e350f9c9d2d74c97c5a00af
2020-08-19 18:15:38 +02:00
Pau Espin b1e01cbbbd stream: Fix some SCTP code not disabled if --disable-libsctp is used
Some previous commit added some code to workaround some kernel ABI
unstabilities but forgot to add the code inside a conditional
preprocessor block.

Fixes: 157ad6d707
Change-Id: Ibee01222d8d11cf2520cdbd4d0d5bed6b72d2107
2020-07-06 12:36:18 +02:00
Harald Welte 77a856878f src/stream.c: Don't leak socket during SCTP_EVENTS getsockopt
In Commit Icc49f347cdc0bb77a5c0e230597d662ac35b4acc I forgot to
close the socket :/

Change-Id: I384c61dac0eac8ad999ff0d62350c2fcf3e57ea9
2020-06-03 10:32:27 +02:00
Harald Welte 157ad6d707 src/stream: Work around more Linux kernel ABI breakage
Back in Change-Id Ia95dd1f9ffed9f743c049e05797b1a6f1f9f8c69 we tried
to work-around kernel ABI breakage introduced in kernel >= v5.5, but it
seems that there have already been similar ABI breakages in v4.11 and v4.12.

See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/uapi/linux/sctp.h?id=b6e6b5f1da7e8d092f86a4351802c27c0170c5a5
and https://marc.info/?l=linux-sctp&m=158729301516157&w=2 for the most
recent incarnation.

See https://osmocom.org/issues/4573#note-6 for all known cases
of SCTP_EVENTS ABI breakage.

Closes: OS#4573
Change-Id: Icc49f347cdc0bb77a5c0e230597d662ac35b4acc
2020-06-02 20:54:05 +00:00
Philipp Maier b61eaaccc3 amr: fix off-by-one in osmo_amr_bwe_to_oa()
The for loop in osmo_amr_bwe_to_oa, that converts the body part of the
AMR payload runs one byte too far. This may cause that some of the
padding bits in the end are not set to zero. The loop is designed to
convert n-1 bytes and the nth byte is done separately at the end.

Change-Id: I91e755b83aaac722079879c026d913cc446812d1
2020-05-25 17:05:04 +02:00
Alexander Chemeris 09c71b04f5 amr: Whitespace fix
Change-Id: I7da6813a501ee97ca54611f627870c7eb842ddbe
2020-05-16 20:21:48 +00:00
Alexander Chemeris 4752930972 amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when
converted from octet-aligned to bandwidth-efficient mode. It does
shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for
AMR modes 0, 1, 5, and SID frames because we only remove 6 bits.
So old code generated truncated AMR packets for those AMR modes.
This patch fixes the length calculation by properly counting bits.

Proper bit counting is also bringing us one small step closer to
properly handlig multi-frame AMR packets.

Change-Id: I0462e054a0adc9080456f3eeea9cab7c229cdb70
2020-05-16 20:21:48 +00:00
Neels Hofmeyr 8b77ad940a Revert "amr: Fix OA<->BWE conversion."
This reverts commit 002a51e218.

Reason for revert: amr_test fails with sanitizer build:

Sample No.: 6
   bw-efficient:  a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f
                  1010011110111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111
../../../src/libosmo-netif/src/amr.c:63:24: runtime error: index 15 out of bounds for type 'size_t [9]'
../../../src/libosmo-netif/src/amr.c:63:24: runtime error: load of address 0x7f69498e56b8 with insufficient space for an object of type 'size_t'
0x7f69498e56b8: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  5f 00 00 00 00 00 00 00  67 00 00 00 00 00 00 00  76 00 00 00
              ^ 
=================================================================
==489935==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7f69498e56b8 at pc 0x7f69498abec7 bp 0x7ffeafb35330 sp 0x7ffeafb35328
READ of size 8 at 0x7f69498e56b8 thread T0
    #0 0x7f69498abec6 in osmo_amr_bytes ../../../src/libosmo-netif/src/amr.c:63
    #1 0x7f69498ac661 in osmo_amr_bwe_to_oa ../../../src/libosmo-netif/src/amr.c:193
    #2 0x5648b11afb96 in osmo_amr_bwe_to_oa_test ../../../src/libosmo-netif/tests/amr/amr_test.c:134
    #3 0x5648b11af31d in main ../../../src/libosmo-netif/tests/amr/amr_test.c:235
    #4 0x7f6948d5de0a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26e0a)
    #5 0x5648b11af3d9 in _start (/n/s/dev/make/libosmo-netif/tests/amr/amr_test+0x43d9)

0x7f69498e56b8 is located 8 bytes to the left of global variable 'amr_ft_to_bits' defined in '../../../src/libosmo-netif/src/amr.c:32:15' (0x7f69498e56c0) of size 72
0x7f69498e56b8 is located 48 bytes to the right of global variable 'amr_ft_to_bytes' defined in '../../../src/libosmo-netif/src/amr.c:44:15' (0x7f69498e5640) of size 72
SUMMARY: AddressSanitizer: global-buffer-overflow ../../../src/libosmo-netif/src/amr.c:63 in osmo_amr_bytes

Change-Id: I8232521c513722435e71dc90bdbfee10f8f83496
2020-05-14 23:22:54 +00:00
Alexander Chemeris 002a51e218 amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when
converted from octet-aligned to bandwidth-efficient mode. It does
shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for
AMR modes 0, 1, 5, and SID frames because we only remove 6 bits.
So old code generated truncated AMR packets for those AMR modes.
This patch fixes the length calculation by properly counting bits.

Proper bit counting is also bringing us one small step closer to
properly handlig multi-frame AMR packets.

Change-Id: I9fc5fb92e9bada22a47a82fcfb0925e892e50ced
2020-05-14 12:03:42 +00:00
Pau Espin b988f2bb36 Use OSMO_FD_* instead of deprecated BSC_FD_*
New define is available since libosmocore 1.1.0, and we already require
1.3.0, so no need to update dependenices.
Let's change it to avoid people re-using old BSC_FD_* symbols when
copy-pasting somewhere else.

Change-Id: I269690c1c9e4d19b5b69eef206b95e71f7931188
2020-05-09 19:14:17 +02:00
Sylvain Munaut 141b64f25b stream: Attempt to workaround kernel ABI breakage
See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/uapi/linux/sctp.h?id=b6e6b5f1da7e8d092f86a4351802c27c0170c5a5
and https://marc.info/?l=linux-sctp&m=158729301516157&w=2

A kernel structure changed size, a new field was added at the end.
Attempt to submit with the known "old" size.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Ia95dd1f9ffed9f743c049e05797b1a6f1f9f8c69
2020-05-08 13:42:51 +02:00
Pau Espin 97c3226e90 stream: Rename cli state NONE to CLOSED
It makes a lot more sense calling it this way since it matches the state
of the stream at that point.

Change-Id: Ic02aec3f7f095e0e0e1f940425f577be5048e98f
2020-01-28 13:19:53 +01:00
Pau Espin 7f8e0502e2 stream: Add new WAIT_RECONNECT cli state
It's not really needed right now from logic point of view, since we
reused NONE for that. But it makes logging and logic clearer, and will
make it easier if we decide to move it to FSMs at a later point in time.

Other state value_string names are also modified with its whitespace
removed since anyway we'd need to change them to match WAIT_RECONNECT
length. Let's drop the space because imho it's not that useful and
anyway if we move to FSMs at some point then we won't have them anyway.

Change-Id: I7b9a6da87081c418b0d14bab5f34369c5eca6fe8
2020-01-28 13:18:36 +01:00
Pau Espin 6326e8ff85 stream: Re-arrange cli states to fix 100% cpu usage bug
With previous state, osmo_stream_cli_close() could be called from
osmo_stream_cli_open()(), and in that case state was kept as NONE while
ending up with an associated fd being registered in the select loop.
As a result, osmo_stream_cli_fd_cb() could be called while in state
NONE, which was not expected and would simply return without modifying
fd state flags, causing it to be called again and again.

Related: OS#4378
Change-Id: Ie3342f882893a71ad1538c17ad9ee9fa4433eaa4
2020-01-28 12:50:31 +01:00
Pau Espin 3fc969e3d6 stream: Drop data during write() while in state NONE
It should not happen anyway because no fd should be active if state is
NONE, but still it's an extra check.

Change-Id: I6d58762b7d10078eb8d0981c13d35cb6f85cfe86
2020-01-28 12:30:24 +01:00
Pau Espin 5ed1a3c85c stream.c: Improve logging during sock send()
Change-Id: Iff275c809ec2bb34f471d15bfdc92296566b76a7
2020-01-09 20:38:05 +01:00
Pau Espin d1b1ff77a6 configure.ac: Introduce --{enable,disable}-libsctp configure flag
Similar to what we do in libosmocore already, we want to
deterministically enable or disable support for the feature without
having into account if the system has a libsctp. If libsctp is missing
and support is enabled, then fail.

Extra checks are also added:
* Check netinet/sctp.h header
* Check libosmocore was built with libsctp support (API
osmo_sock_init2_multiaddr() we require).
* In stream.c make sure it can be built without HAVE_LIBSCTP, and that
set_addrs() fails for more than 1 address (since that feature is only
supported through osmo_sock_init2_multiaddrs()).

Change-Id: I4b3e1f1894f13ac1175a71a5139c02a2633be26d
2020-01-09 14:10:20 +01:00
Pau Espin b8121e79ef Bump version: 0.6.0.16-6413a-dirty → 0.7.0
Change-Id: Iabfa9a706c6456bf554ba59badbc3cbfc9210423
2020-01-02 21:01:22 +01:00
Pau Espin ee5c860268 stream: Fix fd param passed to close() in error conditon
Fixes: CID#205089, CID#205087
Change-Id: I65714f214b9962862cda01605c7c2c578c78d3c7
2019-10-21 11:27:36 +02:00