Commit Graph

386 Commits

Author SHA1 Message Date
Vadim Yanitskiy 9e6542641a src/Makefile.am: do not overwrite AM_LDFLAGS
Change-Id: I7b656c167cceb0657c0362b1237f846b7f3e9770
2023-03-13 04:46:02 +07:00
Neels Hofmeyr 4a2f3e9490 fix msgb leak on OSMO_STREAM_SRV_F_FLUSH_DESTROY
In osmo_stream_srv_send(), call msgb_free() if the msgb is not enqueued.

Before this, osmo_stream_srv_send() enqueues a msgb, assuming the queue
will free it. But if OSMO_STREAM_SRV_F_FLUSH_DESTROY is set, it just
returns and drops the msgb. There is no rc, so the caller cannot know.

Change-Id: I994c5e06a9030cfbf4fca8ab42588c61f7121cee
2023-02-20 14:17:00 +00:00
Max 50d4a66e34 Add osmo_stream_srv_link_is_opened()
We use file descriptor of -1 as an indicator for unopened link internally.
However, since all the structs of libosmo-netif are opaque, using it from external
applications looks like a leaky abstraction.

Let's remedy this by adding function which properly check this for the library user.

Related: OS#5568
Change-Id: I91aa7da5f09ec4e8e2d21c827b45ed92e6b0e3d9
2023-02-10 11:43:26 +00:00
Max 30b6d6134d osmo_stream_srv_link_close(): properly handle NULL input
Related: OS#5568
Change-Id: Ie15bb3dc99bfe18065e03fde68d517b0d389b7ad
2023-02-10 11:43:20 +00:00
Pau Espin e63329eb1f Bump version: 1.2.0.114-3804-dirty → 1.3.0
Change-Id: Id67541378193f22f924409f02301f0063aab639e
2023-02-07 13:28:19 +01:00
Pau Espin c0691ad3fd amr: osmo_amr_bwe_to_oa(): validate input data is long enough
Change-Id: I2d11ce71c29ae046c2feab1e59045d97dc3e5099
2022-12-21 21:35:06 +01:00
Pau Espin 16d9d5dba8 amr: use OSMO_BYTES_FOR_BITS()
Change-Id: Ib92856ede3f493615c24d883954989e952c51157
2022-12-21 21:33:48 +01:00
Pau Espin 99e5470ece amr: Clarify size of AMR BWE header and ToC
Change-Id: I34c76b18ee45e12dba92864715e8ef91e6de3b01
2022-12-21 21:32:25 +01:00
Pau Espin 550aaa28dc amr: use struct bwe_hdr in osmo_amr_bwe_to_oa()
The header conversion is now much clearer. Take the chance to delay the
memset(buf) after the checks.

Change-Id: I5042dc628ac70eca62b4980f4acae991dd976528
2022-12-21 18:37:45 +01:00
Pau Espin 26a02deb12 amr: constify input buffer in osmo_amr_is_oa()
Change-Id: I72ef6fc700f628ea158ea888a5f1e9dc8776ab7e
2022-12-21 18:37:45 +01:00
Pau Espin 1c076ec867 stream: Fix tx data dropped upon show socket write
On some  stream socket types like TCP it is expected that the send()
syscall may return a short write, ie not all bytes being copied to the
socket. In that case we need to keep the bytes not copied and attempt to
submit them later.

Related: OS#5836
Change-Id: I3755aada02ceb186fb990604e3496126fe47e1fb
2022-12-20 15:40:52 +01:00
Pau Espin 5df412519b stream: Avoid useless polling if tx_queue becomes empty
Before this patch, the WRITE poll flag was being left ON and waited to
be polled again by the kernel in order to disable it.
Let's spate that extra polling cycle which only creates more polling
triggers, context switches, etc.

Change-Id: I1dd2145249a7322ad95e49be588fd472f00734e1
2022-12-20 15:23:00 +01:00
Pau Espin be6a895ede stream: Log error on short send
This is clearly a problem on TCP streams which needs to be addressed in
the future.

