rpl-ext-header: Use 8-octet unit for HBHO length

According to RFC 2460 the length field of the Hop-by-Hop options header
should use a 8-octet unit (multiple of 8 byte).

In a normal configuration the RPL_HOP_BY_HOP_LEN define is 8, so the
current implementation works, but if RPL_HOP_BY_HOP_LEN is a multiple
of 8 the length is not calculated correctly.
This commit is contained in:
Tommy Sparber 2016-05-30 10:30:43 +02:00
parent 10cd17b626
commit 27cceda1e8
No known key found for this signature in database
GPG Key ID: B494EF602A3462D8

View File

@ -78,7 +78,7 @@ rpl_verify_hbh_header(int uip_ext_opt_offset)
uip_ds6_route_t *route; uip_ds6_route_t *route;
rpl_parent_t *sender = NULL; rpl_parent_t *sender = NULL;
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)) {
PRINTF("RPL: Hop-by-hop extension header has wrong size\n"); PRINTF("RPL: Hop-by-hop extension header has wrong size\n");
return 1; return 1;
} }
@ -492,7 +492,7 @@ update_hbh_header(void)
switch(UIP_IP_BUF->proto) { switch(UIP_IP_BUF->proto) {
case UIP_PROTO_HBHO: case UIP_PROTO_HBHO:
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)) {
PRINTF("RPL: Hop-by-hop extension header has wrong size\n"); PRINTF("RPL: Hop-by-hop extension header has wrong size\n");
uip_ext_len = last_uip_ext_len; uip_ext_len = last_uip_ext_len;
return 1; return 1;
@ -604,7 +604,7 @@ insert_hbh_header(void)
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = 0; UIP_EXT_HDR_OPT_RPL_BUF->senderrank = 0;
uip_len += RPL_HOP_BY_HOP_LEN; uip_len += RPL_HOP_BY_HOP_LEN;
temp_len = UIP_IP_BUF->len[1]; temp_len = UIP_IP_BUF->len[1];
UIP_IP_BUF->len[1] += UIP_HBHO_BUF->len + 8; UIP_IP_BUF->len[1] += RPL_HOP_BY_HOP_LEN;
if(UIP_IP_BUF->len[1] < temp_len) { if(UIP_IP_BUF->len[1] < temp_len) {
UIP_IP_BUF->len[0]++; UIP_IP_BUF->len[0]++;
} }
@ -625,7 +625,7 @@ rpl_finalize_header(uip_ipaddr_t *addr)
uip_ext_opt_offset = 2; uip_ext_opt_offset = 2;
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO) { if(UIP_IP_BUF->proto == UIP_PROTO_HBHO) {
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)) {
PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n"); PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n");
uip_ext_len = last_uip_ext_len; uip_ext_len = last_uip_ext_len;
return 1; return 1;