From: Tom Haley Date: Thu, 5 Dec 2024 07:54:19 +0000 (+0300) Subject: luci-proto-wireguard: fixed incorrect peer detection for ipv6 and default port X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=d52505ee03b5bc8401e2af6665d11afedfeeedfb;p=project%2Fluci.git luci-proto-wireguard: fixed incorrect peer detection for ipv6 and default port Fixed incorrect peer detection if IP v6 is used and no port for peer is defined. Signed-off-by: Tom Haley (cherry picked from commit 461d632d5c57bb179f2dae0b164b2d7d99d7432c) --- diff --git a/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard b/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard index 32acbb639d..55f0bba2a9 100644 --- a/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard +++ b/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard @@ -20,10 +20,10 @@ function checkPeerHost(configHost, configPort, wgHost) { const hostIp = replace(wgHost, /\[|\]/g, ""); if (ips) { for (let line = ips.read('line'); length(line); line = ips.read('line')) { - const ip = rtrim(line, '\n'); + const ip = rtrim(line, '\n'); if (configPort && (ip + ":" + configPort == hostIp)) { return true; - } else if (ip == substr(hostIp, 0, index(hostIp, ":"))) { + } else if (ip == substr(hostIp, 0, rindex(hostIp, ":"))) { return true; } }