Commit 5923eda7 authored by Johannes Rudolph's avatar Johannes Rudolph

Merge branch 'master' into johannes/201703

parents 639abda9 36d36e62
......@@ -134,13 +134,26 @@ local function mesh_on_lan_enable()
io.stderr:write('Interface mesh_lan enabled.\n')
end
local function filt_if(filt,str)
for _, c in ipairs(filt) do
if c:match(str) then
return true
end
end
return false
end
-- Give a list of interfaces where respondd is listening
local function get_mesh_if()
local vpnIface = uci:get('fastd', 'mesh_vpn_backbone', 'net'):gsub("%_",'-'):gsub("%-", "%%-")
local function get_mesh_if(radios)
local filtert_if = {}
table.insert(filtert_if,(uci:get('fastd', 'mesh_vpn_backbone', 'net'):gsub("%_",'-'):gsub("%-", "%%-")))
for _, radio in ipairs(radios) do
table.insert(filtert_if,(uci:get('wireless', 'ibss_' .. radio, 'ifname')))
end
local respondd_if = {}
for line in io.popen(string.format("ubus call network.interface dump | jsonfilter -e \"@.interface[@.proto='gluon_mesh' && @.up=true].device\" -e \"@.interface[@.interface='$(cat /lib/gluon/respondd/client.dev 2>/dev/null)' && @.up=true].device\""), "r"):lines() do
-- filter vpn interface
if not line:match(vpnIface) then
if not filt_if(filtert_if,line) then
table.insert(respondd_if,line)
end
end
......@@ -156,10 +169,10 @@ local function get_mesh_if()
return ret
end
local function molwm()
local function molwm(radios)
if uci:get_bool("network", "mesh_lan", "auto") or uci:get_bool("network", "mesh_wan", "auto") then
local mesh_en = true
for _,respondd_if in ipairs(get_mesh_if()) do
for _,respondd_if in ipairs(get_mesh_if(radios)) do
local respondd = string.format("gluon-neighbour-info -i " .. respondd_if .. " -p 1001 -d ff02::2 -r hoodselector -t 0.5")
for line in io.popen(respondd, 'r'):lines() do
local obj, _, err = json.parse (line, 1, nil)
......@@ -259,13 +272,13 @@ local function molwm_to_file()
end
-- Write MOLWM content into file
local function write_molwm(hood)
local function write_molwm(hood,radios)
if hood ~= nil then
molwmtable["md5hash"] = "\"" .. string.format(hash.md5(table.tostring(hood))) .. "\""
molwmtable["hoodname"] = "\"" .. hood["name"] .. "\""
molwmtable["bssid"] = "\"" .. hood["bssid"] .. "\""
end
molwm()
molwm(radios)
molwm_to_file()
end
......@@ -801,34 +814,38 @@ local function molw_get_bssid(iface)
for _,respondd_if in ipairs(iface) do
local respondd = string.format("gluon-neighbour-info -i " .. respondd_if .. " -p 1001 -d ff02::2 -r hoodselector -t 0.5")
print(respondd)
local drop_first = false -- first one is node it selfe!
for line in io.popen(respondd, 'r'):lines() do
local obj, _, err = json.parse (line, 1, nil)
if err then
io.stderr:write("json parse error!\n")
else
if obj["hoodinfo"] ~= nil then
if obj["hoodinfo"]["vpnrouter"]:match("true") then
if obj["selectedbssid"] ~= nil then
if obj["selectedbssid"]["bssid"] ~= nil then
if not vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] then
vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = 1
else
vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] + 1
if drop_first then
if obj["hoodinfo"] ~= nil then
if obj["hoodinfo"]["vpnrouter"]:match("true") then
if obj["selectedbssid"] ~= nil then
if obj["selectedbssid"]["bssid"] ~= nil then
if not vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] then
vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = 1
else
vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = vpn_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] + 1
end
end
end
end
else
if obj["selectedbssid"] ~= nil then
if obj["selectedbssid"]["bssid"] ~= nil then
if not mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] then
mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = 1
else
mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] + 1
else
if obj["selectedbssid"] ~= nil then
if obj["selectedbssid"]["bssid"] ~= nil then
if not mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] then
mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = 1
else
mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] = mesh_router_neigbour_bssids[obj["selectedbssid"]["bssid"]] + 1
end
end
end
end
end
end
drop_first = true
end
end
end
......@@ -901,13 +918,13 @@ if directVPN() then
if geoHood ~= nil then
set_hoodconfig(geoHood, radios)
io.stderr:write('Hood set by VPN mode.\n')
write_molwm(geoHood)
write_molwm(geoHood,radios)
exit(0)
end
io.stderr:write('No hood has been defined for current position.\n')
set_hoodconfig(defaultHood, radios)
io.stderr:write('Defaulthood set.\n')
write_molwm(defaultHood)
write_molwm(defaultHood,radios)
exit(0)
end
io.stderr:write('No position found\n')
......@@ -928,7 +945,7 @@ if batmanHasGateway() then
if bssidHood ~= nil then
set_hoodconfig(bssidHood, radios)
io.stderr:write('Hood set by batmanHasGateway mode, GW source is wifi\n')
write_molwm(bssidHood)
write_molwm(bssidHood,radios)
exit(0)
end
end
......@@ -953,13 +970,13 @@ if batmanHasGateway() then
end
local currendHood = getCurrentHood(jhood)
if currendHood ~= nil then
write_molwm(currendHood)
write_molwm(currendHood,radios)
-- else evtl. set hood by pos.
else
io.stderr:write("currend configuration are not defined as hood\n")
set_hoodconfig(defaultHood, radios)
io.stderr:write('Set defaulthood.\n')
write_molwm(defaultHood)
write_molwm(defaultHood,radios)
end
exit(0)
end
......@@ -976,7 +993,7 @@ if next(radios) then
if bssidHood ~= nil then
set_hoodconfig(bssidHood, radios)
io.stderr:write('Hood set by scan mode\n')
write_molwm(bssidHood)
write_molwm(bssidHood,radios)
exit(0)
end
......@@ -994,7 +1011,7 @@ if next(radios) then
end
--Radio less router have mesh lan/wan neigborths
local mesh_inf = get_mesh_if();
local mesh_inf = get_mesh_if(radios);
if next(mesh_inf) then
local neigbourbssid = molw_get_bssid(mesh_inf)
if neigbourBssid ~= nil then
......@@ -1009,6 +1026,7 @@ if next(mesh_inf) then
exit(0)
end
end
io.stderr:write('No molwm neighbors found\n')
end
-- DEFAULT-HOOD MODE
......@@ -1016,12 +1034,12 @@ end
-- scanning then we set the default hood if no currend hood set.
local currendHood = getCurrentHood(jhood)
if currendHood ~= nil then
write_molwm(currendHood)
write_molwm(currendHood,radios)
-- else evtl. set hood by pos.
else
io.stderr:write("currend configuration are not defined as hood\n")
set_hoodconfig(defaultHood, radios)
io.stderr:write('Set defaulthood.\n')
write_molwm(defaultHood)
write_molwm(defaultHood,radios)
end
exit(0)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment