Commit Graph

465 Commits

Author SHA1 Message Date
Pau Espin 05ff552f25 stream_{cli,srv}: Add 'res' param to read_cb2
Notify user about read errors, similar to what is supported in the
earlier ofd cb backend of osmo_stream_cli/srv:
https://osmocom.org/issues/6405#note-15

Related: OS#6405
Fixes: 5fec34a9f2
Fixes: 0245cf5e07
Change-Id: I395c75ff1e9904757ce1d767a9ac2f779593c4c8
2024-04-18 10:55:13 +02:00
Pau Espin a423e12284 stream: Define types for each API callback
The amount and complexity of callbacks is increasing over time.
Use typedefs to define each of them so that callbacks:
- Are easier to identify (which types is used where)
- Are easier to document (have a 1st class place to write doxygen
  documentation)

Change-Id: Ib0c4a9713fa4c755e457b8c2cbde6a7724d36e28
2024-04-17 13:53:57 +02:00
Pau Espin 554a4b2f9d stream_cli: Remove unused write_cb field
Change-Id: I50bee754d01d8de01f4a25c14abf90275a1ac78e
2024-04-17 13:53:27 +02:00
Andreas Eversberg 5fec34a9f2 stream_cli.c: Handle read / recvfrom error and close connection
If read or recvfrom fails or returns 0, the connection must be closed.
This is already done when a write / send fails. In both cases the
disconnect callback is called to notify the user's client.

Not handling the error may cause an infinite loop of read or recvfrom
failures.

Related: OS#6405
Change-Id: I55426de6b49cb4cb0797e50dfeae11f2efc29b15
2024-03-22 07:34:32 +00:00
Harald Welte ed62d190b6 docs: Improve/clean-up doxygen for datagram.[ch]
* make sure datagram.h is part of the group
* don't expose private #defines from C files to API documentation

Change-Id: I64a9ee3306bcc01ba785da476aea581ce31150bd
2024-03-19 14:20:15 +01:00
Harald Welte 2136d599af docs: various osmux API documentation updates
Let's make sure
* only exported / user-relevant #defines appear in the manual
* deprecated functions are marked in a way doxygen can mark them
* descriptive comments are using doxygen syntax

Change-Id: I5af0133322ddd5345a13380f1c007474c0bea117
2024-03-19 14:20:15 +01:00
Harald Welte 34a657d1e1 introduce osmo_stream_cli_get_iofd() API
Using this, a user can obtain the osmo_io_fd, for example in order to
perform configuration like osmo_iofd_set_alloc_info() or
osmo_iofd_set_txqueue_max_length().

Change-Id: Ie19c8294ddb12dfe5e0fd44e047c47e6f9cbd384
2024-03-17 17:41:22 +00:00
Harald Welte f67400d353 docs: jibuf: Prevent internal #defines being documented
Change-Id: Ic3c6e32acb52595875de89f6054a62d9565747f9
2024-03-15 14:14:08 +01:00
Harald Welte 912360157d docs: Split Stream Server and Stream Client into separate groups
This provides us with proper logical separation between client and
server in the documentation.

Change-Id: I9e037fedaecb78396f435577b1652284b4951ded
2024-03-15 14:14:07 +01:00
Harald Welte 8963af0f60 docs: More verbose stream_{cli,srv} API documentation/manual
Change-Id: Iae3c3af6533be408e5755ceeda0067606a3b0ca1
2024-03-15 14:13:32 +01:00
Harald Welte 104265733f Ensure osmo_stream_{cli,srv}_recv() is used only in osmo_fd mode
The osmo_stream_{cli,srv}_recv() is only for osmo_fd mode users; in
case osmo_io mode is used, the read_cb is called with pre-filled message
buffers; no need to recv/read directly anymore.

Change-Id: Ie96cf1241b2ba4e0a7dda584182d18cad2b4f061
2024-03-15 14:13:32 +01:00
Harald Welte 472354b693 docs: Use \defgroup and avoid repeated boilerplate text
Change-Id: I1196c3b035f495c5dbaa4d47ce3f79a08d0727f2
2024-03-15 14:13:31 +01:00
Pau Espin 69878f30fa stream_srv: Fix retrieve of srv_link sockname for AF_UNIX sockets
Change-Id: Idd76ee3b5c9ad503eabd29d676a5d84e34d92071
2024-03-13 11:57:47 +00:00
Pau Espin a5722bb75d prim: Introduce osmo_prim_srv{_link}_set_name APIs
This allows a user setting a name on the underlaying stream which
in turns allows easily identifying the socket.

