1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

ipv6_netif: auto-add corresponding link-local addresses

This commit is contained in:
Martine Lenders 2015-03-27 21:21:40 +01:00
parent 7cbc667199
commit 2dd24edcf8
2 changed files with 24 additions and 3 deletions

View File

@ -20,6 +20,7 @@
#include "kernel_types.h" #include "kernel_types.h"
#include "mutex.h" #include "mutex.h"
#include "net/ng_ipv6.h"
#include "net/ng_ipv6/addr.h" #include "net/ng_ipv6/addr.h"
#include "net/ng_netif.h" #include "net/ng_netif.h"
@ -55,16 +56,28 @@ 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; entry->addrs[i].flags = NG_IPV6_NETIF_ADDR_FLAGS_NON_UNICAST;
return 0;
} }
else { else {
entry->addrs[i].prefix_len = prefix_len; entry->addrs[i].prefix_len = prefix_len;
if (!ng_ipv6_addr_is_link_local(addr)) {
/* add also corresponding link-local address */
ng_ipv6_addr_t ll_addr;
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; entry->addrs[i].flags = NG_IPV6_NETIF_ADDR_FLAGS_UNICAST;
return _add_addr_to_entry(entry, &ll_addr, 64, false);
} }
return 0; return 0;
} }
} }
}
return -ENOMEM; return -ENOMEM;
} }

View File

@ -154,6 +154,9 @@ static void test_ipv6_netif_add_addr__ENOMEM(void)
ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR; ng_ipv6_addr_t addr = DEFAULT_TEST_IPV6_ADDR;
int res = 0, i; 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 */ test_ipv6_netif_add__success(); /* adds DEFAULT_TEST_NETIF as interface */
for (i = 0; res != -ENOMEM; i++, addr.u8[15]++) { 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_NOT_NULL((out = ng_ipv6_netif_find_addr(DEFAULT_TEST_NETIF, &addr)));
TEST_ASSERT(out != &addr); TEST_ASSERT(out != &addr);
TEST_ASSERT_EQUAL_INT(true, ng_ipv6_addr_equal(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) static void test_ipv6_netif_find_by_prefix__success1(void)