From 1c37e11c0e755b8e1fae21b242929e31b499de0a Mon Sep 17 00:00:00 2001 From: Akshai M Date: Thu, 23 Jul 2020 21:00:22 +0530 Subject: [PATCH 1/4] net/dhcpv6 : Move 'DHCPV6_CLIENT_PFX_LEASE_MAX' to 'CONFIG_' --- examples/gnrc_border_router/Makefile.native.conf | 2 +- sys/include/net/dhcpv6/client.h | 5 +++-- sys/net/application_layer/dhcpv6/client.c | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index d691cb512e..ddf15a214d 100644 --- a/examples/gnrc_border_router/Makefile.native.conf +++ b/examples/gnrc_border_router/Makefile.native.conf @@ -4,7 +4,7 @@ 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 += -DCONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX=$(ZEP_DEVICES) CFLAGS += -DASYNC_READ_NUMOF=$(shell expr $(ZEP_DEVICES) + 1) # -z [::1]:$PORT for each ZEP device diff --git a/sys/include/net/dhcpv6/client.h b/sys/include/net/dhcpv6/client.h index 41a7686aa8..6d0b90103e 100644 --- a/sys/include/net/dhcpv6/client.h +++ b/sys/include/net/dhcpv6/client.h @@ -49,8 +49,9 @@ extern "C" { #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 */ + +#ifndef CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX +#define CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX (1U) /**< maximum number of prefix leases to store */ #endif /** 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, From 0413a5881f458040804e6986e88bee795fd111e2 Mon Sep 17 00:00:00 2001 From: Akshai M Date: Thu, 23 Jul 2020 21:00:57 +0530 Subject: [PATCH 2/4] net/dhcpv6 : Expose to Kconfig Expose configurations to Kconfig. Add conditional CFLAGS to avoid conflicts with Kconfig. --- .../gnrc_border_router/Makefile.native.conf | 4 +++- sys/net/application_layer/Kconfig | 2 ++ sys/net/application_layer/dhcpv6/Kconfig | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 sys/net/application_layer/dhcpv6/Kconfig diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index ddf15a214d..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 += -DCONFIG_DHCPV6_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/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 From 6be63000759eb88f00e373194e826973590cc27a Mon Sep 17 00:00:00 2001 From: Akshai M Date: Thu, 23 Jul 2020 21:07:02 +0530 Subject: [PATCH 3/4] net/dhcpv6 : Update documentation Add configuration 'CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX' to configuration group --- sys/include/net/dhcpv6/client.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/include/net/dhcpv6/client.h b/sys/include/net/dhcpv6/client.h index 6d0b90103e..68c71aa296 100644 --- a/sys/include/net/dhcpv6/client.h +++ b/sys/include/net/dhcpv6/client.h @@ -50,9 +50,18 @@ extern "C" { #define DHCPV6_CLIENT_SERVER_MAX (1U) /**< maximum number of servers to store */ #endif +/** + * @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) /**< maximum number of prefix leases to store */ +#define CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX (1U) #endif +/** @} */ /** * @name DHCPv6 unique identifier (DUID) definitions From a9e0a110d7c7e0131f6d214c81f416a9907b27dd Mon Sep 17 00:00:00 2001 From: Akshai M Date: Tue, 28 Jul 2020 15:02:48 +0530 Subject: [PATCH 4/4] net/dhcpv6 : Remove unused macro Remove unused macro 'DHCPV6_CLIENT_SERVER_MAX' --- sys/include/net/dhcpv6/client.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/sys/include/net/dhcpv6/client.h b/sys/include/net/dhcpv6/client.h index 68c71aa296..f61bedcb50 100644 --- a/sys/include/net/dhcpv6/client.h +++ b/sys/include/net/dhcpv6/client.h @@ -46,9 +46,6 @@ 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 /** * @defgroup net_dhcpv6_conf DHCPv6 client compile configurations