From 57e0d045e9373868b3140315dc53c852f49e8cd5 Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Thu, 21 Sep 2023 20:13:38 -0700 Subject: [PATCH] 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 --- files/usr/local/bin/mgr/namechange.lua | 58 +++++++++++---- files/usr/local/bin/olsrd-namechange | 99 ++++++++------------------ files/www/cgi-bin/vpn | 3 - 3 files changed, 72 insertions(+), 88 deletions(-) diff --git a/files/usr/local/bin/mgr/namechange.lua b/files/usr/local/bin/mgr/namechange.lua index 13c98546..7a480d90 100644 --- a/files/usr/local/bin/mgr/namechange.lua +++ b/files/usr/local/bin/mgr/namechange.lua @@ -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,11 +77,19 @@ 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 hosts[ip] then - hosts[ip] = hosts[ip] .. "/" .. name - else - hosts[ip] = name + 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 @@ -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,12 +127,33 @@ 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() - local pid = capture("pidof dnsmasq") - if pid ~= "" then - nixio.kill(tonumber(pid), 1) +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 diff --git a/files/usr/local/bin/olsrd-namechange b/files/usr/local/bin/olsrd-namechange index ed1576be..422bef79 100755 --- a/files/usr/local/bin/olsrd-namechange +++ b/files/usr/local/bin/olsrd-namechange @@ -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 - Copyright (C) 2023 Tim Wilkinson - See Contributors file for additional contributors + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 3 of the License. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation version 3 of the License. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + 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, - but WITHOUT ANY WARRANTY; without even the implied warranty of - 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 + along with this program. If not, see . - You should have received a copy of the GNU General Public License - along with this program. If not, see . + Additional Terms: - 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. - See AREDNLicense.txt for more info. + Attributions to the AREDN Project must be retained in the source code. + 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. - 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. - 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 - and be marked in reasonable ways as differentiate it from the original - 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 diff --git a/files/www/cgi-bin/vpn b/files/www/cgi-bin/vpn index 90e52fa2..3571863b 100755 --- a/files/www/cgi-bin/vpn +++ b/files/www/cgi-bin/vpn @@ -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 }