From 3c0a2f6953fc0d0ee4f8d23d59c7cb1fc2fa2395 Mon Sep 17 00:00:00 2001 From: smlng Date: Fri, 17 Feb 2017 14:16:56 +0100 Subject: [PATCH 1/3] gnrc, ipv6: add static link local ipv6 address --- .../network_layer/ipv6/netif/gnrc_ipv6_netif.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c index 154fe4cc48..d971294533 100644 --- a/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c +++ b/sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c @@ -852,7 +852,19 @@ void gnrc_ipv6_netif_init_by_dev(void) _add_addr_to_entry(ipv6_if, &addr, 64, 0); } - +#ifdef GNRC_IPV6_STATIC_LLADDR + /* parse addr from string and explicitely set a link lokal prefix + * if ifnum > 1 each interface will get its own link local address + * with GNRC_IPV6_STATIC_LLADDR + i + */ + char lladdr_str[] = GNRC_IPV6_STATIC_LLADDR; + ipv6_addr_t lladdr; + if(ipv6_addr_from_str(&lladdr, lladdr_str) != NULL) { + lladdr.u8[15] += i; + assert(ipv6_addr_is_link_local(&lladdr)); + _add_addr_to_entry(ipv6_if, &lladdr, 64, 0); + } +#endif /* set link MTU */ if ((gnrc_netapi_get(ifs[i], NETOPT_MAX_PACKET_SIZE, 0, &tmp, sizeof(uint16_t)) >= 0)) { From 85d189a21dfc4dfc6ae48cf3ed629d0e5a3a8491 Mon Sep 17 00:00:00 2001 From: smlng Date: Fri, 17 Feb 2017 15:33:24 +0100 Subject: [PATCH 2/3] gnrc, ipv6: add documentation on MACRO GNRC_IPV6_STATIC_LLADDR --- sys/include/net/gnrc/ipv6.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sys/include/net/gnrc/ipv6.h b/sys/include/net/gnrc/ipv6.h index d688b4ec05..0e89d852f7 100644 --- a/sys/include/net/gnrc/ipv6.h +++ b/sys/include/net/gnrc/ipv6.h @@ -68,6 +68,25 @@ extern "C" { #define GNRC_IPV6_MSG_QUEUE_SIZE (8U) #endif +#ifdef DOXYGEN +/** + * @brief Add a static IPv6 link local address to any network interface + * + * 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 + * + * 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) + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +#define GNRC_IPV6_STATIC_LLADDR +#endif /* DOXYGEN */ + /** * @brief The PID to the IPv6 thread. * From a2e7a2fea179f0ea6f16e41ec4189f8cd812efef Mon Sep 17 00:00:00 2001 From: smlng Date: Fri, 17 Feb 2017 14:17:27 +0100 Subject: [PATCH 3/3] examples: add optional static link local ipv6 address in gnrc_networking --- examples/gnrc_networking/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/gnrc_networking/Makefile b/examples/gnrc_networking/Makefile index 73fb7909af..a10d81ca29 100644 --- a/examples/gnrc_networking/Makefile +++ b/examples/gnrc_networking/Makefile @@ -40,6 +40,12 @@ USEMODULE += netstats_rpl # development process: CFLAGS += -DDEVELHELP +# Comment the following 2 lines out to specify static link lokal IPv6 address +# this might be useful for testing, in cases whre 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) + # Comment this out to join RPL DODAGs even if DIOs do not contain # DODAG Configuration Options (see the doc for more info) # CFLAGS += -DGNRC_RPL_DODAG_CONF_OPTIONAL_ON_JOIN