1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

sd-dhcp6-client: support multiple NTP server options

Also, it is allowed that the suboption appears multiple times, and each
suboption contains one NTP server.
This commit is contained in:
Yu Watanabe 2021-09-24 14:09:14 +09:00
parent 41b14f0329
commit 9c3d46bf8d
3 changed files with 11 additions and 9 deletions

View File

@ -50,7 +50,7 @@ int dhcp6_lease_get_pd_iaid(sd_dhcp6_lease *lease, be32_t *iaid);
int dhcp6_lease_set_dns(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen);
int dhcp6_lease_add_domains(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen);
int dhcp6_lease_set_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen);
int dhcp6_lease_add_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen);
int dhcp6_lease_set_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) ;
int dhcp6_lease_set_fqdn(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen);

View File

@ -1257,7 +1257,7 @@ static int client_parse_message(
break;
case SD_DHCP6_OPTION_NTP_SERVER:
r = dhcp6_lease_set_ntp(lease, optval, optlen);
r = dhcp6_lease_add_ntp(lease, optval, optlen);
if (r < 0)
return r;

View File

@ -242,15 +242,12 @@ int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***ret) {
return strv_length(lease->domains);
}
int dhcp6_lease_set_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) {
int dhcp6_lease_add_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) {
int r;
assert_return(lease, -EINVAL);
assert_return(optval, -EINVAL);
lease->ntp = mfree(lease->ntp);
lease->ntp_count = 0;
for (size_t offset = 0; offset < optlen;) {
const uint8_t *subval;
size_t sublen;
@ -273,13 +270,18 @@ int dhcp6_lease_set_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t opt
break;
case DHCP6_NTP_SUBOPTION_SRV_FQDN: {
char **servers;
_cleanup_free_ char *server = NULL;
r = dhcp6_option_parse_domainname_list(subval, sublen, &servers);
r = dhcp6_option_parse_domainname(subval, sublen, &server);
if (r < 0)
return r;
strv_free_and_replace(lease->ntp_fqdn, servers);
if (strv_contains(lease->ntp_fqdn, server))
continue;
r = strv_consume(&lease->ntp_fqdn, TAKE_PTR(server));
if (r < 0)
return r;
break;
}}