summaryrefslogtreecommitdiffhomepage
path: root/docs/api/modules/luci.ip.html
blob: 0599396b6fee71ec0a6d6355b1357e7a2ffd358e (plain)
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Reference</title>
    <link rel="stylesheet" href="../luadoc.css" type="text/css" />
	<!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
</head>

<body>
<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->

<div id="main">

<div id="navigation">


<h1>LuaDoc</h1>
<ul>
	
	<li><a href="../index.html">Index</a></li>
	
</ul>


<!-- Module list -->

<h1>Modules</h1>
<ul>

	<li>
		<a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
	</li>

	<li>
		<a href="../modules/luci.http.html">luci.http</a>
	</li>

	<li>
		<a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
	</li>

	<li>
		<a href="../modules/luci.http.date.html">luci.http.date</a>
	</li>

	<li>
		<a href="../modules/luci.http.mime.html">luci.http.mime</a>
	</li>

	<li>
		<a href="../modules/luci.i18n.html">luci.i18n</a>
	</li>

	<li><strong>luci.ip</strong></li>
	
	<li>
		<a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
	</li>

	<li>
		<a href="../modules/luci.json.html">luci.json</a>
	</li>

	<li>
		<a href="../modules/luci.jsonc.html">luci.jsonc</a>
	</li>

	<li>
		<a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
	</li>

	<li>
		<a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
	</li>

	<li>
		<a href="../modules/luci.model.uci.html">luci.model.uci</a>
	</li>

	<li>
		<a href="../modules/luci.rpcc.html">luci.rpcc</a>
	</li>

	<li>
		<a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
	</li>

	<li>
		<a href="../modules/luci.sys.html">luci.sys</a>
	</li>

	<li>
		<a href="../modules/luci.sys.init.html">luci.sys.init</a>
	</li>

	<li>
		<a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
	</li>

	<li>
		<a href="../modules/luci.sys.net.html">luci.sys.net</a>
	</li>

	<li>
		<a href="../modules/luci.sys.process.html">luci.sys.process</a>
	</li>

	<li>
		<a href="../modules/luci.sys.user.html">luci.sys.user</a>
	</li>

	<li>
		<a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
	</li>

	<li>
		<a href="../modules/luci.util.html">luci.util</a>
	</li>

	<li>
		<a href="../modules/nixio.html">nixio</a>
	</li>

	<li>
		<a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
	</li>

	<li>
		<a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
	</li>

	<li>
		<a href="../modules/nixio.File.html">nixio.File</a>
	</li>

	<li>
		<a href="../modules/nixio.README.html">nixio.README</a>
	</li>

	<li>
		<a href="../modules/nixio.Socket.html">nixio.Socket</a>
	</li>

	<li>
		<a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
	</li>

	<li>
		<a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
	</li>

	<li>
		<a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
	</li>

	<li>
		<a href="../modules/nixio.bin.html">nixio.bin</a>
	</li>

	<li>
		<a href="../modules/nixio.bit.html">nixio.bit</a>
	</li>

	<li>
		<a href="../modules/nixio.crypto.html">nixio.crypto</a>
	</li>

	<li>
		<a href="../modules/nixio.fs.html">nixio.fs</a>
	</li>

</ul>



<!-- File list -->







</div><!-- id="navigation" -->

<div id="content">

<h1>Class <code>luci.ip</code></h1>

<p>
 LuCI IP calculation and netlink access library.</p>







<h2>Functions</h2>
<table class="function_list">

	<tr>
	<td class="name" nowrap><a href="#new">new</a>&nbsp;(address, netmask)</td>
	<td class="summary">
 
Construct a new luci.ip.cidr instance and autodetect the address family.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#IPv4">IPv4</a>&nbsp;(address, netmask)</td>
	<td class="summary">
 
Construct a new IPv4 luci.ip.cidr instance.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#IPv6">IPv6</a>&nbsp;(address, netmask)</td>
	<td class="summary">
 
Construct a new IPv6 luci.ip.cidr instance.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#MAC">MAC</a>&nbsp;(address, netmask)</td>
	<td class="summary">
 
