summaryrefslogtreecommitdiffstats
path: root/src/libsystemd-network/sd-dhcp6-client.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-09-04 14:48:43 +0200
committerGitHub <noreply@github.com>2023-09-04 14:48:43 +0200
commit47d8770aace000e0bfcc68ecf7d84e0bd9886431 (patch)
tree01fd8f86562fe9f7960077268927d6bec79725e7 /src/libsystemd-network/sd-dhcp6-client.c
parentMerge pull request #29055 from mrc0mmand/bash-comp (diff)
parentAdding tests for dhcp client and dhcp6 client dbus state interface (diff)
downloadsystemd-47d8770aace000e0bfcc68ecf7d84e0bd9886431.tar.xz
systemd-47d8770aace000e0bfcc68ecf7d84e0bd9886431.zip
Merge pull request #28896 from pelaufer/dhcp_dbus_notify
Add DHCP client state and change notification to networkd dbus interface
Diffstat (limited to 'src/libsystemd-network/sd-dhcp6-client.c')
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 8957e1cf4b..fb209a0c62 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -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) {