mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
Merge pull request #14056 from yuwata/dhcp-debug-logs
dhcp: add debug logs and propagate error in restarting client
This commit is contained in:
commit
ce0d4c4f91
@ -241,6 +241,7 @@ int sd_dhcp_client_set_mac(
|
||||
|
||||
DHCP_CLIENT_DONT_DESTROY(client);
|
||||
bool need_restart = false;
|
||||
int r;
|
||||
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(addr, -EINVAL);
|
||||
@ -268,8 +269,11 @@ int sd_dhcp_client_set_mac(
|
||||
client->mac_addr_len = addr_len;
|
||||
client->arp_type = arp_type;
|
||||
|
||||
if (need_restart && client->state != DHCP_STATE_STOPPED)
|
||||
sd_dhcp_client_start(client);
|
||||
if (need_restart && client->state != DHCP_STATE_STOPPED) {
|
||||
r = sd_dhcp_client_start(client);
|
||||
if (r < 0)
|
||||
return log_dhcp_client_errno(client, r, "Failed to restart DHCPv4 client: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -305,6 +309,7 @@ int sd_dhcp_client_set_client_id(
|
||||
|
||||
DHCP_CLIENT_DONT_DESTROY(client);
|
||||
bool need_restart = false;
|
||||
int r;
|
||||
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(data, -EINVAL);
|
||||
@ -337,8 +342,11 @@ int sd_dhcp_client_set_client_id(
|
||||
memcpy(&client->client_id.raw.data, data, data_len);
|
||||
client->client_id_len = data_len + sizeof (client->client_id.type);
|
||||
|
||||
if (need_restart && client->state != DHCP_STATE_STOPPED)
|
||||
sd_dhcp_client_start(client);
|
||||
if (need_restart && client->state != DHCP_STATE_STOPPED) {
|
||||
r = sd_dhcp_client_start(client);
|
||||
if (r < 0)
|
||||
return log_dhcp_client_errno(client, r, "Failed to restart DHCPv4 client: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -368,7 +376,7 @@ static int dhcp_client_set_iaid_duid_internal(
|
||||
if (duid) {
|
||||
r = dhcp_validate_duid_len(duid_type, duid_len, true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp_client_errno(client, r, "Failed to validate length of DUID: %m");
|
||||
}
|
||||
|
||||
zero(client->client_id);
|
||||
@ -383,7 +391,7 @@ static int dhcp_client_set_iaid_duid_internal(
|
||||
true,
|
||||
&client->client_id.ns.iaid);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp_client_errno(client, r, "Failed to set IAID: %m");
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,32 +403,32 @@ static int dhcp_client_set_iaid_duid_internal(
|
||||
switch (duid_type) {
|
||||
case DUID_TYPE_LLT:
|
||||
if (client->mac_addr_len == 0)
|
||||
return -EOPNOTSUPP;
|
||||
return log_dhcp_client_errno(client, SYNTHETIC_ERRNO(EOPNOTSUPP), "Failed to set DUID-LLT, MAC address is not set.");
|
||||
|
||||
r = dhcp_identifier_set_duid_llt(&client->client_id.ns.duid, llt_time, client->mac_addr, client->mac_addr_len, client->arp_type, &len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp_client_errno(client, r, "Failed to set DUID-LLT: %m");
|
||||
break;
|
||||
case DUID_TYPE_EN:
|
||||
r = dhcp_identifier_set_duid_en(&client->client_id.ns.duid, &len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp_client_errno(client, r, "Failed to set DUID-EN: %m");
|
||||
break;
|
||||
case DUID_TYPE_LL:
|
||||
if (client->mac_addr_len == 0)
|
||||
return -EOPNOTSUPP;
|
||||
return log_dhcp_client_errno(client, SYNTHETIC_ERRNO(EOPNOTSUPP), "Failed to set DUID-LL, MAC address is not set.");
|
||||
|
||||
r = dhcp_identifier_set_duid_ll(&client->client_id.ns.duid, client->mac_addr, client->mac_addr_len, client->arp_type, &len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp_client_errno(client, r, "Failed to set DUID-LL: %m");
|
||||
break;
|
||||
case DUID_TYPE_UUID:
|
||||
r = dhcp_identifier_set_duid_uuid(&client->client_id.ns.duid, &len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp_client_errno(client, r, "Failed to set DUID-UUID: %m");
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
return log_dhcp_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "Invalid DUID type");
|
||||
}
|
||||
|
||||
client->client_id_len = sizeof(client->client_id.type) + len +
|
||||
@ -429,7 +437,9 @@ static int dhcp_client_set_iaid_duid_internal(
|
||||
if (!IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_STOPPED)) {
|
||||
log_dhcp_client(client, "Configured %sDUID, restarting.", iaid_append ? "IAID+" : "");
|
||||
client_stop(client, SD_DHCP_CLIENT_EVENT_STOP);
|
||||
sd_dhcp_client_start(client);
|
||||
r = sd_dhcp_client_start(client);
|
||||
if (r < 0)
|
||||
return log_dhcp_client_errno(client, r, "Failed to restart DHCPv4 client: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -232,7 +232,7 @@ static int dhcp6_client_set_duid_internal(
|
||||
if (r < 0) {
|
||||
r = dhcp_validate_duid_len(duid_type, duid_len, false);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp6_client_errno(client, r, "Failed to validate length of DUID: %m");
|
||||
log_dhcp6_client(client, "Setting DUID of type %u with unexpected content", duid_type);
|
||||
}
|
||||
|
||||
@ -243,32 +243,32 @@ static int dhcp6_client_set_duid_internal(
|
||||
switch (duid_type) {
|
||||
case DUID_TYPE_LLT:
|
||||
if (client->mac_addr_len == 0)
|
||||
return -EOPNOTSUPP;
|
||||
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EOPNOTSUPP), "Failed to set DUID-LLT, MAC address is not set.");
|
||||
|
||||
r = dhcp_identifier_set_duid_llt(&client->duid, llt_time, client->mac_addr, client->mac_addr_len, client->arp_type, &client->duid_len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp6_client_errno(client, r, "Failed to set DUID-LLT: %m");
|
||||
break;
|
||||
case DUID_TYPE_EN:
|
||||
r = dhcp_identifier_set_duid_en(&client->duid, &client->duid_len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp6_client_errno(client, r, "Failed to set DUID-EN: %m");
|
||||
break;
|
||||
case DUID_TYPE_LL:
|
||||
if (client->mac_addr_len == 0)
|
||||
return -EOPNOTSUPP;
|
||||
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EOPNOTSUPP), "Failed to set DUID-LL, MAC address is not set.");
|
||||
|
||||
r = dhcp_identifier_set_duid_ll(&client->duid, client->mac_addr, client->mac_addr_len, client->arp_type, &client->duid_len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp6_client_errno(client, r, "Failed to set DUID-LL: %m");
|
||||
break;
|
||||
case DUID_TYPE_UUID:
|
||||
r = dhcp_identifier_set_duid_uuid(&client->duid, &client->duid_len);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_dhcp6_client_errno(client, r, "Failed to set DUID-UUID: %m");
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "Invalid DUID type");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user