Reduce tunnels in olsrd to minimum (#1012)

Had attempt to optimize restarting olsrd by putting more tunnel devices
in the config file by default. Unfortunately, olsrd can't cope with too
many and performs poorly.
This commit is contained in:
Tim Wilkinson 2023-12-12 23:26:27 -08:00 committed by GitHub
parent aec049c1fa
commit 188719c321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 18 deletions

View File

@ -471,11 +471,13 @@ if tun_start or tun_dns then
end end
cfg.tun_network_config = cfg.tun_network_config .. "\n" cfg.tun_network_config = cfg.tun_network_config .. "\n"
end end
local vtunclients = 0
cm:foreach("vtun", "client", cm:foreach("vtun", "client",
function(s) function(s)
if s.enabled == "1" then if s.enabled == "1" then
cfg.tun_network_config = cfg.tun_network_config .. string.format("config client\n\toption enabled '1'\n\toption node '%s'\n\toption passwd '%s'\n\toption clientip '%s'\n\toption serverip '%s'\n\toption netip '%s'\n\n", cfg.tun_network_config = cfg.tun_network_config .. string.format("config client\n\toption enabled '1'\n\toption node '%s'\n\toption passwd '%s'\n\toption clientip '%s'\n\toption serverip '%s'\n\toption netip '%s'\n\n",
s.node, s.passwd, s.clientip, s.serverip, s.netip) s.node, s.passwd, s.clientip, s.serverip, s.netip)
vtunclients = vtunclients + 1
end end
end end
) )
@ -505,6 +507,7 @@ if wgclients > 0 then
private, (tun_port or 5525), (ab .. c .. "." .. d)) .. private, (tun_port or 5525), (ab .. c .. "." .. d)) ..
cfg.wireguard_network_config cfg.wireguard_network_config
end end
local vtunservers = 0
local wgservers = 0 local wgservers = 0
cm:foreach("vtun", "server", cm:foreach("vtun", "server",
function(s) function(s)
@ -522,6 +525,7 @@ cm:foreach("vtun", "server",
cfg.tun_network_config = cfg.tun_network_config .. cfg.tun_network_config = cfg.tun_network_config ..
string.format("config server\n\toption enabled '1'\n\toption host '%s'\n\toption node '%s'\n\toption passwd '%s'\n\toption clientip '%s'\n\toption serverip '%s'\n\toption netip '%s'\n\n", string.format("config server\n\toption enabled '1'\n\toption host '%s'\n\toption node '%s'\n\toption passwd '%s'\n\toption clientip '%s'\n\toption serverip '%s'\n\toption netip '%s'\n\n",
s.host, s.node, s.passwd, s.clientip, s.serverip, s.netip) s.host, s.node, s.passwd, s.clientip, s.serverip, s.netip)
vtunservers = vtunservers + 1
end end
end end
end end
@ -932,23 +936,27 @@ if nixio.fs.access("/etc/config.mesh/olsrd", "r") then
of:write("\n") of:write("\n")
-- add all the tunnel interfaces -- add all the tunnel interfaces
of:write("config Interface\n") if vtunclients + vtunservers + wgclients + wgservers > 0 then
for dev = 50, 50 + maxclients + maxservers of:write("config Interface\n")
do for dev = 50, 50 + vtunclients + vtunservers
of:write("\tlist interface 'tun" .. dev .. "'\n") do
end of:write("\tlist interface 'tun" .. dev .. "'\n")
of:write("\tlist interface 'wgc'\n") end
for dev = 0, maxwgs - 1 if wgclients + wgservers > 0 then
do of:write("\tlist interface 'wgc'\n")
of:write("\tlist interface 'wgs" .. dev .. "'\n") for dev = 0, wgservers - 1
end do
of:write("\toption Ip4Broadcast '255.255.255.255'\n") of:write("\tlist interface 'wgs" .. dev .. "'\n")
local tun_weight = tonumber(nc:get("aredn", "@tunnel[0]", "weight") or 1) end
local is_supernode = nc:get("aredn", "@supernode[0]", "enable") == "1" end
if not tun_weight or tun_weight < 1 or is_supernode then of:write("\toption Ip4Broadcast '255.255.255.255'\n")
of:write("\toption Mode 'ether'\n") local tun_weight = tonumber(nc:get("aredn", "@tunnel[0]", "weight") or 1)
elseif tun_weight > 1 then local is_supernode = nc:get("aredn", "@supernode[0]", "enable") == "1"
of:write("\toption LinkQualityMult 'default " .. (1 / tun_weight) .. "'\n") if not tun_weight or tun_weight < 1 or is_supernode then
of:write("\toption Mode 'ether'\n")
elseif tun_weight > 1 then
of:write("\toption LinkQualityMult 'default " .. (1 / tun_weight) .. "'\n")
end
end end
-- add xlink interfaces -- add xlink interfaces
@ -966,7 +974,7 @@ if nixio.fs.access("/etc/config.mesh/olsrd", "r") then
if weight > 1 then if weight > 1 then
of:write("\toption LinkQualityMult 'default " .. (1 / weight) .. "'\n") of:write("\toption LinkQualityMult 'default " .. (1 / weight) .. "'\n")
elseif weight < 1 then elseif weight < 1 then
print([[ Mode "ether"]]) of:write([[ Mode "ether"]])
end end
else else
of:write("\toption Mode 'ether'\n") of:write("\toption Mode 'ether'\n")