mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 00:40:19 +01:00
dhcp: sd-dhcp6-client: delay setting the DUID and don't fail constructor
reimport systemd dhcp code to bring patch cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3.
sd-dhcp6-client: delay setting the DUID and don't fail constructor
sd_dhcp6_client_new() tried to set the DUID based on the machine id.
If the host has no /etc/machine-id, the constructor would fail
making it impossible to create an sd_dhcp6_client instance.
Relax this and create a DUID only later as needed. This way a caller
caller can workaround a missing machine-id file and set a DUID of his
choosing via sd_dhcp6_client_set_duid().
Conflicts:
src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
This commit is contained in:
commit
2e788fac45
2 changed files with 13 additions and 11 deletions
|
|
@ -162,6 +162,13 @@ int sd_dhcp6_client_set_mac(sd_dhcp6_client *client, const uint8_t *addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int client_ensure_duid(sd_dhcp6_client *client)
|
||||
{
|
||||
if (client->duid_len != 0)
|
||||
return 0;
|
||||
return dhcp_identifier_set_duid_en(&client->duid, &client->duid_len);
|
||||
}
|
||||
|
||||
int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t type, uint8_t *duid,
|
||||
size_t duid_len)
|
||||
{
|
||||
|
|
@ -382,6 +389,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
assert (client->duid_len);
|
||||
r = dhcp6_option_append(&opt, &optlen, DHCP6_OPTION_CLIENTID,
|
||||
client->duid_len, &client->duid);
|
||||
if (r < 0)
|
||||
|
|
@ -1112,6 +1120,10 @@ int sd_dhcp6_client_start(sd_dhcp6_client *client)
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = client_ensure_duid(client);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dhcp6_network_bind_udp_socket(client->index, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
|
@ -1209,9 +1221,6 @@ sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
|
|||
int sd_dhcp6_client_new(sd_dhcp6_client **ret)
|
||||
{
|
||||
_cleanup_dhcp6_client_unref_ sd_dhcp6_client *client = NULL;
|
||||
#if 0 /* NM_IGNORED */
|
||||
int r;
|
||||
#endif /* NM_IGNORED */
|
||||
size_t t;
|
||||
|
||||
assert_return(ret, -EINVAL);
|
||||
|
|
@ -1228,13 +1237,6 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
|
|||
|
||||
client->fd = -1;
|
||||
|
||||
#if 0 /* NM_IGNORED */
|
||||
/* initialize DUID */
|
||||
r = dhcp_identifier_set_duid_en(&client->duid, &client->duid_len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
#endif /* NM_IGNORED */
|
||||
|
||||
client->req_opts_len = ELEMENTSOF(default_req_opts);
|
||||
|
||||
client->req_opts = new0(be16_t, client->req_opts_len);
|
||||
|
|
|
|||
|
|
@ -6043,7 +6043,7 @@ int on_ac_power(void) {
|
|||
|
||||
d = opendir("/sys/class/power_supply");
|
||||
if (!d)
|
||||
return -errno;
|
||||
return errno == ENOENT ? true : -errno;
|
||||
|
||||
for (;;) {
|
||||
struct dirent *de;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue