]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: attach device to DHCP clients
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 21:36:39 +0000 (06:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 23:08:35 +0000 (08:08 +0900)
The attached sd_device object will be used later.

src/network/networkd-dhcp4.c
src/network/networkd-dhcp6.c
src/network/networkd-link.c

index c5bddb60fd9abb88bd99e805c84c76985a0791f8..e4005719d05065068e7c435f0a1a231e09494801 100644 (file)
@@ -1357,6 +1357,10 @@ static int dhcp4_configure(Link *link) {
         if (r < 0)
                 return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to attach event to DHCPv4 client: %m");
 
+        r = sd_dhcp_client_attach_device(link->dhcp_client, link->dev);
+        if (r < 0)
+                return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to attach device: %m");
+
         r = sd_dhcp_client_set_mac(link->dhcp_client,
                                    link->hw_addr.bytes,
                                    link->bcast_addr.length > 0 ? link->bcast_addr.bytes : NULL,
index 789868c26aaabbdee3a349386f219d0d3f42da45..d6ec2333512bf9b6010c8eab2b7ff236dee32611 100644 (file)
@@ -594,6 +594,10 @@ static int dhcp6_configure(Link *link) {
         if (r < 0)
                 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to attach event: %m");
 
+        r = sd_dhcp6_client_attach_device(client, link->dev);
+        if (r < 0)
+                return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to attach device: %m");
+
         r = dhcp6_set_identifier(link, client);
         if (r < 0)
                 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set identifier: %m");
index 00e4e451ef3ceb695f1c1266156c9700ecdde725..04e3432c948f9c31b36d2de718bd937dba6a716e 100644 (file)
@@ -1410,6 +1410,18 @@ static int link_initialized(Link *link, sd_device *device) {
          * or sysattrs) may be outdated. */
         device_unref_and_replace(link->dev, device);
 
+        if (link->dhcp_client) {
+                r = sd_dhcp_client_attach_device(link->dhcp_client, link->dev);
+                if (r < 0)
+                        log_link_warning_errno(link, r, "Failed to attach device to DHCPv4 client, ignoring: %m");
+        }
+
+        if (link->dhcp6_client) {
+                r = sd_dhcp6_client_attach_device(link->dhcp6_client, link->dev);
+                if (r < 0)
+                        log_link_warning_errno(link, r, "Failed to attach device to DHCPv6 client, ignoring: %m");
+        }
+
         r = link_set_sr_iov_ifindices(link);
         if (r < 0)
                 log_link_warning_errno(link, r, "Failed to manage SR-IOV PF and VF ports, ignoring: %m");