Skip to content

Commit 99f1d3f

Browse files
committed
sd-dhcp6: fix check if serverid is set
Ever since the initial implementation in 631bbe7, 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.
1 parent 21a9905 commit 99f1d3f

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/libsystemd-network/sd-dhcp6-client.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,6 @@ static int client_parse_message(
771771
size_t pos = 0;
772772
int r;
773773
bool clientid = false;
774-
uint8_t *id = NULL;
775-
size_t id_len;
776774
uint32_t lt_t1 = ~0, lt_t2 = ~0;
777775

778776
assert(client);
@@ -817,8 +815,8 @@ static int client_parse_message(
817815
break;
818816

819817
case SD_DHCP6_OPTION_SERVERID:
820-
r = dhcp6_lease_get_serverid(lease, &id, &id_len);
821-
if (r >= 0 && id) {
818+
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
819+
if (r >= 0) {
822820
log_dhcp6_client(client, "%s contains multiple serverids",
823821
dhcp6_message_type_to_string(message->type));
824822
return -EINVAL;
@@ -956,21 +954,23 @@ static int client_parse_message(
956954
}
957955

958956
if (client->state != DHCP6_STATE_INFORMATION_REQUEST) {
959-
r = dhcp6_lease_get_serverid(lease, &id, &id_len);
960-
if (r < 0)
957+
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
958+
if (r < 0) {
961959
log_dhcp6_client(client, "%s has no server id",
962960
dhcp6_message_type_to_string(message->type));
963-
return r;
964-
}
961+
return -EINVAL;
962+
}
965963

966-
if (lease->ia.addresses) {
967-
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
968-
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
969-
}
964+
} else {
965+
if (lease->ia.addresses) {
966+
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
967+
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
968+
}
970969

971-
if (lease->pd.addresses) {
972-
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
973-
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
970+
if (lease->pd.addresses) {
971+
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
972+
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
973+
}
974974
}
975975

976976
return 0;

src/libsystemd-network/sd-dhcp6-lease.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ int dhcp6_lease_set_serverid(sd_dhcp6_lease *lease, const uint8_t *id,
9595

9696
int dhcp6_lease_get_serverid(sd_dhcp6_lease *lease, uint8_t **id, size_t *len) {
9797
assert_return(lease, -EINVAL);
98-
assert_return(id, -EINVAL);
99-
assert_return(len, -EINVAL);
10098

101-
*id = lease->serverid;
102-
*len = lease->serverid_len;
99+
if (!lease->serverid)
100+
return -ENOMSG;
101+
102+
if (id)
103+
*id = lease->serverid;
104+
if (len)
105+
*len = lease->serverid_len;
103106

104107
return 0;
105108
}

0 commit comments

Comments
 (0)