Related: OS#5836
Change-Id: I9bd257b80a378b779df84e204673f8e394eca5b6
2022-12-20 15:22:44 +01:00
Pau Espin c02ee5e8d9 stream: osmo_stream_*_write: Unifiy way to get data and length
Change-Id: I5b5d6f7a5a1722bd01c13d32557c21d8a0889966
2022-12-20 15:12:48 +01:00
Pau Espin 8792432351 stream: Log read/write flags
Change-Id: I57b064fa0498be76579ae9597ab9217d659aae41
2022-12-20 14:52:36 +01:00
Pau Espin a6f4ff0806 osmux: Allow forwarding AMR NO_DATA frames
Related: SYS#6161
Change-Id: If8baebc532090ba9808af7f3dd0afec86f40a7d6
2022-12-19 19:44:20 +01:00
Pau Espin 678c7fc8fe amr: Support all SID and NO_DATA amr formats
Related: SYS#6161
Change-Id: I0e766b3231f03ea87d89fad6ecdce3bd14769054
2022-12-19 19:44:16 +01:00
Pau Espin 09e62cc563 amr: osmo_amr_bwe_to_oa() define variable as unsigned
There's no need to have the variable as signed anymore since the loop
was modified in the previous patch. osmo_amr_bytes() returns a size_t
(unsigned).

Change-Id: I8aa6b5f6d3334e152a62b7c28aac3f881f027894
2022-12-19 14:52:44 +01:00
Pau Espin a7af7ecf0b amr: osmo_amr_bwe_to_oa(): Modify loop to allow osmo_amr_bytes()=0 (NO_DATA)
oa_payload_len can be 2 if osmo_amr_bytes() returns 0 (it will return 0
when FT NO_DATA is supported). In tha case, the loop condition
(oa_payload_len - 3) (signed) is compared against unsigned i which ends
up accessing i=256.

Change-Id: I1e513f493d7883a03acbfa3d9744ec63657810b3
2022-12-19 14:52:44 +01:00
Pau Espin 9336eacff9 osmux_output: Refactor init code to avoid calling deprecated APIs internally
Current internal use of APIs marked as deprecated seems to be causing
issues when building on debian unstable.

Simply rearrange the init code to an internal helper function to avoid
code duplication while still keeping the old deprecated APIs working as
they used to, without getting deprecation warnings at buildtime.

Related: OS#5677
Change-Id: Ie8e168740c0421edd96013620256aab0306dc6c5
2022-11-24 12:49:48 +01:00
Max a6db89089e Add assert for link check to osmo_stream_srv_create()
We implicitly rely on conn->srv availability in several functions.
Let's ensure it's available in function creating conn.

Change-Id: If494eac5dcce6c5ae30e928b92e57067d5681a42
2022-11-22 09:38:06 +00:00
Pau Espin 3d13c2bb42 osmux: Refactor osmux_xfrm_output_pull() to simplify code flow
Change-Id: I0da1d7875bd32f6c1022676b64f9f0d14bad3144
2022-11-21 10:56:52 +01:00
Pau Espin 81201880b8 osmux: Check received osmuxh->amr_ft is correct before using it
Fixes: Coverity CID#283432
Change-Id: Iab525c5b7eb1e455a8229fb39e96897aac53298c
2022-11-21 10:56:52 +01:00
Pau Espin f5001d4148 amr: Guard against incorrect AMR FT passed to osmo_amr_{bits,bytes}()
Fixes: Coverity CID#283433
Change-Id: Ib11d4b64c6df19a85c4374fde89e1b56f410e438
2022-11-21 10:56:52 +01:00
Pau Espin fbce10e286 osmux: Improve logging of osmux_xfrm_input
This allows easily identifying and following state and lifecycle of
CIDs when looking at logs.

Related: SYS#6161
Change-Id: I6a3113dfaef0adbb20162985e3b7d57c46dbc016
2022-11-21 10:56:47 +01:00
Pau Espin 22b4e8159d osmux: Introduce API osmux_xfrm_input_set_name()
This will be used internally by osmux code to print more meaningful
lines.

Related: SYS#6161
Change-Id: Ibbcfdb23a6015ce45840bb64b2b560c2806f7ff6
2022-11-18 17:37:46 +01:00
Pau Espin c798429cb0 osmux: Support recreating lost RTP packets at start of the batch
Previously, if RTP jumps were detected in the incoming RTP stream and
osmux state for that circuit was to start the next batch, the hole would
not been filled during queueing time and instead the encoder would have
set the M bit in the osmuxhdr to announce a sync point.
For small holes (eg less than the batch factor) it makes sense to start
filling the batch with crafted RTP packets in order to avoid the encoder
later on setting the M bit and hence avoid the peer receiving the Osmux
frame having to start a new syncrhonization point.

Related: SYS#6161
Change-Id: I9596501adf5b7b91983618c92c7b1792ee9461a3
2022-11-18 16:46:00 +01:00
Pau Espin b8ef4a0853 osmux: Set M bit in osmuxhdr if seqnum hole found encoding RTP pkts
So far only small intra-batch seqnum jumps are filled in with forged RTP
packets when storing the incoming RTP packets.
Under some conditions, holes may still exist in the queue of RTP packets
for a stream:
* Seqnum detected when first incoming RTP in batch is queued (this can
  be improved in the future).
* Big seqnum jumps > batch_factor or simply filling out of bounds for currently
  enqueued batch.

Specially the second case can come from long network dropouts, or simply
due to a bug in the RTP being feed to osmux layer (be it from local code
or peer). In that case (long jumps) we don't want to generate tons of
packets filling in several entire batches (potentially incredibly big
amount of batches).
Instead, in these scenarios, simply let the osmux peer know there was a
jump by setting the M bit on the next osmux header for that circuit
after the seq jump has been detected.

Related: SYS#6161
Change-Id: I05b1eae400cb60d1f4e927f853619d5ff470163f
2022-11-16 19:54:16 +01:00
Pau Espin 8e4f8574d1 osmux: Avoid filling in seqnum holes upon rx of RTP pkt with M bit set
Change-Id: I561fb836989d31f43a15b193ed9bec4103ea0f2b
2022-11-16 19:53:31 +01:00
Pau Espin e6306faebd osmux: Use better rationale when limiting amount of lost & forged RTP incoming packets
Related: SYS#6161
Change-Id: I4ea700dbbf469498befc939a844324259bbe332a
2022-11-16 19:53:28 +01:00
Pau Espin 348229a37c osmux: Obey current batch_size restrictions when creating forged RTP packets to fill holes
osmux_link_add() is renamed to osmux_link_handle_rtp_req(), and the last
part of it is split out and kept as osmux_link_add().
hence osmux_link_handle_rtp_req() does proper input checking (like
duplicates, holes, etc.) while osmux_link_add() expects all that to be
sorted out.
Reuse osmux_link_add() in osmux_replay_lost_packets() to properly update
the link state of the to-be-transmitted packet, circuit state, etc.

Change-Id: I4ea435bfb2490a375ad3e5068ee926e48b53cf5c
2022-11-16 19:49:42 +01:00
Pau Espin ab65ae0906 osmux: Drop noop OR during assignment
osmuxh->rtp_m is zeroed at that point, it makes no sense to bit-OR at
that point.

Change-Id: I09c920035b1aa1af139a2a63f7cb4a3390bb9d36
2022-11-16 17:57:58 +01:00
Pau Espin 3424ee0c8d osmux: Drop marker bit in forged RTP packets to fill gaps
If the last RTP we received from the user is a Marker bit (which is
expected to be the first in the batch), then there's no need to keep
marking the forged RTP packets to fill holes also as Marker bit.

Change-Id: I5cef6185afbfce748473a096e8ebabd9c9628e12
2022-11-15 19:55:03 +01:00
Pau Espin 8925bf96d5 osmux: recreate lost RTP pkts before handling newest one
In the event we need to fill in the batch with intermediate lost RTP
packets, we must do so before handling the last one.

Change-Id: Ib5dd7b1fa6213c96ece803b781a7ef1cf102a1d4
2022-11-15 19:55:03 +01:00
Pau Espin 7c4d953b6d osmux: dup in RTP pkt: Replace potentially internally forged pkt with incoming one
When RTP packet provided by user to osmux layer, it may contain a seq
gap, and osmux will refill the packets to avoid losing that information
on the other side when it receives the batch.
If out of order UDP packets are received, it can happen that we first
detect a gap and later on we receive the previous RTP packet, which we
is then detected as duplicate because it was previously forged to fill
the hole. In that case, let's better keep the incoming packet instead of
the potentially internall forged one which doesn't contain the real AMR
payload.

Related: SYS#6161
Change-Id: I82e11ef3dcd20ffea33c94ed83abcedf0f186871
2022-11-15 19:55:03 +01:00
Pau Espin 710d304208 osmux: dup in RTP pkt: check before applying queue flush due to Marker bit
We need to filter duplicate messages before checking the Mark bit and
returning 1 to tell the user to deliver the current batchset content.
Otherwise, a repeated RTP packet with an M bit would trigger delivery,
which is wrong.

Change-Id: I4a01b0935f112d650d8fc161b3389eda6c8e75ec
2022-11-15 19:55:03 +01:00
Pau Espin 2fca99c7cf osmux: Use internal struct to cache parsing state of rtp pkt from user
This allows incrementally gathering all the information once and only
once. While doing so, this patch tends to move the decoding/parsing of
the incoming RTP packet further towards the start of the code, hence
detecing errors in the input data early in the process and avoiding
touching internal state in this case.

