Skip to content

Commit

Permalink
sixlowpan: ignore incoming packets if unconfigured
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OlegHahm committed Sep 10, 2014
1 parent 2dc8ea1 commit 1125457
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions sys/net/network_layer/sixlowpan/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 15 additions & 2 deletions sys/net/network_layer/sixlowpan/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1125457

Please sign in to comment.