From e45157021924c6e71af3f72b823afe3ce39b1fbc Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Thu, 19 Dec 2019 19:32:26 +0100 Subject: [PATCH] gnrc_netif: remove GNRC_NETIF_NUMOF macro --- Makefile.include | 7 ------- dist/tools/ethos/README.md | 1 - examples/gcoap/Makefile.slip | 1 - examples/gnrc_border_router/Makefile | 3 --- examples/gnrc_border_router/README.md | 1 - examples/suit_update/Makefile | 1 - sys/include/net/gnrc/netif.h | 2 +- sys/include/net/gnrc/netif/conf.h | 10 ---------- sys/include/net/gnrc/rpl.h | 11 ++++++----- sys/include/net/sock/dtls.h | 4 ++-- sys/net/gnrc/netif/gnrc_netif.c | 18 +++++------------- .../gnrc/netif/init_devs/auto_init_at86rf215.c | 7 ------- sys/shell/commands/sc_gnrc_icmpv6_echo.c | 2 +- tests/driver_at86rf215/Makefile | 1 - tests/gnrc_dhcpv6_client_6lbr/Makefile | 1 - tests/gnrc_ipv6_ext_frag/Makefile | 1 - tests/gnrc_netif/Makefile | 1 - tests/gnrc_netif/common.c | 4 ++-- tests/gnrc_netif/common.h | 3 ++- tests/riotboot_flashwrite/Makefile | 2 -- tests/usbus_cdc_ecm/Makefile | 3 --- 21 files changed, 19 insertions(+), 65 deletions(-) diff --git a/Makefile.include b/Makefile.include index 0a3f9c6f76..958a53a7c5 100644 --- a/Makefile.include +++ b/Makefile.include @@ -353,13 +353,6 @@ include $(RIOTMAKE)/toolchain/$(TOOLCHAIN).inc.mk # For more information, see http://petereisentraut.blogspot.com/2011/09/ccache-and-clang-part-2.html export CCACHE_CPP2=yes -# get number of interfaces straight before resolving dependencies -GNRC_NETIF_NUMOF ?= 1 - -ifneq ($(GNRC_NETIF_NUMOF),1) - CFLAGS += -DGNRC_NETIF_NUMOF=$(GNRC_NETIF_NUMOF) -endif - # handle removal of default modules USEMODULE += $(filter-out $(DISABLE_MODULE), $(DEFAULT_MODULE)) diff --git a/dist/tools/ethos/README.md b/dist/tools/ethos/README.md index 6e75737f5f..59ed4aad64 100644 --- a/dist/tools/ethos/README.md +++ b/dist/tools/ethos/README.md @@ -7,7 +7,6 @@ To use, add # - GNRC_NETIF_NUMOF := 2 USEMODULE += stdio_ethos gnrc_netdev CFLAGS += '-DETHOS_UART=UART_DEV(0)' -DETHOS_BAUDRATE=115200 diff --git a/examples/gcoap/Makefile.slip b/examples/gcoap/Makefile.slip index 77d3cbf751..cbe25e8bd8 100644 --- a/examples/gcoap/Makefile.slip +++ b/examples/gcoap/Makefile.slip @@ -28,7 +28,6 @@ ifeq (,$(SLIP_BAUDRATE)) SLIP_BAUDRATE=115200 endif -GNRC_NETIF_NUMOF := 2 CFLAGS += -DSLIPDEV_PARAM_UART=$(SLIP_UART) CFLAGS += -DSLIPDEV_PARAM_BAUDRATE=$(SLIP_BAUDRATE) diff --git a/examples/gnrc_border_router/Makefile b/examples/gnrc_border_router/Makefile index 2048d61c6e..d7730bdcc4 100644 --- a/examples/gnrc_border_router/Makefile +++ b/examples/gnrc_border_router/Makefile @@ -51,9 +51,6 @@ else USEMODULE += gnrc_uhcpc endif -# Use two network interfaces -GNRC_NETIF_NUMOF := 2 - # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the # development process: diff --git a/examples/gnrc_border_router/README.md b/examples/gnrc_border_router/README.md index 354fb2ae3c..9403554865 100644 --- a/examples/gnrc_border_router/README.md +++ b/examples/gnrc_border_router/README.md @@ -152,7 +152,6 @@ has the following: ```make ifeq (,$(filter native,$(BOARD))) -GNRC_NETIF_NUMOF := 2 USEMODULE += stdio_ethos CFLAGS += '-DETHOS_UART=UART_DEV(0)' -DETHOS_BAUDRATE=115200 FEATURES_REQUIRED += periph_uart diff --git a/examples/suit_update/Makefile b/examples/suit_update/Makefile index a7e9dc67bb..ae154785bd 100644 --- a/examples/suit_update/Makefile +++ b/examples/suit_update/Makefile @@ -59,7 +59,6 @@ CFLAGS += -DSUIT_MANIFEST_RESOURCE=\"$(SUIT_COAP_ROOT)/$(SUIT_NOTIFY_MANIFEST)\" USE_ETHOS ?= 1 ifeq (1,$(USE_ETHOS)) - GNRC_NETIF_NUMOF := 2 USEMODULE += stdio_ethos USEMODULE += gnrc_uhcpc diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h index 7a0f47fd98..ac31a51710 100644 --- a/sys/include/net/gnrc/netif.h +++ b/sys/include/net/gnrc/netif.h @@ -284,7 +284,7 @@ unsigned gnrc_netif_numof(void); */ static inline bool gnrc_netif_highlander(void) { - return (GNRC_NETIF_NUMOF == 1); + return IS_ACTIVE(GNRC_NETIF_SINGLE); } /** diff --git a/sys/include/net/gnrc/netif/conf.h b/sys/include/net/gnrc/netif/conf.h index c891ff0014..916f823501 100644 --- a/sys/include/net/gnrc/netif/conf.h +++ b/sys/include/net/gnrc/netif/conf.h @@ -29,16 +29,6 @@ extern "C" { #endif -/** - * @brief Maximum number of network interfaces - * - * @note Intentionally not calling it `GNRC_NETIF_NUMOF` to not require - * rewrites throughout the stack. - */ -#ifndef GNRC_NETIF_NUMOF -#define GNRC_NETIF_NUMOF (1) -#endif - /** * @brief Default priority for network interface threads */ diff --git a/sys/include/net/gnrc/rpl.h b/sys/include/net/gnrc/rpl.h index 380393f13d..5210cf020a 100644 --- a/sys/include/net/gnrc/rpl.h +++ b/sys/include/net/gnrc/rpl.h @@ -32,11 +32,12 @@ * Auto-Initialization * ------------------- * - * If the application defines only one interface (`GNRC_NETIF_NUMOF == 1`), - * then RPL will be initialized on this interface. + * If the application defines only one interface (@ref gnrc_netif_highlander() + * returns true), then RPL will be initialized on this interface. * - * If the application defines several interfaces (`GNRC_NETIF_NUMOF > 1`), - * then RPL will be initialized on the interface `GNRC_RPL_DEFAULT_NETIF`. + * If the application defines several interfaces (@ref gnrc_netif_highlander() + * returns false), then RPL will be initialized on the interface + * `GNRC_RPL_DEFAULT_NETIF`. * Your application is responsible for setting `GNRC_RPL_DEFAULT_NETIF` to a * valid interface PID, e.g. via `CFLAGS`. * @@ -69,7 +70,7 @@ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * - Set interface for auto-initialization if more than one - * interface exists (`GNRC_NETIF_NUMOF > 1`) + * interface exists (@ref gnrc_netif_highlander() returns false) * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk} * CFLAGS += -DGNRC_RPL_DEFAULT_NETIF=6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/sys/include/net/sock/dtls.h b/sys/include/net/sock/dtls.h index 9f4136aefc..54b098d1df 100644 --- a/sys/include/net/sock/dtls.h +++ b/sys/include/net/sock/dtls.h @@ -314,7 +314,7 @@ * * sock_udp_ep_t remote; * remote.port = DTLS_DEFAULT_PORT; - * remote.netif = gnrc_netif_iter(NULL)->pid; // only if GNRC_NETIF_NUMOF == 1 + * remote.netif = gnrc_netif_iter(NULL)->pid; // only if gnrc_netif_highlander() returns true * * sock_dtls_t dtls_sock; * sock_dtls_session_t session; @@ -380,7 +380,7 @@ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.c} * sock_udp_ep_t remote; * remote.port = DTLS_DEFAULT_PORT; - * remote.netif = gnrc_netif_iter(NULL)->pid; // only if GNRC_NETIF_NUMOF == 1 + * remote.netif = gnrc_netif_iter(NULL)->pid; // only if gnrc_netif_highlander() returns true * * if (!ipv6_addr_from_str((ipv6_addr_t *)remote.addr.ipv6, SERVER_ADDR)) { * puts("Error parsing destination address"); diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 186edc45ed..7b972a9027 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -39,29 +39,21 @@ #define ENABLE_DEBUG (0) #include "debug.h" -static gnrc_netif_t _netifs[GNRC_NETIF_NUMOF]; - static void _update_l2addr_from_dev(gnrc_netif_t *netif); static void _configure_netdev(netdev_t *dev); static void *_gnrc_netif_thread(void *args); static void _event_cb(netdev_t *dev, netdev_event_t event); int gnrc_netif_create(gnrc_netif_t *netif, char *stack, int stacksize, char priority, - const char *name, netdev_t *netdev, - const gnrc_netif_ops_t *ops) + const char *name, netdev_t *netdev, const gnrc_netif_ops_t *ops) { - gnrc_netif_t *netif = NULL; int res; - for (int i = 0; i < GNRC_NETIF_NUMOF; i++) { - if (_netifs[i].dev == netdev) { - return &_netifs[i]; - } - if ((netif == NULL) && (_netifs[i].ops == NULL)) { - netif = &_netifs[i]; - } + if (IS_ACTIVE(DEVELHELP) && IS_ACTIVE(GNRC_NETIF_SINGLE) && netif_iter(NULL)) { + LOG_WARNING("gnrc_netif: GNRC_NETIF_SINGLE set but more than one " + "interface is being registered."); + assert(netif_iter(NULL) == NULL); } - assert(netif != NULL); rmutex_init(&netif->mutex); netif->ops = ops; netif_register((netif_t*) netif); diff --git a/sys/net/gnrc/netif/init_devs/auto_init_at86rf215.c b/sys/net/gnrc/netif/init_devs/auto_init_at86rf215.c index ea606e46d5..2acb0fd36e 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_at86rf215.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_at86rf215.c @@ -35,13 +35,6 @@ #include "at86rf215.h" #include "at86rf215_params.h" -/* If we don't have enough NETIFs configured, disable the sub-GHz band */ -#if (GNRC_NETIF_NUMOF == 1) && IS_USED(MODULE_AT86RF215_SUBGHZ) && IS_USED(MODULE_AT86RF215_24GHZ) -#undef MODULE_AT86RF215_SUBGHZ -#undef USED_BANDS -#define USED_BANDS 1 -#endif - /** * @brief Define stack parameters for the MAC layer thread * @{ diff --git a/sys/shell/commands/sc_gnrc_icmpv6_echo.c b/sys/shell/commands/sc_gnrc_icmpv6_echo.c index 2b679cb30a..9dddcc8abe 100644 --- a/sys/shell/commands/sc_gnrc_icmpv6_echo.c +++ b/sys/shell/commands/sc_gnrc_icmpv6_echo.c @@ -371,7 +371,7 @@ static void _print_reply(_ping_data_t *data, gnrc_pktsnip_t *icmpv6, data->num_recv++; dupmsg += 7; } - if ((GNRC_NETIF_NUMOF == 1) || (if_pid == KERNEL_PID_UNDEF) || + if (gnrc_netif_highlander() || (if_pid == KERNEL_PID_UNDEF) || !ipv6_addr_is_link_local(from)) { printf("%u bytes from %s: icmp_seq=%u ttl=%u", (unsigned)icmpv6->size, diff --git a/tests/driver_at86rf215/Makefile b/tests/driver_at86rf215/Makefile index 9fd605967f..b6dd4a1296 100644 --- a/tests/driver_at86rf215/Makefile +++ b/tests/driver_at86rf215/Makefile @@ -8,7 +8,6 @@ USEMODULE += ps # the radio driver to test USEMODULE += at86rf215 -GNRC_NETIF_NUMOF ?= 2 # gnrc is a meta module including all required, basic gnrc networking modules USEMODULE += gnrc diff --git a/tests/gnrc_dhcpv6_client_6lbr/Makefile b/tests/gnrc_dhcpv6_client_6lbr/Makefile index 486152ac1c..5c9b83b5da 100644 --- a/tests/gnrc_dhcpv6_client_6lbr/Makefile +++ b/tests/gnrc_dhcpv6_client_6lbr/Makefile @@ -2,7 +2,6 @@ DEVELHELP := 1 include $(CURDIR)/../Makefile.tests_common export TAP ?= tap0 -GNRC_NETIF_NUMOF := 2 USEMODULE += auto_init_gnrc_netif USEMODULE += gnrc_dhcpv6_client_6lbr diff --git a/tests/gnrc_ipv6_ext_frag/Makefile b/tests/gnrc_ipv6_ext_frag/Makefile index a691e1a017..1341557502 100644 --- a/tests/gnrc_ipv6_ext_frag/Makefile +++ b/tests/gnrc_ipv6_ext_frag/Makefile @@ -19,7 +19,6 @@ endif USEMODULE += auto_init_gnrc_netif # add dummy interface to test forwarding to smaller MTU USEMODULE += netdev_test -GNRC_NETIF_NUMOF := 2 # Specify the mandatory networking modules for IPv6 USEMODULE += gnrc_ipv6_router_default USEMODULE += gnrc_icmpv6_error diff --git a/tests/gnrc_netif/Makefile b/tests/gnrc_netif/Makefile index 676703a9c8..061bf00c2d 100644 --- a/tests/gnrc_netif/Makefile +++ b/tests/gnrc_netif/Makefile @@ -15,7 +15,6 @@ USEMODULE += od CFLAGS += -DGNRC_IPV6_NIB_CONF_ARSM=0 CFLAGS += -DGNRC_IPV6_NIB_CONF_SLAAC=0 CFLAGS += -DGNRC_IPV6_NIB_CONF_NO_RTR_SOL=1 -CFLAGS += -DGNRC_NETIF_NUMOF=4 CFLAGS += -DGNRC_NETIF_ADDRS_NUMOF=16 CFLAGS += -DGNRC_NETIF_GROUPS_NUMOF=8 CFLAGS += -DLOG_LEVEL=LOG_NONE diff --git a/tests/gnrc_netif/common.c b/tests/gnrc_netif/common.c index a19a7b8b21..04a3b1f757 100644 --- a/tests/gnrc_netif/common.c +++ b/tests/gnrc_netif/common.c @@ -25,7 +25,7 @@ #include "od.h" #include "test_utils/expect.h" -static netdev_test_t _devs[GNRC_NETIF_NUMOF]; +static netdev_test_t _devs[NETIF_NUMOF]; netdev_t *ethernet_dev = (netdev_t *)&_devs[0]; netdev_t *ieee802154_dev = (netdev_t *)&_devs[1]; @@ -179,7 +179,7 @@ void _tests_init(void) _get_netdev_proto); netdev_test_set_get_cb((netdev_test_t *)ieee802154_dev, NETOPT_MAX_PDU_SIZE, _get_netdev_max_packet_size); - for (intptr_t i = SPECIAL_DEVS; i < GNRC_NETIF_NUMOF; i++) { + for (intptr_t i = SPECIAL_DEVS; i < NETIF_NUMOF; i++) { devs[i - SPECIAL_DEVS] = (netdev_t *)&_devs[i]; netdev_test_setup(&_devs[i], (void *)i); netdev_test_set_get_cb(&_devs[i], NETOPT_DEVICE_TYPE, diff --git a/tests/gnrc_netif/common.h b/tests/gnrc_netif/common.h index 9791776d03..34ac806aad 100644 --- a/tests/gnrc_netif/common.h +++ b/tests/gnrc_netif/common.h @@ -26,8 +26,9 @@ extern "C" { #endif +#define NETIF_NUMOF (4) #define SPECIAL_DEVS (2) -#define DEFAULT_DEVS_NUMOF (GNRC_NETIF_NUMOF - SPECIAL_DEVS) +#define DEFAULT_DEVS_NUMOF (NETIF_NUMOF - SPECIAL_DEVS) #define GP1 (0x20U) #define GP2 (0x01U) diff --git a/tests/riotboot_flashwrite/Makefile b/tests/riotboot_flashwrite/Makefile index b1fa10fe5e..ff7320d29f 100644 --- a/tests/riotboot_flashwrite/Makefile +++ b/tests/riotboot_flashwrite/Makefile @@ -28,8 +28,6 @@ USEMODULE += shell_commands # boards LOW_MEMORY_BOARDS := nucleo-f334r8 -GNRC_NETIF_NUMOF := 2 - # uncomment these to use ethos #USEMODULE += stdio_ethos gnrc_uhcpc # diff --git a/tests/usbus_cdc_ecm/Makefile b/tests/usbus_cdc_ecm/Makefile index cde5ee63c8..2f5ab03d1e 100644 --- a/tests/usbus_cdc_ecm/Makefile +++ b/tests/usbus_cdc_ecm/Makefile @@ -9,9 +9,6 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -# Increase the number of network interfaces in case the board under test also provides a network interface -CFLAGS += -DGNRC_NETIF_NUMOF=2 - # USB device vendor and product ID # pid.codes test VID/PID, not globally unique DEFAULT_VID = 1209