]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-client: introduce sd_dhcp_client_attach_device()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 21:31:49 +0000 (06:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 23:08:35 +0000 (08:08 +0900)
It will be used later.

src/libsystemd-network/sd-dhcp-client.c
src/systemd/sd-dhcp-client.h

index a106f7f3b8593eeee1763fadc2e3e8aea47c90f5..98a19c3cb88c5988c5672e74d49864cce7d7ee0c 100644 (file)
@@ -14,6 +14,7 @@
 #include "sd-dhcp-client.h"
 
 #include "alloc-util.h"
+#include "device-util.h"
 #include "dhcp-identifier.h"
 #include "dhcp-internal.h"
 #include "dhcp-lease-internal.h"
@@ -77,8 +78,12 @@ struct sd_dhcp_client {
         sd_event *event;
         int event_priority;
         sd_event_source *timeout_resend;
+
         int ifindex;
         char *ifname;
+
+        sd_device *dev;
+
         int fd;
         uint16_t port;
         union sockaddr_union link;
@@ -2153,6 +2158,12 @@ sd_event *sd_dhcp_client_get_event(sd_dhcp_client *client) {
         return client->event;
 }
 
+int sd_dhcp_client_attach_device(sd_dhcp_client *client, sd_device *dev) {
+        assert_return(client, -EINVAL);
+
+        return device_unref_and_replace(client->dev, dev);
+}
+
 static sd_dhcp_client *dhcp_client_free(sd_dhcp_client *client) {
         if (!client)
                 return NULL;
@@ -2168,6 +2179,8 @@ static sd_dhcp_client *dhcp_client_free(sd_dhcp_client *client) {
 
         sd_dhcp_client_detach_event(client);
 
+        sd_device_unref(client->dev);
+
         set_free(client->req_opts);
         free(client->hostname);
         free(client->vendor_class_identifier);
index 6a863794a4c65c2eb97b1aa1ad0326c5a5acd5b4..b200f17cbdd5dde0744216dd9e13cc60723c2826 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/types.h>
 #include <stdbool.h>
 
+#include "sd-device.h"
 #include "sd-dhcp-lease.h"
 #include "sd-dhcp-option.h"
 #include "sd-event.h"
@@ -337,6 +338,7 @@ int sd_dhcp_client_attach_event(
                 int64_t priority);
 int sd_dhcp_client_detach_event(sd_dhcp_client *client);
 sd_event *sd_dhcp_client_get_event(sd_dhcp_client *client);
+int sd_dhcp_client_attach_device(sd_dhcp_client *client, sd_device *dev);
 
 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_dhcp_client, sd_dhcp_client_unref);