From 54fe031705745fc72fa04f47b0567c57a84bbb43 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 31 Jan 2023 14:49:59 +0100 Subject: [PATCH] sys/net/dhcpv6: add IA Prefix Option in SOLICIT Add the IA Prefix Option when soliciting a prefix so we can tell the server what prefix length we want. --- sys/net/application_layer/dhcpv6/client.c | 34 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index 0136cb7142..2220af8786 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -423,15 +423,32 @@ static inline size_t _compose_oro_opt(dhcpv6_opt_oro_t *oro, uint16_t *opts, } static inline size_t _compose_ia_pd_opt(dhcpv6_opt_ia_pd_t *ia_pd, - uint32_t ia_id, uint16_t opts_len) + const pfx_lease_t *lease) { - uint16_t len = 12U + opts_len; + uint16_t len = 12; + /* add IA Prefix Option if length was given*/ + if (lease->pfx_len != 0) { + dhcpv6_opt_iapfx_t *iapfx = (dhcpv6_opt_iapfx_t *)ia_pd->opts; + uint16_t iapfx_len = 25; + + /* set all unused/requested fields to 0 */ + memset(iapfx, 0, sizeof(*iapfx)); + + iapfx->type = byteorder_htons(DHCPV6_OPT_IAPFX); + iapfx->len = byteorder_htons(iapfx_len); + iapfx->pfx_len = lease->pfx_len; + + len += iapfx_len + sizeof(dhcpv6_opt_t); + } + + /* write Identity Association for Prefix Delegation Option */ ia_pd->type = byteorder_htons(DHCPV6_OPT_IA_PD); ia_pd->len = byteorder_htons(len); - ia_pd->ia_id = byteorder_htonl(ia_id); + ia_pd->ia_id = byteorder_htonl(lease->parent.ia_id.id); ia_pd->t1.u32 = 0; ia_pd->t2.u32 = 0; + return len + sizeof(dhcpv6_opt_t); } @@ -486,12 +503,15 @@ static inline size_t _add_ia_pd_from_config(uint8_t *buf, size_t len_max) size_t msg_len = 0; for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { - uint32_t ia_id = pfx_leases[i].parent.ia_id.id; - if (ia_id != 0) { - dhcpv6_opt_ia_pd_t *ia_pd = (dhcpv6_opt_ia_pd_t *)(&buf[msg_len]); + pfx_lease_t *lease = &pfx_leases[i]; - msg_len += _compose_ia_pd_opt(ia_pd, ia_id, 0U); + if (lease->parent.ia_id.id == 0) { + continue; } + + /* add Identity Association for Prefix Delegation Option */ + dhcpv6_opt_ia_pd_t *ia_pd = (dhcpv6_opt_ia_pd_t *)(&buf[msg_len]); + msg_len += _compose_ia_pd_opt(ia_pd, lease); } if (msg_len > len_max) {