Change-Id: Iba683e4d65e0aba81e13bdf1b9d5a9065b1fc89c
2024-03-13 11:57:47 +00:00
Pau Espin 36eb157ed6 stream: Add osmo_stream_*_get_name() APIs
This allows users to retrieve a previously set name.

Change-Id: If5054d3c207f8f5d58a448f1e58266ad9c4386dd
2024-03-13 11:57:47 +00:00
Harald Welte c17dc5f559 osmo_stream_cli_send(): Drop data if client is not connected [yet]
The behaviour is undefined on what should happen if a stream client user
is trying to write data before the client socket is connected.  In
osmo_io mode we would actually crash due to a NULL-pointer dereference.

Let's discard any sent data in this situation and print a related error log message.

This problem actually shows up with osmo-bsc Change-Id
Icce412e6ee69366c7b131c9bc1d51e8d44204917 where we convert CBSP over to
osmo_io - here in situations where a CBSP client (using stream_cli) was
previously connected but has lost its connection.

Change-Id: I18d2e8e850c23a32f5983a715fa8a18747b296cd
2024-03-12 17:36:02 +00:00
Pau Espin d047924463 osmo_prim_srv_send: assert prim_srv is not NULL
Related: SYS#6826
Change-Id: I1122a1de2c29ee46cce22cec907576719e9c3721
2024-03-12 12:05:32 +01:00
Andreas Eversberg e1153bcd37 stream_cli: Correctly setup and free osmo_io client instance
Free osmo_io instance when calling osmo_stream_cli_close().
Also free osmo_io instance when calling osmo_stream_cli_open() if not
freed, to prevent memory leaks.

osmo_iofd_notify_connected() must be called before any registration
of read or write, because osmo_io_iouring does not allow this.

