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