From b6742e5eb54fccfa4a0cfe6a29fc37caa63eaee7 Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Wed, 22 Jan 2014 12:16:27 +0100 Subject: [PATCH 1/4] Sender rank in Hop-by-Hop option has inverted bytes --- core/net/rpl/rpl-ext-header.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/net/rpl/rpl-ext-header.c b/core/net/rpl/rpl-ext-header.c index 4913e2aee..9c736b4c1 100644 --- a/core/net/rpl/rpl-ext-header.c +++ b/core/net/rpl/rpl-ext-header.c @@ -68,6 +68,7 @@ rpl_verify_header(int uip_ext_opt_offset) { rpl_instance_t *instance; int down; + uint16_t sender_rank; uint8_t sender_closer; uip_ds6_route_t *route; @@ -117,17 +118,18 @@ rpl_verify_header(int uip_ext_opt_offset) down = 1; } - sender_closer = UIP_EXT_HDR_OPT_RPL_BUF->senderrank < instance->current_dag->rank; + sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank); + sender_closer = sender_rank < instance->current_dag->rank; PRINTF("RPL: Packet going %s, sender closer %d (%d < %d)\n", down == 1 ? "down" : "up", sender_closer, - UIP_EXT_HDR_OPT_RPL_BUF->senderrank, + sender_rank, instance->current_dag->rank ); if((down && !sender_closer) || (!down && sender_closer)) { PRINTF("RPL: Loop detected - senderrank: %d my-rank: %d sender_closer: %d\n", - UIP_EXT_HDR_OPT_RPL_BUF->senderrank, instance->current_dag->rank, + sender_rank, instance->current_dag->rank, sender_closer); if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) { PRINTF("RPL: Rank error signalled in RPL option!\n"); @@ -210,7 +212,7 @@ rpl_update_header_empty(void) switch(UIP_EXT_HDR_OPT_BUF->type) { case UIP_EXT_HDR_OPT_RPL: PRINTF("RPL: Updating RPL option\n"); - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = instance->current_dag->rank; + UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank); /* Check the direction of the down flag, as per Section 11.2.2.3, which states that if a packet is going down it should in @@ -276,7 +278,7 @@ rpl_update_header_final(uip_ipaddr_t *addr) UIP_EXT_HDR_OPT_RPL_BUF->flags = RPL_HDR_OPT_DOWN; } UIP_EXT_HDR_OPT_RPL_BUF->instance = default_instance->instance_id; - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = default_instance->current_dag->rank; + UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(default_instance->current_dag->rank); uip_ext_len = last_uip_ext_len; } } @@ -334,7 +336,7 @@ rpl_invert_header(void) PRINTF("RPL: Updating RPL option (switching direction)\n"); UIP_EXT_HDR_OPT_RPL_BUF->flags &= RPL_HDR_OPT_DOWN; UIP_EXT_HDR_OPT_RPL_BUF->flags ^= RPL_HDR_OPT_DOWN; - UIP_EXT_HDR_OPT_RPL_BUF->senderrank = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank; + UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank); uip_ext_len = last_uip_ext_len; return RPL_HOP_BY_HOP_LEN; default: From 2dfe2c377f8a011c95932f54c0c6a244c80cd2ee Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Fri, 31 Jan 2014 09:40:06 +0100 Subject: [PATCH 2/4] Setting uip_ext_len again breaks hop-by-hop option --- core/net/rpl/rpl-ext-header.c | 1 - 1 file changed, 1 deletion(-) diff --git a/core/net/rpl/rpl-ext-header.c b/core/net/rpl/rpl-ext-header.c index 9c736b4c1..fb430fa8d 100644 --- a/core/net/rpl/rpl-ext-header.c +++ b/core/net/rpl/rpl-ext-header.c @@ -279,7 +279,6 @@ rpl_update_header_final(uip_ipaddr_t *addr) } UIP_EXT_HDR_OPT_RPL_BUF->instance = default_instance->instance_id; UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(default_instance->current_dag->rank); - uip_ext_len = last_uip_ext_len; } } } From d45782fbcd5d3c0df14333b4214256eb959b9e54 Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Wed, 22 Jan 2014 14:25:28 +0100 Subject: [PATCH 3/4] Insert properly Hop-by-Hop option at first hop --- core/net/ipv6/uip6.c | 9 +++++---- core/net/rpl/rpl-ext-header.c | 8 ++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/core/net/ipv6/uip6.c b/core/net/ipv6/uip6.c index 746b31ab2..05d0457d9 100644 --- a/core/net/ipv6/uip6.c +++ b/core/net/ipv6/uip6.c @@ -1547,10 +1547,6 @@ uip_process(uint8_t flag) uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN]; -#if UIP_CONF_IPV6_RPL - rpl_insert_header(); -#endif /* UIP_CONF_IPV6_RPL */ - #if UIP_UDP_CHECKSUMS /* Calculate UDP checksum. */ UIP_UDP_BUF->udpchksum = ~(uip_udpchksum()); @@ -1558,6 +1554,11 @@ uip_process(uint8_t flag) UIP_UDP_BUF->udpchksum = 0xffff; } #endif /* UIP_UDP_CHECKSUMS */ + +#if UIP_CONF_IPV6_RPL + rpl_insert_header(); +#endif /* UIP_CONF_IPV6_RPL */ + UIP_STAT(++uip_stat.udp.sent); goto ip_send_nolen; #endif /* UIP_UDP */ diff --git a/core/net/rpl/rpl-ext-header.c b/core/net/rpl/rpl-ext-header.c index fb430fa8d..4aa93d228 100644 --- a/core/net/rpl/rpl-ext-header.c +++ b/core/net/rpl/rpl-ext-header.c @@ -348,12 +348,8 @@ rpl_invert_header(void) void rpl_insert_header(void) { - uint8_t uip_ext_opt_offset; - if(default_instance != NULL) { - uip_ext_opt_offset = 2; - if(UIP_EXT_HDR_OPT_BUF->type == UIP_EXT_HDR_OPT_RPL) { - rpl_update_header_empty(); - } + if(default_instance != NULL && !uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) { + rpl_update_header_empty(); } } /*---------------------------------------------------------------------------*/ From 02972e651439631b70481cbc8a5e2f7715400aef Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Fri, 9 May 2014 11:28:36 +0200 Subject: [PATCH 4/4] Improve RPL hop-by-hop option detection --- core/net/rpl/rpl-ext-header.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/net/rpl/rpl-ext-header.c b/core/net/rpl/rpl-ext-header.c index 4aa93d228..c0a5b3afc 100644 --- a/core/net/rpl/rpl-ext-header.c +++ b/core/net/rpl/rpl-ext-header.c @@ -72,6 +72,16 @@ rpl_verify_header(int uip_ext_opt_offset) uint8_t sender_closer; uip_ds6_route_t *route; + if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { + PRINTF("RPL: Hop-by-hop extension header has wrong size\n"); + return 1; + } + + if(UIP_EXT_HDR_OPT_RPL_BUF->opt_type != UIP_EXT_HDR_OPT_RPL) { + PRINTF("RPL: Non RPL Hop-by-hop option\n"); + return 1; + } + if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { PRINTF("RPL: Bad header option! (wrong length)\n"); return 1; @@ -187,7 +197,17 @@ rpl_update_header_empty(void) switch(UIP_IP_BUF->proto) { case UIP_PROTO_HBHO: if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { - PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n"); + PRINTF("RPL: Hop-by-hop extension header has wrong size\n"); + uip_ext_len = last_uip_ext_len; + return; + } + if(UIP_EXT_HDR_OPT_RPL_BUF->opt_type != UIP_EXT_HDR_OPT_RPL) { + PRINTF("RPL: Non RPL Hop-by-hop option support not implemented\n"); + uip_ext_len = last_uip_ext_len; + return; + } + if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { + PRINTF("RPL: RPL Hop-by-hop option has wrong length\n"); uip_ext_len = last_uip_ext_len; return; }