Commit Graph

317 Commits

Author SHA1 Message Date
Pau Espin d8f2b38eb9 osmux_snprintf: Add doxygen doc
Change-Id: Idb3fcf25be9558bfc2f822352c07ebc2cb7d5caa
2017-10-24 12:37:44 +02:00
Pau Espin 77d08a67b5 osmux_snprintf: Support different types of Osmux frames
Previous implementation handled all types as if they were Osmux AMR
frames. For Dummy frames, we account the padding but we don't care about
the padding content. For Signalling ones, as they are not in the
specification yet, it is better avoid using unespecified fields and
return an error because it's still not known how extra data will be
handled in the input msgb.

Change-Id: I48565472b47c2a0e5db50881fbb005537af8c70d
2017-10-24 12:36:00 +02:00
Pau Espin 05bb1c2b2e osmux_snprintf: Split logic parsing osmux header and AMR payload
The current code still expects to parse only AMR osmux frames, but that
will be fixed in following patches.

Change-Id: Ic2f4d1d3cc88af912bb43c8ecd90eacc6ff7190f
2017-10-23 17:16:01 +02:00
Max 1bfbf98f06 cosmetic: print textual error from recv()
Change-Id: Ic9557c6519b44b5985daf7d2d14ec063790441fb
2017-10-13 18:24:37 +02:00
Max a2b50809c7 cosmetic: relax UDP length check
Previously recv() returning 0 for UDP socket was considered as error
although it's legitimate return value for empty UDP packets. Relax the
error check to avoid confusing error messages.

The function behavior is the same:
* msg is not altered while receiving 0-length UDP packet
* return value is 0

The only result of the relaxed error check is the absense of error log
message for 0-length UDP packet.

Change-Id: I32e5fcbf5ed92cc923660ac59e6a37fd3f0703a7
Fixes: OS#2219
2017-10-13 18:19:32 +02:00
Max 8440357d4c examples: add simple UDP client/server
In addition to showing basic UDP send/receive example, it helps to test
corner-case when dealing with 0-length UDP packets.

Change-Id: I08c0adf1cf9b6a6f1f7090b237d0497c2ec13cdf
Related: OS#2219
2017-10-13 18:13:14 +02:00
Alexander Couzens fae8559ff5 debian/rules: show testsuite.log when tests are failing
Change-Id: I3af7b50e3d3e0ba3eddace0e6d4e58c6cb98b9aa
2017-10-11 07:08:08 +02:00
Harald Welte c98bf1b880 rs232.c: Don't #include <osmocom/abis/e1_input.h>
There's no need for the rs232 code to include a files from
libosmoabis. The only users of libosmoabis left now are the LAPD
examples:
	examples/lapd-over-datagram-network.c
	examples/lapd-over-datagram-user.c

Change-Id: Ie1bc0dd811362cec546486edc41d632740ed19cd
2017-10-05 08:41:52 +08:00
Pablo Neira Ayuso 5994198208 src: _snprintf() helper functions nul-terminate buffers, if possible
This patch inconditionally initializes the buffer we get to
nul-terminate it, whenever possible. It's a very simple solution to
catch three overly corner cases:

1) snprintf() returns -1, very much unlikely in practise.

2) msg->len == 0: In such case, I would expect this function is never
   called with an empty message, but let's be safe in this case too.

3) If your buffer is empty, it doesn't nul-terminate the buffer.

Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
2017-09-12 13:28:41 +02:00
Pablo Neira Ayuso 14af167a55 osmux: fix buffer management mess in snprintf() calls
SNPRINTF_BUFFER_SIZE() looks too complex, previous version maintains two
different variables to account for the remaining space in the buffer,
one of them is always decremented based on what snprintf() returns,
which may result in underflow. These variables are swapped - not used
consistently - all over this code.

Replace this macro by a simplified version, with one single parameter to
account for remaining space. This macro also deals with two corner
cases:

1) snprintf() fails, actually never happens in practise, but
   documentation indicates it may return -1, so let's catch this case
   from here to stick to specs.

2) There is not enough space in the buffer, in that case, keep
   increasing offset, so we know how much would have been printed, just
   like snprintf() does.

Thanks to Pau Espin for reporting, and Holger for clues on this.
I have run osmux_test and, at quick glance, it looks good.

