aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric <ewild@sysmocom.de>2021-09-27 22:10:01 +0200
committerHoernchen <ewild@sysmocom.de>2021-10-06 13:01:26 +0000
commit8ae40cbb9186729202068f83576efd025450fd5e (patch)
treeefb8d97b445f79f850d89420d75e415eff27aaa2
parent6dce2cbc1e53e9f25b1fa9201cb812949f540096 (diff)
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
-rw-r--r--src/socket.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/socket.c b/src/socket.c
index 19d48e4f..45b0f5b7 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1129,6 +1129,25 @@ static int sockaddr_equal(const struct sockaddr *a,
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 @@ int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen)
{
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));