Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc/ipv6_auto_subnets: allow to configure minimal prefix length #19656

Merged
merged 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/lib/include/compiler_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
Expand Down Expand Up @@ -90,6 +89,7 @@
* @author Benjamin Valentin <[email protected]>
*/

#include "compiler_hints.h"
#include "net/gnrc/ipv6.h"
#include "net/gnrc/netif.h"
#include "net/gnrc/netif/hdr.h"
Expand Down Expand Up @@ -142,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.
*
Expand Down Expand Up @@ -370,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;
Expand Down