Construct a new MAC luci.ip.cidr instance.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#checkip4">checkip4</a>&nbsp;(address)</td>
	<td class="summary">
 
Verify an IPv4 address.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#checkip6">checkip6</a>&nbsp;(address)</td>
	<td class="summary">
 
Verify an IPv6 address.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#checkmac">checkmac</a>&nbsp;(address)</td>
	<td class="summary">
 
Verify an ethernet MAC address.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#route">route</a>&nbsp;(address, source)</td>
	<td class="summary">
 
Determine the route leading to the given destination.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#routes">routes</a>&nbsp;(filter, callback)</td>
	<td class="summary">
 
Fetch all routes, optionally matching the given criteria.</td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#neighbors">neighbors</a>&nbsp;(filter, callback)</td>
	<td class="summary">
 
Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table </td>
	</tr>

	<tr>
	<td class="name" nowrap><a href="#link">link</a>&nbsp;(device)</td>
	<td class="summary">
 
Fetch basic device information </td>
	</tr>

</table>






<br/>
<br/>


<h2><a name="functions"></a>Functions</h2>
<dl class="function">



<dt><a name="new"></a><strong>new</strong>&nbsp;(address, netmask)</dt>
<dd>

 
Construct a new luci.ip.cidr instance and autodetect the address family. 
Throws an error if the given strings do not represent a valid address or 
if the given optional netmask is of a different family.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid IPv4 or IPv6 address, optionally 
with prefix size (CIDR notation) or netmask separated by slash.
	</li>
	
	<li>
	  netmask: String containing a valid IPv4 or IPv6 netmask or number 
containing a prefix size in bits (<code>0..32</code> for IPv4, 
<code>0..128</code> for IPv6). Overrides mask embedded in the first argument 
if specified. (optional)
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>addr = luci.ip.new("10.24.0.1/24") 
addr = luci.ip.new("10.24.0.1/255.255.255.0") 
addr = luci.ip.new("10.24.0.1", "255.255.255.0")        -- separate netmask 
addr = luci.ip.new("10.24.0.1/24", 16)                  -- override netmask 
 
addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64") 
addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::") 
addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::") 
addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>



<h3>Return value:</h3>
A <code>luci.ip.cidr</code> object representing the given 
address/mask range.



<h3>See also:</h3>
<ul>
	
	<li><a href="#IPv4">
		IPv4
	</a>
	
	<li><a href="#IPv6">
		IPv6
	</a>
	
	<li><a href="#MAC">
		MAC
	</a>
	
</ul>

</dd>




<dt><a name="IPv4"></a><strong>IPv4</strong>&nbsp;(address, netmask)</dt>
<dd>

 
Construct a new IPv4 luci.ip.cidr instance. 
Throws an error if the given string does not represent a valid IPv4 address or 
if the given optional netmask is of a different family.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid IPv4, optionally with prefix size 
(CIDR notation) or netmask separated by slash.
	</li>
	
	<li>
	  netmask: String containing a valid IPv4 netmask or number 
containing a prefix size between <code>0</code> and <code>32</code> bit. 
Overrides mask embedded in the first argument if specified. (optional)
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>addr = luci.ip.IPv4("10.24.0.1/24") 
addr = luci.ip.IPv4("10.24.0.1/255.255.255.0") 
addr = luci.ip.IPv4("10.24.0.1", "255.255.255.0")        -- separate netmask 
addr = luci.ip.IPv4("10.24.0.1/24", 16)                  -- override netmask</pre>



<h3>Return value:</h3>
A <code>luci.ip.cidr</code> object representing the given IPv4 range.



<h3>See also:</h3>
<ul>
	
	<li><a href="#IPv6">
		IPv6
	</a>
	
	<li><a href="#MAC">
		MAC
	</a>
	
</ul>

</dd>




