From 0ee46e8d4206084e6eca02c17168d68b92eb2806 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 23 May 2023 17:38:05 +0200 Subject: [PATCH 1/3] core/compiler_hints: add may_be_zero() --- core/lib/include/compiler_hints.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/lib/include/compiler_hints.h b/core/lib/include/compiler_hints.h index d300146fed49..7d3bc8583fd7 100644 --- a/core/lib/include/compiler_hints.h +++ b/core/lib/include/compiler_hints.h @@ -181,6 +181,19 @@ extern "C" { #define assume(cond) assert(cond) #endif +/** + * @brief Wrapper function to silence "comparison is always false due to limited + * range of data type" type of warning when the warning is caused by a + * preprocessor configuration value that may be zero. + * + * @param[in] n Variable that may be zero + * @return The same variable @p n + */ +static inline unsigned may_be_zero(unsigned n) +{ + return n; +} + #ifdef __cplusplus } #endif From 9358a4430d07d5b7eb93f29fc85a001d6eea2eeb Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 23 May 2023 16:48:17 +0200 Subject: [PATCH 2/3] gnrc/ipv6_auto_subnets: remove superfluous newline --- sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c b/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c index 9de3b37ed9bc..b0b9e0cd046f 100644 --- a/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c +++ b/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c @@ -1,4 +1,3 @@ - /* * Copyright (C) 2021 ML!PA Consulting GmbH * From 2a7691176b67ea63574bc51d69a5847eb7191be5 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 22 May 2023 13:52:29 +0200 Subject: [PATCH 3/3] gnrc/ipv6_auto_subnets: allow to configure minimal prefix length --- .../ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c b/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c index b0b9e0cd046f..75b367910c7b 100644 --- a/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c +++ b/sys/net/gnrc/routing/ipv6_auto_subnets/gnrc_ipv6_auto_subnets.c @@ -89,6 +89,7 @@ * @author Benjamin Valentin */ +#include "compiler_hints.h" #include "net/gnrc/ipv6.h" #include "net/gnrc/netif.h" #include "net/gnrc/netif/hdr.h" @@ -141,6 +142,14 @@ #define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_FIX_LEN (0) #endif +/** + * @brief Minimal length of a new prefix. + * e.g. Linux will only accept /64 prefixes for SLAAC + */ +#ifndef CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN +#define CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN (0) +#endif + /** * @brief Number of subnets that can be configured. * @@ -369,6 +378,10 @@ static void _configure_subnets(uint8_t subnets, uint8_t start_idx, gnrc_netif_t return; } + if (new_prefix_len < may_be_zero(CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN)) { + new_prefix_len = CONFIG_GNRC_IPV6_AUTO_SUBNETS_PREFIX_MIN_LEN; + } + while ((downstream = gnrc_netif_iter(downstream))) { gnrc_pktsnip_t *tmp; ipv6_addr_t new_prefix;