Skip to contentSkip to conversation

netconfig: Drop D-Bus path from debug message

PATCH In review Andrew Zaborowski 2 participants 4 messages Sep 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 netconfig: Drop D-Bus path from debug message

l_dbus_message_get_path(reply) is normally NULL in this callback so don't bother printing it.

---
 src/netconfig-commit.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
src/netconfig-commit.c +1 -2
index 9894ace2..96436c1c 100644
@@ -373,8 +373,7 @@ static void netconfig_agent_receive_reply(struct l_dbus_message *reply,
 	const char *error, *text;
 	bool success = true;
 
-	l_debug("agent reply from %s %s", l_dbus_message_get_sender(reply),
-		l_dbus_message_get_path(reply));
+	l_debug("agent reply from %s", l_dbus_message_get_sender(reply));
 
 	data->pending_id[INDEX_FOR_AF(cd->family)] = 0;
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 netconfig: Update l_netconfig API calls

Since l_netconfig's DHCPv6 client instance no longer sets parameters on the l_icmp6_client instance, call l_icmp6_client_set_nodelay() and l_icmp6_client_set_debug() directly. Also enable optimistic DAD to speed up IPv6 setup if available.

---
 src/netconfig.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
src/netconfig.c +8 -2
index feb7f87a..c7cc6b1b 100644
@@ -659,6 +659,7 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 	const char *debug_level = NULL;
 	int dhcp_priority = L_LOG_INFO;
 	struct l_dhcp6_client *dhcp6;
+	struct l_icmp6_client *icmp6;
 
 	l_debug("Creating netconfig for interface: %d", ifindex);
 
@@ -691,12 +692,17 @@ struct netconfig *netconfig_new(uint32_t ifindex)
 
 	dhcp6 = l_netconfig_get_dhcp6_client(netconfig->nc);
 	l_dhcp6_client_set_lla_randomized(dhcp6, true);
-	l_dhcp6_client_set_nodelay(dhcp6, true);
 
-	if (debug_level)
+	icmp6 = l_netconfig_get_icmp6_client(netconfig->nc);
+	l_icmp6_client_set_nodelay(icmp6, true);
+
+	if (debug_level) {
 		l_dhcp6_client_set_debug(dhcp6, do_debug, "[DHCPv6] ", NULL);
+		l_icmp6_client_set_debug(icmp6, do_debug, "[ICMPv6] ", NULL);
+	}
 
 	l_netconfig_set_route_priority(netconfig->nc, ROUTE_PRIORITY_OFFSET);
+	l_netconfig_set_optimistic_dad_enabled(netconfig->nc, true);
 
 	return netconfig;
 }
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/3 autotests: Add a SLAAC test

In reply to Andrew Zaborowski
---
 autotests/testNetconfig/slaac_test.py | 154 ++++++++++++++++++++++++++
 1 file changed, 154 insertions(+)
 create mode 100644 autotests/testNetconfig/slaac_test.py
