mirror of https://github.com/aredn/aredn.git
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:
parent
819812f753
commit
57e0d045e9
|
@ -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,11 +77,19 @@ 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 hosts[ip] then
|
if ip:match("^%d") and originator and originator ~= "myself" and (ip == originator or mid == "(mid") then
|
||||||
hosts[ip] = hosts[ip] .. "/" .. name
|
if hosts[ip] then
|
||||||
else
|
hosts[ip] = hosts[ip] .. "/" .. name
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -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,12 +127,33 @@ 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
|
||||||
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function dns_update()
|
function dns_update(reload)
|
||||||
local pid = capture("pidof dnsmasq")
|
if reload then
|
||||||
if pid ~= "" then
|
os.execute("/etc/init.d/dnsmasq restart")
|
||||||
nixio.kill(tonumber(pid), 1)
|
else
|
||||||
|
local pid = capture("pidof dnsmasq")
|
||||||
|
if pid ~= "" then
|
||||||
|
nixio.kill(tonumber(pid), 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,81 +1,38 @@
|
||||||
#!/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
|
||||||
|
|
||||||
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
This program is free software: you can redistribute it and/or modify
|
||||||
Copyright (C) 2023 Tim Wilkinson
|
it under the terms of the GNU General Public License as published by
|
||||||
See Contributors file for additional contributors
|
the Free Software Foundation version 3 of the License.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is distributed in the hope that it will be useful,
|
||||||
it under the terms of the GNU General Public License as published by
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
the Free Software Foundation version 3 of the License.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
You should have received a copy of the GNU General Public License
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
Additional Terms:
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Additional Terms:
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
||||||
|
See AREDNLicense.txt for more info.
|
||||||
|
|
||||||
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
Attributions to the AREDN Project must be retained in the source code.
|
||||||
See AREDNLicense.txt for more info.
|
If importing this code into a new or existing project attribution
|
||||||
|
to the AREDN project must be added to the source code.
|
||||||
|
|
||||||
Attributions to the AREDN Project must be retained in the source code.
|
You must not misrepresent the origin of the material contained within.
|
||||||
If importing this code into a new or existing project attribution
|
|
||||||
to the AREDN project must be added to the source code.
|
|
||||||
|
|
||||||
You must not misrepresent the origin of the material contained within.
|
Modified versions must be modified to attribute to the original source
|
||||||
|
and be marked in reasonable ways as differentiate it from the original
|
||||||
|
version.
|
||||||
|
|
||||||
Modified versions must be modified to attribute to the original source
|
LICENSE
|
||||||
and be marked in reasonable ways as differentiate it from the original
|
|
||||||
version
|
|
||||||
|
|
||||||
--]]
|
cp /var/run/hosts_olsr /var/run/hosts_olsr.snapshot
|
||||||
|
mv -f /var/run/hosts_olsr.snapshot /var/run/hosts_olsr.stable
|
||||||
local dns_file = "/tmp/dnsmasq.d/subdomains.conf"
|
touch /tmp/namechange
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
|
@ -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 }
|
||||||
|
|
Loading…
Reference in New Issue