<dt><a name="IPv6"></a><strong>IPv6</strong>&nbsp;(address, netmask)</dt>
<dd>

 
Construct a new IPv6 luci.ip.cidr instance. 
Throws an error if the given string does not represent a valid IPv6 address or 
if the given optional netmask is of a different family.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid IPv6, optionally with prefix size 
(CIDR notation) or netmask separated by slash.
	</li>
	
	<li>
	  netmask: String containing a valid IPv4 netmask or number 
containing a prefix size between <code>0</code> and <code>128</code> bit. 
Overrides mask embedded in the first argument if specified. (optional)
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64") 
addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::") 
addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::") 
addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>



<h3>Return value:</h3>
A <code>luci.ip.cidr</code> object representing the given IPv6 range.



<h3>See also:</h3>
<ul>
	
	<li><a href="#IPv4">
		IPv4
	</a>
	
	<li><a href="#MAC">
		MAC
	</a>
	
</ul>

</dd>




<dt><a name="MAC"></a><strong>MAC</strong>&nbsp;(address, netmask)</dt>
<dd>

 
Construct a new MAC luci.ip.cidr instance. 
Throws an error if the given string does not represent a valid ethernet MAC 
address or if the given optional mask is of a different family.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid ethernet MAC address, optionally with 
prefix size (CIDR notation) or mask separated by slash.
	</li>
	
	<li>
	  netmask: String containing a valid MAC address mask or number 
containing a prefix size between <code>0</code> and <code>48</code> bit. 
Overrides mask embedded in the first argument if specified. (optional)
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24") 
intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/FF:FF:FF:0:0:0") 
intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00", "FF:FF:FF:0:0:0") 
intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24", 48) -- override mask</pre>



<h3>Return value:</h3>
A <code>luci.ip.cidr</code> object representing the given MAC address range.



<h3>See also:</h3>
<ul>
	
	<li><a href="#IPv4">
		IPv4
	</a>
	
	<li><a href="#IPv6">
		IPv6
	</a>
	
</ul>

</dd>




<dt><a name="checkip4"></a><strong>checkip4</strong>&nbsp;(address)</dt>
<dd>

 
Verify an IPv4 address. 
 
Checks whether given argument is a preexisting luci.ip.cidr IPv4 address 
instance or a string literal convertible to an IPv4 address and returns a 
plain Lua string containing the canonical representation of the address. 
 
If the argument is not a valid address, returns nothing. This function is 
intended to aid in safely verifying address literals without having to deal 
with exceptions.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid IPv4 address or existing 
luci.ip.cidr IPv4 instance.
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>ipv4 = luci.ip.checkip4(luci.ip.new("127.0.0.1"))  -- "127.0.0.1" 
ipv4 = luci.ip.checkip4("127.0.0.1")               -- "127.0.0.1" 
ipv4 = luci.ip.checkip4("nonesense")               -- nothing 
ipv4 = luci.ip.checkip4(123)                       -- nothing 
ipv4 = luci.ip.checkip4(nil)                       -- nothing 
ipv4 = luci.ip.checkip4()                          -- nothing</pre>



<h3>Return value:</h3>
A string representing the given IPv4 address.



<h3>See also:</h3>
<ul>
	
	<li><a href="#checkip6">
		checkip6
	</a>
	
	<li><a href="#checkmac">
		checkmac
	</a>
	
</ul>

</dd>




<dt><a name="checkip6"></a><strong>checkip6</strong>&nbsp;(address)</dt>
<dd>

 
Verify an IPv6 address. 
 
Checks whether given argument is a preexisting luci.ip.cidr IPv6 address 
instance or a string literal convertible to an IPv6 address and returns a 
plain Lua string containing the canonical representation of the address. 
 
If the argument is not a valid address, returns nothing. This function is 
intended to aid in safely verifying address literals without having to deal 
with exceptions.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid IPv6 address or existing 
luci.ip.cidr IPv6 instance.
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>ipv6 = luci.ip.checkip6(luci.ip.new("0:0:0:0:0:0:0:1"))  -- "::1" 
ipv6 = luci.ip.checkip6("0:0:0:0:0:0:0:1")               -- "::1" 
ipv6 = luci.ip.checkip6("nonesense")                     -- nothing 
ipv6 = luci.ip.checkip6(123)                             -- nothing 
ipv6 = luci.ip.checkip6(nil)                             -- nothing 
ipv6 = luci.ip.checkip6()                                -- nothing</pre>



