Change in libosmocore[master]: socket: add flag to enforce SO_REUSEADDR on UDP sockets

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/.

dexter gerrit-no-reply at lists.osmocom.org
Thu Aug 23 18:43:59 UTC 2018


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/10587


Change subject: socket: add flag to enforce SO_REUSEADDR on UDP sockets
......................................................................

socket: add flag to enforce SO_REUSEADDR on UDP sockets

When IPPROTO_UDP is used then SO_REUSEADDR omitted since UDP is
connection less we do not have to wait until lingering connections time
out. There were also negative effects such as that two applicatications
could use the same UDP port, normally one of the two applications would
get an error, but with SO_REUSEADDR this is supressed. However, there
are applications (UDP MULTICAST) where two applications must be able to
use the same port. In the osmocom project those are osmo-bts-virtual,
virtphy and gsmtap in general.

Lets introduce a flag that the API user can supply in order to have
SO_REUSEADDR applied.

- Add new flag OSMO_SOCK_F_UDP_REUSEADDR

Change-Id: I94aaf6d5224ab23bde5ea5c4a83569b6145ab32b
Related: OS#3497
---
M include/osmocom/core/socket.h
M src/socket.c
2 files changed, 5 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/87/10587/1

diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 20515b9..f23a243 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -24,6 +24,8 @@
 #define OSMO_SOCK_F_NO_MCAST_LOOP (1 << 3)
 /*! disable receiving all multiast even for non-subscribed groups */
 #define OSMO_SOCK_F_NO_MCAST_ALL  (1 << 4)
+/*! use SO_REUSEADDR on UDP ports (required for multicast) */
+#define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)
 
 int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
 		   const char *host, uint16_t port, unsigned int flags);
diff --git a/src/socket.c b/src/socket.c
index 210dbf9..7e7f6d9 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -209,7 +209,7 @@
 			if (sfd < 0)
 				continue;
 
-			if (proto != IPPROTO_UDP) {
+			if (proto != IPPROTO_UDP || flags & OSMO_SOCK_F_UDP_REUSEADDR) {
 				rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
 						&on, sizeof(on));
 				if (rc < 0) {
@@ -349,7 +349,7 @@
 				continue;
 			}
 		} else {
-			if (proto != IPPROTO_UDP) {
+			if (proto != IPPROTO_UDP || flags & OSMO_SOCK_F_UDP_REUSEADDR) {
 				rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
 						&on, sizeof(on));
 				if (rc < 0) {
@@ -379,7 +379,7 @@
 		return -ENODEV;
 	}
 
-	if (proto != IPPROTO_UDP) {
+	if (proto != IPPROTO_UDP || flags & OSMO_SOCK_F_UDP_REUSEADDR) {
 		rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
 		if (rc < 0) {
 			LOGP(DLGLOBAL, LOGL_ERROR,

-- 
To view, visit https://gerrit.osmocom.org/10587
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I94aaf6d5224ab23bde5ea5c4a83569b6145ab32b
Gerrit-Change-Number: 10587
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180823/75532540/attachment.htm>


More information about the gerrit-log mailing list