diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index d691cb512e..89b8528d25 100644 --- a/examples/gnrc_border_router/Makefile.native.conf +++ b/examples/gnrc_border_router/Makefile.native.conf @@ -4,9 +4,11 @@ ZEP_PORT_BASE ?= 17754 ZEP_PORT_MAX := $(shell expr $(ZEP_PORT_BASE) + $(ZEP_DEVICES) - 1) CFLAGS += -DSOCKET_ZEP_MAX=$(ZEP_DEVICES) -CFLAGS += -DDHCPV6_CLIENT_PFX_LEASE_MAX=$(ZEP_DEVICES) CFLAGS += -DASYNC_READ_NUMOF=$(shell expr $(ZEP_DEVICES) + 1) +# Set CFLAGS if not being set via Kconfig +CFLAGS += $(if $(CONFIG_KCONFIG_MODULE_DHCPV6),,-DCONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX=$(ZEP_DEVICES)) + # -z [::1]:$PORT for each ZEP device TERMFLAGS += $(patsubst %,-z [::1]:%, $(shell seq $(ZEP_PORT_BASE) $(ZEP_PORT_MAX))) diff --git a/sys/include/net/dhcpv6/client.h b/sys/include/net/dhcpv6/client.h index 41a7686aa8..f61bedcb50 100644 --- a/sys/include/net/dhcpv6/client.h +++ b/sys/include/net/dhcpv6/client.h @@ -46,12 +46,19 @@ extern "C" { */ #define DHCPV6_CLIENT_DUID_LEN (sizeof(dhcpv6_duid_l2_t) + 8U) #define DHCPV6_CLIENT_BUFLEN (256) /**< length for send and receive buffer */ -#ifndef DHCPV6_CLIENT_SERVER_MAX -#define DHCPV6_CLIENT_SERVER_MAX (1U) /**< maximum number of servers to store */ -#endif -#ifndef DHCPV6_CLIENT_PFX_LEASE_MAX -#define DHCPV6_CLIENT_PFX_LEASE_MAX (1U) /**< maximum number of prefix leases to store */ + +/** + * @defgroup net_dhcpv6_conf DHCPv6 client compile configurations + * @ingroup config + * @{ + */ +/** + * @brief Maximum number of prefix leases to be stored + */ +#ifndef CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX +#define CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX (1U) #endif +/** @} */ /** * @name DHCPv6 unique identifier (DUID) definitions diff --git a/sys/net/application_layer/Kconfig b/sys/net/application_layer/Kconfig index 39779d9e73..b3d1dda5f7 100644 --- a/sys/net/application_layer/Kconfig +++ b/sys/net/application_layer/Kconfig @@ -13,3 +13,5 @@ rsource "gcoap/Kconfig" rsource "nanocoap/Kconfig" endmenu # CoAP + +rsource "dhcpv6/Kconfig" diff --git a/sys/net/application_layer/dhcpv6/Kconfig b/sys/net/application_layer/dhcpv6/Kconfig new file mode 100644 index 0000000000..5edf2ccd3f --- /dev/null +++ b/sys/net/application_layer/dhcpv6/Kconfig @@ -0,0 +1,19 @@ +# Copyright (c) 2020 Freie Universitaet Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# +menuconfig KCONFIG_MODULE_DHCPV6 + bool "Configure DHCPv6" + depends on MODULE_DHCPV6 + help + Configure DHCPv6 client using Kconfig. + +if KCONFIG_MODULE_DHCPV6 + +config DHCPV6_CLIENT_PFX_LEASE_MAX + int "Maximum number of prefix leases to be stored" + default 1 + +endif # KCONFIG_MODULE_DHCPv6 diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index 04c3d9440e..3f4161fb20 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -68,7 +68,7 @@ static uint8_t send_buf[DHCPV6_CLIENT_BUFLEN]; static uint8_t recv_buf[DHCPV6_CLIENT_BUFLEN]; static uint8_t best_adv[DHCPV6_CLIENT_BUFLEN]; static uint8_t duid[DHCPV6_CLIENT_DUID_LEN]; -static pfx_lease_t pfx_leases[DHCPV6_CLIENT_PFX_LEASE_MAX]; +static pfx_lease_t pfx_leases[CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX]; static server_t server; static xtimer_t timer, rebind_timer; static event_queue_t *event_queue; @@ -149,7 +149,7 @@ void dhcpv6_client_req_ia_pd(unsigned netif, unsigned pfx_len) pfx_lease_t *lease = NULL; assert(pfx_len <= 128); - for (unsigned i = 0; i < DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + 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]; lease->parent.ia_id.info.netif = netif; @@ -276,7 +276,7 @@ static inline size_t _add_ia_pd_from_config(uint8_t *buf) { size_t msg_len = 0; - for (unsigned i = 0; i < DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + 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]); @@ -489,7 +489,7 @@ 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 < DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + for (unsigned i = 0; 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); @@ -602,7 +602,7 @@ static bool _parse_reply(uint8_t *rep, 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 < DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + for (unsigned i = 0; 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; @@ -777,7 +777,7 @@ 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 < DHCPV6_CLIENT_PFX_LEASE_MAX; i++) { + for (unsigned i = 0; 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,