]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/dhcp6: do not request IA_PD when running in the other-information mode
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 20 Oct 2024 19:41:57 +0000 (04:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 21 Oct 2024 19:34:50 +0000 (04:34 +0900)
This reverts the following commits:
180cc5421d9712fb95a6bbc725dc8ba459360c8b
  "sd-dhcp6-client: allow to request IA_PD on information requesting mode"
cf7a403e470368049165ecff7ac7686928778d7c
  "sd-dhcp6-lease: adjust information refresh time with lifetime of IA_PD"
1918eda30d12e1ba3ee55921c18ec53267463e24
  "network/dhcp6: process hostname and IA_PD on information requesting mode"

As per discussion in #34299,
https://github.com/systemd/systemd/issues/34299#issuecomment-2425153221
the offending commits violate RFC 8415 section 18.2.6:
> The client uses an Information-request message to obtain
> configuration information without having addresses and/or delegated
> prefixes assigned to it.

src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/sd-dhcp6-lease.c
src/libsystemd-network/test-dhcp6-client.c
src/network/networkd-dhcp6.c

index 5661beeb657a968dc57f9fbe7aa96b645d659830..3e992d7cadcdb56872f72a94aef672e7e1da4cc5 100644 (file)
@@ -767,14 +767,6 @@ int dhcp6_client_send_message(sd_dhcp6_client *client) {
 
         switch (client->state) {
         case DHCP6_STATE_INFORMATION_REQUEST:
-                /* RFC 7084 section 4.2 (https://datatracker.ietf.org/doc/html/rfc7084#section-4.2)
-                 * WPD-4: By default, the IPv6 CE router MUST initiate DHCPv6 prefix delegation when either
-                 * the M or O flags are set to 1 in a received Router Advertisement (RA) message. */
-                if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD)) {
-                        r = dhcp6_option_append_ia(&buf, &offset, (client->lease ? client->lease->ia_pd : NULL) ?: &client->ia_pd);
-                        if (r < 0)
-                                return r;
-                }
                 break;
 
         case DHCP6_STATE_SOLICITATION:
index 261ab83c6489c89c479d788517c0f2a964f82285..30c0e514f86fe411246d3e76efa22054a229651e 100644 (file)
@@ -71,32 +71,6 @@ 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,                          \
@@ -795,6 +769,11 @@ static int dhcp6_lease_parse_message(
                 case SD_DHCP6_OPTION_IA_PD: {
                         _cleanup_(dhcp6_ia_freep) DHCP6IA *ia = NULL;
 
+                        if (client->state == DHCP6_STATE_INFORMATION_REQUEST) {
+                                log_dhcp6_client(client, "Ignoring IA PD option in information requesting mode.");
+                                break;
+                        }
+
                         r = dhcp6_option_parse_ia(client, client->ia_pd.header.id, optcode, optlen, optval, &ia);
                         if (r == -ENOMEM)
                                 return log_oom_debug();
@@ -891,9 +870,12 @@ 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)
-                dhcp6_client_set_information_refresh_time(client, lease, irt);
-        else {
+        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 {
                 r = dhcp6_lease_get_serverid(lease, NULL, NULL);
                 if (r < 0)
                         return log_dhcp6_client_errno(client, r, "%s has no server id",
index 29cbdc95b4a2192d7ef271cf25c17344061af46a..7afd464dc0ff6ee0e92232e695bf5e2aabb350c1 100644 (file)
@@ -493,11 +493,6 @@ static const uint8_t msg_information_request[] = {
         DHCP6_MESSAGE_INFORMATION_REQUEST,
         /* Transaction ID */
         0x0f, 0xb4, 0xe5,
-        /* IA_PD */
-        0x00, SD_DHCP6_OPTION_IA_PD, 0x00, 0x0c,
-        IA_ID_BYTES,
-        0x00, 0x00, 0x00, 0x00, /* lifetime T1 */
-        0x00, 0x00, 0x00, 0x00, /* lifetime T2 */
         /* MUD URL */
         /* ORO */
         0x00, SD_DHCP6_OPTION_ORO, 0x00, 0x0c,
index f1ecf6420516c7c2a8925ee7e78d6b16a56b406a..39471d6628dd8ecf7aa51e42103157632f42bd69 100644 (file)
@@ -297,7 +297,7 @@ static int dhcp6_request_hostname(Link *link) {
         return 0;
 }
 
-static int dhcp6_lease_acquired(sd_dhcp6_client *client, Link *link) {
+static int dhcp6_lease_ip_acquired(sd_dhcp6_client *client, Link *link) {
         _cleanup_(sd_dhcp6_lease_unrefp) sd_dhcp6_lease *lease_old = NULL;
         sd_dhcp6_lease *lease;
         int r;
@@ -341,6 +341,22 @@ static int dhcp6_lease_acquired(sd_dhcp6_client *client, Link *link) {
                 link_set_state(link, LINK_STATE_CONFIGURING);
 
         link_check_ready(link);
+        return 0;
+}
+
+static int dhcp6_lease_information_acquired(sd_dhcp6_client *client, Link *link) {
+        sd_dhcp6_lease *lease;
+        int r;
+
+        assert(client);
+        assert(link);
+
+        r = sd_dhcp6_client_get_lease(client, &lease);
+        if (r < 0)
+                return log_link_error_errno(link, r, "Failed to get DHCPv6 lease: %m");
+
+        unref_and_replace_full(link->dhcp6_lease, lease, sd_dhcp6_lease_ref, sd_dhcp6_lease_unref);
+
         link_dirty(link);
         return 0;
 }
@@ -385,8 +401,11 @@ static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) {
                 break;
 
         case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE:
+                r = dhcp6_lease_ip_acquired(client, link);
+                break;
+
         case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST:
-                r = dhcp6_lease_acquired(client, link);
+                r = dhcp6_lease_information_acquired(client, link);
                 break;
 
         default: