Commit Graph

465 Commits

Author SHA1 Message Date
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
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 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 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 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 2640c157f8 osmux: Print osmux_hdr rtp_m field in osmux_snprintf()
Change-Id: Idfe530b944ac5dfd5ce6b5150421c2d4daee8788
2022-09-28 19:03:52 +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 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
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
Pau Espin c3a6c75cea stream: osmo_stream_cli: Support setting multiple addr
This API will be later used to set multiple addresses for SCTP sockets.

Depends: libosmocore.git Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Related: OS#3608

Change-Id: I09f0d989f2309abdeb304fe570355abed2cd107b
2019-10-15 13:11:54 +02:00
Pau Espin f254ef80f2 stream: osmo_stream_srv_link: Support setting multiple addr
This API will be later used to set multiple addresses for SCTP sockets.

Depends: libosmocore.git Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Related: OS#3608
Change-Id: I0fe62f518e195db4e34f3b0ad1762bb57ba9d92a
2019-10-15 13:11:51 +02:00
Pau Espin c25285f40e stream.c: remove duplicated line setting variable
Change-Id: I03b05179f5656ab81e5e14cd146f82a471f7b071
2019-10-10 12:26:30 +02:00
Pau Espin 238c844593 osmux: squash LOGP message to one line
It seems different compiler versions (jenkins and my workstation) are
generating different line number for that message, and it makes osmux_test
fail when improving logging on next commit.

Change-Id: Ie2bb0ecf4cc165b9a1080e2558b33ba37014278c
2019-10-04 16:00:31 +02:00
Pau Espin 69e04689bf osmux: osmux_snprintf(): Remove dangling whitespace at the end of dummy frames
Change-Id: I1ef73807c3300cbcc332f32e6bb905d9b30557be
2019-10-04 12:43:43 +02:00
Pau Espin b4486278b9 osmux: osmux_snprintf(): Append comma between osmux frames in msg
Change-Id: I7acaba9429466db6cb5700b206d6b42da5e4627a
2019-10-04 12:32:13 +02:00
Pau Espin a1e9de1ec4 stream: Fix scheduling of queued messages during connecting state
If messages are sent using osmo_stream_cli_send() while the stream
is still (re)connecting, they won't have a chance to be sent until the
stream is connected, and hence they are queued until
CONNECTING->CONNECTED is done. However, at that time
(osmo_stream_cli_fd_cb), the WRITE flag was dropped unconditionally,
which meant already queued packets didn't have the opportunity to be
sent by the same callback until first message is enqueued and WRITE flag
is set (again by osmo_stream_cli_send()).
Let's make them be sent as soon as possible once the connection is
available.

Related: OS#4188
Change-Id: I289495f9aad6389c5f2623fb072d676235b7d24c
2019-09-04 17:40:22 +02:00
Pau Espin 962bf9a48e stream: Introduce API osmo_stream_cli_is_connected
Can be used by users to fetch current status of the stream.

Change-Id: I5402430e5f39eef22dfa18f33807ab6b1e771f1b
2019-09-04 17:04:18 +02:00
Pau Espin 592057bb33 Bump version: 0.5.0.2-6563-dirty → 0.6.0
Change-Id: I3af3b7aaff5c6dc3ac94e942191e27af4bf5392a
2019-08-07 20:59:51 +02:00
Pau Espin f0f1ebf70e osmux: Extend osmux_out_handle and add new API to set rtp payload_type
Previously payload_type was always hardcoded to 98 for generated rtp
packets from incoming osmux frame.

Change-Id: I5cbeb494a8932953d9fd2dc24dacf8cd97fd84e4
2019-05-17 17:12:56 +02:00
Harald Welte fd339712c4 Bump version: 0.4.0.1-738f → 0.5.0
Change-Id: Iea2da939e259d0a9e7c5dad14d7a961434c276ef
2019-05-10 12:40:04 +02:00
Philipp Maier e380b38e28 amr: use sizeof(struct amr_hdr) when working with amr header length
The header of an AMR header payload is 2 bytes long. At the moment we
use just a constant of 2 when we refer to the header length, but we have a
struct amr_hdr defined. Lets use sizeof(struct amr_hdr) to make it more
clear that we are refering to the header length.