Change-Id: I5b5d6ec57a02f57c23b1ae86dbd894bad28ea797
2017-09-11 18:06:37 +00:00
Pablo Neira Ayuso 9c5f01e7b2 rtp: return offset in osmo_rtp_snprintf()
Instead of the result of the last snprintf() call.

Change-Id: I10066d73387be96a4e1f3349d700405beb138076
2017-09-05 14:57:52 +02:00
Max 03b84ec99b Use release helper from libosmocore
See
https://osmocom.org/projects/cellular-infrastructure/wiki/Make_a_new_release
for details.

Change-Id: I01b0aae741b83a3f17f1caf2b6837cf365a1709b
Related: OS#1861
2017-08-28 10:53:35 +00:00
Max e3189dc8c2 Use value string check from osmo-ci
Change-Id: Id6048a69c9e0cc15010de643330aeb2a7271b2a6
2017-08-26 06:10:23 +00:00
Pau Espin e786055567 osmux: Slightly improve output format of osmux_snprintf
The buffer for osmux_test is increased as the former doesn't seem to be
able to cope with the whole output.

Change-Id: Ic838dd9d7ad89b4510ccfa58c0390c69a075b616
2017-08-14 17:24:11 +02:00
Pau Espin 7cca0da1cc osmux: Fix buffer overflow in osmux_snprintf
When running osmux_test on my PC, the process was aborted with a "stack
smashing detected" error.

Change-Id: I8a7cc422c181c0c5712ac8976a5be5f0ad44a9c0
2017-08-14 17:24:11 +02:00
Pau Espin 6032a35be8 tests: osmo-pcap: Allow different l2 pkts
Before this patch, ETH was assumed and other types were not supported.
This patch also adds Linux cooked packet support for L2.

Change-Id: Ie62fa0a8e45e1e141edb64b116dad185ad9c7a5f
2017-08-08 20:39:16 +02:00
Pau Espin 76c0acb149 tests: osmo-pcap: Fix per packet timer
Before this commit, the gap time between 2 packets {n-1, n} was being
applied to {n, n+1}.

Change-Id: I715865c1edd1fc2ec9b024671d91eb72559cbdea
2017-08-08 20:39:16 +02:00
Pau Espin 243a3b0372 contrib: Enable -Werror by default
Change-Id: I045536c21d7a0fa2fc23258c727d67bedf176ece
2017-07-13 21:32:26 +02:00
Pau Espin 728c2df796 rtp.c: Fix print format
Fixes compilation warning

Change-Id: I0146a19bf852c9e27d265a098dc9d7a337424e10
2017-07-13 21:32:26 +02:00
Harald Welte baff9c752e jenkins.sh: Proper error message if local environment isn't set up
Change-Id: I79c2302365824d9c8783dadfa378c8eaa07e2ee7
2017-07-10 15:00:00 +02:00
Pau Espin a6c6fa3a9a configure.ac: Use -Wall in C(PP)FLAGS
Change-Id: Ia1d7e99541089a92e6bc17798a94ac756047aeba
2017-07-08 10:41:09 +00:00
Pau Espin b049f39f31 configure.ac: Add --disable-doxygen flag
This flag, when set, allows to unconditionally disable doxygen
documentation generation, even if doxygen command is found.

Change-Id: I16b3502be3e32274f548da6a2a0b0363dd3bfe5d
2017-07-06 10:46:12 +02:00
Pablo Neira Ayuso 57b5f82491 src: use osmo_timer_setup()
Use new function available in libosmocore to set up timers. Compile
tested only.

Change-Id: Id3dd32102c7362f3b280d2c058c2decebccb357a
2017-06-07 18:40:35 +02:00
Harald Welte 31b1dbd894 somo_stream_srv_fd_cb(): close socket if NODELAY fails
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-05-14 21:51:26 +02:00
Pau Espin 56add1e780 stream.h: Add missing stdint.h include
This header uses uint16_t, which is provided by stdint.h.

Change-Id: I399e2986c9d8cb5b3dd31673a6b4bf63070a4770
2017-05-02 07:26:30 +00:00
Holger Hans Peter Freyther 4e93766a4b misc: Call the variable ctx like in all other places
We couldn't figure out what "crx" as supposed to mean and assume
it is a typo. Fix the code and call it ctx, this is fixing the
API documentation as well.

