Skip to contentSkip to conversation

netconfig: Fix address format validation

PATCH Applied Andrew Zaborowski 3 participants 30 messages Jun 16, 2022 – Jun 27, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/15 netconfig: Fix address format validation

Drop the wrong negation in the error check. Check that there are no extra characters after prefix length suffix. Reset errno 0 before the strtoul call, as recommended by the manpage.

---
 src/netconfig.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/netconfig.c +4 -2
index 2ab03b90..4a70b0ca 100644
@@ -515,6 +515,7 @@ static struct l_rtnl_address *netconfig_get_static6_address(
 {
 	L_AUTO_FREE_VAR(char *, ip);
 	char *p;
+	char *endp;
 	struct l_rtnl_address *ret;
 	uint32_t prefix_len = 128;
 
@@ -530,8 +531,9 @@ static struct l_rtnl_address *netconfig_get_static6_address(
 	if (*++p == '\0')
 		goto no_prefix_len;
 
-	prefix_len = strtoul(p, NULL, 10);
-	if (!unlikely(errno == EINVAL || errno == ERANGE ||
+	errno = 0;
+	prefix_len = strtoul(p, &endp, 10);
+	if (unlikely(*endp != '\0' || errno ||
 			!prefix_len || prefix_len > 128)) {
 		l_error("netconfig: Invalid prefix '%s' provided in network"
 				" configuration file", p);
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/15 storage: Log a message on network file parse errors

Most users of storage_network_open don't log errors when the function returns a NULL and fall back to defaults (empty l_settings). storage_network_open() itself only logs errors if the flie is encrypted. Now also log an error when l_settings_load_from_file() fails to help track down potential syntax errors.

---
 src/storage.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/storage.c +3 -1
index 2100d08d..77be36c8 100644
@@ -597,8 +597,10 @@ struct l_settings *storage_network_open(enum security type, const char *ssid)
 
 	settings = l_settings_new();
 
-	if (!l_settings_load_from_file(settings, path))
+	if (!l_settings_load_from_file(settings, path)) {
+		l_error("Error loading %s", path);
 		goto error;
+	}
 
 	if (type != SECURITY_NONE && !storage_decrypt(settings, path, ssid))
 		goto error;
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 02/15] storage: Log a message on network file parse errors

Quoted 9 lines · Andrew Zaborowski

Most users of storage_network_open don't log errors when the function returns a NULL and fall back to defaults (empty l_settings). storage_network_open() itself only logs errors if the flie is encrypted. Now also log an error when l_settings_load_from_file() fails to help track down potential syntax errors.

---
  src/storage.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Hmm, I'm still not sure logging l_errors inside storage.c is the right approach.
I see this crept in when encrypted profiles were merged.

Anyway, I went ahead and applied this, but I wonder if we need to fix this to return proper error codes at some point.

Applied, thanks.

Regards,
-Denis

#3 lore raw

Re: [PATCH 02/15] storage: Log a message on network file parse errors

In reply to Andrew Zaborowski
Quoted 9 lines · Andrew Zaborowski

Most users of storage_network_open don't log errors when the function returns a NULL and fall back to defaults (empty l_settings). storage_network_open() itself only logs errors if the flie is encrypted. Now also log an error when l_settings_load_from_file() fails to help track down potential syntax errors.

---
  src/storage.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Hmm, I'm still not sure logging l_errors inside storage.c is the right approach.
I see this crept in when encrypted profiles were merged.

Anyway, I went ahead and applied this, but I wonder if we need to fix this to return proper error codes at some point.

Applied, thanks.

Regards,
-Denis

#4 lore raw

PATCH 3/15 station: Move netconfig_reset() to common path

In reply to Andrew Zaborowski

To avoid repetition, call netconfig_reset in
station_reset_connection_state.

---
 src/station.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
src/station.c +3 -9
index 7c88f266..e5972269 100644
@@ -1623,6 +1623,9 @@ static void station_reset_connection_state(struct station *station)
 
 	station_roam_state_clear(station);
 
+	if (station->netconfig)
+		netconfig_reset(station->netconfig);
+
 	/* Refresh the ordered network list */
 	network_rank_update(station->connected_network, false);
 	l_queue_remove(station->networks_sorted, station->connected_network);
@@ -1655,9 +1658,6 @@ static void station_disassociated(struct station *station)
 {
 	l_debug("%u", netdev_get_ifindex(station->netdev));
 
-	if (station->netconfig)
-		netconfig_reset(station->netconfig);
-
 	station_reset_connection_state(station);
 
 	station_enter_state(station, STATION_STATE_DISCONNECTED);
@@ -3096,9 +3096,6 @@ static void station_disconnect_onconnect(struct station *station,
 		return;
 	}
 
-	if (station->netconfig)
-		netconfig_reset(station->netconfig);
-
 	station_reset_connection_state(station);
 
 	station_enter_state(station, STATION_STATE_DISCONNECTING);
@@ -3402,9 +3399,6 @@ int station_disconnect(struct station *station)
 	if (!station->connected_bss)
 		return -ENOTCONN;
 
-	if (station->netconfig)
-		netconfig_reset(station->netconfig);
-
 	/*
 	 * If the disconnect somehow fails we won't know if we're still
 	 * connected so we may as well indicate now that we're no longer
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 03/15] station: Move netconfig_reset() to common path

Hi Andrew,

Quoted 6 lines · Andrew Zaborowski

To avoid repetition, call netconfig_reset in
station_reset_connection_state.

---
  src/station.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)

Applied, thanks.

Regards,
-Denis

#6 lore raw

PATCH 4/15 monitor: Print netlink errors from Extended ACKs if available

In reply to Andrew Zaborowski
---
 monitor/nlmon.c | 55 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 17 deletions(-)
monitor/nlmon.c +38 -17
index 34c5eed6..ff23140d 100644
@@ -50,6 +50,7 @@
 #include "linux/nl80211.h"
 
 #include "ell/useful.h"
+#include "ell/netlink-private.h"
 #include "src/ie.h"
 #include "src/mpdu.h"
 #include "src/eapol.h"
@@ -5332,15 +5333,7 @@ static const struct attr_entry rekey_table[] = {
 	{ }
 };
 
-#define NLA_OK(nla,len)         ((len) >= (int) sizeof(struct nlattr) && \
-				(nla)->nla_len >= sizeof(struct nlattr) && \
-				(nla)->nla_len <= (len))
-#define NLA_NEXT(nla,attrlen)	((attrlen) -= NLA_ALIGN((nla)->nla_len), \
-				(struct nlattr*)(((char*)(nla)) + \
-				NLA_ALIGN((nla)->nla_len)))
-
-#define NLA_LENGTH(len)		(NLA_ALIGN(sizeof(struct nlattr)) + (len))
-#define NLA_DATA(nla)		((void*)(((char*)(nla)) + NLA_LENGTH(0)))
+#undef NLA_PAYLOAD
 #define NLA_PAYLOAD(nla)	((int)((nla)->nla_len - NLA_LENGTH(0)))
 
 static void print_supported_commands(unsigned int level, const char *label,
@@ -6835,7 +6828,7 @@ static void netlink_str(char *str, size_t size,
 	}
 }
 
-static void print_message(struct nlmon *nlmon, const struct timeval *tv,
+static bool print_message(struct nlmon *nlmon, const struct timeval *tv,
 						enum msg_type type,
 						uint16_t flags, int status,
 						uint8_t cmd, uint8_t version,
@@ -6848,11 +6841,11 @@ static void print_message(struct nlmon *nlmon, const struct timeval *tv,
 	bool out = false;
 
 	if (nlmon->nowiphy && (cmd == NL80211_CMD_NEW_WIPHY))
-		return;
+		return false;
 
 	if (nlmon->noscan && ((cmd == NL80211_CMD_NEW_SCAN_RESULTS) ||
 			(cmd == NL80211_CMD_TRIGGER_SCAN)))
-		return;
+		return false;
 
 	switch (type) {
 	case MSG_REQUEST:
@@ -6911,6 +6904,8 @@ static void print_message(struct nlmon *nlmon, const struct timeval *tv,
 			print_field("Status: %d", status);
 		break;
 	}
+
+	return true;
 }
 
 struct nlmon_req_match {
@@ -6978,12 +6973,17 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv,
 			enum msg_type type;
 			struct nlmsgerr *err;
 			int status;
+			bool print;
+			const char *err_str = NULL;
+			uint32_t err_offset = -1U;
 
 			switch (nlmsg->nlmsg_type) {
 			case NLMSG_ERROR:
 				type = MSG_RESPONSE;
 				err = NLMSG_DATA(nlmsg);
 				status = -err->error;
+				netlink_parse_ext_ack_error(nlmsg, &err_str,
+								&err_offset);
 				break;
 			case NLMSG_DONE:
 				type = MSG_COMPLETE;
@@ -6994,10 +6994,18 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv,
 			}
 
 			store_message(nlmon, tv, nlmsg);
-			print_message(nlmon, tv, type, nlmsg->nlmsg_flags, status,
+			print = print_message(nlmon, tv, type,
+						nlmsg->nlmsg_flags, status,
 						req->cmd, req->version,
 						NULL, sizeof(status));
 			nlmon_req_free(req);
+
+			if (err_str && print)
+				print_field("Extended error: %s", err_str);
+
+			if (err_offset != -1U && print)
+				print_field("Offending element offset: %i "
+						"bytes", (int) err_offset);
 		}
 		return;
 	}
@@ -7795,6 +7803,8 @@ static void print_nlmsg(const struct timeval *tv, const struct nlmsghdr *nlmsg)
 {
 	struct nlmsgerr *err;
 	int status;
+	const char *err_str = NULL;
+	uint32_t err_offset = -1U;
 
 	print_nlmsghdr(tv, nlmsg);
 
@@ -7802,11 +7812,22 @@ static void print_nlmsg(const struct timeval *tv, const struct nlmsghdr *nlmsg)
 	case NLMSG_ERROR:
 		err = NLMSG_DATA(nlmsg);
 		status = err->error;
-		if (status < 0)
-			print_field("Error: %d (%s)",
-						status, strerror(-status));
-		else
+		if (status >= 0) {
 			print_field("ACK: %d", status);
+			break;
+		}
+
+		print_field("Error: %d (%s)", status, strerror(-status));
+
+		netlink_parse_ext_ack_error(nlmsg, &err_str, &err_offset);
+
+		if (err_str)
+			print_field("Extended error: %s", err_str);
+
+		if (err_offset != -1U)
+			print_field("Offending element offset: %i bytes",
+					(int) err_offset);
+
 		break;
 
 	case NLMSG_DONE:
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 04/15] monitor: Print netlink errors from Extended ACKs if available

Hi Andrew,

monitor/nlmon.c line 53

Quoted 13 lines · Andrew Zaborowski
---
  monitor/nlmon.c | 55 ++++++++++++++++++++++++++++++++++---------------
  1 file changed, 38 insertions(+), 17 deletions(-)
monitor/nlmon.c +1 -0
index 34c5eed6..ff23140d 100644
@@ -50,6 +50,7 @@
  #include "linux/nl80211.h"
 
  #include "ell/useful.h"
+#include "ell/netlink-private.h"

I'm pretty sure this breaks shared-ell builds as netlink-private.h is not an installed header.

You'd need to expose this function into public API.

Regards,
-Denis

#8 lore raw

PATCH 5/15 testrunner: Fix parsing for some arguments

In reply to Andrew Zaborowski

Currently the parameter values reach run-tests by first being parsed by runner.py's RunnerArgParser, then the resulting object members being encoded as a commandline string, then as environment variables, then the environment being converted to a python string list and passed to RunnerCoreArgParser again. Where argument names (like --sub-tests) had dashes, the object members had underscores (.sub_tests), this wasn't taken into account when building the python string list from environment variables so convert all underscores to dashes and hope that all the names match now.

Additionally some arguments used nargs='1' or nargs='*' which resulted in their python values becoming lists. They were converted back to command line arguments such as: --sub_tests ['static_test.py'], and when parsed by RunnerCoreArgParser again, the values ended up being lists of lists. In all three cases it seems the actual user of the parsed value actually expects a single string with comma-separated substrings in it so just drop the nargs= uses.

---
 tools/runner.py | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
tools/runner.py +2 -5
index 2ce26de0..b018a0ad 100644
@@ -108,7 +108,7 @@ class RunnerCoreArgParse(ArgumentParser):
 				help='Enables iwmon output to file')
 		self.add_argument('--sub-tests', '-S',
 				metavar='<subtests>',
-				type=str, nargs=1, help='List of subtests to run',
+				type=str, help='List of subtests to run',
 				default=None, dest='sub_tests')
 		self.add_argument('--result', '-e',
 				type=os.path.abspath,
@@ -131,8 +131,6 @@ class RunnerCoreArgParse(ArgumentParser):
 		auto_unit_group.add_argument('--unit-tests', '-U',
 				metavar='<tests>',
 				type=str,
-				nargs='?',
-				const='*',
 				help='List of unit tests to run',
 				dest='unit_tests')
 
@@ -141,7 +139,6 @@ class RunnerCoreArgParse(ArgumentParser):
 		valgrind_gdb_group.add_argument('--gdb', '-g',
 				metavar='<exec>',
 				type=str,
-				nargs=1,
 				help='Run gdb on specified executable',
 				dest='gdb')
 		valgrind_gdb_group.add_argument('--valgrind', '-V',
@@ -156,7 +153,7 @@ class RunnerCoreArgParse(ArgumentParser):
 
 		options = []
 		for k, v in os.environ.items():
-			options.append('--' + k)
+			options.append('--' + k.replace('_', '-'))
 			options.append(v)
 
 		return self.parse_known_args(args=options, namespace=RunnerNamespace())[0]
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH 05/15] testrunner: Fix parsing for some arguments

Hi Andrew,

Quoted 17 lines · Andrew Zaborowski

Currently the parameter values reach run-tests by first being parsed by runner.py's RunnerArgParser, then the resulting object members being encoded as a commandline string, then as environment variables, then the environment being converted to a python string list and passed to RunnerCoreArgParser again. Where argument names (like --sub-tests) had dashes, the object members had underscores (.sub_tests), this wasn't taken into account when building the python string list from environment variables so convert all underscores to dashes and hope that all the names match now.

Additionally some arguments used nargs='1' or nargs='*' which resulted in their python values becoming lists. They were converted back to command line arguments such as: --sub_tests ['static_test.py'], and when parsed by RunnerCoreArgParser again, the values ended up being lists of lists. In all three cases it seems the actual user of the parsed value actually expects a single string with comma-separated substrings in it so just drop the nargs= uses.

Quoted 4 lines
---
  tools/runner.py | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)

Patches 5,8-12 applied, thanks.

Regards,
-Denis

#10 lore raw

PATCH 6/15 test-runner: Support iwd-rtnl as a --verbose value

In reply to Andrew Zaborowski
---
 tools/utils.py | 3 +++
 1 file changed, 3 insertions(+)
tools/utils.py +3 -0
index d16f221f..3cee9a22 100644
@@ -405,6 +405,9 @@ class Namespace:
 		if Process.is_verbose('iwd-acd'):
 			env['IWD_ACD_DEBUG'] = '1'
 
+		if Process.is_verbose('iwd-rtnl'):
+			env['IWD_RTNL_DEBUG'] = '1'
+
 		return self.start_process(args, env=env)
 
 	@staticmethod
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH 06/15] test-runner: Support iwd-rtnl as a --verbose value

Hi Andrew,

Quoted 4 lines · Andrew Zaborowski
---
  tools/utils.py | 3 +++
  1 file changed, 3 insertions(+)

Patch 6-7 applied, thanks.

Regards,
-Denis

#12 lore raw

PATCH 7/15 autotests: Drop unused file+directory

In reply to Andrew Zaborowski
---
 autotests/testNetconfig/storage/ssidTKIP.psk | 3 ---
 1 file changed, 3 deletions(-)
 delete mode 100644 autotests/testNetconfig/storage/ssidTKIP.psk
autotests/testNetconfig/storage/ssidTKIP.psk deleted +0 -3
deleted file mode 100644
index f15724a3..00000000
@@ -1,3 +0,0 @@
-[IPv4]
-Address=192.168.1.10
-Gateway=192.168.1.1
Signature · 1 line
2.34.1
#13 lore raw

PATCH 8/15 autotests: Validate netmasks in testNetconfig, add utility

In reply to Andrew Zaborowski

Extend test_ip_address_match to support IPv6 and to test the netmask/prefix length while it reads the local address since those are retrieved using the same API.

Modify testNetconfig to validate the prefix lengths, change the prefix lengths to be less common values (not 24 bits for IPv4 or 64 for IPv6), minor cleanup.

---
 autotests/testNetconfig/connection_test.py | 12 ++--
 autotests/testNetconfig/dhcpd-v6.conf      |  2 +-
 autotests/testNetconfig/dhcpd.conf         |  8 +--
 autotests/testNetconfig/ssidTKIP.psk       |  1 +
 autotests/testNetconfig/static_test.py     |  6 +-
 autotests/util/testutil.py                 | 75 ++++++++++++++++++----
 6 files changed, 79 insertions(+), 25 deletions(-)
autotests/testNetconfig/connection_test.py +7 -5
index 672efb72..0334267b 100644
@@ -11,7 +11,7 @@ from iwd import NetworkType
 from hostapd import HostapdCLI
 import testutil
 from config import ctx
-import os, time
+import os
 import subprocess
 
 class Test(unittest.TestCase):
@@ -19,8 +19,9 @@ class Test(unittest.TestCase):
     def test_connection_success(self):
         def check_addr(device):
             try:
-                subprocess.check_output('ip addr show ' + device.name + \
-                            ' | grep \'inet6 3ffe:501:ffff:100::\'', shell=True)
+                # DHCPv6 addresses always have a prefix length of 128 bits, the actual
+                # subnet's prefix length is in the route.
+                testutil.test_ip_address_match(device.name, '3ffe:501:ffff:100::1', 128, 112)
             except:
                 return False
 
@@ -49,6 +50,7 @@ class Test(unittest.TestCase):
         testutil.test_iface_operstate()
         testutil.test_ifaces_connected()
 
+        testutil.test_ip_address_match(device.name, '192.168.1.10', 17, 24)
         ctx.non_block_wait(check_addr, 10, device,
                             exception=Exception("IPv6 address was not set"))
 
@@ -78,14 +80,14 @@ class Test(unittest.TestCase):
         # TODO: This could be moved into test-runner itself if other tests ever
         #       require this functionality (p2p, FILS, etc.). Since its simple
         #       enough it can stay here for now.
-        ctx.start_process(['ip', 'addr','add', '192.168.1.1/255.255.255.0',
+        ctx.start_process(['ip', 'addr','add', '192.168.1.1/255.255.128.0',
                             'dev', hapd.ifname,]).wait()
         ctx.start_process(['touch', '/tmp/dhcpd.leases']).wait()
         cls.dhcpd_pid = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf',
                                             '-lf', '/tmp/dhcpd.leases',
                                             hapd.ifname], cleanup=remove_lease4)
 
-        ctx.start_process(['ip', 'addr', 'add', '3ffe:501:ffff:100::1/64',
+        ctx.start_process(['ip', 'addr', 'add', '3ffe:501:ffff:100::1/72',
                             'dev', hapd.ifname]).wait()
         ctx.start_process(['touch', '/tmp/dhcpd6.leases']).wait()
         cls.dhcpd6_pid = ctx.start_process(['dhcpd', '-6', '-f', '-cf', '/tmp/dhcpd-v6.conf',
autotests/testNetconfig/dhcpd-v6.conf +1 -1
index 7a22cc65..917ee8a3 100644
@@ -1,4 +1,4 @@
-subnet6 3ffe:501:ffff:100::/64
+subnet6 3ffe:501:ffff:100::/72
  {
   option dhcp6.name-servers 3ffe:501:ffff:100::1;
   range6 3ffe:501:ffff:100::10 3ffe:501:ffff:100::20;
autotests/testNetconfig/dhcpd.conf +4 -4
index 0c4fe9b9..ea9957a3 100644
@@ -1,14 +1,14 @@
 default-lease-time 600;         # 10 minutes
 max-lease-time 7200;            # 2  hours
 
-option broadcast-address 192.168.1.255;
+option broadcast-address 192.168.127.255;
 option routers 192.168.1.254;
-option subnet-mask 255.255.255.0;
+option subnet-mask 255.255.128.0;
 
-subnet 192.168.1.0 netmask 255.255.255.0
+subnet 192.168.0.0 netmask 255.255.128.0
  {
   option routers 192.168.1.1;
-  option subnet-mask 255.255.255.0;
+  option subnet-mask 255.255.128.0;
   option domain-name-servers 192.168.1.1;
   range 192.168.1.10 192.168.1.20;
   range 192.168.1.100 192.168.1.200;
autotests/testNetconfig/ssidTKIP.psk +1 -0
index 64e84f12..eea59cda 100644
@@ -1,5 +1,6 @@
 [IPv4]
 Address=192.168.1.10
+Netmask=255.255.255.128
 Gateway=192.168.1.1
 
 [Settings]
autotests/testNetconfig/static_test.py +3 -3
index bba2c644..e82dbaeb 100644
@@ -45,7 +45,7 @@ class Test(unittest.TestCase):
         testutil.test_iface_operstate()
         testutil.test_ifaces_connected()
 
-        testutil.test_ip_address_match(dev1.name, '192.168.1.10')
+        testutil.test_ip_address_match(dev1.name, '192.168.1.10', 25)
 
         ordered_network = dev2.get_ordered_network('ssidTKIP')
 
@@ -79,9 +79,9 @@ class Test(unittest.TestCase):
 
         hapd = HostapdCLI()
         # TODO: This could be moved into test-runner itself if other tests ever
-        #       require this functionality (p2p, FILS, etc.). Since its simple
+        #       require this functionality (p2p, FILS, etc.). Since it's simple
         #       enough it can stay here for now.
-        ctx.start_process(['ip', 'addr','add', '192.168.1.1/255.255.255.0',
+        ctx.start_process(['ip', 'addr','add', '192.168.1.1/255.255.128.0',
                             'dev', hapd.ifname]).wait()
         ctx.start_process(['touch', '/tmp/dhcpd.leases']).wait()
         cls.dhcpd_pid = ctx.start_process(['dhcpd', '-f', '-cf', '/tmp/dhcpd.conf',
autotests/util/testutil.py +63 -12

94 lines not on this page · raw message

Signature · 1 line
2.34.1
#14 lore raw

PATCH 9/15 autotests: Ensure storage_dir exists, clean up

In reply to Andrew Zaborowski

In iwd.py make sure all the static methods that touch IWD storage take the storage_dir parameter instead of hardcoding IWD_STORAGE_DIR, and make sure that parameter is actually used.

Create the directory if it doesn't exist before copying files into it. This fixes a problem in testNetconfig where

IWD.copy_to_storage('ssidTKIP.psk', '/tmp/storage')

would result in /tmp/storage being created as a file, rather than a directory containing a file, and resulting in IWD failing to start with:

Failed to create /tmp/storage

runner.py creates /tmp/iwd but that doesn't account for IWD sessions with a custom storage dir path.

---
 autotests/testNetconfig/static_test.py |  2 +-
 autotests/util/iwd.py                  | 39 ++++++++++++++++----------
 2 files changed, 25 insertions(+), 16 deletions(-)
autotests/testNetconfig/static_test.py +1 -1
index e82dbaeb..8d5710c1 100644
@@ -91,7 +91,7 @@ class Test(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        IWD.clear_storage()
+        IWD.clear_storage(storage_dir='/tmp/storage')
         cls.dhcpd_pid.kill()
 
 if __name__ == '__main__':
autotests/util/iwd.py +24 -15
index 6cee1e07..f609e37e 100755
@@ -1086,7 +1086,7 @@ class IWD(AsyncOpAbstract):
     psk_agent = None
 
     def __init__(self, start_iwd_daemon = False, iwd_config_dir = '/tmp',
-                            iwd_storage_dir = '/tmp/iwd', namespace=ctx):
+                            iwd_storage_dir = IWD_STORAGE_DIR, namespace=ctx):
         self.namespace = namespace
         self._bus = namespace.get_bus()
 
@@ -1197,40 +1197,49 @@ class IWD(AsyncOpAbstract):
         os.system('rm -rf ' + storage_dir + '/ap/*')
 
     @staticmethod
-    def create_in_storage(file_name, file_content):
-        fo = open(IWD_STORAGE_DIR + '/' + file_name, 'w')
+    def create_in_storage(file_name, file_content, storage_dir=IWD_STORAGE_DIR):
+        fo = open(storage_dir + '/' + file_name, 'w')
 
         fo.write(file_content)
         fo.close()
 
+    @staticmethod
+    def _ensure_storage_dir_exists(storage_dir):
+        if not os.path.exists(storage_dir):
+            os.mkdir(storage_dir)
+
     @staticmethod
     def copy_to_storage(source, storage_dir=IWD_STORAGE_DIR, name=None):
         import shutil
 
         assert not os.path.isabs(source)
 
+        target = storage_dir
         if name:
-            storage_dir += '/%s' % name
+            target += '/%s' % name
 
-        shutil.copy(source, storage_dir)
+        IWD._ensure_storage_dir_exists(storage_dir)
+        shutil.copy(source, target)
 
     @staticmethod
-    def copy_to_hotspot(source):
-        if not os.path.exists(IWD_STORAGE_DIR + "/hotspot"):
-            os.mkdir(IWD_STORAGE_DIR + "/hotspot")
+    def copy_to_hotspot(source, storage_dir=IWD_STORAGE_DIR):
+        IWD._ensure_storage_dir_exists(storage_dir)
+
+        if not os.path.exists(storage_dir + "/hotspot"):
+            os.mkdir(storage_dir + "/hotspot")
 
-        IWD.copy_to_storage(source, IWD_STORAGE_DIR + "/hotspot")
+        IWD.copy_to_storage(source, storage_dir + "/hotspot")
 
     @staticmethod
-    def copy_to_ap(source):
-        if not os.path.exists(IWD_STORAGE_DIR + "/ap"):
-            os.mkdir(IWD_STORAGE_DIR + "/ap")
+    def copy_to_ap(source, storage_dir=IWD_STORAGE_DIR):
+        if not os.path.exists(storage_dir + "/ap"):
+            os.mkdir(storage_dir + "/ap")
 
-        IWD.copy_to_storage(source, IWD_STORAGE_DIR + '/ap/')
+        IWD.copy_to_storage(source, storage_dir + '/ap/')
 
     @staticmethod
-    def remove_from_storage(file_name):
-        os.system('rm -rf ' + IWD_STORAGE_DIR + '/\'' + file_name + '\'')
+    def remove_from_storage(file_name, storage_dir=IWD_STORAGE_DIR):
+        os.system('rm -rf ' + storage_dir + '/\'' + file_name + '\'')
 
     def list_devices(self, wait_to_appear = 0, max_wait = 50, p2p = False):
         if not wait_to_appear:
Signature · 1 line
2.34.1
#15 lore raw

PATCH 10/15 autotests: In testNetconfig add static IPv6, add comments

In reply to Andrew Zaborowski

In static_test.py add IPv6. Add comments on what we're actually testing since it wasn't very clear. After the expected ACD conflict detection, succeed if either the lost address was removed or the client disconnected from the AP since this seems like a correct action for netconfig to implement.

---
 autotests/testNetconfig/ssidTKIP.psk   |  7 +++++++
 autotests/testNetconfig/static_test.py | 11 ++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
autotests/testNetconfig/ssidTKIP.psk +7 -0
index eea59cda..72a71ce9 100644
@@ -1,7 +1,14 @@
 [IPv4]
+# Use a different netmask than DHCP on purpose, but use the same address
+# as DHCP would assign us to produce a conflict and test ACD
 Address=192.168.1.10
 Netmask=255.255.255.128
 Gateway=192.168.1.1
 
+[IPv6]
+# Use a different subnet than DHCP on purpose
+Address=3ffe:501:ffff:200::10/80
+Gateway=3ffe:501:ffff:200::1
+
 [Settings]
 AutoConnect=false
autotests/testNetconfig/static_test.py +10 -1
index 8d5710c1..a3b294a2 100644
@@ -16,6 +16,7 @@ import os
 class Test(unittest.TestCase):
 
     def test_connection_success(self):
+        # Use a non-default storage_dir for one of the instances, the default for the other one
         wd = IWD(True, iwd_storage_dir='/tmp/storage')
 
         ns0 = ctx.get_namespace('ns0')
@@ -46,19 +47,27 @@ class Test(unittest.TestCase):
         testutil.test_ifaces_connected()
 
         testutil.test_ip_address_match(dev1.name, '192.168.1.10', 25)
+        testutil.test_ip_address_match(dev1.name, '3ffe:501:ffff:200::10', 80)
 
         ordered_network = dev2.get_ordered_network('ssidTKIP')
 
         condition = 'not obj.connected'
         wd_ns0.wait_for_object_condition(ordered_network.network_object, condition)
 
+        # Connect to the same network from a dynamically configured client.  The
+        # DHCP server doesn't know (even though dev1 announced itself) that
+        # 192.168.1.10 is already in use and if it assigns dev2 the lowest
+        # available address, that's going to be 192.168.1.10.  dev1's ACD
+        # implementation should then stop using this address.
         ordered_network.network_object.connect()
 
         condition = 'obj.state == DeviceState.connected'
         wd_ns0.wait_for_object_condition(dev2, condition)
 
         wd.wait(1)
-        testutil.test_ip_address_match(dev1.name, None)
+        # Check dev1 is now disconnected or without its IPv4 address
+        if dev1.state == iwd.DeviceState.connected:
+            testutil.test_ip_address_match(dev1.name, None)
 
         dev1.disconnect()
         dev2.disconnect()
Signature · 1 line
2.34.1
#16 lore raw

PATCH 11/15 autotests: In testNetconfig verify routes created

In reply to Andrew Zaborowski

Check that the right set of routes is being added for IPv4 and IPv6. Chane gateway addresses to differ from the AP or dhcpd addresses.

---
 autotests/testNetconfig/connection_test.py | 39 +++++++++++++--
 autotests/testNetconfig/ssidTKIP.psk       |  4 +-
 autotests/testNetconfig/static_test.py     | 23 +++++++++
 autotests/util/testutil.py                 | 57 ++++++++++++++++++++++
 4 files changed, 118 insertions(+), 5 deletions(-)
autotests/testNetconfig/connection_test.py +36 -3
index 0334267b..db3327ef 100644
@@ -12,7 +12,7 @@ from hostapd import HostapdCLI
 import testutil
 from config import ctx
 import os
-import subprocess
+import socket
 
 class Test(unittest.TestCase):
 
@@ -54,6 +54,29 @@ class Test(unittest.TestCase):
         ctx.non_block_wait(check_addr, 10, device,
                             exception=Exception("IPv6 address was not set"))
 
+        ifname = str(device.name)
+        router_ll_addr = [addr for addr, _, _ in testutil.get_addrs6(self.hapd.ifname) if addr[0:2] == b'\xfe\x80'][0]
+        # Since we're in an isolated VM with freshly created interfaces we know any routes
+        # will have been created by IWD and don't have to allow for pre-existing routes
+        # in the table.
+        # Flags: 1=RTF_UP, 2=RTF_GATEWAY
+        expected_routes4 = {
+                testutil.RouteInfo(gw=socket.inet_pton(socket.AF_INET, '192.168.1.1'),
+                    flags=3, ifname=ifname),
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET, '192.168.0.0'), plen=17,
+                    flags=1, ifname=ifname)
+            }
+        expected_routes6 = {
+                # Default router
+                testutil.RouteInfo(gw=router_ll_addr, flags=3, ifname=ifname),
+                # On-link prefix
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:100::'), plen=72,
+                    flags=1, ifname=ifname),
+            }
+        self.maxDiff = None
+        self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname)))
+        self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname)))
+
         device.disconnect()
 
         condition = 'not obj.connected'
@@ -77,6 +100,7 @@ class Test(unittest.TestCase):
                 pass
 
         hapd = HostapdCLI()
+        cls.hapd = hapd
         # TODO: This could be moved into test-runner itself if other tests ever
         #       require this functionality (p2p, FILS, etc.). Since its simple
         #       enough it can stay here for now.
@@ -94,9 +118,18 @@ class Test(unittest.TestCase):
                                             '-lf', '/tmp/dhcpd6.leases',
                                             hapd.ifname], cleanup=remove_lease6)
         ctx.start_process(['sysctl', 'net.ipv6.conf.' + hapd.ifname + '.forwarding=1']).wait()
-        # Tell clients to use DHCPv6
+        # Send out Router Advertisements telling clients to use DHCPv6.
+        # Note trying to send the RAs from the router's global IPv6 address by adding a
+        # "AdvRASrcAddress { 3ffe:501:ffff:100::1; };" line will fail because the client
+        # and the router interfaces are in the same namespace and Linux won't allow routes
+        # with a non-link-local gateway address that is present on another interface in the
+        # same namespace.
         config = open('/tmp/radvd.conf', 'w')
-        config.write('interface ' + hapd.ifname + ' { AdvSendAdvert on; AdvManagedFlag on; };')
+        config.write('interface ' + hapd.ifname + ''' {
+            AdvSendAdvert on;
+            AdvManagedFlag on;
+            prefix 3ffe:501:ffff:100::/72 { AdvAutonomous off; };
+            };''')
         config.close()
         cls.radvd_pid = ctx.start_process(['radvd', '-n', '-d5', '-p', '/tmp/radvd.pid', '-C', '/tmp/radvd.conf'])
 
autotests/testNetconfig/ssidTKIP.psk +2 -2
index 72a71ce9..e371c97f 100644
@@ -3,12 +3,12 @@
 # as DHCP would assign us to produce a conflict and test ACD
 Address=192.168.1.10
 Netmask=255.255.255.128
-Gateway=192.168.1.1
+Gateway=192.168.1.3
 
 [IPv6]
 # Use a different subnet than DHCP on purpose
 Address=3ffe:501:ffff:200::10/80
-Gateway=3ffe:501:ffff:200::1
+Gateway=3ffe:501:ffff:200::3
 
 [Settings]
 AutoConnect=false
autotests/testNetconfig/static_test.py +23 -0
index a3b294a2..cd147894 100644
@@ -12,6 +12,7 @@ from hostapd import HostapdCLI
 import testutil
 from config import ctx
 import os
+import socket
 
 class Test(unittest.TestCase):
 
@@ -49,6 +50,28 @@ class Test(unittest.TestCase):
         testutil.test_ip_address_match(dev1.name, '192.168.1.10', 25)
         testutil.test_ip_address_match(dev1.name, '3ffe:501:ffff:200::10', 80)
 
+        ifname = str(dev1.name)
+        # Since we're in an isolated VM with freshly created interfaces we know any routes
+        # will have been created by IWD and don't have to allow for pre-existing routes
+        # in the table.
+        # Flags: 1=RTF_UP, 2=RTF_GATEWAY
+        expected_routes4 = {
+                testutil.RouteInfo(gw=socket.inet_pton(socket.AF_INET, '192.168.1.3'),
+                    flags=3, ifname=ifname),
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET, '192.168.1.0'), plen=25,
+                    flags=1, ifname=ifname)
+            }
+        expected_routes6 = {
+                testutil.RouteInfo(gw=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:200::3'),
+                    flags=3, ifname=ifname),
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:200::'), plen=80,
+                    flags=1, ifname=ifname),
+            }
+
+        self.maxDiff = None
+        self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname)))
+        self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname)))
+
         ordered_network = dev2.get_ordered_network('ssidTKIP')
 
         condition = 'not obj.connected'
autotests/util/testutil.py +57 -0

66 lines not on this page · raw message

Signature · 1 line
2.34.1
#17 lore raw

PATCH 12/15 autotests: Verify DNS entries added from DHCP/static

In reply to Andrew Zaborowski

Add a fake resolvconf executable to verify that the right nameserver addresses were actually committed by iwd. Again use unique nameserver addresses to reduce the possibility that the test succeeds by pure luck.

---
 autotests/testNetconfig/connection_test.py | 15 ++++++++++++++-
 autotests/testNetconfig/dhcpd-v6.conf      |  2 +-
 autotests/testNetconfig/dhcpd.conf         |  2 +-
 autotests/testNetconfig/main.conf          |  2 +-
 autotests/testNetconfig/resolvconf         |  2 ++
 autotests/testNetconfig/ssidTKIP.psk       |  2 ++
 autotests/testNetconfig/static_test.py     | 15 ++++++++++++++-
 7 files changed, 35 insertions(+), 5 deletions(-)
 create mode 100755 autotests/testNetconfig/resolvconf
autotests/testNetconfig/connection_test.py +14 -1
index db3327ef..4b05c745 100644
@@ -77,6 +77,14 @@ class Test(unittest.TestCase):
         self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname)))
         self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname)))
 
+        rclog = open('/tmp/resolvconf.log', 'r')
+        entries = rclog.readlines()
+        rclog.close()
+        expected_rclog = ['-a wlan1.dns\n', 'nameserver 192.168.1.2\n', 'nameserver 3ffe:501:ffff:100::2\n']
+        # Every real resolvconf -a run overwrites the previous settings.  Check the last three lines
+        # of our log since we care about the end result here.
+        self.assertEqual(expected_rclog, entries[-3:])
+
         device.disconnect()
 
         condition = 'not obj.connected'
@@ -133,6 +141,10 @@ class Test(unittest.TestCase):
         config.close()
         cls.radvd_pid = ctx.start_process(['radvd', '-n', '-d5', '-p', '/tmp/radvd.pid', '-C', '/tmp/radvd.conf'])
 
+        cls.orig_path = os.environ['PATH']
+        os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH']
+        IWD.copy_to_storage('resolvconf', '/tmp/test-bin')
+
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
@@ -142,7 +154,8 @@ class Test(unittest.TestCase):
         cls.dhcpd6_pid = None
         ctx.stop_process(cls.radvd_pid)
         cls.radvd_pid = None
-        os.remove('/tmp/radvd.conf')
+        os.system('rm -rf /tmp/radvd.conf /tmp/resolvconf.log /tmp/test-bin')
+        os.environ['PATH'] = cls.orig_path
 
 if __name__ == '__main__':
     unittest.main(exit=True)
autotests/testNetconfig/dhcpd-v6.conf +1 -1
index 917ee8a3..45057ab8 100644
@@ -1,6 +1,6 @@
 subnet6 3ffe:501:ffff:100::/72
  {
-  option dhcp6.name-servers 3ffe:501:ffff:100::1;
+  option dhcp6.name-servers 3ffe:501:ffff:100::2;
   range6 3ffe:501:ffff:100::10 3ffe:501:ffff:100::20;
   range6 3ffe:501:ffff:100::100 3ffe:501:ffff:100::200;
  }
autotests/testNetconfig/dhcpd.conf +1 -1
index ea9957a3..d8a9d24c 100644
@@ -9,7 +9,7 @@ subnet 192.168.0.0 netmask 255.255.128.0
  {
   option routers 192.168.1.1;
   option subnet-mask 255.255.128.0;
-  option domain-name-servers 192.168.1.1;
+  option domain-name-servers 192.168.1.2;
   range 192.168.1.10 192.168.1.20;
   range 192.168.1.100 192.168.1.200;
  }
autotests/testNetconfig/main.conf +1 -1
index 1ffe2be1..8641a390 100644
@@ -3,4 +3,4 @@ EnableNetworkConfiguration=true
 
 [Network]
 EnableIPv6=true
-NameResolvingService=none
+NameResolvingService=resolvconf
autotests/testNetconfig/resolvconf new file +2 -0
new file mode 100755
index 00000000..7c56c616
@@ -0,0 +1,2 @@
+#! /bin/sh
+(echo "$*" ; [ "$1" = -a ] && cat) >> /tmp/resolvconf.log 2> /dev/null
autotests/testNetconfig/ssidTKIP.psk +2 -0
index e371c97f..032e2185 100644
@@ -4,11 +4,13 @@
 Address=192.168.1.10
 Netmask=255.255.255.128
 Gateway=192.168.1.3
+DNS=192.168.1.4
 
 [IPv6]
 # Use a different subnet than DHCP on purpose
 Address=3ffe:501:ffff:200::10/80
 Gateway=3ffe:501:ffff:200::3
+DNS=3ffe:501:ffff:200::4
 
 [Settings]
 AutoConnect=false
autotests/testNetconfig/static_test.py +14 -1
index cd147894..ac525b28 100644
@@ -72,6 +72,14 @@ class Test(unittest.TestCase):
         self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname)))
         self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname)))
 
+        rclog = open('/tmp/resolvconf.log', 'r')
+        entries = rclog.readlines()
+        rclog.close()
+        expected_rclog = ['-a wlan1.dns\n', 'nameserver 192.168.1.4\n', 'nameserver 3ffe:501:ffff:200::4\n']
+        # Every resolvconf -a run overwrites the previous settings.  Check the last three lines
+        # of the log since we care about the end result here.
+        self.assertEqual(expected_rclog, entries[-3:])
+
         ordered_network = dev2.get_ordered_network('ssidTKIP')
 
         condition = 'not obj.connected'
@@ -121,10 +129,15 @@ class Test(unittest.TestCase):
                                             hapd.ifname], cleanup=remove_lease)
         IWD.copy_to_storage('ssidTKIP.psk', '/tmp/storage')
 
+        cls.orig_path = os.environ['PATH']
+        os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH']
+        IWD.copy_to_storage('resolvconf', '/tmp/test-bin')
+
     @classmethod
     def tearDownClass(cls):
-        IWD.clear_storage(storage_dir='/tmp/storage')
         cls.dhcpd_pid.kill()
+        os.system('rm -rf /tmp/resolvconf.log /tmp/test-bin /tmp/storage')
+        os.environ['PATH'] = cls.orig_path
 
 if __name__ == '__main__':
     unittest.main(exit=True)
Signature · 1 line
2.34.1
#18 lore raw

RFC PATCH 13/15 netconfig: Switch to l_netconfig

In reply to Andrew Zaborowski

Posting this for early review only.

This leaves IWD's netconfig.h mostly unchanged but the implementation is switched over to use l_netconfig.

The struct netconfig declaration is nearly empty now but contains the resolver client, the data received from FILS and some state that mirrors l_netconfig state and could be replaced by using l_netconfig getters for the settings which have only setters at this time.

A minor behaviour change is that a netconfig failure, such as DHCP error or timeout, would now cause station to signal an DBus error and continue with autoconnect instead of being stuck in netconfig.

---
 Makefile.am     |    6 +-
 src/netconfig.c | 1685 +++++++++++------------------------------------
 src/netconfig.h |    1 +
 src/station.c   |  134 ++--
 4 files changed, 497 insertions(+), 1329 deletions(-)
Makefile.am +4 -2
index 80377613..bcb313d7 100644
@@ -62,7 +62,8 @@ ell_headers = ell/util.h \
 			ell/icmp6.h \
 			ell/dhcp6.h \
 			ell/acd.h \
-			ell/cleanup.h
+			ell/cleanup.h \
+			ell/netconfig.h
 
 ell_sources = ell/private.h \
 			ell/missing.h \
@@ -141,7 +142,8 @@ ell_sources = ell/private.h \
 			ell/icmp6-private.h \
 			ell/dhcp6-lease.c \
 			ell/dhcp6-transport.c \
-			ell/acd.c
+			ell/acd.c \
+			ell/netconfig.c
 
 ell_shared = ell/useful.h ell/asn1-private.h
 
src/netconfig.c +396 -1289

2,033 lines not on this page · raw message

src/netconfig.h +1 -0
index c9ac6f8f..b42e9cc8 100644
@@ -26,6 +26,7 @@ struct ie_fils_ip_addr_response_info;
 
 enum netconfig_event {
 	NETCONFIG_EVENT_CONNECTED,
+	NETCONFIG_EVENT_FAILED,
 };
 
 typedef void (*netconfig_notify_func_t)(enum netconfig_event event,
src/station.c +96 -38

159 lines not on this page · raw message

Signature · 1 line
2.34.1
#19 lore raw

PATCH 14/15 autotests: Add bad netconfig settings scenario

In reply to Andrew Zaborowski
---
 autotests/testNetconfig/connection_test.py | 30 +++++++++++++++++++++-
 autotests/testNetconfig/mismatch.psk       |  7 +++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 autotests/testNetconfig/mismatch.psk
autotests/testNetconfig/connection_test.py +29 -1
index 4b05c745..837b19ec 100644
@@ -92,6 +92,35 @@ class Test(unittest.TestCase):
 
         wd.unregister_psk_agent(psk_agent)
 
+    def test_addr_type_error(self):
+        IWD.copy_to_storage('mismatch.psk', name='ssidTKIP.psk')
+        wd = IWD(True)
+
+        psk_agent = PSKAgent("secret123")
+        wd.register_psk_agent(psk_agent)
+
+        devices = wd.list_devices(1)
+        device = devices[0]
+
+        ordered_network = device.get_ordered_network('ssidTKIP')
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        # Ideally we want to check that this errors out at an early phase, especially
+        # before any radio operations, due to netconfig setting validation, but this is
+        # tricky to ensure.  Also ideally this would happen even before asking the user
+        # for the passphrase which is easier to ensure in the tests, but currently IWD
+        # asks for the PSK before control reaches station.c.
+        self.assertRaises(iwd.InvalidArgumentsEx, ordered_network.network_object.connect)
+
+        wd.unregister_psk_agent(psk_agent)
+
+    def tearDown(self):
+        IWD.clear_storage()
+
     @classmethod
     def setUpClass(cls):
         def remove_lease4():
@@ -147,7 +176,6 @@ class Test(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        IWD.clear_storage()
         ctx.stop_process(cls.dhcpd_pid)
         cls.dhcpd_pid = None
         ctx.stop_process(cls.dhcpd6_pid)
autotests/testNetconfig/mismatch.psk new file +7 -0
new file mode 100644
index 00000000..f8920b7c
@@ -0,0 +1,7 @@
+[IPv6]
+# IPv4 addresses where IPv6 are expected
+Address=192.168.1.10
+Gateway=192.168.1.1
+
+[Settings]
+AutoConnect=false
Signature · 1 line
2.34.1
#20 lore raw

Re: [PATCH 14/15] autotests: Add bad netconfig settings scenario

Hi Andrew,

Quoted 68 lines · Andrew Zaborowski

---
 autotests/testNetconfig/connection_test.py | 30 +++++++++++++++++++++- autotests/testNetconfig/mismatch.psk       |  7 +++++

 2 files changed, 36 insertions(+), 1 deletion(-)

 create mode 100644 autotests/testNetconfig/mismatch.psk

autotests/testNetconfig/connection_test.py +0 -0
index 4b05c745..837b19ec 100644
@@ -92,6 +92,35 @@ class Test(unittest.TestCase):


         wd.unregister_psk_agent(psk_agent)

+    def test_addr_type_error(self):
+        IWD.copy_to_storage('mismatch.psk', name='ssidTKIP.psk') +        wd = IWD(True)

autotests/testNetconfig/connection_test.py +13 -0
+
+        psk_agent = PSKAgent("secret123")
+        wd.register_psk_agent(psk_agent)
+
+        devices = wd.list_devices(1)
+        device = devices[0]
+
+        ordered_network = device.get_ordered_network('ssidTKIP')
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object,

condition)
+
+        # Ideally we want to check that this errors out at an early phase, especially
+        # before any radio operations, due to netconfig setting validation, but this is
+        # tricky to ensure.  Also ideally this would happen even before asking the user
+        # for the passphrase which is easier to ensure in the tests, but currently IWD
+        # asks for the PSK before control reaches station.c. +        self.assertRaises(iwd.InvalidArgumentsEx, ordered_network.network_object.connect)

autotests/testNetconfig/connection_test.py +6 -0
+
+        wd.unregister_psk_agent(psk_agent)
+
+    def tearDown(self):
+        IWD.clear_storage()
+

     @classmethod
     def setUpClass(cls):
         def remove_lease4():

autotests/testNetconfig/connection_test.py +0 -0
@@ -147,7 +176,6 @@ class Test(unittest.TestCase):


     @classmethod
     def tearDownClass(cls):
-        IWD.clear_storage()
         ctx.stop_process(cls.dhcpd_pid)
         cls.dhcpd_pid = None
         ctx.stop_process(cls.dhcpd6_pid)

autotests/testNetconfig/mismatch.psk new file +0 -0
new file mode 100644
index 00000000..f8920b7c

autotests/testNetconfig/mismatch.psk line 7

Quoted 7 lines
autotests/testNetconfig/mismatch.psk new file +7 -0
@@ -0,0 +1,7 @@
+[IPv6]
+# IPv4 addresses where IPv6 are expected
+Address=192.168.1.10
+Gateway=192.168.1.1
+
+[Settings]
+AutoConnect=false

Does this happen to depend on patch 13/15? I applied all the other autotest changes but this one fails to pass testNetconfig. The assertRaises() call is what fails for me.

Thanks,
James

#21 lore raw

Re: [PATCH 14/15] autotests: Add bad netconfig settings scenario

Quoted 3 lines · James Prestwood

Does this happen to depend on patch 13/15? I applied all the other autotest changes but this one fails to pass testNetconfig. The assertRaises() call is what fails for me.

It does, sorry I didn't make this clear. Both 14 and 15 depend on 13/15.

Best regards

#22 lore raw

Re: [PATCH 14/15] autotests: Add bad netconfig settings scenario

Hi Andrew,

Quoted 7 lines · Andrew Zaborowski
Quoted 3 lines · James Prestwood

Does this happen to depend on patch 13/15? I applied all the other autotest changes but this one fails to pass testNetconfig. The assertRaises() call is what fails for me.

It does, sorry I didn't make this clear. Both 14 and 15 depend on 13/15.

Can this test be made applicable to the current netconfig implementation? In other words, does it really need to depend on patch 13? Same with 15?

Regards,
-Denis

#23 lore raw

Re: [PATCH 14/15] autotests: Add bad netconfig settings scenario

Hi Denis,

Quoted 11 lines · Denis Kenzior
Quoted 7 lines · Andrew Zaborowski
Quoted 3 lines · James Prestwood

Does this happen to depend on patch 13/15? I applied all the other autotest changes but this one fails to pass testNetconfig. The assertRaises() call is what fails for me.

It does, sorry I didn't make this clear. Both 14 and 15 depend on 13/15.

Can this test be made applicable to the current netconfig implementation? In other words, does it really need to depend on patch 13? Same with 15?

Since this tests things that are fixed by switching to l_netconfig, the test doesn't need any changes but src/netconfig.c does (that's what patch 13 does), but it's safe to hold on with this.

Best regards

#24 lore raw

Re: [PATCH 14/15] autotests: Add bad netconfig settings scenario

Hi Andrew,

Quoted 2 lines

Since this tests things that are fixed by switching to l_netconfig, the test doesn't need any changes but src/netconfig.c does (that's

Shouldn't we fix the current netconfig implementation? And then apply this test?

Quoted 1 line

what patch 13 does), but it's safe to hold on with this.

It might take us a bit of time until the switch to l_netconfig happens. So fixing these small issues might be a good idea in the interim.

Regards,
-Denis

#25 lore raw

PATCH 15/15 autotests: In testNetconfig verify routes from RIOs

In reply to Andrew Zaborowski

Verify that IWD with NetworkConfigurationEnabled creates the off-link routes for Route Information Options in the Router Advertisements. Sending this last because these options are not supported by current netconfig code and the test should fail without the l_netconfig patch.

---
 autotests/testNetconfig/connection_test.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
autotests/testNetconfig/connection_test.py +12 -0
index 837b19ec..9c1d2efa 100644
@@ -72,6 +72,15 @@ class Test(unittest.TestCase):
                 # On-link prefix
                 testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:100::'), plen=72,
                     flags=1, ifname=ifname),
+                # Router for an off-link prefix, medium preference
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:300::'), plen=64,
+                    gw=router_ll_addr, flags=3, ifname=ifname),
+                # Router for an off-link prefix, high preference
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:400::'), plen=65,
+                    gw=router_ll_addr, flags=3, ifname=ifname),
+                # Router for an off-link prefix, low preference
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:500::'), plen=66,
+                    gw=router_ll_addr, flags=3, ifname=ifname)
             }
         self.maxDiff = None
         self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname)))
@@ -166,6 +175,9 @@ class Test(unittest.TestCase):
             AdvSendAdvert on;
             AdvManagedFlag on;
             prefix 3ffe:501:ffff:100::/72 { AdvAutonomous off; };
+            route 3ffe:501:ffff:300::/64 {};
+            route 3ffe:501:ffff:400::/65 { AdvRoutePreference low; };
+            route 3ffe:501:ffff:500::/66 { AdvRoutePreference high; };
             };''')
         config.close()
         cls.radvd_pid = ctx.start_process(['radvd', '-n', '-d5', '-p', '/tmp/radvd.pid', '-C', '/tmp/radvd.conf'])
Signature · 1 line
2.34.1
#26 lore raw

Re: [PATCH 15/15] autotests: In testNetconfig verify routes from RIOs

Hi Andrew,

Quoted 4 lines · Andrew Zaborowski

Verify that IWD with NetworkConfigurationEnabled creates the off-link routes for Route Information Options in the Router Advertisements. Sending this last because these options are not supported by current netconfig code and the test should fail without the l_netconfig patch.

So is this true? Didn't ell commit:
9c5cbf5484b2 ("icmp6: Parse extra options") add off-link route setting directly to l_icmp6? Shouldn't this work with the current (upstream) netconfig implementation?

Regards,
-Denis

#27 lore raw

Re: [PATCH 15/15] autotests: In testNetconfig verify routes from RIOs

Hi Denis,

Quoted 10 lines · Denis Kenzior
Quoted 4 lines · Andrew Zaborowski

Verify that IWD with NetworkConfigurationEnabled creates the off-link routes for Route Information Options in the Router Advertisements. Sending this last because these options are not supported by current netconfig code and the test should fail without the l_netconfig patch.

So is this true? Didn't ell commit:
9c5cbf5484b2 ("icmp6: Parse extra options") add off-link route setting directly to l_icmp6? Shouldn't this work with the current (upstream) netconfig implementation?

True, looking at the code this should work together with the l_icmp6_client_set_rtnl().

Best regards

#28 lore raw

Re: [PATCH 15/15] autotests: In testNetconfig verify routes from RIOs

In reply to Andrew Zaborowski

Hi Andrew,

Quoted 8 lines · Andrew Zaborowski

Verify that IWD with NetworkConfigurationEnabled creates the off-link routes for Route Information Options in the Router Advertisements. Sending this last because these options are not supported by current netconfig code and the test should fail without the l_netconfig patch.

---
  autotests/testNetconfig/connection_test.py | 12 ++++++++++++
  1 file changed, 12 insertions(+)

I went ahead and applied this patch with a slight amendment of the commit description.

Regards,
-Denis

#29 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 7 lines · Andrew Zaborowski

Drop the wrong negation in the error check. Check that there are no extra characters after prefix length suffix. Reset errno 0 before the strtoul call, as recommended by the manpage.

---
  src/netconfig.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

Applied, thanks.

Regards,
-Denis