Merge pull request #473 from FreifunkBremen/batctl-if-lua
Don't fork batctl from announce scripts
This commit is contained in:
commit
96033758ab
@ -1,3 +1,4 @@
|
|||||||
|
local batman_adv = require 'gluon.batman_adv'
|
||||||
local iwinfo = require 'iwinfo'
|
local iwinfo = require 'iwinfo'
|
||||||
|
|
||||||
function neighbours(iface)
|
function neighbours(iface)
|
||||||
@ -16,8 +17,7 @@ end
|
|||||||
|
|
||||||
function interfaces()
|
function interfaces()
|
||||||
local interfaces = {}
|
local interfaces = {}
|
||||||
local popen = io.popen('exec batctl if')
|
for ifname in batman_adv.interfaces('bat0') do
|
||||||
for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
|
|
||||||
pcall(function()
|
pcall(function()
|
||||||
local address = util.readline(io.open('/sys/class/net/' .. ifname .. '/address'))
|
local address = util.readline(io.open('/sys/class/net/' .. ifname .. '/address'))
|
||||||
local wifitype = iwinfo.type(ifname)
|
local wifitype = iwinfo.type(ifname)
|
||||||
@ -26,7 +26,6 @@ function interfaces()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
popen:close()
|
|
||||||
|
|
||||||
return interfaces
|
return interfaces
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local batman_adv = require 'gluon.batman_adv'
|
||||||
|
|
||||||
local wireless = {}
|
local wireless = {}
|
||||||
local tunnel = {}
|
local tunnel = {}
|
||||||
local other = {}
|
local other = {}
|
||||||
@ -36,8 +38,7 @@ local function nil_table(t)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local popen = io.popen('exec batctl if')
|
for ifname in batman_adv.interfaces('bat0') do
|
||||||
for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
|
|
||||||
if is_wireless(ifname) then
|
if is_wireless(ifname) then
|
||||||
get_address(wireless, ifname)
|
get_address(wireless, ifname)
|
||||||
elseif is_tuntap(ifname) then
|
elseif is_tuntap(ifname) then
|
||||||
@ -46,7 +47,6 @@ for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
|
|||||||
get_address(other, ifname)
|
get_address(other, ifname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
popen:close()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
wireless = nil_table(wireless),
|
wireless = nil_table(wireless),
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
local batman_adv = require 'gluon.batman_adv'
|
||||||
|
|
||||||
local interfaces = {}
|
local interfaces = {}
|
||||||
|
|
||||||
local popen = io.popen('exec batctl if')
|
for ifname in batman_adv.interfaces('bat0') do
|
||||||
for ifname in popen:read('*a'):gmatch('([^%s]+): active') do
|
|
||||||
pcall(
|
pcall(
|
||||||
function()
|
function()
|
||||||
table.insert(interfaces, util.readline(io.open('/sys/class/net/' .. ifname .. '/address')))
|
table.insert(interfaces, util.readline(io.open('/sys/class/net/' .. ifname .. '/address')))
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
popen:close()
|
|
||||||
|
|
||||||
return interfaces
|
return interfaces
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
local gateway = ''
|
local gateway = ''
|
||||||
|
|
||||||
local popen = io.popen("exec batctl -m bat0 gateways")
|
for line in io.lines('/sys/kernel/debug/batman_adv/bat0/gateways') do
|
||||||
for line in popen:lines() do
|
|
||||||
if line:sub(1, 3) == '=> ' then
|
if line:sub(1, 3) == '=> ' then
|
||||||
gateway = line:sub(4, 20)
|
gateway = line:sub(4, 20)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
popen:close()
|
|
||||||
|
|
||||||
if gateway ~= '' then
|
if gateway ~= '' then
|
||||||
return gateway
|
return gateway
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
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
|
Loading…
Reference in New Issue
Block a user