File: ipops_admin.xml

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 (685 lines) | stat: -rw-r--r-- 18,002 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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
%docentities;
 
]>

<!-- Module User's Guide -->
     
<chapter>

  <title>&adminguide;</title>
       
  <section>
         
    <title>Overview</title>
         
    <para>
      The IPops module offers operations for handling IP addresses, both IPv4 and IPv6.
    </para>
    <para>
      IPv6 is defined in <ulink url="http://tools.ietf.org/html/rfc2460">RFC 2460</ulink>.
	The same IPv6 address can be represented by different ASCII strings, so binary comparison is required.
	For example, the following IPv6 addresses are equivalent:
    </para>

    <itemizedlist>
      <listitem>
        <para>2001:DB8:0000:0000:0008:0800:200C:417A</para>
      </listitem>
      <listitem>
        <para>2001:DB8:0:0:8:800:200C:417A</para>
      </listitem>
      <listitem>
        <para>2001:DB8::200C:417A</para>
      </listitem>
    </itemizedlist>

    <para>
      	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 <quote>sip:alice@[2001:DB8:0:0:8:800:200C:417A]</quote>. This allows separation of
	address and port number with a :, like <quote>[2001:DB8:0:0:8:800:200C:417A]:5060</quote>.
	This module also allows comparing an IPv6 address with its IPv6 reference representation.
    </para>
           
  </section>
           
  <section>
             
    <title>Dependencies</title>
             
    <section>
      <title>&siprouter; Modules</title>
      <para>
        The following modules must be loaded before this module:
        <itemizedlist>
          <listitem>
            <para>
              <emphasis>No dependencies on other &siprouter; modules</emphasis>
            </para>
          </listitem>
        </itemizedlist>
      </para>
    </section>
               
    <section>
      <title>External Libraries or Applications</title>
      <para>
        The following libraries or applications must be installed before running &siprouter; with this module loaded:
        <itemizedlist>
          <listitem>
            <para>
              <emphasis>No dependencies on external libraries</emphasis>
            </para>
          </listitem>
        </itemizedlist>
      </para>
    </section>
             
  </section>
           
  <section>

    <title>Parameters</title>
             
  </section>
           
  <section>

    <title>Functions</title>
             
    <section id="ipops.f.is_ip">
      <title>
        <function moreinfo="none">is_ip (ip)</function>
      </title>

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

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP address to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_ip</function> usage
        </title>
        <programlisting format="linespecific">
