Commit Graph

18 Commits

Author SHA1 Message Date
Harald Welte fab993bd31 osmo_io: Dont use __linux__ but !EMBEDDED
osmo_io (unlike its io_uring backend) is not linux specific, so putting
it in an "#ifdef __linux__" block is plain wrong.

A side-effect is that all our doxygen comments are not processed as
__linux__ is not set while doxygen parses the source file.

Change-Id: I260443ba3cd0bb81dade434208dea4ea70fe8ad8
2024-03-15 21:29:35 +01:00
Andreas Eversberg 28c97a7238 osmo_io_poll: Use -errno as result on write error
This was done for read error in a previous patch. This is required
because osmo_io_uring does not support errno, instead it uses the
result code. To have a unified API, set the result code equally.

Related: OS#5751
Change-Id: I405094449a6644db37534757f2fbccbcff982f23
2024-03-08 08:08:54 +00:00
Andreas Eversberg 3c0d5001a5 osmo_io_poll: Declare local functions "static"
Change-Id: I6ba88cd7bbd5b5ef42eb460679696f105c9158cb
2024-02-29 09:15:41 +01:00
Andreas Eversberg 76f7678cb1 osmo_io_poll: Use -errno as result on read error
Related: OS#5751
Change-Id: Ida63b74feecddf96bab7b2ade4e9ad216fe56e06
2024-02-28 16:43:03 +01:00
Harald Welte 1047ed7255 osmo_io: sendmsg/recvmsg support
Add support osmo_io operations resembling sendmsg() and recvmsg() socket
operations.  This is what will enable the implementation of higher-layer
functions like equivalents of sctp_recvmsg() and sctp_send() in
libosmo-netif and/or other users.

Change-Id: I89eb519b22d21011d61a7855b2364bc3c295df82
Related: OS#5751
2024-02-28 16:42:57 +01:00
Andreas Eversberg 848faf9256 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-28 16:42:53 +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 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
arehbein 2e2a0a1561 osmo_io_poll: Handle -EAGAIN in case of OSMO_FD_WRITE
Related: OS#6213
Change-Id: I59c86370d13f2bb33c289d1b177df895726975cb
2023-10-20 10:00:32 +00:00
Daniel Willmann 435856be51 osmo_io: Init struct msghdr to zero
Avoid uninitialized read, found with valgrind

Syscall param recvmsg(msg) points to uninitialised byte(s)
   at 0x49FD865: __recvmsg_syscall (recvmsg.c:27)
   by 0x49FD865: recvmsg (recvmsg.c:41)
   by 0x4891FAE: iofd_poll_ofd_cb_recvmsg_sendmsg (osmo_io_poll.c:66)
   by 0x48921B2: iofd_poll_ofd_cb_dispatch (osmo_io_poll.c:119)
   by 0x48941F1: poll_disp_fds (select.c:419)
   by 0x4894299: _osmo_select_main (select.c:457)
   by 0x4894304: osmo_select_main (select.c:496)
   by 0x10DC3E: test_segm_ipa_stream_srv_run (stream_test.c:628)
   by 0x10E2A5: main (stream_test.c:879)
 Address 0x1ffefffa68 is on thread 1's stack
 in frame #1, created by iofd_poll_ofd_cb_recvmsg_sendmsg (osmo_io_poll.c:45)

Change-Id: I21114ad57784126cfdeb4a932ed44dbf23946fbe
2023-09-27 11:14:02 +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 f89162f8ab osmo_io: Use bitfield for various boolean flags
Change-Id: Ic134e4c8d791c34778202fea98a70bc04007a113
2023-06-29 17:06:23 +00:00
Daniel Willmann a8a27c2c6f osmo_io: Use LOGPIO instead of LOGP
Change-Id: I4ee256b18544f7ca6bff6b7c6ebcce15546bb1f2
2023-06-26 19:28:54 +02:00
arehbein 5099d99192 core/osmo_io: Fix reception of partial packets
Always append to 'msg->tail' instead of to 'msg->data'.

Change-Id: I0ab8028c807b4181fddd3c00ea2e037c40cf0813
2023-06-19 15:40:57 +00: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 a4b958bda2 osmo_io: Avoid read of uninitialized variable
Change-Id: Ica8087c73fc10f01026fdbe692b172ad07fe593d
Fixes: CID#315618
2023-05-15 18:10:25 +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