summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-15 22:02:06 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-15 11:23:59 +0200
commitcf7a403e470368049165ecff7ac7686928778d7c (patch)
tree97bfa4eb7f37c575f0b6b7c5d0172d576e00ddef /src
parentsd-dhcp6-client: allow to request IA_PD on information requesting mode (diff)
downloadsystemd-cf7a403e470368049165ecff7ac7686928778d7c.tar.xz
systemd-cf7a403e470368049165ecff7ac7686928778d7c.zip
sd-dhcp6-lease: adjust information refresh time with lifetime of IA_PD
For the case when IRT is too large but lifetime of IA_PD is too short.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/sd-dhcp6-lease.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c
index 3f8183c2c6..261ab83c64 100644
--- a/src/libsystemd-network/sd-dhcp6-lease.c
+++ b/src/libsystemd-network/sd-dhcp6-lease.c
@@ -71,6 +71,32 @@ static void dhcp6_lease_set_lifetime(sd_dhcp6_lease *lease) {
lease->lifetime_t2 = t2;
}
+static void dhcp6_client_set_information_refresh_time(sd_dhcp6_client *client, sd_dhcp6_lease *lease, usec_t irt) {
+ usec_t t1 = USEC_INFINITY, t2 = USEC_INFINITY, min_valid_lt = USEC_INFINITY;
+
+ if (lease->ia_pd) {
+ t1 = be32_sec_to_usec(lease->ia_pd->header.lifetime_t1, /* max_as_infinity = */ true);
+ t2 = be32_sec_to_usec(lease->ia_pd->header.lifetime_t2, /* max_as_infinity = */ true);
+
+ LIST_FOREACH(addresses, a, lease->ia_pd->addresses)
+ min_valid_lt = MIN(min_valid_lt, be32_sec_to_usec(a->iapdprefix.lifetime_valid, /* max_as_infinity = */ true));
+
+ if (t2 == 0 || t2 > min_valid_lt) {
+ /* If T2 is zero or longer than the minimum valid lifetime of the prefixes,
+ * then adjust lifetime with it. */
+ t1 = min_valid_lt / 2;
+ t2 = min_valid_lt / 10 * 8;
+ }
+
+ /* Adjust the received information refresh time with T1. */
+ irt = MIN(irt, t1);
+ }
+
+ client->information_refresh_time_usec = MAX(irt, IRT_MINIMUM);
+ log_dhcp6_client(client, "New information request will be refused in %s.",
+ FORMAT_TIMESPAN(client->information_refresh_time_usec, USEC_PER_SEC));
+}
+
#define DEFINE_GET_TIME_FUNCTIONS(name, val) \
int sd_dhcp6_lease_get_##name( \
sd_dhcp6_lease *lease, \
@@ -865,12 +891,9 @@ static int dhcp6_lease_parse_message(
"The client ID in %s message does not match. Ignoring.",
dhcp6_message_type_to_string(message->type));
- if (client->state == DHCP6_STATE_INFORMATION_REQUEST) {
- client->information_refresh_time_usec = MAX(irt, IRT_MINIMUM);
- log_dhcp6_client(client, "New information request will be refused in %s.",
- FORMAT_TIMESPAN(client->information_refresh_time_usec, USEC_PER_SEC));
-
- } else {
+ if (client->state == DHCP6_STATE_INFORMATION_REQUEST)
+ dhcp6_client_set_information_refresh_time(client, lease, irt);
+ else {
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
if (r < 0)
return log_dhcp6_client_errno(client, r, "%s has no server id",