luci-proto-wireguard: Fix incorrect peer detection for IP v6
authorTom Haley <[email protected]>
Mon, 2 Dec 2024 15:40:32 +0000 (18:40 +0300)
committerPaul Donald <[email protected]>
Thu, 5 Dec 2024 17:13:49 +0000 (18:13 +0100)
This commit fixes incorrect peer detection when using IP v6 by deleting all the square the square brackets from the wgHost variable.

Signed-off-by: Tom Haley <[email protected]>
(cherry picked from commit 5c97a89684cbc9eb6cf891f44cfd7f89237c52d4)

protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard

index c177da4773a6a5bdf6753767eff9f303c616e1aa..5ffcfd85a274def33b10ed5ee0288cdd4d1db5cb 100644 (file)
@@ -17,10 +17,11 @@ function command(cmd) {
 
 function checkPeerHost(configHost, configPort, wgHost) {
        const ips = popen(`resolveip ${configHost} 2>/dev/null`);
+       const hostIp = replace(wgHost, /\[|\]/g, "");
        if (ips) {
                for (let line = ips.read('line'); length(line); line = ips.read('line')) {
                        const ip =  rtrim(line, '\n');
-                       if (ip + ":" + configPort == wgHost) {
+                       if (ip + ":" + configPort == hostIp) {
                                return true;
                        }
                }