2
0

luci.ip.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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.protocol.html">luci.http.protocol</a>
  33. </li>
  34. <li>
  35. <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
  36. </li>
  37. <li>
  38. <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
  39. </li>
  40. <li>
  41. <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
  42. </li>
  43. <li>
  44. <a href="../modules/luci.i18n.html">luci.i18n</a>
  45. </li>
  46. <li><strong>luci.ip</strong></li>
  47. <li>
  48. <a href="../modules/luci.ip.cidr.html">luci.ip.cidr</a>
  49. </li>
  50. <li>
  51. <a href="../modules/luci.json.html">luci.json</a>
  52. </li>
  53. <li>
  54. <a href="../modules/luci.jsonc.html">luci.jsonc</a>
  55. </li>
  56. <li>
  57. <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
  58. </li>
  59. <li>
  60. <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
  61. </li>
  62. <li>
  63. <a href="../modules/luci.model.uci.html">luci.model.uci</a>
  64. </li>
  65. <li>
  66. <a href="../modules/luci.rpcc.html">luci.rpcc</a>
  67. </li>
  68. <li>
  69. <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
  70. </li>
  71. <li>
  72. <a href="../modules/luci.sys.html">luci.sys</a>
  73. </li>
  74. <li>
  75. <a href="../modules/luci.sys.init.html">luci.sys.init</a>
  76. </li>
  77. <li>
  78. <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
  79. </li>
  80. <li>
  81. <a href="../modules/luci.sys.net.html">luci.sys.net</a>
  82. </li>
  83. <li>
  84. <a href="../modules/luci.sys.process.html">luci.sys.process</a>
  85. </li>
  86. <li>
  87. <a href="../modules/luci.sys.user.html">luci.sys.user</a>
  88. </li>
  89. <li>
  90. <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
  91. </li>
  92. <li>
  93. <a href="../modules/luci.util.html">luci.util</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="#route">route</a>&nbsp;(address)</td>
  160. <td class="summary">
  161. Determine the route leading to the given destination.</td>
  162. </tr>
  163. <tr>
  164. <td class="name" nowrap><a href="#routes">routes</a>&nbsp;(filter, callback)</td>
  165. <td class="summary">
  166. Fetch all routes, optionally matching the given criteria.</td>
  167. </tr>
  168. <tr>
  169. <td class="name" nowrap><a href="#neighbors">neighbors</a>&nbsp;(filter, callback)</td>
  170. <td class="summary">
  171. Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table </td>
  172. </tr>
  173. <tr>
  174. <td class="name" nowrap><a href="#link">link</a>&nbsp;(device)</td>
  175. <td class="summary">
  176. Fetch basic device information </td>
  177. </tr>
  178. </table>
  179. <br/>
  180. <br/>
  181. <h2><a name="functions"></a>Functions</h2>
  182. <dl class="function">
  183. <dt><a name="new"></a><strong>new</strong>&nbsp;(address, netmask)</dt>
  184. <dd>
  185. Construct a new luci.ip.cidr instance and autodetect the address family.
  186. Throws an error if the given strings do not represent a valid address or
  187. if the given optional netmask is of a different family.
  188. <h3>Parameters</h3>
  189. <ul>
  190. <li>
  191. address: String containing a valid IPv4 or IPv6 address, optionally
  192. with prefix size (CIDR notation) or netmask separated by slash.
  193. </li>
  194. <li>
  195. netmask: String containing a valid IPv4 or IPv6 netmask or number
  196. containing a prefix size in bits (<code>0..32</code> for IPv4,
  197. <code>0..128</code> for IPv6). Overrides mask embedded in the first argument
  198. if specified. (optional)
  199. </li>
  200. </ul>
  201. <h3>Usage:</h3>
  202. <pre>addr = luci.ip.new("10.24.0.1/24")
  203. addr = luci.ip.new("10.24.0.1/255.255.255.0")
  204. addr = luci.ip.new("10.24.0.1", "255.255.255.0") -- separate netmask
  205. addr = luci.ip.new("10.24.0.1/24", 16) -- override netmask
  206. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64")
  207. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::")
  208. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::")
  209. addr6 = luci.ip.new("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
  210. <h3>Return value:</h3>
  211. A <code>luci.ip.cidr</code> object representing the given
  212. address/mask range.
  213. <h3>See also:</h3>
  214. <ul>
  215. <li><a href="#IPv4">
  216. IPv4
  217. </a>
  218. <li><a href="#IPv6">
  219. IPv6
  220. </a>
  221. </ul>
  222. </dd>
  223. <dt><a name="IPv4"></a><strong>IPv4</strong>&nbsp;(address, netmask)</dt>
  224. <dd>
  225. Construct a new IPv4 luci.ip.cidr instance.
  226. Throws an error if the given string does not represent a valid IPv4 address or
  227. if the given optional netmask is of a different family.
  228. <h3>Parameters</h3>
  229. <ul>
  230. <li>
  231. address: String containing a valid IPv4, optionally with prefix size
  232. (CIDR notation) or netmask separated by slash.
  233. </li>
  234. <li>
  235. netmask: String containing a valid IPv4 netmask or number
  236. containing a prefix size between <code>0</code> and <code>32</code> bit.
  237. Overrides mask embedded in the first argument if specified. (optional)
  238. </li>
  239. </ul>
  240. <h3>Usage:</h3>
  241. <pre>addr = luci.ip.IPv4("10.24.0.1/24")
  242. addr = luci.ip.IPv4("10.24.0.1/255.255.255.0")
  243. addr = luci.ip.IPv4("10.24.0.1", "255.255.255.0") -- separate netmask
  244. addr = luci.ip.IPv4("10.24.0.1/24", 16) -- override netmask</pre>
  245. <h3>Return value:</h3>
  246. A <code>luci.ip.cidr</code> object representing the given IPv4 range.
  247. <h3>See also:</h3>
  248. <ul>
  249. <li><a href="#IPv6">
  250. IPv6
  251. </a>
  252. </ul>
  253. </dd>
  254. <dt><a name="IPv6"></a><strong>IPv6</strong>&nbsp;(address, netmask)</dt>
  255. <dd>
  256. Construct a new IPv6 luci.ip.cidr instance.
  257. Throws an error if the given string does not represent a valid IPv6 address or
  258. if the given optional netmask is of a different family.
  259. <h3>Parameters</h3>
  260. <ul>
  261. <li>
  262. address: String containing a valid IPv6, optionally with prefix size
  263. (CIDR notation) or netmask separated by slash.
  264. </li>
  265. <li>
  266. netmask: String containing a valid IPv4 netmask or number
  267. containing a prefix size between <code>0</code> and <code>128</code> bit.
  268. Overrides mask embedded in the first argument if specified. (optional)
  269. </li>
  270. </ul>
  271. <h3>Usage:</h3>
  272. <pre>addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64")
  273. addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/ffff:ffff:ffff:ffff::")
  274. addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17", "ffff:ffff:ffff:ffff::")
  275. addr6 = luci.ip.IPv6("fe80::221:63ff:fe75:aa17/64", 128) -- override netmask</pre>
  276. <h3>Return value:</h3>
  277. A <code>luci.ip.cidr</code> object representing the given IPv6 range.
  278. <h3>See also:</h3>
  279. <ul>
  280. <li><a href="#IPv4">
  281. IPv4
  282. </a>
  283. </ul>
  284. </dd>
  285. <dt><a name="route"></a><strong>route</strong>&nbsp;(address)</dt>
  286. <dd>
  287. Determine the route leading to the given destination.
  288. <h3>Parameters</h3>
  289. <ul>
  290. <li>
  291. address: A <code>luci.ip.cidr</code> instance or a string containing
  292. a valid IPv4 or IPv6 range as specified by <code>luci.ip.new()</code>.
  293. </li>
  294. </ul>
  295. <h3>Usage:</h3>
  296. <ul>
  297. <li>Find default gateway by getting route to Google's public NS server
  298. <pre>rt = luci.ip.route("8.8.8.8")
  299. if rt ~= nil then
  300. print("gateway is", rt.gw)
  301. end</pre></li>
  302. <li>Determine IPv6 upstream interface <pre>rt = luci.ip.route("2001::/7")
  303. if rt ~= nil then
  304. print("ipv6 upstream device is", rt.dev)
  305. end</pre></li>
  306. </ul>
  307. <h3>Return value:</h3>
  308. <p>Table containing the fields described below.</p>
  309. <table id="routetable">
  310. <tr><th>Field</th><th>Description</th></tr>
  311. <tr><td><code>type</code><td>
  312. <p>Route type with one of the following numeric values:</p>
  313. <table>
  314. <tr>
  315. <td><code>1</code></td>
  316. <td><code>RTN_UNICAST</code> - Gateway or direct route</td>
  317. </tr>
  318. <tr>
  319. <td><code>2</code></td>
  320. <td><code>RTN_LOCAL</code> - Accept locally</td>
  321. </tr>
  322. <tr>
  323. <td><code>3</code></td>
  324. <td><code>RTN_BROADCAST</code> -
  325. Accept locally as broadcast send as broadcast</td>
  326. </tr>
  327. <tr>
  328. <td><code>4</code></td>
  329. <td><code>RTN_ANYCAST</code> -
  330. Accept locally as broadcast but send as unicast</td>
  331. </tr>
  332. <tr>
  333. <td><code>5</code></td>
  334. <td><code>RTN_MULTICAST</code> - Multicast route</td>
  335. </tr>
  336. </table>
  337. </td></tr>
  338. <tr>
  339. <td><code>family</code></td>
  340. <td>Number containing the route family, <code>4</code> for IPv4 or
  341. <code>6</code> for IPv6</td>
  342. </tr>
  343. <tr>
  344. <td><code>dest</code></td>
  345. <td>Destination <code>luci.ip.cidr</code> instance</td>
  346. </tr>
  347. <tr>
  348. <td><code>gw</code></td>
  349. <td>Gateway <code>luci.ip.cidr</code> instance (optional)</td>
  350. </tr>
  351. <tr>
  352. <td><code>from</code></td>
  353. <td>Source address <code>luci.ip.cidr</code> instance (optional)</td>
  354. </tr>
  355. <tr>
  356. <td><code>src</code></td>
  357. <td>Preferred source <code>luci.ip.cidr</code> instance (optional)</td>
  358. </tr>
  359. <tr>
  360. <td><code>dev</code></td>
  361. <td>String containing the name of the outgoing interface</td>
  362. </tr>
  363. <tr>
  364. <td><code>iif</code></td>
  365. <td>String containing the name of the incoming interface (optional)</td>
  366. </tr>
  367. <tr>
  368. <td><code>table</code></td>
  369. <td>Number of the associated routing table (<code>0..65535</code>)</td>
  370. </tr>
  371. <tr>
  372. <td><code>proto</code></td>
  373. <td>Number of the associated routing protocol</td>
  374. </tr>
  375. <tr>
  376. <td><code>scope</code></td>
  377. <td>Number describing the scope of the route, most commonly
  378. <code>0</code> for global or <code>253</code> for on-link</td>
  379. </tr>
  380. <tr>
  381. <td><code>metric</code></td>
  382. <td>Number describing the route metric (optional)</td>
  383. </tr>
  384. <tr>
  385. <td><code>expires</code></td>
  386. <td>Number of seconds the prefix is valid (IPv6 only, optional)</td>
  387. </tr>
  388. <tr>
  389. <td><code>error</code></td>
  390. <td>Route destination error code (optional)</td>
  391. </tr>
  392. </table>
  393. <h3>See also:</h3>
  394. <ul>
  395. <li><a href="#routes">
  396. routes
  397. </a>
  398. </ul>
  399. </dd>
  400. <dt><a name="routes"></a><strong>routes</strong>&nbsp;(filter, callback)</dt>
  401. <dd>
  402. Fetch all routes, optionally matching the given criteria.
  403. <h3>Parameters</h3>
  404. <ul>
  405. <li>
  406. filter: <p>Table containing one or more of the possible filter
  407. critera described below (optional)</p><table>
  408. <tr><th>Field</th><th>Description</th></tr>
  409. <tr><td><code>family</code></td><td>
  410. Number describing the address family to return - <code>4</code> selects
  411. IPv4 routes, <code>6</code> IPv6 ones. Any other value selects both.
  412. </td></tr>
  413. <tr><td><code>iif</code></td><td>
  414. String containing the incoming route interface to match.
  415. </td></tr>
  416. <tr><td><code>oif</code></td><td>
  417. String containing the outgoing route interface to match.
  418. </td></tr>
  419. <tr><td><code>type</code></td><td>
  420. Numeric type to match, e.g. <code>1</code> for unicast.
  421. </td></tr>
  422. <tr><td><code>scope</code></td><td>
  423. Numeric scope to match, e.g. <code>253</code> for onlink.
  424. </td></tr>
  425. <tr><td><code>proto</code></td><td>
  426. Numeric protocol to match, e.g. <code>2</code> for boot.
  427. </td></tr>
  428. <tr><td><code>table</code></td><td>
  429. Numeric routing table to match (<code>0..65535</code>).
  430. </td></tr>
  431. <tr><td><code>gw</code></td><td>
  432. String containing the gateway address to match. Can be in any notation
  433. specified by <code>luci.ip.new()</code>. Prefix matching is performed when
  434. comparing the routes, e.g. "192.168.1.0/24" would select routes with gateway
  435. addresses <code>192.168.1.1 .. 192.168.1.255</code>.
  436. </td></tr>
  437. <tr><td><code>dest</code></td><td>
  438. String containing the destination to match. Prefix matching is performed.
  439. </td></tr>
  440. <tr><td><code>from</code></td><td>
  441. String containing the source address to match. Prefix matching is performed.
  442. </td></tr>
  443. <tr><td><code>src</code></td><td>
  444. String containing the preferred source address to match.
  445. Prefix matching is performed.
  446. </td></tr>
  447. <tr><td><code>dest_exact</code></td><td>
  448. String containing the destination to match. Exact matching is performed,
  449. e.g. <code>dest = "0.0.0.0/0"</code> would match <em>any</em> IPv4 route
  450. while <code>dest_exact = "0.0.0.0/0"</code> will <em>only</em> match the
  451. default route.
  452. </td></tr>
  453. <tr><td><code>from_exact</code></td><td>
  454. String containing the source address to match. Exact matching is performed.
  455. </td></tr>
  456. </table>
  457. </li>
  458. <li>
  459. callback: <p>Callback function to invoke for each found route
  460. instead of returning one table of route objects (optional)</p>
  461. </li>
  462. </ul>
  463. <h3>Usage:</h3>
  464. <ul>
  465. <li>Find all IPv4 default routes:
  466. <pre>luci.ip.routes({ dest_exact = "0.0.0.0/0" }, function(rt)
  467. print(rt.type, rt.gw, rt.dev)
  468. end)</pre></li>
  469. <li>Find all global IPv6 prefixes on the current system:
  470. <pre>luci.ip.routes({ from = "2001::/7" }, function(rt)
  471. print(rt.from)
  472. end)</pre></li>
  473. <li>Fetch all IPv4 routes:
  474. <pre>routes = luci.ip.routes({ family = 4 })
  475. for _, rt in ipairs(routes) do
  476. print(rt.dest, rt.gw, rt.dev)
  477. end</pre></li>
  478. </ul>
  479. <h3>Return value:</h3>
  480. If no callback function is provided, a table of routes
  481. <a href="#routetable">as specified by <code>luci.ip.route()</code></a>
  482. is returned. If a callback function is given, it is invoked for each route
  483. and nothing is returned.
  484. <h3>See also:</h3>
  485. <ul>
  486. <li><a href="#route">
  487. route
  488. </a>
  489. </ul>
  490. </dd>
  491. <dt><a name="neighbors"></a><strong>neighbors</strong>&nbsp;(filter, callback)</dt>
  492. <dd>
  493. Fetches entries from the IPv4 ARP and IPv6 neighbour kernel table
  494. <h3>Parameters</h3>
  495. <ul>
  496. <li>
  497. filter: <p>Table containing one or more of the possible filter
  498. critera described below (optional)</p><table>
  499. <tr><th>Field</th><th>Description</th></tr>
  500. <tr><td><code>family</code></td><td>
  501. Number describing the address family to return - <code>4</code> selects
  502. IPv4 ARP, <code>6</code> select IPv6 neighbour entries. Any other value
  503. selects both.
  504. </td></tr>
  505. <tr><td><code>dev</code></td><td>
  506. String containing the associated interface to match.
  507. </td></tr>
  508. <tr><td><code>dest</code></td><td>
  509. String containing the associated address to match. Can be in any notation
  510. specified by <code>luci.ip.new()</code>. Prefix matching is performed when
  511. comparing the addresses, e.g. "192.168.1.0/24" would select ARP entries
  512. for <code>192.168.1.1 .. 192.168.1.255</code>.
  513. </td></tr>
  514. <tr><td><code>mac</code></td><td>
  515. String containing MAC address to match.
  516. </td></tr>
  517. </table>
  518. </li>
  519. <li>
  520. callback: <p>Callback function to invoke for each found neighbour
  521. entry instead of returning one table of neighbour entries (optional)</p>
  522. </li>
  523. </ul>
  524. <h3>Usage:</h3>
  525. <ul>
  526. <li>Find all ARP neighbours in the LAN:
  527. <pre>luci.ip.neighbors({ dest = "192.168.0.0/16" }, function(n)
  528. print(n.dest, n.mac)
  529. end)</pre></li>
  530. <li>Find all active IPv6 addresses of host with given MAC:
  531. <pre>luci.ip.neighbors({ family = 6, mac = "00:21:63:75:aa:17" },
  532. function(n)
  533. print(n.dest)
  534. end)</pre></li>
  535. </ul>
  536. <h3>Return value:</h3>
  537. If no callback function is provided, a table of neighbour entries
  538. is returned. If a callback function is given, it is invoked for each entry
  539. and nothing is returned.
  540. A neighbour entry is a table containing the following fields:
  541. <table>
  542. <tr><th>Field</th><th>Description</th></tr>
  543. <tr>
  544. <td><code>family</code></td>
  545. <td>Number containing the neighbour entry family, <code>4</code> for IPv4
  546. ARP or <code>6</code> for IPv6 NDP</td>
  547. </tr>
  548. <tr>
  549. <td><code>dev</code></td>
  550. <td>String containing the associated device of the neighbour entry</td>
  551. </tr>
  552. <tr>
  553. <td><code>dest</code></td>
  554. <td>IP address <code>luci.ip.cidr</code> instance</td>
  555. </tr>
  556. <tr>
  557. <td><code>mac</code></td>
  558. <td>String containing the associated MAC address</td>
  559. </tr>
  560. <tr>
  561. <td><code>router</code></td>
  562. <td>Boolean "true" if the neighbour entry is a router (IPv6, optional)</td>
  563. </tr>
  564. <tr>
  565. <td><code>proxy</code></td>
  566. <td>Boolean "true" if this is a proxy entry (optional)</td>
  567. </tr>
  568. <tr>
  569. <td><code>incomplete</code></td>
  570. <td>Boolean "true" if the entry is in incomplete state (optional)</td>
  571. </tr>
  572. <tr>
  573. <td><code>reachable</code></td>
  574. <td>Boolean "true" if the entry is in reachable state (optional)</td>
  575. </tr>
  576. <tr>
  577. <td><code>stale</code></td>
  578. <td>Boolean "true" if the entry is stale (optional)</td>
  579. </tr>
  580. <tr>
  581. <td><code>delay</code></td>
  582. <td>Boolean "true" if the entry is delayed (optional)</td>
  583. </tr>
  584. <tr>
  585. <td><code>probe</code></td>
  586. <td>Boolean "true" if the entry is in probe state (optional)</td>
  587. </tr>
  588. <tr>
  589. <td><code>failed</code></td>
  590. <td>Boolean "true" if the entry is in failed state (optional)</td>
  591. </tr>
  592. <tr>
  593. <td><code>noarp</code></td>
  594. <td>Boolean "true" if the entry is not caused by NDP or
  595. ARP (optional)</td>
  596. </tr>
  597. <tr>
  598. <td><code>permanent</code></td>
  599. <td>Boolean "true" if the entry was statically configured from
  600. userspace (optional)</td>
  601. </tr>
  602. </table>
  603. </dd>
  604. <dt><a name="link"></a><strong>link</strong>&nbsp;(device)</dt>
  605. <dd>
  606. Fetch basic device information
  607. <h3>Parameters</h3>
  608. <ul>
  609. <li>
  610. device: String containing the network device to query
  611. </li>
  612. </ul>
  613. <h3>Usage:</h3>
  614. <ul>
  615. <li>Test whether device br-lan exists:
  616. <pre>print(luci.ip.link("br-lan").name ~= nil)
  617. </pre></li>
  618. <li>Query MAC address of eth0:
  619. <pre>print(luci.ip.link("eth0").mac)
  620. </pre></li>
  621. </ul>
  622. <h3>Return value:</h3>
  623. If the given interface is found, a table containing the fields
  624. described below is returned, else an empty table.
  625. <table>
  626. <tr><th>Field</th><th>Description</th></tr>
  627. <tr>
  628. <td><code>up</code></td>
  629. <td>Boolean indicating whether the device is in IFF_RUNNING state</td>
  630. </tr>
  631. <tr>
  632. <td><code>type</code></td>
  633. <td>Numeric value indicating the type of the device, e.g. <code>1</code>
  634. for ethernet.</td>
  635. </tr>
  636. <tr>
  637. <td><code>name</code></td>
  638. <td>String containing the name of the device</td>
  639. </tr>
  640. <tr>
  641. <td><code>master</code></td>
  642. <td>If queried device is a bridge port, string containing the name of
  643. parent bridge device (optional)</td>
  644. </tr>
  645. <tr>
  646. <td><code>mtu</code></td>
  647. <td>Number containing the current MTU of the device</td>
  648. </tr>
  649. <tr>
  650. <td><code>qlen</code></td>
  651. <td>Number containing the TX queue length of the device</td>
  652. </tr>
  653. <tr>
  654. <td><code>mac</code></td>
  655. <td>String containing the link local address of the device in
  656. dotted hex notation</td>
  657. </tr>
  658. </table>
  659. </dd>
  660. </dl>
  661. </div> <!-- id="content" -->
  662. </div> <!-- id="main" -->
  663. <div id="about">
  664. <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>
  665. </div> <!-- id="about" -->
  666. </div> <!-- id="container" -->
  667. </body>
  668. </html>