]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Adding dhcp client and dhcp6 client state interface
authorpelaufer <paul@laufernet.com>
Sat, 2 Sep 2023 20:51:03 +0000 (14:51 -0600)
committerpelaufer <paul@laufernet.com>
Sat, 2 Sep 2023 20:51:03 +0000 (14:51 -0600)
src/libsystemd-network/dhcp-client-internal.h
src/libsystemd-network/dhcp-internal.h
src/libsystemd-network/dhcp6-client-internal.h [new file with mode: 0644]
src/libsystemd-network/dhcp6-internal.h
src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp6-client.c
src/network/networkd-dhcp-common.c

index a6f37522d1ee96f01f2282ecb25c4af0a05f4c70..6f43975977a270ae398334a9f81e705f2ffa59d1 100644 (file)
@@ -1,4 +1,12 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
+#include "sd-dhcp-client.h"
+
 extern const struct hash_ops dhcp_option_hash_ops;
+
+int dhcp_client_set_state_callback(
+                sd_dhcp_client *client,
+                sd_dhcp_client_callback_t cb,
+                void *userdata);
+int dhcp_client_get_state(sd_dhcp_client *client);
index e020db7bcd0e081f409776a7a16cea72065bf79f..d4e4a026b5275ba9d283ac868224a534234b7ae2 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "sd-dhcp-client.h"
 
+#include "dhcp-client-internal.h"
 #include "dhcp-protocol.h"
 #include "ether-addr-util.h"
 #include "network-common.h"
@@ -29,8 +30,6 @@ typedef struct DHCPServerData {
         size_t size;
 } DHCPServerData;
 
-extern const struct hash_ops dhcp_option_hash_ops;
-
 typedef struct sd_dhcp_client sd_dhcp_client;
 
 int dhcp_network_bind_raw_socket(
diff --git a/src/libsystemd-network/dhcp6-client-internal.h b/src/libsystemd-network/dhcp6-client-internal.h
new file mode 100644 (file)
index 0000000..6c17f57
--- /dev/null
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "sd-dhcp6-client.h"
+
+int dhcp6_client_set_state_callback(
+                sd_dhcp6_client *client,
+                sd_dhcp6_client_callback_t cb,
+                void *userdata);
+int dhcp6_client_get_state(sd_dhcp6_client *client);
index fa43f28eb55e09e92ce332e004235c0f215b3a86..97bc82d5210cb9da75352a97c233d681dd26a622 100644 (file)
@@ -12,6 +12,7 @@
 #include "sd-dhcp6-client.h"
 
 #include "dhcp-identifier.h"
+#include "dhcp6-client-internal.h"
 #include "dhcp6-option.h"
 #include "dhcp6-protocol.h"
 #include "ether-addr-util.h"
@@ -79,6 +80,8 @@ struct sd_dhcp6_client {
 
         sd_dhcp6_client_callback_t callback;
         void *userdata;
+        sd_dhcp6_client_callback_t state_callback;
+        void *state_userdata;
         bool send_release;
 
         /* Ignore machine-ID when generating DUID. See dhcp_identifier_set_duid_en(). */
index 2e17f3cfd511104a85efc359c8a27cc123f09f4b..82a93af0bcba0e7672813e1e3f1b1aac209152ab 100644 (file)
@@ -118,6 +118,8 @@ struct sd_dhcp_client {
         sd_event_source *timeout_expire;
         sd_dhcp_client_callback_t callback;
         void *userdata;
+        sd_dhcp_client_callback_t state_callback;
+        void *state_userdata;
         sd_dhcp_lease *lease;
         usec_t start_delay;
         int ip_service_type;
@@ -226,6 +228,19 @@ int sd_dhcp_client_id_to_string(const void *data, size_t len, char **ret) {
         return 0;
 }
 
+int dhcp_client_set_state_callback(
+                sd_dhcp_client *client,
+                sd_dhcp_client_callback_t cb,
+                void *userdata) {
+
+        assert_return(client, -EINVAL);
+
+        client->state_callback = cb;
+        client->state_userdata = userdata;
+
+        return 0;
+}
+
 int sd_dhcp_client_set_callback(
                 sd_dhcp_client *client,
                 sd_dhcp_client_callback_t cb,
@@ -740,6 +755,15 @@ static void client_set_state(sd_dhcp_client *client, DHCPState state) {
                         dhcp_state_to_string(client->state), dhcp_state_to_string(state));
 
         client->state = state;
+
+        if (client->state_callback)
+                client->state_callback(client, state, client->state_userdata);
+}
+
+int dhcp_client_get_state(sd_dhcp_client *client) {
+        assert_return(client, -EINVAL);
+
+        return client->state;
 }
 
 static int client_notify(sd_dhcp_client *client, int event) {
index 8957e1cf4bfe57d2fe86a31efffd431e6a799fbf..fb209a0c624cf71b12c18d051205196dba3f4f3a 100644 (file)
@@ -47,6 +47,19 @@ int sd_dhcp6_client_set_callback(
         return 0;
 }
 
+int dhcp6_client_set_state_callback(
+                sd_dhcp6_client *client,
+                sd_dhcp6_client_callback_t cb,
+                void *userdata) {
+
+        assert_return(client, -EINVAL);
+
+        client->state_callback = cb;
+        client->state_userdata = userdata;
+
+        return 0;
+}
+
 int sd_dhcp6_client_set_ifindex(sd_dhcp6_client *client, int ifindex) {
         assert_return(client, -EINVAL);
         assert_return(!sd_dhcp6_client_is_running(client), -EBUSY);
@@ -553,6 +566,15 @@ static void client_set_state(sd_dhcp6_client *client, DHCP6State state) {
                          dhcp6_state_to_string(client->state), dhcp6_state_to_string(state));
 
         client->state = state;
+
+        if (client->state_callback)
+                client->state_callback(client, state, client->state_userdata);
+}
+
+int dhcp6_client_get_state(sd_dhcp6_client *client) {
+        assert_return(client, -EINVAL);
+
+        return client->state;
 }
 
 static void client_notify(sd_dhcp6_client *client, int event) {
index 5b5b251e61ed259c5622dffd778e4a411e0d05e0..ff0ee717c5ddd51edd2e5ab9957f39aa6a2064fd 100644 (file)
@@ -6,7 +6,7 @@
 #include "bus-error.h"
 #include "bus-locator.h"
 #include "dhcp-identifier.h"
-#include "dhcp-internal.h"
+#include "dhcp-client-internal.h"
 #include "dhcp6-internal.h"
 #include "escape.h"
 #include "hexdecoct.h"