luci.ip.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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. <body>
  10. <div id="container">
  11. <div id="product">
  12. <div id="product_logo"></div>
  13. <div id="product_name"><big><b></b></big></div>
  14. <div id="product_description"></div>
  15. </div> <!-- id="product" -->
  16. <div id="main">
  17. <div id="navigation">
  18. <h1>LuaDoc</h1>
  19. <ul>
  20. <li><a href="../index.html">Index</a></li>
  21. </ul>
  22. <!-- Module list -->
  23. <h1>Modules</h1>
  24. <ul>
  25. <li>
  26. <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
  27. </li>
  28. <li>
  29. <a href="../modules/luci.http.html">luci.http</a>
  30. </li>
  31. <li>
  32. <a href="../modules/luci.http.conditionals.html">luci.http.conditionals</a>
  33. </li>
  34. <li>
  35. <a href="../modules/luci.http.date.html">luci.http.date</a>
  36. </li>
  37. <li>
  38. <a href="../modules/luci.http.mime.html">luci.http.mime</a>
  39. </li>
  40. <li>
  41. <a href="../modules/luci.i18n.html">luci.i18n</a>
  42. </li>
  43. <li><strong>luci.ip</strong></li>
  44. <li>
  45. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  46. </li>
  47. <li>
  48. <a href="../modules/luci.json.html">luci.json</a>
  49. </li>
  50. <li>
  51. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  52. </li>
  53. <li>
  54. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  55. </li>
  56. <li>
  57. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  58. </li>
  59. <li>
  60. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  61. </li>
  62. <li>
  63. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  64. </li>
  65. <li>
  66. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  67. </li>
  68. <li>
  69. <a href="../modules/luci.sys.html">luci.sys</a>
  70. </li>
  71. <li>
  72. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  73. </li>
  74. <li>
  75. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  76. </li>
  77. <li>
  78. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  79. </li>
  80. <li>
  81. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  82. </li>
  83. <li>
  84. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  85. </li>
  86. <li>
  87. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  88. </li>
  89. <li>
  90. <a href="../modules/luci.util.html">luci.util</a>
  91. </li>
  92. <li>
  93. <a href="../modules/luci.xml.html">luci.xml</a>
  94. </li>
  95. <li>
  96. <a href="../modules/nixio.html">nixio</a>
  97. </li>
  98. <li>
  99. <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
  100. </li>
  101. <li>
  102. <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
  103. </li>
  104. <li>
  105. <a href="../modules/nixio.File.html">nixio.File</a>
  106. </li>
  107. <li>
  108. <a href="../modules/nixio.README.html">nixio.README</a>
  109. </li>
  110. <li>
  111. <a href="../modules/nixio.Socket.html">nixio.Socket</a>
  112. </li>
  113. <li>
  114. <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
  115. </li>
  116. <li>
  117. <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
  118. </li>
  119. <li>
  120. <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
  121. </li>
  122. <li>
  123. <a href="../modules/nixio.bin.html">nixio.bin</a>
  124. </li>
  125. <li>
  126. <a href="../modules/nixio.bit.html">nixio.bit</a>
  127. </li>
  128. <li>
  129. <a href="../modules/nixio.crypto.html">nixio.crypto</a>
  130. </li>
  131. <li>
  132. <a href="../modules/nixio.fs.html">nixio.fs</a>
  133. </li>
  134. </ul>
  135. <!-- File list -->
  136. </div><!-- id="navigation" -->
  137. <div id="content">
  138. <h1>Class <code>luci.ip</code></h1>
  139. <p>
  140. LuCI IP calculation and netlink access library.</p>
  141. <h2>Functions</h2>
  142. <table class="function_list">
  143. <tr>
  144. <td class="name" nowrap><a href="#new">new</a>&nbsp;(address, netmask)</td>
  145. <td class="summary">
  146. Construct a new luci.ip.cidr instance and autodetect the address family.</td>
  147. </tr>
  148. <tr>
  149. <td class="name" nowrap><a href="#IPv4">IPv4</a>&nbsp;(address, netmask)</td>
  150. <td class="summary">
  151. Construct a new IPv4 luci.ip.cidr instance.</td>
  152. </tr>
  153. <tr>
  154. <td class="name" nowrap><a href="#IPv6">IPv6</a>&nbsp;(address, netmask)</td>
  155. <td class="summary">
  156. Construct a new IPv6 luci.ip.cidr instance.</td>
  157. </tr>
  158. <tr>
  159. <td class="name" nowrap><a href="#MAC">MAC</a>&nbsp;(address, netmask)</td>
  160. <td class="summary">
  161. Construct a new MAC luci.ip.cidr instance.</td>
  162. </tr>
  163. <tr>
  164. <td class="name" nowrap><a href="#checkip4">checkip4</a>&nbsp;(address)</td>
  165. <td class="summary">
  166. Verify an IPv4 address.</td>
  167. </tr>
  168. <tr>
  169. <td class="name" nowrap><a href="#checkip6">checkip6</a>&nbsp;(address)</td>
  170. <td class="summary">
  171. Verify an IPv6 address.</td>
  172. </tr>
  173. <tr>
  174. <td class="name" nowrap><a href="#checkmac">checkmac</a>&nbsp;(address)</td>
  175. <td class="summary">
  176. Verify an ethernet MAC address.</td>
  177. </tr>
  178. <tr>
  179. <td class="name" nowrap><a href="#route">route</a>&nbsp;(address, source)</td>
  180. <td class="summary">
  181. Determine the route leading to the given destination.</td>
  182. </tr>
  183. <tr>
  184. <td class="name" nowrap><a href="#routes">routes</a>&nbsp;(filter, callback)</td>
  185. <td class="summary">
  186. Fetch all routes, optionally matching the given criteria.</td>
  187. </tr>
  188. <tr>
  189. <td class="name" nowrap><a href="#neighbors">neighbors</a>&nbsp;(filter, callback)</td>
  190. <td class="summary">
  191. Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table </td>
  192. </tr>
  193. <tr>
  194. <td class="name" nowrap><a href="#link">link</a>&nbsp;(device)</td>
  195. <td class="summary">
  196. Fetch basic device information </td>
  197. </tr>
  198. </table>
  199. <br/>
  200. <br/>
  201. <h2><a name="functions"></a>Functions</h2>
  202. <dl class="function">
  203. <dt><a name="new"></a><strong>new</strong>&nbsp;(address, netmask)</dt>
  204. <dd>
  205. Construct a new luci.ip.cidr instance and autodetect the address family.
  206. Throws an error if the given strings do not represent a valid address or
  207. if the given optional netmask is of a different family.
  208. <h3>Parameters</h3>
  209. <ul>
  210. <li>
  211. address: String containing a valid IPv4 or IPv6 address, optionally
  212. with prefix size (CIDR notation) or netmask separated by slash.
  213. </li>
  214. <li>
  215. netmask: String containing a valid IPv4 or IPv6 netmask or number
  216. containing a prefix size in bits (<code>0..32</code> for IPv4,
  217. <code>0..128</code> for IPv6). Overrides mask embedded in the first argument
  218. if specified. (optional)
  219. </li>
  220. </ul>
  221. <h3>Usage:</h3>
  222. <pre>addr = luci.ip.new("10.24.0.1/24")
  223. addr = luci.ip.new("10.24.0.1/255.255.255.0")
  224. addr = luci.ip.new("10.24.0.1", "255.255.255.0") -- separate netmask
  225. addr = luci.ip.new("10.24.0.1/24", 16) -- override netmask
  226. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64")
  227. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::")
  228. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::")
  229. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
  230. <h3>Return value:</h3>
  231. A <code>luci.ip.cidr</code> object representing the given
  232. address/mask range.
  233. <h3>See also:</h3>
  234. <ul>
  235. <li><a href="#IPv4">
  236. IPv4
  237. </a>
  238. <li><a href="#IPv6">
  239. IPv6
  240. </a>
  241. <li><a href="#MAC">
  242. MAC
  243. </a>
  244. </ul>
  245. </dd>
  246. <dt><a name="IPv4"></a><strong>IPv4</strong>&nbsp;(address, netmask)</dt>
  247. <dd>
  248. Construct a new IPv4 luci.ip.cidr instance.
  249. Throws an error if the given string does not represent a valid IPv4 address or
  250. if the given optional netmask is of a different family.
  251. <h3>Parameters</h3>
  252. <ul>
  253. <li>
  254. address: String containing a valid IPv4, optionally with prefix size
  255. (CIDR notation) or netmask separated by slash.
  256. </li>
  257. <li>
  258. netmask: String containing a valid IPv4 netmask or number
  259. containing a prefix size between <code>0</code> and <code>32</code> bit.
  260. Overrides mask embedded in the first argument if specified. (optional)
  261. </li>
  262. </ul>
  263. <h3>Usage:</h3>
  264. <pre>addr = luci.ip.IPv4("10.24.0.1/24")
  265. addr = luci.ip.IPv4("10.24.0.1/255.255.255.0")
  266. addr = luci.ip.IPv4("10.24.0.1", "255.255.255.0") -- separate netmask
  267. addr = luci.ip.IPv4("10.24.0.1/24", 16) -- override netmask</pre>
  268. <h3>Return value:</h3>
  269. A <code>luci.ip.cidr</code> object representing the given IPv4 range.
  270. <h3>See also:</h3>
  271. <ul>
  272. <li><a href="#IPv6">
  273. IPv6
  274. </a>
  275. <li><a href="#MAC">
  276. MAC
  277. </a>
  278. </ul>
  279. </dd>
  280. <dt><a name="IPv6"></a><strong>IPv6</strong>&nbsp;(address, netmask)</dt>
  281. <dd>
  282. Construct a new IPv6 luci.ip.cidr instance.
  283. Throws an error if the given string does not represent a valid IPv6 address or
  284. if the given optional netmask is of a different family.
  285. <h3>Parameters</h3>
  286. <ul>
  287. <li>
  288. address: String containing a valid IPv6, optionally with prefix size
  289. (CIDR notation) or netmask separated by slash.
  290. </li>
  291. <li>
  292. netmask: String containing a valid IPv4 netmask or number
  293. containing a prefix size between <code>0</code> and <code>128</code> bit.
  294. Overrides mask embedded in the first argument if specified. (optional)
  295. </li>
  296. </ul>
  297. <h3>Usage:</h3>
  298. <pre>addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64")
  299. addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::")
  300. addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::")
  301. addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
  302. <h3>Return value:</h3>
  303. A <code>luci.ip.cidr</code> object representing the given IPv6 range.
  304. <h3>See also:</h3>
  305. <ul>
  306. <li><a href="#IPv4">
  307. IPv4
  308. </a>
  309. <li><a href="#MAC">
  310. MAC
  311. </a>
  312. </ul>
  313. </dd>
  314. <dt><a name="MAC"></a><strong>MAC</strong>&nbsp;(address, netmask)</dt>
  315. <dd>
  316. Construct a new MAC luci.ip.cidr instance.
  317. Throws an error if the given string does not represent a valid ethernet MAC
  318. address or if the given optional mask is of a different family.
  319. <h3>Parameters</h3>
  320. <ul>
  321. <li>
  322. address: String containing a valid ethernet MAC address, optionally with
  323. prefix size (CIDR notation) or mask separated by slash.
  324. </li>
  325. <li>
  326. netmask: String containing a valid MAC address mask or number
  327. containing a prefix size between <code>0</code> and <code>48</code> bit.
  328. Overrides mask embedded in the first argument if specified. (optional)
  329. </li>
  330. </ul>
  331. <h3>Usage:</h3>
  332. <pre>intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24")
  333. intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/FF:FF:FF:0:0:0")
  334. intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00", "FF:FF:FF:0:0:0")
  335. intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24", 48) -- override mask</pre>
  336. <h3>Return value:</h3>
  337. A <code>luci.ip.cidr</code> object representing the given MAC address range.
  338. <h3>See also:</h3>
  339. <ul>
  340. <li><a href="#IPv4">
  341. IPv4
  342. </a>
  343. <li><a href="#IPv6">
  344. IPv6
  345. </a>
  346. </ul>
  347. </dd>
  348. <dt><a name="checkip4"></a><strong>checkip4</strong>&nbsp;(address)</dt>
  349. <dd>
  350. Verify an IPv4 address.
  351. Checks whether given argument is a preexisting luci.ip.cidr IPv4 address
  352. instance or a string literal convertible to an IPv4 address and returns a
  353. plain Lua string containing the canonical representation of the address.
  354. If the argument is not a valid address, returns nothing. This function is
  355. intended to aid in safely verifying address literals without having to deal
  356. with exceptions.
  357. <h3>Parameters</h3>
  358. <ul>
  359. <li>
  360. address: String containing a valid IPv4 address or existing
  361. luci.ip.cidr IPv4 instance.
  362. </li>
  363. </ul>
  364. <h3>Usage:</h3>
  365. <pre>ipv4 = luci.ip.checkip4(luci.ip.new("127.0.0.1")) -- "127.0.0.1"
  366. ipv4 = luci.ip.checkip4("127.0.0.1") -- "127.0.0.1"
  367. ipv4 = luci.ip.checkip4("nonesense") -- nothing
  368. ipv4 = luci.ip.checkip4(123) -- nothing
  369. ipv4 = luci.ip.checkip4(nil) -- nothing
  370. ipv4 = luci.ip.checkip4() -- nothing</pre>
  371. <h3>Return value:</h3>
  372. A string representing the given IPv4 address.
  373. <h3>See also:</h3>
  374. <ul>
  375. <li><a href="#checkip6">
  376. checkip6
  377. </a>
  378. <li><a href="#checkmac">
  379. checkmac
  380. </a>
  381. </ul>
  382. </dd>
  383. <dt><a name="checkip6"></a><strong>checkip6</strong>&nbsp;(address)</dt>
  384. <dd>
  385. Verify an IPv6 address.
  386. Checks whether given argument is a preexisting luci.ip.cidr IPv6 address
  387. instance or a string literal convertible to an IPv6 address and returns a
  388. plain Lua string containing the canonical representation of the address.
  389. If the argument is not a valid address, returns nothing. This function is
  390. intended to aid in safely verifying address literals without having to deal
  391. with exceptions.
  392. <h3>Parameters</h3>
  393. <ul>
  394. <li>
  395. address: String containing a valid IPv6 address or existing
  396. luci.ip.cidr IPv6 instance.
  397. </li>
  398. </ul>
  399. <h3>Usage:</h3>
  400. <pre>ipv6 = luci.ip.checkip6(luci.ip.new("0:0:0:0:0:0:0:1")) -- "::1"
  401. ipv6 = luci.ip.checkip6("0:0:0:0:0:0:0:1") -- "::1"
  402. ipv6 = luci.ip.checkip6("nonesense") -- nothing
  403. ipv6 = luci.ip.checkip6(123) -- nothing
  404. ipv6 = luci.ip.checkip6(nil) -- nothing
  405. ipv6 = luci.ip.checkip6() -- nothing</pre>
  406. <h3>Return value:</h3>
  407. A string representing the given IPv6 address.
  408. <h3>See also:</h3>
  409. <ul>
  410. <li><a href="#checkip4">
  411. checkip4
  412. </a>
  413. <li><a href="#checkmac">
  414. checkmac
  415. </a>
  416. </ul>
  417. </dd>
  418. <dt><a name="checkmac"></a><strong>checkmac</strong>&nbsp;(address)</dt>
  419. <dd>
  420. Verify an ethernet MAC address.
  421. Checks whether given argument is a preexisting luci.ip.cidr MAC address
  422. instance or a string literal convertible to an ethernet MAC and returns a
  423. plain Lua string containing the canonical representation of the address.
  424. If the argument is not a valid address, returns nothing. This function is
  425. intended to aid in safely verifying address literals without having to deal
  426. with exceptions.
  427. <h3>Parameters</h3>
  428. <ul>
  429. <li>
  430. address: String containing a valid MAC address or existing luci.ip.cidr
  431. MAC address instance.
  432. </li>
  433. </ul>
  434. <h3>Usage:</h3>
  435. <pre>mac = luci.ip.checkmac(luci.ip.new("00-11-22-cc-dd-ee")) -- "00:11:22:CC:DD:EE"
  436. mac = luci.ip.checkmac("00:11:22:cc:dd:ee") -- "00:11:22:CC:DD:EE"
  437. mac = luci.ip.checkmac("nonesense") -- nothing
  438. mac = luci.ip.checkmac(123) -- nothing
  439. mac = luci.ip.checkmac(nil) -- nothing
  440. mac = luci.ip.checkmac() -- nothing</pre>
  441. <h3>Return value:</h3>
  442. A string representing the given MAC address.
  443. <h3>See also:</h3>
  444. <ul>
  445. <li><a href="#checkip4">
  446. checkip4
  447. </a>
  448. <li><a href="#checkip6">
  449. checkip6
  450. </a>
  451. </ul>
  452. </dd>
  453. <dt><a name="route"></a><strong>route</strong>&nbsp;(address, source)</dt>
  454. <dd>
  455. Determine the route leading to the given destination.
  456. <h3>Parameters</h3>
  457. <ul>
  458. <li>
  459. address: A <code>luci.ip.cidr</code> instance or a string containing
  460. a valid IPv4 or IPv6 range as specified by <code>luci.ip.new()</code>.
  461. </li>
  462. <li>
  463. source: A <code>luci.ip.cidr</code> instance or a string containing
  464. the preferred source address for route selection (optional).
  465. </li>
  466. </ul>
  467. <h3>Usage:</h3>
  468. <ul>
  469. <li>Find default gateway by getting route to Google's public NS server
  470. <pre>rt = luci.ip.route("8.8.8.8")
  471. if rt ~= nil then
  472. print("gateway is", rt.gw)
  473. end</pre></li>
  474. <li>Determine IPv6 upstream interface <pre>rt = luci.ip.route("2001::/7")
  475. if rt ~= nil then
  476. print("ipv6 upstream device is", rt.dev)
  477. end</pre></li>
  478. </ul>
  479. <h3>Return value:</h3>
  480. <p>Table containing the fields described below.</p>
  481. <table id="routetable">
  482. <tr><th>Field</th><th>Description</th></tr>
  483. <tr><td><code>type</code><td>
  484. <p>Route type with one of the following numeric values:</p>
  485. <table>
  486. <tr>
  487. <td><code>1</code></td>
  488. <td><code>RTN_UNICAST</code> - Gateway or direct route</td>
  489. </tr>
  490. <tr>
  491. <td><code>2</code></td>
  492. <td><code>RTN_LOCAL</code> - Accept locally</td>
  493. </tr>
  494. <tr>
  495. <td><code>3</code></td>
  496. <td><code>RTN_BROADCAST</code> -
  497. Accept locally as broadcast send as broadcast</td>
  498. </tr>
  499. <tr>
  500. <td><code>4</code></td>
  501. <td><code>RTN_ANYCAST</code> -
  502. Accept locally as broadcast but send as unicast</td>
  503. </tr>
  504. <tr>
  505. <td><code>5</code></td>
  506. <td><code>RTN_MULTICAST</code> - Multicast route</td>
  507. </tr>
  508. </table>
  509. </td></tr>
  510. <tr>
  511. <td><code>family</code></td>
  512. <td>Number containing the route family, <code>4</code> for IPv4 or
  513. <code>6</code> for IPv6</td>
  514. </tr>
  515. <tr>
  516. <td><code>dest</code></td>
  517. <td>Destination <code>luci.ip.cidr</code> instance</td>
  518. </tr>
  519. <tr>
  520. <td><code>gw</code></td>
  521. <td>Gateway <code>luci.ip.cidr</code> instance (optional)</td>
  522. </tr>
  523. <tr>
  524. <td><code>from</code></td>
  525. <td>Source address <code>luci.ip.cidr</code> instance (optional)</td>
  526. </tr>
  527. <tr>
  528. <td><code>src</code></td>
  529. <td>Preferred source <code>luci.ip.cidr</code> instance (optional)</td>
  530. </tr>
  531. <tr>
  532. <td><code>dev</code></td>
  533. <td>String containing the name of the outgoing interface</td>
  534. </tr>
  535. <tr>
  536. <td><code>iif</code></td>
  537. <td>String containing the name of the incoming interface (optional)</td>
  538. </tr>
  539. <tr>
  540. <td><code>table</code></td>
  541. <td>Number of the associated routing table (<code>0..65535</code>)</td>
  542. </tr>
  543. <tr>
  544. <td><code>proto</code></td>
  545. <td>Number of the associated routing protocol</td>
  546. </tr>
  547. <tr>
  548. <td><code>scope</code></td>
  549. <td>Number describing the scope of the route, most commonly
  550. <code>0</code> for global or <code>253</code> for on-link</td>
  551. </tr>
  552. <tr>
  553. <td><code>metric</code></td>
  554. <td>Number describing the route metric (optional)</td>
  555. </tr>
  556. <tr>
  557. <td><code>expires</code></td>
  558. <td>Number of seconds the prefix is valid (IPv6 only, optional)</td>
  559. </tr>
  560. <tr>
  561. <td><code>error</code></td>
  562. <td>Route destination error code (optional)</td>
  563. </tr>
  564. </table>
  565. <h3>See also:</h3>
  566. <ul>
  567. <li><a href="#routes">
  568. routes
  569. </a>
  570. </ul>
  571. </dd>
  572. <dt><a name="routes"></a><strong>routes</strong>&nbsp;(filter, callback)</dt>
  573. <dd>
  574. Fetch all routes, optionally matching the given criteria.
  575. <h3>Parameters</h3>
  576. <ul>
  577. <li>
  578. filter: <p>Table containing one or more of the possible filter
  579. criteria described below (optional)</p><table>
  580. <tr><th>Field</th><th>Description</th></tr>
  581. <tr><td><code>family</code></td><td>
  582. Number describing the address family to return - <code>4</code> selects
  583. IPv4 routes, <code>6</code> IPv6 ones. Any other value selects both.
  584. </td></tr>
  585. <tr><td><code>iif</code></td><td>
  586. String containing the incoming route interface to match.
  587. </td></tr>
  588. <tr><td><code>oif</code></td><td>
  589. String containing the outgoing route interface to match.
  590. </td></tr>
  591. <tr><td><code>type</code></td><td>
  592. Numeric type to match, e.g. <code>1</code> for unicast.
  593. </td></tr>
  594. <tr><td><code>scope</code></td><td>
  595. Numeric scope to match, e.g. <code>253</code> for onlink.
  596. </td></tr>
  597. <tr><td><code>proto</code></td><td>
  598. Numeric protocol to match, e.g. <code>2</code> for boot.
  599. </td></tr>
  600. <tr><td><code>table</code></td><td>
  601. Numeric routing table to match (<code>0..65535</code>).
  602. </td></tr>
  603. <tr><td><code>gw</code></td><td>
  604. String containing the gateway address to match. Can be in any notation
  605. specified by <code>luci.ip.new()</code>. Prefix matching is performed when
  606. comparing the routes, e.g. "192.168.1.0/24" would select routes with gateway
  607. addresses <code>192.168.1.1 .. 192.168.1.255</code>.
  608. </td></tr>
  609. <tr><td><code>dest</code></td><td>
  610. String containing the destination to match. Prefix matching is performed.
  611. </td></tr>
  612. <tr><td><code>from</code></td><td>
  613. String containing the source address to match. Prefix matching is performed.
  614. </td></tr>
  615. <tr><td><code>src</code></td><td>
  616. String containing the preferred source address to match.
  617. Prefix matching is performed.
  618. </td></tr>
  619. <tr><td><code>dest_exact</code></td><td>
  620. String containing the destination to match. Exact matching is performed,
  621. e.g. <code>dest = "0.0.0.0/0"</code> would match <em>any</em> IPv4 route
  622. while <code>dest_exact = "0.0.0.0/0"</code> will <em>only</em> match the
  623. default route.
  624. </td></tr>
  625. <tr><td><code>from_exact</code></td><td>
  626. String containing the source address to match. Exact matching is performed.
  627. </td></tr>
  628. </table>
  629. </li>
  630. <li>
  631. callback: <p>Callback function to invoke for each found route
  632. instead of returning one table of route objects (optional)</p>
  633. </li>
  634. </ul>
  635. <h3>Usage:</h3>
  636. <ul>
  637. <li>Find all IPv4 default routes:
  638. <pre>luci.ip.routes({ dest_exact = "0.0.0.0/0" }, function(rt)
  639. print(rt.type, rt.gw, rt.dev)
  640. end)</pre></li>
  641. <li>Find all global IPv6 prefixes on the current system:
  642. <pre>luci.ip.routes({ from = "2001::/7" }, function(rt)
  643. print(rt.from)
  644. end)</pre></li>
  645. <li>Fetch all IPv4 routes:
  646. <pre>routes = luci.ip.routes({ family = 4 })
  647. for _, rt in ipairs(routes) do
  648. print(rt.dest, rt.gw, rt.dev)
  649. end</pre></li>
  650. </ul>
  651. <h3>Return value:</h3>
  652. If no callback function is provided, a table of routes
  653. <a href="#routetable">as specified by <code>luci.ip.route()</code></a>
  654. is returned. If a callback function is given, it is invoked for each route
  655. and nothing is returned.
  656. <h3>See also:</h3>
  657. <ul>
  658. <li><a href="#route">
  659. route
  660. </a>
  661. </ul>
  662. </dd>
  663. <dt><a name="neighbors"></a><strong>neighbors</strong>&nbsp;(filter, callback)</dt>
  664. <dd>
  665. Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table
  666. <h3>Parameters</h3>
  667. <ul>
  668. <li>
  669. filter: <p>Table containing one or more of the possible filter
  670. criteria described below (optional)</p><table>
  671. <tr><th>Field</th><th>Description</th></tr>
  672. <tr><td><code>family</code></td><td>
  673. Number describing the address family to return - <code>4</code> selects
  674. IPv4 ARP, <code>6</code> select IPv6 neighbour entries. Any other value
  675. selects both.
  676. </td></tr>
  677. <tr><td><code>dev</code></td><td>
  678. String containing the associated interface to match.
  679. </td></tr>
  680. <tr><td><code>dest</code></td><td>
  681. String containing the associated address to match. Can be in any notation
  682. specified by <code>luci.ip.new()</code>. Prefix matching is performed when
  683. comparing the addresses, e.g. "192.168.1.0/24" would select ARP entries
  684. for <code>192.168.1.1 .. 192.168.1.255</code>.
  685. </td></tr>
  686. <tr><td><code>mac</code></td><td>
  687. String containing MAC address to match.
  688. </td></tr>
  689. </table>
  690. </li>
  691. <li>
  692. callback: <p>Callback function to invoke for each found neighbour
  693. entry instead of returning one table of neighbour entries (optional)</p>
  694. </li>
  695. </ul>
  696. <h3>Usage:</h3>
  697. <ul>
  698. <li>Find all ARP neighbours in the LAN:
  699. <pre>luci.ip.neighbors({ dest = "192.168.0.0/16" }, function(n)
  700. print(n.dest, n.mac)
  701. end)</pre></li>
  702. <li>Find all active IPv6 addresses of host with given MAC:
  703. <pre>luci.ip.neighbors({ family = 6, mac = "00:21:63:75:aa:17" },
  704. function(n)
  705. print(n.dest)
  706. end)</pre></li>
  707. </ul>
  708. <h3>Return value:</h3>
  709. If no callback function is provided, a table of neighbour entries
  710. is returned. If a callback function is given, it is invoked for each entry
  711. and nothing is returned.
  712. A neighbour entry is a table containing the following fields:
  713. <table>
  714. <tr><th>Field</th><th>Description</th></tr>
  715. <tr>
  716. <td><code>family</code></td>
  717. <td>Number containing the neighbour entry family, <code>4</code> for IPv4
  718. ARP or <code>6</code> for IPv6 NDP</td>
  719. </tr>
  720. <tr>
  721. <td><code>dev</code></td>
  722. <td>String containing the associated device of the neighbour entry</td>
  723. </tr>
  724. <tr>
  725. <td><code>dest</code></td>
  726. <td>IP address <code>luci.ip.cidr</code> instance</td>
  727. </tr>
  728. <tr>
  729. <td><code>mac</code></td>
  730. <td>MAC address <code>luci.ip.cidr</code> instance</td>
  731. </tr>
  732. <tr>
  733. <td><code>router</code></td>
  734. <td>Boolean "true" if the neighbour entry is a router (IPv6, optional)</td>
  735. </tr>
  736. <tr>
  737. <td><code>proxy</code></td>
  738. <td>Boolean "true" if this is a proxy entry (optional)</td>
  739. </tr>
  740. <tr>
  741. <td><code>incomplete</code></td>
  742. <td>Boolean "true" if the entry is in incomplete state (optional)</td>
  743. </tr>
  744. <tr>
  745. <td><code>reachable</code></td>
  746. <td>Boolean "true" if the entry is in reachable state (optional)</td>
  747. </tr>
  748. <tr>
  749. <td><code>stale</code></td>
  750. <td>Boolean "true" if the entry is stale (optional)</td>
  751. </tr>
  752. <tr>
  753. <td><code>delay</code></td>
  754. <td>Boolean "true" if the entry is delayed (optional)</td>
  755. </tr>
  756. <tr>
  757. <td><code>probe</code></td>
  758. <td>Boolean "true" if the entry is in probe state (optional)</td>
  759. </tr>
  760. <tr>
  761. <td><code>failed</code></td>
  762. <td>Boolean "true" if the entry is in failed state (optional)</td>
  763. </tr>
  764. <tr>
  765. <td><code>noarp</code></td>
  766. <td>Boolean "true" if the entry is not caused by NDP or
  767. ARP (optional)</td>
  768. </tr>
  769. <tr>
  770. <td><code>permanent</code></td>
  771. <td>Boolean "true" if the entry was statically configured from
  772. userspace (optional)</td>
  773. </tr>
  774. </table>
  775. </dd>
  776. <dt><a name="link"></a><strong>link</strong>&nbsp;(device)</dt>
  777. <dd>
  778. Fetch basic device information
  779. <h3>Parameters</h3>
  780. <ul>
  781. <li>
  782. device: String containing the network device to query
  783. </li>
  784. </ul>
  785. <h3>Usage:</h3>
  786. <ul>
  787. <li>Test whether device br-lan exists:
  788. <pre>print(luci.ip.link("br-lan").name ~= nil)
  789. </pre></li>
  790. <li>Query MAC address of eth0:
  791. <pre>print(luci.ip.link("eth0").mac)
  792. </pre></li>
  793. </ul>
  794. <h3>Return value:</h3>
  795. If the given interface is found, a table containing the fields
  796. described below is returned, else an empty table.
  797. <table>
  798. <tr><th>Field</th><th>Description</th></tr>
  799. <tr>
  800. <td><code>up</code></td>
  801. <td>Boolean indicating whether the device is in IFF_RUNNING state</td>
  802. </tr>
  803. <tr>
  804. <td><code>type</code></td>
  805. <td>Numeric value indicating the type of the device, e.g. <code>1</code>
  806. for ethernet.</td>
  807. </tr>
  808. <tr>
  809. <td><code>name</code></td>
  810. <td>String containing the name of the device</td>
  811. </tr>
  812. <tr>
  813. <td><code>master</code></td>
  814. <td>If queried device is a bridge port, string containing the name of
  815. parent bridge device (optional)</td>
  816. </tr>
  817. <tr>
  818. <td><code>mtu</code></td>
  819. <td>Number containing the current MTU of the device</td>
  820. </tr>
  821. <tr>
  822. <td><code>qlen</code></td>
  823. <td>Number containing the TX queue length of the device</td>
  824. </tr>
  825. <tr>
  826. <td><code>mac</code></td>
  827. <td>MAC address <code>luci.ip.cidr</code> instance representing the device ethernet
  828. address</td>
  829. </tr>
  830. </table>
  831. </dd>
  832. </dl>
  833. </div> <!-- id="content" -->
  834. </div> <!-- id="main" -->
  835. <div id="about">
  836. <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>
  837. </div> <!-- id="about" -->
  838. </div> <!-- id="container" -->
  839. </body>
  840. </html>