Skip to content

Commit

Permalink
ip_addr: simplify check for RFC 1918
Browse files Browse the repository at this point in the history
This function is used everywhere as follows:

```c
flag = (ip_addr_is_1918(x)==1) ? 1 : 0;
```

Let's just make it return the expected 0 or 1.

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
  • Loading branch information
lemenkov committed Apr 24, 2022
1 parent b8e6295 commit 89ae768
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ip_addr.c
Expand Up @@ -188,7 +188,7 @@ int ip_addr_is_1918(str *s_ip)

/* is it an IPv4 address? */
if ( (ip=str2ip(s_ip))==NULL )
return -1;
return 0;

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

Expand All @@ -197,7 +197,7 @@ int ip_addr_is_1918(str *s_ip)
return 1;
}

return -1;
return 0;
}


Expand Down
7 changes: 2 additions & 5 deletions modules/nat_traversal/nat_traversal.c
Expand Up @@ -747,9 +747,6 @@ get_contact_uri(struct sip_msg* msg, struct sip_uri *uri, contact_t **_c)
return True;
}


#define is_private_address(x) (ip_addr_is_1918(x)==1 ? 1 : 0)

// Test if address of signaling is different from address in 1st Via field
static Bool
test_source_address(struct sip_msg *msg)
Expand All @@ -775,15 +772,15 @@ test_private_contact(struct sip_msg *msg)
if (!get_contact_uri(msg, &uri, &contact))
return False;

return is_private_address(&(uri.host));
return ip_addr_is_1918(&(uri.host));
}


// Test if top Via field contains a private IP address
static Bool
test_private_via(struct sip_msg *msg)
{
return is_private_address(&(msg->via1->host));
return ip_addr_is_1918(&(msg->via1->host));
}


Expand Down
4 changes: 2 additions & 2 deletions modules/nathelper/nathelper.c
Expand Up @@ -794,7 +794,7 @@ sdp_1918(struct sip_msg* msg)
if (pf != AF_INET || isnulladdr(&ip, pf))
return 0;

ret |= (ip_addr_is_1918(&ip) == 1) ? 1 : 0;
ret |= ip_addr_is_1918(&ip);
}

return ret;
Expand All @@ -807,7 +807,7 @@ static int
via_1918(struct sip_msg* msg)
{

return (ip_addr_is_1918(&(msg->via1->host)) == 1) ? 1 : 0;
return ip_addr_is_1918(&(msg->via1->host));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion transformations.c
Expand Up @@ -2001,7 +2001,7 @@ int tr_eval_ip(struct sip_msg *msg, tr_param_t *tp,int subtype,
if(!(val->flags&PV_VAL_STR))
val->rs.s = int2str(val->ri, &val->rs.len);

val->ri = (ip_addr_is_1918(&(val->rs))==1) ? 1 : 0;
val->ri = ip_addr_is_1918(&(val->rs));

val->flags = PV_TYPE_INT|PV_VAL_INT|PV_VAL_STR;
val->rs.s = int2str(val->ri, &val->rs.len);
Expand Down

0 comments on commit 89ae768

Please sign in to comment.