Rework uIP6 extension header access

This commit is contained in:
Simon Duquennoy 2018-10-17 16:32:00 +02:00
parent 4035d840dd
commit 8152342c11
5 changed files with 87 additions and 91 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_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
/** \brief temporary IP address */
@ -172,7 +171,7 @@ void
uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
/* check if originating packet is not an ICMP error */
if(uip_ext_len) {
if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) {
if(UIP_EXT_BUF(uip_ext_len)->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) {
uip_clear_buf();
return;
}

View File

@ -93,6 +93,15 @@
#define UIP_TCP_BUF ((struct uip_tcp_hdr *)UIP_IP_PAYLOAD(uip_ext_len))
#define UIP_TCP_PAYLOAD ((unsigned char *)UIP_IP_PAYLOAD(uip_ext_len) + UIP_TCPH_LEN)
/**
* Direct access to extension headers, with explicit ext header offset
*/
#define UIP_EXT_BUF(ext) ((struct uip_ext_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_HBHO_BUF(ext) ((struct uip_hbho_hdr *)UIP_IP_PAYLOAD(ext))
#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))
#include "net/ipv6/uipopt.h"
#include "net/ipv6/uipbuf.h"
#include "net/linkaddr.h"

View File

@ -142,14 +142,8 @@ uint8_t uip_ext_opt_offset = 0;
* @{
*/
#define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0])
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_ROUTING_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_FRAG_BUF ((struct uip_frag_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_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_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
/** @} */
/**
* \name Buffer variables
@ -520,7 +514,7 @@ remove_ext_hdr(void)
}
last_uip_ext_len = uip_ext_len;
uip_ext_len = 0;
UIP_IP_BUF->proto = UIP_EXT_BUF->next;
UIP_IP_BUF->proto = UIP_EXT_BUF(uip_ext_len)->next;
memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + last_uip_ext_len,
uip_len - UIP_IPH_LEN - last_uip_ext_len);
@ -658,7 +652,7 @@ uip_reass(void)
etimer_set(&uip_reass_timer, UIP_REASS_MAXAGE*CLOCK_SECOND);
uip_reass_on = 1;
uip_reassflags = 0;
uip_id = UIP_FRAG_BUF->id;
uip_id = UIP_FRAG_BUF(uip_ext_len)->id;
/* Clear the bitmap. */
memset(uip_reassbitmap, 0, sizeof(uip_reassbitmap));
}
@ -669,9 +663,9 @@ uip_reass(void)
*/
if(uip_ipaddr_cmp(&FBUF->srcipaddr, &UIP_IP_BUF->srcipaddr) &&
uip_ipaddr_cmp(&FBUF->destipaddr, &UIP_IP_BUF->destipaddr) &&
UIP_FRAG_BUF->id == uip_id) {
UIP_FRAG_BUF(uip_ext_len)->id == uip_id) {
len = uip_len - uip_ext_len - UIP_IPH_LEN - UIP_FRAGH_LEN;
offset = (uip_ntohs(UIP_FRAG_BUF->offsetresmore) & 0xfff8);
offset = (uip_ntohs(UIP_FRAG_BUF(uip_ext_len)->offsetresmore) & 0xfff8);
/* in byte, originaly in multiple of 8 bytes*/
LOG_INFO("len %d\n", len);
LOG_INFO("offset %d\n", offset);
@ -682,7 +676,7 @@ uip_reass(void)
* Part is obtained from the Next Header field of the first
* fragment's Fragment header.
*/
*uip_next_hdr = UIP_FRAG_BUF->next;
*uip_next_hdr = UIP_FRAG_BUF(uip_ext_len)->next;
memcpy(FBUF, UIP_IP_BUF, uip_ext_len + UIP_IPH_LEN);
LOG_INFO("src ");
LOG_INFO_6ADDR(&FBUF->srcipaddr);
@ -703,7 +697,7 @@ uip_reass(void)
/* If this fragment has the More Fragments flag set to zero, it is the
last fragment*/
if((uip_ntohs(UIP_FRAG_BUF->offsetresmore) & IP_MF) == 0) {
if((uip_ntohs(UIP_FRAG_BUF(uip_ext_len)->offsetresmore) & IP_MF) == 0) {
uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
/*calculate the size of the entire packet*/
uip_reasslen = offset + len;
@ -727,7 +721,7 @@ uip_reass(void)
/* Copy the fragment into the reassembly buffer, at the right
offset. */
memcpy((uint8_t *)FBUF + UIP_IPH_LEN + uip_ext_len + offset,
(uint8_t *)UIP_FRAG_BUF + UIP_FRAGH_LEN, len);
(uint8_t *)UIP_FRAG_BUF(uip_ext_len) + UIP_FRAGH_LEN, len);
/* Update the bitmap. */
if(offset >> 6 == (offset + len) >> 6) {
@ -844,7 +838,7 @@ ext_hdr_options_process(void)
* length field in an option : the length of data in the option
*/
uip_ext_opt_offset = 2;
while(uip_ext_opt_offset < ((UIP_EXT_BUF->len << 3) + 8)) {
while(uip_ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) {
switch(UIP_EXT_HDR_OPT_BUF->type) {
/*
* for now we do not support any options except padding ones
@ -1150,8 +1144,8 @@ uip_process(uint8_t flag)
switch(ext_hdr_options_process()) {
case 0:
/* continue */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
case 1:
LOG_ERR("Dropping packet after extension header processing\n");
@ -1285,8 +1279,8 @@ uip_process(uint8_t flag)
switch(ext_hdr_options_process()) {
case 0:
/*continue*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
case 1:
/*silently discard*/
@ -1314,8 +1308,8 @@ uip_process(uint8_t flag)
switch(ext_hdr_options_process()) {
case 0:
/*continue*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
case 1:
/*silently discard*/
@ -1344,7 +1338,7 @@ uip_process(uint8_t flag)
*/
LOG_DBG("Processing Routing header\n");
if(UIP_ROUTING_BUF->seg_left > 0) {
if(UIP_RH_BUF(uip_ext_len)->seg_left > 0) {
if(NETSTACK_ROUTING.ext_header_srh_update()) {
/* With routing header, the detination address is us and will
@ -1378,8 +1372,8 @@ uip_process(uint8_t flag)
LOG_ERR("unrecognized routing type");
goto send;
}
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
case UIP_PROTO_FRAG:
/* Fragmentation header:call the reassembly function, then leave */

View File

@ -61,10 +61,7 @@
#include <string.h>
/*---------------------------------------------------------------------------*/
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
#define UIP_RH_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_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])
@ -80,12 +77,12 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
uip_ds6_route_t *route;
rpl_parent_t *sender = NULL;
if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
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) {
LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n",
UIP_HBHO_BUF->len,
UIP_HBHO_BUF(uip_ext_len)->len,
UIP_EXT_HDR_OPT_RPL_BUF->opt_type,
UIP_EXT_HDR_OPT_RPL_BUF->opt_len);
return 0; /* Drop */
@ -200,8 +197,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
* header.
*/
/* Move to next header */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
default:
uip_next_hdr = NULL;
@ -214,7 +211,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
dest_node = uip_sr_get_node(dag, &UIP_IP_BUF->destipaddr);
if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING
&& UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) ||
&& UIP_RH_BUF(uip_ext_len)->routing_type == RPL_RH_TYPE_SRH) ||
(dest_node != NULL && root_node != NULL &&
dest_node->parent == root_node)) {
/* Routing header found or the packet destined for a direct child of the root.
@ -255,8 +252,8 @@ rpl_ext_header_srh_update(void)
* header.
*/
/* Move to next header */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
default:
uip_next_hdr = NULL;
@ -265,7 +262,7 @@ rpl_ext_header_srh_update(void)
}
if(uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING
&& UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) {
&& UIP_RH_BUF(uip_ext_len)->routing_type == RPL_RH_TYPE_SRH) {
/* SRH found, now look for next hop */
uint8_t cmpri, cmpre;
uint8_t ext_len;
@ -274,8 +271,8 @@ rpl_ext_header_srh_update(void)
uint8_t segments_left;
uip_ipaddr_t current_dest_addr;
segments_left = UIP_RH_BUF->seg_left;
ext_len = (UIP_RH_BUF->len * 8) + 8;
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;
@ -289,7 +286,7 @@ rpl_ext_header_srh_update(void)
/* We are the final destination, do nothing */
} else {
uint8_t i = path_len - segments_left; /* The index of the next address to be visited */
uint8_t *addr_ptr = ((uint8_t *)UIP_RH_BUF) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri));
uint8_t *addr_ptr = ((uint8_t *)UIP_RH_BUF(uip_ext_len)) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri));
uint8_t cmpr = segments_left == 1 ? cmpre : cmpri;
/* As per RFC6554: swap the IPv6 destination address and address[i] */
@ -302,7 +299,7 @@ rpl_ext_header_srh_update(void)
memcpy(addr_ptr, ((uint8_t *)&current_dest_addr) + cmpr, 16 - cmpr);
/* Update segments left field */
UIP_RH_BUF->seg_left--;
UIP_RH_BUF(uip_ext_len)->seg_left--;
LOG_INFO("SRH next hop ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
@ -428,13 +425,13 @@ insert_srh_header(void)
memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len);
/* Insert source routing header */
UIP_RH_BUF->next = UIP_IP_BUF->proto;
UIP_RH_BUF(uip_ext_len)->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_ROUTING;
/* Initialize IPv6 Routing Header */
UIP_RH_BUF->len = (ext_len - 8) / 8;
UIP_RH_BUF->routing_type = RPL_RH_TYPE_SRH;
UIP_RH_BUF->seg_left = path_len;
UIP_RH_BUF(uip_ext_len)->len = (ext_len - 8) / 8;
UIP_RH_BUF(uip_ext_len)->routing_type = RPL_RH_TYPE_SRH;
UIP_RH_BUF(uip_ext_len)->seg_left = path_len;
/* Initialize RPL Source Routing Header */
UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre;
@ -443,7 +440,7 @@ insert_srh_header(void)
/* Initialize addresses field (the actual source route).
* From last to first. */
node = dest_node;
hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */
hop_ptr = ((uint8_t *)UIP_RH_BUF(uip_ext_len)) + ext_len - padding; /* Pointer where to write the next hop compressed address */
while(node != NULL && node->parent != root_node) {
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
@ -484,7 +481,7 @@ update_hbh_header(void)
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_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
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) {
LOG_ERR("Hop-by-hop extension header has wrong size (%u %u)\n",
@ -565,16 +562,16 @@ insert_hbh_header(const rpl_instance_t *instance)
return 0;
}
/* Move existing ext headers and payload UIP_EXT_BUF further */
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN);
/* 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);
/* Update IP and HBH protocol and fields */
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
UIP_HBHO_BUF(uip_ext_len)->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
/* Initialize HBH option */
UIP_HBHO_BUF->len = (RPL_HOP_BY_HOP_LEN - 8) / 8;
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;
@ -612,8 +609,8 @@ rpl_ext_header_remove(void)
case UIP_PROTO_ROUTING:
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) {
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF->next;
rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8;
*uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next;
rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->len * 8) + 8;
temp_len = UIP_IP_BUF->len[1];
uip_len -= rpl_ext_hdr_len;
UIP_IP_BUF->len[1] -= rpl_ext_hdr_len;
@ -621,10 +618,10 @@ rpl_ext_header_remove(void)
UIP_IP_BUF->len[0]--;
}
LOG_DBG("Removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len);
memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
memmove(UIP_EXT_BUF(uip_ext_len), ((uint8_t *)UIP_EXT_BUF(uip_ext_len)) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
} else {
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
}
break;
case UIP_PROTO_DESTO:
@ -637,8 +634,8 @@ rpl_ext_header_remove(void)
* UIP_PROTO_DESTO. Otherwise, we'll return.
*/
/* Move to next header */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
default:
return;

View File

@ -54,10 +54,7 @@
#define LOG_LEVEL LOG_LEVEL_RPL
/*---------------------------------------------------------------------------*/
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
#define UIP_RH_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_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])
@ -84,8 +81,8 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
* As per RFC 2460, only the Hop-by-Hop Options header and
* Destination Options header can appear before the Routing header.
*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
default:
uip_next_hdr = NULL;
@ -101,7 +98,7 @@ rpl_ext_header_srh_get_next_hop(uip_ipaddr_t *ipaddr)
dest_node = uip_sr_get_node(NULL, &UIP_IP_BUF->destipaddr);
if((uip_next_hdr != NULL && *uip_next_hdr == UIP_PROTO_ROUTING
&& UIP_RH_BUF->routing_type == RPL_RH_TYPE_SRH) ||
&& UIP_RH_BUF(uip_ext_len)->routing_type == RPL_RH_TYPE_SRH) ||
(dest_node != NULL && root_node != NULL &&
dest_node->parent == root_node)) {
/* Routing header found or the packet destined for a direct child of the root.
@ -143,8 +140,8 @@ rpl_ext_header_srh_update(void)
* As per RFC 2460, only the Hop-by-Hop Options header and
* Destination Options header can appear before the Routing header.
*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
default:
uip_next_hdr = NULL;
@ -153,15 +150,15 @@ rpl_ext_header_srh_update(void)
}
if(uip_next_hdr == NULL || *uip_next_hdr != UIP_PROTO_ROUTING
|| UIP_RH_BUF->routing_type != RPL_RH_TYPE_SRH) {
|| UIP_RH_BUF(uip_ext_len)->routing_type != RPL_RH_TYPE_SRH) {
LOG_INFO("SRH not found\n");
uip_ext_len = last_uip_ext_len;
return 0;
}
/* Parse SRH */
segments_left = UIP_RH_BUF->seg_left;
ext_len = (UIP_RH_BUF->len * 8) + 8;
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;
@ -176,7 +173,7 @@ rpl_ext_header_srh_update(void)
/* We are the final destination, do nothing */
} else {
uint8_t i = path_len - segments_left; /* The index of the next address to be visited */
uint8_t *addr_ptr = ((uint8_t *)UIP_RH_BUF) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri));
uint8_t *addr_ptr = ((uint8_t *)UIP_RH_BUF(uip_ext_len)) + RPL_RH_LEN + RPL_SRH_LEN + (i * (16 - cmpri));
uint8_t cmpr = segments_left == 1 ? cmpre : cmpri;
/* As per RFC6554: swap the IPv6 destination address with address[i] */
@ -189,7 +186,7 @@ rpl_ext_header_srh_update(void)
memcpy(addr_ptr, ((uint8_t *)&current_dest_addr) + cmpr, 16 - cmpr);
/* Update segments left field */
UIP_RH_BUF->seg_left--;
UIP_RH_BUF(uip_ext_len)->seg_left--;
LOG_INFO("SRH next hop ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
@ -314,13 +311,13 @@ insert_srh_header(void)
memset(uip_buf + uip_l2_l3_hdr_len, 0, ext_len);
/* Insert source routing header */
UIP_RH_BUF->next = UIP_IP_BUF->proto;
UIP_RH_BUF(uip_ext_len)->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_ROUTING;
/* Initialize IPv6 Routing Header */
UIP_RH_BUF->len = (ext_len - 8) / 8;
UIP_RH_BUF->routing_type = RPL_RH_TYPE_SRH;
UIP_RH_BUF->seg_left = path_len;
UIP_RH_BUF(uip_ext_len)->len = (ext_len - 8) / 8;
UIP_RH_BUF(uip_ext_len)->routing_type = RPL_RH_TYPE_SRH;
UIP_RH_BUF(uip_ext_len)->seg_left = path_len;
/* Initialize RPL Source Routing Header */
UIP_RPL_SRH_BUF->cmpr = (cmpri << 4) + cmpre;
@ -329,7 +326,7 @@ insert_srh_header(void)
/* Initialize addresses field (the actual source route).
* From last to first. */
node = dest_node;
hop_ptr = ((uint8_t *)UIP_RH_BUF) + ext_len - padding; /* Pointer where to write the next hop compressed address */
hop_ptr = ((uint8_t *)UIP_RH_BUF(uip_ext_len)) + ext_len - padding; /* Pointer where to write the next hop compressed address */
while(node != NULL && node->parent != root_node) {
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);
@ -369,11 +366,11 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset)
uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF->opt_type;
uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF->opt_len;
if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
if(UIP_HBHO_BUF(uip_ext_len)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| opt_type != UIP_EXT_HDR_OPT_RPL
|| 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->len, opt_type, opt_len);
UIP_HBHO_BUF(uip_ext_len)->len, opt_type, opt_len);
return 0; /* Drop */
}
@ -425,7 +422,7 @@ update_hbh_header(void)
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_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
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) {
LOG_ERR("hop-by-hop extension header has wrong size (%u %u)\n",
@ -471,16 +468,16 @@ insert_hbh_header(void)
return 0;
}
/* Move existing ext headers and payload UIP_EXT_BUF further */
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN);
/* 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);
/* Update IP and HBH protocol and fields */
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
UIP_HBHO_BUF(uip_ext_len)->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
/* Initialize HBH option */
UIP_HBHO_BUF->len = (RPL_HOP_BY_HOP_LEN - 8) / 8;
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;
@ -546,8 +543,8 @@ rpl_ext_header_remove(void)
case UIP_PROTO_ROUTING:
if((*uip_next_hdr != UIP_PROTO_HBHO || UIP_EXT_HDR_OPT_RPL_BUF->opt_type == UIP_EXT_HDR_OPT_RPL)) {
/* Remove hop-by-hop and routing headers */
*uip_next_hdr = UIP_EXT_BUF->next;
rpl_ext_hdr_len = (UIP_EXT_BUF->len * 8) + 8;
*uip_next_hdr = UIP_EXT_BUF(uip_ext_len)->next;
rpl_ext_hdr_len = (UIP_EXT_BUF(uip_ext_len)->len * 8) + 8;
temp_len = UIP_IP_BUF->len[1];
uip_len -= rpl_ext_hdr_len;
UIP_IP_BUF->len[1] -= rpl_ext_hdr_len;
@ -555,10 +552,10 @@ rpl_ext_header_remove(void)
UIP_IP_BUF->len[0]--;
}
LOG_INFO("removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len);
memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
memmove(UIP_EXT_BUF(uip_ext_len), ((uint8_t *)UIP_EXT_BUF(uip_ext_len)) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN);
} else {
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
}
break;
case UIP_PROTO_DESTO:
@ -571,8 +568,8 @@ rpl_ext_header_remove(void)
* UIP_PROTO_DESTO. Otherwise, we'll return.
*/
/* Move to next header */
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
uip_next_hdr = &UIP_EXT_BUF(uip_ext_len)->next;
uip_ext_len += (UIP_EXT_BUF(uip_ext_len)->len << 3) + 8;
break;
default:
return;