<h3>Return value:</h3>
A string representing the given IPv6 address.



<h3>See also:</h3>
<ul>
	
	<li><a href="#checkip4">
		checkip4
	</a>
	
	<li><a href="#checkmac">
		checkmac
	</a>
	
</ul>

</dd>




<dt><a name="checkmac"></a><strong>checkmac</strong>&nbsp;(address)</dt>
<dd>

 
Verify an ethernet MAC address. 
 
Checks whether given argument is a preexisting luci.ip.cidr MAC address 
instance or a string literal convertible to an ethernet MAC and returns a 
plain Lua string containing the canonical representation of the address. 
 
If the argument is not a valid address, returns nothing. This function is 
intended to aid in safely verifying address literals without having to deal 
with exceptions.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: String containing a valid MAC address or existing luci.ip.cidr 
MAC address instance.
	</li>
	
</ul>




<h3>Usage:</h3>
<pre>mac = luci.ip.checkmac(luci.ip.new("00-11-22-cc-dd-ee"))  -- "00:11:22:CC:DD:EE" 
mac = luci.ip.checkmac("00:11:22:cc:dd:ee")               -- "00:11:22:CC:DD:EE" 
mac = luci.ip.checkmac("nonesense")                       -- nothing 
mac = luci.ip.checkmac(123)                               -- nothing 
mac = luci.ip.checkmac(nil)                               -- nothing 
mac = luci.ip.checkmac()                                  -- nothing</pre>



<h3>Return value:</h3>
A string representing the given MAC address.



<h3>See also:</h3>
<ul>
	
	<li><a href="#checkip4">
		checkip4
	</a>
	
	<li><a href="#checkip6">
		checkip6
	</a>
	
</ul>

</dd>




<dt><a name="route"></a><strong>route</strong>&nbsp;(address, source)</dt>
<dd>

 
Determine the route leading to the given destination.


<h3>Parameters</h3>
<ul>
	
	<li>
	  address: A <code>luci.ip.cidr</code> instance or a string containing 
a valid IPv4 or IPv6 range as specified by <code>luci.ip.new()</code>.
	</li>
	
	<li>
	  source: A <code>luci.ip.cidr</code> instance or a string containing 
the preferred source address for route selection (optional).
	</li>
	
</ul>




<h3>Usage:</h3>
<ul> 
<li>Find default gateway by getting route to Google's public NS server 
<pre>rt = luci.ip.route("8.8.8.8") 
if rt ~= nil then 
	print("gateway is", rt.gw) 
end</pre></li> 
<li>Determine IPv6 upstream interface <pre>rt = luci.ip.route("2001::/7") 
if rt ~= nil then 
	print("ipv6 upstream device is", rt.dev) 
end</pre></li> 
</ul>



<h3>Return value:</h3>
<p>Table containing the fields described below.</p> 
<table id="routetable"> 
<tr><th>Field</th><th>Description</th></tr> 
<tr><td><code>type</code><td> 
  <p>Route type with one of the following numeric values:</p> 
  <table> 
  <tr> 
	<td><code>1</code></td> 
	<td><code>RTN_UNICAST</code> - Gateway or direct route</td> 
  </tr> 
  <tr> 
	<td><code>2</code></td> 
	<td><code>RTN_LOCAL</code> - Accept locally</td> 
  </tr> 
  <tr> 
	<td><code>3</code></td> 
	<td><code>RTN_BROADCAST</code> - 
	    Accept locally as broadcast send as broadcast</td> 
  </tr> 
  <tr> 
	<td><code>4</code></td> 
	<td><code>RTN_ANYCAST</code> - 
        Accept locally as broadcast but send as unicast</td> 
  </tr> 
  <tr> 
	<td><code>5</code></td> 
	<td><code>RTN_MULTICAST</code> - Multicast route</td> 
  </tr> 
  </table> 
