Skip to content
New issue

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

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

Already on GitHub? # to your account

gnrc/ipv6/nib: allow for predictable static link-local addresses #20224

Merged
merged 2 commits into from
Jan 5, 2024
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
2 changes: 1 addition & 1 deletion examples/gnrc_networking/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ endif
# this might be useful for testing, in cases where you cannot or do not want to
# run a shell with ifconfig to get the real link lokal address.
#IPV6_STATIC_LLADDR ?= '"fe80::cafe:cafe:cafe:1"'
#CFLAGS += -DGNRC_IPV6_STATIC_LLADDR=$(IPV6_STATIC_LLADDR)
#CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR=$(IPV6_STATIC_LLADDR)

# Uncomment this to join RPL DODAGs even if DIOs do not contain
# DODAG Configuration Options (see the doc for more info)
Expand Down
2 changes: 1 addition & 1 deletion examples/gnrc_networking_mac/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ DEVELHELP ?= 1
# this might be useful for testing, in cases where you cannot or do not want to
# run a shell with ifconfig to get the real link lokal address.
#IPV6_STATIC_LLADDR ?= '"fe80::cafe:cafe:cafe:1"'
#CFLAGS += -DGNRC_IPV6_STATIC_LLADDR=$(IPV6_STATIC_LLADDR)
#CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR=$(IPV6_STATIC_LLADDR)

# Uncomment this to join RPL DODAGs even if DIOs do not contain
# DODAG Configuration Options (see the doc for more info)
Expand Down
17 changes: 14 additions & 3 deletions sys/include/net/gnrc/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,30 @@ extern "C" {
* This macro allows to specify a certain link local IPv6 address to be assigned
* to a network interface on startup, which might be handy for testing.
* Note: a) a interface will keep its auto-generated link local address, too
* b) the address is incremented by 1, if multiple interfaces are present
* b) the address is incremented by the interface PID unless
`CONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED` is set.
*
* To use the macro just add it to `CFLAGS` in the application's Makefile, like:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.mk}
* IPV6_STATIC_LLADDR ?= '"fe80::cafe:cafe:cafe:1"'
* CFLAGS += -DGNRC_IPV6_STATIC_LLADDR=$(STATIC_IPV6_LLADDR)
* CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR=$(STATIC_IPV6_LLADDR)
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#define GNRC_IPV6_STATIC_LLADDR
#define CONFIG_GNRC_IPV6_STATIC_LLADDR
#endif /* DOXYGEN */
/** @} */

/**
* @brief Use the same static IPv6 link local address on every network interface
*
* When CONFIG_GNRC_IPV6_STATIC_LLADDR is used, to not add the interface pid to the
* set static address but use the same static link local address for all interfaces.
*/
#ifndef CONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED
#define CONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED 0
#endif

/**
* @brief Message queue size to use for the IPv6 thread.
*/
Expand Down
23 changes: 23 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ config GNRC_IPV6_MSG_QUEUE_SIZE_EXP
represents the exponent of 2^n, which will be used as the size of
the queue.

config GNRC_IPV6_STATIC_LLADDR_ENABLE
bool "Add a static IPv6 link local address to any network interface"
help
This allows to specify a certain link local IPv6 address to be assigned
to a network interface on startup, which might be handy for testing.

A interface will keep its auto-generated link local address, too.

config GNRC_IPV6_STATIC_LLADDR
string "Static link-local address"
depends on GNRC_IPV6_STATIC_LLADDR_ENABLE
default "fe80::cafe:cafe:cafe:1"
help
The address is configured on each interface and incremented by the
interface PID.

config GNRC_IPV6_STATIC_LLADDR_IS_FIXED
bool "Same link-local address on every interface"
depends on GNRC_IPV6_STATIC_LLADDR_ENABLE
help
Don't add the interface PID to the least significant byte
of the address.

endif # KCONFIG_USEMODULE_GNRC_IPV6

rsource "blacklist/Kconfig"
Expand Down
10 changes: 6 additions & 4 deletions sys/net/gnrc/network_layer/ipv6/nib/nib.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,18 @@

static void _add_static_lladdr(gnrc_netif_t *netif)
{
#ifdef GNRC_IPV6_STATIC_LLADDR
#ifdef CONFIG_GNRC_IPV6_STATIC_LLADDR
/* parse addr from string and explicitly set a link local prefix
* if ifnum > 1 each interface will get its own link local address
* with GNRC_IPV6_STATIC_LLADDR + i
* with CONFIG_GNRC_IPV6_STATIC_LLADDR + i
*/
char lladdr_str[] = GNRC_IPV6_STATIC_LLADDR;
const char lladdr_str[] = CONFIG_GNRC_IPV6_STATIC_LLADDR;
ipv6_addr_t lladdr;

if (ipv6_addr_from_str(&lladdr, lladdr_str) != NULL) {
lladdr.u8[15] += netif->pid;
if (!IS_ACTIVE(CONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED)) {
lladdr.u8[15] += netif->pid;
}
assert(ipv6_addr_is_link_local(&lladdr));
gnrc_netif_ipv6_addr_add_internal(
netif, &lladdr, 64U, GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID
Expand Down Expand Up @@ -525,7 +527,7 @@
icmpv6_len -= (opt->len << 3), \
opt = (ndp_opt_t *)(((uint8_t *)opt) + (opt->len << 3)))

#if IS_ACTIVE(CONFIG_GNRC_IPV6_NIB_ROUTER)

Check warning on line 530 in sys/net/gnrc/network_layer/ipv6/nib/nib.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
static void _handle_rtr_sol(gnrc_netif_t *netif, const ipv6_hdr_t *ipv6,
const ndp_rtr_sol_t *rtr_sol, size_t icmpv6_len)
{
Expand Down
Loading