549a55307e7f09ab2bdbd368b9a9528056290d6b
[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="#route">route</a>&nbsp;(address)</td>
236 <td class="summary">
237
238 Determine the route leading to the given destination.</td>
239 </tr>
240
241 <tr>
242 <td class="name" nowrap><a href="#routes">routes</a>&nbsp;(filter, callback)</td>
243 <td class="summary">
244
245 Fetch all routes, optionally matching the given criteria.</td>
246 </tr>
247
248 <tr>
249 <td class="name" nowrap><a href="#neighbors">neighbors</a>&nbsp;(filter, callback)</td>
250 <td class="summary">
251
252 Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table </td>
253 </tr>
254
255 <tr>
256 <td class="name" nowrap><a href="#link">link</a>&nbsp;(device)</td>
257 <td class="summary">
258
259 Fetch basic device information </td>
260 </tr>
261
262 </table>
263
264
265
266
267
268
269 <br/>
270 <br/>
271
272
273 <h2><a name="functions"></a>Functions</h2>
274 <dl class="function">
275
276
277
278 <dt><a name="new"></a><strong>new</strong>&nbsp;(address, netmask)</dt>
279 <dd>
280
281
282 Construct a new luci.ip.cidr instance and autodetect the address family.
283 Throws an error if the given strings do not represent a valid address or
284 if the given optional netmask is of a different family.
285
286
287 <h3>Parameters</h3>
288 <ul>
289
290 <li>
291 address: String containing a valid IPv4 or IPv6 address, optionally
292 with prefix size (CIDR notation) or netmask separated by slash.
293 </li>
294
295 <li>
296 netmask: String containing a valid IPv4 or IPv6 netmask or number
297 containing a prefix size in bits (<code>0..32</code> for IPv4,
298 <code>0..128</code> for IPv6). Overrides mask embedded in the first argument
299 if specified. (optional)
300 </li>
301
302 </ul>
303
304
305
306
307 <h3>Usage:</h3>
308 <pre>addr = luci.ip.new("10.24.0.1/24")
309 addr = luci.ip.new("10.24.0.1/255.255.255.0")
310 addr = luci.ip.new("10.24.0.1", "255.255.255.0") -- separate netmask
311 addr = luci.ip.new("10.24.0.1/24", 16) -- override netmask
312
313 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64")
314 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::")
315 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::")
316 addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
317
318
319
320 <h3>Return value:</h3>
321 A <code>luci.ip.cidr</code> object representing the given
322 address/mask range.
323
324
325
326 <h3>See also:</h3>
327 <ul>
328
329 <li><a href="#IPv4">
330 IPv4
331 </a>
332
333 <li><a href="#IPv6">
334 IPv6
335 </a>
336
337 </ul>
338
339 </dd>
340
341
342
343
344 <dt><a name="IPv4"></a><strong>IPv4</strong>&nbsp;(address, netmask)</dt>
345 <dd>
346
347
348 Construct a new IPv4 luci.ip.cidr instance.
349 Throws an error if the given string does not represent a valid IPv4 address or
350 if the given optional netmask is of a different family.
351
352
353 <h3>Parameters</h3>
354 <ul>
355
356 <li>
357 address: String containing a valid IPv4, optionally with prefix size
358 (CIDR notation) or netmask separated by slash.
359 </li>
360
361 <li>
362 netmask: String containing a valid IPv4 netmask or number
363 containing a prefix size between <code>0</code> and <code>32</code> bit.
364 Overrides mask embedded in the first argument if specified. (optional)
365 </li>
366
367 </ul>
368
369
370
371
372 <h3>Usage:</h3>
373 <pre>addr = luci.ip.IPv4("10.24.0.1/24")
374 addr = luci.ip.IPv4("10.24.0.1/255.255.255.0")
375 addr = luci.ip.IPv4("10.24.0.1", "255.255.255.0") -- separate netmask
376 addr = luci.ip.IPv4("10.24.0.1/24", 16) -- override netmask</pre>
377
378
379
380 <h3>Return value:</h3>
381 A <code>luci.ip.cidr</code> object representing the given IPv4 range.
382
383
384
385 <h3>See also:</h3>
386 <ul>
387
388 <li><a href="#IPv6">
389 IPv6
390 </a>
391
392 </ul>
393
394 </dd>
395
396
397
398
399 <dt><a name="IPv6"></a><strong>IPv6</strong>&nbsp;(address, netmask)</dt>
400 <dd>
401
402
403 Construct a new IPv6 luci.ip.cidr instance.
404 Throws an error if the given string does not represent a valid IPv6 address or
405 if the given optional netmask is of a different family.
406
407
408 <h3>Parameters</h3>
409 <ul>
410
411 <li>
412 address: String containing a valid IPv6, optionally with prefix size
413 (CIDR notation) or netmask separated by slash.
414 </li>
415
416 <li>
417 netmask: String containing a valid IPv4 netmask or number
418 containing a prefix size between <code>0</code> and <code>128</code> bit.
419 Overrides mask embedded in the first argument if specified. (optional)
420 </li>
421
422 </ul>
423
424
425
426
427 <h3>Usage:</h3>
428 <pre>addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64")
429 addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::")
430 addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::")
431 addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
432
433
434
435 <h3>Return value:</h3>
436 A <code>luci.ip.cidr</code> object representing the given IPv6 range.
437
438
439
440 <h3>See also:</h3>
441 <ul>
442
443 <li><a href="#IPv4">
444 IPv4
445 </a>
446
447 </ul>
448
449 </dd>
450
451
452
453
454 <dt><a name="route"></a><strong>route</strong>&nbsp;(address)</dt>
455 <dd>
456
457
458 Determine the route leading to the given destination.
459
460
461 <h3>Parameters</h3>
462 <ul>
463
464 <li>
465 address: A <code>luci.ip.cidr</code> instance or a string containing
466 a valid IPv4 or IPv6 range as specified by <code>luci.ip.new()</code>.
467 </li>
468
469 </ul>
470
471
472
473
474 <h3>Usage:</h3>
475 <ul>
476 <li>Find default gateway by getting route to Google's public NS server
477 <pre>rt = luci.ip.route("8.8.8.8")
478 if rt ~= nil then
479 print("gateway is", rt.gw)
480 end</pre></li>
481 <li>Determine IPv6 upstream interface <pre>rt = luci.ip.route("2001::/7")
482 if rt ~= nil then
483 print("ipv6 upstream device is", rt.dev)
484 end</pre></li>
485 </ul>
486
487
488
489 <h3>Return value:</h3>
490 <p>Table containing the fields described below.</p>
491 <table id="routetable">
492 <tr><th>Field</th><th>Description</th></tr>
493 <tr><td><code>type</code><td>
494 <p>Route type with one of the following numeric values:</p>
495 <table>
496 <tr>
497 <td><code>1</code></td>
498 <td><code>RTN_UNICAST</code> - Gateway or direct route</td>
499 </tr>
500 <tr>
501 <td><code>2</code></td>
502 <td><code>RTN_LOCAL</code> - Accept locally</td>
503 </tr>
504 <tr>
505 <td><code>3</code></td>
506 <td><code>RTN_BROADCAST</code> -
507 Accept locally as broadcast send as broadcast</td>
508 </tr>
509 <tr>
510 <td><code>4</code></td>
511 <td><code>RTN_ANYCAST</code> -
512 Accept locally as broadcast but send as unicast</td>
513 </tr>
514 <tr>
515 <td><code>5</code></td>
516 <td><code>RTN_MULTICAST</code> - Multicast route</td>
517 </tr>
518 </table>
519 </td></tr>
520 <tr>
521 <td><code>family</code></td>
522 <td>Number containing the route family, <code>4</code> for IPv4 or
523 <code>6</code> for IPv6</td>
524 </tr>
525 <tr>
526 <td><code>dest</code></td>
527 <td>Destination <code>luci.ip.cidr</code> instance</td>
528 </tr>
529 <tr>
530 <td><code>gw</code></td>
531 <td>Gateway <code>luci.ip.cidr</code> instance (optional)</td>
532 </tr>
533 <tr>
534 <td><code>from</code></td>
535 <td>Source address <code>luci.ip.cidr</code> instance (optional)</td>
536 </tr>
537 <tr>
538 <td><code>src</code></td>
539 <td>Preferred source <code>luci.ip.cidr</code> instance (optional)</td>
540 </tr>
541 <tr>
542 <td><code>dev</code></td>
543 <td>String containing the name of the outgoing interface</td>
544 </tr>
545 <tr>
546 <td><code>iif</code></td>
547 <td>String containing the name of the incoming interface (optional)</td>
548 </tr>
549 <tr>
550 <td><code>table</code></td>
551 <td>Number of the associated routing table (<code>0..65535</code>)</td>
552 </tr>
553 <tr>
554 <td><code>proto</code></td>
555 <td>Number of the associated routing protocol</td>
556 </tr>
557 <tr>
558 <td><code>scope</code></td>
559 <td>Number describing the scope of the route, most commonly
560 <code>0</code> for global or <code>253</code> for on-link</td>
561 </tr>
562 <tr>
563 <td><code>metric</code></td>
564 <td>Number describing the route metric (optional)</td>
565 </tr>
566 <tr>
567 <td><code>expires</code></td>
568 <td>Number of seconds the prefix is valid (IPv6 only, optional)</td>
569 </tr>
570 <tr>
571 <td><code>error</code></td>
572 <td>Route destination error code (optional)</td>
573 </tr>
574 </table>
575
576
577
578 <h3>See also:</h3>
579 <ul>
580
581 <li><a href="#routes">
582 routes
583 </a>
584
585 </ul>
586
587 </dd>
588
589
590
591
592 <dt><a name="routes"></a><strong>routes</strong>&nbsp;(filter, callback)</dt>
593 <dd>
594
595
596 Fetch all routes, optionally matching the given criteria.
597
598
599 <h3>Parameters</h3>
600 <ul>
601
602 <li>
603 filter: <p>Table containing one or more of the possible filter
604 critera described below (optional)</p><table>
605 <tr><th>Field</th><th>Description</th></tr>
606 <tr><td><code>family</code></td><td>
607 Number describing the address family to return - <code>4</code> selects
608 IPv4 routes, <code>6</code> IPv6 ones. Any other value selects both.
609 </td></tr>
610 <tr><td><code>iif</code></td><td>
611 String containing the incoming route interface to match.
612 </td></tr>
613 <tr><td><code>oif</code></td><td>
614 String containing the outgoing route interface to match.
615 </td></tr>
616 <tr><td><code>type</code></td><td>
617 Numeric type to match, e.g. <code>1</code> for unicast.
618 </td></tr>
619 <tr><td><code>scope</code></td><td>
620 Numeric scope to match, e.g. <code>253</code> for onlink.
621 </td></tr>
622 <tr><td><code>proto</code></td><td>
623 Numeric protocol to match, e.g. <code>2</code> for boot.
624 </td></tr>
625 <tr><td><code>table</code></td><td>
626 Numeric routing table to match (<code>0..65535</code>).
627 </td></tr>
628 <tr><td><code>gw</code></td><td>
629 String containing the gateway address to match. Can be in any notation
630 specified by <code>luci.ip.new()</code>. Prefix matching is performed when
631 comparing the routes, e.g. "192.168.1.0/24" would select routes with gateway
632 addresses <code>192.168.1.1 .. 192.168.1.255</code>.
633 </td></tr>
634 <tr><td><code>dest</code></td><td>
635 String containing the destination to match. Prefix matching is performed.
636 </td></tr>
637 <tr><td><code>from</code></td><td>
638 String containing the source address to match. Prefix matching is performed.
639 </td></tr>
640 <tr><td><code>src</code></td><td>
641 String containing the preferred source address to match.
642 Prefix matching is performed.
643 </td></tr>
644 <tr><td><code>dest_exact</code></td><td>
645 String containing the destination to match. Exact matching is performed,
646 e.g. <code>dest = "0.0.0.0/0"</code> would match <em>any</em> IPv4 route
647 while <code>dest_exact = "0.0.0.0/0"</code> will <em>only</em> match the
648 default route.
649 </td></tr>
650 <tr><td><code>from_exact</code></td><td>
651 String containing the source address to match. Exact matching is performed.
652 </td></tr>
653 </table>
654 </li>
655
656 <li>
657 callback: <p>Callback function to invoke for each found route
658 instead of returning one table of route objects (optional)</p>
659 </li>
660
661 </ul>
662
663
664
665
666 <h3>Usage:</h3>
667 <ul>
668 <li>Find all IPv4 default routes:
669 <pre>luci.ip.routes({ dest_exact = "0.0.0.0/0" }, function(rt)
670 print(rt.type, rt.gw, rt.dev)
671 end)</pre></li>
672 <li>Find all global IPv6 prefixes on the current system:
673 <pre>luci.ip.routes({ from = "2001::/7" }, function(rt)
674 print(rt.from)
675 end)</pre></li>
676 <li>Fetch all IPv4 routes:
677 <pre>routes = luci.ip.routes({ family = 4 })
678 for _, rt in ipairs(routes) do
679 print(rt.dest, rt.gw, rt.dev)
680 end</pre></li>
681 </ul>
682
683
684
685 <h3>Return value:</h3>
686 If no callback function is provided, a table of routes
687 <a href="#routetable">as specified by <code>luci.ip.route()</code></a>
688 is returned. If a callback function is given, it is invoked for each route
689 and nothing is returned.
690
691
692
693 <h3>See also:</h3>
694 <ul>
695
696 <li><a href="#route">
697 route
698 </a>
699
700 </ul>
701
702 </dd>
703
704
705
706
707 <dt><a name="neighbors"></a><strong>neighbors</strong>&nbsp;(filter, callback)</dt>
708 <dd>
709
710
711 Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table
712
713
714 <h3>Parameters</h3>
715 <ul>
716
717 <li>
718 filter: <p>Table containing one or more of the possible filter
719 critera described below (optional)</p><table>
720 <tr><th>Field</th><th>Description</th></tr>
721 <tr><td><code>family</code></td><td>
722 Number describing the address family to return - <code>4</code> selects
723 IPv4 ARP, <code>6</code> select IPv6 neighbour entries. Any other value
724 selects both.
725 </td></tr>
726 <tr><td><code>dev</code></td><td>
727 String containing the associated interface to match.
728 </td></tr>
729 <tr><td><code>dest</code></td><td>
730 String containing the associated address to match. Can be in any notation
731 specified by <code>luci.ip.new()</code>. Prefix matching is performed when
732 comparing the addresses, e.g. "192.168.1.0/24" would select ARP entries
733 for <code>192.168.1.1 .. 192.168.1.255</code>.
734 </td></tr>
735 <tr><td><code>mac</code></td><td>
736 String containing MAC address to match.
737 </td></tr>
738 </table>
739 </li>
740
741 <li>
742 callback: <p>Callback function to invoke for each found neighbour
743 entry instead of returning one table of neighbour entries (optional)</p>
744 </li>
745
746 </ul>
747
748
749
750
751 <h3>Usage:</h3>
752 <ul>
753 <li>Find all ARP neighbours in the LAN:
754 <pre>luci.ip.neighbors({ dest = "192.168.0.0/16" }, function(n)
755 print(n.dest, n.mac)
756 end)</pre></li>
757 <li>Find all active IPv6 addresses of host with given MAC:
758 <pre>luci.ip.neighbors({ family = 6, mac = "00:21:63:75:aa:17" },
759 function(n)
760 print(n.dest)
761 end)</pre></li>
762 </ul>
763
764
765
766 <h3>Return value:</h3>
767 If no callback function is provided, a table of neighbour entries
768 is returned. If a callback function is given, it is invoked for each entry
769 and nothing is returned.
770
771 A neighbour entry is a table containing the following fields:
772
773 <table>
774 <tr><th>Field</th><th>Description</th></tr>
775 <tr>
776 <td><code>family</code></td>
777 <td>Number containing the neighbour entry family, <code>4</code> for IPv4
778 ARP or <code>6</code> for IPv6 NDP</td>
779 </tr>
780 <tr>
781 <td><code>dev</code></td>
782 <td>String containing the associated device of the neighbour entry</td>
783 </tr>
784 <tr>
785 <td><code>dest</code></td>
786 <td>IP address <code>luci.ip.cidr</code> instance</td>
787 </tr>
788 <tr>
789 <td><code>mac</code></td>
790 <td>String containing the associated MAC address</td>
791 </tr>
792 <tr>
793 <td><code>router</code></td>
794 <td>Boolean "true" if the neighbour entry is a router (IPv6, optional)</td>
795 </tr>
796 <tr>
797 <td><code>proxy</code></td>
798 <td>Boolean "true" if this is a proxy entry (optional)</td>
799 </tr>
800 <tr>
801 <td><code>incomplete</code></td>
802 <td>Boolean "true" if the entry is in incomplete state (optional)</td>
803 </tr>
804 <tr>
805 <td><code>reachable</code></td>
806 <td>Boolean "true" if the entry is in reachable state (optional)</td>
807 </tr>
808 <tr>
809 <td><code>stale</code></td>
810 <td>Boolean "true" if the entry is stale (optional)</td>
811 </tr>
812 <tr>
813 <td><code>delay</code></td>
814 <td>Boolean "true" if the entry is delayed (optional)</td>
815 </tr>
816 <tr>
817 <td><code>probe</code></td>
818 <td>Boolean "true" if the entry is in probe state (optional)</td>
819 </tr>
820 <tr>
821 <td><code>failed</code></td>
822 <td>Boolean "true" if the entry is in failed state (optional)</td>
823 </tr>
824 <tr>
825 <td><code>noarp</code></td>
826 <td>Boolean "true" if the entry is not caused by NDP or
827 ARP (optional)</td>
828 </tr>
829 <tr>
830 <td><code>permanent</code></td>
831 <td>Boolean "true" if the entry was statically configured from
832 userspace (optional)</td>
833 </tr>
834 </table>
835
836
837
838 </dd>
839
840
841
842
843 <dt><a name="link"></a><strong>link</strong>&nbsp;(device)</dt>
844 <dd>
845
846
847 Fetch basic device information
848
849
850 <h3>Parameters</h3>
851 <ul>
852
853 <li>
854 device: String containing the network device to query
855 </li>
856
857 </ul>
858
859
860
861
862 <h3>Usage:</h3>
863 <ul>
864 <li>Test whether device br-lan exists:
865 <pre>print(luci.ip.link("br-lan").name ~= nil)
866 </pre></li>
867 <li>Query MAC address of eth0:
868 <pre>print(luci.ip.link("eth0").mac)
869 </pre></li>
870 </ul>
871
872
873
874 <h3>Return value:</h3>
875 If the given interface is found, a table containing the fields
876 described below is returned, else an empty table.
877
878 <table>
879 <tr><th>Field</th><th>Description</th></tr>
880 <tr>
881 <td><code>up</code></td>
882 <td>Boolean indicating whether the device is in IFF_RUNNING state</td>
883 </tr>
884 <tr>
885 <td><code>type</code></td>
886 <td>Numeric value indicating the type of the device, e.g. <code>1</code>
887 for ethernet.</td>
888 </tr>
889 <tr>
890 <td><code>name</code></td>
891 <td>String containing the name of the device</td>
892 </tr>
893 <tr>
894 <td><code>master</code></td>
895 <td>If queried device is a bridge port, string containing the name of
896 parent bridge device (optional)</td>
897 </tr>
898 <tr>
899 <td><code>mtu</code></td>
900 <td>Number containing the current MTU of the device</td>
901 </tr>
902 <tr>
903 <td><code>qlen</code></td>
904 <td>Number containing the TX queue length of the device</td>
905 </tr>
906 <tr>
907 <td><code>mac</code></td>
908 <td>String containing the link local address of the device in
909 dotted hex notation</td>
910 </tr>
911 </table>
912
913
914
915 </dd>
916
917
918 </dl>
919
920
921
922
923
924 </div> <!-- id="content" -->
925
926 </div> <!-- id="main" -->
927
928 <div id="about">
929 <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>
930 </div> <!-- id="about" -->
931
932 </div> <!-- id="container" -->
933 </body>
934 </html>