...
if (is_ip($rd)) {
  xlog("L_INFO", "RURI domain is an IP address (not a host name/domain)\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.is_pur_ip">
      <title>
        <function moreinfo="none">is_pure_ip (ip)</function>
      </title>

      <para>
        Returns TRUE if the argument is a valid IPv4 or IPv6. FALSE otherwise.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_pure_ip</function> usage
        </title>
        <programlisting format="linespecific">
...
$var(ip) = "::1";
if (is_pure_ip($var(ip))) {
  xlog("L_INFO", "it's IPv4 or IPv6\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.is_ipv4">
      <title>
        <function moreinfo="none">is_ipv4 (ip)</function>
      </title>

      <para>
        Returns TRUE if the argument is a valid IPv4. FALSE otherwise.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_ipv4</function> usage
        </title>
        <programlisting format="linespecific">
...
if (is_ipv4("1.2.3.4")) {
  xlog("L_INFO", "it's IPv4\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.is_ipv6">
      <title>
        <function moreinfo="none">is_ipv6 (ip)</function>
      </title>

      <para>
        Returns TRUE if the argument is a valid IPv6. FALSE otherwise.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_ipv6</function> usage
        </title>
        <programlisting format="linespecific">
...
if (is_ipv6("1080:0:0:0:8:800:200C:417A")) {
  xlog("L_INFO", "it's IPv6\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.is_ipv6_reference">
      <title>
        <function moreinfo="none">is_ipv6_reference (ip)</function>
      </title>

      <para>
        Returns TRUE if the argument is a valid IPv6 reference. FALSE otherwise.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_ipv6_reference</function> usage
        </title>
        <programlisting format="linespecific">
...
if (is_ipv6_reference("[1080:0:0:0:8:800:200C:417A]")) {
  xlog("L_INFO", "it's IPv6 reference\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.is_ip_type">
      <title>
        <function moreinfo="none">ip_type (ip)</function>
      </title>

      <para>
        Returns the type of the given IP.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>Return value:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>1</emphasis> - IPv4
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>2</emphasis> - IPv6
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>3</emphasis> - IPv6 reference
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>-1</emphasis> - invalid IP
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>ip_type</function> usage
        </title>
        <programlisting format="linespecific">
...
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;
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.compare_ips">
      <title>
        <function moreinfo="none">compare_ips (ip1, ip2)</function>
      </title>

      <para>
        Returns TRUE if both IP addresses are the same. FALSE otherwise.
	This function also allows comparing an IPv6 address against an IPv6 reference.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip1</emphasis> - String or pseudo-variable containing the first IP to compare.
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>ip2</emphasis> - String or pseudo-variable containing the second IP to compare.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>compare_ips</function> usage
        </title>
        <programlisting format="linespecific">
...
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");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.compare_pure_ips">
      <title>
        <function moreinfo="none">compare_pure_ips (ip1, ip2)</function>
      </title>

      <para>
        Returns TRUE if both IP's are the same. FALSE otherwise. This function does NOT 
	allow comparing an IPv6 against an IPv6 reference.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip1</emphasis> - String or pseudo-variable containing the first IP address to compare.
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>ip2</emphasis> - String or pseudo-variable containing the second IP address to compare.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>compare_pure_ips</function> usage
        </title>
        <programlisting format="linespecific">
...
if (compare_pure_ips($si, "1080::8:800:200C:417A")) {
  xlog("L_INFO", "both are the same IP\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.is_ip_rfc1918">
      <title>
        <function moreinfo="none">is_ip_rfc1918 (ip)</function>
      </title>

      <para>
        Returns TRUE if the argument is a private IPv4 according to RFC 1918. FALSE otherwise.
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - String or pseudo-variable containing the IP to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_ip_rfc1918</function> usage
        </title>
        <programlisting format="linespecific">
...
if (is_ip_rfc1918("10.0.123.123")) {
  xlog("L_INFO", "it's a private IPv4\n");
}
...
        </programlisting>
      </example>

    </section>
 
    <section id="ipops.f.is_in_subnet">
      <title>
        <function moreinfo="none">is_in_subnet (ip, subnet)</function>
      </title>

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

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
            <emphasis>ip</emphasis> - string or pseudo-variable containing the ip to evaluate.
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>subnet</emphasis> - string or pseudo-variable containing the (CIDR notation) subnet to evaluate.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.
      </para>

      <example>
        <title>
          <function>is_in_subnet</function> usage
        </title>
        <programlisting format="linespecific">
...
if (is_in_subnet("10.0.123.123", "10.0.123.1/24")) {
  xlog("L_INFO", "it's in the subnet\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.dns_sys_match_ip">
      <title>
        <function moreinfo="none">dns_sys_match_ip(hostname, ipaddr)</function>
      </title>

      <para>
		  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).
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
			  <emphasis>hostname</emphasis> - string or pseudo-variable containing the hostname.
			  The resulting IP addresses from DNS query are compared with ipaddr.
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>ipaddr</emphasis> - string or pseudo-variable containing the ip address.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from ANY_ROUTE.
      </para>

      <example>
        <title>
          <function>dns_sys_match_ip</function> usage
        </title>
        <programlisting format="linespecific">
...
if (!dns_sys_match_ip("myhost.com", "1.2.3.4")) {
    xdbg("ip address not associated with hostname\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.dns_int_match_ip">
      <title>
        <function moreinfo="none">dns_int_match_ip(hostname, ipaddr)</function>
      </title>

      <para>
		  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).
      </para>

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
			  <emphasis>hostname</emphasis> - string or pseudo-variable containing the hostname.
			  The resulting IP addresses from DNS query are compared with ipaddr.
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>ipaddr</emphasis> - string or pseudo-variable containing the ip address.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from ANY_ROUTE.
      </para>

      <example>
        <title>
          <function>dns_int_match_ip</function> usage
        </title>
        <programlisting format="linespecific">
...
if (!dns_int_match_ip("myhost.com", "1.2.3.4")) {
    xdbg("ip address not associated with hostname\n");
}
...
        </programlisting>
      </example>

    </section>

    <section id="ipops.f.dns_query">
      <title>
        <function moreinfo="none">dns_query(hostname, pvid)</function>
      </title>

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

      <para>Parameters:</para>

      <itemizedlist>
        <listitem>
          <para>
			  <emphasis>hostname</emphasis> - string or pseudo-variable containing the hostname.
			  The resulting IP addresses from DNS query are compared with ipaddr.
          </para>
        </listitem>
        <listitem>
          <para>
            <emphasis>pvid</emphasis> - container id for script variable.
          </para>
        </listitem>
      </itemizedlist>

      <para>
        This function can be used from ANY_ROUTE.
      </para>

      <example>
        <title>
          <function>dns_query</function> usage
        </title>
        <programlisting format="linespecific">
...
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)&lt;$dns(xyz=>count)) {
        xlog(" #[$var(i)] type ($dns(xyz=>type[$var(i)]))"
             " addr [$dns(xyz=>addr[$var(i)])]\n");
        $var(i) = $var(i) + 1;
    }
}
...
        </programlisting>
      </example>

    </section>

  </section>
 
</chapter>