Rework uIP6 extension header options access

This commit is contained in:
Simon Duquennoy 2018-10-17 16:58:51 +02:00
parent 8152342c11
commit 01b795a4c2
6 changed files with 86 additions and 93 deletions

View File

@ -54,7 +54,6 @@
#define LOG_LEVEL LOG_LEVEL_IPV6
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)UIP_ICMP_PAYLOAD)
#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
/** \brief temporary IP address */
static uip_ipaddr_t tmp_ipaddr;
@ -194,14 +193,14 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
uip_len = UIP_LINK_MTU;
}
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN,
memmove(UIP_ICMP_PAYLOAD + uip_ext_len + UIP_ICMP6_ERROR_LEN,
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN);
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
if (uip_ext_len) {
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
UIP_EXT_BUF(0)->next = UIP_PROTO_ICMP6;
} else {
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
}

View File

@ -101,6 +101,14 @@
#define UIP_RH_BUF(ext) ((struct uip_routing_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_FRAG_BUF(ext) ((struct uip_frag_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_DESTO_BUF(ext) ((struct uip_desto_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_RPL_SRH_BUF(ext) ((struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(ext) + RPL_RH_LEN))
/**
* Direct access to extension header options, with explicit ext header and option offset
*/
#define UIP_EXT_HDR_OPT_BUF(ext, opt) ((struct uip_ext_hdr_opt *)(UIP_IP_PAYLOAD(ext) + (opt)))
#define UIP_EXT_HDR_OPT_PADN_BUF(ext, opt) ((struct uip_ext_hdr_opt_padn *)(UIP_IP_PAYLOAD(ext) + (opt)))
#define UIP_EXT_HDR_OPT_RPL_BUF(ext, opt) ((struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(ext) + (opt)))
#include "net/ipv6/uipopt.h"
#include "net/ipv6/uipbuf.h"

View File

@ -138,12 +138,11 @@ uint8_t uip_ext_opt_offset = 0;
/* Buffers */
/*---------------------------------------------------------------------------*/
/**
* \name Buffer defines
* \name Reassembly buffer definition
* @{
*/
#define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0])
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
/** @} */
/**
* \name Buffer variables
@ -839,7 +838,7 @@ ext_hdr_options_process(void)
*/
uip_ext_opt_offset = 2;
while(uip_ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) {
switch(UIP_EXT_HDR_OPT_BUF->type) {
switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type) {
/*
* for now we do not support any options except padding ones
* PAD1 does not make sense as the header must be 8bytes aligned,
@ -851,7 +850,7 @@ ext_hdr_options_process(void)
break;
case UIP_EXT_HDR_OPT_PADN:
LOG_DBG("Processing PADN option\n");
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2;
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len + 2;
break;
case UIP_EXT_HDR_OPT_RPL:
/* Fixes situation when a node that is not using RPL
@ -866,7 +865,7 @@ ext_hdr_options_process(void)
LOG_ERR("RPL Option Error: Dropping Packet\n");
return 1;
}
uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF->len) + 2;
uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len) + 2;
return 0;
default:
/*
@ -882,8 +881,8 @@ ext_hdr_options_process(void)
* Problem, Code 2, message to the packet's Source Address,
* pointing to the unrecognized Option Type.
*/
LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF->type);
switch(UIP_EXT_HDR_OPT_BUF->type & 0xC0) {
LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type);
switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type & 0xC0) {
case 0:
break;
case 0x40:
@ -898,7 +897,7 @@ ext_hdr_options_process(void)
return 2;
}
/* in the cases were we did not discard, update ext_opt* */
uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF->len + 2;
uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len + 2;
break;
}
}

View File

