aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
AgeCommit message (Collapse)AuthorFilesLines
2020-09-02stream: add missing Doxygen \return statements to non-void functionsVadim Yanitskiy1-3/+9
Change-Id: I693939946497ad08f45cab238a56ceee29578056
2020-08-24stream: Fix log of IPv6 during accept()pespin/ipv6Pau Espin Pedrol1-2/+9
Change-Id: Ib13db8d135138059a70d18a8bba14e53c6514fa7
2020-08-19stream: Support creating sockets with IPv6 addressesPau Espin Pedrol1-6/+6
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-07-06stream: Fix some SCTP code not disabled if --disable-libsctp is usedPau Espin Pedrol1-0/+2
Some previous commit added some code to workaround some kernel ABI unstabilities but forgot to add the code inside a conditional preprocessor block. Fixes: 157ad6d7075ad56038c984ebf8634f1bc7c6c59c Change-Id: Ibee01222d8d11cf2520cdbd4d0d5bed6b72d2107
2020-06-03src/stream.c: Don't leak socket during SCTP_EVENTS getsockoptHarald Welte1-0/+1
In Commit Icc49f347cdc0bb77a5c0e230597d662ac35b4acc I forgot to close the socket :/ Change-Id: I384c61dac0eac8ad999ff0d62350c2fcf3e57ea9
2020-06-02src/stream: Work around more Linux kernel ABI breakageHarald Welte1-20/+93
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-05-09Use OSMO_FD_* instead of deprecated BSC_FD_*Pau Espin Pedrol1-13/+13
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-08stream: Attempt to workaround kernel ABI breakageSylvain Munaut1-0/+16
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-01-28stream: Rename cli state NONE to CLOSEDpespin/fixPau Espin Pedrol1-5/+5
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-28stream: Add new WAIT_RECONNECT cli statePau Espin Pedrol1-6/+10
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-28stream: Re-arrange cli states to fix 100% cpu usage bugPau Espin Pedrol1-16/+11
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-28stream: Drop data during write() while in state NONEPau Espin Pedrol1-1/+1
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-09stream.c: Improve logging during sock send()Pau Espin Pedrol1-4/+4
Change-Id: Iff275c809ec2bb34f471d15bfdc92296566b76a7
2020-01-09configure.ac: Introduce --{enable,disable}-libsctp configure flagPau Espin Pedrol1-6/+20
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
2019-10-21stream: Fix fd param passed to close() in error conditonPau Espin Pedrol1-2/+2
Fixes: CID#205089, CID#205087 Change-Id: I65714f214b9962862cda01605c7c2c578c78d3c7
2019-10-15stream: osmo_stream_cli: Support setting multiple addrPau Espin Pedrol1-12/+83
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-15stream: osmo_stream_srv_link: Support setting multiple addrPau Espin Pedrol1-4/+37
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-10stream.c: remove duplicated line setting variablePau Espin Pedrol1-1/+0
Change-Id: I03b05179f5656ab81e5e14cd146f82a471f7b071
2019-09-04stream: Fix scheduling of queued messages during connecting statePau Espin Pedrol1-1/+6
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-04stream: Introduce API osmo_stream_cli_is_connectedPau Espin Pedrol1-0/+8
Can be used by users to fetch current status of the stream. Change-Id: I5402430e5f39eef22dfa18f33807ab6b1e771f1b
2019-03-19Deprecate osmo_stream_cli_open2()Max1-6/+42
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-02-20Stream client: add disconnect callbackMax1-1/+14
It's similar to connect_cb() but called once client has been disconnected. Change-Id: I905adb2d6191216551a3bcdcd1aec1f96f01612a
2019-02-07Stream client: report reconnection event as INFOMax1-2/+2
This helps to avoid unnecessary debug output in reconnection logic tests in follow-up patches. Change-Id: Ic96430a9e9294e72de23b0bbacdbf3e99a453f1d
2019-02-05Stream client: fix disconnection logicMax1-2/+8
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-05Add socket name functions to stream client/serverMax1-0/+31
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-05Stream client: update loggingMax1-16/+25
Introduce logging macro wrapper to properly log current client state and function to aid in debugging. Change-Id: Ie22a80dcec95998cce0b25053fdf74f23eab6e53
2019-02-04Stream client: fix doxygen typoMax1-4/+4
Change-Id: Ic45d3e0520db4060c5c24e5ef5a766a52f060a34
2018-12-10logging: fix typo in stream.cNeels Hofmeyr1-1/+1
Change-Id: I5dcae1f19e18f04709ce7585943af1d582ebc7ed
2018-11-09detect freed connections in osmo_stream_srv_read()Stefan Sperling1-7/+10
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-07-05stream.c: Use non-blocking connect in osmo_stream_cliHarald Welte1-1/+1
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-04-05stream.c: osmo_stream_cli_open2: Remove wrong assumption in reconnect decisionPau Espin Pedrol1-1/+1
Documentation of osmo_sock_init2 doesn't provide information of any specific value of errno set/expected after running the function. It is incorrect to expect a specific value of errno and looking at the implementation it is actually not a good idea to check it. If reconnect flag is set, let's reconnect always instead of looking at errno to decide. Change-Id: I25b33f4cdc496ae31ff240d445b9b2805091845c
2018-02-22add support for flushing and destroying a server-side streamStefan Sperling1-1/+29
Introduce osmo_stream_srv_set_flush_and_destroy() which marks a stream to be 'flushed and destroyed'. No new messages will be received on this stream, and no new messages can be queued. Once the Tx queue has been drained, the connection is destroyed. The API user is given a chance to perform cleanup operations in the closed_cb() callback for the connection. The same mechanism will be added for client-side connections in a follow-up patch. Change-Id: I8ed78fe39c463e9018756700d13ee5ebe003b57f Related: OS#2789 Suggested-by: Harald Welte
2017-11-20osmo_stream_{cli,srv}_destroy: fix mem leak: empty msgb queueNeels Hofmeyr1-0/+2
On destroying a client or server stream, deallocate any msgbs that are still pending in the queue. In libosmo-sccp, the ss7_test.c in test_as(), messages are queued and were, before this, left floating after the stream was destroyed, causing a sanitizer memory leak. This patch fixes the leak. Depends: Ia291832ca445d4071f0ed9a01730d945ff691cf7 (libosmocore) Change-Id: Iaad35f03e3bdfabf3ba82b16e563c0a5d1f03639
2017-11-17stream: Avoid re-creating and leaking socket when unneededPau Espin Pedrol1-2/+6
In previous implementation, if no reconfiguring is needed, a new socket would be created without closing the old one, leaking the previous socket. Instead, if we don't need reconfiguring, we return 0 as no operation is required. Change-Id: I6c1a7fff63e44840fb5e2bc7ace5e9a61e304987
2017-11-13Add SPDX-License-Identifier + Copyright statementsHarald Welte1-0/+21
Change-Id: I43bb1c4a889421907a1a08eb29c96f2330ab00ec
2017-10-27some more Doxygen header text for datagram, osmux and stream moduleHarald Welte1-0/+5
Change-Id: Ied83e6b117a420d734a88e3aff925a874c3dd520
2017-06-07src: use osmo_timer_setup()Pablo Neira Ayuso1-2/+1
Use new function available in libosmocore to set up timers. Compile tested only. Change-Id: Id3dd32102c7362f3b280d2c058c2decebccb357a
2017-05-14somo_stream_srv_fd_cb(): close socket if NODELAY failsHarald Welte1-8/+14
We didn't check for cases where setsockopt_nodelay() fails. Let's check for that and bail out + close the socket. Change-Id: I0adbc4cec35be7c36bdf01d4d8fefd6097e9be5d Fixes: coverity CID#166970
2017-04-17SCTP: Don't enable sender_dry_event for SCTP, as it breaks Linux SCTPHarald Welte1-2/+11
Enabling sender_dry_event in SCTP_FLAGS breaks reliable delivery of DATA chunks to the scoket user on Linux. Let's avoid enabling that, while still enabling various other interesting events. See https://bugzilla.redhat.com/show_bug.cgi?id=1442784 for all related details. Change-Id: Ib616cd07a6044ca2ee7e05093b22df3369c62b56
2017-04-16stream.c: Fix SCTP_NODELAY settingHarald Welte1-1/+1
We were using the wrong variable when setting the SCTP_NODELAY, resulting in the setsoctkopt() fialing. Change-Id: Ic04cb8bb5ff41f177f7f5b7f7e2a2ecc686dd4c0
2017-04-14osmo_stream_srv_fd_cb(): don't leak socket FDs on errorsNeels Hofmeyr1-6/+23
So far we seem to assume that the accept_cb does all handling of socket fd cleanup. However, there are cases where there is no accept_cb set, the accept_cb returns error, or an earlier sctp_sock_activate_events() or the activation of non-blocking mode fails. For those cases, close the socket and return an error code. Fixes: CID#57915 Change-Id: I3a3ce9194ab7ca5c1921fc79c2a1c9e10a552cf0
2017-04-12SCTP: Fix PPID byte widthHarald Welte1-3/+3
In a659590e29412588bca2243b8329e82286244b00 we fixed endianness issues with the Stream ID field, but at the same time mistook the PPID field for 16bits. In reality it is 32bits, and hence our 'htons' is rendering wrong PPID values. Change-Id: I1b60523044835ee630dba9a43d26af4f1ebd1ced
2017-04-11Add osmo_stream_{cli,srv_link}_set_nodelay() functionHarald Welte1-0/+60
Using this function, the user can configure if sockets related to the respective stream client or server should have the NODELAY socket option set in order to avoid Nagle algorithm or related algorithms that may introduce packet delay on the transmitter side. Change-Id: Ibeb9ba227bab18f7f4f16518c0022c4f003cc8e9
2017-04-10stream.c: Fix endianness handling of PPID and STREAM_IDHarald Welte1-6/+6
In their infinite wisdom, the inventors of SCTP designed an API (the sockets API described in RFC6458), where some members are in host byte order (like the stream identifier), while other members are in network byte order (like the PPID). Let's handle this properly (we assumed both are network byte order), and also use 16-bit htons/ntohs fo the PPID, rather than htonl/ntohl. Change-Id: I777174ca2915c6de0063db41a745c71b4a09bbec
2017-04-10stream/datagram: Ensure reliable close/destroyHarald Welte1-3/+6
* when using osmo_*_destroy(), always call *_close() internally to make sure we don't free memory holding references to sockets that are still open * when closing the socket, always make sure to set the fd to -1 in all cases, to avoid attempts to avoid later close() on a new file using the same fd number as the socket closed previously. Change-Id: I29c37da6e8f5be8ab030e68952a8f92add146821
2017-04-10stream/datagram: Consistently use osmo_talloc_replace_string()Harald Welte1-4/+4
during osmo_*_set_addr(), we must make sure to talloc_free() any old address before copying in the new address. Not all functions did this, and those that did implemented it manually. Let's use osmo_talloc_replace_string() which is exactly intended for this case. Change-Id: Ie1b140a160c66e8b62c745174865d5ba525cb2c2
2017-04-10stream+datagram: Allow local bind + connect for client socketsHarald Welte1-4/+18
This uses the new osmo_sock_init2() features introduced in libosmocore Change-Id Idab124bcca47872f55311a82d6818aed590965e6 to bind *and* connect a given socket during creation. Change-Id: I013f4cc10b26d332d52d231f252bb0f03df8c54b
2017-04-08Add minimal doxygen documentation for stream + datagram modulesHarald Welte1-4/+149
We should have doxygen documentation for all libosmo-* APIs. libosmo-netif is currently devoid of any API docs. Let's start with the stream and datagram socket related functions. Change-Id: I589a5e60d9df2b8a65fbaf68f80e3ae0039d8c2a
2017-03-29stream.c: Handle SCTP in osmo_stream_srv_recv()Daniel Willmann1-1/+57
Change-Id: If0875cfa3eba9ef36acc0c4bfd0d168a45c380b9
2017-03-20stream client: Ensure client is notified on reconnectionHarald Welte1-0/+1
without setting the BSC_FD_* flags prior to reconnection, the re-connect would happen silently and the client program would not be notified via the connect_cb(). Change-Id: Iaf8ec8662cf83476eee1b76fa41dc57f063f0ad3