From b3dec790951444d5e5f5c6659ca8b51569207b03 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Tue, 31 Aug 2021 21:30:38 +0000 Subject: [PATCH] Ensure that vpnc-script-win.js picks a legal "internal gateway" address even for /32 netmask Attempted fix for https://gitlab.com/openconnect/vpnc-scripts/-/issues/26 (formerly https://gitlab.com/openconnect/openconnect/-/issues/306). Signed-off-by: Daniel Lenski --- vpnc-script-win.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vpnc-script-win.js b/vpnc-script-win.js index 129bb93..56f85ed 100644 --- a/vpnc-script-win.js +++ b/vpnc-script-win.js @@ -60,9 +60,12 @@ case "pre-init": break; case "connect": var gw = getDefaultGateway(); - // Calculate the first usable address in subnet + // Calculate the first legal host address in subnet + // (identical to the INTERNAL_IP4_ADDRESS if the netmask is + // 255.255.255.255, otherwise increment the last octet) var internal_gw_array = env("INTERNAL_IP4_NETADDR").split("."); - internal_gw_array[3]++; + if (env("INTERNAL_IP4_NETMASK").trim() != "255.255.255.255" && env("INTERNAL_IP4_NETMASKLEN") != 32) + internal_gw_array[3]++; var internal_gw = internal_gw_array.join("."); echo("VPN Gateway: " + env("VPNGATEWAY")); -- 2.49.0