]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp6-client: store PD prefix hint in ia_pd
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 6 Feb 2022 05:32:36 +0000 (14:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Feb 2022 05:43:45 +0000 (14:43 +0900)
And allows to specify multiple hints.

src/libsystemd-network/dhcp6-internal.h
src/libsystemd-network/dhcp6-option.c
src/libsystemd-network/sd-dhcp6-client.c
src/systemd/sd-dhcp6-client.h

index 131922b658ea8bd448297ced7afb4c2a7219bdd0..ad77a9c44c5405f99f0ef51d41a79a79783a12c8 100644 (file)
@@ -81,7 +81,7 @@ bool dhcp6_option_can_request(uint16_t option);
 int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
                         size_t optlen, const void *optval);
 int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia);
-int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, const DHCP6Address *hint_pd_prefix);
+int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd);
 int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn);
 int dhcp6_option_append_user_class(uint8_t **buf, size_t *buflen, char * const *user_class);
 int dhcp6_option_append_vendor_class(uint8_t **buf, size_t *buflen, char * const *user_class);
index 049380cdd9bce2d98f48a66d9075a55fab65c502..f570e78875dae5767f49654c1973fa3849f29d93 100644 (file)
@@ -381,7 +381,7 @@ static int option_append_pd_prefix(uint8_t **buf, size_t *buflen, const DHCP6Add
         return offsetof(DHCP6Option, data) + sizeof(struct iapdprefix);
 }
 
-int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, const DHCP6Address *hint_pd_prefix) {
+int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd) {
         struct ia_header header;
         size_t len, pd_buflen;
         uint8_t *pd_hdr;
@@ -422,14 +422,6 @@ int dhcp6_option_append_pd(uint8_t **buf, size_t *buflen, const DHCP6IA *pd, con
                 len += r;
         }
 
-        if (hint_pd_prefix && hint_pd_prefix->iapdprefix.prefixlen > 0) {
-                r = option_append_pd_prefix(buf, buflen, hint_pd_prefix);
-                if (r < 0)
-                        return r;
-
-                len += r;
-        }
-
         return option_append_hdr(&pd_hdr, &pd_buflen, pd->type, len);
 }
 
index 30795082bdf022c84d4b63d11cbea0697a9dbc65..b60950740af109ae19128f392ce10cd409a2382e 100644 (file)
@@ -50,7 +50,6 @@ struct sd_dhcp6_client {
         int event_priority;
         int ifindex;
         char *ifname;
-        DHCP6Address hint_pd_prefix;
         struct in6_addr local_address;
         uint8_t mac_addr[MAX_MAC_ADDR_LEN];
         size_t mac_addr_len;
@@ -261,16 +260,32 @@ int sd_dhcp6_client_set_mac(
 int sd_dhcp6_client_set_prefix_delegation_hint(
                 sd_dhcp6_client *client,
                 uint8_t prefixlen,
-                const struct in6_addr *pd_address) {
+                const struct in6_addr *pd_prefix) {
+
+        _cleanup_free_ DHCP6Address *prefix = NULL;
 
         assert_return(client, -EINVAL);
-        assert_return(pd_address, -EINVAL);
         assert_return(client->state == DHCP6_STATE_STOPPED, -EBUSY);
 
-        client->hint_pd_prefix.iapdprefix.address = *pd_address;
-        client->hint_pd_prefix.iapdprefix.prefixlen = prefixlen;
+        if (!pd_prefix) {
+                /* clear previous assignments. */
+                dhcp6_ia_clear_addresses(&client->ia_pd);
+                return 0;
+        }
+
+        assert_return(prefixlen > 0 && prefixlen <= 128, -EINVAL);
 
-        return 0;
+        prefix = new(DHCP6Address, 1);
+        if (!prefix)
+                return -ENOMEM;
+
+        *prefix = (DHCP6Address) {
+                .iapdprefix.address = *pd_prefix,
+                .iapdprefix.prefixlen = prefixlen,
+        };
+
+        LIST_PREPEND(addresses, client->ia_pd.addresses, TAKE_PTR(prefix));
+        return 1;
 }
 
 int sd_dhcp6_client_add_vendor_option(sd_dhcp6_client *client, sd_dhcp6_option *v) {
@@ -667,8 +682,7 @@ static int client_append_common_options_in_managed_mode(
                 uint8_t **opt,
                 size_t *optlen,
                 const DHCP6IA *ia_na,
-                const DHCP6IA *ia_pd,
-                const DHCP6Address *hint_pd_prefix) {
+                const DHCP6IA *ia_pd) {
 
         int r;
 
@@ -688,7 +702,7 @@ static int client_append_common_options_in_managed_mode(
         }
 
         if (FLAGS_SET(client->request_ia, DHCP6_REQUEST_IA_PD) && ia_pd) {
-                r = dhcp6_option_append_pd(opt, optlen, ia_pd, hint_pd_prefix);
+                r = dhcp6_option_append_pd(opt, optlen, ia_pd);
                 if (r < 0)
                         return r;
         }
@@ -778,8 +792,8 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
                 if (r < 0)
                         return r;
 
-                r = client_append_common_options_in_managed_mode(client, &opt, &optlen, &client->ia_na,
-                                                                 &client->ia_pd, &client->hint_pd_prefix);
+                r = client_append_common_options_in_managed_mode(client, &opt, &optlen,
+                                                                 &client->ia_na, &client->ia_pd);
                 if (r < 0)
                         return r;
                 break;
@@ -799,7 +813,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
                 assert(client->lease);
 
                 r = client_append_common_options_in_managed_mode(client, &opt, &optlen,
-                                                                 client->lease->ia_na, client->lease->ia_pd, NULL);
+                                                                 client->lease->ia_na, client->lease->ia_pd);
                 if (r < 0)
                         return r;
                 break;
@@ -1804,7 +1818,7 @@ static sd_dhcp6_client *dhcp6_client_free(sd_dhcp6_client *client) {
         free(client->req_opts);
         free(client->fqdn);
         free(client->mudurl);
-
+        dhcp6_ia_clear_addresses(&client->ia_pd);
         ordered_hashmap_free(client->extra_options);
         strv_free(client->user_class);
         strv_free(client->vendor_class);
@@ -1841,8 +1855,6 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret) {
                 .request_ia = DHCP6_REQUEST_IA_NA | DHCP6_REQUEST_IA_PD,
                 .fd = -1,
                 .req_opts_len = ELEMENTSOF(default_req_opts),
-                .hint_pd_prefix.iapdprefix.lifetime_preferred = (be32_t) -1,
-                .hint_pd_prefix.iapdprefix.lifetime_valid = (be32_t) -1,
                 .req_opts = TAKE_PTR(req_opts),
         };
 
index 0e23c84e64c517e8bf5f0c3722de37201a15e10f..d857af5acf65df293b8d4bc90808a36268c349ce 100644 (file)
@@ -251,7 +251,7 @@ int sd_dhcp6_client_set_request_vendor_class(
 int sd_dhcp6_client_set_prefix_delegation_hint(
                 sd_dhcp6_client *client,
                 uint8_t prefixlen,
-                const struct in6_addr *pd_address);
+                const struct in6_addr *pd_prefix);
 int sd_dhcp6_client_get_prefix_delegation(sd_dhcp6_client *client,
                                           int *delegation);
 int sd_dhcp6_client_set_prefix_delegation(sd_dhcp6_client *client,