diff --git a/package/gluon-alfred/files/lib/gluon/cron/alfred b/package/gluon-alfred/files/lib/gluon/cron/alfred index adab7322..9f79bc64 100644 --- a/package/gluon-alfred/files/lib/gluon/cron/alfred +++ b/package/gluon-alfred/files/lib/gluon/cron/alfred @@ -1 +1 @@ -* * * * * /lib/gluon/announce/collect.lua nodeinfo | gzip | alfred -s 158; /lib/gluon/announce/collect.lua statistics | gzip | alfred -s 159 +* * * * * /lib/gluon/announce/collect.lua nodeinfo | gzip | alfred -s 158; /lib/gluon/announce/collect.lua statistics | gzip | alfred -s 159; /lib/gluon/announce/collect.lua neighbours | gzip | alfred -s 160 diff --git a/package/gluon-announce/files/lib/gluon/announce/neighbours.d/node_id b/package/gluon-announce/files/lib/gluon/announce/neighbours.d/node_id new file mode 100644 index 00000000..66303f4c --- /dev/null +++ b/package/gluon-announce/files/lib/gluon/announce/neighbours.d/node_id @@ -0,0 +1 @@ +return require('gluon.util').node_id() diff --git a/package/gluon-mesh-batman-adv-core/Makefile b/package/gluon-mesh-batman-adv-core/Makefile index 93191348..fc4bc224 100644 --- a/package/gluon-mesh-batman-adv-core/Makefile +++ b/package/gluon-mesh-batman-adv-core/Makefile @@ -11,7 +11,7 @@ define Package/gluon-mesh-batman-adv-core SECTION:=gluon CATEGORY:=Gluon TITLE:=Support for batman-adv meshing (core) - DEPENDS:=+gluon-core +firewall +kmod-ipt-nathelper + DEPENDS:=+gluon-core +firewall +kmod-ipt-nathelper +libiwinfo-lua endef define Build/Prepare diff --git a/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/neighbours.d/batadv b/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/neighbours.d/batadv new file mode 100644 index 00000000..f93a11f9 --- /dev/null +++ b/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/neighbours.d/batadv @@ -0,0 +1,41 @@ +local json = require 'luci.json' +local util = require 'luci.util' +local fs = require 'nixio.fs' + +local ifname_address_cache = {} + +function ifname2address(ifname) + local ifaddress + if ifname_address_cache[ifname] ~= nil then + ifaddress = ifname_address_cache[ifname] + else + ifaddress = util.trim(fs.readfile("/sys/class/net/" .. ifname .. "/address")) + ifname_address_cache[ifname] = ifaddress + end + + return ifaddress +end + +function batadv() + local interfaces = {} + local list = io.lines("/sys/kernel/debug/batman_adv/bat0/originators") + for line in list do + local mac1, lastseen, tq, mac2, ifname = + line:match("^([0-9a-f:]+) +(%d+%.%d+)s +%( *(%d+)%) +([0-9a-f:]+) +%[ *(.-)%]") + + if mac1 ~= nil and mac1 == mac2 then + ifaddress = ifname2address(ifname) + if interfaces[ifaddress] == nil then + interfaces[ifaddress] = { neighbours = {} } + end + + interfaces[ifaddress].neighbours[mac1] = { tq = tonumber(tq) + , lastseen = tonumber(lastseen) + } + end + end + + return interfaces +end + +return batadv() diff --git a/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/neighbours.d/wifi b/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/neighbours.d/wifi new file mode 100644 index 00000000..d3754222 --- /dev/null +++ b/package/gluon-mesh-batman-adv-core/files/lib/gluon/announce/neighbours.d/wifi @@ -0,0 +1,41 @@ +local json = require 'luci.json' +local util = require 'luci.util' +local fs = require 'nixio.fs' +local iwinfo = require 'iwinfo' + +function neighbours(iface) + local stations = {} + for k, v in pairs(iface.iw.assoclist(iface.ifname)) do + stations[k:lower()] = { signal = v.signal + , noise = v.noise + , inactive = v.inactive + } + end + + return stations +end + +function interfaces() + local interfaces = {} + for _, line in ipairs(util.split(util.exec('batctl if'))) do + ifname = line:match('^(.-): active') + if ifname ~= nil then + pcall(function() + local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address')) + local wifitype = iwinfo.type(ifname) + if wifitype ~= nil then + interfaces[address] = { ifname = ifname, iw = iwinfo[wifitype] } + end + end) + end + end + + return interfaces +end + +local wifi = {} +for address, iface in pairs(interfaces()) do + wifi[address] = { neighbours = neighbours(iface) } +end + +return wifi