Commit Graph

533 Commits

Author SHA1 Message Date
Pau Espin 6fe1f35001 osmux: Replace deprecated osmux_xfrm_input_* APIs in examples & tests
Change-Id: I7f3f8d40f89ffdd135a73316ee60fd429ba2a5b0
2022-10-03 11:30:45 +02:00
Pau Espin 36ca79e708 osmux: Allocate struct osmux_out_handle through API
Until now, the osmux_in_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, openbsci, osmo-bts) can still work fine, since there's no
change on the struct osmux_in_handle. However, they will somehow break
next time thestruct is changed until they are ported to the same API
(easy to do).

Change-Id: I752ab031f935f04731bb1a354333f1682a1aa5bd
Related: SYS#5987
2022-10-03 11:30:45 +02:00
Pau Espin 9d7ea681ef tests/osmo-pcap/osmux: Replace deprecated API osmux_xfrm_output_init2()
Replacing this one with the newer API was missed a few commits ago when
this API was marked as deprectated. Do it now.

Change-Id: Ia0958dfae951d82feafe427eff2112d327d3b0a4
2022-10-03 11:30:41 +02:00
Pau Espin 6bd64fc928 cosmetic: osmux: Make linter happy
Change-Id: I8472e1b508babfa231c7e0ecc75b4fe63e090a0d
2022-10-03 11:30:13 +02:00
Pau Espin 5fd33980b8 osmux: Split input and output code into separate files
The output and input paths are totally independent, they share no code
or structures holding state. They can be operated totally independently.
Hence, let's split the code into separate file since when someone looks
at the osmux code one is really looking specifically at Tx or Rx side,
but not at both sides.
Moreover, the "input" and "output" concepts have always been a bit
difficult to understand (would have been better calling them "src" and
"sink" instead), which adds more confusion when trying to find the
relevant part of code.

Change-Id: Ia72995092a36ca50147611e617cb88c4dcf231d5
2022-10-03 11:29:58 +02:00
Pau Espin b0369f375f osmux: Take into account configured osmux_in_handle->osmux_seq field
It was not being used anywhere, yet older applications used to set it
(always to 0, which was the default value applied internally).
Let's make use of it and apply it as first seqnum to be used on a
circuit.
This value is applied upon call to osmux_xfrm_input_open_circuit(),
hence it can be set independently for every new circuit.

Change-Id: Ia26fcba5d7364a5744b2d64d0542a2b3880eee34
2022-10-03 09:29:18 +00:00
Pau Espin 11f725ae78 osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circuit()
There's no real use in having it split, it just makes it more difficult
to extend since extra prams must be passed over 2 functions.
In fact, the duplicity of "struct osmux_in_handle" and "struct
osmux_batch" as its ->internal_data should go away in the future.

Change-Id: Ie4c6b55827ac27bcdfbe1b14fb238f5873243000
2022-10-03 09:29:18 +00:00
Pau Espin 3e6f4d12c9 stream: Document osmo_stream_srv_recv() SCTP specialties
Change-Id: I47b066f26e63afd4bdb135f822667d1cd9479920
2022-09-30 17:57:56 +02:00
Pau Espin 96271688cf stream: Return 0 when receiving sctp notification SCTP_COMM_LOST
It was seen on a real pcap trace (sctp & gsmtap_log) that the Linux
kernel stack may decide to kill the connection (sending an ABORT) if
it fails to transmit some data after a while:
ABORT Cause code: "Protocol violation (0x000d)",
      Cause Information: "Association exceeded its max_retrans count".
When this occurs, the kernel sends the
MSG_NOTIFICATION,SCTP_ASSOC_CHANGE,SCTP_COMM_LOST notification when
reading from the socket with sctp_recvmsg(). This basically signals that
the socket conn is dead, and subsequent writes to it will result in
send() failures (and receive SCTP_SEND_FAILED notification upon follow
up reads).
It's important to notice that after those events, there's no other sort
of different event like SHUTDOWN coming in, so that's the time at which
we must tell the user to close the socket.
Hence, let's signal the caller that the socket is dead by returning 0,
to comply with usual recv() API.

Related: SYS#6113
Change-Id: If94d44f25b76a96a5ea402fec9fc14c4e6296ba3
2022-09-30 17:57:40 +02:00
Pau Espin 04572b2f6a stream: Remove unneeded break statement
Change-Id: Iaa36a3661fc3d049f656342ee6dc3aafd45498bb
2022-09-30 14:24:12 +02:00
Pau Espin 8dd1e15661 stream: Set sctp_ppid and sctp_stream when sctp notifciation is received
Let's set these values in all cases.

Change-Id: I99f6098d8d9fc1c06bc28373bf7ee76f15d5f525
2022-09-30 14:22:15 +02:00
Pau Espin 36a9f3eae8 stream: Log rx of sctp notification SCTP_SEND_FAILED
Change-Id: I16d3ed950d4da3b13cca25bcd8f29af0d880c23e
2022-09-30 14:21:22 +02:00
Pau Espin 5dd81f3c63 stream: Erase sctp_msg_flags if receiving user data
It could be that the user reuses the msgb passed to
osmo_stream_srv_recv() all the time, hence we need to reset the flags,
otherwise it may end up being set forever.

Change-Id: Id358140db82b018e3973111e530834589c0b7224
2022-09-30 14:09:34 +02:00
Pau Espin 56f20d4192 stream: Set proper msgb length when returning sctp_notification
This allows the user to properly check the size of the content in case
the struct ABI changes.
-EAGAIN is still returned to avoid older users of the API reading SCTP
notifications as user data.

Change-Id: I95e2457498fd8e0d790d221cb97695ace0dd673e
2022-09-30 14:07:03 +02:00
Pau Espin de68bc9065 osmux: Fix unwanted RTP marker bit upon rx of osmux seqnum wrap around
The wrap around case was not properly considered in the condition
setting the Marker bit. Let's fix it.

Related: SYS#5987
Change-Id: I6e01f29a6239f930c9be2bcb2efe447e5de8fedf
2022-09-29 11:49:47 +02:00
Pau Espin dc4e8747e9 tests/osmux: Test rx of osmux seqnum wrap around
This test shows that there's a bug where the first RTP packet extracted
from the received osmux batch with seqnum=0 has the M bit marked for no
good reason.

Related: SYS#5987
Change-Id: Ida658c681e84878f209ab4965d8aa821a570a580
2022-09-29 11:49:47 +02:00
Pau Espin e486efa264 tests/osmux: Properly flush and free out_handle in osmux_test
Change-Id: Ia86e4324e21ccc4bd4b138fa5b2b748df23b0aed
2022-09-29 11:49:43 +02:00
Pau Espin d2810679c7 osmux: Fix osmux seqnum incremented globally instead of per circuit
There's no real use in having a global seqnum. The seqnum, as specified
by the osmux protocol specification, relates to that of the RTP
seq+timestamp, hence it is per circuit.
Having it per circuit allows detecting gaps and lost batches on the
receiver side, applying the Marker bit on the re-assembled RTP packets.

As a resut of the fix, tests/osmux/osmux_test part validating Marker bit
started failing. It failed because it was wrongly written to start with,
since it used only one osmux_out_handle for the 4 CIDs in use, which was
wrong, since each CID must have its own osmux_out_handle as state is
kept there per circuit.

Related: SYS#5987
Change-Id: I562de6a871d8a35475c314ca107c2a12b55d6683
2022-09-29 11:48:39 +02:00
Pau Espin 9aa01ae7b5 cosmetic: osmux: Fix typo in comment
Change-Id: I05aa1941f9cc8f3aa5ba873cf134767b56b56b69
2022-09-28 19:14:02 +02:00
Pau Espin c4c6746be7 cosmetic: osmux: Properly separate expressions with whitespace
Change-Id: I524899148da767516c7c1e4bc47b9d3a7b726356
2022-09-28 19:14:02 +02:00
Pau Espin 77f989504b osmux: Fix AMR F,Q,CMR fields not properly encoded in osmux header
The value of the first RTP packet in the batch was being encoded,
instead of the last one (as documented in the Osmux protocol
specification).

