Commit Graph

30 Commits

Author SHA1 Message Date
Andreas Eversberg 3ecc733147 osmo_io: Move notify_connected function to backend
This relocation is necessary as the backend (osmo_io_fd or
osmo_io_uring) requires a different approach in handling connect
notifications. As a result, a function call has been introduced to
struct iofd_backend_ops.

In a subsequent patch, the process for the osmo_io_uring backend will
be modified to handle SCTP connect notifications using poll/select.

If connect notification is requested using poll/select, the file
descriptior must be registered to osmo_fd, using osmo_fd_register. If
read / write notification is requested by application, the file
descriptior must be registered also. A flag is used prevent calling
osmo_fd_register / osmo_fd_unregister multiple times, which would cause
a crash.

Change-Id: I905ec85210570aff8addadfc9603335d04eb057a
Related: OS#5751
2024-02-23 18:01:36 +01:00
Harald Welte b365b1d094 osmo_io: Change struct osmo_io_ops to contain struct, not union
As we introduce more modes, and each mode aliases call-back function
pointers to those of another mode, we have more and more error cases
where we (for exampele) access read_cb, but in reality the user has
populated recvfrom_cb.

Let's use a struct, meaning that call-backs of one mode no longer alias
to the same memory locations of call-backs fro another mode.  This
allows us to properly check if the user actually provided the right
callbacks for the given mode of the iofd.

This breaks ABI, but luckily not API.  So a simple recompile of
higher-layer library + application code will work.

Change-Id: I9d302df8d00369e7b30437a52deb205f75882be3
2024-02-23 18:01:36 +01:00
Daniel Willmann 84611881c9 osmo_io: Factor out and use common send function from backend
This handles reenqueuing a message on EAGAIN and incomplete write

Change-Id: I6da2653d32aedd0e7872be0cf90a841b56462e59
2023-11-30 14:27:39 +01:00
Harald Welte c380f29c0c osmo_io: Reject unknown/unsupported modes in osmo_iofd_setup()
The current code does not check the value range of the 'mode' parameter
and would later run into OSMO_ASSERT(), rather than rejecting such a
mode from the very beginning.

Change-Id: I10dd612487638f456d0ad59c2cca203f1e098da3
Related: OS#5751
2023-11-22 12:20:12 +00:00
Harald Welte 38d8170fa4 osmo_io: rename unsupported SCTP mode to OSMO_IO_FD_MODE_SCTP_RECVMSG_SEND
The two functions of the SCTP socket interface we use in osmo-* are
sctp_send() and sctp_recvmsg().  We do not use sctp_sendmsg() at all,
so let's make sure the mode is named correctly.

Change-Id: Ie2d1c7ce6f211dbe025a0e843ad733443102ea15
Related: OS#5751
2023-11-22 12:20:12 +00:00
Harald Welte 987a86af88 io_uring: add some more source code comments/docs
Change-Id: I8ba77a18b51f67a9edbd1fa488b9791f8bf6e40a
2023-11-22 12:20:12 +00:00
Daniel Willmann afdfc6a034 osmo_io: Assert that iofd mode is correct when calling *_write_msgb
Change-Id: Ief82ba7f9b280f85d66d68c358c36ba9866fe47a
Fixes: OS#6264
2023-11-21 21:02:13 +00:00
Daniel Willmann 2386e9a7e2 osmo_io: Only allow reading/writing if the relevant callback is set
Allow the callbacks to be NULL, but then sending/receiving is disabled.
There are some cases where we only care about writing to or reading from
an fd.

Change-Id: I11ce072510b591f7881d09888524426579bd0169
2023-09-28 17:51:05 +02:00
Daniel Willmann f39c23f918 osmo_io: Change parent of msghdr to iofd (instead of msg)
msg was made a parent of msghdr after discussion in change
I3a279b55a3adff96948120683c844e1508d0ba94

It turns out this violates some assumptions made in osmo_io,
specifically that the user read callback shall free msg, but we expect
msghdr to remain valid until after that callback returns.

In general I think it is cleaner to make iofd a parent of msghdr.

Change-Id: I41277190e3020cd8fa625bd57a743973e2a65c4b
2023-08-31 14:28:13 +00:00
Daniel Willmann f91d2aac9d osmo_io: Add io_uring backend
Change-Id: I5152129eb84b31ccc9e02bc2a5c5bdb046d331bc
2023-08-24 17:33:19 +02:00
Daniel Willmann 012d9044a2 osmo_io: Avoid potential double free when sending msgb
Ensure that a msgb  has the proper talloc parent:

All msgbs inside an iofd get the iofd as parent. Received msgbs are reparented
to iofd->msgb_alloc.ctx (which was set in osmo_iofd_setup()) before
being passed to the receive callback.

Before this change the code could fail for msgbs that are submitted via uring
where the (failed) write returns after the iofd has already been
osmo_iofd_free()d. free()ing the iofd is deferred until the write
completes, but the (iofd) parent context could have been free()d in the
meantime.

Change-Id: I3a279b55a3adff96948120683c844e1508d0ba94
2023-08-24 17:13:33 +02:00
Daniel Willmann 2b34e92d0e osmo_io: Add iofd_handle_recv()
Handle msg reception in a common function that can be called from the
different backends.

Change-Id: Ifc407d446805f885d37767f421ff710cb276a01f
2023-08-24 14:46:51 +00:00
Daniel Willmann 92efac26d7 osmo_io: Use MSG_NOSIGNAL to avoid SIGPIPE on write
Change-Id: I85433124a8e80fc2aa19b551bdaf2655ef1eea2c
2023-08-08 10:02:33 +02:00
Daniel Willmann f083382b9c osmo_io: Ensure correct ownership of msgb when sending
Use talloc_steal() if a msg is passed in to osmo_io when sending. This
avoids the message being free()d early in case the original parent is
free()d.

Change-Id: Ie36bd68a8bd63e67d76fb41996f8fdf99f51d96c
2023-08-08 10:02:33 +02:00
Daniel Willmann 97d21447f7 osmo_io: Fix length calculation in iofd_handle_segmentation()
We need to account for the fact that segmentation_cb() could have
changed the length by calling msgb_pull(). Calculate the new len
according to the new tail/data pointers.

Change-Id: I5486ddc0d3345e92b20cbc6e5bcf2cefea3958c8
2023-07-18 09:58:47 +00:00
Daniel Willmann d0d9ecbad1 osmo_io(cosmetic): End in a dot for doxygen AUTO_BRIEF
Change-Id: I397304eed524db12e60a6534d21ea268f304cfdc
2023-07-18 06:30:28 +00:00
Daniel Willmann 4731e71a79 cosmetic: Fix doc comment
Change-Id: Iec614004a0382534f4bfcc375f4d89192d7f27aa
2023-07-18 06:30:28 +00:00
Daniel Willmann a9303f3bce osmo_io: Add function to change the maximum length of the tx_queue
Change-Id: If3d1de8bffe1123002515878655ea9e02b482888
2023-07-18 06:30:28 +00:00
Daniel Willmann 7b59bab794 osmo_io: Document expectation that segmentation_cb() can modify msgb
This is used for parsing e.g. the ipa header and setting msg->cb.
Guard against segmentation_cb changing msg->data in
iofd_handle_segmentation().

Change-Id: Idd2115baae98a7818aabb26232d4423d2d48fb5c
2023-07-18 06:30:28 +00:00
Daniel Willmann e2a8dc4131 osmo_io: Add osmo_iofd_notify_connected()
Don't call write_enable() in osmo_iofd_register(). This was used to
detect whether a socket is connected or not, but would always be
enabled, even on unconnected sockets. Instead make this behaviour
explicit by calling osmo_iofd_notify_connected().