</td></tr> 
<tr> 
  <td><code>family</code></td> 
  <td>Number containing the route family, <code>4</code> for IPv4 or 
      <code>6</code> for IPv6</td> 
</tr> 
<tr> 
  <td><code>dest</code></td> 
  <td>Destination <code>luci.ip.cidr</code> instance</td> 
</tr> 
<tr> 
  <td><code>gw</code></td> 
  <td>Gateway <code>luci.ip.cidr</code> instance (optional)</td> 
</tr> 
<tr> 
  <td><code>from</code></td> 
  <td>Source address <code>luci.ip.cidr</code> instance (optional)</td> 
</tr> 
<tr> 
  <td><code>src</code></td> 
  <td>Preferred source <code>luci.ip.cidr</code> instance (optional)</td> 
</tr> 
<tr> 
  <td><code>dev</code></td> 
  <td>String containing the name of the outgoing interface</td> 
</tr> 
<tr> 
  <td><code>iif</code></td> 
  <td>String containing the name of the incoming interface (optional)</td> 
</tr> 
<tr> 
  <td><code>table</code></td> 
  <td>Number of the associated routing table (<code>0..65535</code>)</td> 
</tr> 
<tr> 
  <td><code>proto</code></td> 
  <td>Number of the associated routing protocol</td> 
</tr> 
<tr> 
  <td><code>scope</code></td> 
  <td>Number describing the scope of the route, most commonly 
      <code>0</code> for global or <code>253</code> for on-link</td> 
</tr> 
<tr> 
  <td><code>metric</code></td> 
  <td>Number describing the route metric (optional)</td> 
</tr> 
<tr> 
  <td><code>expires</code></td> 
  <td>Number of seconds the prefix is valid (IPv6 only, optional)</td> 
</tr> 
<tr> 
  <td><code>error</code></td> 
  <td>Route destination error code (optional)</td> 
</tr> 
</table>



<h3>See also:</h3>
<ul>
	
	<li><a href="#routes">
		routes
	</a>
	
</ul>

</dd>




<dt><a name="routes"></a><strong>routes</strong>&nbsp;(filter, callback)</dt>
<dd>

 
Fetch all routes, optionally matching the given criteria.


<h3>Parameters</h3>
<ul>
	
	<li>
	  filter: <p>Table containing one or more of the possible filter 
criteria described below (optional)</p><table> 
<tr><th>Field</th><th>Description</th></tr> 
<tr><td><code>family</code></td><td> 
 Number describing the address family to return - <code>4</code> selects 
 IPv4 routes, <code>6</code> IPv6 ones. Any other value selects both. 
</td></tr> 
<tr><td><code>iif</code></td><td> 
 String containing the incoming route interface to match. 
</td></tr> 
<tr><td><code>oif</code></td><td> 
 String containing the outgoing route interface to match. 
</td></tr> 
<tr><td><code>type</code></td><td> 
 Numeric type to match, e.g. <code>1</code> for unicast. 
</td></tr> 
<tr><td><code>scope</code></td><td> 
 Numeric scope to match, e.g. <code>253</code> for onlink. 
</td></tr> 
<tr><td><code>proto</code></td><td> 
 Numeric protocol to match, e.g. <code>2</code> for boot. 
</td></tr> 
<tr><td><code>table</code></td><td> 
 Numeric routing table to match (<code>0..65535</code>). 
</td></tr> 
<tr><td><code>gw</code></td><td> 
 String containing the gateway address to match. Can be in any notation 
 specified by <code>luci.ip.new()</code>. Prefix matching is performed when 
 comparing the routes, e.g. "192.168.1.0/24" would select routes with gateway 
 addresses <code>192.168.1.1 .. 192.168.1.255</code>. 
</td></tr> 
<tr><td><code>dest</code></td><td> 
 String containing the destination to match. Prefix matching is performed. 
</td></tr> 
<tr><td><code>from</code></td><td> 
 String containing the source address to match. Prefix matching is performed. 
