luci-mod-admin-full: convert luci.sys.net.arptable() to luci.ip.neighbors()

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
Jo-Philipp Wich 2015-01-22 18:45:28 +01:00
parent 577b772824
commit 213595ce85
3 changed files with 19 additions and 20 deletions

View file

@ -1,7 +1,7 @@
-- Copyright 2008 Steven Barth <steven@midlink.org> -- Copyright 2008 Steven Barth <steven@midlink.org>
-- Licensed to the public under the Apache License 2.0. -- Licensed to the public under the Apache License 2.0.
local sys = require "luci.sys" local ipc = require "luci.ip"
m = Map("dhcp", translate("DHCP and DNS"), m = Map("dhcp", translate("DHCP and DNS"),
translate("Dnsmasq is a combined <abbr title=\"Dynamic Host Configuration Protocol" .. translate("Dnsmasq is a combined <abbr title=\"Dynamic Host Configuration Protocol" ..
@ -232,12 +232,11 @@ ip.datatype = "or(ip4addr,'ignore')"
hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)")) hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
sys.net.arptable(function(entry) ipc.neighbors({ family = 4 }, function(n)
ip:value(entry["IP address"]) if n.mac and n.dest then
mac:value( ip:value(n.dest:string())
entry["HW address"], mac:value(n.mac, "%s (%s)" %{ n.mac, n.dest:string() })
entry["HW address"] .. " (" .. entry["IP address"] .. ")" end
)
end) end)
function ip.validate(self, value, section) function ip.validate(self, value, section)

View file

@ -1,9 +1,9 @@
-- Copyright 2008 Steven Barth <steven@midlink.org> -- Copyright 2008 Steven Barth <steven@midlink.org>
-- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org> -- Copyright 2010-2015 Jo-Philipp Wich <jow@openwrt.org>
-- Licensed to the public under the Apache License 2.0. -- Licensed to the public under the Apache License 2.0.
require("luci.sys") local ipc = require "luci.ip"
require("luci.util")
m = Map("dhcp", translate("Hostnames")) m = Map("dhcp", translate("Hostnames"))
s = m:section(TypedSection, "domain", translate("Host entries")) s = m:section(TypedSection, "domain", translate("Host entries"))
@ -19,12 +19,10 @@ ip = s:option(Value, "ip", translate("IP address"))
ip.datatype = "ipaddr" ip.datatype = "ipaddr"
ip.rmempty = true ip.rmempty = true
local arptable = luci.sys.net.arptable() or {} ipc.neighbors({ }, function(n)
for i, dataset in ipairs(arptable) do if n.mac and n.dest and not n.dest:is6linklocal() then
ip:value( ip:value(n.dest:string(), "%s (%s)" %{ n.dest:string(), n.mac })
dataset["IP address"], end
"%s (%s)" %{ dataset["IP address"], dataset["HW address"] } end)
)
end
return m return m

View file

@ -1,12 +1,12 @@
<%# <%#
Copyright 2008-2009 Steven Barth <steven@midlink.org> Copyright 2008-2009 Steven Barth <steven@midlink.org>
Copyright 2008-2013 Jo-Philipp Wich <jow@openwrt.org> Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
Licensed to the public under the Apache License 2.0. Licensed to the public under the Apache License 2.0.
-%> -%>
<%- <%-
local sys = require "luci.sys" local ip = require "luci.ip"
local fs = require "nixio.fs" local fs = require "nixio.fs"
local utl = require "luci.util" local utl = require "luci.util"
local uci = require "luci.model.uci".cursor() local uci = require "luci.model.uci".cursor()
@ -90,7 +90,9 @@
local devices = ntm:get_wifidevs() local devices = ntm:get_wifidevs()
local arpcache = { } local arpcache = { }
sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end) ip.neighbors({ family = 4 }, function(n)
if n.mac and n.dest then arpcache[n.mac:upper()] = n.dest:string() end
end)
local netlist = { } local netlist = { }
local netdevs = { } local netdevs = { }