From mboxrd@z Thu Jan  1 00:00:00 1970
From: Bernhard Held <berny156@gmx.de>
To: development@lists.ipfire.org
Subject:
 [PATCH v2 4/4] proxy.cgi: fix subnet comparison for proxy.pac generation
Date: Mon, 12 Feb 2018 23:19:32 +0100
Message-ID: <20180212221932.29122-5-berny156@gmx.de>
In-Reply-To: <20180212221932.29122-1-berny156@gmx.de>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============4093558912022667355=="
List-Id: <development.lists.ipfire.org>

--===============4093558912022667355==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

The logic of subnet comparison is broken. E.g. if the blue netmask is
255.255.255.0, it's impossible to add a VPN subnet with the same netmask.
The fix simplifies the logic by using Network::network_equal.
---
 html/cgi-bin/proxy.cgi | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/html/cgi-bin/proxy.cgi b/html/cgi-bin/proxy.cgi
index ea3b41126..df436595b 100644
--- a/html/cgi-bin/proxy.cgi
+++ b/html/cgi-bin/proxy.cgi
@@ -3065,9 +3065,10 @@ END
 			{
 				@temp =3D split(/\//);
 				chomp $temp[1];
-				if (
-					($temp[0] ne $netsettings{'GREEN_NETADDRESS'}) && ($temp[1] ne $netsett=
ings{'GREEN_NETMASK'}) &&
-					($temp[0] ne $netsettings{'BLUE_NETADDRESS'}) && ($temp[1] ne $netsetti=
ngs{'BLUE_NETMASK'})
+				unless (
+					# GREEN or BLUE networks are already added to "DIRECT". Check if given =
network is different from these.
+					&Network::network_equal("$temp[0]/$temp[1]", "$netsettings{'GREEN_NETAD=
DRESS'}/$netsettings{'GREEN_NETMASK'}") ||
+					&Network::network_equal("$temp[0]/$temp[1]", "$netsettings{'BLUE_NETADD=
RESS'}/$netsettings{'BLUE_NETMASK'}")
 					)
 				{
 					print FILE " ||\n     (isInNet(myIpAddress(), \"$temp[0]\", \"$temp[1]\=
"))";
--=20
2.16.1


--===============4093558912022667355==--