</td></tr> 
<tr><td><code>src</code></td><td> 
 String containing the preferred source address to match. 
 Prefix matching is performed. 
</td></tr> 
<tr><td><code>dest_exact</code></td><td> 
 String containing the destination to match. Exact matching is performed, 
 e.g. <code>dest = "0.0.0.0/0"</code> would match <em>any</em> IPv4 route 
 while <code>dest_exact = "0.0.0.0/0"</code> will <em>only</em> match the 
 default route. 
</td></tr> 
<tr><td><code>from_exact</code></td><td> 
 String containing the source address to match. Exact matching is performed. 
</td></tr> 
</table>
	</li>
	
	<li>
	  callback: <p>Callback function to invoke for each found route 
instead of returning one table of route objects (optional)</p>
	</li>
	
</ul>




<h3>Usage:</h3>
<ul> 
<li>Find all IPv4 default routes: 
<pre>luci.ip.routes({ dest_exact = "0.0.0.0/0" }, function(rt) 
	print(rt.type, rt.gw, rt.dev) 
end)</pre></li> 
<li>Find all global IPv6 prefixes on the current system: 
<pre>luci.ip.routes({ from = "2001::/7" }, function(rt) 
	print(rt.from) 
end)</pre></li> 
<li>Fetch all IPv4 routes: 
<pre>routes = luci.ip.routes({ family = 4 }) 
for _, rt in ipairs(routes) do 
	print(rt.dest, rt.gw, rt.dev) 
end</pre></li> 
</ul>



<h3>Return value:</h3>
If no callback function is provided, a table of routes 
<a href="#routetable">as specified by <code>luci.ip.route()</code></a> 
is returned. If a callback function is given, it is invoked for each route 
and nothing is returned.



<h3>See also:</h3>
<ul>
	
	<li><a href="#route">
		route
	</a>
	
</ul>

</dd>




<dt><a name="neighbors"></a><strong>neighbors</strong>&nbsp;(filter, callback)</dt>
<dd>

 
Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table


<h3>Parameters</h3>
<ul>
	
	<li>
	  filter: <p>Table containing one or more of the possible filter 
criteria described below (optional)</p><table> 
<tr><th>Field</th><th>Description</th></tr> 
<tr><td><code>family</code></td><td> 
 Number describing the address family to return - <code>4</code> selects 
 IPv4 ARP, <code>6</code> select IPv6 neighbour entries. Any other value 
 selects both. 
</td></tr> 
<tr><td><code>dev</code></td><td> 
 String containing the associated interface to match. 
</td></tr> 
<tr><td><code>dest</code></td><td> 
 String containing the associated address to match. Can be in any notation 
 specified by <code>luci.ip.new()</code>. Prefix matching is performed when 
 comparing the addresses, e.g. "192.168.1.0/24" would select ARP entries 
 for <code>192.168.1.1 .. 192.168.1.255</code>. 
</td></tr> 
<tr><td><code>mac</code></td><td> 
 String containing MAC address to match. 
</td></tr> 
</table>
	</li>
	
	<li>
	  callback: <p>Callback function to invoke for each found neighbour 
entry instead of returning one table of neighbour entries (optional)</p>
	</li>
	
</ul>




<h3>Usage:</h3>
<ul> 
<li>Find all ARP neighbours in the LAN: 
<pre>luci.ip.neighbors({ dest = "192.168.0.0/16" }, function(n) 
	print(n.dest, n.mac) 
end)</pre></li> 
<li>Find all active IPv6 addresses of host with given MAC: 
<pre>luci.ip.neighbors({ family = 6, mac = "00:21:63:75:aa:17" }, 
	function(n) 
		print(n.dest) 
	end)</pre></li> 
</ul>



<h3>Return value:</h3>
If no callback function is provided, a table of neighbour entries 
is returned. If a callback function is given, it is invoked for each entry 
and nothing is returned. 
 
A neighbour entry is a table containing the following fields: 
 
