diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 9994f5edf7..22d23e6dcd 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -25,6 +25,7 @@ PSEUDOMODULES += dbgpin PSEUDOMODULES += devfs_% PSEUDOMODULES += dhcpv6_% PSEUDOMODULES += dhcpv6_client_dns +PSEUDOMODULES += dhcpv6_client_ia_pd PSEUDOMODULES += dhcpv6_client_mud_url PSEUDOMODULES += ecc_% PSEUDOMODULES += event_% diff --git a/sys/include/net/dhcpv6/client.h b/sys/include/net/dhcpv6/client.h index 9d00eb2679..958da1bf77 100644 --- a/sys/include/net/dhcpv6/client.h +++ b/sys/include/net/dhcpv6/client.h @@ -122,8 +122,13 @@ void dhcpv6_client_start(void); * @brief Configures the client to request prefix delegation for a network * interface from a server * + * @pre Module `dhcpv6_client_ia_pd` is compiled in. * @pre `pfx_len <= 128` * + * Without module `dhcpv6_client_ia_pd` and `NDEBUG` set this function is a NOP. + * Without module `dhcpv6_client_ia_pd` and `NDEBUG` unset this function will + * abort the running code on a failed assertion. + * * @param[in] netif The interface to request the prefix delegation for. * @param[in] pfx_len The desired length of the prefix (note that the server * might not consider this request). Must be <= 128 diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index d4e0bbb612..f5890cb32e 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -17,6 +17,7 @@ #include #include "event.h" +#include "log.h" #include "kernel_defines.h" #include "net/dhcpv6/client.h" #include "net/dhcpv6.h" @@ -155,7 +156,13 @@ void dhcpv6_client_req_ia_pd(unsigned netif, unsigned pfx_len) { pfx_lease_t *lease = NULL; + assert(IS_USED(MODULE_DHCPV6_CLIENT_IA_PD)); assert(pfx_len <= 128); + if (!IS_USED(MODULE_DHCPV6_CLIENT_IA_PD)) { + LOG_WARNING("DHCPv6 client: Unable to request IA_PD as module " + "`dhcpv6_client_ia_pd` is not used\n"); + return; + } for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { if (pfx_leases[i].parent.ia_id.id == 0) { lease = &pfx_leases[i]; @@ -300,6 +307,10 @@ static inline size_t _compose_ia_pd_opt(dhcpv6_opt_ia_pd_t *ia_pd, static inline size_t _add_ia_pd_from_config(uint8_t *buf, size_t len_max) { + if (!IS_USED(MODULE_DHCPV6_CLIENT_IA_PD)) { + return 0; + } + size_t msg_len = 0; for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { @@ -445,7 +456,9 @@ static int _preparse_advertise(uint8_t *adv, size_t len, uint8_t **buf) status = (dhcpv6_opt_status_t *)opt; break; case DHCPV6_OPT_IA_PD: - ia_pd = (dhcpv6_opt_ia_pd_t *)opt; + if (IS_USED(MODULE_DHCPV6_CLIENT_IA_PD)) { + ia_pd = (dhcpv6_opt_ia_pd_t *)opt; + } break; case DHCPV6_OPT_PREF: pref = (dhcpv6_opt_pref_t *)opt; @@ -454,7 +467,8 @@ static int _preparse_advertise(uint8_t *adv, size_t len, uint8_t **buf) break; } } - if ((cid == NULL) || (sid == NULL) || (ia_pd == NULL)) { + if ((cid == NULL) || (sid == NULL) || + (IS_USED(MODULE_DHCPV6_CLIENT_IA_PD) && (ia_pd == NULL))) { DEBUG("DHCPv6 client: ADVERTISE does not contain either server ID, " "client ID or IA_PD option\n"); return -1; @@ -524,7 +538,10 @@ static void _parse_advertise(uint8_t *adv, size_t len) len > 0; len -= _opt_len(opt), opt = _opt_next(opt)) { switch (byteorder_ntohs(opt->type)) { case DHCPV6_OPT_IA_PD: - for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + for (unsigned i = 0; + IS_USED(MODULE_DHCPV6_CLIENT_IA_PD) && + (i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX); + i++) { dhcpv6_opt_ia_pd_t *ia_pd = (dhcpv6_opt_ia_pd_t *)opt; unsigned pd_t1, pd_t2; uint32_t ia_id = byteorder_ntohl(ia_pd->ia_id); @@ -609,7 +626,9 @@ static bool _parse_reply(uint8_t *rep, size_t len) status = (dhcpv6_opt_status_t *)opt; break; case DHCPV6_OPT_IA_PD: - ia_pd = (dhcpv6_opt_ia_pd_t *)opt; + if (IS_USED(MODULE_DHCPV6_CLIENT_IA_PD)) { + ia_pd = (dhcpv6_opt_ia_pd_t *)opt; + } break; case DHCPV6_OPT_SMR: smr = (dhcpv6_opt_smr_t *)opt; @@ -618,7 +637,8 @@ static bool _parse_reply(uint8_t *rep, size_t len) break; } } - if ((cid == NULL) || (sid == NULL) || (ia_pd == NULL)) { + if ((cid == NULL) || (sid == NULL) || + (IS_USED(MODULE_DHCPV6_CLIENT_IA_PD) && (ia_pd == NULL))) { DEBUG("DHCPv6 client: ADVERTISE does not contain either server ID, " "client ID or IA_PD option\n"); return false; @@ -643,7 +663,10 @@ static bool _parse_reply(uint8_t *rep, size_t len) break; #endif /* IS_USED(MODULE_DHCPV6_CLIENT_DNS) */ case DHCPV6_OPT_IA_PD: - for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + for (unsigned i = 0; + IS_USED(MODULE_DHCPV6_CLIENT_IA_PD) && + (i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX); + i++) { dhcpv6_opt_iapfx_t *iapfx = NULL; pfx_lease_t *lease = &pfx_leases[i]; ia_pd = (dhcpv6_opt_ia_pd_t *)opt; @@ -818,7 +841,10 @@ static void _request_renew_rebind(uint8_t type) irt = DHCPV6_REB_TIMEOUT; mrt = DHCPV6_REB_MAX_RT; /* calculate MRD from prefix leases */ - for (unsigned i = 0; i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + for (unsigned i = 0; + IS_USED(MODULE_DHCPV6_CLIENT_IA_PD) && + (i < CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX); + i++) { const pfx_lease_t *lease = &pfx_leases[i]; uint32_t valid_until = dhcpv6_client_prefix_valid_until( lease->parent.ia_id.info.netif, diff --git a/sys/net/gnrc/Makefile.dep b/sys/net/gnrc/Makefile.dep index 965adcc389..0ec70ba6d9 100644 --- a/sys/net/gnrc/Makefile.dep +++ b/sys/net/gnrc/Makefile.dep @@ -57,6 +57,7 @@ endif ifneq (,$(filter gnrc_dhcpv6_client_simple_pd,$(USEMODULE))) USEMODULE += gnrc_dhcpv6_client + USEMODULE += dhcpv6_client_ia_pd endif ifneq (,$(filter gnrc_uhcpc,$(USEMODULE))) diff --git a/tests/gnrc_dhcpv6_client/Makefile b/tests/gnrc_dhcpv6_client/Makefile index e02d2f5552..e3eb7c0a42 100644 --- a/tests/gnrc_dhcpv6_client/Makefile +++ b/tests/gnrc_dhcpv6_client/Makefile @@ -8,6 +8,7 @@ RIOTBASE ?= $(CURDIR)/../.. # boards don't support ethos BOARD_BLACKLIST += mips-malta pic32-wifire pic32-clicker ruuvitag thingy52 +USEMODULE += dhcpv6_client_ia_pd USEMODULE += gnrc_dhcpv6_client USEMODULE += gnrc_ipv6_default USEMODULE += xtimer