Table of Contents
List of Examples
is_ip
usage
is_pure_ip
usage
is_ipv4
usage
is_ipv6
usage
is_ipv6_reference
usage
ip_type
usage
compare_ips
usage
compare_pure_ips
usage
is_ip_rfc1918
usage
Table of Contents
This module offers operations for IPv4 and IPv6.
IPv6 is defined in RFC 2460. The same IPv6 can be represented by different ASCII strings, so binary comparison is required. For example, the following IPv6 are equivalent:
1080:0000:0000:0000:0008:0800:200C:417A
1080:0:0:0:8:800:200C:417A
1080::8:800:200C:417A
When using IPv6 in an URI (i.e. a SIP URI) such IP must be written in "IPv6 reference" format (which is the textual representation of the IPv6 enclosed between [ ] symbols). An example is “sip:alice@[1080:0:0:0:8:800:200C:417A]”. This module also allows comparing a IPv6 with its IPv6 reference representation.
The following modules must be loaded before this module:
No dependencies on other SIP Router modules
Returns TRUE if the argument is a valid IPv4, IPv6 or IPv6 reference. FALSE otherwise.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Returns TRUE if the argument is a valid IPv4 or IPv6. FALSE otherwise.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.2.
is_pure_ip
usage
... $var(ip) = "::1"; if (is_pure_ip($var(ip))) { xlog("L_INFO", "it's IPv4 or IPv6\n"); } ...
Returns TRUE if the argument is a valid IPv4. FALSE otherwise.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Returns TRUE if the argument is a valid IPv6. FALSE otherwise.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.4.
is_ipv6
usage
... if (is_ipv6("1080:0:0:0:8:800:200C:417A")) { xlog("L_INFO", "it's IPv6\n"); } ...
Returns TRUE if the argument is a valid IPv6 reference. FALSE otherwise.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.5.
is_ipv6_reference
usage
... if (is_ipv6_reference("[1080:0:0:0:8:800:200C:417A]")) { xlog("L_INFO", "it's IPv6 reference\n"); } ...
Returns the type of the given IP.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
Return value:
1 - IPv4
2 - IPv6
3 - IPv6 reference
-1 - invalid IP
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.6.
ip_type
usage
... ip_type($var(myip)); switch($rc) { case 1: xlog("L_INFO", "it's IPv4\n"); break; case 2: xlog("L_INFO", "it's IPv6\n"); break; case 3: xlog("L_INFO", "it's IPv6 reference\n"); break; case -1: xlog("L_INFO", it's type invalid\n"); break; } ...
Returns TRUE if both IP's are the same. FALSE otherwise. This function also allows comparing an IPv6 against an IPv6 reference.
Parameters:
ip1 - String or pseudo-variable containing the first IP to compare.
ip2 - String or pseudo-variable containing the second IP to compare.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.7.
compare_ips
usage
... if (compare_ips("1080:0000:0000:0000:0008:0800:200C:417A", "[1080::8:800:200C:417A]")) { xlog("L_INFO", "both are the same IP\n"); } ...
Returns TRUE if both IP's are the same. FALSE otherwise. This function does NOT allow comparing an IPv6 against an IPv6 reference.
Parameters:
ip1 - String or pseudo-variable containing the first IP to compare.
ip2 - String or pseudo-variable containing the second IP to compare.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.8.
compare_pure_ips
usage
... if (compare_pure_ips($si, "1080::8:800:200C:417A")) { xlog("L_INFO", "both are the same IP\n"); } ...
Returns TRUE if the argument is a private IPv4 according to RFC 1918. FALSE otherwise.
Parameters:
ip - String or pseudo-variable containing the IP to evaluate.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.9.
is_ip_rfc1918
usage
... if (is_ip_rfc1918("10.0.123.123")) { xlog("L_INFO", "it's a private IPv4\n"); } ...