More wireguard fixes (#1059)

* More wireguard fixes

* Fix monitoring bug when finding tunnel address
This commit is contained in:
Tim Wilkinson 2024-01-10 00:02:54 -08:00 committed by GitHub
parent f1567d662f
commit bb83a8d1c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 18 deletions

View File

@ -371,18 +371,21 @@ function lqm()
rx_bitrate = 0
}
stations[#stations + 1] = tunnel
else
elseif line:match("^%s*$") then
tunnel = nil
elseif tunnel then
local ip = line:match("P-t-P:(%d+%.%d+%.%d+%.%d+)")
if ip then
tunnel.ip = ip
-- Fake a mac from the ip
local a, b, c, d = ip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
tunnel.mac = string.format("00:00:%02X:%02X:%02X:%02X", a, b, c, d)
end
local txp, txf = line:match("TX packets:(%d+)%s+errors:(%d+)")
if txp and txf then
tunnel.tx_packets = txp
tunnel.tx_fail = txf
else
local txp, txf = line:match("TX packets:(%d+)%s+errors:(%d+)")
if txp and txf then
tunnel.tx_packets = txp
tunnel.tx_fail = txf
end
end
end
end
@ -392,7 +395,7 @@ function lqm()
cursorm:foreach("wireguard", "client",
function(s)
if s.enabled == "1" then
local a, b, c, d = s.clientip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")
local a, b, c, d = s.clientip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+):")
d = tonumber(d) + 1
stations[#stations + 1] = {
type = "Tunnel",

View File

@ -482,23 +482,19 @@ cm:foreach("vtun", "client",
end
)
local wgclients = 0
local wgport = tonumber(tun_port or 5525)
if is_supernode then
wgport = wgport + 1000
end
cm:foreach("wireguard", "client",
function(s)
if s.enabled == "1" then
local server_priv, _, _, client_pub = s.key:match("^(.+=)(.+=)(.+=)(.+=)$")
local addr, port = s.clientip:match("^(%d+%.%d+%.%d+%.%d+):(%d+)$")
cfg.wireguard_network_config = cfg.wireguard_network_config ..
string.format("config interface 'wgc%d'\n\toption proto 'wireguard'\n\toption private_key '%s'\n\toption nohostroute '1'\n\toption listen_port '%s'\n\tlist addresses '%s'\n\n",
wgclients, server_priv, wgport, s.clientip)
wgclients, server_priv, port, addr)
cfg.wireguard_network_config = cfg.wireguard_network_config ..
string.format("config wireguard_wgc%d\n\toption public_key '%s'\n\toption persistent_keepalive '25'\n\tlist allowed_ips '0.0.0.0/0'\n\n",
wgclients, client_pub)
wgclients = wgclients + 1
end
wgport = wgport + 1
end
)
local vtunservers = 0
@ -512,7 +508,7 @@ cm:foreach("vtun", "server",
d = tonumber(d) + 1
cfg.wireguard_network_config = cfg.wireguard_network_config ..
string.format("config interface 'wgs%d'\n\toption proto 'wireguard'\n\toption private_key '%s'\n\toption nohostroute '1'\n\tlist addresses '%s'\n\n",
wgservers, client_priv,(abc .. "." .. d))
wgservers, client_priv, (abc .. "." .. d))
cfg.wireguard_network_config = cfg.wireguard_network_config ..
string.format("config wireguard_wgs%d\n\toption public_key '%s'\n\toption endpoint_host '%s'\n\toption endpoint_port '%s'\n\toption persistent_keepalive '25'\n\tlist allowed_ips '0.0.0.0/0'\n\n",
wgservers, server_pub, s.host, p)
@ -1079,6 +1075,7 @@ do
end
elseif file == "network" then
changes.network = true
changes.tunnels = true -- restarting network devices requires tunnels to restart
elseif file == "dhcp" then
changes.dnsmasq = true
elseif file == "olsrd" then

View File

@ -497,7 +497,7 @@ if parms.button_save and #cli_err == 0 then
cursor:commit("vtun")
cursor:commit("wireguard")
os.execute("/usr/local/bin/node-setup > /dev/null 2>&1")
os.execute("/usr/local/bin/restart-services.sh olsrd tunnels network > /dev/null 2>&1")
os.execute("/usr/local/bin/restart-services.sh network tunnels olsrd > /dev/null 2>&1")
end
local active_tun = get_active_tun()
@ -704,14 +704,15 @@ if config == "mesh" then
end
html.print(" title='client name'></td>")
html.print("<td>")
html.print("<input type=" .. (val == '_add' and 'hidden' or 'text') .. " readonly size=25 oncopy='return false' onmousedown='return false' name=wgclient" .. val .. "_key value='" .. key .. "' title='client key'>")
local _, server_pub, client_priv, client_pub = key:match("^(.+=)(.+=)(.+=)(.+=)$")
local client_key = val == "_add" and "" or (server_pub .. client_priv .. client_pub)
html.print("<input type=hidden name=wgclient" .. val .. "_key value='" .. key .. "'><input type=" .. (val == '_add' and 'hidden' or 'text') .. " readonly size=25 name=wgclient" .. val .. "_clientkey value='" .. client_key .. "' title='client key'>")
html.print("</td>")
local fullnet = netwg[1] .. "." .. netwg[2] .. "." .. netwg[3] .. "." .. (netwg[4] + 2 * cnum) .. ":" .. (wg_port + cnum)
html.print("<td rowspan='2' class='tun_client_center_item'>")
html.print("<input style='min-width:90px;background-color:transparent;border:0;text-align:center;' readonly type=text size=20 name=wgclient" .. val .. "_clientip value='" .. fullnet .. "'/></td>")
html.print("<td rowspan='2' class='tun_client_center_item' align=center>&nbsp;")
local _, server_pub, client_priv, client_pub = key:match("^(.+=)(.+=)(.+=)(.+=)$")
if val ~= "_add" and is_wgtunnel_active(client_pub) then
html.print("<img class='tun_client_active_img' src='/connected.png' title='Connected' />")
else

View File

@ -352,7 +352,7 @@ end
if parms.button_save and #conn_err == 0 then
cursor:commit("vtun")
os.execute("/usr/local/bin/node-setup > /dev/null 2>&1")
os.execute("/usr/local/bin/restart-services.sh olsrd tunnels network > /dev/null 2>&1")
os.execute("/usr/local/bin/restart-services.sh network tunnels olsrd > /dev/null 2>&1")
end
local active_tun = get_active_tun()