Skip to content

Commit

Permalink
Added support for RFC6598 private address range
Browse files Browse the repository at this point in the history
(cherry picked from commit b604bd9)
  • Loading branch information
danpascu committed Apr 25, 2017
1 parent 65c5b34 commit 7fb9ef1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions modules/nat_traversal/nat_traversal.c
Expand Up @@ -219,10 +219,11 @@ stat_var *registered_endpoints = 0;
stat_var *subscribed_endpoints = 0;
stat_var *dialog_endpoints = 0;

static NetInfo rfc1918nets[] = {
{"10.0.0.0", 0x0a000000UL, 0xff000000UL},
{"172.16.0.0", 0xac100000UL, 0xfff00000UL},
{"192.168.0.0", 0xc0a80000UL, 0xffff0000UL},
static NetInfo private_networks[] = {
{"10.0.0.0", 0x0a000000UL, 0xff000000UL}, // RFC 1918 10.0.0.0/8
{"172.16.0.0", 0xac100000UL, 0xfff00000UL}, // RFC 1918 172.16.0.0/12
{"192.168.0.0", 0xc0a80000UL, 0xffff0000UL}, // RFC 1918 192.168.0.0/16
{"100.64.0.0", 0x64400000UL, 0xffc00000UL}, // RFC 6598 100.64.0.0/10
{NULL, 0UL, 0UL}
};

Expand Down Expand Up @@ -753,11 +754,11 @@ get_contact_uri(struct sip_msg* msg, struct sip_uri *uri, contact_t **_c)
}


#define is_private_address(x) (rfc1918address(x)==1 ? 1 : 0)
#define is_private_address(x) (private_address(x)==1 ? 1 : 0)

// Test if IP in `address' belongs to a RFC1918 network
// Test if IP in `address' belongs to a private network
static INLINE int
rfc1918address(str *address)
private_address(str *address)
{
struct ip_addr *ip;
uint32_t netaddr;
Expand All @@ -769,8 +770,8 @@ rfc1918address(str *address)

netaddr = ntohl(ip->u.addr32[0]);

for (i=0; rfc1918nets[i].name!=NULL; i++) {
if ((netaddr & rfc1918nets[i].mask)==rfc1918nets[i].address) {
for (i=0; private_networks[i].name!=NULL; i++) {
if ((netaddr & private_networks[i].mask)==private_networks[i].address) {
return 1;
}
}
Expand All @@ -794,7 +795,7 @@ test_source_address(struct sip_msg *msg)
}


// Test if Contact field contains a private IP address as defined in RFC1918
// Test if Contact field contains a private IP address
static Bool
test_private_contact(struct sip_msg *msg)
{
Expand All @@ -808,7 +809,7 @@ test_private_contact(struct sip_msg *msg)
}


// Test if top Via field contains a private IP address as defined in RFC1918
// Test if top Via field contains a private IP address
static Bool
test_private_via(struct sip_msg *msg)
{
Expand Down

0 comments on commit 7fb9ef1

Please sign in to comment.