[MERGED] libosmocore[master]: socket: Allow disabling multicast loop on socket creation

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

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Jul 13 15:11:16 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: socket: Allow disabling multicast loop on socket creation
......................................................................


socket: Allow disabling multicast loop on socket creation

This introduces a new flag OSMO_SOCK_F_NO_MCAST_LOOP, which can be used
to disable the looping back of multicast packets transmitted throug this
socket to other local sockets on the machine.

As this looping-back is active by default, a single option to deviate
from the default is deemed sufficient.

Change-Id: I24a5b1ebc3f84d2d5d4734e54df50efaea26490b
---
M include/osmocom/core/socket.h
M src/socket.c
2 files changed, 18 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 6db436a..695e1d7 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -20,6 +20,8 @@
 #define OSMO_SOCK_F_BIND	(1 << 1)
 /*! switch socket to non-blocking mode */
 #define OSMO_SOCK_F_NONBLOCK	(1 << 2)
+/*! disable multiast loop (IP_MULTICAST_LOOP) */
+#define OSMO_SOCK_F_NO_MCAST_LOOP (1 << 3)
 
 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 d0e4c24..c7d081c 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -106,7 +106,7 @@
 
 static int osmo_sock_init_tail(int fd, uint16_t type, unsigned int flags)
 {
-	int rc = 0;
+	int rc;
 
 	/* Make sure to call 'listen' on a bound, connection-oriented sock */
 	if ((flags & (OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT)) == OSMO_SOCK_F_BIND) {
@@ -114,13 +114,25 @@
 		case SOCK_STREAM:
 		case SOCK_SEQPACKET:
 			rc = listen(fd, 10);
+			if (rc < 0) {
+				LOGP(DLGLOBAL, LOGL_ERROR, "unable to listen on socket: %s\n",
+					strerror(errno));
+				return rc;
+			}
+			break;
 		}
 	}
 
-	if (rc < 0)
-		LOGP(DLGLOBAL, LOGL_ERROR, "unable to listen on socket: %s\n", strerror(errno));
+	if (flags & OSMO_SOCK_F_NO_MCAST_LOOP) {
+		rc = osmo_sock_mcast_loop_set(fd, false);
+		if (rc < 0) {
+			LOGP(DLGLOBAL, LOGL_ERROR, "unable to disable multicast loop: %s\n",
+				strerror(errno));
+			return rc;
+		}
+	}
 
-	return rc;
+	return 0;
 }
 
 /*! Initialize a socket (including bind and/or connect)

-- 
To view, visit https://gerrit.osmocom.org/3240
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I24a5b1ebc3f84d2d5d4734e54df50efaea26490b
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list