From: Yu Watanabe Date: Sun, 6 Feb 2022 05:32:36 +0000 (+0900) Subject: sd-dhcp6-client: store PD prefix hint in ia_pd X-Git-Tag: v251-rc1~291^2~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=877bfc78fdf0e106164593641eb40cd1ac22bbbc;p=thirdparty%2Fsystemd.git sd-dhcp6-client: store PD prefix hint in ia_pd And allows to specify multiple hints. --- diff --git a/src/libsystemd-network/dhcp6-internal.h b/src/libsystemd-network/dhcp6-internal.h index 131922b658e..ad77a9c44c5 100644 --- a/src/libsystemd-network/dhcp6-internal.h +++ b/src/libsystemd-network/dhcp6-internal.h @@ -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); diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c index 049380cdd9b..f570e78875d 100644 --- a/src/libsystemd-network/dhcp6-option.c +++ b/src/libsystemd-network/dhcp6-option.c @@ -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); } diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 30795082bdf..b60950740af 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -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), }; diff --git a/src/systemd/sd-dhcp6-client.h b/src/systemd/sd-dhcp6-client.h index 0e23c84e64c..d857af5acf6 100644 --- a/src/systemd/sd-dhcp6-client.h +++ b/src/systemd/sd-dhcp6-client.h @@ -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,