Change in libosmo-abis[pespin/0.8.0]: Add rtp_test to show the double-bind bug of OS#4444

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Mon Mar 9 11:09:22 UTC 2020


Hello laforge,

I'd like you to do a code review. Please visit

    https://gerrit.osmocom.org/c/libosmo-abis/+/17432

to review the following change.


Change subject: Add rtp_test to show the double-bind bug of OS#4444
......................................................................

Add rtp_test to show the double-bind bug of OS#4444

Change-Id: I6742e5504cfb827031031e4d8d49a616ab203a94
---
M tests/Makefile.am
A tests/rtp_test/rtp_test.c
A tests/rtp_test/rtp_test.ok
M tests/testsuite.at
4 files changed, 109 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/32/17432/1

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 @@
 		  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 @@
 			$(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 @@
 
 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 @@
 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
+

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/17432
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-abis
Gerrit-Branch: pespin/0.8.0
Gerrit-Change-Id: I6742e5504cfb827031031e4d8d49a616ab203a94
Gerrit-Change-Number: 17432
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200309/330b263d/attachment.htm>


More information about the gerrit-log mailing list