| 1 |
ipops Module |
| 2 |
|
| 3 |
Iñaki Baz Castillo |
| 4 |
|
| 5 |
<[email protected]> |
| 6 |
|
| 7 |
Edited by |
| 8 |
|
| 9 |
Iñaki Baz Castillo |
| 10 |
|
| 11 |
<[email protected]> |
| 12 |
|
| 13 |
Copyright © 2011 Iñaki Baz Castillo |
| 14 |
__________________________________________________________________ |
| 15 |
|
| 16 |
Table of Contents |
| 17 |
|
| 18 |
1. Admin Guide |
| 19 |
|
| 20 |
1. Overview |
| 21 |
2. Dependencies |
| 22 |
|
| 23 |
2.1. SIP Router Modules |
| 24 |
2.2. External Libraries or Applications |
| 25 |
|
| 26 |
3. Parameters |
| 27 |
4. Functions |
| 28 |
|
| 29 |
4.1. is_ip (ip) |
| 30 |
4.2. is_pure_ip (ip) |
| 31 |
4.3. is_ipv4 (ip) |
| 32 |
4.4. is_ipv6 (ip) |
| 33 |
4.5. is_ipv6_reference (ip) |
| 34 |
4.6. ip_type (ip) |
| 35 |
4.7. detailed_ip_type (ip, result) |
| 36 |
4.8. detailed_ipv4_type (ip, result) |
| 37 |
4.9. detailed_ipv6_type (ip, result) |
| 38 |
4.10. compare_ips (ip1, ip2) |
| 39 |
4.11. compare_pure_ips (ip1, ip2) |
| 40 |
4.12. is_ip_rfc1918 (ip) |
| 41 |
4.13. is_in_subnet (ip, subnets_list) |
| 42 |
4.14. dns_sys_match_ip(hostname, ipaddr) |
| 43 |
4.15. dns_int_match_ip(hostname, ipaddr) |
| 44 |
4.16. dns_query(hostname, pvid) |
| 45 |
4.17. ptr_query(ip, pvid) |
| 46 |
4.18. srv_query(srvcname, pvid) |
| 47 |
4.19. naptr_query(domain, pvid) |
| 48 |
4.20. dns_set_local_ttl(vttl) |
| 49 |
|
| 50 |
List of Examples |
| 51 |
|
| 52 |
1.1. is_ip usage |
| 53 |
1.2. is_pure_ip usage |
| 54 |
1.3. is_ipv4 usage |
| 55 |
1.4. is_ipv6 usage |
| 56 |
1.5. is_ipv6_reference usage |
| 57 |
1.6. ip_type usage |
| 58 |
1.7. detailed_ip_type usage |
| 59 |
1.8. detailed_ipv4_type usage |
| 60 |
1.9. detailed_ipv6_type usage |
| 61 |
1.10. compare_ips usage |
| 62 |
1.11. compare_pure_ips usage |
| 63 |
1.12. is_ip_rfc1918 usage |
| 64 |
1.13. is_in_subnet usage |
| 65 |
1.14. dns_sys_match_ip usage |
| 66 |
1.15. dns_int_match_ip usage |
| 67 |
1.16. dns_query usage |
| 68 |
1.17. ptr_query usage |
| 69 |
1.18. srv_query usage |
| 70 |
1.19. naptr_query usage |
| 71 |
1.20. dns_set_local_ttl usage |
| 72 |
|
| 73 |
Chapter 1. Admin Guide |
| 74 |
|
| 75 |
Table of Contents |
| 76 |
|
| 77 |
1. Overview |
| 78 |
2. Dependencies |
| 79 |
|
| 80 |
2.1. SIP Router Modules |
| 81 |
2.2. External Libraries or Applications |
| 82 |
|
| 83 |
3. Parameters |
| 84 |
4. Functions |
| 85 |
|
| 86 |
4.1. is_ip (ip) |
| 87 |
4.2. is_pure_ip (ip) |
| 88 |
4.3. is_ipv4 (ip) |
| 89 |
4.4. is_ipv6 (ip) |
| 90 |
4.5. is_ipv6_reference (ip) |
| 91 |
4.6. ip_type (ip) |
| 92 |
4.7. detailed_ip_type (ip, result) |
| 93 |
4.8. detailed_ipv4_type (ip, result) |
| 94 |
4.9. detailed_ipv6_type (ip, result) |
| 95 |
4.10. compare_ips (ip1, ip2) |
| 96 |
4.11. compare_pure_ips (ip1, ip2) |
| 97 |
4.12. is_ip_rfc1918 (ip) |
| 98 |
4.13. is_in_subnet (ip, subnets_list) |
| 99 |
4.14. dns_sys_match_ip(hostname, ipaddr) |
| 100 |
4.15. dns_int_match_ip(hostname, ipaddr) |
| 101 |
4.16. dns_query(hostname, pvid) |
| 102 |
4.17. ptr_query(ip, pvid) |
| 103 |
4.18. srv_query(srvcname, pvid) |
| 104 |
4.19. naptr_query(domain, pvid) |
| 105 |
4.20. dns_set_local_ttl(vttl) |
| 106 |
|
| 107 |
1. Overview |
| 108 |
|
| 109 |
The IPops module offers operations for handling IP addresses, both IPv4 |
| 110 |
and IPv6. |
| 111 |
|
| 112 |
IPv6 is defined in RFC 2460. The same IPv6 address can be represented |
| 113 |
by different ASCII strings, so binary comparison is required. For |
| 114 |
example, the following IPv6 addresses are equivalent: |
| 115 |
* 2001:DB8:0000:0000:0008:0800:200C:417A |
| 116 |
* 2001:DB8:0:0:8:800:200C:417A |
| 117 |
* 2001:DB8::200C:417A |
| 118 |
|
| 119 |
When using IPv6 in an URI (i.e. a SIP URI) the IP address must be |
| 120 |
written in "IPv6 reference" format (which is the textual representation |
| 121 |
of the IPv6 enclosed between [ ] symbols). An example is |
| 122 |
“sip:alice@[2001:DB8:0:0:8:800:200C:417A]”. This allows separation of |
| 123 |
address and port number with a :, like |
| 124 |
“[2001:DB8:0:0:8:800:200C:417A]:5060”. This module also allows |
| 125 |
comparing an IPv6 address with its IPv6 reference representation. |
| 126 |
|
| 127 |
2. Dependencies |
| 128 |
|
| 129 |
2.1. SIP Router Modules |
| 130 |
2.2. External Libraries or Applications |
| 131 |
|
| 132 |
2.1. SIP Router Modules |
| 133 |
|
| 134 |
The following modules must be loaded before this module: |
| 135 |
* No dependencies on other SIP Router modules |
| 136 |
|
| 137 |
2.2. External Libraries or Applications |
| 138 |
|
| 139 |
The following libraries or applications must be installed before |
| 140 |
running SIP Router with this module loaded: |
| 141 |
* No dependencies on external libraries |
| 142 |
|
| 143 |
3. Parameters |
| 144 |
|
| 145 |
4. Functions |
| 146 |
|
| 147 |
4.1. is_ip (ip) |
| 148 |
4.2. is_pure_ip (ip) |
| 149 |
4.3. is_ipv4 (ip) |
| 150 |
4.4. is_ipv6 (ip) |
| 151 |
4.5. is_ipv6_reference (ip) |
| 152 |
4.6. ip_type (ip) |
| 153 |
4.7. detailed_ip_type (ip, result) |
| 154 |
4.8. detailed_ipv4_type (ip, result) |
| 155 |
4.9. detailed_ipv6_type (ip, result) |
| 156 |
4.10. compare_ips (ip1, ip2) |
| 157 |
4.11. compare_pure_ips (ip1, ip2) |
| 158 |
4.12. is_ip_rfc1918 (ip) |
| 159 |
4.13. is_in_subnet (ip, subnets_list) |
| 160 |
4.14. dns_sys_match_ip(hostname, ipaddr) |
| 161 |
4.15. dns_int_match_ip(hostname, ipaddr) |
| 162 |
4.16. dns_query(hostname, pvid) |
| 163 |
4.17. ptr_query(ip, pvid) |
| 164 |
4.18. srv_query(srvcname, pvid) |
| 165 |
4.19. naptr_query(domain, pvid) |
| 166 |
4.20. dns_set_local_ttl(vttl) |
| 167 |
|
| 168 |
4.1. is_ip (ip) |
| 169 |
|
| 170 |
Returns TRUE if the argument is a valid IPv4, IPv6 or IPv6 reference. |
| 171 |
FALSE otherwise. |
| 172 |
|
| 173 |
Parameters: |
| 174 |
* ip - String or pseudo-variable containing the IP address to |
| 175 |
evaluate. |
| 176 |
|
| 177 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 178 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 179 |
|
| 180 |
Example 1.1. is_ip usage |
| 181 |
... |
| 182 |
if (is_ip($rd)) { |
| 183 |
xlog("L_INFO", "RURI domain is an IP address (not a host name/domain)\n"); |
| 184 |
} |
| 185 |
... |
| 186 |
|
| 187 |
4.2. is_pure_ip (ip) |
| 188 |
|
| 189 |
Returns TRUE if the argument is a valid IPv4 or IPv6. FALSE otherwise. |
| 190 |
|
| 191 |
Parameters: |
| 192 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 193 |
|
| 194 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 195 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 196 |
|
| 197 |
Example 1.2. is_pure_ip usage |
| 198 |
... |
| 199 |
$var(ip) = "::1"; |
| 200 |
if (is_pure_ip($var(ip))) { |
| 201 |
xlog("L_INFO", "it's IPv4 or IPv6\n"); |
| 202 |
} |
| 203 |
... |
| 204 |
|
| 205 |
4.3. is_ipv4 (ip) |
| 206 |
|
| 207 |
Returns TRUE if the argument is a valid IPv4. FALSE otherwise. |
| 208 |
|
| 209 |
Parameters: |
| 210 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 211 |
|
| 212 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 213 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 214 |
|
| 215 |
Example 1.3. is_ipv4 usage |
| 216 |
... |
| 217 |
if (is_ipv4("1.2.3.4")) { |
| 218 |
xlog("L_INFO", "it's IPv4\n"); |
| 219 |
} |
| 220 |
... |
| 221 |
|
| 222 |
4.4. is_ipv6 (ip) |
| 223 |
|
| 224 |
Returns TRUE if the argument is a valid IPv6. FALSE otherwise. |
| 225 |
|
| 226 |
Parameters: |
| 227 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 228 |
|
| 229 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 230 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 231 |
|
| 232 |
Example 1.4. is_ipv6 usage |
| 233 |
... |
| 234 |
if (is_ipv6("1080:0:0:0:8:800:200C:417A")) { |
| 235 |
xlog("L_INFO", "it's IPv6\n"); |
| 236 |
} |
| 237 |
... |
| 238 |
|
| 239 |
4.5. is_ipv6_reference (ip) |
| 240 |
|
| 241 |
Returns TRUE if the argument is a valid IPv6 reference. FALSE |
| 242 |
otherwise. |
| 243 |
|
| 244 |
Parameters: |
| 245 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 246 |
|
| 247 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 248 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 249 |
|
| 250 |
Example 1.5. is_ipv6_reference usage |
| 251 |
... |
| 252 |
if (is_ipv6_reference("[1080:0:0:0:8:800:200C:417A]")) { |
| 253 |
xlog("L_INFO", "it's IPv6 reference\n"); |
| 254 |
} |
| 255 |
... |
| 256 |
|
| 257 |
4.6. ip_type (ip) |
| 258 |
|
| 259 |
Returns the type of the given IP. |
| 260 |
|
| 261 |
Parameters: |
| 262 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 263 |
|
| 264 |
Return value: |
| 265 |
* 1 - IPv4 |
| 266 |
* 2 - IPv6 |
| 267 |
* 3 - IPv6 reference |
| 268 |
* -1 - invalid IP |
| 269 |
|
| 270 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 271 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 272 |
|
| 273 |
Example 1.6. ip_type usage |
| 274 |
... |
| 275 |
ip_type($var(myip)); |
| 276 |
switch($rc) { |
| 277 |
case 1: |
| 278 |
xlog("L_INFO", "it's IPv4\n"); |
| 279 |
break; |
| 280 |
case 2: |
| 281 |
xlog("L_INFO", "it's IPv6\n"); |
| 282 |
break; |
| 283 |
case 3: |
| 284 |
xlog("L_INFO", "it's IPv6 reference\n"); |
| 285 |
break; |
| 286 |
case -1: |
| 287 |
xlog("L_INFO", it's type invalid\n"); |
| 288 |
break; |
| 289 |
} |
| 290 |
... |
| 291 |
|
| 292 |
4.7. detailed_ip_type (ip, result) |
| 293 |
|
| 294 |
Returns the detailed type of the given IP () (see |
| 295 |
http://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.t |
| 296 |
xt, |
| 297 |
http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-sp |
| 298 |
ecial-registry.txt, RFC 5735 and RFC 6598: PRIVATE, SHARED, LOOPBACK, |
| 299 |
IPV4MAP, DISCARD etc). |
| 300 |
|
| 301 |
Parameters: |
| 302 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 303 |
* result - String or pseudo-variable containing the detailed type of |
| 304 |
the IP. |
| 305 |
+ IPv4 - PUBLIC, RIVATE, SHARED, LOOPBACK, LINK-LOCAL, RESERVED, |
| 306 |
TEST-NET, 6TO4-RELAY, MULTICAST, BROADCAST |
| 307 |
+ IPv6 - UNSPECIFIED, LOOPBACK, IPV4MAP, RESERVED, DISCARD, |
| 308 |
GLOBAL-UNICAST, TEREDO, BMWG, DOCUMENTATION, ORCHID, 6TO4, |
| 309 |
UNIQUE-LOCAL-UNICAST, LINK-LOCAL-UNICAST, MULTICAST |
| 310 |
|
| 311 |
Return value: |
| 312 |
* 1 - successful operation |
| 313 |
* negative value - error occurred |
| 314 |
|
| 315 |
This function can be used from ALL ROUTES |
| 316 |
|
| 317 |
Example 1.7. detailed_ip_type usage |
| 318 |
... |
| 319 |
detailed_ip_type("192.168.1.2","$var(result)"); |
| 320 |
xlog("L_ERR","IP address is of detailed type: $var(result) "); |
| 321 |
... |
| 322 |
|
| 323 |
4.8. detailed_ipv4_type (ip, result) |
| 324 |
|
| 325 |
Returns the detailed type of the given IP () (see RFC 5735 and RFC |
| 326 |
6598). |
| 327 |
|
| 328 |
Parameters: |
| 329 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 330 |
* result - String or pseudo-variable containing the detailed type of |
| 331 |
the IP. |
| 332 |
+ IPv4 - PUBLIC, PRIVATE, SHARED, LOOPBACK, LINK-LOCAL, |
| 333 |
RESERVED, TEST-NET, 6TO4-RELAY, MULTICAST, BROADCAST |
| 334 |
|
| 335 |
Return value: |
| 336 |
* 1 - successful operation |
| 337 |
* negative value - error occurred |
| 338 |
|
| 339 |
This function can be used from ALL ROUTES |
| 340 |
|
| 341 |
Example 1.8. detailed_ipv4_type usage |
| 342 |
... |
| 343 |
detailed_ipv4_type("192.168.1.2","$var(result)"); |
| 344 |
xlog("L_ERR","IP address is of detailed type: $var(result) "); |
| 345 |
... |
| 346 |
|
| 347 |
4.9. detailed_ipv6_type (ip, result) |
| 348 |
|
| 349 |
Returns the detailed type of the given IP () (see |
| 350 |
http://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.t |
| 351 |
xt, |
| 352 |
http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-sp |
| 353 |
ecial-registry.txt). |
| 354 |
|
| 355 |
Parameters: |
| 356 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 357 |
* result - String or pseudo-variable containing the detailed type of |
| 358 |
the IP. |
| 359 |
+ IPv6 - UNSPECIFIED, LOOPBACK, IPV4MAP, RESERVED, DISCARD, |
| 360 |
GLOBAL-UNICAST, TEREDO, BMWG, DOCUMENTATION, ORCHID, 6TO4, |
| 361 |
UNIQUE-LOCAL-UNICAST, LINK-LOCAL-UNICAST, MULTICAST |
| 362 |
|
| 363 |
Return value: |
| 364 |
* 1 - successful operation |
| 365 |
* negative value - error occurred |
| 366 |
|
| 367 |
This function can be used from ALL ROUTES |
| 368 |
|
| 369 |
Example 1.9. detailed_ipv6_type usage |
| 370 |
... |
| 371 |
detailed_ipv6_type("2001:8d8:7c0:402:217:72:194:30","$var(result)"); |
| 372 |
xlog("L_ERR","IP address is of detailed type: $var(result) "); |
| 373 |
|
| 374 |
detailed_ipv6_type("[2001:8d8:7c0:402:217:72:194:30]","$var(result)"); |
| 375 |
xlog("L_ERR","IP address is of detailed type: $var(result) "); |
| 376 |
... |
| 377 |
|
| 378 |
4.10. compare_ips (ip1, ip2) |
| 379 |
|
| 380 |
Returns TRUE if both IP addresses are the same. FALSE otherwise. This |
| 381 |
function also allows comparing an IPv6 address against an IPv6 |
| 382 |
reference. |
| 383 |
|
| 384 |
Parameters: |
| 385 |
* ip1 - String or pseudo-variable containing the first IP to compare. |
| 386 |
* ip2 - String or pseudo-variable containing the second IP to |
| 387 |
compare. |
| 388 |
|
| 389 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 390 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 391 |
|
| 392 |
Example 1.10. compare_ips usage |
| 393 |
... |
| 394 |
if (compare_ips("1080:0000:0000:0000:0008:0800:200C:417A", "[1080::8:800:200C:41 |
| 395 |
7A]")) { |
| 396 |
xlog("L_INFO", "both are the same IP\n"); |
| 397 |
} |
| 398 |
... |
| 399 |
|
| 400 |
4.11. compare_pure_ips (ip1, ip2) |
| 401 |
|
| 402 |
Returns TRUE if both IP's are the same. FALSE otherwise. This function |
| 403 |
does NOT allow comparing an IPv6 against an IPv6 reference. |
| 404 |
|
| 405 |
Parameters: |
| 406 |
* ip1 - String or pseudo-variable containing the first IP address to |
| 407 |
compare. |
| 408 |
* ip2 - String or pseudo-variable containing the second IP address to |
| 409 |
compare. |
| 410 |
|
| 411 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 412 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 413 |
|
| 414 |
Example 1.11. compare_pure_ips usage |
| 415 |
... |
| 416 |
if (compare_pure_ips($si, "1080::8:800:200C:417A")) { |
| 417 |
xlog("L_INFO", "both are the same IP\n"); |
| 418 |
} |
| 419 |
... |
| 420 |
|
| 421 |
4.12. is_ip_rfc1918 (ip) |
| 422 |
|
| 423 |
Returns TRUE if the argument is a private IPv4 according to RFC 1918. |
| 424 |
FALSE otherwise. |
| 425 |
|
| 426 |
Parameters: |
| 427 |
* ip - String or pseudo-variable containing the IP to evaluate. |
| 428 |
|
| 429 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 430 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 431 |
|
| 432 |
Example 1.12. is_ip_rfc1918 usage |
| 433 |
... |
| 434 |
if (is_ip_rfc1918("10.0.123.123")) { |
| 435 |
xlog("L_INFO", "it's a private IPv4\n"); |
| 436 |
} |
| 437 |
... |
| 438 |
|
| 439 |
4.13. is_in_subnet (ip, subnets_list) |
| 440 |
|
| 441 |
Returns TRUE if the first argument is an IP address within the (CIDR |
| 442 |
notation) subnets list in the second argument. FALSE otherwise. |
| 443 |
|
| 444 |
Parameters: |
| 445 |
* ip - string or pseudo-variable containing the ip to evaluate. |
| 446 |
* subnet - string or pseudo-variable containing the (CIDR notation) |
| 447 |
subnets list to evaluate. |
| 448 |
|
| 449 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, |
| 450 |
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE. |
| 451 |
|
| 452 |
Example 1.13. is_in_subnet usage |
| 453 |
... |
| 454 |
if (is_in_subnet("10.0.123.123", "10.0.123.1/24")) { |
| 455 |
xlog("L_INFO", "it's in the subnet\n"); |
| 456 |
} |
| 457 |
... |
| 458 |
if (is_in_subnet("10.0.123.123", "10.0.0.0/16,192.168.0.0/24")) { |
| 459 |
xlog("L_INFO", "it's in the subnets\n"); |
| 460 |
} |
| 461 |
... |
| 462 |
|
| 463 |
4.14. dns_sys_match_ip(hostname, ipaddr) |
| 464 |
|
| 465 |
Returns TRUE if ipaddr is associated by DNS to hostname. FALSE |
| 466 |
otherwise. It does not use the internal DNS resolver, but directly |
| 467 |
getaddrinfo(...). All addresses returned for the hostname are checked. |
| 468 |
Note that some hosts may return different lists of IP addresses for |
| 469 |
each query, if the DNS server is configured in that way (e.g., for |
| 470 |
providing load balancing through DNS). |
| 471 |
|
| 472 |
Parameters: |
| 473 |
* hostname - string or pseudo-variable containing the hostname. The |
| 474 |
resulting IP addresses from DNS query are compared with ipaddr. |
| 475 |
* ipaddr - string or pseudo-variable containing the ip address. |
| 476 |
|
| 477 |
This function can be used from ANY_ROUTE. |
| 478 |
|
| 479 |
Example 1.14. dns_sys_match_ip usage |
| 480 |
... |
| 481 |
if (!dns_sys_match_ip("myhost.com", "1.2.3.4")) { |
| 482 |
xdbg("ip address not associated with hostname\n"); |
| 483 |
} |
| 484 |
... |
| 485 |
|
| 486 |
4.15. dns_int_match_ip(hostname, ipaddr) |
| 487 |
|
| 488 |
Returns TRUE if ipaddr is associated by DNS to hostname. FALSE |
| 489 |
otherwise. It uses internal DNS resolver. At this moment, the function |
| 490 |
might not check all the IP addresses as returned by dns_sys_match_ip(), |
| 491 |
because the internal resolver targets to discover the first address to |
| 492 |
be used for relaying SIP traffic. Thus is better to use |
| 493 |
dns_sys_match_ip() if the host you want to check has many IP addresses, |
| 494 |
in different address families (IPv4/6). |
| 495 |
|
| 496 |
Parameters: |
| 497 |
* hostname - string or pseudo-variable containing the hostname. The |
| 498 |
resulting IP addresses from DNS query are compared with ipaddr. |
| 499 |
* ipaddr - string or pseudo-variable containing the ip address. |
| 500 |
|
| 501 |
This function can be used from ANY_ROUTE. |
| 502 |
|
| 503 |
Example 1.15. dns_int_match_ip usage |
| 504 |
... |
| 505 |
if (!dns_int_match_ip("myhost.com", "1.2.3.4")) { |
| 506 |
xdbg("ip address not associated with hostname\n"); |
| 507 |
} |
| 508 |
... |
| 509 |
|
| 510 |
4.16. dns_query(hostname, pvid) |
| 511 |
|
| 512 |
Store the IP addresses and their type that correspond to hostname in a |
| 513 |
config variable $dns(pvid=>key). |
| 514 |
|
| 515 |
Parameters: |
| 516 |
* hostname - string or pseudo-variable containing the hostname. The |
| 517 |
resulting IP addresses from DNS query are compared with ipaddr. |
| 518 |
* pvid - container id for script variable. |
| 519 |
|
| 520 |
This function can be used from ANY_ROUTE. |
| 521 |
|
| 522 |
Example 1.16. dns_query usage |
| 523 |
... |
| 524 |
if(dns_query("test.com", "xyz")) |
| 525 |
{ |
| 526 |
xlog(" number of addresses: $dns(xyz=>count)\n"); |
| 527 |
xlog(" ipv4 address found: $dns(xyz=>ipv4)\n"); |
| 528 |
xlog(" ipv6 address found: $dns(xyz=>ipv6)\n"); |
| 529 |
$var(i) = 0; |
| 530 |
while($var(i)<$dns(xyz=>count)) { |
| 531 |
xlog(" #[$var(i)] type ($dns(xyz=>type[$var(i)]))" |
| 532 |
" addr [$dns(xyz=>addr[$var(i)])]\n"); |
| 533 |
$var(i) = $var(i) + 1; |
| 534 |
} |
| 535 |
} |
| 536 |
... |
| 537 |
|
| 538 |
4.17. ptr_query(ip, pvid) |
| 539 |
|
| 540 |
Store the hostname that correspond to an IP address (IPv4 or IPv6) in a |
| 541 |
pseudo-variable variable $ptrquery(pvid=>hostname). |
| 542 |
|
| 543 |
Note: Results will be in in $ptrquery(pvid=>key). key can be: |
| 544 |
* addr - IP address |
| 545 |
* type - type of IP address |
| 546 |
* ipv4 - 1 if IPv4 address |
| 547 |
* ipv6 - 1 if IPv6 address |
| 548 |
* count - number of hostnames found |
| 549 |
* hostname - hostname |
| 550 |
|
| 551 |
Parameters: |
| 552 |
* ip - string or pseudo-variable containing the ip. |
| 553 |
* pvid - AVP id for script variable. |
| 554 |
|
| 555 |
This function can be used from ANY_ROUTE. |
| 556 |
|
| 557 |
Example 1.17. ptr_query usage |
| 558 |
... |
| 559 |
if(ptr_query("8.8.8.8","ip4")) |
| 560 |
{ |
| 561 |
xlog(" number of names: $ptrquery(ip4=>count)\n"); |
| 562 |
$var(j) = 0; |
| 563 |
while($var(j)<$ptrquery(ip4=>count)) { |
| 564 |
xlog(" #[$var(j)] name [ $ptrquery(ip4=>hostname) ]\n"); |
| 565 |
$var(j) = $var(j) + 1; |
| 566 |
} |
| 567 |
} |
| 568 |
... |
| 569 |
|
| 570 |
4.18. srv_query(srvcname, pvid) |
| 571 |
|
| 572 |
Queries DNS SRV records to resolve a service/protocol name into a list |
| 573 |
of priorities, weights, ports, and targets sorted by priority and |
| 574 |
weight as outlined in RFC 2782. |
| 575 |
|
| 576 |
Parameters: |
| 577 |
* srvcname - string or pseudo-variable containing the |
| 578 |
service/protocol. For example, "_sip._tcp.example.com". |
| 579 |
* pvid - container id for script variable. |
| 580 |
|
| 581 |
Output: |
| 582 |
|
| 583 |
Returns a positive number indicating success or a negative number when |
| 584 |
an error is encountered. It can be used from ANY_ROUTE. |
| 585 |
|
| 586 |
The $srvquery pseudo-variable (PV) is loaded with the results of the |
| 587 |
query. Multiple queries can be stored in the PV using the pvid key. |
| 588 |
Each query contains zero-indexed arrays sorted by priority and weight |
| 589 |
that contain: |
| 590 |
* count - number of records found |
| 591 |
* port [index] - port number |
| 592 |
* priority [index] - priority number as defined by RFC 2782 |
| 593 |
* target [index] - target host name |
| 594 |
* weight [index] - weight number as defined by RFC 2782 |
| 595 |
|
| 596 |
Example 1.18. srv_query usage |
| 597 |
... |
| 598 |
if (srv_query ("_sip._udp.example.com", "udp") > 0) { |
| 599 |
$var(cnt) = $srvquery(udp=>count); |
| 600 |
$var(i) = 0; |
| 601 |
while ($var(i) < $var(cnt)) { |
| 602 |
xlog ("port[$var(i)] $srvquery(udp=>port[$var(i)])\n"); |
| 603 |
xlog ("priority[$var(i)] $srvquery(udp=>priority[$var(i)])\n"); |
| 604 |
xlog ("target[$var(i)] $srvquery(udp=>target[$var(i)])\n"); |
| 605 |
xlog ("weight[$var(i)] $srvquery(udp=>weight[$var(i)])\n"); |
| 606 |
$var(i) = $var(i) + 1; |
| 607 |
} |
| 608 |
} |
| 609 |
... |
| 610 |
|
| 611 |
4.19. naptr_query(domain, pvid) |
| 612 |
|
| 613 |
Queries DNS NAPTR records to resolve a domain name into a list of |
| 614 |
orders, preferences, flags, services, regex, replaces sorted by orders |
| 615 |
and preferences as outlined in RFC 2915. |
| 616 |
|
| 617 |
Parameters: |
| 618 |
* domain - string or pseudo-variable containing the domain. For |
| 619 |
example, "example.com". |
| 620 |
* pvid - container id for script variable. |
| 621 |
|
| 622 |
Output: |
| 623 |
|
| 624 |
Returns a positive number indicating success or a negative number when |
| 625 |
an error is encountered. It can be used from ANY_ROUTE. |
| 626 |
|
| 627 |
The $naptrquery pseudo-variable (PV) is loaded with the results of the |
| 628 |
query. Multiple queries can be stored in the PV using the pvid key. |
| 629 |
Each query contains zero-indexed arrays sorted by order and preference |
| 630 |
that contain: |
| 631 |
* count - number of records found |
| 632 |
* order [index] - order as defined by RFC 2915 |
| 633 |
* pref [index] - preference as defined by RFC 2915 |
| 634 |
* flags [index] - flags |
| 635 |
* services [index] - services |
| 636 |
* regex [index] - regular expression |
| 637 |
* replace [index] - replace |
| 638 |
|
| 639 |
Example 1.19. naptr_query usage |
| 640 |
... |
| 641 |
if (naptr_query ("example.com", "res") > 0) { |
| 642 |
$var(cnt) = $naptrquery(res=>count); |
| 643 |
$var(i) = 0; |
| 644 |
while ($var(i) < $var(cnt)) { |
| 645 |
xlog ("order[$var(i)] $naptrquery(udp=>order[$var(i)])\n"); |
| 646 |
xlog ("pref[$var(i)] $naptrquery(udp=>pref[$var(i)])\n"); |
| 647 |
xlog ("flags[$var(i)] $naptrquery(udp=>flags[$var(i)])\n"); |
| 648 |
xlog ("services[$var(i)] $naptrquery(udp=>services[$var(i)])\n"); |
| 649 |
xlog ("regex[$var(i)] $naptrquery(udp=>regex[$var(i)])\n"); |
| 650 |
xlog ("replace[$var(i)] $naptrquery(udp=>replace[$var(i)])\n"); |
| 651 |
$var(i) = $var(i) + 1; |
| 652 |
} |
| 653 |
} |
| 654 |
... |
| 655 |
|
| 656 |
4.20. dns_set_local_ttl(vttl) |
| 657 |
|
| 658 |
Set local ttl for DNS query results. If vttl is 0, then the value of |
| 659 |
the result and the core parameters are used. |
| 660 |
|
| 661 |
Parameters: |
| 662 |
* vttl - TTL value in seconds. It can be static integer or a variable |
| 663 |
holding an integer value. |
| 664 |
|
| 665 |
This function can be used from ANY_ROUTE. |
| 666 |
|
| 667 |
Example 1.20. dns_set_local_ttl usage |
| 668 |
... |
| 669 |
dns_set_local_ttl("7200"); |
| 670 |
dns_query("test.com", "xyz") |
| 671 |
dns_set_local_ttl("0"); |
| 672 |
... |