mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
sd-dhcp6: fix check if serverid is set
Ever since the initial implementation in 631bbe7129
,
client_parse_message() was supposed to check that the message contains exactly
one serverid. The check that no more than one is given was implemented
correctly, but the check that at least one is given was not. Simplify the whole
thing by making dhcp6_lease_get_serverid() return an error if the id is not
set, and do not require the arguments to be present if the contents of the id
are not needed.
This commit is contained in:
parent
21a9905c7a
commit
99f1d3fc50
@ -771,8 +771,6 @@ static int client_parse_message(
|
|||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
int r;
|
int r;
|
||||||
bool clientid = false;
|
bool clientid = false;
|
||||||
uint8_t *id = NULL;
|
|
||||||
size_t id_len;
|
|
||||||
uint32_t lt_t1 = ~0, lt_t2 = ~0;
|
uint32_t lt_t1 = ~0, lt_t2 = ~0;
|
||||||
|
|
||||||
assert(client);
|
assert(client);
|
||||||
@ -817,8 +815,8 @@ static int client_parse_message(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SD_DHCP6_OPTION_SERVERID:
|
case SD_DHCP6_OPTION_SERVERID:
|
||||||
r = dhcp6_lease_get_serverid(lease, &id, &id_len);
|
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
|
||||||
if (r >= 0 && id) {
|
if (r >= 0) {
|
||||||
log_dhcp6_client(client, "%s contains multiple serverids",
|
log_dhcp6_client(client, "%s contains multiple serverids",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -956,21 +954,23 @@ static int client_parse_message(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (client->state != DHCP6_STATE_INFORMATION_REQUEST) {
|
if (client->state != DHCP6_STATE_INFORMATION_REQUEST) {
|
||||||
r = dhcp6_lease_get_serverid(lease, &id, &id_len);
|
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
|
||||||
if (r < 0)
|
if (r < 0) {
|
||||||
log_dhcp6_client(client, "%s has no server id",
|
log_dhcp6_client(client, "%s has no server id",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return r;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lease->ia.addresses) {
|
} else {
|
||||||
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
|
if (lease->ia.addresses) {
|
||||||
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
|
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
|
||||||
}
|
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
|
||||||
|
}
|
||||||
|
|
||||||
if (lease->pd.addresses) {
|
if (lease->pd.addresses) {
|
||||||
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
|
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
|
||||||
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
|
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -95,11 +95,14 @@ int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
|
|||||||
|
|
||||||
int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len) {
|
int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len) {
|
||||||
assert_return(lease, -EINVAL);
|
assert_return(lease, -EINVAL);
|
||||||
assert_return(id, -EINVAL);
|
|
||||||
assert_return(len, -EINVAL);
|
|
||||||
|
|
||||||
*id = lease->serverid;
|
if (!lease->serverid)
|
||||||
*len = lease->serverid_len;
|
return -ENOMSG;
|
||||||
|
|
||||||
|
if (id)
|
||||||
|
*id = lease->serverid;
|
||||||
|
if (len)
|
||||||
|
*len = lease->serverid_len;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user