|
@@ -32,14 +32,17 @@ Iñaki Baz Castillo
|
|
4.4. is_ipv6 (ip)
|
|
4.4. is_ipv6 (ip)
|
|
4.5. is_ipv6_reference (ip)
|
|
4.5. is_ipv6_reference (ip)
|
|
4.6. ip_type (ip)
|
|
4.6. ip_type (ip)
|
|
- 4.7. compare_ips (ip1, ip2)
|
|
|
|
- 4.8. compare_pure_ips (ip1, ip2)
|
|
|
|
- 4.9. is_ip_rfc1918 (ip)
|
|
|
|
- 4.10. is_in_subnet (ip, subnets_list)
|
|
|
|
- 4.11. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
- 4.12. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
- 4.13. dns_query(hostname, pvid)
|
|
|
|
- 4.14. srv_query(srvcname, pvid)
|
|
|
|
|
|
+ 4.7. detailed_ip_type (ip, result)
|
|
|
|
+ 4.8. detailed_ipv4_type (ip, result)
|
|
|
|
+ 4.9. detailed_ipv6_type (ip, result)
|
|
|
|
+ 4.10. compare_ips (ip1, ip2)
|
|
|
|
+ 4.11. compare_pure_ips (ip1, ip2)
|
|
|
|
+ 4.12. is_ip_rfc1918 (ip)
|
|
|
|
+ 4.13. is_in_subnet (ip, subnets_list)
|
|
|
|
+ 4.14. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
+ 4.15. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
+ 4.16. dns_query(hostname, pvid)
|
|
|
|
+ 4.17. srv_query(srvcname, pvid)
|
|
|
|
|
|
List of Examples
|
|
List of Examples
|
|
|
|
|
|
@@ -49,14 +52,17 @@ Iñaki Baz Castillo
|
|
1.4. is_ipv6 usage
|
|
1.4. is_ipv6 usage
|
|
1.5. is_ipv6_reference usage
|
|
1.5. is_ipv6_reference usage
|
|
1.6. ip_type usage
|
|
1.6. ip_type usage
|
|
- 1.7. compare_ips usage
|
|
|
|
- 1.8. compare_pure_ips usage
|
|
|
|
- 1.9. is_ip_rfc1918 usage
|
|
|
|
- 1.10. is_in_subnet usage
|
|
|
|
- 1.11. dns_sys_match_ip usage
|
|
|
|
- 1.12. dns_int_match_ip usage
|
|
|
|
- 1.13. dns_query usage
|
|
|
|
- 1.14. srv_query usage
|
|
|
|
|
|
+ 1.7. detailed_ip_type usage
|
|
|
|
+ 1.8. detailed_ipv4_type usage
|
|
|
|
+ 1.9. detailed_ipv6_type usage
|
|
|
|
+ 1.10. compare_ips usage
|
|
|
|
+ 1.11. compare_pure_ips usage
|
|
|
|
+ 1.12. is_ip_rfc1918 usage
|
|
|
|
+ 1.13. is_in_subnet usage
|
|
|
|
+ 1.14. dns_sys_match_ip usage
|
|
|
|
+ 1.15. dns_int_match_ip usage
|
|
|
|
+ 1.16. dns_query usage
|
|
|
|
+ 1.17. srv_query usage
|
|
|
|
|
|
Chapter 1. Admin Guide
|
|
Chapter 1. Admin Guide
|
|
|
|
|
|
@@ -77,14 +83,17 @@ Chapter 1. Admin Guide
|
|
4.4. is_ipv6 (ip)
|
|
4.4. is_ipv6 (ip)
|
|
4.5. is_ipv6_reference (ip)
|
|
4.5. is_ipv6_reference (ip)
|
|
4.6. ip_type (ip)
|
|
4.6. ip_type (ip)
|
|
- 4.7. compare_ips (ip1, ip2)
|
|
|
|
- 4.8. compare_pure_ips (ip1, ip2)
|
|
|
|
- 4.9. is_ip_rfc1918 (ip)
|
|
|
|
- 4.10. is_in_subnet (ip, subnets_list)
|
|
|
|
- 4.11. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
- 4.12. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
- 4.13. dns_query(hostname, pvid)
|
|
|
|
- 4.14. srv_query(srvcname, pvid)
|
|
|
|
|
|
+ 4.7. detailed_ip_type (ip, result)
|
|
|
|
+ 4.8. detailed_ipv4_type (ip, result)
|
|
|
|
+ 4.9. detailed_ipv6_type (ip, result)
|
|
|
|
+ 4.10. compare_ips (ip1, ip2)
|
|
|
|
+ 4.11. compare_pure_ips (ip1, ip2)
|
|
|
|
+ 4.12. is_ip_rfc1918 (ip)
|
|
|
|
+ 4.13. is_in_subnet (ip, subnets_list)
|
|
|
|
+ 4.14. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
+ 4.15. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
+ 4.16. dns_query(hostname, pvid)
|
|
|
|
+ 4.17. srv_query(srvcname, pvid)
|
|
|
|
|
|
1. Overview
|
|
1. Overview
|
|
|
|
|
|
@@ -132,14 +141,17 @@ Chapter 1. Admin Guide
|
|
4.4. is_ipv6 (ip)
|
|
4.4. is_ipv6 (ip)
|
|
4.5. is_ipv6_reference (ip)
|
|
4.5. is_ipv6_reference (ip)
|
|
4.6. ip_type (ip)
|
|
4.6. ip_type (ip)
|
|
- 4.7. compare_ips (ip1, ip2)
|
|
|
|
- 4.8. compare_pure_ips (ip1, ip2)
|
|
|
|
- 4.9. is_ip_rfc1918 (ip)
|
|
|
|
- 4.10. is_in_subnet (ip, subnets_list)
|
|
|
|
- 4.11. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
- 4.12. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
- 4.13. dns_query(hostname, pvid)
|
|
|
|
- 4.14. srv_query(srvcname, pvid)
|
|
|
|
|
|
+ 4.7. detailed_ip_type (ip, result)
|
|
|
|
+ 4.8. detailed_ipv4_type (ip, result)
|
|
|
|
+ 4.9. detailed_ipv6_type (ip, result)
|
|
|
|
+ 4.10. compare_ips (ip1, ip2)
|
|
|
|
+ 4.11. compare_pure_ips (ip1, ip2)
|
|
|
|
+ 4.12. is_ip_rfc1918 (ip)
|
|
|
|
+ 4.13. is_in_subnet (ip, subnets_list)
|
|
|
|
+ 4.14. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
+ 4.15. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
+ 4.16. dns_query(hostname, pvid)
|
|
|
|
+ 4.17. srv_query(srvcname, pvid)
|
|
|
|
|
|
4.1. is_ip (ip)
|
|
4.1. is_ip (ip)
|
|
|
|
|
|
@@ -265,7 +277,93 @@ switch($rc) {
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.7. compare_ips (ip1, ip2)
|
|
|
|
|
|
+4.7. detailed_ip_type (ip, result)
|
|
|
|
+
|
|
|
|
+ Returns the detailed type of the given IP () (see
|
|
|
|
+ http://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.t
|
|
|
|
+ xt,
|
|
|
|
+ http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-sp
|
|
|
|
+ ecial-registry.txt, RFC 5735 and RFC 6598: PRIVATE, SHARED, LOOPBACK,
|
|
|
|
+ IPV4MAP, DISCARD etc).
|
|
|
|
+
|
|
|
|
+ Parameters:
|
|
|
|
+ * ip - String or pseudo-variable containing the IP to evaluate.
|
|
|
|
+ * result - String or pseudo-variable containing the detailed type of
|
|
|
|
+ the IP.
|
|
|
|
+ + IPv4 - PUBLIC, RIVATE, SHARED, LOOPBACK, LINK-LOCAL, RESERVED,
|
|
|
|
+ TEST-NET, 6TO4-RELAY, MULTICAST, BROADCAST
|
|
|
|
+ + IPv6 - UNSPECIFIED, LOOPBACK, IPV4MAP, RESERVED, DISCARD,
|
|
|
|
+ GLOBAL-UNICAST, TEREDO, BMWG, DOCUMENTATION, ORCHID, 6TO4,
|
|
|
|
+ UNIQUE-LOCAL-UNICAST, LINK-LOCAL-UNICAST, MULTICAST
|
|
|
|
+
|
|
|
|
+ Return value:
|
|
|
|
+ * 1 - successful operation
|
|
|
|
+ * negative value - error occured
|
|
|
|
+
|
|
|
|
+ This function can be used from ALL ROUTES
|
|
|
|
+
|
|
|
|
+ Example 1.7. detailed_ip_type usage
|
|
|
|
+...
|
|
|
|
+ detailed_ip_type("192.168.1.2","$var(result)");
|
|
|
|
+ xlog("L_ERR","IP address is of detailed type: $var(result) ");
|
|
|
|
+...
|
|
|
|
+
|
|
|
|
+4.8. detailed_ipv4_type (ip, result)
|
|
|
|
+
|
|
|
|
+ Returns the detailed type of the given IP () (see RFC 5735 and RFC
|
|
|
|
+ 6598).
|
|
|
|
+
|
|
|
|
+ Parameters:
|
|
|
|
+ * ip - String or pseudo-variable containing the IP to evaluate.
|
|
|
|
+ * result - String or pseudo-variable containing the detailed type of
|
|
|
|
+ the IP.
|
|
|
|
+ + IPv4 - PUBLIC, PRIVATE, SHARED, LOOPBACK, LINK-LOCAL,
|
|
|
|
+ RESERVED, TEST-NET, 6TO4-RELAY, MULTICAST, BROADCAST
|
|
|
|
+
|
|
|
|
+ Return value:
|
|
|
|
+ * 1 - successful operation
|
|
|
|
+ * negative value - error occured
|
|
|
|
+
|
|
|
|
+ This function can be used from ALL ROUTES
|
|
|
|
+
|
|
|
|
+ Example 1.8. detailed_ipv4_type usage
|
|
|
|
+...
|
|
|
|
+ detailed_ipv4_type("192.168.1.2","$var(result)");
|
|
|
|
+ xlog("L_ERR","IP address is of detailed type: $var(result) ");
|
|
|
|
+...
|
|
|
|
+
|
|
|
|
+4.9. detailed_ipv6_type (ip, result)
|
|
|
|
+
|
|
|
|
+ Returns the detailed type of the given IP () (see
|
|
|
|
+ http://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.t
|
|
|
|
+ xt,
|
|
|
|
+ http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-sp
|
|
|
|
+ ecial-registry.txt).
|
|
|
|
+
|
|
|
|
+ Parameters:
|
|
|
|
+ * ip - String or pseudo-variable containing the IP to evaluate.
|
|
|
|
+ * result - String or pseudo-variable containing the detailed type of
|
|
|
|
+ the IP.
|
|
|
|
+ + IPv6 - UNSPECIFIED, LOOPBACK, IPV4MAP, RESERVED, DISCARD,
|
|
|
|
+ GLOBAL-UNICAST, TEREDO, BMWG, DOCUMENTATION, ORCHID, 6TO4,
|
|
|
|
+ UNIQUE-LOCAL-UNICAST, LINK-LOCAL-UNICAST, MULTICAST
|
|
|
|
+
|
|
|
|
+ Return value:
|
|
|
|
+ * 1 - successful operation
|
|
|
|
+ * negative value - error occured
|
|
|
|
+
|
|
|
|
+ This function can be used from ALL ROUTES
|
|
|
|
+
|
|
|
|
+ Example 1.9. detailed_ipv6_type usage
|
|
|
|
+...
|
|
|
|
+ detailed_ipv6_type("2001:8d8:7c0:402:217:72:194:30","$var(result)");
|
|
|
|
+ xlog("L_ERR","IP address is of detailed type: $var(result) ");
|
|
|
|
+
|
|
|
|
+ detailed_ipv6_type("[2001:8d8:7c0:402:217:72:194:30]","$var(result)");
|
|
|
|
+ xlog("L_ERR","IP address is of detailed type: $var(result) ");
|
|
|
|
+...
|
|
|
|
+
|
|
|
|
+4.10. compare_ips (ip1, ip2)
|
|
|
|
|
|
Returns TRUE if both IP addresses are the same. FALSE otherwise. This
|
|
Returns TRUE if both IP addresses are the same. FALSE otherwise. This
|
|
function also allows comparing an IPv6 address against an IPv6
|
|
function also allows comparing an IPv6 address against an IPv6
|
|
@@ -279,7 +377,7 @@ switch($rc) {
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
|
|
|
|
- Example 1.7. compare_ips usage
|
|
|
|
|
|
+ Example 1.10. compare_ips usage
|
|
...
|
|
...
|
|
if (compare_ips("1080:0000:0000:0000:0008:0800:200C:417A", "[1080::8:800:200C:41
|
|
if (compare_ips("1080:0000:0000:0000:0008:0800:200C:417A", "[1080::8:800:200C:41
|
|
7A]")) {
|
|
7A]")) {
|
|
@@ -287,7 +385,7 @@ if (compare_ips("1080:0000:0000:0000:0008:0800:200C:417A", "[1080::8:800:200C:41
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.8. compare_pure_ips (ip1, ip2)
|
|
|
|
|
|
+4.11. compare_pure_ips (ip1, ip2)
|
|
|
|
|
|
Returns TRUE if both IP's are the same. FALSE otherwise. This function
|
|
Returns TRUE if both IP's are the same. FALSE otherwise. This function
|
|
does NOT allow comparing an IPv6 against an IPv6 reference.
|
|
does NOT allow comparing an IPv6 against an IPv6 reference.
|
|
@@ -301,14 +399,14 @@ if (compare_ips("1080:0000:0000:0000:0008:0800:200C:417A", "[1080::8:800:200C:41
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
|
|
|
|
- Example 1.8. compare_pure_ips usage
|
|
|
|
|
|
+ Example 1.11. compare_pure_ips usage
|
|
...
|
|
...
|
|
if (compare_pure_ips($si, "1080::8:800:200C:417A")) {
|
|
if (compare_pure_ips($si, "1080::8:800:200C:417A")) {
|
|
xlog("L_INFO", "both are the same IP\n");
|
|
xlog("L_INFO", "both are the same IP\n");
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.9. is_ip_rfc1918 (ip)
|
|
|
|
|
|
+4.12. is_ip_rfc1918 (ip)
|
|
|
|
|
|
Returns TRUE if the argument is a private IPv4 according to RFC 1918.
|
|
Returns TRUE if the argument is a private IPv4 according to RFC 1918.
|
|
FALSE otherwise.
|
|
FALSE otherwise.
|
|
@@ -319,14 +417,14 @@ if (compare_pure_ips($si, "1080::8:800:200C:417A")) {
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
|
|
|
|
- Example 1.9. is_ip_rfc1918 usage
|
|
|
|
|
|
+ Example 1.12. is_ip_rfc1918 usage
|
|
...
|
|
...
|
|
if (is_ip_rfc1918("10.0.123.123")) {
|
|
if (is_ip_rfc1918("10.0.123.123")) {
|
|
xlog("L_INFO", "it's a private IPv4\n");
|
|
xlog("L_INFO", "it's a private IPv4\n");
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.10. is_in_subnet (ip, subnets_list)
|
|
|
|
|
|
+4.13. is_in_subnet (ip, subnets_list)
|
|
|
|
|
|
Returns TRUE if the first argument is an IP address within the (CIDR
|
|
Returns TRUE if the first argument is an IP address within the (CIDR
|
|
notation) subnets list in the second argument. FALSE otherwise.
|
|
notation) subnets list in the second argument. FALSE otherwise.
|
|
@@ -339,7 +437,7 @@ if (is_ip_rfc1918("10.0.123.123")) {
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
|
|
|
|
|
|
- Example 1.10. is_in_subnet usage
|
|
|
|
|
|
+ Example 1.13. is_in_subnet usage
|
|
...
|
|
...
|
|
if (is_in_subnet("10.0.123.123", "10.0.123.1/24")) {
|
|
if (is_in_subnet("10.0.123.123", "10.0.123.1/24")) {
|
|
xlog("L_INFO", "it's in the subnet\n");
|
|
xlog("L_INFO", "it's in the subnet\n");
|
|
@@ -350,7 +448,7 @@ if (is_in_subnet("10.0.123.123", "10.0.0.0/16,192.168.0.0/24")) {
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.11. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
|
|
+4.14. dns_sys_match_ip(hostname, ipaddr)
|
|
|
|
|
|
Returns TRUE if ipaddr is associated by DNS to hostname. FALSE
|
|
Returns TRUE if ipaddr is associated by DNS to hostname. FALSE
|
|
otherwise. It does not use the internal DNS resolver, but directly
|
|
otherwise. It does not use the internal DNS resolver, but directly
|
|
@@ -366,14 +464,14 @@ if (is_in_subnet("10.0.123.123", "10.0.0.0/16,192.168.0.0/24")) {
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.11. dns_sys_match_ip usage
|
|
|
|
|
|
+ Example 1.14. dns_sys_match_ip usage
|
|
...
|
|
...
|
|
if (!dns_sys_match_ip("myhost.com", "1.2.3.4")) {
|
|
if (!dns_sys_match_ip("myhost.com", "1.2.3.4")) {
|
|
xdbg("ip address not associated with hostname\n");
|
|
xdbg("ip address not associated with hostname\n");
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.12. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
|
|
+4.15. dns_int_match_ip(hostname, ipaddr)
|
|
|
|
|
|
Returns TRUE if ipaddr is associated by DNS to hostname. FALSE
|
|
Returns TRUE if ipaddr is associated by DNS to hostname. FALSE
|
|
otherwise. It uses internal DNS resolver. At this moment, the function
|
|
otherwise. It uses internal DNS resolver. At this moment, the function
|
|
@@ -390,14 +488,14 @@ if (!dns_sys_match_ip("myhost.com", "1.2.3.4")) {
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.12. dns_int_match_ip usage
|
|
|
|
|
|
+ Example 1.15. dns_int_match_ip usage
|
|
...
|
|
...
|
|
if (!dns_int_match_ip("myhost.com", "1.2.3.4")) {
|
|
if (!dns_int_match_ip("myhost.com", "1.2.3.4")) {
|
|
xdbg("ip address not associated with hostname\n");
|
|
xdbg("ip address not associated with hostname\n");
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.13. dns_query(hostname, pvid)
|
|
|
|
|
|
+4.16. dns_query(hostname, pvid)
|
|
|
|
|
|
Store the IP addresses and their type that correspond to hostname in a
|
|
Store the IP addresses and their type that correspond to hostname in a
|
|
config variable $dns(pvid=>key).
|
|
config variable $dns(pvid=>key).
|
|
@@ -409,7 +507,7 @@ if (!dns_int_match_ip("myhost.com", "1.2.3.4")) {
|
|
|
|
|
|
This function can be used from ANY_ROUTE.
|
|
This function can be used from ANY_ROUTE.
|
|
|
|
|
|
- Example 1.13. dns_query usage
|
|
|
|
|
|
+ Example 1.16. dns_query usage
|
|
...
|
|
...
|
|
if(dns_query("test.com", "xyz"))
|
|
if(dns_query("test.com", "xyz"))
|
|
{
|
|
{
|
|
@@ -425,7 +523,7 @@ if(dns_query("test.com", "xyz"))
|
|
}
|
|
}
|
|
...
|
|
...
|
|
|
|
|
|
-4.14. srv_query(srvcname, pvid)
|
|
|
|
|
|
+4.17. srv_query(srvcname, pvid)
|
|
|
|
|
|
Queries DNS SRV records to resolve a service/protocol name into a list
|
|
Queries DNS SRV records to resolve a service/protocol name into a list
|
|
of priorities, weights, ports, and targets sorted by priority and
|
|
of priorities, weights, ports, and targets sorted by priority and
|
|
@@ -451,7 +549,7 @@ if(dns_query("test.com", "xyz"))
|
|
* target [index] - target host name
|
|
* target [index] - target host name
|
|
* weight [index] - weight number as defined by RFC 2782
|
|
* weight [index] - weight number as defined by RFC 2782
|
|
|
|
|
|
- Example 1.14. srv_query usage
|
|
|
|
|
|
+ Example 1.17. srv_query usage
|
|
...
|
|
...
|
|
if (srv_query ("_sip._udp.example.com", "udp") > 0) {
|
|
if (srv_query ("_sip._udp.example.com", "udp") > 0) {
|
|
$var(cnt) = $srvquery(udp=>count);
|
|
$var(cnt) = $srvquery(udp=>count);
|