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
os.remove("/tmp/namechange")
end
do_namechange()
if not exists then
dns_update()
local reload = do_namechange()
if not exists or reload then
dns_update(reload)
end
count = 0
end
@ -60,13 +60,14 @@ end
function do_namechange()
-- Do nothing if olsrd is not running
if capture("pidof olsrd") == "" then
return
return false
end
local uptime = nixio.sysinfo().uptime
local hosts = {}
local history = {}
local subdomains = ""
-- Load the hosts file
for line in io.lines("/var/run/hosts_olsr.stable")
@ -76,13 +77,21 @@ function do_namechange()
local name = v[2]
local originator = v[4]
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
hosts[ip] = hosts[ip] .. "/" .. name
else
hosts[ip] = name
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
-- Find the current neighbors
@ -90,7 +99,7 @@ function do_namechange()
local links = luci.jsonc.parse(raw:read("*a"))
raw:close()
if not (links and links.links and #links.links > 0) then
return
return false
end
for i, link in ipairs(links.links)
do
@ -118,13 +127,34 @@ function do_namechange()
f:close()
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
return false
end
function dns_update()
function dns_update(reload)
if reload then
os.execute("/etc/init.d/dnsmasq restart")
else
local pid = capture("pidof dnsmasq")
if pid ~= "" then
nixio.kill(tonumber(pid), 1)
end
end
end
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
Copyright (C) 2023 Tim Wilkinson
See Contributors file for additional contributors
@ -30,52 +29,10 @@
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version
version.
--]]
LICENSE
local dns_file = "/tmp/dnsmasq.d/subdomains.conf"
local f = io.open("/var/run/hosts_olsr")
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()
cp /var/run/hosts_olsr /var/run/hosts_olsr.snapshot
mv -f /var/run/hosts_olsr.snapshot /var/run/hosts_olsr.stable
touch /tmp/namechange

View File

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