Adding dhcp client and dhcp6 client state interface
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
@@ -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(). */
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user