Change in libosmocore[master]: gsmtap: allow 127.0.0.x local listeners

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

Hoernchen gerrit-no-reply at lists.osmocom.org
Mon Sep 27 20:10:06 UTC 2021


Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/25622 )


Change subject: gsmtap: allow 127.0.0.x local listeners
......................................................................

gsmtap: allow 127.0.0.x local listeners

Even if not bound to a IF they just exist and work as expected, and make
distinguishing traffic for local setups easy.

Change-Id: I1043dfd8075f14481011f43db45c943e9320413c
---
M src/socket.c
1 file changed, 22 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/22/25622/1

diff --git a/src/socket.c b/src/socket.c
index 19d48e4..3d5ad63 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1129,6 +1129,25 @@
 	return 0;
 }
 
+/* linux has a default route:
+local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1
+*/
+static int sockaddr_is_local_routed(const struct sockaddr *a)
+{
+#if __linux__
+	if(a->sa_family != AF_INET)
+		return 0;
+
+	uint32_t address = ((struct sockaddr_in *)a)->sin_addr.s_addr; /* already BE */
+	uint32_t eightmask = htonl(0xff000000); /* /8 mask */
+	uint32_t local_prefix_127 = htonl(0x7f000000); /* 127.0.0.0 */
+
+	if ((address & eightmask) == local_prefix_127)
+		return 1;
+#endif
+	return 0;
+}
+
 /*! Determine if the given address is a local address
  *  \param[in] addr Socket Address
  *  \param[in] addrlen Length of socket address in bytes
@@ -1138,6 +1157,9 @@
 {
 	struct ifaddrs *ifaddr, *ifa;
 
+	if (sockaddr_is_local_routed(addr))
+		return 1;
+
 	if (getifaddrs(&ifaddr) == -1) {
 		LOGP(DLGLOBAL, LOGL_ERROR, "getifaddrs:"
 		     " %s\n", strerror(errno));

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1043dfd8075f14481011f43db45c943e9320413c
Gerrit-Change-Number: 25622
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210927/71e8eeb7/attachment.htm>


More information about the gerrit-log mailing list