Change-Id: Ic7ca04b99a97d7d3b91717b0c3e6c55ef3001a3e
2019-03-20 15:45:05 +01:00
Max b3e34435b3 Deprecate osmo_stream_cli_open2()
This supposed to be variant of osmo_stream_cli_open() with explicit
control over reconnection logic but it's plain broken: doxygen docs
contradict the code, actual reconnection logic is affected by timeout
parameter directly which is set in different function.

It seems like we haven't been affected by this so far because we always
use it in auto-reconnection mode which is triggered by default due to
positive reconnection timeout value (5 sec) automatically used in the
absense of explicitly set timeout.

Looking at commit history, this function already been source of
confusion in the past. Instead of trying to fix this mess, let's just
deprecate it entirely and properly document use of
osmo_stream_cli_set_reconnect_timeout() to control reconnection logic.

The only known user is libosmo-sccp which won't use it as of
0a93a683f3cb8e5977eb4a666ab207db6e7d7af9 commit.

Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a
2019-03-19 13:40:55 +00:00
Philipp Maier 5ca043655a amr: be sure result of osmo_amr_bwe_to_oa() fits into int buf
osmo_amr_bwe_to_oa() uses an internal buffer with static size to store
intermediate results. The buffer is large enough for any real world
situation, but the check that tests if the result would fit into the
internal buffer is incorrect. It checks if there is enough room for the
existing payload, but does not include the expected growth of the
payload. Eventually the buffer could be overrun by one byte if one would
put a 256 byte long AMR payload.

Fixes: CID#195926
Change-Id: I4d7ac570a0b48368a82183673c46bca5f235f228
2019-03-12 09:29:06 +01:00
Philipp Maier 3e77d57281 amr: cosmetic: correct sourcecode formatting
Change-Id: Ie4ad6b1a2382da4dc21e66a45c2a96224cab5752
2019-03-12 09:29:06 +01:00
Philipp Maier fa7df87260 AMR: add functions to convert between bw-efficient and octet-aligned
RFC 3267 describes two different AMR frame formats. Octet Aligned and
Bandwidth efficient mode. In Bandwith efficient mode the padding bits,
which are used to align CMR, TOC and payload on octet boundaries are
saved and the fielda are packed directly one after another.

- Add functions to convert from one mode to the other and vice versa.
- Add function to detect in which mode an AMR frame is encoded.

Change-Id: I5b5a0fa644d8dbb1f04f9d7e35312683c7b3d196
Related: SYS#4470
2019-03-07 10:22:22 +01:00
Philipp Maier 0fe9b3664a AMR: add define constants for AMR payload length
AMR uses different payload sizes, those sizes are well defined in RFC
3267. Lets add define constants and replace the magic values with the
define constants.

Also correct the value for AMR_FT_SID in amr_ft_to_bytes from 6 to 5
(39bits / 8 = 4.875 bytes ==> 5 byte, see also RFC 3267, chapter 3.6)

Change-Id: I65b5da920d58015b875d6dcf17aacdc04b58955e
2019-03-01 09:12:20 +01:00
Max af63d87a76 Stream client: add disconnect callback
It's similar to connect_cb() but called once client has been
disconnected.

Change-Id: I905adb2d6191216551a3bcdcd1aec1f96f01612a
2019-02-20 17:33:32 +01:00
Max 1a357720b5 Stream client: report reconnection event as INFO
This helps to avoid unnecessary debug output in reconnection logic tests
in follow-up patches.

Change-Id: Ic96430a9e9294e72de23b0bbacdbf3e99a453f1d
2019-02-07 13:38:22 +01:00
Max 827d693b50 Stream client: fix disconnection logic
Previously closing the client did not alter its state, so we might
end-up with a client without any file descriptors, but being in state
STREAM_CLI_STATE_CONNECTED. Fix this inconsistency by setting
appropriate state.

Related issue is that reconnect function, which is always (at least in
the library and examples) called when some problem with the connection
is detected, closed the connection only after checking whether
reconnection is enabled. This might result in another inconsistency
fixed in this patch by moving the check below connection cleanup.

While at it, also move connection close logging to appropriate place:
it's confusing to see logs about connection being closed while in
reality it wasn't even established.

Change-Id: If41ed60bd625488c283d1e8a2b078e640f04c78e
2019-02-05 16:26:49 +00:00
Max 732652b5b7 Add socket name functions to stream client/server
Add functions to get the description of a server link or client
connection which examine data on corresponding socket.