Change-Id: I27ed1178fdbbcf3fc0e1070dc19b4ecf9a327a04
2017-04-29 11:56:14 +00:00
Pau Espin a18caad5fd osmux: Fix delay between RTP packets
AMR frame contains 160 samples at 8000Hz -> 20 ms long

Change-Id: I36dc69f9caf591dd1b578bc914a2ce426c7f2813
2017-04-28 08:15:52 +00:00
Max 2c83b9a0ad deb: add missing dependency on doxygen
Attempt to fix OBS nightly by adding explicit dependency on doxygen,
similar to other libosmo*

Change-Id: I9cfc94a115c19eedf0923caacd17d1521b4c8fe4
2017-04-27 11:32:38 +02:00
Pau Espin 3460ad7f31 osmux: Use osmo_gettimeofday for testing puroposes
This way we can use fake time and osmux_test take 700ms instead of
>2sec to run.

Change-Id: Ic39cab74400aca8262a00c0d06884230b1a15ca3
2017-04-27 08:50:01 +00:00
Pau Espin e98afe5808 osmux: Add RTP marker bit support
According to RFC4867 (RTP payload format for AMR):
"The RTP header marker bit (M) SHALL be set to 1 if the first frameblock
carried in the packet contains a speech frame which is the first in a
talkspurt.  For all other packets the marker bit SHALL be set to zero (M=0)."

This information bit provides a way for the receiver to better
synchronize the delay with ther sender.

This is specially useful if AMR DTX features are supported and
enabled on the sender.

Change-Id: I0315658159429603f1d80a168718b026015060e9
2017-04-27 08:50:01 +00:00
Pau Espin a67c47cab4 osmux: Check batch_factor overflow in osmux_batch_enqueue
This commit should fix a bug present if for instance batch_factor < 8
and osmux_batch_enqueue is called from osmux_replay_lost_packets and
enough packets were lost from last received packet.

Change-Id: I5d643810949aeca4762f0cad05eed534d35087f7
2017-04-27 08:50:01 +00:00
Pau Espin a15d00ca57 osmux: use uint8_t everywhere for batch_factor
Change-Id: I9fcc8e94b2fcd843b10cb3f8f009f2348eb3a4af
2017-04-27 08:50:01 +00:00
Max dafdb5ef8c Fix debian packaging
* add separate -doc packages
* fix dh_install override
* add conflict with previous version

Change-Id: I2781c800d39923c5541bac00f00cb128f4acf008
2017-04-25 13:28:10 +02:00
Harald Welte c108c9db96 SCTP: Don't enable sender_dry_event for SCTP, as it breaks Linux SCTP
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-17 16:05:22 +02:00
Harald Welte c200a95615 stream.c: Fix SCTP_NODELAY setting
We were using the wrong variable when setting the SCTP_NODELAY,
resulting in the setsoctkopt() fialing.

Change-Id: Ic04cb8bb5ff41f177f7f5b7f7e2a2ecc686dd4c0
2017-04-16 23:34:28 +02:00
Harald Welte d8348ddafc netif/ipa.h: Don't redefine 'struct ipaccess_unit' from libosmocore
'struct ipaccess_unit' is defined in libosmocore/gsm/ipa.h, we shouldn't
re-define it here.  This entire IPA code duplication accross multiple
libraries and programs is a big mess.

Change-Id: If378a088c741df540befb928a5557fc62dea954a
2017-04-15 16:06:56 +02:00
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 a7d7dd220c ipa.h: Don't redefine what libosmocore already defines
Change-Id: Ibd81efc1dc61b8c2019d55a8fa6e3bb99b5acb20
2017-04-14 10:55:55 +02:00
Harald Welte 73a44d2348 stream.h: Add missing stdbool.h include
Functions introduced in 9ec26583cd are
using the bool type without referencing stdbool.h as include file.

Change-Id: I736cb04629d516c10c7d5f42f792ed3d5ae6658f
2017-04-12 15:06:37 +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 edad98b4a0 doc: Add Doxygen group for OSMUX related functions
Change-Id: I87e08bd84236ae5d5c057bca96d122e568a6b52a
2017-04-08 20:13:14 +02: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 3a060c59be README.md: Make sure all hyperlinks have <>
Change-Id: I5a5659afde32f08b324e602b7b1f96de805ba031
2017-03-17 21:30:33 +01:00