aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
AgeCommit message (Collapse)AuthorFilesLines
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
2017-03-17stream: Export osmo_stream_cli_reconnect()Harald Welte1-1/+1
In case the application is using the read-callback and a read returns 0, then the application itself would want to trigger the reconnect. This is different from the osmo_stream_cli_recv() case where the reconnect can be handled internally to the library. Change-Id: I41314bad4a9f44e8a61b9d2ba33d1a76b25bd145
2017-03-17stream: When destroying, make sure to kill reconnect timerHarald Welte1-0/+1
if osmo_stream_cli_destroy() is called while the reconnect timer is running, we would end up in a crash. Change-Id: If6597130f472f1e2b8d9682002250ecd54675bb0
2017-03-17stream: don't crash in _close() when fd is not initializedHarald Welte1-0/+6
We use the magic value '-1' in case the file descriptor is not yet initialized. If somebody calls osmo_stream_*_close() before this changes, we used to crash. Let's check for this and avoid a crash. Also, after close let's change the fd to -1 again to mark the fd invalidity. Change-Id: I3aa04999ab01cb7971ee2dad45dfc31ab4142868
2017-03-17stream_client: Actually use/honor the reconect parameterHarald Welte1-1/+4
The reconnect behavior was likely broken in commit de3f57a8293a5b39435d6f283da23e0172bad8bb If the user requests a re-connect, we should start it. Not only in case the connection drops later, but also if the initial connection itself fails. Change-Id: I817e026404cbd9145cae2ce90bc57a1db1d2e12b
2016-12-01osmo_stream_cli_open2(): Fix bogus EINPROGRESS handlingHarald Welte1-10/+3
osmo_sock_init() never returns -1 + errno EINPROGRESS. It will return a positive fd in case the connect operation is in progress. Therefore, the related code in osmo_stream_cli_open2() was impossible to execute. Change-Id: Id3483d1d1d4d2eabba94729ea29e5c93b33abff0 Fixes: Coverity CID 57861
2016-11-26sctp_sock_activate_events(): Print error message on errorHarald Welte1-0/+3
When the setsockopt() in sctp_sock_activate_events() indicates an error, let's print an error message in the log about this. Change-Id: I5920154e23debe6d01eaa156005db0842f1a18cc Fixes: Coverity CID 57634
2016-11-02Set SO_NOSIGPIPE on SCTP connections, for patforms which support it (macOS, ↵Arran Cudbard-Bell1-1/+17
FreeBSD etc...) Change-Id: If4f2a99b2baf143551a7122f40ed1f9088c5936c Signed-off-by: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
2016-02-19stream: Use macros to access data and lengthDaniel Willmann1-1/+1
2015-12-25stream.c: ensure to zero-initialize sctp_sndrcvinfoHarald Welte1-0/+2
caught by valgrind: ==3150== Syscall param sendmsg(msg.msg_control) points to uninitialised byte(s) ==3150== at 0x60DC0D0: __sendmsg_nocancel (syscall-template.S:81) ==3150== by 0x5DF3413: sctp_send (in /usr/lib/x86_64-linux-gnu/libsctp.so.1.0.16) ==3150== by 0x65AA066: osmo_stream_srv_write (stream.c:540)
2015-12-22fix/complete stream client re-connect logicHarald Welte1-4/+16
So far, when the first connection attempt failed in osmo_stream_cli_open(), we returned a terminal errro without any re-connection attempts. While this may be useful in some cases, our general idea of the stream client logic is to handle the reconnection attempts insid the library. We introduce a new osmo_stream_cli_open2() function while keping the old behavior for backwards compatibility.
2015-12-22stream.c: Fix another 'link' variable / symbol mismatchHarald Welte1-1/+1
2015-12-22osmo_stream_cli_destroy: call talloc_free on right objectHarald Welte1-1/+1
'link' turns out to be a really bad variable name, as the symbol resolves to the global link(2)...
2015-12-21SCTP support for osmo_stream_{cli,srv} codeHarald Welte1-5/+84
Wih this change, osmo_stream_ client and server API can be used not only for TCP but also for SCTP. The latter is needed in SIGTRAN ad Iuh applications, for example.
2015-02-25Fix the compilation on FreeBSD.Nikola Kolev1-0/+1
2012-08-19stream: add osmo_stream_srv_get_masterPablo Neira Ayuso1-0/+5
To obtain the information of the server data that this connection belongs to.
2012-08-15src: shorter stream function namesPablo Neira Ayuso1-160/+153
%s/_client_conn_/_cli_/g %s/_server_conn_/_srv_/g %s/_client_/cli/g %s/server/srv/g %s/RECONFIG/RECONF/g %s/SERVER/SRV/g %s/CLIENT/CLI/g
2011-11-08src: add generic channel infrastructure and A-bis IPA server supportPablo Neira Ayuso1-0/+7
This patch adds the generic channel infrastructure that allows to create channel of different types. Each channel has their own configuration functions. struct osmo_chan *chan; chan = osmo_chan_create(tall_example, CHAN_ABIS_IPA_SERVER); ... /* specific configuration functions per supported channel. */ osmo_chan_abis_ipa_server_set_cb_signalmsg(chan, signal_msg_cb); osmo_chan_abis_ipa_unit_add(chan, 1801, 0); /* open channel. */ osmo_chan_open(chan); The input path requires a callback to be registered. The output path is handled through: int osmo_chan_enqueue(struct osmo_chan *c, struct msgb *msg); The msg->dst must be set (it can be taken from the original message to route one reply). This patch also adds A-bis IPA server support. It has been tested with e1inp_ipa_bsc_test available in libosmo-abis.
2011-11-08stream: don't destroy server connection on errorPablo Neira Ayuso1-2/+0
This patch includes a minor fix. We don't destroy connection on errors, it should be the caller which must control this.
2011-11-08stream: allow to set reconnect timeoutPablo Neira Ayuso1-7/+20
This patch allows to set reconnect timeout. If zero, it will try immediately. If negative, it will skip retrying.
2011-10-17stream: add osmo_stream_*_conn_get_ofd(...) functionsPablo Neira Ayuso1-0/+18
To obtain the file description.