Change-Id: I91a6a76b9ff96034a7b333edf87af27490202932
2024-03-07 10:28:17 +01:00
Vadim Yanitskiy 1eb221a923 osmo_stream_cli_write(): fix double-free of msgb
Change-Id: I954678acd90593e5311d22a10033c7741f280be3
Fixes: 48f9a3c2 "stream_cli: Proper handling of send() socket errors"
2024-03-05 17:05:50 +07:00
Andreas Eversberg da3ca9a69e stream_{cli,srv}: Free received messages when not forwarded
If a message is not forwarded (to a read callback function, it must be
freed, to prevent memory leaks.

The message musst be freed before calling osmo_stream_srv_destroy() or
stream_cli_handle_connecting(), because within the function calls the
client/server instance may get destroyed and the message is 'owned' by
it. Calling msgb_free(msg) afterwards may result in double free bug.

Related: OS#5753
Change-Id: Ic043f11cdba0df9e0b78cac8db7206800098e0ba
2024-03-02 09:21:43 +00:00
Harald Welte 313f528027 osmo_io: make use of osmo_iofd_get_ioops()
This avoids resetting the callbacks with the wrong ones in the SCTP
case.

Change-Id: Id3cb11bc0000299faa79d980de8abc1980916d70
2024-03-02 09:18:00 +00:00
Andreas Eversberg d467b6348c stream_{cli,srv}: Fix memory leak, if sending a message fails
Also the example client/server must not access msgb after sending it,
especially if the msgb got freed due to a failure.

Change-Id: I627a71b4f0183cd83835c328a5cdd67a413ae614
2024-02-29 13:23:20 +01:00
Harald Welte 7e6d2e0f99 stream_{cli,srv}: Add support for SCTP in OSMO_IO mode
Let's enable the OSMO_IO_FD_MODE_RECVMSG_SENDMSG mode for SCTP
sockets, allowing OSMO_STREAM_MODE_OSMO_IO to be used with SCTP.

Change-Id: I6cf5bad5f618e71c80017960c38009b089dbd6a1
Depends: libosmocore Change-Id: I89eb519b22d21011d61a7855b2364bc3c295df82
Closes: OS#5753
2024-02-29 13:23:13 +01:00
Pau Espin 26cdbe02be stream_srv_link: osmo_stream_srv_link_get_sockname() now returns the full set of addresses
As a result, internal stream_srv_link logging will also show the whole
set of listening addresses. This is mostly fine since it mainly happens
only once, during connection accept(), and this way it provides full
view of where from and where to the client connected.

Depends: libosmocore.git Change-Id I18a0e1a652a3e8ef3e97154355eb1d07a14ef0bd
Related: SYS#5581
Change-Id: I216502a9aeafe638940f110bc9fddf2504b2ac3a
2023-12-12 15:47:34 +01:00
Pau Espin 5aa00fe885 stream_cli: Introduce API osmo_stream_srv_get_sockname()
Similar to what osmo_stream_srv_link and osmo_stream_cli already have.

Change-Id: I171befd1fdf40c3cbb3fc7e4c3eedf82128b0712
Related: SYS#5580
2023-12-08 18:43:31 +01:00
Pau Espin d4407a7f32 stream_cli: osmo_stream_cli_get_sockname() now returns the full set of addresses
This is used by API callers, and internally to log
connected/disconnected events.

Related: SYS#5581
Change-Id: I249ee7cad824cf971faabe06d10de2426c1b0c8b
2023-12-08 18:43:31 +01:00
Pau Espin a7650de412 netif: sctp.h: Introduce value_string for enum sctp_sstat_state
This can be used by apps retrieving struct sctp_status through
getsockopt(SCTP_STATUS).
The relevant field is spinfo_state: osmo_sctp_sstat_state_str(st.sstat_state);

Change-Id: Id7d8a9ad7b32406ac603e520b33809d7ae5c762f
Related: SYS#6636
2023-12-08 17:45:20 +01:00
Pau Espin 1810e12df3 netif: sctp.h: Introduce value_string for enum sctp_spinfo_state
This can be used by apps retrieving struct sctp_paddrinfo through
getsockopt(SCTP_GET_PEER_ADDR_INFO).
The relevant field is spinfo_state: osmo_sctp_spinfo_state_str(pinfo.spinfo_state);

Related: SYS#6636
Change-Id: I78a0bd8279a04f4011c7273e0f542981308e482f
2023-12-08 17:45:07 +01:00
Pau Espin 14dd5ba329 stream: Add missing osmo_stream_srv_link_get_fd() API
osmo_stream_srv and osmo_stream_cli already had that API introduced in
order to use it instead of *_get_ofd(), since the later will eventually
be deprecated due to incoming osmo_io.

Change-Id: I1bd3f790d93af74c150938a59108b882ad2820f3
2023-12-06 17:56:46 +01:00
Pau Espin a15d8f7f20 stream_cli: Fix opening sctp client socket if no local address set
Properly call osmo_sock_init2_multiaddr2() to use default binding
address if user of osmo_stream_cli didn't set one on the object
through the API.
osmo_sock_init2_multiaddr2() was also borken under that scenario until
recently (see Depends below). Until now, users of osmo_stream for SCTP
(mainly libosmo-sccp) relied on always setting a proper local address to
overcome this limitation.

Depends: libosmocore.git Change-Id I2641fbaca6f477404b094dbc53c0c1a3dd3fd2fd
Related: OS#6279
Change-Id: I0d9d0e48690c915f7b51ad09f452e551e01368b5
2023-12-06 13:46:28 +01:00
Harald Welte 5ccee1e1b1 Introduce generic osmo_stream_{cli,srv}_get_fd() API
The old osmo_stream_{cli,srv}_get_ofd() API only works for streams
in OSMO_FD mode.  However, it is legitimate for an application
wanting to get low-level access to the file descriptor, for example
to issue some {get,set}sockopt() calls on it.

Change-Id: Ib0737f21150f6ac8d524b92c7ddb098f2afdeaab
Related: OS#5753
2023-11-21 20:25:21 +01:00
Harald Welte 1a5f879ae2 stream_srv: osmo_stream_srv_get_ofd() works only in OSMO_FD mode
The corresponding client function osmo_stream_cli_get_ofd()
already contained an OSMO_ASSERT, but the server side was missing
this so far.  The 'ofd' member only has meaning in the context
of OSMO_FD, so calling that function from generic code is wrong!

Change-Id: I50df259040e011135a31fe1aee231eba430fa94a
Fixes: Change-Id I2f52c7107c392b6f4b0bf2a84f8c873c084a200c
Related: OS#5753
2023-11-20 12:25:43 +01:00
Daniel Willmann 8601625666 stream_srv: Make osmo_stream_srv_clear_tx_queue() aware of osmo_io
Change-Id: I818fe4e3792ed88ae4d6fd6afb677b39264ab662
2023-10-24 19:38:04 +00:00
arehbein 106b63907a stream: Add and use helper function osmo_ipa_push_headers()
Related OS#5753, OS#5751

Change-Id: I61e1fe59166c46595efe8c1f32b8f2607cb6c529
2023-10-09 12:49:36 +00:00
arehbein bc496b1db0 stream: Add client-side (segmentation) support for IPA
With this commit, IPA segmentation is taken care of by setting the
segmentation callback provided by libosmo-netif.

The ipa-stream-server example needs to prepend IPA headers now because
those are stripped by the segm. cb on both sides.

Depends: libosmocore.git I3a639e6896cc3b3fc8e9b2e1a58254710efa0d3f

Related: OS#5753, OS#5751
Change-Id: I822abf52c6ae396c90b5c50228a0a39c848d3de6
2023-10-02 13:40:01 +00:00
Daniel Willmann 59a785b628 stream_srv: Fix connection error handling
If read returned an error or the stream got closed then simply destroy
the connection.
If the user code called osmo_stream_srv_set_flush_and_destroy() then
ignore any incoming messages and destroy the connection once the tx
queue is empty.

Change-Id: I84eea2717f3762830f3f5b115e6fc8545eaa4fd5
2023-09-29 15:26:46 +00:00
arehbein 0c4c47ddfb stream_srv: Set io_fd pointer to NULL after freeing
Change-Id: Idb815a3e4e51189f9f1f3cceedd570dff9caf401
2023-09-25 23:16:07 +02:00
Pau Espin fd2eaea824 Bump version: 1.3.0.56-745c-dirty → 1.4.0
Change-Id: I2f0d6617c89cff83b1937996006ffe7106db2557
2023-09-12 13:50:26 +02:00
Pau Espin 745c0e2a0f stream: Add new stream_{cli,srv_link} parameters to set SCTP_INITMSG sockopt values
This will allow osmo_stream users (like libosmo-sccp) to set
SCTP_INITMSG related parameters, like number on inbound/outbound
streams, connect attempts, connect timeout.

Related: SYS#6558
Change-Id: I5343c7659881b29e0201e72badbc2d07e1ef2dca
2023-09-12 00:01:00 +02:00
Pau Espin efd56fb2a2 stream: Introduce API to set several transport parameters
This will allow extending capabilitites to set different parameters at
the lower layers as we need them.

This commit changes the behavior of osmo_stream_{cli,srv_link}: It now
doesn't enable by default SCTP AUTH/ASCONF features using setsockopt. It
is left up to the user of the API (libosmo-sccp in this case) to set it.
Since this unilateral use of setsockopt() has only been added recently
and we didn't release yet, it's fine changing it. libosmo-sccp will be
changed to unconditionally set its using setsockopt. It is left up to
the user of the API (libosmo-sccp in this case) to set it.

Related: SYS#6501
Related: SYS#6558
Change-Id: I2607c1c926a625986cd851adc65dd8b4de83d6ab
2023-09-08 17:53:21 +02:00
Pau Espin 839c90e149 stream: Use new libosmocore API osmo_sock_init2_multiaddr2()
Use the new API available in libosmocore to set sockopts related to
ASCONF SCTP features. The old flag OSMO_SOCK_F_SCTP_ASCONF_SUPPORTED has
been dropped. This only affects master builds since there's no release
ever done with that flag defined.

Depends: libosmocore.git Change-Id I1f6fd09a79b0a2bd794e5669d933be25bbf1eeaa
Related: SYS#6501
Related: SYS#6558
Change-Id: I2b2073de72625b4f4f99892179c9406163d28592
2023-09-08 13:15:56 +02:00
arehbein f990b307bd stream: Add server-side (segmentation) support for IPA
With this commit, IPA segmentation can be taken care of by setting
the segmentation callback osmo_ipa_segmentation_cb().

Depends: libosmocore.git I3a639e6896cc3b3fc8e9b2e1a58254710efa0d3f

Related: OS#5753, OS#5751
Change-Id: I6c91ff385cb5f36ab6b6c96d0e44997995d0d24c
2023-08-25 13:26:46 +00:00
Pau Espin 74b626282c stream: Use new flag OSMO_SOCK_F_SCTP_ASCONF_SUPPORTED for SCTP sockets
This is required if the user of the stream API wants to use SCTP extra
features such as setting the Peer Primary Address through ASCONF.

At a later point we may want to add new osmo_stream APIs to set extra
flags for the socket, or maybe simply add a new API specifically to
enable ASCONF for the stream.

Depends: libosmocore.git Change-Id Iac07031927b66a9d32d2bb2faab817e4c922a359
Related: OS#6076
Change-Id: I807b3748b8535d8e75ceea812d7baaf153fa1d60
2023-08-21 10:25:57 +02:00
Pau Espin 18c160a012 stream_cli: Forward SCTP MSG_NOTIFICATION to upper layers
Same mechanism as already used in stream_srv.

Change-Id: I4cb94d264109f1b763cccd44c6ba049cc7509319
2023-08-21 10:25:54 +02:00
Pau Espin deafe50cef stream: Refactor sctp_recvmsg_wrapper() logging
*Move the helper function to stream.c and pass a logging prefix string
so that it can be used by both client and server.
* Adapt log level based on message type.
* Rework logging code to log everything in one line

Change-Id: I0ed84cc2effb71b6ef1f6efb3f8b663c602a5a31
2023-08-21 10:25:01 +02:00
Pau Espin a49a2b4d70 stream_srv: Log SCTP REMOTE_ERROR events
The event was enabled but was not being logged.

Change-Id: I49f5a648fd474e320101424fb6873a37442339bf
2023-08-07 19:16:24 +02:00
Pau Espin bcfa37ade0 stream_srv: sctp: Log error cause of COMM_LOST event
RFC 6458 6.1.1:
"""
sac_error:  If the state was reached due to an error condition (e.g.,
SCTP_COMM_LOST), any relevant error information is available in
this field.  This corresponds to the protocol error codes defined
in [RFC4960].
"""
Change-Id: Ie48360d22ce1e35eefb1a305dde106948dfa80e8
2023-08-07 19:16:24 +02:00
Pau Espin 48f9a3c27f stream_cli: Proper handling of send() socket errors
Upon EAGAIN, simply re-enqueue the message and return waiting for next
poll. Upon any other error, force close + reconnect.

Related: OS#6134
Change-Id: I462cb176ebc51f3e99ee796310e8665144c84ccc
2023-08-07 19:16:24 +02:00
Pau Espin 3ee5274265 stream_srv: Handle ESHUTDOWN and other write() errors destroying the socket
If internal send() fails with a fatal error, it should destroy the
socket. The user will know about the event through the close_cb() called
during osmo_stream_srv_destroy().

As a result, the socket is not closed when receiving SHUTDOWN by the
peer (through SCTP MSG_NOTIFICATION), but keep it alive since the socket
can still keep receiving data from the peer. Only fail if write() to
that read-only socket is attempted.

Related: OS#6134
Change-Id: I84ddebabdffe47733cb529bcfebec8757e6a172b
2023-08-07 19:16:24 +02:00
Pau Espin a69a958ae3 stream: Append data to current tail of message upon recv()
The previous behavior was not standarized, and even erratic under some
code paths (passing msgb_data() and size=msgb_tailroom()).
This patch standarizes the behavior, and makes it possible to append
content if the user wishes so instead of erasing old data in the msgb
passed to it.

Change-Id: I2cfcd4f61545e6a76d84495c3467999efccf22df
2023-08-07 19:16:24 +02:00