public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times
@ 2024-01-30 17:50 James Prestwood
  2024-01-30 17:50 ` [PATCH v2 2/2] auto-t: add netconfig timeout test James Prestwood
  2024-01-30 20:00 ` [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: James Prestwood @ 2024-01-30 17:50 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

ELL now has a setting to limit the number of DHCP attempts. This
will now be set in IWD and if reached will result in a failure
event, and in turn a disconnect.

IWD will set a maximum of 4 retries which should keep the maximum
DHCP time to ~60 seconds roughly.
---
 src/netconfig.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/netconfig.c b/src/netconfig.c
index 52307025..b31209cf 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -50,6 +50,8 @@
 #include "src/netconfig.h"
 #include "src/sysfs.h"
 
+#define DHCP_ATTEMPTS 4
+
 /*
  * Routing priority offset, configurable in main.conf. The route with lower
  * priority offset is preferred.
@@ -696,6 +698,7 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 	int dhcp_priority = L_LOG_INFO;
 	struct l_dhcp6_client *dhcp6;
 	struct l_icmp6_client *icmp6;
+	struct l_dhcp_client *dhcp;
 
 	l_debug("Creating netconfig for interface: %d", ifindex);
 
@@ -723,8 +726,8 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 	l_netconfig_set_event_handler(netconfig->nc, netconfig_event_handler,
 					netconfig, NULL);
 
-	l_dhcp_client_set_debug(l_netconfig_get_dhcp_client(netconfig->nc),
-				do_debug, "[DHCPv4] ", NULL, dhcp_priority);
+	dhcp = l_netconfig_get_dhcp_client(netconfig->nc);
+	l_dhcp_client_set_max_attempts(dhcp, DHCP_ATTEMPTS);
 
 	dhcp6 = l_netconfig_get_dhcp6_client(netconfig->nc);
 	l_dhcp6_client_set_lla_randomized(dhcp6, true);
@@ -735,6 +738,8 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 	if (debug_level) {
 		l_dhcp6_client_set_debug(dhcp6, do_debug, "[DHCPv6] ", NULL);
 		l_icmp6_client_set_debug(icmp6, do_debug, "[ICMPv6] ", NULL);
+		l_dhcp_client_set_debug(dhcp, do_debug, "[DHCPv4] ", NULL,
+					dhcp_priority);
 	}
 
 	return netconfig;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] auto-t: add netconfig timeout test
  2024-01-30 17:50 [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times James Prestwood
@ 2024-01-30 17:50 ` James Prestwood
  2024-01-30 20:00 ` [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: James Prestwood @ 2024-01-30 17:50 UTC (permalink / raw)
  To: iwd; +Cc: James Prestwood

Tests that netconfig eventually times out and that IWD disconnects
---
 autotests/testNetconfig/autoconnect.psk |  2 +
 autotests/testNetconfig/timeout_test.py | 65 +++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 autotests/testNetconfig/autoconnect.psk
 create mode 100644 autotests/testNetconfig/timeout_test.py

diff --git a/autotests/testNetconfig/autoconnect.psk b/autotests/testNetconfig/autoconnect.psk
new file mode 100644
index 00000000..c28936bf
--- /dev/null
+++ b/autotests/testNetconfig/autoconnect.psk
@@ -0,0 +1,2 @@
+[IPv4]
+SendHostname=true
diff --git a/autotests/testNetconfig/timeout_test.py b/autotests/testNetconfig/timeout_test.py
new file mode 100644
index 00000000..a15706e3
--- /dev/null
+++ b/autotests/testNetconfig/timeout_test.py
@@ -0,0 +1,65 @@
+import unittest
+import sys
+import os
+
+sys.path.append('../util')
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+
+class Test(unittest.TestCase):
+
+    def test_netconfig_timeout(self):
+        IWD.copy_to_storage('autoconnect.psk', name='ap-ns1.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('ap-ns1')
+
+        self.assertEqual(ordered_network.type, NetworkType.psk)
+
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connecting'
+        wd.wait_for_object_condition(device, condition)
+
+        device.wait_for_event("connecting (netconfig)")
+
+        # Netconfig should fail, and IWD should disconnect
+        from_condition = 'obj.state == DeviceState.connecting'
+        to_condition = 'obj.state == DeviceState.disconnecting'
+        wd.wait_for_object_change(device, from_condition, to_condition, max_wait=60)
+
+        # Autoconnect should then try again
+        condition = 'obj.state == DeviceState.connecting'
+        wd.wait_for_object_condition(device, condition)
+
+        device.wait_for_event("connecting (netconfig)")
+
+        device.disconnect()
+        condition = 'obj.state == DeviceState.disconnected'
+        wd.wait_for_object_condition(device, condition)
+
+    @classmethod
+    def setUpClass(cls):
+        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()
+        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)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times
  2024-01-30 17:50 [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times James Prestwood
  2024-01-30 17:50 ` [PATCH v2 2/2] auto-t: add netconfig timeout test James Prestwood
@ 2024-01-30 20:00 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2024-01-30 20:00 UTC (permalink / raw)
  To: James Prestwood, iwd

Hi James,

On 1/30/24 11:50, James Prestwood wrote:
> ELL now has a setting to limit the number of DHCP attempts. This
> will now be set in IWD and if reached will result in a failure
> event, and in turn a disconnect.
> 
> IWD will set a maximum of 4 retries which should keep the maximum
> DHCP time to ~60 seconds roughly.
> ---
>   src/netconfig.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 

All applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-30 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-30 17:50 [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times James Prestwood
2024-01-30 17:50 ` [PATCH v2 2/2] auto-t: add netconfig timeout test James Prestwood
2024-01-30 20:00 ` [PATCH v2 1/2] netconfig: limit DHCPv4 attempts to avoid extended netconfig times Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox