summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-olsr
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-03-12 16:12:18 +0100
committerJo-Philipp Wich <jo@mein.io>2018-03-12 16:12:18 +0100
commit28e3b328545529c19429ce88c7d1769e64e2de0f (patch)
tree3d7d85d7d4d1202199bad98df125f2af88b73c86 /applications/luci-app-olsr
parentdfba318140e1a84359e221b7a9154337595dbded (diff)
treewide: unify mac address handling
Use the new luci.ip MAC address facilities to parse and verify MAC addresses in a common way, instead of relying on various ad-hoc solutions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-olsr')
-rw-r--r--applications/luci-app-olsr/luasrc/controller/olsr.lua42
1 files changed, 10 insertions, 32 deletions
diff --git a/applications/luci-app-olsr/luasrc/controller/olsr.lua b/applications/luci-app-olsr/luasrc/controller/olsr.lua
index 0564bd4ea..229f3d61b 100644
--- a/applications/luci-app-olsr/luasrc/controller/olsr.lua
+++ b/applications/luci-app-olsr/luasrc/controller/olsr.lua
@@ -101,41 +101,19 @@ end
local function local_mac_lookup(ipaddr)
- local _, ifa, dev
-
- ipaddr = tostring(ipaddr)
-
- if not ifaddr_table then
- ifaddr_table = nixio.getifaddrs()
- end
-
- -- ipaddr -> ifname
- for _, ifa in ipairs(ifaddr_table) do
- if ifa.addr == ipaddr then
- dev = ifa.name
- break
- end
- end
-
- -- ifname -> macaddr
- for _, ifa in ipairs(ifaddr_table) do
- if ifa.name == dev and ifa.family == "packet" then
- return ifa.addr
- end
+ local _, rt
+ for _, rt in ipairs(luci.ip.routes({ type = 1, src = ipaddr })) do
+ local link = rt.dev and luci.ip.link(rt.dev)
+ local mac = link and luci.ip.checkmac(link.mac)
+ if mac then return mac end
end
end
local function remote_mac_lookup(ipaddr)
local _, n
-
- if not neigh_table then
- neigh_table = luci.ip.neighbors()
- end
-
- for _, n in ipairs(neigh_table) do
- if n.mac and n.dest and n.dest:equal(ipaddr) then
- return n.mac
- end
+ for _, n in ipairs(luci.ip.neighbors({ dest = ipaddr })) do
+ local mac = luci.ip.checkmac(n.mac)
+ if mac then return mac end
end
end
@@ -201,9 +179,9 @@ function action_neigh(json)
for _, val in ipairs(assoclist) do
if val.network == interface and val.list then
+ local assocmac, assot
for assocmac, assot in pairs(val.list) do
- assocmac = string.lower(assocmac or "")
- if rmac == assocmac then
+ if rmac == luci.ip.checkmac(assocmac) then
signal = tonumber(assot.signal)
noise = tonumber(assot.noise)
snr = (noise*-1) - (signal*-1)