File: README

package info (click to toggle)
kamailio 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 56,100 kB
  • sloc: ansic: 552,832; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (418 lines) | stat: -rw-r--r-- 11,480 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
ipops Module

Iaki Baz Castillo

   <ibc@aliax.net>

Edited by

Iaki Baz Castillo

   <ibc@aliax.net>

   Copyright  2011 Iaki 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)
              4.11. dns_sys_match_ip(hostname, ipaddr)
              4.12. dns_int_match_ip(hostname, ipaddr)
              4.13. dns_query(hostname, pvid)

   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
   1.11. dns_sys_match_ip usage
   1.12. dns_int_match_ip usage
   1.13. dns_query 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)
        4.11. dns_sys_match_ip(hostname, ipaddr)
        4.12. dns_int_match_ip(hostname, ipaddr)
        4.13. dns_query(hostname, pvid)

1. Overview

   The IPops 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.11. dns_sys_match_ip(hostname, ipaddr)
   4.12. dns_int_match_ip(hostname, ipaddr)
   4.13. dns_query(hostname, pvid)

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

4.11. dns_sys_match_ip(hostname, ipaddr)

   Returns TRUE if ipaddr is associated by DNS to hostname. FALSE
   otherwise. It does not use the internal DNS resolver, but directly
   getaddrinfo(...). All addresses returned for the hostname are checked.
   Note that some hosts may return different lists of IP addresses for
   each query, if the DNS server is configured in that way (e.g., for
   providing load balancing through DNS).

   Parameters:
     * hostname - string or pseudo-variable containing the hostname. The
       resulting IP addresses from DNS query are compared with ipaddr.
     * ipaddr - string or pseudo-variable containing the ip address.

   This function can be used from ANY_ROUTE.

   Example 1.11. dns_sys_match_ip usage
...
if (!dns_sys_match_ip("myhost.com", "1.2.3.4")) {
    xdbg("ip address not associated with hostname\n");
}
...

4.12. dns_int_match_ip(hostname, ipaddr)

   Returns TRUE if ipaddr is associated by DNS to hostname. FALSE
   otherwise. It uses internal DNS resolver. At this moment, the function
   might not check all the IP addresses as returned by dns_sys_match_ip(),
   because the internal resolver targets to discover the first address to
   be used for relaying SIP traffic. Thus is better to use
   dns_sys_match_ip() if the host you want to check has many IP addresses,
   in different address famililies (IPv4/6).

   Parameters:
     * hostname - string or pseudo-variable containing the hostname. The
       resulting IP addresses from DNS query are compared with ipaddr.
     * ipaddr - string or pseudo-variable containing the ip address.

   This function can be used from ANY_ROUTE.

   Example 1.12. dns_int_match_ip usage
...
if (!dns_int_match_ip("myhost.com", "1.2.3.4")) {
    xdbg("ip address not associated with hostname\n");
}
...

4.13. dns_query(hostname, pvid)

   Store the IP addresses and their type that correspond to hostname in a
   config variable $dns(pvid=>key).

   Parameters:
     * hostname - string or pseudo-variable containing the hostname. The
       resulting IP addresses from DNS query are compared with ipaddr.
     * pvid - container id for script variable.

   This function can be used from ANY_ROUTE.

   Example 1.13. dns_query usage
...
if(dns_query("test.com", "xyz"))
{
    xlog(" number of addresses: $dns(xyz=>count)\n");
    xlog(" ipv4 address found: $dns(xyz=>ipv4)\n");
    xlog(" ipv6 address found: $dns(xyz=>ipv6)\n");
    $var(i) = 0;
    while($var(i)<$dns(xyz=>count)) {
        xlog(" #[$var(i)] type ($dns(xyz=>type[$var(i)]))"
             " addr [$dns(xyz=>addr[$var(i)])]\n");
        $var(i) = $var(i) + 1;
    }
}
...