Merge remote-tracking branch 'origin/meshinterfaces'
This commit is contained in:
commit
cd00eeb367
@ -0,0 +1,52 @@
|
||||
local list = util.exec('batctl if')
|
||||
|
||||
local wireless = {}
|
||||
local tunnel = {}
|
||||
local other = {}
|
||||
|
||||
local function get_address(t, ifname)
|
||||
pcall(
|
||||
function()
|
||||
table.insert(t, util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address')))
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
local function is_wireless(ifname)
|
||||
local type = fs.stat('/sys/class/net/' .. ifname .. '/wireless', 'type')
|
||||
|
||||
return type == 'directory'
|
||||
end
|
||||
|
||||
local function is_tuntap(ifname)
|
||||
local type = fs.stat('/sys/class/net/' .. ifname .. '/tun_flags', 'type')
|
||||
|
||||
return type == 'regular'
|
||||
end
|
||||
|
||||
local function nil_table(t)
|
||||
if next(t) ~= nil then
|
||||
return t
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
for _, line in ipairs(util.split(list)) do
|
||||
local ifname = line:match('^(.-):')
|
||||
if ifname ~= nil then
|
||||
if is_wireless(ifname) then
|
||||
get_address(wireless, ifname)
|
||||
elseif is_tuntap(ifname) then
|
||||
get_address(tunnel, ifname)
|
||||
else
|
||||
get_address(other, ifname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
wireless = nil_table(wireless),
|
||||
tunnel = nil_table(tunnel),
|
||||
other = nil_table(other)
|
||||
}
|
@ -22,9 +22,23 @@ function neighbours(ifname)
|
||||
for _, line in ipairs(util.split(info)) do
|
||||
local data = json.decode(line)
|
||||
if data then
|
||||
if data["network"] and data["network"]["mesh_interfaces"] then
|
||||
for _, mac in ipairs(data["network"]["mesh_interfaces"]) do
|
||||
macs[mac] = data
|
||||
local function add_macs(list)
|
||||
if list then
|
||||
for _, mac in ipairs(list) do
|
||||
macs[mac] = data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if data["network"] then
|
||||
add_macs(data["network"]["mesh_interfaces"])
|
||||
|
||||
if data["network"]["mesh"] and data["network"]["mesh"]["bat0"] and
|
||||
data["network"]["mesh"]["bat0"]["interfaces"] then
|
||||
local interfaces = data["network"]["mesh"]["bat0"]["interfaces"]
|
||||
add_macs(interfaces["other"])
|
||||
add_macs(interfaces["wireless"])
|
||||
add_macs(interfaces["tunnel"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user