Those functions use static buffers and intended for single use in
log/printf statements as illustarted by corresponding example changes.

Change-Id: If9a8e211da85956781479862a63c4fc6e53ed6be
2019-02-05 16:25:20 +00:00
Max a93bb2ca34 Stream client: update logging
Introduce logging macro wrapper to properly log current client state and
function to aid in debugging.

Change-Id: Ie22a80dcec95998cce0b25053fdf74f23eab6e53
2019-02-05 16:21:26 +00:00
Max e3366cf144 Stream client: fix doxygen typo
Change-Id: Ic45d3e0520db4060c5c24e5ef5a766a52f060a34
2019-02-04 13:23:27 +01:00
Harald Welte c775ffe1cc Bump version: 0.3.0.6-a555 → 0.4.0
Change-Id: I99a3244f922382468251df675287520ca40d9d0d
2019-01-20 10:12:46 +01:00
Neels Hofmeyr dc8fcf5a69 logging: fix typo in stream.c
Change-Id: I5dcae1f19e18f04709ce7585943af1d582ebc7ed
2018-12-10 13:11:41 +01:00
Stefan Sperling a555a1fca2 detect freed connections in osmo_stream_srv_read()
While we are processing a read event, the connection's
callback might free the connection. Check for this and don't
attempt to process further events on an already freed connection.

