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
This commit is contained in:
Eric Wild 2021-09-27 22:10:01 +02:00 committed by Hoernchen
parent 6dce2cbc1e
commit 8ae40cbb91
1 changed files with 22 additions and 0 deletions

View File

@ -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));