2
0
Daniel-Constantin Mierla 2c290ee296 modules/*: README regenerated for updates to db_url and wiki 12 жил өмнө
..
doc a9ca3f4a05 ipops Minor updates to README 12 жил өмнө
Makefile 5e886dbbef all: OPENSER_MOD_INTERFACE replaced with KAMAILIO_MOD_INTERFACE 13 жил өмнө
README 2c290ee296 modules/*: README regenerated for updates to db_url and wiki 12 жил өмнө
api.c 8ab4daa7f1 modules/ipops: Corrected is_in_subnet() exported function and added is_ip to module C API 13 жил өмнө
api.h 8ab4daa7f1 modules/ipops: Corrected is_in_subnet() exported function and added is_ip to module C API 13 жил өмнө
compile_ip_parser.rl.sh 59403946f9 - new module 'ipops' for operations with IPv4 and IPv6. 14 жил өмнө
compile_rfc1918_parser.rl.sh aa940ed3b5 ipops: Added function is_ip_rfc1918(ip) for detecting private IPv4 according to RFC 1918. 14 жил өмнө
ip_parser.c f369faa6d0 ipops: add a comment about autogenerated files from ragel 14 жил өмнө
ip_parser.h f369faa6d0 ipops: add a comment about autogenerated files from ragel 14 жил өмнө
ip_parser.rl 422f81d42d - ipops module: fix in documentation. 14 жил өмнө
ipops_mod.c 8ab4daa7f1 modules/ipops: Corrected is_in_subnet() exported function and added is_ip to module C API 13 жил өмнө
rfc1918_parser.c aa940ed3b5 ipops: Added function is_ip_rfc1918(ip) for detecting private IPv4 according to RFC 1918. 14 жил өмнө
rfc1918_parser.h aa940ed3b5 ipops: Added function is_ip_rfc1918(ip) for detecting private IPv4 according to RFC 1918. 14 жил өмнө
rfc1918_parser.rl aa940ed3b5 ipops: Added function is_ip_rfc1918(ip) for detecting private IPv4 according to RFC 1918. 14 жил өмнө

README

ipops Module

I�aki Baz Castillo



Edited by

I�aki Baz Castillo



Copyright � 2011 I�aki Baz Castillo
__________________________________________________________________

Table of Contents

1. Admin Guide

1. Overview
2. Dependencies

2.1. SIP Router Modules
2.2. External Libraries or Applications

3. Parameters
4. Functions

4.1. is_ip (ip)
4.2. is_pure_ip (ip)
4.3. is_ipv4 (ip)
4.4. is_ipv6 (ip)
4.5. is_ipv6_reference (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, subnet)

List of Examples

1.1. is_ip usage
1.2. is_pure_ip usage
1.3. is_ipv4 usage
1.4. is_ipv6 usage
1.5. is_ipv6_reference 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

Chapter 1. Admin Guide

Table of Contents

1. Overview
2. Dependencies

2.1. SIP Router Modules
2.2. External Libraries or Applications

3. Parameters
4. Functions

4.1. is_ip (ip)
4.2. is_pure_ip (ip)
4.3. is_ipv4 (ip)
4.4. is_ipv6 (ip)
4.5. is_ipv6_reference (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, subnet)

1. Overview

This module offers operations for handling IP addresses, both IPv4 and
IPv6.

IPv6 is defined in RFC 2460. The same IPv6 address can be represented
by different ASCII strings, so binary comparison is required. For
example, the following IPv6 addresses are equivalent:
* 2001:DB8:0000:0000:0008:0800:200C:417A
* 2001:DB8:0:0:8:800:200C:417A
* 2001:DB8::200C:417A

When using IPv6 in an URI (i.e. a SIP URI) the IP address must be
written in "IPv6 reference" format (which is the textual representation
of the IPv6 enclosed between [ ] symbols). An example is
"sip:alice@[2001:DB8:0:0:8:800:200C:417A]". This allows separation of
address and port number with a :, like
"[2001:DB8:0:0:8:800:200C:417A]:5060". This module also allows
comparing an IPv6 address with its IPv6 reference representation.

2. Dependencies

2.1. SIP Router Modules
2.2. External Libraries or Applications

2.1. SIP Router Modules

The following modules must be loaded before this module:
* No dependencies on other SIP Router modules

2.2. External Libraries or Applications

The following libraries or applications must be installed before
running SIP Router with this module loaded:
* No dependencies on external libraries

3. Parameters

4. Functions

4.1. is_ip (ip)
4.2. is_pure_ip (ip)
4.3. is_ipv4 (ip)
4.4. is_ipv6 (ip)
4.5. is_ipv6_reference (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, subnet)

4.1. is_ip (ip)

Returns TRUE if the argument is a valid IPv4, IPv6 or IPv6 reference.
FALSE otherwise.

Parameters:
* ip - String or pseudo-variable containing the IP address to
evaluate.

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.

Example 1.1. is_ip usage
...
if (is_ip($rd)) {
xlog("L_INFO", "RURI domain is an IP address (not a host name/domain)\n");
}
...

4.2. is_pure_ip (ip)

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");
}
...

4.3. is_ipv4 (ip)

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.

Example 1.3. is_ipv4 usage
...
if (is_ipv4("1.2.3.4")) {
xlog("L_INFO", "it's IPv4\n");
}
...

4.4. is_ipv6 (ip)

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");
}
...

4.5. is_ipv6_reference (ip)

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");
}
...

4.6. ip_type (ip)

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;
}
...

4.7. compare_ips (ip1, ip2)

Returns TRUE if both IP addresses are the same. FALSE otherwise. This
function also allows comparing an IPv6 address 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:41
7A]")) {
xlog("L_INFO", "both are the same IP\n");
}
...

4.8. compare_pure_ips (ip1, ip2)

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 address to
compare.
* ip2 - String or pseudo-variable containing the second IP address 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");
}
...

4.9. is_ip_rfc1918 (ip)

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");
}
...

4.10. is_in_subnet (ip, subnet)

Returns TRUE if the first argument is an IP address within the (CIDR
notation) subnet in the second argument. FALSE otherwise.

Parameters:
* ip - string or pseudo-variable containing the ip to evaluate.
* subnet - string or pseudo-variable containing the (CIDR notation)
subnet to evaluate.

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.

Example 1.10. is_in_subnet usage
...
if (is_in_subnet("10.0.123.123", "10.0.123.1/24")) {
xlog("L_INFO", "it's in the subnet\n");
}
...