From 11254577eb01178b4ca90fe6383987cc0721fca6 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 22 Aug 2014 21:19:42 +0200 Subject: [PATCH 1/2] sixlowpan: ignore incoming packets if unconfigured If there's no IPv6 address configured so far to any interface, 6lowpan should not try to handle incoming packets. This can easily lead to looping packets. --- sys/net/network_layer/sixlowpan/icmp.c | 3 +++ sys/net/network_layer/sixlowpan/ip.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sys/net/network_layer/sixlowpan/icmp.c b/sys/net/network_layer/sixlowpan/icmp.c index 65092fd2c2..30d6c65d9c 100644 --- a/sys/net/network_layer/sixlowpan/icmp.c +++ b/sys/net/network_layer/sixlowpan/icmp.c @@ -1523,7 +1523,10 @@ int ndp_addr_is_on_link(ipv6_addr_t *dest_addr) int if_id = -1; if ((nce = ndp_neighbor_cache_search(dest_addr))) { +#ifdef DEBUG_ENABLED + char addr_str[IPV6_MAX_ADDR_STR_LEN]; DEBUG("INFO: %s is in nbr cache\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, dest_addr)); +#endif return 1; } diff --git a/sys/net/network_layer/sixlowpan/ip.c b/sys/net/network_layer/sixlowpan/ip.c index 64e7c431a2..df06945fd4 100644 --- a/sys/net/network_layer/sixlowpan/ip.c +++ b/sys/net/network_layer/sixlowpan/ip.c @@ -313,6 +313,7 @@ int is_our_address(ipv6_addr_t *addr) ipv6_net_if_addr_t *myaddr; uint8_t prefix, suffix; int if_id = -1; + unsigned counter = 0; DEBUGF("Is this my addres: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, addr)); while ((if_id = net_if_iter_interfaces(if_id)) >= 0) { @@ -323,6 +324,7 @@ int is_our_address(ipv6_addr_t *addr) while ((myaddr = (ipv6_net_if_addr_t *)net_if_iter_addresses(if_id, (net_if_addr_t **) &myaddr)) != NULL) { + counter++; DEBUGF("\tCompare with: %s?\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, (ipv6_addr_t*) myaddr->addr_data)); if ((ipv6_get_addr_match(myaddr->addr_data, addr) >= net_if_ext->prefix) && (memcmp(&addr->uint8[prefix], &myaddr->addr_data->uint8[prefix], suffix) == 0)) { @@ -331,7 +333,11 @@ int is_our_address(ipv6_addr_t *addr) } } - return 0; + if (!counter) { + counter = -1; + } + /* return negative value if no address is configured so far */ + return counter; } void *ipv6_process(void *arg) @@ -362,8 +368,15 @@ void *ipv6_process(void *arg) } } + int addr_match = is_our_address(&ipv6_buf->destaddr); + + /* no address configured for this node so far, exit early */ + if (addr_match < 1) { + msg_reply(&m_recv_lowpan, &m_send_lowpan); + continue; + } /* destination is our address */ - if (is_our_address(&ipv6_buf->destaddr)) { + else if (addr_match) { switch (*nextheader) { case (IPV6_PROTO_NUM_ICMPV6): { icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len); From c92407572213c693c4d492180f9cdd0be66b486c Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sat, 23 Aug 2014 12:58:35 +0200 Subject: [PATCH 2/2] sixlowpan: documented internal is_our_address() --- sys/net/network_layer/sixlowpan/ip.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sys/net/network_layer/sixlowpan/ip.c b/sys/net/network_layer/sixlowpan/ip.c index df06945fd4..1dc4e9e76d 100644 --- a/sys/net/network_layer/sixlowpan/ip.c +++ b/sys/net/network_layer/sixlowpan/ip.c @@ -307,7 +307,17 @@ uint8_t ipv6_get_addr_match(const ipv6_addr_t *src, return val; } -int is_our_address(ipv6_addr_t *addr) +/** + * @brief Check if the given IPv6 address is assigned to any configured + * interface + * + * @param[in] addr The IPv6 address to check + * + * @return 1 If *addr* is assigned to at least one interface + * @return 0 If *addr* is not assigned to any interface + * @return -1 If no IPv6 address is configured to any interface + */ +static int is_our_address(ipv6_addr_t *addr) { ipv6_net_if_ext_t *net_if_ext; ipv6_net_if_addr_t *myaddr;