autotests/testNetconfig/slaac_test.py new file +154 -0
new file mode 100644
index 00000000..26ae0e46
@@ -0,0 +1,154 @@
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+import iwd
+from iwd import IWD
+from iwd import PSKAgent
+from iwd import NetworkType
+from hostapd import HostapdCLI
+import testutil
+from config import ctx
+import os
+import socket
+
+class Test(unittest.TestCase):
+
+    def test_connection_success(self):
+        def check_addr(device):
+            try:
+                testutil.test_ip_address_match(device.name, '3ffe:501:ffff:200::', 128, 64)
+            except:
+                return False
+
+            return True
+
+        def get_ll_addrs6(ns, ifname):
+            show_ip = ns.start_process(['ip', 'addr', 'show', ifname])
+            show_ip.wait()
+            for l in show_ip.out.split('\n'):
+                if 'inet6 fe80::' in l:
+                    return socket.inet_pton(socket.AF_INET6, l.split(None, 1)[1].split('/', 1)[0])
+            return None
+
+        IWD.copy_to_storage('auto.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)
+
+        # Give the AP's interface time to set up addresses so that radvd can
+        # reply to our Router Solicitation immediately.
+        ctx.non_block_wait(lambda: False, 3, exception=False)
+
+        ordered_network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        wd.wait_for_object_condition(device, condition)
+
+        testutil.test_iface_operstate()
+
+        ctx.non_block_wait(check_addr, 10, device,
+                            exception=Exception("IPv6 address was not set"))
+
+        # Cannot use test_ifaces_connected() across namespaces (implementation details)
+        testutil.test_ip_connected(('192.168.1.10', ctx), ('192.168.1.1', self.ns1))
+
+        ifname = str(device.name)
+        router_ll_addr = get_ll_addrs6(self.ns1, self.hapd.ifname)
+        expected_routes6 = {
+                # Default router
+                testutil.RouteInfo(gw=router_ll_addr, flags=3, ifname=ifname),
+                # On-link prefixes
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:100::'), plen=64,
+                    flags=1, ifname=ifname),
+                testutil.RouteInfo(dst=socket.inet_pton(socket.AF_INET6, '3ffe:501:ffff:200::'), plen=64,
+                    flags=1, ifname=ifname),
+            }
+        self.maxDiff = None
+        self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname)))
+
+        rclog = open('/tmp/resolvconf.log', 'r')
+        entries = rclog.readlines()
+        rclog.close()
+        expected_rclog = ['-a %s.dns\n' % (ifname,), 'nameserver 192.168.1.2\n',
+                'nameserver 3ffe:501:ffff:100::10\n', 'nameserver 3ffe:501:ffff:100::50\n',
+                '-a %s.domain\n' % (ifname,), 'search test1\n', 'search test2\n']
+        # Every resolvconf -a run overwrites the previous settings.  Check the last seven lines
+        # of our log since we care about the end result here.
+        self.assertEqual(expected_rclog, entries[-7:])
+
+        device.disconnect()
+        condition = 'not obj.connected'
+        wd.wait_for_object_condition(ordered_network.network_object, condition)
+        wd.unregister_psk_agent(psk_agent)
+
+    @classmethod
+    def setUpClass(cls):
+        def remove_lease4():
+            try:
+                os.remove('/tmp/dhcpd.leases')
+                os.remove('/tmp/dhcpd.leases~')
+            except:
+                pass
+        cls.ns1 = ctx.get_namespace('ns1')
+        cls.hapd = HostapdCLI('ap-ns1.conf')
+        cls.ns1.start_process(['ip', 'addr','add', '192.168.1.1/17',
+                            'dev', cls.hapd.ifname]).wait()
+        cls.ns1.start_process(['touch', '/tmp/dhcpd.leases']).wait()
+        cls.dhcpd_pid = cls.ns1.start_process(['dhcpd', '-f', '-d', '-cf', '/tmp/dhcpd.conf',
+                                                '-lf', '/tmp/dhcpd.leases',
+                                                cls.hapd.ifname], cleanup=remove_lease4)
+
+        cls.ns1.start_process(['ip', 'addr', 'add', '3ffe:501:ffff:100::1/72',
+                            'dev', cls.hapd.ifname]).wait()
+        cls.ns1.start_process(['sysctl',
+                                'net.ipv6.conf.' + cls.hapd.ifname + '.forwarding=1']).wait()
+        config = open('/tmp/radvd.conf', 'w')
+        config.write('interface ' + cls.hapd.ifname + ''' {
+            AdvSendAdvert on;
+            # Trick radvd to accept MinDelayBetweenRAs values less than 3 seconds.
+            AdvHomeAgentFlag on;
+            # Don't throttle so we can test solicited RA reception before link-local addr DAD done.
+            # radvd may have sent an unsolicited RA just before our RS and would complain -- the
+            # test should succeed regardless but will take some extra seconds.
+            MinDelayBetweenRAs 0.05;
+            AdvManagedFlag off;
+            # Test that the prefix with longer lifetime is selected.
+            prefix 3ffe:501:ffff:100::/64 { AdvAutonomous on; };
+            prefix 3ffe:501:ffff:200::/64 { AdvAutonomous on; AdvPreferredLifetime infinity; AdvValidLifetime infinity; };
+            RDNSS 3ffe:501:ffff:100::10 3ffe:501:ffff:100::50 { AdvRDNSSLifetime 3600; };
+            DNSSL test1 test2 { AdvDNSSLLifetime 3600; };
+            };''')
+        config.close()
+        cls.radvd_pid = cls.ns1.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()
+        cls.ns1.stop_process(cls.dhcpd_pid)
+        cls.dhcpd_pid = None
+        cls.ns1.stop_process(cls.radvd_pid)
+        cls.radvd_pid = None
+        os.system('rm -rf /tmp/radvd.conf /tmp/test-bin')
+        os.environ['PATH'] = cls.orig_path
+
+if __name__ == '__main__':
+    unittest.main(exit=True)
Signature · 1 line
2.34.1
#3 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 6 lines · Andrew Zaborowski

l_dbus_message_get_path(reply) is normally NULL in this callback so don't bother printing it.

---
  src/netconfig-commit.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

All applied, thanks.

Regards,
-Denis