mirror of https://gerrit.osmocom.org/libosmocore
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:
parent
6dce2cbc1e
commit
8ae40cbb91
22
src/socket.c
22
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));
|
||||
|
|
Loading…
Reference in New Issue