Change-Id: Ieed10bc94c8aad821c0a8f7764db0e05c054c1e3
2023-06-30 13:57:05 +02:00
Daniel Willmann e4ecd996d4 osmo_io: Fix write_enable handling in iofd_txqueue
Enable write on first message in both iofd_txqueue_enqueue{,_front}(),
but only if the iofd is not closed.

Change-Id: I75827491bb9fe0c6d1e4a195ac434f049b1a6ba6
2023-06-30 13:55:31 +02:00
Daniel Willmann f89162f8ab osmo_io: Use bitfield for various boolean flags
Change-Id: Ic134e4c8d791c34778202fea98a70bc04007a113
2023-06-29 17:06:23 +00:00
Daniel Willmann acb97765ef osmo_io: Return early on error in osmo_iofd_register()
Change-Id: I2561c82e6bf7e2bb5fd699c899238f9c43ea4d9c
2023-06-26 19:28:47 +02:00
Pau Espin 63e45e6c6a osmo_io: Make name optional, add _set_name() API
This allows renaming the iofd at any later point in time. This is useful
for instance if the parent object holding the iofd changes its name.

Change-Id: If2772a3ccaa98616e0189862a49ab0243435e343
2023-06-20 07:16:41 +00:00
arehbein c0aa4bdf8f core/osmo_io: Rename variables for readability
Rename msg_len -> received_len, len -> expected_len
so the variable names have a consistent scheme.
For instance,
	extra_len = msg_len - len
becomes
	extra_len = received_len - expected_len

Change-Id: I3d752ce91a1b16c855522f643d10a52ef28a8a84
2023-06-19 12:59:03 +00:00
Daniel Willmann eb9edbab54 osmo_io: Remove osmo_iofd_read/write_enable/disable
This API is not really used or needed, so remove it.
See discussion in https://gerrit.osmocom.org/c/libosmocore/+/33084

Change-Id: I0dbc14a8cbbdc7b6e4688942c0dac865bbd72c8b
2023-06-07 15:04:47 +02:00
Daniel Willmann cbbd17e3f4 osmo_io: Support detecting non-blocking connect()
libosmo-netif does a non blocking connect(), which as per definition of
 the socket API is signalled from the OS to the user by marking the file
descriptor writable.

osmo_io needs to signal this somehow. Previously osmo_io would only call
the write_cb if actual data has been sent. This patch changes the behaviour
so that calling osmo_iofd_write_enable() will call write_cb() on a writable
socket even if the write queue is empty.

Change-Id: I893cbc3becd5e125f2f06b3654578aed0aacadf3
2023-05-19 12:50:21 +00:00
Daniel Willmann d4d03705f9 osmo_io: Improve handling and documentation of segmentation_cb
The read length is not needed in the segmentation callback, msgb
already has all the necessary information, the parameter previously was
just msgb_length(msg).

Also handle negative return values (except -EAGAIN) of the callback as
errors which cause the msg to be dropped. -EAGAIN will defer the msg.

Change-Id: I6a0eebb8d4490f09a3cc6eb97d4ff47b4a8fd377
2023-05-19 12:50:21 +00:00
arehbein 0c374c68a1 core: Add function to update osmo_io_ops field for osmo_io_fd
Added, because the field 'io_ops' of 'struct osmo_io_fd' is not a
reference, so subsequent changes to the osmo_io_ops structure that was
used to set it up aren't automatically reflected in the osmo_io_fd
structure that got its copy.

Change-Id: Ie45402ad8e86e3cecf75ad78a512c17e61e68b19
2023-05-19 12:50:24 +02:00
Harald Welte 8857f3b798 Add osmo_io with initial poll backend
* make backend configurable for later
* segmentation callback for chunked streams
* logging target for osmo_io
* support partial writes

Change-Id: I50d73cf550d6ce8154bf827bf47408131cf5b0a0
Related: SYS#5094, OS#5751
2023-05-10 06:04:57 +00:00