Hoernchen has submitted this change. ( 
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(-)

Approvals:
  dexter: Looks good to me, but someone else must approve
  pespin: Looks good to me, but someone else must approve
  osmith: Looks good to me, but someone else must approve
  Hoernchen: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/socket.c b/src/socket.c
index 19d48e4..45b0f5b 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: 3
Gerrit-Owner: Hoernchen <[email protected]>
Gerrit-Reviewer: Hoernchen <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-CC: fixeria <[email protected]>
Gerrit-MessageType: merged

Reply via email to