Supernode fixes (#944)

* Subdomain check too slow for realtime
 so now do it in the namecheck service instead.
* Dont commit to VPN address until we set the DNS name
 helps supernode setup
This commit is contained in:
Tim Wilkinson 2023-09-21 20:13:38 -07:00 committed by GitHub
parent 819812f753
commit 57e0d045e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 88 deletions

View File

@ -47,9 +47,9 @@ function namechange()
if exists then if exists then
os.remove("/tmp/namechange") os.remove("/tmp/namechange")
end end
do_namechange() local reload = do_namechange()
if not exists then if not exists or reload then
dns_update() dns_update(reload)
end end
count = 0 count = 0
end end
@ -60,13 +60,14 @@ end
function do_namechange() function do_namechange()
-- Do nothing if olsrd is not running -- Do nothing if olsrd is not running
if capture("pidof olsrd") == "" then if capture("pidof olsrd") == "" then
return return false
end end
local uptime = nixio.sysinfo().uptime local uptime = nixio.sysinfo().uptime
local hosts = {} local hosts = {}
local history = {} local history = {}
local subdomains = ""
-- Load the hosts file -- Load the hosts file
for line in io.lines("/var/run/hosts_olsr.stable") for line in io.lines("/var/run/hosts_olsr.stable")
@ -76,13 +77,21 @@ function do_namechange()
local name = v[2] local name = v[2]
local originator = v[4] local originator = v[4]
local mid = v[5] local mid = v[5]
if ip and string.match(ip, "^%d") and originator and originator ~= "myself" and (ip == originator or mid == "(mid") then if ip then
if ip:match("^%d") and originator and originator ~= "myself" and (ip == originator or mid == "(mid") then
if hosts[ip] then if hosts[ip] then
hosts[ip] = hosts[ip] .. "/" .. name hosts[ip] = hosts[ip] .. "/" .. name
else else
hosts[ip] = name hosts[ip] = name
end end
end end
if name and name:sub(1,2) == "*." then
if not name:match("%.local%.mesh$") then
name = name .. ".local.mesh"
end
subdomains = subdomains .. "address=/." .. name:sub(3) .. "/" .. ip .. "\n"
end
end
end end
-- Find the current neighbors -- Find the current neighbors
@ -90,7 +99,7 @@ function do_namechange()
local links = luci.jsonc.parse(raw:read("*a")) local links = luci.jsonc.parse(raw:read("*a"))
raw:close() raw:close()
if not (links and links.links and #links.links > 0) then if not (links and links.links and #links.links > 0) then
return return false
end end
for i, link in ipairs(links.links) for i, link in ipairs(links.links)
do do
@ -118,13 +127,34 @@ function do_namechange()
f:close() f:close()
end end
-- Write out the subdomains
local osubdomains = ""
f = io.open("/tmp/dnsmasq.d/subdomains.conf")
if f then
osubdomains = f:read("*a")
f:close()
end
if osubdomains ~= subdomains then
local w = io.open("/tmp/dnsmasq.d/subdomains.conf", "w+")
if w then
w:write(subdomains)
w:close()
return true
end
end end
function dns_update() return false
end
function dns_update(reload)
if reload then
os.execute("/etc/init.d/dnsmasq restart")
else
local pid = capture("pidof dnsmasq") local pid = capture("pidof dnsmasq")
if pid ~= "" then if pid ~= "" then
nixio.kill(tonumber(pid), 1) nixio.kill(tonumber(pid), 1)
end end
end end
end
return namechange return namechange

View File

@ -1,6 +1,5 @@
#!/usr/bin/lua #!/bin/sh
--[[ <<'LICENSE'
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (C) 2023 Tim Wilkinson Copyright (C) 2023 Tim Wilkinson
See Contributors file for additional contributors See Contributors file for additional contributors
@ -30,52 +29,10 @@
Modified versions must be modified to attribute to the original source Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original and be marked in reasonable ways as differentiate it from the original
version version.
--]] LICENSE
local dns_file = "/tmp/dnsmasq.d/subdomains.conf" cp /var/run/hosts_olsr /var/run/hosts_olsr.snapshot
mv -f /var/run/hosts_olsr.snapshot /var/run/hosts_olsr.stable
local f = io.open("/var/run/hosts_olsr") touch /tmp/namechange
if f then
local data = ""
local subdomains = ""
for line in f:lines()
do
local ip, host = line:match("^(%S+)%s+%*%.(%S+)")
if host then
if not host:match("%.local%.mesh$") then
host = host .. ".local.mesh"
end
subdomains = subdomains .. "address=/." .. host .. "/" .. ip .. "\n"
else
data = data .. line .. "\n"
end
end
f:close()
local w = io.open("/var/run/hosts_olsr.stable", "w+")
if w then
w:write(data)
w:close()
end
-- Write out the subdomains to lookup
local osubdomains = ""
f = io.open(dns_file)
if f then
osubdomains = f:read("*a")
f:close()
end
if osubdomains ~= subdomains then
local w = io.open(dns_file, "w+")
if w then
w:write(subdomains)
w:close()
end
os.execute("/etc/init.d/dnsmasq restart")
end
end
io.open("/tmp/namechange", "w+"):close()

View File

@ -122,9 +122,6 @@ function get_server_network_address()
net_base = "172.30." net_base = "172.30."
end end
server_net = net_base .. tonumber(b, 16) .. "." .. ((tonumber(a, 16) * 4) % 256) server_net = net_base .. tonumber(b, 16) .. "." .. ((tonumber(a, 16) * 4) % 256)
cursor:set("vtun", "@network[0]", "start", server_net)
cursor:commit("vtun")
end end
local a, b, c, d = server_net:match("^(%d+).(%d+).(%d+).(%d+)$") local a, b, c, d = server_net:match("^(%d+).(%d+).(%d+).(%d+)$")
return { a, b, c, d } return { a, b, c, d }