Change-Id: I55e0d2772e7054c0d734f5918c6938a5c8a6e781
2022-11-15 19:54:59 +01:00
Pau Espin c272446dc1 osmux: Fix endianness logging duplicaed seqnum
Change-Id: I431d3a64e971bd7ba2bed007265559af876bc10b
2022-11-15 16:43:52 +01:00
Pau Espin b0a2f549df osmux: Add internal backpointer to in_handle to simplify param passing
A lof of mess is inherited from the fact that there's a public object
(struct osmux_in_handle) which internally uses a private object (struct
osmux_link).
The struct osmux_in_handle fields are no longer expected to be accessed
or allocated by the user, hence the struct is only kept in the header
for backward compatibility with older versions.
At some point, both structs can be moved to the C file and merged,
simplifying the code further.
For now, let's simply add a backpointer from struct osmux_link to the
related struct osmux_in_handle, so that we can pass 1 pointer and have
all fields accessible in the code.
This allows further simplifying the code.

We could also add an extra backpointer from osmux_circuit to osmux_link,
but that's not really estimated as needed as of now since we can easily
pass the osmux_link pointer down the called functions.

Change-Id: I5c226c5c809a240f9eb80aa2e83679adc717d717
2022-11-15 16:24:50 +01:00
Pau Espin 20ed5bfeb0 osmux: rename internal struct osmux_batch -> osmux_link
This struct matches the lifecycle of the link, holds all the circuits
acting as a trunk. The previous name was utterly misleading since "batch"
usually is per circuit group of AMR frames with an osmux header.

Change-Id: Ib118fd2c1fead78655756156ce5d4ce4a6d080df
2022-11-15 14:59:20 +01:00
Pau Espin 9ee4c974b4 osmux: Fix naming of functions operating on osmux circuits
Let's put the object and update the naming of the functions accordingly.

Change-Id: Ieaac449fe04831e47ff932c234c18994f157df88
2022-11-15 14:51:24 +01:00
Pau Espin e94ab6efb4 osmux: Log AMR FT when incorrect AMR payload size detected
Change-Id: Idd9712644d9a6204f1fe972cbbd393d4b7fd34f6
2022-11-14 18:27:17 +01:00
Pau Espin ac73f1c330 osmux: Use msgb_copy() API in osmux_replay_lost_packets()
Change-Id: I137872af77dbce68210ad8ef7f61bd337811c7c4
2022-11-14 17:53:19 +01:00
Pau Espin 17fca03cf8 osmux: Rework log formatting when replaying detected RTP gaps
The existing code has several flaws which will be fixed in follow-up
patches.

Related: SYS#6161
Change-Id: I5fd64acf7bc1e53efae0674d0c906d1255a9bbf6
2022-11-14 17:53:16 +01:00
Pau Espin 2cd10fe9bb amr: Document SID frame length from spec
Change-Id: I15197857d17829c1dc7408b6f007fabb3a80a537
2022-11-02 11:21:14 +01:00
Pau Espin a07cf80746 cosmetic: Fix indentation whitespace
Change-Id: Ia47d30aceee0db30b403575dd696c1bec2dcf271
2022-10-24 17:59:12 +02:00
Pau Espin d8c5a906b4 stream: Introduce APIs osmo_stream_{cli,srv}_clear_tx_queue()
Related: SYS#6113
Change-Id: Iecb0a4bc281647673d2930d1f1586a2df231af52
2022-10-17 13:48:07 +02:00
Pau Espin c76b54ba63 stream: Improve logging of SCTP_PEER_ADDR_CHANGE notification
Related: SYS#6113
Change-Id: Ieebc6e623874b4770ec7cd8b934244ffecaa089d
2022-10-17 12:27:16 +02:00
Max 3be20740bc Better handling of send() error
Avoid logging confusion when -1 == ENOTSUP.

Change-Id: Iaa7e16e717c56466c5d9a64deb438776ca88022e
2022-10-08 16:42:06 +00:00
Pau Espin f10f354e3f osmux: Introduce API osmux_xfrm_input_get_deliver_cb_data()
This API allows retrieving back the private pointer set previously by
osmux_xfrm_input_set_deliver_cb().

Change-Id: I95433b18802f73fa70e758f4aa02128eee940d88
2022-10-03 17:21:10 +02:00