2011-11-16 09:00:19 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*/
|
2014-11-08 01:15:42 +01:00
|
|
|
|
2011-11-16 09:00:19 +01:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Management of extension headers for ContikiRPL.
|
|
|
|
*
|
2011-12-02 15:55:07 +01:00
|
|
|
* \author Vincent Brillault <vincent.brillault@imag.fr>,
|
|
|
|
* Joakim Eriksson <joakime@sics.se>,
|
|
|
|
* Niclas Finne <nfi@sics.se>,
|
|
|
|
* Nicolas Tsiftes <nvt@sics.se>.
|
2011-11-16 09:00:19 +01:00
|
|
|
*/
|
|
|
|
|
2014-11-08 01:15:42 +01:00
|
|
|
/**
|
|
|
|
* \addtogroup uip6
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip.h"
|
|
|
|
#include "net/ip/tcpip.h"
|
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2011-11-16 09:00:19 +01:00
|
|
|
#include "net/rpl/rpl-private.h"
|
2014-01-31 09:38:42 +01:00
|
|
|
#include "net/packetbuf.h"
|
2011-11-16 09:00:19 +01:00
|
|
|
|
|
|
|
#define DEBUG DEBUG_NONE
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip-debug.h"
|
2011-11-16 09:00:19 +01:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-11-22 14:18:32 +01:00
|
|
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
|
|
|
#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])
|
2011-12-02 15:55:07 +01:00
|
|
|
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
|
2011-11-22 14:18:32 +01:00
|
|
|
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
2011-11-16 09:00:19 +01:00
|
|
|
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
2011-11-22 14:18:32 +01:00
|
|
|
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-11-16 09:00:19 +01:00
|
|
|
int
|
|
|
|
rpl_verify_header(int uip_ext_opt_offset)
|
|
|
|
{
|
|
|
|
rpl_instance_t *instance;
|
2011-12-02 16:16:42 +01:00
|
|
|
int down;
|
2014-01-22 12:16:27 +01:00
|
|
|
uint16_t sender_rank;
|
2012-01-13 14:37:30 +01:00
|
|
|
uint8_t sender_closer;
|
2013-11-20 15:14:11 +01:00
|
|
|
uip_ds6_route_t *route;
|
2011-11-16 09:00:19 +01:00
|
|
|
|
2014-05-09 11:28:36 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-16 09:00:19 +01:00
|
|
|
if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|
|
|
|
PRINTF("RPL: Bad header option! (wrong length)\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance);
|
|
|
|
if(instance == NULL) {
|
2011-11-16 09:49:22 +01:00
|
|
|
PRINTF("RPL: Unknown instance: %u\n",
|
2011-11-16 09:00:19 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->instance);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-08-12 00:06:12 +02:00
|
|
|
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) {
|
2013-11-20 14:07:29 +01:00
|
|
|
PRINTF("RPL: Forward error!\n");
|
2013-08-12 00:06:12 +02:00
|
|
|
/* We should try to repair it by removing the neighbor that caused
|
|
|
|
the packet to be forwareded in the first place. We drop any
|
|
|
|
routes that go through the neighbor that sent the packet to
|
|
|
|
us. */
|
|
|
|
route = uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr);
|
|
|
|
if(route != NULL) {
|
|
|
|
uip_ds6_route_rm(route);
|
|
|
|
}
|
2014-01-22 15:26:43 +01:00
|
|
|
RPL_STAT(rpl_stats.forward_errors++);
|
|
|
|
/* Trigger DAO retransmission */
|
|
|
|
rpl_reset_dio_timer(instance);
|
|
|
|
/* drop the packet as it is not routable */
|
|
|
|
return 1;
|
2013-08-12 00:06:12 +02:00
|
|
|
}
|
|
|
|
|
2011-11-16 09:00:19 +01:00
|
|
|
if(!instance->current_dag->joined) {
|
|
|
|
PRINTF("RPL: No DAG in the instance\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-12-02 16:16:42 +01:00
|
|
|
down = 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) {
|
2011-12-02 16:16:42 +01:00
|
|
|
down = 1;
|
|
|
|
}
|
|
|
|
|
2014-01-22 12:16:27 +01:00
|
|
|
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF->senderrank);
|
|
|
|
sender_closer = sender_rank < instance->current_dag->rank;
|
2012-11-26 19:33:54 +01:00
|
|
|
|
|
|
|
PRINTF("RPL: Packet going %s, sender closer %d (%d < %d)\n", down == 1 ? "down" : "up",
|
|
|
|
sender_closer,
|
2014-01-22 12:16:27 +01:00
|
|
|
sender_rank,
|
2012-11-26 19:33:54 +01:00
|
|
|
instance->current_dag->rank
|
|
|
|
);
|
|
|
|
|
2012-01-13 14:37:30 +01:00
|
|
|
if((down && !sender_closer) || (!down && sender_closer)) {
|
|
|
|
PRINTF("RPL: Loop detected - senderrank: %d my-rank: %d sender_closer: %d\n",
|
2014-01-22 12:16:27 +01:00
|
|
|
sender_rank, instance->current_dag->rank,
|
2012-01-13 14:37:30 +01:00
|
|
|
sender_closer);
|
2011-12-02 16:16:42 +01:00
|
|
|
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) {
|
2014-01-16 09:24:55 +01:00
|
|
|
RPL_STAT(rpl_stats.loop_errors++);
|
2011-12-02 16:16:42 +01:00
|
|
|
PRINTF("RPL: Rank error signalled in RPL option!\n");
|
2014-01-31 09:37:35 +01:00
|
|
|
/* Packet must be dropped and dio trickle timer reset, see RFC6550 - 11.2.2.2 */
|
2013-08-12 00:07:13 +02:00
|
|
|
rpl_reset_dio_timer(instance);
|
2014-01-31 09:37:35 +01:00
|
|
|
return 1;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
2011-12-02 16:16:42 +01:00
|
|
|
PRINTF("RPL: Single error tolerated\n");
|
2014-01-16 09:24:55 +01:00
|
|
|
RPL_STAT(rpl_stats.loop_warnings++);
|
2011-12-02 16:16:42 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
|
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PRINTF("RPL: Rank OK\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-12-02 15:55:07 +01:00
|
|
|
static void
|
|
|
|
set_rpl_opt(unsigned uip_ext_opt_offset)
|
|
|
|
{
|
|
|
|
uint8_t temp_len;
|
|
|
|
|
|
|
|
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
|
|
|
|
memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN);
|
|
|
|
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
|
|
|
|
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
|
|
|
|
UIP_HBHO_BUF->len = RPL_HOP_BY_HOP_LEN - 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;
|
2011-12-02 16:16:42 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->flags = 0;
|
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->instance = 0;
|
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = 0;
|
2011-12-02 15:55:07 +01:00
|
|
|
uip_len += RPL_HOP_BY_HOP_LEN;
|
|
|
|
temp_len = UIP_IP_BUF->len[1];
|
|
|
|
UIP_IP_BUF->len[1] += UIP_HBHO_BUF->len + 8;
|
|
|
|
if(UIP_IP_BUF->len[1] < temp_len) {
|
|
|
|
UIP_IP_BUF->len[0]++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-01-31 09:38:42 +01:00
|
|
|
int
|
2011-11-16 09:00:19 +01:00
|
|
|
rpl_update_header_empty(void)
|
|
|
|
{
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
int uip_ext_opt_offset;
|
|
|
|
int last_uip_ext_len;
|
2014-01-31 09:38:42 +01:00
|
|
|
rpl_parent_t *parent;
|
2011-11-16 09:00:19 +01:00
|
|
|
|
|
|
|
last_uip_ext_len = uip_ext_len;
|
|
|
|
uip_ext_len = 0;
|
|
|
|
uip_ext_opt_offset = 2;
|
|
|
|
|
|
|
|
PRINTF("RPL: Verifying the presence of the RPL header option\n");
|
2011-11-23 14:36:50 +01:00
|
|
|
|
2011-11-16 09:00:19 +01:00
|
|
|
switch(UIP_IP_BUF->proto) {
|
|
|
|
case UIP_PROTO_HBHO:
|
2011-12-02 15:55:07 +01:00
|
|
|
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) {
|
2014-05-09 11:28:36 +02:00
|
|
|
PRINTF("RPL: Hop-by-hop extension header has wrong size\n");
|
|
|
|
uip_ext_len = last_uip_ext_len;
|
2014-12-15 17:34:22 +01:00
|
|
|
return 0;
|
2014-05-09 11:28:36 +02:00
|
|
|
}
|
|
|
|
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;
|
2014-12-15 17:34:22 +01:00
|
|
|
return 0;
|
2014-05-09 11:28:36 +02:00
|
|
|
}
|
|
|
|
if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
|
|
|
|
PRINTF("RPL: RPL Hop-by-hop option has wrong length\n");
|
2011-11-16 09:00:19 +01:00
|
|
|
uip_ext_len = last_uip_ext_len;
|
2014-01-31 09:38:42 +01:00
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance);
|
|
|
|
if(instance == NULL || !instance->used || !instance->current_dag->joined) {
|
|
|
|
PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect instance\n");
|
2014-01-31 09:38:42 +01:00
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2014-08-08 15:08:15 +02:00
|
|
|
#if RPL_INSERT_HBH_OPTION
|
2011-11-16 09:00:19 +01:00
|
|
|
PRINTF("RPL: No hop-by-hop option found, creating it\n");
|
2012-01-10 15:51:06 +01:00
|
|
|
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) {
|
2011-11-16 09:00:19 +01:00
|
|
|
PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n");
|
|
|
|
uip_ext_len = last_uip_ext_len;
|
2014-01-31 09:38:42 +01:00
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
2011-12-02 15:55:07 +01:00
|
|
|
set_rpl_opt(uip_ext_opt_offset);
|
|
|
|
uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN;
|
2014-08-08 15:08:15 +02:00
|
|
|
#endif
|
2014-01-31 09:38:42 +01:00
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(UIP_EXT_HDR_OPT_BUF->type) {
|
|
|
|
case UIP_EXT_HDR_OPT_RPL:
|
|
|
|
PRINTF("RPL: Updating RPL option\n");
|
2014-01-22 12:16:27 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank);
|
2012-11-26 19:33:54 +01:00
|
|
|
|
2013-08-12 00:06:12 +02:00
|
|
|
/* 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_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) {
|
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_FWD_ERR;
|
|
|
|
PRINTF("RPL forwarding error\n");
|
2014-01-31 09:38:42 +01:00
|
|
|
/* We should send back the packet to the originating parent,
|
|
|
|
but it is not feasible yet, so we send a No-Path DAO instead */
|
|
|
|
PRINTF("RPL generate No-Path DAO\n");
|
|
|
|
parent = rpl_get_parent((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
|
|
|
if(parent != NULL) {
|
|
|
|
dao_output_target(parent, &UIP_IP_BUF->destipaddr, RPL_ZERO_LIFETIME);
|
|
|
|
}
|
|
|
|
/* Drop packet */
|
|
|
|
return 1;
|
2013-08-12 00:06:12 +02:00
|
|
|
}
|
2012-11-26 19:33:54 +01:00
|
|
|
} else {
|
2013-08-12 00:06:12 +02:00
|
|
|
/* Set the down extension flag correctly as described in Section
|
|
|
|
11.2 of RFC6550. If the packet progresses along a DAO route,
|
|
|
|
the down flag should be set. */
|
|
|
|
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;
|
|
|
|
PRINTF("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;
|
|
|
|
PRINTF("RPL option going down\n");
|
|
|
|
}
|
2012-11-26 19:33:54 +01:00
|
|
|
}
|
|
|
|
|
2011-11-16 09:00:19 +01:00
|
|
|
uip_ext_len = last_uip_ext_len;
|
2014-01-31 09:38:42 +01:00
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
default:
|
|
|
|
PRINTF("RPL: Multi Hop-by-hop options not implemented\n");
|
|
|
|
uip_ext_len = last_uip_ext_len;
|
2014-01-31 09:38:42 +01:00
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-11-16 09:00:19 +01:00
|
|
|
int
|
|
|
|
rpl_update_header_final(uip_ipaddr_t *addr)
|
|
|
|
{
|
2011-11-23 14:36:50 +01:00
|
|
|
rpl_parent_t *parent;
|
2011-11-16 09:00:19 +01:00
|
|
|
int uip_ext_opt_offset;
|
|
|
|
int last_uip_ext_len;
|
|
|
|
|
2011-11-23 14:36:50 +01:00
|
|
|
last_uip_ext_len = uip_ext_len;
|
|
|
|
uip_ext_len = 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
uip_ext_opt_offset = 2;
|
|
|
|
|
|
|
|
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO) {
|
2011-12-02 15:55:07 +01:00
|
|
|
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) {
|
2011-11-16 09:00:19 +01:00
|
|
|
PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n");
|
|
|
|
uip_ext_len = last_uip_ext_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(UIP_EXT_HDR_OPT_BUF->type == UIP_EXT_HDR_OPT_RPL) {
|
|
|
|
if(UIP_EXT_HDR_OPT_RPL_BUF->senderrank == 0) {
|
|
|
|
PRINTF("RPL: Updating RPL option\n");
|
|
|
|
if(default_instance == NULL || !default_instance->used || !default_instance->current_dag->joined) {
|
|
|
|
PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect default instance\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
parent = rpl_find_parent(default_instance->current_dag, addr);
|
|
|
|
if(parent == NULL || parent != parent->dag->preferred_parent) {
|
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->flags = RPL_HDR_OPT_DOWN;
|
|
|
|
}
|
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->instance = default_instance->instance_id;
|
2014-01-22 12:16:27 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(default_instance->current_dag->rank);
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-11-16 09:00:19 +01:00
|
|
|
void
|
|
|
|
rpl_remove_header(void)
|
|
|
|
{
|
2011-12-02 15:55:07 +01:00
|
|
|
uint8_t temp_len;
|
2011-11-16 09:00:19 +01:00
|
|
|
|
|
|
|
uip_ext_len = 0;
|
|
|
|
|
|
|
|
PRINTF("RPL: Verifying the presence of the RPL header option\n");
|
|
|
|
switch(UIP_IP_BUF->proto){
|
2011-11-23 14:36:50 +01:00
|
|
|
case UIP_PROTO_HBHO:
|
2011-12-02 16:16:42 +01:00
|
|
|
PRINTF("RPL: Removing the RPL header option\n");
|
2011-11-23 14:36:50 +01:00
|
|
|
UIP_IP_BUF->proto = UIP_HBHO_BUF->next;
|
|
|
|
temp_len = UIP_IP_BUF->len[1];
|
|
|
|
uip_len -= UIP_HBHO_BUF->len + 8;
|
|
|
|
UIP_IP_BUF->len[1] -= UIP_HBHO_BUF->len + 8;
|
|
|
|
if(UIP_IP_BUF->len[1] > temp_len) {
|
|
|
|
UIP_IP_BUF->len[0]--;
|
|
|
|
}
|
|
|
|
memmove(UIP_EXT_BUF, UIP_HBHO_NEXT_BUF, uip_len - UIP_IPH_LEN);
|
|
|
|
break;
|
|
|
|
default:
|
2011-12-02 16:16:42 +01:00
|
|
|
PRINTF("RPL: No hop-by-hop Option found\n");
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
|
|
|
}
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-12-02 15:55:07 +01:00
|
|
|
uint8_t
|
2011-11-16 09:00:19 +01:00
|
|
|
rpl_invert_header(void)
|
|
|
|
{
|
2011-12-02 15:55:07 +01:00
|
|
|
uint8_t uip_ext_opt_offset;
|
|
|
|
uint8_t last_uip_ext_len;
|
2011-11-16 09:00:19 +01:00
|
|
|
|
|
|
|
last_uip_ext_len = uip_ext_len;
|
|
|
|
uip_ext_len = 0;
|
|
|
|
uip_ext_opt_offset = 2;
|
|
|
|
|
|
|
|
PRINTF("RPL: Verifying the presence of the RPL header option\n");
|
|
|
|
switch(UIP_IP_BUF->proto) {
|
2011-11-23 14:36:50 +01:00
|
|
|
case UIP_PROTO_HBHO:
|
|
|
|
break;
|
|
|
|
default:
|
2011-12-02 16:16:42 +01:00
|
|
|
PRINTF("RPL: No hop-by-hop Option found\n");
|
2011-11-23 14:36:50 +01:00
|
|
|
uip_ext_len = last_uip_ext_len;
|
|
|
|
return 0;
|
2011-11-16 09:00:19 +01:00
|
|
|
}
|
2011-12-02 16:16:42 +01:00
|
|
|
|
2011-11-16 09:00:19 +01:00
|
|
|
switch (UIP_EXT_HDR_OPT_BUF->type) {
|
|
|
|
case UIP_EXT_HDR_OPT_RPL:
|
2011-12-02 16:16:42 +01:00
|
|
|
PRINTF("RPL: Updating RPL option (switching direction)\n");
|
2011-11-16 09:00:19 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->flags &= RPL_HDR_OPT_DOWN;
|
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->flags ^= RPL_HDR_OPT_DOWN;
|
2014-01-22 12:16:27 +01:00
|
|
|
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank);
|
2011-11-16 09:00:19 +01:00
|
|
|
uip_ext_len = last_uip_ext_len;
|
2011-12-02 15:55:07 +01:00
|
|
|
return RPL_HOP_BY_HOP_LEN;
|
2011-11-16 09:00:19 +01:00
|
|
|
default:
|
|
|
|
PRINTF("RPL: Multi Hop-by-hop options not implemented\n");
|
|
|
|
uip_ext_len = last_uip_ext_len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 11:47:02 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2013-07-31 22:39:00 +02:00
|
|
|
void
|
|
|
|
rpl_insert_header(void)
|
|
|
|
{
|
2014-08-08 15:08:15 +02:00
|
|
|
#if RPL_INSERT_HBH_OPTION
|
2014-01-22 14:25:28 +01:00
|
|
|
if(default_instance != NULL && !uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
|
|
|
|
rpl_update_header_empty();
|
2013-07-31 22:39:00 +02:00
|
|
|
}
|
2014-08-08 15:08:15 +02:00
|
|
|
#endif
|
2013-07-31 22:39:00 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-30 11:01:20 +02:00
|
|
|
|
|
|
|
/** @}*/
|