1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

sd-dhcp6-client: do not merge NTP and SNTP options

Previously, SNTP option is ignored when it appears after NTP option(s),
but merged later NTP options when it appears first.
This makes split the NTP and SNTP addresses, and use SNTP addresses only
when no NTP option is provided.
This commit is contained in:
Yu Watanabe 2021-09-24 15:00:43 +09:00
parent 9c3d46bf8d
commit e693e96961
4 changed files with 20 additions and 15 deletions

View File

@ -31,6 +31,8 @@ struct sd_dhcp6_lease {
struct in6_addr *ntp;
size_t ntp_count;
char **ntp_fqdn;
struct in6_addr *sntp;
size_t sntp_count;
char *fqdn;
};
@ -51,7 +53,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_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_add_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);
int dhcp6_lease_new(sd_dhcp6_lease **ret);

View File

@ -1264,7 +1264,7 @@ static int client_parse_message(
break;
case SD_DHCP6_OPTION_SNTP_SERVERS:
r = dhcp6_lease_set_sntp(lease, optval, optlen);
r = dhcp6_lease_add_sntp(lease, optval, optlen);
if (r < 0)
return r;

View File

@ -290,30 +290,33 @@ int dhcp6_lease_add_ntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t opt
return 0;
}
int dhcp6_lease_set_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) {
int dhcp6_lease_add_sntp(sd_dhcp6_lease *lease, const uint8_t *optval, size_t optlen) {
assert_return(lease, -EINVAL);
assert_return(optval, -EINVAL);
if (optlen == 0)
return 0;
if (lease->ntp || lease->ntp_fqdn)
return -EEXIST;
/* Using deprecated SNTP information */
return dhcp6_option_parse_addresses(optval, optlen, &lease->ntp, &lease->ntp_count);
/* SNTP option is defined in RFC4075, and deprecated by RFC5908. */
return dhcp6_option_parse_addresses(optval, optlen, &lease->sntp, &lease->sntp_count);
}
int sd_dhcp6_lease_get_ntp_addrs(sd_dhcp6_lease *lease, const struct in6_addr **ret) {
assert_return(lease, -EINVAL);
assert_return(ret, -EINVAL);
if (!lease->ntp)
return -ENOENT;
if (lease->ntp) {
*ret = lease->ntp;
return lease->ntp_count;
}
*ret = lease->ntp;
return lease->ntp_count;
if (lease->sntp && !lease->ntp_fqdn) {
/* Fallback to the deprecated SNTP option. */
*ret = lease->sntp;
return lease->sntp_count;
}
return -ENOENT;
}
int sd_dhcp6_lease_get_ntp_fqdn(sd_dhcp6_lease *lease, char ***ret) {
@ -369,6 +372,7 @@ static sd_dhcp6_lease *dhcp6_lease_free(sd_dhcp6_lease *lease) {
strv_free(lease->domains);
free(lease->ntp);
strv_free(lease->ntp_fqdn);
free(lease->sntp);
return mfree(lease);
}

View File

@ -521,8 +521,7 @@ static int test_advertise_option(sd_event *e) {
case SD_DHCP6_OPTION_SNTP_SERVERS:
assert_se(optlen == 16);
assert_se(dhcp6_lease_set_sntp(lease, optval,
optlen) >= 0);
assert_se(dhcp6_lease_add_sntp(lease, optval, optlen) >= 0);
break;
default: