tpws: block connections to 127.0.0.0/8

This commit is contained in:
bol-van 2021-03-19 10:55:20 +03:00
parent 638a27c181
commit 94405e89c3
11 changed files with 10 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -76,6 +76,9 @@ bool check_local_ip(const struct sockaddr *saddr)
{
struct ifaddrs *addrs,*a;
if (saddr->sa_family==AF_INET && is_localnet((struct sockaddr_in *)saddr))
return true;
if (getifaddrs(&addrs)<0) return false;
a = addrs;
@ -150,6 +153,10 @@ bool saconvmapped(struct sockaddr_storage *a)
return false;
}
bool is_localnet(const struct sockaddr_in *a)
{
return (htonl(a->sin_addr.s_addr)>>24)==127;
}
bool is_linklocal(const struct sockaddr_in6 *a)
{
// fe80::/10

View File

@ -21,6 +21,7 @@ uint16_t saport(const struct sockaddr *sa);
// true = was converted
bool saconvmapped(struct sockaddr_storage *a);
bool is_localnet(const struct sockaddr_in *a);
bool is_linklocal(const struct sockaddr_in6* a);
bool is_private6(const struct sockaddr_in6* a);