<table> 
<tr><th>Field</th><th>Description</th></tr> 
<tr> 
  <td><code>family</code></td> 
  <td>Number containing the neighbour entry family, <code>4</code> for IPv4 
      ARP or <code>6</code> for IPv6 NDP</td> 
</tr> 
<tr> 
  <td><code>dev</code></td> 
  <td>String containing the associated device of the neighbour entry</td> 
</tr> 
<tr> 
  <td><code>dest</code></td> 
  <td>IP address <code>luci.ip.cidr</code> instance</td> 
</tr> 
<tr> 
  <td><code>mac</code></td> 
  <td>MAC address <code>luci.ip.cidr</code> instance</td> 
</tr> 
<tr> 
  <td><code>router</code></td> 
  <td>Boolean "true" if the neighbour entry is a router (IPv6, optional)</td> 
</tr> 
<tr> 
  <td><code>proxy</code></td> 
  <td>Boolean "true" if this is a proxy entry (optional)</td> 
</tr> 
<tr> 
  <td><code>incomplete</code></td> 
  <td>Boolean "true" if the entry is in incomplete state (optional)</td> 
</tr> 
<tr> 
  <td><code>reachable</code></td> 
  <td>Boolean "true" if the entry is in reachable state (optional)</td> 
</tr> 
<tr> 
  <td><code>stale</code></td> 
  <td>Boolean "true" if the entry is stale (optional)</td> 
</tr> 
<tr> 
  <td><code>delay</code></td> 
  <td>Boolean "true" if the entry is delayed (optional)</td> 
</tr> 
<tr> 
  <td><code>probe</code></td> 
  <td>Boolean "true" if the entry is in probe state (optional)</td> 
</tr> 
<tr> 
  <td><code>failed</code></td> 
  <td>Boolean "true" if the entry is in failed state (optional)</td> 
</tr> 
<tr> 
  <td><code>noarp</code></td> 
  <td>Boolean "true" if the entry is not caused by NDP or 
      ARP (optional)</td> 
</tr> 
<tr> 
  <td><code>permanent</code></td> 
  <td>Boolean "true" if the entry was statically configured from 
      userspace (optional)</td> 
</tr> 
</table>



</dd>




<dt><a name="link"></a><strong>link</strong>&nbsp;(device)</dt>
<dd>

 
Fetch basic device information


<h3>Parameters</h3>
<ul>
	
	<li>
	  device: String containing the network device to query
	</li>
	
</ul>




<h3>Usage:</h3>
<ul> 
<li>Test whether device br-lan exists: 
<pre>print(luci.ip.link("br-lan").name ~= nil) 
</pre></li> 
<li>Query MAC address of eth0: 
<pre>print(luci.ip.link("eth0").mac) 
</pre></li> 
</ul>



<h3>Return value:</h3>
If the given interface is found, a table containing the fields 
described below is returned, else an empty table. 
 
<table> 
<tr><th>Field</th><th>Description</th></tr> 
<tr> 
  <td><code>up</code></td> 
  <td>Boolean indicating whether the device is in IFF_RUNNING state</td> 
</tr> 
<tr> 
  <td><code>type</code></td> 
  <td>Numeric value indicating the type of the device, e.g. <code>1</code> 
      for ethernet.</td> 
</tr> 
<tr> 
  <td><code>name</code></td> 
  <td>String containing the name of the device</td> 
</tr> 
<tr> 
  <td><code>master</code></td> 
  <td>If queried device is a bridge port, string containing the name of 
      parent bridge device (optional)</td> 
</tr> 
<tr> 
  <td><code>mtu</code></td> 
  <td>Number containing the current MTU of the device</td> 
</tr> 
<tr> 
  <td><code>qlen</code></td> 
  <td>Number containing the TX queue length of the device</td> 
</tr> 
<tr> 
  <td><code>mac</code></td> 
  <td>MAC address <code>luci.ip.cidr</code> instance representing the device ethernet 
      address</td> 
</tr> 
</table>



</dd>


</dl>





</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
	<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>
</div> <!-- id="about" -->

</div> <!-- id="container" -->
</body>
</html>