@ -60,12 +60,6 @@
#include <limits.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
#define UIP_RPL_SRH_BUF ((struct uip_rpl_srh_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_RH_LEN])
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
/*---------------------------------------------------------------------------*/
int
rpl_ext_header_hbh_update(int uip_ext_opt_offset)
@ -78,24 +72,24 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
rpl_parent_t *sender = NULL;
if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| UIP_EXT_HDR_OPT_RPL_BUF->opt_type != UIP_EXT_HDR_OPT_RPL
|| UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|| UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type != UIP_EXT_HDR_OPT_RPL
|| UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n",
UIP_HBHO_BUF(uip_ext_len)->len,
UIP_EXT_HDR_OPT_RPL_BUF->opt_type,
UIP_EXT_HDR_OPT_RPL_BUF->opt_len);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type,
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len);
return 0; /* Drop */
}
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance);
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance);
if(instance == NULL) {
LOG_ERR("Unknown instance: %u\n",
UIP_EXT_HDR_OPT_RPL_BUF->instance);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance);
return 0;
}
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) {
if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) {
LOG_ERR("Forward error!\n");
/* We should try to repair it by removing the neighbor that caused
the packet to be forwareded in the first place. We drop any
@ -119,14 +113,14 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
return 0;
}
down = 0;
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) {
if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN) {
down = 1;
}
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank);
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank);
sender = nbr_table_get_from_lladdr(rpl_parents, packetbuf_addr(PACKETBUF_ADDR_SENDER));
if(sender != NULL && (UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR)) {
if(sender != NULL && (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR)) {
/* A rank error was signalled, attempt to repair it by updating
* the sender's rank from ext header */
sender->rank = sender_rank;
@ -156,7 +150,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
instance->unicast_dio_target = sender;
rpl_schedule_unicast_dio_immediately(instance);
}
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) {
if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) {
RPL_STAT(rpl_stats.loop_errors++);
LOG_ERR(" Rank error signalled in RPL option!\n");
/* Packet must be dropped and dio trickle timer reset, see RFC6550 - 11.2.2.2 */
@ -165,7 +159,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
}
LOG_WARN("Single error tolerated\n");
RPL_STAT(rpl_stats.loop_warnings++);
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR;
return 1;
}
@ -273,9 +267,9 @@ rpl_ext_header_srh_update(void)
segments_left = UIP_RH_BUF(uip_ext_len)->seg_left;
ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8;
cmpri = UIP_RPL_SRH_BUF->cmpr >> 4;
cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f;
padding = UIP_RPL_SRH_BUF->pad >> 4;
cmpri = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr >> 4;
cmpre = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr & 0x0f;
padding = UIP_RPL_SRH_BUF(uip_ext_len)->pad >> 4;
path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1;
(void)path_len;
@ -419,7 +413,7 @@ insert_srh_header(void)
return 0;
}
/* Move existing ext headers and payload uip_ext_len further */
/* Move existing ext headers and payload ext_len further */
memmove(uip_buf + uip_l2_l3_hdr_len + ext_len,
uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN);
memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len);
@ -434,8 +428,8 @@ insert_srh_header(void)
UIP_RH_BUF(uip_ext_len)->seg_left = path_len;
/* Initialize RPL Source Routing Header */
UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre;
UIP_RPL_SRH_BUF->pad = padding << 4;
UIP_RPL_SRH_BUF(uip_ext_len)->cmpr = (cmpri << 4) + cmpre;
UIP_RPL_SRH_BUF(uip_ext_len)->pad = padding << 4;
/* Initialize addresses field (the actual source route).
* From last to first. */
@ -480,17 +474,17 @@ update_hbh_header(void)
uip_ext_len = 0;
uip_ext_opt_offset = 2;
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|| UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("Hop-by-hop extension header has wrong size (%u %u)\n",
UIP_EXT_HDR_OPT_RPL_BUF->opt_len,
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len,
uip_ext_len);
return 0; /* Drop */
}
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance);
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance);
if(instance == NULL || !instance->used || !instance->current_dag->joined) {
LOG_ERR("Unable to add/update hop-by-hop extension header: incorrect instance\n");
uip_ext_len = last_uip_ext_len;
@ -499,17 +493,17 @@ update_hbh_header(void)
LOG_INFO("Updating RPL option\n");
/* Update sender rank and instance, will update flags next */
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank);
UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = instance->instance_id;
if(RPL_IS_STORING(instance)) { /* In non-storing mode, downwards traffic does not have the HBH option */
/* 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
general not go back up again. If this happens, a
RPL_HDR_OPT_FWD_ERR should be flagged. */
if((UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN)) {
if((UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN)) {
if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) {
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_FWD_ERR;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_FWD_ERR;
LOG_WARN("RPL forwarding error\n");
/* We should send back the packet to the originating parent,
but it is not feasible yet, so we send a No-Path DAO instead */
@ -528,11 +522,11 @@ update_hbh_header(void)
if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) {
/* No route was found, so this packet will go towards the RPL
root. If so, we should not set the down flag. */
UIP_EXT_HDR_OPT_RPL_BUF->flags &= ~RPL_HDR_OPT_DOWN;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags &= ~RPL_HDR_OPT_DOWN;
LOG_DBG("RPL option going up\n");
} else {
/* A DAO route was found so we set the down flag. */
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_DOWN;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_DOWN;
LOG_DBG("RPL option going down\n");
}
}
@ -562,9 +556,9 @@ insert_hbh_header(const rpl_instance_t *instance)
return 0;
}
/* Move existing ext headers and payload UIP_EXT_BUF(uip_ext_len) further */
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF(uip_ext_len), uip_len - UIP_IPH_LEN);
memset(UIP_HBHO_BUF(uip_ext_len), 0, RPL_HOP_BY_HOP_LEN);
/* Move existing ext headers and payload RPL_HOP_BY_HOP_LEN further */
memmove(UIP_IP_PAYLOAD(RPL_HOP_BY_HOP_LEN), UIP_IP_PAYLOAD(0), uip_len - UIP_IPH_LEN);
memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN);
/* Update IP and HBH protocol and fields */
UIP_HBHO_BUF(uip_ext_len)->next = UIP_IP_BUF->proto;
@ -572,11 +566,11 @@ insert_hbh_header(const rpl_instance_t *instance)
/* Initialize HBH option */
UIP_HBHO_BUF(uip_ext_len)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8;
UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank);
UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = instance->instance_id;
uip_len += RPL_HOP_BY_HOP_LEN;
temp_len = UIP_IP_BUF->len[1];
UIP_IP_BUF->len[1] += RPL_HOP_BY_HOP_LEN;
@ -607,7 +601,7 @@ rpl_ext_header_remove(void)
switch(*uip_next_hdr) {
case UIP_PROTO_HBHO:
case UIP_PROTO_ROUTING:
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) {
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL)) {
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next;
rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->len * 8) + 8;

