From 15c8ad2e8ed25cbd33cc58230c148f0bdffbda65 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 19 Aug 2022 12:21:41 +0200 Subject: [PATCH 1/6] sys/net/ipv6: add ipv6_prefix_from_str() --- sys/include/net/ipv6/addr.h | 16 ++++++++++ .../ipv6/addr/ipv6_addr_from_str.c | 29 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/sys/include/net/ipv6/addr.h b/sys/include/net/ipv6/addr.h index 355a04db6b..b1d3ce4af9 100644 --- a/sys/include/net/ipv6/addr.h +++ b/sys/include/net/ipv6/addr.h @@ -737,6 +737,22 @@ char *ipv6_addr_to_str(char *result, const ipv6_addr_t *addr, uint8_t result_len */ ipv6_addr_t *ipv6_addr_from_str(ipv6_addr_t *result, const char *addr); +/** + * @brief Converts an IPv6 prefix string representation to a byte-represented + * IPv6 address + * + * @see + * RFC 5952 + * + * + * @param[out] result The resulting byte representation + * @param[in] prefix An IPv6 prefix string representation + * + * @return prefix length in bits, on success + * @return <0 on error + */ +int ipv6_prefix_from_str(ipv6_addr_t *result, const char *prefix); + /** * @brief Converts an IPv6 address from a buffer of characters to a * byte-represented IPv6 address diff --git a/sys/net/network_layer/ipv6/addr/ipv6_addr_from_str.c b/sys/net/network_layer/ipv6/addr/ipv6_addr_from_str.c index 870879d086..1986cae1f3 100644 --- a/sys/net/network_layer/ipv6/addr/ipv6_addr_from_str.c +++ b/sys/net/network_layer/ipv6/addr/ipv6_addr_from_str.c @@ -26,6 +26,7 @@ * @author Martine Lenders */ +#include #include #include #include @@ -163,6 +164,34 @@ ipv6_addr_t *ipv6_addr_from_str(ipv6_addr_t *result, const char *addr) return ipv6_addr_from_buf(result, addr, strlen(addr)); } +int ipv6_prefix_from_str(ipv6_addr_t *result, const char *addr) +{ + size_t str_len; + int pfx_len; + const char *separator; + + if ((result == NULL) || (addr == NULL)) { + return -EINVAL; + } + + if ((separator = strrchr(addr, '/')) == NULL) { + return -EINVAL; + } + + str_len = separator - addr; + pfx_len = strtol(separator + 1, NULL, 10); + + if (pfx_len <= 0) { + return pfx_len; + } + + if (ipv6_addr_from_buf(result, addr, str_len) == NULL) { + return -EINVAL; + } + + return pfx_len; +} + /** * @} */ From 249901bc9633c949e7e13066e9906e97e7accae4 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 19 Aug 2022 13:52:15 +0200 Subject: [PATCH 2/6] gnrc_static: add static network configuration --- sys/auto_init/auto_init.c | 5 + sys/auto_init/include/auto_init_priorities.h | 6 + sys/include/net/gnrc/ipv6/nib/conf.h | 2 +- sys/net/gnrc/Makefile | 3 + sys/net/gnrc/network_layer/ipv6/Kconfig | 1 + .../network_layer/ipv6/static_addr/Kconfig | 35 +++++ .../network_layer/ipv6/static_addr/Makefile | 3 + .../ipv6/static_addr/gnrc_ipv6_static_addr.c | 148 ++++++++++++++++++ 8 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 sys/net/gnrc/network_layer/ipv6/static_addr/Kconfig create mode 100644 sys/net/gnrc/network_layer/ipv6/static_addr/Makefile create mode 100644 sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 89a10ac866..8986239413 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -327,6 +327,11 @@ extern void auto_init_sock_dns(void); AUTO_INIT(auto_init_sock_dns, AUTO_INIT_PRIO_MOD_DOCK_DNS); #endif +#if IS_USED(MODULE_GNRC_IPV6_STATIC_ADDR) +extern void auto_init_gnrc_ipv6_static_addr(void); +AUTO_INIT(auto_init_gnrc_ipv6_static_addr, + AUTO_INIT_PRIO_MOD_GNRC_IPV6_STATIC_ADDR); +#endif void auto_init(void) { diff --git a/sys/auto_init/include/auto_init_priorities.h b/sys/auto_init/include/auto_init_priorities.h index 773916b2e5..e55578b774 100644 --- a/sys/auto_init/include/auto_init_priorities.h +++ b/sys/auto_init/include/auto_init_priorities.h @@ -353,6 +353,12 @@ extern "C" { */ #define AUTO_INIT_PRIO_MOD_DOCK_DNS 1550 #endif +#ifndef AUTO_INIT_PRIO_MOD_GNRC_IPV6_STATIC_ADDR +/** + * @brief Static network configuration priority + */ +#define AUTO_INIT_PRIO_MOD_GNRC_IPV6_STATIC_ADDR 1560 +#endif #ifdef __cplusplus } diff --git a/sys/include/net/gnrc/ipv6/nib/conf.h b/sys/include/net/gnrc/ipv6/nib/conf.h index 39e91c2ee9..e4c5c133d4 100644 --- a/sys/include/net/gnrc/ipv6/nib/conf.h +++ b/sys/include/net/gnrc/ipv6/nib/conf.h @@ -136,7 +136,7 @@ extern "C" { #if CONFIG_GNRC_IPV6_NIB_ROUTER && \ (!CONFIG_GNRC_IPV6_NIB_6LR || CONFIG_GNRC_IPV6_NIB_6LBR) && \ !(IS_USED(MODULE_DHCPV6_CLIENT_IA_PD) || IS_USED(MODULE_GNRC_UHCPC) || \ - IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS)) + IS_USED(MODULE_GNRC_IPV6_AUTO_SUBNETS) || IS_USED(MODULE_GNRC_IPV6_STATIC_ADDR)) #define CONFIG_GNRC_IPV6_NIB_ADV_ROUTER 1 #else #define CONFIG_GNRC_IPV6_NIB_ADV_ROUTER 0 diff --git a/sys/net/gnrc/Makefile b/sys/net/gnrc/Makefile index 8c4242a83e..941ca66ac7 100644 --- a/sys/net/gnrc/Makefile +++ b/sys/net/gnrc/Makefile @@ -88,6 +88,9 @@ endif ifneq (,$(filter gnrc_rpl_p2p,$(USEMODULE))) DIRS += routing/rpl/p2p endif +ifneq (,$(filter gnrc_ipv6_static_addr,$(USEMODULE))) + DIRS += network_layer/ipv6/static_addr +endif ifneq (,$(filter gnrc_ipv6_auto_subnets,$(USEMODULE))) DIRS += routing/ipv6_auto_subnets endif diff --git a/sys/net/gnrc/network_layer/ipv6/Kconfig b/sys/net/gnrc/network_layer/ipv6/Kconfig index 277dd5b145..d3a5007a4a 100644 --- a/sys/net/gnrc/network_layer/ipv6/Kconfig +++ b/sys/net/gnrc/network_layer/ipv6/Kconfig @@ -28,5 +28,6 @@ rsource "blacklist/Kconfig" rsource "ext/frag/Kconfig" rsource "nib/Kconfig" rsource "whitelist/Kconfig" +rsource "static_addr/Kconfig" endmenu # IPv6 diff --git a/sys/net/gnrc/network_layer/ipv6/static_addr/Kconfig b/sys/net/gnrc/network_layer/ipv6/static_addr/Kconfig new file mode 100644 index 0000000000..450fca1652 --- /dev/null +++ b/sys/net/gnrc/network_layer/ipv6/static_addr/Kconfig @@ -0,0 +1,35 @@ +# Copyright (c) 2022 ML!PA Consulting GmbH +# +# 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_USEMODULE_GNRC_IPV6_STATIC_ADDR + bool "Configure static IPv6 addresses and routes" + depends on USEMODULE_GNRC_IPV6_STATIC_ADDR + help + Configure GNRC IPv6 Whitelisting module using Kconfig. + +if KCONFIG_USEMODULE_GNRC_IPV6_STATIC_ADDR + +config GNRC_IPV6_STATIC_ADDR + string "Static IPv6 address of the upstream interface" + default "2001:db8::100" + +config GNRC_IPV6_STATIC_ADDR_UPSTREAM + int "ID of the upstream interface, use 0 to auto-select wired interface" + default 0 + +config GNRC_IPV6_STATIC_PREFIX + string "Static IPv6 prefix for the downstream network" + default "2001:db8:8000::/48" + +config GNRC_IPV6_STATIC_ADDR_DOWNSTREAM + int "ID of the downstream interface, use 0 to auto-select wireless interface" + default 0 + +config GNRC_IPV6_STATIC_DEFAULT_ROUTER + string "Static IPv6 address of the default router" + default "2001:db8::1" + +endif # KCONFIG_USEMODULE_GNRC_IPV6_STATIC_ADDR diff --git a/sys/net/gnrc/network_layer/ipv6/static_addr/Makefile b/sys/net/gnrc/network_layer/ipv6/static_addr/Makefile new file mode 100644 index 0000000000..8dd83788ac --- /dev/null +++ b/sys/net/gnrc/network_layer/ipv6/static_addr/Makefile @@ -0,0 +1,3 @@ +MODULE = gnrc_ipv6_static_addr + +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c b/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c new file mode 100644 index 0000000000..d4f924dbf8 --- /dev/null +++ b/sys/net/gnrc/network_layer/ipv6/static_addr/gnrc_ipv6_static_addr.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * 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. + */ + +/** + * @{ + * + * @file + * @author Benjamin Valentin + */ + +#include "net/gnrc/ipv6/nib.h" +#include "net/gnrc/ipv6.h" +#include "net/gnrc/netapi.h" +#include "net/gnrc/netif.h" +#include "net/gnrc/rpl.h" +#include "net/ipv6/addr.h" +#include "net/netdev.h" +#include "net/netopt.h" + +#define ENABLE_DEBUG 0 +#include "debug.h" + +/** + * @brief ID of the upstream interface, set to 0 to attempt auto-select + */ +#ifndef CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM +#define CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM 0 +#endif + +/** + * @brief ID of the downstream interface, set to 0 to attempt auto-select + */ +#ifndef CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM +#define CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM 0 +#endif + +static void _config_upstream(gnrc_netif_t *upstream) +{ + ipv6_addr_t addr; + + const char *static_addr = +#ifdef CONFIG_GNRC_IPV6_STATIC_ADDR + CONFIG_GNRC_IPV6_STATIC_ADDR; +#else + NULL; +#endif + + const char *static_route = +#ifdef CONFIG_GNRC_IPV6_STATIC_DEFAULT_ROUTER + CONFIG_GNRC_IPV6_STATIC_DEFAULT_ROUTER; +#else + NULL; +#endif + + DEBUG("gnrc_ipv6_static_addr: interface %u selected as upstream\n", upstream->pid); + + /* configure static address */ + int addr_len; + if (static_addr != NULL && + (addr_len = ipv6_prefix_from_str(&addr, static_addr)) > 0) { + gnrc_netif_ipv6_addr_add_internal(upstream, &addr, addr_len, + GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID); + } + + /* configure static route */ + if (static_route != NULL && + ipv6_addr_from_str(&addr, static_route) != NULL) { + gnrc_ipv6_nib_ft_add(&addr, 0, &addr, upstream->pid, 0); + } +} + +static void _config_downstream(gnrc_netif_t *downstream) +{ + const char *static_prefix = +#ifdef CONFIG_GNRC_IPV6_STATIC_PREFIX + CONFIG_GNRC_IPV6_STATIC_PREFIX; +#else + NULL; +#endif + + DEBUG("gnrc_ipv6_static_addr: interface %u selected as downstream\n", downstream->pid); + + if (CONFIG_GNRC_IPV6_STATIC_PREFIX == NULL) { + return; + } + + ipv6_addr_t prefix; + int len = ipv6_prefix_from_str(&prefix, static_prefix); + if (len <= 0) { + return; + } + + /* configure subnet on downstream interface */ + int idx = gnrc_netif_ipv6_add_prefix(downstream, &prefix, len, + UINT32_MAX, UINT32_MAX); + if (idx < 0) { + DEBUG("gnrc_ipv6_static_addr: adding prefix to %u failed\n", downstream->pid); + return; + } + + /* start advertising subnet */ + gnrc_ipv6_nib_change_rtr_adv_iface(downstream, true); + + /* configure RPL root if applicable */ + if (IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_6LBR)) { + gnrc_rpl_configure_root(downstream, &downstream->ipv6.addrs[idx]); + } +} + +void auto_init_gnrc_ipv6_static_addr(void) +{ + gnrc_netif_t *netif = NULL; + gnrc_netif_t *upstream = NULL; + gnrc_netif_t *downstream = NULL; + + if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM)) { + upstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_UPSTREAM); + } + + if (IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM)) { + downstream = gnrc_netif_get_by_pid(CONFIG_GNRC_IPV6_STATIC_ADDR_DOWNSTREAM); + } + + while ((netif = gnrc_netif_iter(netif))) { + bool is_wired = gnrc_netapi_get(netif->pid, NETOPT_IS_WIRED, 0, NULL, 0) == 1; + + if (!upstream && is_wired) { + upstream = netif; + } else if (!downstream && !is_wired) { + downstream = netif; + } + } + + if (upstream) { + _config_upstream(upstream); + } + + if (downstream) { + _config_downstream(downstream); + } +} + +/** @} */ From 34e9d66261ea7586f9b2a853d335d48d06f1ba39 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 19 Aug 2022 14:04:26 +0200 Subject: [PATCH 3/6] examples/gnrc_border_router: add static network config option --- examples/gnrc_border_router/Makefile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/gnrc_border_router/Makefile b/examples/gnrc_border_router/Makefile index bd73d1c6b2..025a212eab 100644 --- a/examples/gnrc_border_router/Makefile +++ b/examples/gnrc_border_router/Makefile @@ -50,8 +50,8 @@ else endif # Check if the selected method for prefix configuration is valid -ifeq (,$(filter dhcpv6 uhcp auto_subnets,$(PREFIX_CONF))) - $(error Supported methods for prefix configuration are `dhcpv6`, `uhcp` and `auto_subnets`) +ifeq (,$(filter dhcpv6 uhcp auto_subnets static,$(PREFIX_CONF))) + $(error Supported methods for prefix configuration are `dhcpv6`, `uhcp` `static` and `auto_subnets`) endif ifeq (dhcpv6,$(PREFIX_CONF)) @@ -62,6 +62,10 @@ else ifeq (uhcp,$(PREFIX_CONF)) USEMODULE += gnrc_uhcpc else ifeq (auto_subnets,$(PREFIX_CONF)) USEMODULE += gnrc_ipv6_auto_subnets_simple +else ifeq (static,$(PREFIX_CONF)) + IPV6_ADDR ?= 2001:db8:1::1 + IPV6_DEFAULT_ROUTER ?= fe80::1 + USEMODULE += gnrc_ipv6_static_addr endif # Comment this out to disable code in RIOT that does safety checking @@ -126,6 +130,16 @@ ifeq (dhcpv6,$(PREFIX_CONF)) CFLAGS += -DCONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF=3 endif endif +else ifeq (static,$(PREFIX_CONF)) + ifndef CONFIG_GNRC_IPV6_STATIC_ADDR + CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_ADDR=\"$(IPV6_ADDR)\" + endif + ifndef CONFIG_GNRC_IPV6_STATIC_PREFIX + CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_PREFIX=\"$(IPV6_PREFIX)\" + endif + ifndef CONFIG_GNRC_IPV6_STATIC_DEFAULT_ROUTER + CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_DEFAULT_ROUTER=\"$(IPV6_DEFAULT_ROUTER)\" + endif endif From 571026d3944db220e02edce6628e9d854758b81d Mon Sep 17 00:00:00 2001 From: Teufelchen1 Date: Mon, 16 Jan 2023 11:28:30 +0100 Subject: [PATCH 4/6] Revert "sys/pm_layered: pm_(un)block add attribute optimize(3) -shortens hotpath" This reverts commit 5447203921ab39962d7d378a631a6bc048e7f30b. --- sys/pm_layered/pm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sys/pm_layered/pm.c b/sys/pm_layered/pm.c index b7c61b0759..efff800cdf 100644 --- a/sys/pm_layered/pm.c +++ b/sys/pm_layered/pm.c @@ -74,7 +74,6 @@ void pm_set_lowest(void) irq_restore(state); } -__attribute__((optimize(3))) void pm_block(unsigned mode) { DEBUG("[pm_layered] pm_block(%d)\n", mode); @@ -85,7 +84,6 @@ void pm_block(unsigned mode) irq_restore(state); } -__attribute__((optimize(3))) void pm_unblock(unsigned mode) { DEBUG("[pm_layered] pm_unblock(%d)\n", mode); From d912b25bc2d1243a925d1e65e8d2a043f208028a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 16 Jan 2023 12:46:37 +0100 Subject: [PATCH 5/6] CI: update check-labels-action, using missing_approvals_label --- .github/workflows/check-labels.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 027e7e3e80..dffe1066bb 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -1,6 +1,6 @@ name: check-labels on: - pull_request: + pull_request_target: types: [opened, reopened, labeled, unlabeled, synchronize] pull_request_review: types: [submitted, dismissed] @@ -8,8 +8,9 @@ jobs: check-labels: runs-on: ubuntu-latest steps: - - uses: RIOT-OS/check-labels-action@v1.0.0 + - uses: RIOT-OS/check-labels-action@v1.1.0 with: access_token: ${{ secrets.GITHUB_TOKEN }} unset_labels: 'CI: needs squashing,State: waiting for CI update,State: waiting for other PR,Process: blocked by feature freeze' cond_labels: '(Process: needs >1 ACK,review.approvals>1),(Area: RDM,review.approvals>2)' + missing_approvals_label: 'Process: missing approvals' From 1dabd685bd614a3c7679beb14bec4b50e55d53a9 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 16 Jan 2023 13:37:29 +0100 Subject: [PATCH 6/6] CI: temporarily remove `check-labels` from bors `pr_status` --- bors.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bors.toml b/bors.toml index d430328e26..e982df39c2 100644 --- a/bors.toml +++ b/bors.toml @@ -3,7 +3,8 @@ pr_status = [ "python-tests", "tools-build-success", - "check-labels", +# temporarily disabling while testing updated check-labels-action (#19101) +# "check-labels", "static-tests", "check-commits (commit-msg)", "check-commits (pr_check)",