From 2dd24edcf842107fa6f0033ac319a43ef1ab8375 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 27 Mar 2015 21:21:40 +0100 Subject: [PATCH] ipv6_netif: auto-add corresponding link-local addresses --- .../ng_ipv6/netif/ng_ipv6_netif.c | 19 ++++++++++++++++--- .../tests-ipv6_netif/tests-ipv6_netif.c | 8 ++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c b/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c index 016a63ef74..72e7a0f8e0 100644 --- a/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c +++ b/sys/net/network_layer/ng_ipv6/netif/ng_ipv6_netif.c @@ -20,6 +20,7 @@ #include "kernel_types.h" #include "mutex.h" +#include "net/ng_ipv6.h" #include "net/ng_ipv6/addr.h" #include "net/ng_netif.h" @@ -55,14 +56,26 @@ static int _add_addr_to_entry(ng_ipv6_netif_t *entry, const ng_ipv6_addr_t *addr } entry->addrs[i].flags = NG_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST; + + return 0; } else { entry->addrs[i].prefix_len = prefix_len; - entry->addrs[i].flags = NG_IPV6_NETIF_ADDR_FLAGS_UNICAST; - } + if (!ng_ipv6_addr_is_link_local(addr)) { + /* add also corresponding link-local address */ + ng_ipv6_addr_t ll_addr; - return 0; + ll_addr.u64[1] = addr->u64[1]; + ng_ipv6_addr_set_link_local_prefix(&ll_addr); + + entry->addrs[i].flags = NG_IPV6_NETIF_ADDR_FLAGS_UNICAST; + + return _add_addr_to_entry(entry, &ll_addr, 64, false); + } + + return 0; + } } } diff --git a/tests/unittests/tests-ipv6_netif/tests-ipv6_netif.c b/tests/unittests/tests-ipv6_netif/tests-ipv6_netif.c index 8debce06b1..5c9cb3aa47 100644 --- a/tests/unittests/tests-ipv6_netif/tests-ipv6_netif.c +++ b/tests/unittests/tests-ipv6_netif/tests-ipv6_netif.c @@ -154,6 +154,9 @@ static void test_ipv6_netif_add_addr__ENOMEM(void) ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR; int res = 0, i; + /* make link local to avoid automatic link local adding */ + ng_ipv6_addr_set_link_local_prefix(&addr); + test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */ for (i = 0; res != -ENOMEM; i++, addr.u8[15]++) { @@ -273,6 +276,11 @@ static void test_ipv6_netif_find_addr__success(void) TEST_ASSERT_NOT_NULL((out = ng_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr))); TEST_ASSERT(out != &addr); TEST_ASSERT_EQUAL_INT(true, ng_ipv6_addr_equal(out, &addr)); + + /* also test for link local address */ + ng_ipv6_addr_set_link_local_prefix(&addr); + TEST_ASSERT_NOT_NULL((out = ng_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr))); + TEST_ASSERT_EQUAL_INT(true, ng_ipv6_addr_equal(out, &addr)); } static void test_ipv6_netif_find_by_prefix__success1(void)