Related: SYS#5987
Change-Id: I06f3d07a05181d938c22bbd0da7172b5dad6659a
2022-09-28 19:13:54 +02:00
Pau Espin b6f4fa2334 tests/osmux: Add new osmux_input_test to validate AMR FT changes
Related: SYS#5987
Change-Id: I105466fc8a4d92341f34886ee81ef0ca04014514
2022-09-28 19:12:39 +02:00
Pau Espin e36cbdf99e osmux: Proper encoding of osmux frames when when AMR FT changes
The AMR FT (and hence payload content and size) may well change over the
lifetime of an RTP stream. Since all AMR payloads in an osmux batch
share the same FT (its joined payload is calculated based on
osmuxh->ctr*amr_bytes((osmuxh->amr_ft)), if a new RTP/AMR with a
different FT arrives we cannot simply append it to the current batch.
Instead, the current batch must be considered done and a new batch with
anew osmuxh header must be prepared for the resulting osmux frame to
send over UDP.

Before this patch, when a packet with a different AMR FT was submitted
for batching, it would be added in the same batch and decoding would
fail since the sizes of the batches would be wrong.

Related: SYS#5987
Change-Id: I25eb6ee54c898f575cc71ccfd6d190fe51d56dbe
2022-09-28 19:03:52 +02:00
Pau Espin f136c648fb amr: Add data[0] field to amr_hdr
This allows easily accessing the AMR payload located after the TOC.

Change-Id: I72c0a001bf7ce9a63ac03beef352af177084e644
2022-09-28 19:03:52 +02:00
Pau Espin 2640c157f8 osmux: Print osmux_hdr rtp_m field in osmux_snprintf()
Change-Id: Idfe530b944ac5dfd5ce6b5150421c2d4daee8788
2022-09-28 19:03:52 +02:00
Pau Espin bc68849a68 tests: rename test osmux_test2 -> osmux_output_test
That file focuses on testing the osmux_output_* API, ie receiving Osmux
frames and decoding it into batches and later on into rtp packets.

Change-Id: I7e6eda1e2e676673771bc6a7c3682d07ac1d344e
2022-09-28 19:03:52 +02:00
Pau Espin fffbfaa6f8 tests/osmux: Always run with fake time
Let's not make the tests more difficult to maintain and extend by
allowing them to run in real clock time, there's no real need for it.

Change-Id: I549a4722d63d700b54b146260131a68e656b843e
2022-09-28 19:03:52 +02:00
Pau Espin 038d957b7d tests/osmux_test2: Document unit tests
Change-Id: I56f27af52b6a8d798879c70d68a9a3b9e512867d
2022-09-28 19:03:49 +02:00
Pau Espin 8a3b1acf35 osmux: assert no batch factor greater than 8 is used
Change-Id: Ie17a8174bc220d091cb7ff880363d22179b4f621
2022-09-27 18:26:48 +02:00
Pau Espin a50895f7eb osmux: Early return on error or batch full during osmux_replay_lost_packets()
If there's an error while replaying lost packets, return the error to
the caller.
If the batch is found full, early return indicating so, there's no need
to continue flow calling osmux_batch_enqueue() in osmux_batch_add()
again.

Change-Id: I62f494d2b2e7903a6683f6dea00781bb721a3d41
2022-09-27 18:24:11 +02:00
Pau Espin d6e8765faf osmux: Unify return codes of osmux_batch_add() and osmux_batch_enqueue()
This way it's way easier to return the error to the caller, and the code
is easier to read.

Change-Id: Ib78c9b82b85c74be2c5e94dae7c212175244d5fa
2022-09-27 18:21:45 +02:00
Pau Espin 845a386dcd cosmetic: osmux: Fix typo in comment
Change-Id: Ieeaa5543e56a824752413dadf161329f5ea0e4e7
2022-09-27 17:37:28 +02:00
Pau Espin fe78dc46ed osmux: Change order of lines to follow packet fill order
The osmux header goes before in the packet, so let's move the line
checking is size before the content.

Change-Id: I33feac834700d22ed06472d8971abd0567ce623b
2022-09-27 17:31:51 +02:00
Pau Espin 414b34e713 osmux: Avoid duplicated RTP msg trigger Tx of osmux frame
The RTP msg will be dropped, so it makes no sense to signal the caller
to deliver the batchbeing built, since it may still have space for next
non-duplicated message.

The exception is the case where the new packet has the M marker bit set,
since the sequence numbers can be reset or jump in those scenarios.

Change-Id: Idc457bc3b26bed68796d714bc3f37a2d016ba5c3
2022-09-27 17:31:22 +02:00
Pau Espin 3de07cf481 osmux: osmux_xfrm_input(): Propagate error code to inform caller
This way the caller can log or make statistics based on the return code.
All known implementations simply check the return code to be >0, so we
are fine here.

Change-Id: I981cc7e560cd9c792a8a2a219b3612f9834296ce
2022-09-23 18:31:03 +02:00
Pau Espin 2f58903376 osmux: Improve logging non-usual conditions
Change-Id: I854b0ae78e7e701ec3cb0525063f7292185d05a3
2022-09-23 17:39:53 +02:00
Pau Espin 0d52cdfe77 tests/osmo-pcap-test/osmux_test: Fix return condition check for osmux_xfrm_input()
According to API doc and implementation, it never returns >1.
Do as done in all other places where this API is used, that this check
for >0.

Change-Id: If23dfecb566f590b7a898356469df6e322f57653
2022-09-23 17:38:33 +02:00
Pau Espin 668c804197 stream: Provide caller with SCTP flags during osmo_stream_*_recv()
The user may want to check the flags in order to know if the content
pointed at by msgb is an sctp_notification structure, and not in-band
data.
This is useful for the user in order to gain connection state such as
SCTP RESET notification, which means the client reconnected reusing the
same socket, loosing all higher layers state.

The MSG_NOTIFICATION from netinet/sctp.h is not reused, and instead an
osmocom specific flag (and bitmask) is used. This is done in order to
fit the flags in one byte, since for instance MSG_NOTIFICATION requires
2 bytes in my system (0x8000).

Related: SYS#6113
Change-Id: I0ee94846a15a23950b9d70eaaef1251267296bdd
2022-09-19 14:50:34 +02:00
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
Pau Espin bc45a8f599 examples/osmux-test-output: Avoid using deprecated Osmux API
Change-Id: I408bfc84b9c1740df946fa29191f0e286f5b46e1
2022-08-31 16:19:25 +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 e95ad0e66e osmux.h: Define default Osmux port
This has been the port being used historically in most osmux setups,
and projects using osmux.h have it defined locally. Let's define it here
so that there's no need to define it on each client.

Change-Id: Ibfd058bceeeaa1384a00d8fcd6d6268b445e19bd
2022-08-10 17:46:30 +02:00