Commit Graph

89 Commits

Author SHA1 Message Date
Neels Hofmeyr 719d1a38c6 osmo_stream_srv_fd_cb(): don't leak socket FDs on errors
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-14 11:06:09 +02:00
Harald Welte 5ae42bca91 SCTP: Fix PPID byte width
In a659590e29 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-12 12:08:45 +02:00
Harald Welte 9ec26583cd Add osmo_stream_{cli,srv_link}_set_nodelay() function
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-11 19:54:07 +02:00
Harald Welte a659590e29 stream.c: Fix endianness handling of PPID and STREAM_ID
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-10 17:48:42 +02:00
Harald Welte 7cee4b67e9 stream/datagram: Ensure reliable close/destroy
* 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-10 06:52:59 +00:00
Harald Welte 0bacc71fc2 stream/datagram: Consistently use osmo_talloc_replace_string()
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-10 06:47:28 +00:00
Harald Welte a2c2b59165 stream+datagram: Allow local bind + connect for client sockets
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-10 06:40:14 +00:00
Harald Welte d0f9bd600c Add minimal doxygen documentation for stream + datagram modules
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-04-08 20:13:14 +02:00
Daniel Willmann 5fe77a4656 stream.c: Handle SCTP in osmo_stream_srv_recv()
Change-Id: If0875cfa3eba9ef36acc0c4bfd0d168a45c380b9
2017-03-29 15:23:52 +02:00
Harald Welte db9808e883 stream client: Ensure client is notified on reconnection
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-20 01:32:06 +00:00
Harald Welte d8c820570b stream: Export osmo_stream_cli_reconnect()
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-17 12:07:19 +01:00
Harald Welte f2174ef1a2 stream: When destroying, make sure to kill reconnect timer
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-17 12:07:19 +01:00
Harald Welte a4c1a73250 stream: don't crash in _close() when fd is not initialized
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-17 12:06:24 +01:00
Harald Welte 781e7b38f8 stream_client: Actually use/honor the reconect parameter
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
2017-03-17 00:24:23 +01:00
Harald Welte 29d6cd4134 osmo_stream_cli_open2(): Fix bogus EINPROGRESS handling
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-12-01 15:52:54 +01:00
Harald Welte b2b2fe643f sctp_sock_activate_events(): Print error message on error
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-26 16:41:06 +00:00
Arran Cudbard-Bell 5b0ad8bd85
Set SO_NOSIGPIPE on SCTP connections, for patforms which support it (macOS, FreeBSD etc...)
Change-Id: If4f2a99b2baf143551a7122f40ed1f9088c5936c
Signed-off-by: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
2016-11-02 13:22:24 -04:00
Daniel Willmann 10f981a4a1 stream: Use macros to access data and length 2016-02-19 09:23:31 +01:00
Harald Welte 2b03b8c07c stream.c: ensure to zero-initialize sctp_sndrcvinfo
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-25 17:47:19 +01:00
Harald Welte cc4ce39fc6 fix/complete stream client re-connect logic
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-22 23:54:21 +01:00
Harald Welte b60edf05a6 stream.c: Fix another 'link' variable / symbol mismatch 2015-12-22 23:53:55 +01:00
Harald Welte b36fd0b912 osmo_stream_cli_destroy: call talloc_free on right object
'link' turns out to be a really bad variable name, as the symbol
resolves to the global link(2)...
2015-12-22 23:40:47 +01:00
Harald Welte fb3e20b4b2 SCTP support for osmo_stream_{cli,srv} code
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-12-21 20:54:19 +01:00
Nikola Kolev 2f1ddb2709 Fix the compilation on FreeBSD. 2015-02-25 15:52:14 +01:00
Pablo Neira Ayuso 5abf7f2ea4 stream: add osmo_stream_srv_get_master
To obtain the information of the server data that this connection
belongs to.
2012-08-19 18:35:10 +02:00
Pablo Neira Ayuso cee5fb36da src: shorter stream function names
%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
2012-08-15 23:34:35 +02:00
Pablo Neira Ayuso 2b5d3ce7c6 src: add generic channel infrastructure and A-bis IPA server support
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-08 11:17:44 +01:00
Pablo Neira Ayuso e57c7e1e3f stream: don't destroy server connection on error
This patch includes a minor fix. We don't destroy connection on
errors, it should be the caller which must control this.
2011-11-08 11:17:38 +01:00
Pablo Neira Ayuso d3ba14648c stream: allow to set reconnect timeout
This patch allows to set reconnect timeout. If zero, it will try
immediately. If negative, it will skip retrying.
2011-11-08 11:13:22 +01:00
Pablo Neira Ayuso 1434e40951 stream: add osmo_stream_*_conn_get_ofd(...) functions
To obtain the file description.
2011-10-17 22:12:37 +02:00
Pablo Neira Ayuso 96dbb24b50 stream: reconfiguration is only required if address and port change
No need to force reconfiguration if any of the callback or data
pointers are changed.
2011-10-17 12:52:39 +02:00
Pablo Neira Ayuso 98ec00d8d2 stream: add osmo_stream_*_conn_recv
Like c43bb08906 but for stream
sockets.
2011-10-17 12:51:18 +02:00
Pablo Neira Ayuso 60eb983964 stream: use debug loglevel instead of notice for spamming debug message 2011-10-17 12:10:30 +02:00
Pablo Neira Ayuso 2bd6adfd86 stream: add *_get_data() function to obtain private data
Add new functions:

osmo_stream_server_link_get_data
osmo_stream_server_conn_get_data
osmo_stream_client_conn_get_data

To obtain private data from osmo_stream_* handlers.

This patch also introduces missing osmo_stream_server_conn_set_data.
2011-10-09 21:35:51 +02:00
Pablo Neira Ayuso cc7a948d3e stream: support calling stream_*_open() multiple times for reconfigurations
This patch allows you to call stream_*_open(..) as many times as
you want to trigger reconfigurations.
2011-10-09 20:44:09 +02:00
Pablo Neira Ayuso ad2eca4768 stream: add osmo_ prefix to all functions
Modify examples as well to use the new API.
2011-10-09 18:00:53 +02:00
Pablo Neira Ayuso 7c20d4ef1e stream: remove internal stream_msg_recv()
Remove stream_msg_recv(...), now we use recv(...) directly. This fixes
since we were calling msgb_put(...) twice.
2011-10-05 13:43:18 +02:00
Pablo Neira Ayuso 57d86b7d28 stream: remove includes from stream.h header
The should be uses in the client program. They are not required by
the generic stream socket infrastructure.
2011-10-05 13:43:15 +02:00
Pablo Neira Ayuso 8bf16493f6 initial commit 2011-10-04 02:36:46 +02:00