diff options
author | Harald Welte <laforge@osmocom.org> | 2020-03-08 22:23:30 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2020-03-09 11:24:38 +0100 |
commit | 9104597d7656c1914d71951c4894c89172ade624 (patch) | |
tree | 0240a4e0733b346414152270cd301fb530bd1d7f | |
parent | 3c51482e3d4043e79dec892296fbcd9a53d75b00 (diff) |
Add rtp_test to show the double-bind bug of OS#4444
Change-Id: I6742e5504cfb827031031e4d8d49a616ab203a94
-rw-r--r-- | tests/Makefile.am | 11 | ||||
-rw-r--r-- | tests/rtp_test/rtp_test.c | 92 | ||||
-rw-r--r-- | tests/rtp_test/rtp_test.ok | 2 | ||||
-rw-r--r-- | tests/testsuite.at | 6 |
4 files changed, 109 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ee91bb..bd95cf5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,7 +6,8 @@ check_PROGRAMS = e1inp_ipa_bsc_test \ e1inp_ipa_bts_test \ ipa_proxy_test \ subchan_demux/subchan_demux_test \ - ipa_recv/ipa_recv_test + ipa_recv/ipa_recv_test \ + rtp_test/rtp_test e1inp_ipa_bsc_test_SOURCES = e1inp_ipa_bsc_test.c e1inp_ipa_bsc_test_LDADD = $(top_builddir)/src/libosmoabis.la \ @@ -31,6 +32,11 @@ ipa_recv_ipa_recv_test_LDADD = $(top_builddir)/src/libosmoabis.la \ $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) \ $(LIBOSMOVTY_LIBS) +rtp_test_rtp_test_SOURCES = rtp_test/rtp_test.c +rtp_test_rtp_test_LDADD = $(top_builddir)/src/libosmotrau.la \ + $(LIBOSMOCORE_LIBS) + + # boilerplate for the tests # The `:;' works around a Bash 3.2 bug when the output is not writeable. $(srcdir)/package.m4: $(top_srcdir)/configure.ac @@ -52,7 +58,8 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \ subchan_demux/subchan_demux_test.ok \ - ipa_recv/ipa_recv_test.ok + ipa_recv/ipa_recv_test.ok \ + rtp_test/rtp_test.ok TESTSUITE = $(srcdir)/testsuite diff --git a/tests/rtp_test/rtp_test.c b/tests/rtp_test/rtp_test.c new file mode 100644 index 0000000..d696033 --- /dev/null +++ b/tests/rtp_test/rtp_test.c @@ -0,0 +1,92 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdint.h> +#include <errno.h> + +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include <osmocom/core/utils.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/logging.h> +#include <osmocom/core/application.h> +#include <osmocom/trau/osmo_ortp.h> + +static void *tall_test; + +static struct osmo_rtp_socket *create_bind_any(void) +{ + struct osmo_rtp_socket *rs; + int i; + + rs = osmo_rtp_socket_create(tall_test, 0); + for (i = 16384; i < 65535; i+=2) { + if (osmo_rtp_socket_bind(rs, "0.0.0.0", i) == 0) + return rs; + } + osmo_rtp_socket_free(rs); + return NULL; +} + +/* test if binding two sockets to the same local port fails (See OS#4444) */ +static void test_bind_fail(void) +{ + struct osmo_rtp_socket *rs[2]; + uint32_t ip; + int rc, port[2]; + + printf("First bind to any random local port...\n"); + rs[0] = create_bind_any(); + OSMO_ASSERT(rs[0]); + + /* then obtain the local port */ + rc = osmo_rtp_get_bound_ip_port(rs[0], &ip, &port[0]); + OSMO_ASSERT(rc == 0); + + printf("Now try to bind another socket to the same port: "); + rs[1] = osmo_rtp_socket_create(tall_test, 0); + OSMO_ASSERT(rs[1]); + rc = osmo_rtp_socket_bind(rs[1], "0.0.0.0", port[0]); + if (rc == -1 && errno == EADDRINUSE) + printf("OK (EADDRINUSE)\n"); + else { + printf("FAILED - second bind to port %u worked\n", port[0]); + fflush(stdout); + //OSMO_ASSERT(0); + } + + osmo_rtp_socket_free(rs[0]); + osmo_rtp_socket_free(rs[1]); +} + +#define DTEST 0 + +static const struct log_info_cat bts_test_cat[] = { + [DTEST] = { + .name = "DTEST", + .description = "test", + .color = "\033[1;35m", + .enabled = 1, .loglevel = LOGL_NOTICE, + }, +}; + +static const struct log_info bts_test_log_info = { + .filter_fn = NULL, + .cat = bts_test_cat, + .num_cat = ARRAY_SIZE(bts_test_cat), +}; + + +int main(int argc, char **argv) +{ + tall_test = talloc_named_const(NULL, 1, "rtp_test"); + osmo_init_logging2(tall_test, &bts_test_log_info); + osmo_rtp_init(tall_test); + + test_bind_fail(); + + exit(0); +} + diff --git a/tests/rtp_test/rtp_test.ok b/tests/rtp_test/rtp_test.ok new file mode 100644 index 0000000..ded2792 --- /dev/null +++ b/tests/rtp_test/rtp_test.ok @@ -0,0 +1,2 @@ +First bind to any random local port... +Now try to bind another socket to the same port: FAILED - second bind to port 16384 worked diff --git a/tests/testsuite.at b/tests/testsuite.at index ff550b0..5e87248 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -23,3 +23,9 @@ cat $abs_srcdir/subchan_demux/subchan_demux_test.ok > expout AT_CHECK([$abs_top_builddir/tests/subchan_demux/subchan_demux_test], [], [expout]) AT_CLEANUP +AT_SETUP([rtp_test]) +AT_KEYWORDS([rtp_test]) +cat $abs_srcdir/rtp_test/rtp_test.ok > expout +AT_CHECK([$abs_top_builddir/tests/rtp_test/rtp_test], [ignore], [expout]) +AT_CLEANUP + |