Change-Id: I0a9c7d8e3263c73440f7084dbb1792a4ca5038f0
Related: OS#3685
Depends: g#11704 (for libosmo-sccp)
2018-11-09 15:33:19 +01:00
Pau Espin 7028d7387e jibuf: fix indentation in line inside conditional clause
Change-Id: I3cb356a4a13d53e7f88a5e4595899bb2eb510d20
2018-08-13 16:09:24 +02:00
Harald Welte 635984c5e1 link libosmo-netif against libosmogsm
The recently-introduced dependency to libosmogsm symbols needed
some explicit addition of linker flags to avoid user applications
to fail linking with
/usr/bin/ld: /usr/local/lib/libosmonetif.so: undefined reference to `ipa_ccm_id_resp_parse'

Change-Id: I07a28f8970b90f82736e2de783bafc9d2c5ea0e5
2018-08-01 18:02:04 +02:00
Harald Welte da5f41cdad Migrate from osmo_ipa_idtag_parse() to ipa_ccm_id_resp_parse()
In libosmocore Change-ID I1834d90fbcdbfcb05f5b8cfe39bfe9543737ef8f
we have introduced ipa_ccm_id_resp_parse() as a bugfixed replacement
of ipa_ccm_idtag_parse().

The main difference is that the returned "value" parts now have
a correct reported "length", whereas before this commit they all
reported a one-byte too-long "length" for each IE.

Let's use this opportunity to remove the copy+pasted
osmo_ipa_idtag_parse() function from the libosmo-netif codebase.

Change-Id: I4626d247626543e032593bf226b6c233f6678562
2018-08-01 17:36:21 +02:00
Neels Hofmeyr d5a35ed932 fix strncpy bug in rs232.c
Change-Id: I2f3b7888acb4f25da22ffef4391e1d0831485483
2018-07-27 18:51:59 +02:00
Pau Espin 322dbbeaa2 Bump version: 0.2.0.6-ac33-dirty → 0.3.0
Change-Id: Ic9bbe8427c44ef2a9ee02537f17821048f177cdd
2018-07-27 18:31:43 +02:00
Harald Welte ac33f6fbd2 stream.c: Use non-blocking connect in osmo_stream_cli
When establishing a client-side stream connection via libosmo-netif,
we must using non-blocking connect if we want to avoid blocking/stalling
the entire process.  The libosmocore socket API provides the
OSMO_SOCK_F_NONBLOCK flag for this.  Make use of it!

Change-Id: I9bfcb39b5801a36ef32ca0d1f3eb8236687d7ed6
Related: OS#3383
2018-07-05 14:07:25 +02:00
Harald Welte e2fbd3dee4 remove "channel" layer
The "channel" layer on top of IPA client + server was introduced in
2011 but never used in any osmocom program/project so far.  Contrary
to the several other IPA multiplex related implementations in libosmo*,
it did not deal properly with segmented IPA messages, i.e. where a
single TCP segment (and hence recv/read call) does not contain a full
IPA message.

So rather than fixing it up and having yet another IPA related API in
our libraries, let's remove it.

Change-Id: I97c378750acb1637ee032fa88a968edf68d8979f
2018-06-29 10:57:24 +02:00
Pau Espin 7839556ca9 osmux: change log lvl of batch full to debug
This message is expected as all code filling batches call
osmux_batch_enqueue() and checks for error to know if it must tell the
user of the lib to call osmux_xfrm_input_deliver.

Change-Id: I3d8227f2281f6ca92fd2502d3e328765dc7ecfe9
2018-05-15 17:09:19 +02:00
Pau Espin 7b7562a713 jibuf: Fix out-of-order seq queue around syncpoints
Fixes: OS#3262

Change-Id: Ib8c61dbe6261cf73d6efcd7873e23b7656117556
2018-05-15 16:49:50 +02:00
Pau Espin e38ee9b808 Bump version: 0.1.1.38-ef190-dirty → 0.2.0
Change-Id: Ic8a9e44b2f930fed024040777eab58699fdcaadc
2018-05-03 16:55:21 +02:00
Harald Welte ef19001517 osmux: Fix use of uninitialized memory in osmux_out_handle
In Change-Id: I2efed6d726a1b8e77e686c7a5fe1940d3f4901a7 we're adding a
new member to 'struct osmux_out_handle' which is not initialized.

Rather than initializing this single new member, let's do a memset()
over the entire osmux_out_handle at the beginnign of
osmux_xfrm_output_init().

Change-Id: I751e9414c6de2413a9f977e5ae5655ebfd114f45
Closes: OS#3219
2018-04-28 13:36:40 +02:00
Pau Espin e259c8ab18 osmux: Set Marker bit on osmux frame loss detected
Until this patch, we didn't notify in any way to the RTP reader when an
Osmux frame was lost. Instead, we updated the seq&timestamp as if there
was no lost, and as a result the RTP reader would only see a steady
increase of delay every time an osmux frame was lost.

As the batch_factor for the lost packet is unknown, we cannot assume any
number of amr payloads lost, and thus we cannot simply increment seq and
timestamp for a specific amount. Instead, the only viable solution seems
to set the M marker bit in the first rtp packet generated after a
non-consecutive osmux frame is received.

The implementation may act differently with the first generated RTP
packet based on the first osmux seq number used for the stream. In case
0 it's used as first osmux seq number, M will be set depending on
request from original RTP packet having the M bit set. If it's not 0,
the first RTP packer will unconditionally have the M bit. That's not an
issue because it's anyway expect for receiver to sync on the first
packet.

Related: OS#3185

Change-Id: I2efed6d726a1b8e77e686c7a5fe1940d3f4901a7
2018-04-19 18:24:25 +02:00
Pau Espin dbf8e53192 osmux: Add new API osmux_xfrm_output_sched to fix rtp generation issues
With old implementation, in conditions with jitter we could end up
scheduling RTP generated packets from two consecutive osmux frames in an
interleaved way (from seq field point of view).

This new implementation should make it easier for any RTP
reader/playback to have better results in those conditions.

Old APIs osmux_xfm_output and osmux_tx_sched are marked as deprecated in
favour of the new one, which has a better control of generated RTP
packets. However, they are still usable despite the implementation changes
done to support the new API.

Related: OS#3180

Change-Id: I4e05ff141eb4041128ae77812bbcfe84ed4c02de
2018-04-19 18:24:25 +02:00
Pau Espin e9e6200d84 jibuf: Estimate src clock skew
Change-Id: Ifae633d53107417a8e2f9b0f200d2711db72d199
2018-04-13 16:13:17 +02:00
Pau Espin 13c01178c5 jibuf: re-sync clock out of sync timestamps
Change-Id: I33556b33d7549654442d9bdd7f31128792506652
2018-04-13 16:13:17 +02:00
Pau Espin 1ad87f26a1 jibuf: Take RTP marker into account
Change-Id: Ie142acfb45650e0af775f58226fd191beaf8178e
2018-04-13 16:13:08 +02:00
Pau Espin ce820763c1 jibuf: Add initial implementation of Jitter Buffer
Change-Id: I9688ba9c4d5b733b9f29d0f15f73750f9271ef55
2018-04-13 15:51:43 +02:00