aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
AgeCommit message (Collapse)AuthorFilesLines
2024-03-15docs: Split Stream Server and Stream Client into separate groupsHarald Welte1-10/+2
This provides us with proper logical separation between client and server in the documentation. Change-Id: I9e037fedaecb78396f435577b1652284b4951ded
2024-03-15docs: Use \defgroup and avoid repeated boilerplate textHarald Welte1-6/+1
Change-Id: I1196c3b035f495c5dbaa4d47ce3f79a08d0727f2
2024-02-29stream_{cli,srv}: Add support for SCTP in OSMO_IO modeHarald Welte1-12/+74
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
2023-08-21stream: Refactor sctp_recvmsg_wrapper() loggingPau Espin Pedrol1-0/+79
*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-04stream: Split cli/srv specific code out of stream.cPau Espin Pedrol1-1786/+4
The dev/user in general is only interested about one side of the stream when looking at the code. Since the stream.c file is tarting to be quite large/bloated, this patch splits its content into stream_cli.c and stream_srv.c to make it easier to improve/extend and review. Keep common code between cli and srv in stream.c, and add a private header to contain references to it. Change-Id: I22af01bba2040eb320ba48fd1b46c090c98be159
2023-07-25stream: Fix osmo_panic log fmtsarehbein1-4/+5
Change-Id: Id082a9473b788f8de20cdc2ba4430b3289f4ce5a
2023-06-30stream: Notify stream_cli on connect()Daniel Willmann1-0/+1
Change-Id: I29621ca53cdbdf8b5b2d128307fcb6432db669d3 Depends: Ieed10bc94c8aad821c0a8f7764db0e05c054c1e3 (libosmocore.git)
2023-06-27stream: Rename static function to have correct prefixPau Espin Pedrol1-2/+2
That function is used by the srv_link object, not the srv object. Rename it to avoid confusion. Change-Id: I1a3870b3a269b84ac2a9285ee6fe3389c5c96a94
2023-06-20stream: srv cb: Use osmo_sockaddr and improve logging when cli connectsPau Espin Pedrol1-18/+9
Specially important is the change where we now print the remote port which connected to us, not our local port (which is already printed as part of LOGSLNK). Change-Id: I6e556f8263496ded41bb221ccc8e193c5361697f
2023-06-20stream: Drop name param from recently added API osmo_stream_srv_create2()Pau Espin Pedrol1-6/+2
It was later decided that since setting a name is not really required, it is best to leave it out of the create() function and let the user use the osmo_stream_srv_set_name() API if needed (otherwise a dynamic name based on socket is selected) Change-Id: I5d677ef57b7db0aedd8c43282568c845097cb12b
2023-06-20stream: Drop recently added API osmo_stream_cli_create2Pau Espin Pedrol1-32/+19
It was later decided that since setting a name is not really required, it is best to leave it out of the create() function and let the user use the osmo_stream_cli_set_name() API if needed (otherwise a dynamic name based on socket is selected). Change-Id: I2a2fad318ef22c2ac117f95588a078ca3beccea5
2023-06-20stream: Print socket info as part of the logging contextPau Espin Pedrol1-5/+23
Since the local port is logged now in stream_test, it must be set to a specific value in order to have deterministic log output being validated. Change-Id: I17ef699dab72c1b613708070d22e9f040b0fe069
2023-06-20stream: Allow setting name printed during loggingPau Espin Pedrol1-27/+74
Depends: libosmocore.git Change-Id If2772a3ccaa98616e0189862a49ab0243435e343 Change-Id: I539a0d29d11348efe702f971965a55cf56db5c59
2023-06-17stream: Set state to closed before calling disconnect_cb()Daniel Willmann1-3/+5
Fixes recent crashes in ttcn-cbc-test Change-Id: I40ceb17c32d1f58f8d0eeda8d1d794cf3f478e83 Related: OS#6063
2023-06-16stream: Assert that fd is valid in stream_cli_handle_connecting()Daniel Willmann1-0/+1
This function should never be called if we don't have a valid fd. Change-Id: If0bed2bae556e0a8233e9e66e82c70a5c677fc3c Fixes: Coverity CID#321045
2023-06-15stream: Remove duplicated code in osmo_stream_cli_create()Daniel Willmann1-17/+1
Simply call osmo_stream_cli_create2() with name "" Change-Id: I0652361a6bdf194545f36edc5e12e5d26798163a
2023-06-15stream: Document osmo_stream_cli_create2()Daniel Willmann1-1/+7
Change-Id: I0c2f46e02d94c3459e4043a9db7fccd906521dd2
2023-06-15stream: Setup ofd in osmo_stream_cli_openDaniel Willmann1-6/+2
Don't reset the osmo_fd data in osmo_stream_cli_set_read_cb(). osmo_ss7_asp_restart() in libosmo-sccp calls osmo_stream_cli_set_read_cb() which causes the fd to be set to -1. osmo_stream_cli_open() which is called after that then doesn't close the old fd and opening the new one fails. osmo_fd priv_nr, callback and data are never modified in osmo_stream_cli so simply use these values in osmo_stream_cli_open() Change-Id: Id9b4db06d5ea1f29cbd1817cab3c71765ab30a53
2023-06-14Add osmo_io support to osmo_stream_cli and osmo_stream_srvDaniel Willmann1-29/+320
Change-Id: I2f52c7107c392b6f4b0bf2a84f8c873c084a200c
2023-06-14stream: Correctly close osmo_stream_cli when in state WAIT_RECONNECTDaniel Willmann1-0/+6
If cli is in STREAM_CLI_STATE_WAIT_RECONNECT cli->timer is scheduled. Delete the timer if osmo_steam_cli_close() called so we don't end up reconnecting. Also fixes the recent test failures in master-libosmo-sccp Jenkins jobs. Change-Id: Ic5227432192c4007f861f171ae961a8f4dea6522
2023-06-12stream: Use cli->state to check if cli is already closedDaniel Willmann1-1/+1
Change-Id: I92231528da08f8891e20c1226b61989a65e00ccd
2023-06-12stream: Factor out reconnection handlingDaniel Willmann1-31/+43
Change-Id: I418377eabd465ee4ffce9b4440e96287c7734924
2023-06-08stream: Update log messagesDaniel Willmann1-9/+7
Change-Id: Ife20b9d18e6ca86a06991d68165694e31052c58a
2023-06-08cosmetic: Change name of osmo_stream_src_fd_cb()Daniel Willmann1-2/+2
Change-Id: I8a9d27856ebdd5405b1977d12e91f8dcbdcd1d6b
2023-06-08stream: Properly name osmo_stream_srv read callbackDaniel Willmann1-5/+5
Change-Id: I12d74e9b407f1ea7af83fb3ec4d03ad7228a27cf
2023-05-17stream: (typo) Change callback param name of struct osmo_stream_cli from srv ↵Daniel Willmann1-4/+4
to cli Change-Id: I742db401165477f85e66bb428f156ecbbd5d6665
2023-05-17stream: Introduce and use osmo_stream_cli_fd() to get the fdDaniel Willmann1-6/+13
This will become useful once osmo_io can be used as a backend. Change-Id: I7e964dea0adee8edbb9b75d2d17e7d0c5d8917d5
2023-02-20fix msgb leak on OSMO_STREAM_SRV_F_FLUSH_DESTROYNeels Hofmeyr1-0/+1
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-10Add osmo_stream_srv_link_is_opened()Max1-3/+14
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-10osmo_stream_srv_link_close(): properly handle NULL inputMax1-0/+3
Related: OS#5568 Change-Id: Ie15bb3dc99bfe18065e03fde68d517b0d389b7ad
2022-12-20stream: Fix tx data dropped upon show socket writePau Espin Pedrol1-12/+22
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-20stream: Avoid useless polling if tx_queue becomes emptyPau Espin Pedrol1-2/+10
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-20stream: Log error on short sendPau Espin Pedrol1-0/+4
This is clearly a problem on TCP streams which needs to be addressed in the future. Related: OS#5836 Change-Id: I9bd257b80a378b779df84e204673f8e394eca5b6
2022-12-20stream: osmo_stream_*_write: Unifiy way to get data and lengthPau Espin Pedrol1-6/+6
Change-Id: I5b5d6f7a5a1722bd01c13d32557c21d8a0889966
2022-12-20stream: Log read/write flagsPau Espin Pedrol1-1/+1
Change-Id: I57b064fa0498be76579ae9597ab9217d659aae41
2022-11-22Add assert for link check to osmo_stream_srv_create()Max1-0/+2
We implicitly rely on conn->srv availability in several functions. Let's ensure it's available in function creating conn. Change-Id: If494eac5dcce6c5ae30e928b92e57067d5681a42
2022-10-17stream: Introduce APIs osmo_stream_{cli,srv}_clear_tx_queue()Pau Espin Pedrol1-0/+17
Related: SYS#6113 Change-Id: Iecb0a4bc281647673d2930d1f1586a2df231af52
2022-10-17stream: Improve logging of SCTP_PEER_ADDR_CHANGE notificationPau Espin Pedrol1-1/+12
Related: SYS#6113 Change-Id: Ieebc6e623874b4770ec7cd8b934244ffecaa089d
2022-10-08Better handling of send() errorMax1-4/+5
Avoid logging confusion when -1 == ENOTSUP. Change-Id: Iaa7e16e717c56466c5d9a64deb438776ca88022e
2022-09-30stream: Document osmo_stream_srv_recv() SCTP specialtiesPau Espin Pedrol1-0/+10
Change-Id: I47b066f26e63afd4bdb135f822667d1cd9479920
2022-09-30stream: Return 0 when receiving sctp notification SCTP_COMM_LOSTPau Espin Pedrol1-1/+2
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-30stream: Remove unneeded break statementPau Espin Pedrol1-1/+0
Change-Id: Iaa36a3661fc3d049f656342ee6dc3aafd45498bb
2022-09-30stream: Set sctp_ppid and sctp_stream when sctp notifciation is receivedPau Espin Pedrol1-2/+2
Let's set these values in all cases. Change-Id: I99f6098d8d9fc1c06bc28373bf7ee76f15d5f525
2022-09-30stream: Log rx of sctp notification SCTP_SEND_FAILEDPau Espin Pedrol1-0/+3
Change-Id: I16d3ed950d4da3b13cca25bcd8f29af0d880c23e
2022-09-30stream: Erase sctp_msg_flags if receiving user dataPau Espin Pedrol1-0/+1
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-30stream: Set proper msgb length when returning sctp_notificationPau Espin Pedrol1-0/+1
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-19stream: Provide caller with SCTP flags during osmo_stream_*_recv()Pau Espin Pedrol1-0/+1
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-13stream: Unset fd value after close() before calling closed_cb()Pau Espin Pedrol1-1/+2
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-12stream: Fix typos in log messagesPau Espin Pedrol1-2/+2
Change-Id: I9e49e222c254c89d182402501024badfd3bf9d9c
2022-08-21Properly handle send() return codeMax1-2/+2
Change-Id: If9b80e855b740254d5414ea50b4ce594855da8e9