From patchwork Sat Jul 25 19:08:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 3273 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BDb3W50BLz3xVB for ; Sat, 25 Jul 2020 18:59:51 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BDb3S5RXwzTZ; Sat, 25 Jul 2020 18:59:48 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BDb3S270Qz2yJ7; Sat, 25 Jul 2020 18:59:48 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BDb3R25Pbz2xVp for ; Sat, 25 Jul 2020 18:59:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BDb3P0pd7zTZ for ; Sat, 25 Jul 2020 18:59:44 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1595703585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tIN73qnLS+denD2tc2LcHAX7r6+wXi7WCnLtJIh1tR8=; b=cKra1GXdquMxIaFHaVfzoEIWS79Tkq4KdagtcuQWiTMrsd09gdFUqs56HIqoIWtrE/aOcF UnfjW6bj37HysEBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1595703585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tIN73qnLS+denD2tc2LcHAX7r6+wXi7WCnLtJIh1tR8=; b=Zu7XjV2wMkx1lnKz52s2TAUygb/qBO1it9V8FX9bHBW4dfkPHLvoM+stQEBZz4eY1crY/l RmoNxmybmWpfACd7RGsFaee9nThxpI80kc/QUZCFfrZxg7myHbIyFSsdanzCrLEm3UqtK7 intBhXJw8tBUFxNX/avgRp9OpBgCtBxzBlJIWX/H4yN+/2zqm9BI1iwpZCkz3W0ehGvYGu yWrYenM3IEUjp9k6/JF/jDYDmBkFF2m132qNFwi7ZoUviEO4Tgkf3n9rM3xMJSQ9+6wi8X 86jcCPAgL6oONw1E71jl9C2ZrxvYnj6w9eAuzHOo4in3SZ2TMA0gWbghWBaY7Q== To: development@lists.ipfire.org From: =?utf-8?q?Peter_M=C3=BCller?= Subject: [PATCH 1/2] network-functions.pl: fix network membership test Message-ID: <6bc37aaf-4096-9ec6-030b-3781a015fc11@ipfire.org> Date: Sat, 25 Jul 2020 19:08:07 +0000 MIME-Version: 1.0 Content-Language: en-US Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=peter.mueller@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This is based on an orphaned patch provided by Tim FitzGeorge and _finally_ fixes incorrect network membership calculations. Those were are usability pain in the ass deluxe, as they rendered some combinations of configuring OpenVPN and IPsec services unusable. Fixes: #11235 Fixes: #12263 Cc: Tim FitzGeorge Cc: Michael Tremer Cc: Alexander Marx Signed-off-by: Peter Müller --- config/cfgroot/network-functions.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index 8649d0502..b6f994522 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -115,7 +115,7 @@ sub network_equal { return undef; } - if ($bin1[0] eq $bin2[0] && $bin1[1] eq $bin2[1]) { + if ($bin1[0] == $bin2[0] && $bin1[1] == $bin2[1]) { return 1; } @@ -295,7 +295,7 @@ sub ip_address_in_network($$) { # Find end address my $broadcast_bin = $network_bin ^ (~$netmask_bin % 2 ** 32); - return (($address_bin ge $network_bin) && ($address_bin le $broadcast_bin)); + return (($address_bin >= $network_bin) && ($address_bin <= $broadcast_bin)); } sub setup_upstream_proxy() { From patchwork Sat Jul 25 19:08:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 3274 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4BDb3x3TjNz3xVB for ; Sat, 25 Jul 2020 19:00:13 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4BDb3w5y2rz2mn; Sat, 25 Jul 2020 19:00:12 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4BDb3w4Gprz2yW9; Sat, 25 Jul 2020 19:00:12 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4BDb3v0r8zz2xVp for ; Sat, 25 Jul 2020 19:00:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4BDb3s6l1vz1VR for ; Sat, 25 Jul 2020 19:00:09 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1595703610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ljiQ+UXJIbcrjWGcRCgqrPLP5rI0xlLNyy969UH74w=; b=XT/X+5YY9vqUH1ZauXdVmWRTta1VEpp8xvQCpNkWD+bOQuLsy3AyGdQp9jTH9eOMNC9mx1 PUL2Q/3p61wL91DQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1595703610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ljiQ+UXJIbcrjWGcRCgqrPLP5rI0xlLNyy969UH74w=; b=AJyAjjmNQ0EXM7JzzyqI7To3mtqVZDMIjE5rCFLmMtILr/xgtZokTYzgrEpO4p5ewBATm0 +a0FVK9D1HV0se2YrAuTe5tugQTAPGEr3bHt2SYGD598buVrN6ZEl/KeMOhyLZMZFcAsjH UsBXyrLyEtM4RLxqAY3AVaW571HPZhC7zjkWxsyKj4n3YfXIpx0q2drv0pUTv8sXZVWFXe A2K1b5sRXLG5IrysdQHMbS63vob5OTk4JLEVH0udB+OYDeAu1AVtAKDg+cIahj+9b2vx6B QJSUGcTCDAPgFAxTQrtSsnpOYMjmS915kuGXoGwxULmHFEukNUICtrZ67JhpZQ== Subject: [PATCH 2/2] network-functions.pl: add missing unit tests for changed, network membership procedure To: development@lists.ipfire.org References: <6bc37aaf-4096-9ec6-030b-3781a015fc11@ipfire.org> From: =?utf-8?q?Peter_M=C3=BCller?= Message-ID: <982fdab7-5283-0639-f96b-9ef37a955b3d@ipfire.org> Date: Sat, 25 Jul 2020 19:08:37 +0000 MIME-Version: 1.0 In-Reply-To: <6bc37aaf-4096-9ec6-030b-3781a015fc11@ipfire.org> Content-Language: en-US Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=peter.mueller@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Cc: Tim FitzGeorge Cc: Alexander Marx Signed-off-by: Peter Müller --- config/cfgroot/network-functions.pl | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index b6f994522..3d7f04743 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -191,7 +191,7 @@ sub check_ip_address_and_netmask($$) { my ($address, $netmask) = split(/\//, $network, 2); # Check if the IP address is fine. - # + # my $result = &check_ip_address($address); unless ($result) { return $result; @@ -449,14 +449,15 @@ sub get_mac_by_name($) { # Remove the next line to enable the testsuite __END__ -sub assert($) { +sub assert($$) { + my $tst = shift; my $ret = shift; if ($ret) { return; } - print "ASSERTION ERROR"; + print "ASSERTION ERROR - $tst\n"; exit(1); } @@ -464,10 +465,10 @@ sub testsuite() { my $result; my $address1 = &ip2bin("8.8.8.8"); - assert($address1 == 134744072); + assert('ip2bin("8.8.8.8")', $address1 == 134744072); my $address2 = &bin2ip($address1); - assert($address2 eq "8.8.8.8"); + assert("bin2ip($address1)", $address2 eq "8.8.8.8"); # Check if valid IP addresses are correctly recognised. foreach my $address ("1.2.3.4", "192.168.180.1", "127.0.0.1") { @@ -486,34 +487,37 @@ sub testsuite() { } $result = &check_ip_address_and_netmask("192.168.180.0/255.255.255.0"); - assert($result); + assert('check_ip_address_and_netmask("192.168.180.0/255.255.255.0")', $result); $result = &convert_netmask2prefix("255.255.254.0"); - assert($result == 23); + assert('convert_netmask2prefix("255.255.254.0")', $result == 23); $result = &convert_prefix2netmask(8); - assert($result eq "255.0.0.0"); + assert('convert_prefix2netmask(8)', $result eq "255.0.0.0"); $result = &find_next_ip_address("1.2.3.4", 2); - assert($result eq "1.2.3.6"); + assert('find_next_ip_address("1.2.3.4", 2)', $result eq "1.2.3.6"); $result = &network_equal("192.168.0.0/24", "192.168.0.0/255.255.255.0"); - assert($result); + assert('network_equal("192.168.0.0/24", "192.168.0.0/255.255.255.0")', $result); $result = &network_equal("192.168.0.0/24", "192.168.0.0/25"); - assert(!$result); + assert('network_equal("192.168.0.0/24", "192.168.0.0/25")', !$result); $result = &network_equal("192.168.0.0/24", "192.168.0.128/25"); - assert(!$result); + assert('network_equal("192.168.0.0/24", "192.168.0.128/25")', !$result); $result = &network_equal("192.168.0.1/24", "192.168.0.XXX/24"); - assert(!$result); + assert('network_equal("192.168.0.1/24", "192.168.0.XXX/24")', !$result); $result = &ip_address_in_network("10.0.1.4", "10.0.0.0/8"); - assert($result); + assert('ip_address_in_network("10.0.1.4", "10.0.0.0/8"', $result); $result = &ip_address_in_network("192.168.30.11", "192.168.30.0/255.255.255.0"); - assert($result); + assert('ip_address_in_network("192.168.30.11", "192.168.30.0/255.255.255.0")', $result); + + $result = &ip_address_in_network("192.168.30.11", "0.0.0.0/8"); + assert('ip_address_in_network("192.168.30.11", "0.0.0.0/8")', !$result); print "Testsuite completed successfully!\n";