From c23885f6a776db74aa728b1efcd1bf644dde626d Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 20 Jan 2016 16:55:15 +0100 Subject: [PATCH] luci-base: add luci.sys.net.host_hints() and regenerate documentation Signed-off-by: Jo-Philipp Wich --- documentation/api/modules/luci.model.uci.html | 8 +++-- documentation/api/modules/luci.sys.net.html | 32 +++++++++++++++++++ modules/luci-base/luasrc/sys.lua | 22 +++++++++++++ modules/luci-base/luasrc/sys.luadoc | 10 ++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/documentation/api/modules/luci.model.uci.html b/documentation/api/modules/luci.model.uci.html index cf75aebccb..c84d1eb0eb 100644 --- a/documentation/api/modules/luci.model.uci.html +++ b/documentation/api/modules/luci.model.uci.html @@ -903,7 +903,8 @@ Get an option or list and return values as table.

Return value:

-UCI value +table. If the option was not found, you will simply get + an empty table. @@ -1200,7 +1201,8 @@ Boolean whether operation succeeded
-Set given values as list. +Set given values as list. Setting a list option to an empty list +has the same effect as deleting the option. @@ -1220,7 +1222,7 @@ Set given values as list.
  • - value: UCI value + value: value or table. Raw values will become a single item table.
  • diff --git a/documentation/api/modules/luci.sys.net.html b/documentation/api/modules/luci.sys.net.html index 4a049e2307..09cef175f9 100644 --- a/documentation/api/modules/luci.sys.net.html +++ b/documentation/api/modules/luci.sys.net.html @@ -241,6 +241,13 @@ Return information about available network interfaces. Determine the names of available network interfaces. + + host_hints () + + +Returns a two-dimensional table of host hints. + + ipv4_hints () @@ -393,6 +400,31 @@ Table containing all current interface names +
    host_hints ()
    +
    + + +Returns a two-dimensional table of host hints. + + + + + + + + +

    Return value:

    +Table of table containing known hosts from various sources, + indexed by mac address. Each subtable contains at least one + of the fields "name", "ipv4" or "ipv6". + + + +
    + + + +
    ipv4_hints ()
    diff --git a/modules/luci-base/luasrc/sys.lua b/modules/luci-base/luasrc/sys.lua index 31c3e12095..5d203aa8f8 100644 --- a/modules/luci-base/luasrc/sys.lua +++ b/modules/luci-base/luasrc/sys.lua @@ -292,6 +292,28 @@ function net.ipv6_hints(callback) end end +function net.host_hints(callback) + if callback then + _nethints(1, function(mac, v4, v6, name) + if mac and mac ~= "00:00:00:00:00:00" and (v4 or v6 or name) then + callback(mac, v4, v6, name) + end + end) + else + local rv = { } + _nethints(1, function(mac, v4, v6, name) + if mac and mac ~= "00:00:00:00:00:00" and (v4 or v6 or name) then + local e = { } + if v4 then e.ipv4 = v4 end + if v6 then e.ipv6 = v6 end + if name then e.name = name end + rv[mac] = e + end + end) + return rv + end +end + function net.conntrack(callback) local ok, nfct = pcall(io.lines, "/proc/net/nf_conntrack") if not ok or not nfct then diff --git a/modules/luci-base/luasrc/sys.luadoc b/modules/luci-base/luasrc/sys.luadoc index 54be34958a..1c1fa92602 100644 --- a/modules/luci-base/luasrc/sys.luadoc +++ b/modules/luci-base/luasrc/sys.luadoc @@ -150,6 +150,16 @@ Returns a two-dimensional table of IPv6 address hints. [ "ip", "name" ] ]] +---[[ +Returns a two-dimensional table of host hints. + +@class function +@name net.host_hints +@return Table of table containing known hosts from various sources, + indexed by mac address. Each subtable contains at least one + of the fields "name", "ipv4" or "ipv6". +]] + ---[[ Returns conntrack information -- 2.30.2