View File

@ -53,13 +53,6 @@
#define LOG_MODULE "RPL"
#define LOG_LEVEL LOG_LEVEL_RPL
/*---------------------------------------------------------------------------*/
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
#define UIP_RPL_SRH_BUF ((struct uip_rpl_srh_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_RH_LEN])
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
/*---------------------------------------------------------------------------*/
int
rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
@ -159,9 +152,9 @@ rpl_ext_header_srh_update(void)
/* Parse SRH */
segments_left = UIP_RH_BUF(uip_ext_len)->seg_left;
ext_len = (UIP_RH_BUF(uip_ext_len)->len * 8) + 8;
cmpri = UIP_RPL_SRH_BUF->cmpr >> 4;
cmpre = UIP_RPL_SRH_BUF->cmpr & 0x0f;
padding = UIP_RPL_SRH_BUF->pad >> 4;
cmpri = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr >> 4;
cmpre = UIP_RPL_SRH_BUF(uip_ext_len)->cmpr & 0x0f;
padding = UIP_RPL_SRH_BUF(uip_ext_len)->pad >> 4;
path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1;
(void)path_len;
@ -305,7 +298,7 @@ insert_srh_header(void)
return 0;
}
/* Move existing ext headers and payload uip_ext_len further */
/* Move existing ext headers and payload ext_len further */
memmove(uip_buf + uip_l2_l3_hdr_len + ext_len,
uip_buf + uip_l2_l3_hdr_len, uip_len - UIP_IPH_LEN);
memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len);
@ -320,8 +313,8 @@ insert_srh_header(void)
UIP_RH_BUF(uip_ext_len)->seg_left = path_len;
/* Initialize RPL Source Routing Header */
UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre;
UIP_RPL_SRH_BUF->pad = padding << 4;
UIP_RPL_SRH_BUF(uip_ext_len)->cmpr = (cmpri << 4) + cmpre;
UIP_RPL_SRH_BUF(uip_ext_len)->pad = padding << 4;
/* Initialize addresses field (the actual source route).
* From last to first. */
@ -363,8 +356,8 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
uint16_t sender_rank;
uint8_t sender_closer;
rpl_nbr_t *sender;
uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF->opt_type;
uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF->opt_len;
uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type;
uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len;
if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| opt_type != UIP_EXT_HDR_OPT_RPL
@ -374,21 +367,21 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
return 0; /* Drop */
}
if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF->instance) {
if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance) {
LOG_ERR("unknown instance: %u\n",
UIP_EXT_HDR_OPT_RPL_BUF->instance);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance);
return 0; /* Drop */
}
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) {
if(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) {
LOG_ERR("forward error!\n");
return 0; /* Drop */
}
down = (UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) ? 1 : 0;
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank);
down = (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_DOWN) ? 1 : 0;
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank);
sender = nbr_table_get_from_lladdr(rpl_neighbors, packetbuf_addr(PACKETBUF_ADDR_SENDER));
rank_error_signaled = (UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0;
rank_error_signaled = (UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0;
sender_closer = sender_rank < curr_instance.dag.rank;
loop_detected = (down && !sender_closer) || (!down && sender_closer);
@ -402,7 +395,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
if(loop_detected) {
/* Set forward error flag */
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR;
}
return rpl_process_hbh(sender, sender_rank, loop_detected, rank_error_signaled);
@ -421,24 +414,24 @@ update_hbh_header(void)
uip_ext_len = 0;
uip_ext_opt_offset = 2;
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|| UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("hop-by-hop extension header has wrong size (%u %u)\n",
UIP_EXT_HDR_OPT_RPL_BUF->opt_len, uip_ext_len);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len, uip_ext_len);
return 0; /* Drop */
}
if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF->instance) {
if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance) {
LOG_ERR("unable to add/update hop-by-hop extension header: incorrect instance\n");
uip_ext_len = last_uip_ext_len;
return 0; /* Drop */
}
/* Update sender rank and instance, will update flags next */
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(curr_instance.dag.rank);
UIP_EXT_HDR_OPT_RPL_BUF->instance = curr_instance.instance_id;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = curr_instance.instance_id;
}
uip_ext_len = last_uip_ext_len;
@ -468,9 +461,9 @@ insert_hbh_header(void)
return 0;
}
/* Move existing ext headers and payload UIP_EXT_BUF(uip_ext_len) further */
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF(uip_ext_len), uip_len - UIP_IPH_LEN);
memset(UIP_HBHO_BUF(uip_ext_len), 0, RPL_HOP_BY_HOP_LEN);
/* Move existing ext headers and payload RPL_HOP_BY_HOP_LEN further */
memmove(UIP_IP_PAYLOAD(RPL_HOP_BY_HOP_LEN), UIP_IP_PAYLOAD(0), uip_len - UIP_IPH_LEN);
memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN);
/* Update IP and HBH protocol and fields */
UIP_HBHO_BUF(uip_ext_len)->next = UIP_IP_BUF->proto;
@ -478,11 +471,11 @@ insert_hbh_header(void)
/* Initialize HBH option */
UIP_HBHO_BUF(uip_ext_len)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8;
UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(curr_instance.dag.rank);
UIP_EXT_HDR_OPT_RPL_BUF->instance = curr_instance.instance_id;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank);
UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->instance = curr_instance.instance_id;
uip_len += RPL_HOP_BY_HOP_LEN;
temp_len = UIP_IP_BUF->len[1];
UIP_IP_BUF->len[1] += RPL_HOP_BY_HOP_LEN;
@ -541,7 +534,7 @@ rpl_ext_header_remove(void)
switch(*uip_next_hdr) {
case UIP_PROTO_HBHO:
case UIP_PROTO_ROUTING:
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) {
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF(uip_ext_len, uip_ext_opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL)) {
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next;
rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->len * 8) + 8;

View File

@ -379,7 +379,7 @@ typedef struct {
uint8_t data[16];
} icmp_opts_t;
#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x])
#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)UIP_IP_PAYLOAD(x))
void slide(uint8_t * data, uint8_t length, int16_t slide);