#include "hostname-util.h"
#include "io-util.h"
#include "memory-util.h"
+#include "network-common.h"
#include "random-util.h"
#include "set.h"
#include "sort-util.h"
int event_priority;
sd_event_source *timeout_resend;
int ifindex;
+ char *ifname;
int fd;
uint16_t port;
union sockaddr_union link;
sd_dhcp_lease *lease;
usec_t start_delay;
int ip_service_type;
+
+ /* Ignore ifindex when generating iaid. See dhcp_identifier_set_iaid(). */
+ bool test_mode;
};
static const uint8_t default_req_opts[] = {
return 0;
}
+int sd_dhcp_client_set_ifname(sd_dhcp_client *client, const char *ifname) {
+ assert_return(client, -EINVAL);
+ assert_return(ifname, -EINVAL);
+
+ if (!ifname_valid_full(ifname, IFNAME_VALID_ALTERNATIVE))
+ return -EINVAL;
+
+ return free_and_strdup(&client->ifname, ifname);
+}
+
+const char *sd_dhcp_client_get_ifname(sd_dhcp_client *client) {
+ if (!client)
+ return NULL;
+
+ return get_ifname(client->ifindex, &client->ifname);
+}
+
int sd_dhcp_client_set_mac(
sd_dhcp_client *client,
const uint8_t *addr,
else {
r = dhcp_identifier_set_iaid(client->ifindex, client->mac_addr,
client->mac_addr_len,
- true,
+ /* legacy_unstable_byteorder = */ true,
+ /* use_mac = */ client->test_mode,
&client->client_id.ns.iaid);
if (r < 0)
return log_dhcp_client_errno(client, r, "Failed to set IAID: %m");
return dhcp_client_set_iaid_duid_internal(client, false, false, 0, DUID_TYPE_LLT, NULL, 0, llt_time);
}
+void dhcp_client_set_test_mode(sd_dhcp_client *client, bool test_mode) {
+ assert(client);
+
+ client->test_mode = test_mode;
+}
+
int sd_dhcp_client_set_hostname(
sd_dhcp_client *client,
const char *hostname) {
client->client_id.type = 255;
r = dhcp_identifier_set_iaid(client->ifindex, client->mac_addr, client->mac_addr_len,
- true, &client->client_id.ns.iaid);
+ /* legacy_unstable_byteorder = */ true,
+ /* use_mac = */ client->test_mode,
+ &client->client_id.ns.iaid);
if (r < 0)
return r;
return client_initialize_time_events(client);
}
+int sd_dhcp_client_is_running(sd_dhcp_client *client) {
+ if (!client)
+ return 0;
+
+ return !IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_STOPPED);
+}
+
int sd_dhcp_client_start(sd_dhcp_client *client) {
int r;
client->user_class = strv_free(client->user_class);
ordered_hashmap_free(client->extra_options);
ordered_hashmap_free(client->vendor_options);
+ free(client->ifname);
return mfree(client);
}