Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / documentation / api / modules / luci.ip.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html>
4 <head>
5     <title>Reference</title>
6     <link rel="stylesheet" href="../luadoc.css" type="text/css" />
7         <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
8 </head>
9
10 <body>
11 <div id="container">
12
13 <div id="product">
14         <div id="product_logo"></div>
15         <div id="product_name"><big><b></b></big></div>
16         <div id="product_description"></div>
17 </div> <!-- id="product" -->
18
19 <div id="main">
20
21 <div id="navigation">
22
23
24 <h1>LuaDoc</h1>
25 <ul>
26         
27         <li><a href="../index.html">Index</a></li>
28         
29 </ul>
30
31
32 <!-- Module list -->
33
34 <h1>Modules</h1>
35 <ul>
36
37         <li>
38                 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
39         </li>
40
41         <li>
42                 <a href="../modules/luci.http.html">luci.http</a>
43         </li>
44
45         <li>
46                 <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
47         </li>
48
49         <li>
50                 <a href="../modules/luci.http.date.html">luci.http.date</a>
51         </li>
52
53         <li>
54                 <a href="../modules/luci.http.mime.html">luci.http.mime</a>
55         </li>
56
57         <li>
58                 <a href="../modules/luci.i18n.html">luci.i18n</a>
59         </li>
60
61         <li><strong>luci.ip</strong></li>
62         
63         <li>
64                 <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
65         </li>
66
67         <li>
68                 <a href="../modules/luci.json.html">luci.json</a>
69         </li>
70
71         <li>
72                 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
73         </li>
74
75         <li>
76                 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
77         </li>
78
79         <li>
80                 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
81         </li>
82
83         <li>
84                 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
85         </li>
86
87         <li>
88                 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
89         </li>
90
91         <li>
92                 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
93         </li>
94
95         <li>
96                 <a href="../modules/luci.sys.html">luci.sys</a>
97         </li>
98
99         <li>
100                 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
101         </li>
102
103         <li>
104                 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
105         </li>
106
107         <li>
108                 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
109         </li>
110
111         <li>
112                 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
113         </li>
114
115         <li>
116                 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
117         </li>
118
119         <li>
120                 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
121         </li>
122
123         <li>
124                 <a href="../modules/luci.util.html">luci.util</a>
125         </li>
126
127         <li>
128                 <a href="../modules/nixio.html">nixio</a>
129         </li>
130
131         <li>
132                 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
133         </li>
134
135         <li>
136                 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
137         </li>
138
139         <li>
140                 <a href="../modules/nixio.File.html">nixio.File</a>
141         </li>
142
143         <li>
144                 <a href="../modules/nixio.README.html">nixio.README</a>
145         </li>
146
147         <li>
148                 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
149         </li>
150
151         <li>
152                 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
153         </li>
154
155         <li>
156                 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
157         </li>
158
159         <li>
160                 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
161         </li>
162
163         <li>
164                 <a href="../modules/nixio.bin.html">nixio.bin</a>
165         </li>
166
167         <li>
168                 <a href="../modules/nixio.bit.html">nixio.bit</a>
169         </li>
170
171         <li>
172                 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
173         </li>
174
175         <li>
176                 <a href="../modules/nixio.fs.html">nixio.fs</a>
177         </li>
178
179 </ul>
180
181
182
183 <!-- File list -->
184
185
186
187
188
189
190
191 </div><!-- id="navigation" -->
192
193 <div id="content">
194
195 <h1>Class <code>luci.ip</code></h1>
196
197 <p>
198  LuCI IP calculation and netlink access library.</p>
199
200
201
202
203
204
205
206 <h2>Functions</h2>
207 <table class="function_list">
208
209         <tr>
210         <td class="name" nowrap><a href="#new">new</a>&nbsp;(address, netmask)</td>
211         <td class="summary">
212  
213 Construct a new luci.ip.cidr instance and autodetect the address family.</td>
214         </tr>
215
216         <tr>
217         <td class="name" nowrap><a href="#IPv4">IPv4</a>&nbsp;(address, netmask)</td>
218         <td class="summary">
219  
220 Construct a new IPv4 luci.ip.cidr instance.</td>
221         </tr>
222
223         <tr>
224         <td class="name" nowrap><a href="#IPv6">IPv6</a>&nbsp;(address, netmask)</td>
225         <td class="summary">
226  
227 Construct a new IPv6 luci.ip.cidr instance.</td>
228         </tr>
229
230         <tr>
231         <td class="name" nowrap><a href="#MAC">MAC</a>&nbsp;(address, netmask)</td>
232         <td class="summary">
233  
234 Construct a new MAC luci.ip.cidr instance.</td>
235         </tr>
236
237         <tr>
238         <td class="name" nowrap><a href="#checkip4">checkip4</a>&nbsp;(address)</td>
239         <td class="summary">
240  
241 Verify an IPv4 address.</td>
242         </tr>
243
244         <tr>
245         <td class="name" nowrap><a href="#checkip6">checkip6</a>&nbsp;(address)</td>
246         <td class="summary">
247  
248 Verify an IPv6 address.</td>
249         </tr>
250
251         <tr>
252         <td class="name" nowrap><a href="#checkmac">checkmac</a>&nbsp;(address)</td>
253         <td class="summary">
254  
255 Verify an ethernet MAC address.</td>
256         </tr>
257
258         <tr>
259         <td class="name" nowrap><a href="#route">route</a>&nbsp;(address)</td>
260         <td class="summary">
261  
262 Determine the route leading to the given destination.</td>
263         </tr>
264
265         <tr>
266         <td class="name" nowrap><a href="#routes">routes</a>&nbsp;(filter, callback)</td>
267         <td class="summary">
268  
269 Fetch all routes, optionally matching the given criteria.</td>
270         </tr>
271
272         <tr>
273         <td class="name" nowrap><a href="#neighbors">neighbors</a>&nbsp;(filter, callback)</td>
274         <td class="summary">
275  
276 Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table </td>
277         </tr>
278
279         <tr>
280         <td class="name" nowrap><a href="#link">link</a>&nbsp;(device)</td>
281         <td class="summary">
282  
283 Fetch basic device information </td>
284         </tr>
285
286 </table>
287
288
289
290
291
292
293 <br/>
294 <br/>
295
296
297 <h2><a name="functions"></a>Functions</h2>
298 <dl class="function">
299
300
301
302 <dt><a name="new"></a><strong>new</strong>&nbsp;(address, netmask)</dt>
303 <dd>
304
305  
306 Construct a new luci.ip.cidr instance and autodetect the address family. 
307 Throws an error if the given strings do not represent a valid address or 
308 if the given optional netmask is of a different family.
309
310
311 <h3>Parameters</h3>
312 <ul>
313         
314         <li>
315           address: String containing a valid IPv4 or IPv6 address, optionally 
316 with prefix size (CIDR notation) or netmask separated by slash.
317         </li>
318         
319         <li>
320           netmask: String containing a valid IPv4 or IPv6 netmask or number 
321 containing a prefix size in bits (<code>0..32</code> for IPv4, 
322 <code>0..128</code> for IPv6). Overrides mask embedded in the first argument 
323 if specified. (optional)
324         </li>
325         
326 </ul>
327
328
329
330
331 <h3>Usage:</h3>
332 <pre>addr = luci.ip.new("10.24.0.1/24") 
333 addr = luci.ip.new("10.24.0.1/255.255.255.0") 
334 addr = luci.ip.new("10.24.0.1", "255.255.255.0")        -- separate netmask 
335 addr = luci.ip.new("10.24.0.1/24", 16)                  -- override netmask 
336  
337 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64") 
338 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::") 
339 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::") 
340 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
341
342
343
344 <h3>Return value:</h3>
345 A <code>luci.ip.cidr</code> object representing the given 
346 address/mask range.
347
348
349
350 <h3>See also:</h3>
351 <ul>
352         
353         <li><a href="#IPv4">
354                 IPv4
355         </a>
356         
357         <li><a href="#IPv6">
358                 IPv6
359         </a>
360         
361         <li><a href="#MAC">
362                 MAC
363         </a>
364         
365 </ul>
366
367 </dd>
368
369
370
371
372 <dt><a name="IPv4"></a><strong>IPv4</strong>&nbsp;(address, netmask)</dt>
373 <dd>
374
375  
376 Construct a new IPv4 luci.ip.cidr instance. 
377 Throws an error if the given string does not represent a valid IPv4 address or 
378 if the given optional netmask is of a different family.
379
380
381 <h3>Parameters</h3>
382 <ul>
383         
384         <li>
385           address: String containing a valid IPv4, optionally with prefix size 
386 (CIDR notation) or netmask separated by slash.
387         </li>
388         
389         <li>
390           netmask: String containing a valid IPv4 netmask or number 
391 containing a prefix size between <code>0</code> and <code>32</code> bit. 
392 Overrides mask embedded in the first argument if specified. (optional)
393         </li>
394         
395 </ul>
396
397
398
399
400 <h3>Usage:</h3>
401 <pre>addr = luci.ip.IPv4("10.24.0.1/24") 
402 addr = luci.ip.IPv4("10.24.0.1/255.255.255.0") 
403 addr = luci.ip.IPv4("10.24.0.1", "255.255.255.0")        -- separate netmask 
404 addr = luci.ip.IPv4("10.24.0.1/24", 16)                  -- override netmask</pre>
405
406
407
408 <h3>Return value:</h3>
409 A <code>luci.ip.cidr</code> object representing the given IPv4 range.
410
411
412
413 <h3>See also:</h3>
414 <ul>
415         
416         <li><a href="#IPv6">
417                 IPv6
418         </a>
419         
420         <li><a href="#MAC">
421                 MAC
422         </a>
423         
424 </ul>
425
426 </dd>
427
428
429
430
431 <dt><a name="IPv6"></a><strong>IPv6</strong>&nbsp;(address, netmask)</dt>
432 <dd>
433
434  
435 Construct a new IPv6 luci.ip.cidr instance. 
436 Throws an error if the given string does not represent a valid IPv6 address or 
437 if the given optional netmask is of a different family.
438
439
440 <h3>Parameters</h3>
441 <ul>
442         
443         <li>
444           address: String containing a valid IPv6, optionally with prefix size 
445 (CIDR notation) or netmask separated by slash.
446         </li>
447         
448         <li>
449           netmask: String containing a valid IPv4 netmask or number 
450 containing a prefix size between <code>0</code> and <code>128</code> bit. 
451 Overrides mask embedded in the first argument if specified. (optional)
452         </li>
453         
454 </ul>
455
456
457
458
459 <h3>Usage:</h3>
460 <pre>addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64") 
461 addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::") 
462 addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::") 
463 addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
464
465
466
467 <h3>Return value:</h3>
468 A <code>luci.ip.cidr</code> object representing the given IPv6 range.
469
470
471
472 <h3>See also:</h3>
473 <ul>
474         
475         <li><a href="#IPv4">
476                 IPv4
477         </a>
478         
479         <li><a href="#MAC">
480                 MAC
481         </a>
482         
483 </ul>
484
485 </dd>
486
487
488
489
490 <dt><a name="MAC"></a><strong>MAC</strong>&nbsp;(address, netmask)</dt>
491 <dd>
492
493  
494 Construct a new MAC luci.ip.cidr instance. 
495 Throws an error if the given string does not represent a valid ethernet MAC 
496 address or if the given optional mask is of a different family.
497
498
499 <h3>Parameters</h3>
500 <ul>
501         
502         <li>
503           address: String containing a valid ethernet MAC address, optionally with 
504 prefix size (CIDR notation) or mask separated by slash.
505         </li>
506         
507         <li>
508           netmask: String containing a valid MAC address mask or number 
509 containing a prefix size between <code>0</code> and <code>48</code> bit. 
510 Overrides mask embedded in the first argument if specified. (optional)
511         </li>
512         
513 </ul>
514
515
516
517
518 <h3>Usage:</h3>
519 <pre>intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24") 
520 intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/FF:FF:FF:0:0:0") 
521 intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00", "FF:FF:FF:0:0:0") 
522 intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24", 48) -- override mask</pre>
523
524
525
526 <h3>Return value:</h3>
527 A <code>luci.ip.cidr</code> object representing the given MAC address range.
528
529
530
531 <h3>See also:</h3>
532 <ul>
533         
534         <li><a href="#IPv4">
535                 IPv4
536         </a>
537         
538         <li><a href="#IPv6">
539                 IPv6
540         </a>
541         
542 </ul>
543
544 </dd>
545
546
547
548
549 <dt><a name="checkip4"></a><strong>checkip4</strong>&nbsp;(address)</dt>
550 <dd>
551
552  
553 Verify an IPv4 address. 
554  
555 Checks whether given argument is a preexisting luci.ip.cidr IPv4 address 
556 instance or a string literal convertible to an IPv4 address and returns a 
557 plain Lua string containing the canonical representation of the address. 
558  
559 If the argument is not a valid address, returns nothing. This function is 
560 intended to aid in safely verifying address literals without having to deal 
561 with exceptions.
562
563
564 <h3>Parameters</h3>
565 <ul>
566         
567         <li>
568           address: String containing a valid IPv4 address or existing 
569 luci.ip.cidr IPv4 instance.
570         </li>
571         
572 </ul>
573
574
575
576
577 <h3>Usage:</h3>
578 <pre>ipv4 = luci.ip.checkip4(luci.ip.new("127.0.0.1"))  -- "127.0.0.1" 
579 ipv4 = luci.ip.checkip4("127.0.0.1")               -- "127.0.0.1" 
580 ipv4 = luci.ip.checkip4("nonesense")               -- nothing 
581 ipv4 = luci.ip.checkip4(123)                       -- nothing 
582 ipv4 = luci.ip.checkip4(nil)                       -- nothing 
583 ipv4 = luci.ip.checkip4()                          -- nothing</pre>
584
585
586
587 <h3>Return value:</h3>
588 A string representing the given IPv4 address.
589
590
591
592 <h3>See also:</h3>
593 <ul>
594         
595         <li><a href="#checkip6">
596                 checkip6
597         </a>
598         
599         <li><a href="#checkmac">
600                 checkmac
601         </a>
602         
603 </ul>
604
605 </dd>
606
607
608
609
610 <dt><a name="checkip6"></a><strong>checkip6</strong>&nbsp;(address)</dt>
611 <dd>
612
613  
614 Verify an IPv6 address. 
615  
616 Checks whether given argument is a preexisting luci.ip.cidr IPv6 address 
617 instance or a string literal convertible to an IPv6 address and returns a 
618 plain Lua string containing the canonical representation of the address. 
619  
620 If the argument is not a valid address, returns nothing. This function is 
621 intended to aid in safely verifying address literals without having to deal 
622 with exceptions.
623
624
625 <h3>Parameters</h3>
626 <ul>
627         
628         <li>
629           address: String containing a valid IPv6 address or existing 
630 luci.ip.cidr IPv6 instance.
631         </li>
632         
633 </ul>
634
635
636
637
638 <h3>Usage:</h3>
639 <pre>ipv6 = luci.ip.checkip6(luci.ip.new("0:0:0:0:0:0:0:1"))  -- "::1" 
640 ipv6 = luci.ip.checkip6("0:0:0:0:0:0:0:1")               -- "::1" 
641 ipv6 = luci.ip.checkip6("nonesense")                     -- nothing 
642 ipv6 = luci.ip.checkip6(123)                             -- nothing 
643 ipv6 = luci.ip.checkip6(nil)                             -- nothing 
644 ipv6 = luci.ip.checkip6()                                -- nothing</pre>
645
646
647
648 <h3>Return value:</h3>
649 A string representing the given IPv6 address.
650
651
652
653 <h3>See also:</h3>
654 <ul>
655         
656         <li><a href="#checkip4">
657                 checkip4
658         </a>
659         
660         <li><a href="#checkmac">
661                 checkmac
662         </a>
663         
664 </ul>
665
666 </dd>
667
668
669
670
671 <dt><a name="checkmac"></a><strong>checkmac</strong>&nbsp;(address)</dt>
672 <dd>
673
674  
675 Verify an ethernet MAC address. 
676  
677 Checks whether given argument is a preexisting luci.ip.cidr MAC address 
678 instance or a string literal convertible to an ethernet MAC and returns a 
679 plain Lua string containing the canonical representation of the address. 
680  
681 If the argument is not a valid address, returns nothing. This function is 
682 intended to aid in safely verifying address literals without having to deal 
683 with exceptions.
684
685
686 <h3>Parameters</h3>
687 <ul>
688         
689         <li>
690           address: String containing a valid MAC address or existing luci.ip.cidr 
691 MAC address instance.
692         </li>
693         
694 </ul>
695
696
697
698
699 <h3>Usage:</h3>
700 <pre>mac = luci.ip.checkmac(luci.ip.new("00-11-22-cc-dd-ee"))  -- "00:11:22:CC:DD:EE" 
701 mac = luci.ip.checkmac("00:11:22:cc:dd:ee")               -- "00:11:22:CC:DD:EE" 
702 mac = luci.ip.checkmac("nonesense")                       -- nothing 
703 mac = luci.ip.checkmac(123)                               -- nothing 
704 mac = luci.ip.checkmac(nil)                               -- nothing 
705 mac = luci.ip.checkmac()                                  -- nothing</pre>
706
707
708
709 <h3>Return value:</h3>
710 A string representing the given MAC address.
711
712
713
714 <h3>See also:</h3>
715 <ul>
716         
717         <li><a href="#checkip4">
718                 checkip4
719         </a>
720         
721         <li><a href="#checkip6">
722                 checkip6
723         </a>
724         
725 </ul>
726
727 </dd>
728
729
730
731
732 <dt><a name="route"></a><strong>route</strong>&nbsp;(address)</dt>
733 <dd>
734
735  
736 Determine the route leading to the given destination.
737
738
739 <h3>Parameters</h3>
740 <ul>
741         
742         <li>
743           address: A <code>luci.ip.cidr</code> instance or a string containing 
744 a valid IPv4 or IPv6 range as specified by <code>luci.ip.new()</code>.
745         </li>
746         
747 </ul>
748
749
750
751
752 <h3>Usage:</h3>
753 <ul> 
754 <li>Find default gateway by getting route to Google's public NS server 
755 <pre>rt = luci.ip.route("8.8.8.8") 
756 if rt ~= nil then 
757         print("gateway is", rt.gw) 
758 end</pre></li> 
759 <li>Determine IPv6 upstream interface <pre>rt = luci.ip.route("2001::/7") 
760 if rt ~= nil then 
761         print("ipv6 upstream device is", rt.dev) 
762 end</pre></li> 
763 </ul>
764
765
766
767 <h3>Return value:</h3>
768 <p>Table containing the fields described below.</p> 
769 <table id="routetable"> 
770 <tr><th>Field</th><th>Description</th></tr> 
771 <tr><td><code>type</code><td> 
772   <p>Route type with one of the following numeric values:</p> 
773   <table> 
774   <tr> 
775         <td><code>1</code></td> 
776         <td><code>RTN_UNICAST</code> - Gateway or direct route</td> 
777   </tr> 
778   <tr> 
779         <td><code>2</code></td> 
780         <td><code>RTN_LOCAL</code> - Accept locally</td> 
781   </tr> 
782   <tr> 
783         <td><code>3</code></td> 
784         <td><code>RTN_BROADCAST</code> - 
785             Accept locally as broadcast send as broadcast</td> 
786   </tr> 
787   <tr> 
788         <td><code>4</code></td> 
789         <td><code>RTN_ANYCAST</code> - 
790         Accept locally as broadcast but send as unicast</td> 
791   </tr> 
792   <tr> 
793         <td><code>5</code></td> 
794         <td><code>RTN_MULTICAST</code> - Multicast route</td> 
795   </tr> 
796   </table> 
797 </td></tr> 
798 <tr> 
799   <td><code>family</code></td> 
800   <td>Number containing the route family, <code>4</code> for IPv4 or 
801       <code>6</code> for IPv6</td> 
802 </tr> 
803 <tr> 
804   <td><code>dest</code></td> 
805   <td>Destination <code>luci.ip.cidr</code> instance</td> 
806 </tr> 
807 <tr> 
808   <td><code>gw</code></td> 
809   <td>Gateway <code>luci.ip.cidr</code> instance (optional)</td> 
810 </tr> 
811 <tr> 
812   <td><code>from</code></td> 
813   <td>Source address <code>luci.ip.cidr</code> instance (optional)</td> 
814 </tr> 
815 <tr> 
816   <td><code>src</code></td> 
817   <td>Preferred source <code>luci.ip.cidr</code> instance (optional)</td> 
818 </tr> 
819 <tr> 
820   <td><code>dev</code></td> 
821   <td>String containing the name of the outgoing interface</td> 
822 </tr> 
823 <tr> 
824   <td><code>iif</code></td> 
825   <td>String containing the name of the incoming interface (optional)</td> 
826 </tr> 
827 <tr> 
828   <td><code>table</code></td> 
829   <td>Number of the associated routing table (<code>0..65535</code>)</td> 
830 </tr> 
831 <tr> 
832   <td><code>proto</code></td> 
833   <td>Number of the associated routing protocol</td> 
834 </tr> 
835 <tr> 
836   <td><code>scope</code></td> 
837   <td>Number describing the scope of the route, most commonly 
838       <code>0</code> for global or <code>253</code> for on-link</td> 
839 </tr> 
840 <tr> 
841   <td><code>metric</code></td> 
842   <td>Number describing the route metric (optional)</td> 
843 </tr> 
844 <tr> 
845   <td><code>expires</code></td> 
846   <td>Number of seconds the prefix is valid (IPv6 only, optional)</td> 
847 </tr> 
848 <tr> 
849   <td><code>error</code></td> 
850   <td>Route destination error code (optional)</td> 
851 </tr> 
852 </table>
853
854
855
856 <h3>See also:</h3>
857 <ul>
858         
859         <li><a href="#routes">
860                 routes
861         </a>
862         
863 </ul>
864
865 </dd>
866
867
868
869
870 <dt><a name="routes"></a><strong>routes</strong>&nbsp;(filter, callback)</dt>
871 <dd>
872
873  
874 Fetch all routes, optionally matching the given criteria.
875
876
877 <h3>Parameters</h3>
878 <ul>
879         
880         <li>
881           filter: <p>Table containing one or more of the possible filter 
882 critera described below (optional)</p><table> 
883 <tr><th>Field</th><th>Description</th></tr> 
884 <tr><td><code>family</code></td><td> 
885  Number describing the address family to return - <code>4</code> selects 
886  IPv4 routes, <code>6</code> IPv6 ones. Any other value selects both. 
887 </td></tr> 
888 <tr><td><code>iif</code></td><td> 
889  String containing the incoming route interface to match. 
890 </td></tr> 
891 <tr><td><code>oif</code></td><td> 
892  String containing the outgoing route interface to match. 
893 </td></tr> 
894 <tr><td><code>type</code></td><td> 
895  Numeric type to match, e.g. <code>1</code> for unicast. 
896 </td></tr> 
897 <tr><td><code>scope</code></td><td> 
898  Numeric scope to match, e.g. <code>253</code> for onlink. 
899 </td></tr> 
900 <tr><td><code>proto</code></td><td> 
901  Numeric protocol to match, e.g. <code>2</code> for boot. 
902 </td></tr> 
903 <tr><td><code>table</code></td><td> 
904  Numeric routing table to match (<code>0..65535</code>). 
905 </td></tr> 
906 <tr><td><code>gw</code></td><td> 
907  String containing the gateway address to match. Can be in any notation 
908  specified by <code>luci.ip.new()</code>. Prefix matching is performed when 
909  comparing the routes, e.g. "192.168.1.0/24" would select routes with gateway 
910  addresses <code>192.168.1.1 .. 192.168.1.255</code>. 
911 </td></tr> 
912 <tr><td><code>dest</code></td><td> 
913  String containing the destination to match. Prefix matching is performed. 
914 </td></tr> 
915 <tr><td><code>from</code></td><td> 
916  String containing the source address to match. Prefix matching is performed. 
917 </td></tr> 
918 <tr><td><code>src</code></td><td> 
919  String containing the preferred source address to match. 
920  Prefix matching is performed. 
921 </td></tr> 
922 <tr><td><code>dest_exact</code></td><td> 
923  String containing the destination to match. Exact matching is performed, 
924  e.g. <code>dest = "0.0.0.0/0"</code> would match <em>any</em> IPv4 route 
925  while <code>dest_exact = "0.0.0.0/0"</code> will <em>only</em> match the 
926  default route. 
927 </td></tr> 
928 <tr><td><code>from_exact</code></td><td> 
929  String containing the source address to match. Exact matching is performed. 
930 </td></tr> 
931 </table>
932         </li>
933         
934         <li>
935           callback: <p>Callback function to invoke for each found route 
936 instead of returning one table of route objects (optional)</p>
937         </li>
938         
939 </ul>
940
941
942
943
944 <h3>Usage:</h3>
945 <ul> 
946 <li>Find all IPv4 default routes: 
947 <pre>luci.ip.routes({ dest_exact = "0.0.0.0/0" }, function(rt) 
948         print(rt.type, rt.gw, rt.dev) 
949 end)</pre></li> 
950 <li>Find all global IPv6 prefixes on the current system: 
951 <pre>luci.ip.routes({ from = "2001::/7" }, function(rt) 
952         print(rt.from) 
953 end)</pre></li> 
954 <li>Fetch all IPv4 routes: 
955 <pre>routes = luci.ip.routes({ family = 4 }) 
956 for _, rt in ipairs(routes) do 
957         print(rt.dest, rt.gw, rt.dev) 
958 end</pre></li> 
959 </ul>
960
961
962
963 <h3>Return value:</h3>
964 If no callback function is provided, a table of routes 
965 <a href="#routetable">as specified by <code>luci.ip.route()</code></a> 
966 is returned. If a callback function is given, it is invoked for each route 
967 and nothing is returned.
968
969
970
971 <h3>See also:</h3>
972 <ul>
973         
974         <li><a href="#route">
975                 route
976         </a>
977         
978 </ul>
979
980 </dd>
981
982
983
984
985 <dt><a name="neighbors"></a><strong>neighbors</strong>&nbsp;(filter, callback)</dt>
986 <dd>
987
988  
989 Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table
990
991
992 <h3>Parameters</h3>
993 <ul>
994         
995         <li>
996           filter: <p>Table containing one or more of the possible filter 
997 critera described below (optional)</p><table> 
998 <tr><th>Field</th><th>Description</th></tr> 
999 <tr><td><code>family</code></td><td> 
1000  Number describing the address family to return - <code>4</code> selects 
1001  IPv4 ARP, <code>6</code> select IPv6 neighbour entries. Any other value 
1002  selects both. 
1003 </td></tr> 
1004 <tr><td><code>dev</code></td><td> 
1005  String containing the associated interface to match. 
1006 </td></tr> 
1007 <tr><td><code>dest</code></td><td> 
1008  String containing the associated address to match. Can be in any notation 
1009  specified by <code>luci.ip.new()</code>. Prefix matching is performed when 
1010  comparing the addresses, e.g. "192.168.1.0/24" would select ARP entries 
1011  for <code>192.168.1.1 .. 192.168.1.255</code>. 
1012 </td></tr> 
1013 <tr><td><code>mac</code></td><td> 
1014  String containing MAC address to match. 
1015 </td></tr> 
1016 </table>
1017         </li>
1018         
1019         <li>
1020           callback: <p>Callback function to invoke for each found neighbour 
1021 entry instead of returning one table of neighbour entries (optional)</p>
1022         </li>
1023         
1024 </ul>
1025
1026
1027
1028
1029 <h3>Usage:</h3>
1030 <ul> 
1031 <li>Find all ARP neighbours in the LAN: 
1032 <pre>luci.ip.neighbors({ dest = "192.168.0.0/16" }, function(n) 
1033         print(n.dest, n.mac) 
1034 end)</pre></li> 
1035 <li>Find all active IPv6 addresses of host with given MAC: 
1036 <pre>luci.ip.neighbors({ family = 6, mac = "00:21:63:75:aa:17" }, 
1037         function(n) 
1038                 print(n.dest) 
1039         end)</pre></li> 
1040 </ul>
1041
1042
1043
1044 <h3>Return value:</h3>
1045 If no callback function is provided, a table of neighbour entries 
1046 is returned. If a callback function is given, it is invoked for each entry 
1047 and nothing is returned. 
1048  
1049 A neighbour entry is a table containing the following fields: 
1050  
1051 <table> 
1052 <tr><th>Field</th><th>Description</th></tr> 
1053 <tr> 
1054   <td><code>family</code></td> 
1055   <td>Number containing the neighbour entry family, <code>4</code> for IPv4 
1056       ARP or <code>6</code> for IPv6 NDP</td> 
1057 </tr> 
1058 <tr> 
1059   <td><code>dev</code></td> 
1060   <td>String containing the associated device of the neighbour entry</td> 
1061 </tr> 
1062 <tr> 
1063   <td><code>dest</code></td> 
1064   <td>IP address <code>luci.ip.cidr</code> instance</td> 
1065 </tr> 
1066 <tr> 
1067   <td><code>mac</code></td> 
1068   <td>MAC address <code>luci.ip.cidr</code> instance</td> 
1069 </tr> 
1070 <tr> 
1071   <td><code>router</code></td> 
1072   <td>Boolean "true" if the neighbour entry is a router (IPv6, optional)</td> 
1073 </tr> 
1074 <tr> 
1075   <td><code>proxy</code></td> 
1076   <td>Boolean "true" if this is a proxy entry (optional)</td> 
1077 </tr> 
1078 <tr> 
1079   <td><code>incomplete</code></td> 
1080   <td>Boolean "true" if the entry is in incomplete state (optional)</td> 
1081 </tr> 
1082 <tr> 
1083   <td><code>reachable</code></td> 
1084   <td>Boolean "true" if the entry is in reachable state (optional)</td> 
1085 </tr> 
1086 <tr> 
1087   <td><code>stale</code></td> 
1088   <td>Boolean "true" if the entry is stale (optional)</td> 
1089 </tr> 
1090 <tr> 
1091   <td><code>delay</code></td> 
1092   <td>Boolean "true" if the entry is delayed (optional)</td> 
1093 </tr> 
1094 <tr> 
1095   <td><code>probe</code></td> 
1096   <td>Boolean "true" if the entry is in probe state (optional)</td> 
1097 </tr> 
1098 <tr> 
1099   <td><code>failed</code></td> 
1100   <td>Boolean "true" if the entry is in failed state (optional)</td> 
1101 </tr> 
1102 <tr> 
1103   <td><code>noarp</code></td> 
1104   <td>Boolean "true" if the entry is not caused by NDP or 
1105       ARP (optional)</td> 
1106 </tr> 
1107 <tr> 
1108   <td><code>permanent</code></td> 
1109   <td>Boolean "true" if the entry was statically configured from 
1110       userspace (optional)</td> 
1111 </tr> 
1112 </table>
1113
1114
1115
1116 </dd>
1117
1118
1119
1120
1121 <dt><a name="link"></a><strong>link</strong>&nbsp;(device)</dt>
1122 <dd>
1123
1124  
1125 Fetch basic device information
1126
1127
1128 <h3>Parameters</h3>
1129 <ul>
1130         
1131         <li>
1132           device: String containing the network device to query
1133         </li>
1134         
1135 </ul>
1136
1137
1138
1139
1140 <h3>Usage:</h3>
1141 <ul> 
1142 <li>Test whether device br-lan exists: 
1143 <pre>print(luci.ip.link("br-lan").name ~= nil) 
1144 </pre></li> 
1145 <li>Query MAC address of eth0: 
1146 <pre>print(luci.ip.link("eth0").mac) 
1147 </pre></li> 
1148 </ul>
1149
1150
1151
1152 <h3>Return value:</h3>
1153 If the given interface is found, a table containing the fields 
1154 described below is returned, else an empty table. 
1155  
1156 <table> 
1157 <tr><th>Field</th><th>Description</th></tr> 
1158 <tr> 
1159   <td><code>up</code></td> 
1160   <td>Boolean indicating whether the device is in IFF_RUNNING state</td> 
1161 </tr> 
1162 <tr> 
1163   <td><code>type</code></td> 
1164   <td>Numeric value indicating the type of the device, e.g. <code>1</code> 
1165       for ethernet.</td> 
1166 </tr> 
1167 <tr> 
1168   <td><code>name</code></td> 
1169   <td>String containing the name of the device</td> 
1170 </tr> 
1171 <tr> 
1172   <td><code>master</code></td> 
1173   <td>If queried device is a bridge port, string containing the name of 
1174       parent bridge device (optional)</td> 
1175 </tr> 
1176 <tr> 
1177   <td><code>mtu</code></td> 
1178   <td>Number containing the current MTU of the device</td> 
1179 </tr> 
1180 <tr> 
1181   <td><code>qlen</code></td> 
1182   <td>Number containing the TX queue length of the device</td> 
1183 </tr> 
1184 <tr> 
1185   <td><code>mac</code></td> 
1186   <td>MAC address <code>luci.ip.cidr</code> instance representing the device ethernet 
1187       address</td> 
1188 </tr> 
1189 </table>
1190
1191
1192
1193 </dd>
1194
1195
1196 </dl>
1197
1198
1199
1200
1201
1202 </div> <!-- id="content" -->
1203
1204 </div> <!-- id="main" -->
1205
1206 <div id="about">
1207         <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
1208 </div> <!-- id="about" -->
1209
1210 </div> <!-- id="container" -->
1211 </body>
1212 </html>