Skip to content
Snippets Groups Projects
Commit bccf4f7b authored by Jan-Philipp Litza's avatar Jan-Philipp Litza
Browse files

gluon-mesh-batman-adv-core: Add lua code for iface listing, don't fork

parent 339a6c99
No related branches found
No related tags found
No related merge requests found
local batman_adv = require 'gluon.batman_adv'
local iwinfo = require 'iwinfo'
function neighbours(iface)
......@@ -16,8 +17,7 @@ end
function interfaces()
local interfaces = {}
local popen = io.popen('exec batctl if')
for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
for ifname in batman_adv.interfaces('bat0') do
pcall(function()
local address = util.readline(io.open('/sys/class/net/' .. ifname .. '/address'))
local wifitype = iwinfo.type(ifname)
......@@ -26,7 +26,6 @@ function interfaces()
end
end)
end
popen:close()
return interfaces
end
......
local batman_adv = require 'gluon.batman_adv'
local wireless = {}
local tunnel = {}
local other = {}
......@@ -36,8 +38,7 @@ local function nil_table(t)
end
end
local popen = io.popen('exec batctl if')
for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
for ifname in batman_adv.interfaces('bat0') do
if is_wireless(ifname) then
get_address(wireless, ifname)
elseif is_tuntap(ifname) then
......@@ -46,7 +47,6 @@ for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
get_address(other, ifname)
end
end
popen:close()
return {
wireless = nil_table(wireless),
......
local batman_adv = require 'gluon.batman_adv'
local interfaces = {}
local popen = io.popen('exec batctl if')
for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
for ifname in batman_adv.interfaces('bat0') do
pcall(
function()
table.insert(interfaces, util.readline(io.open('/sys/class/net/' .. ifname .. '/address')))
end
)
end
popen:close()
return interfaces
local gateway = ''
local popen = io.popen("exec batctl -m bat0 gateways")
for line in popen:lines() do
for line in io.lines('/sys/kernel/debug/batman_adv/bat0/gateways') do
if line:sub(1, 3) == '=> ' then
gateway = line:sub(4, 20)
break
end
end
popen:close()
if gateway ~= '' then
return gateway
......
local nixio = require 'nixio'
module 'gluon.batman_adv'
function interfaces(bat_if)
local iter = nixio.fs.glob('/sys/class/net/' .. bat_if .. '/lower_*')
return function()
local path = iter()
if path == nil then
return nil
end
local ifname = path:match('/lower_([^/]+)$')
return ifname
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment