2010-04-30 15:43:53 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, 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
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* ICMP6 I/O for RPL control messages.
|
|
|
|
*
|
|
|
|
* \author Joakim Eriksson <joakime@sics.se>, Nicolas Tsiftes <nvt@sics.se>
|
2010-05-01 01:10:45 +02:00
|
|
|
* Contributors: Niclas Finne <nfi@sics.se>, Joel Hoglund <joel@sics.se>,
|
2010-04-30 15:43:53 +02:00
|
|
|
* Mathieu Pouillot <m.pouillot@watteco.com>
|
2011-12-09 13:15:04 +01:00
|
|
|
* George Oikonomou <oikonomou@users.sourceforge.net> (multicast)
|
2010-04-30 15:43:53 +02:00
|
|
|
*/
|
|
|
|
|
2014-11-08 01:15:42 +01:00
|
|
|
/**
|
|
|
|
* \addtogroup uip6
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/tcpip.h"
|
|
|
|
#include "net/ip/uip.h"
|
|
|
|
#include "net/ipv6/uip-ds6.h"
|
|
|
|
#include "net/ipv6/uip-nd6.h"
|
|
|
|
#include "net/ipv6/uip-icmp6.h"
|
2011-02-11 16:21:17 +01:00
|
|
|
#include "net/rpl/rpl-private.h"
|
2016-02-01 18:02:33 +01:00
|
|
|
#include "net/rpl/rpl-ns.h"
|
2010-06-14 21:19:16 +02:00
|
|
|
#include "net/packetbuf.h"
|
2011-12-09 13:15:04 +01:00
|
|
|
#include "net/ipv6/multicast/uip-mcast6.h"
|
2015-10-02 07:38:52 +02:00
|
|
|
#include "random.h"
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
#include <limits.h>
|
2010-05-19 18:16:57 +02:00
|
|
|
#include <string.h>
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-11-03 16:41:23 +01:00
|
|
|
#define DEBUG DEBUG_NONE
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2013-11-22 09:17:54 +01:00
|
|
|
#include "net/ip/uip-debug.h"
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-06-06 23:42:50 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-12-13 11:54:25 +01:00
|
|
|
#define RPL_DIO_GROUNDED 0x80
|
|
|
|
#define RPL_DIO_MOP_SHIFT 3
|
2015-02-11 09:26:51 +01:00
|
|
|
#define RPL_DIO_MOP_MASK 0x38
|
2010-12-13 11:54:25 +01:00
|
|
|
#define RPL_DIO_PREFERENCE_MASK 0x07
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
|
|
|
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
|
|
|
#define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
2010-06-06 23:42:50 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 15:43:53 +02:00
|
|
|
static void dis_input(void);
|
|
|
|
static void dio_input(void);
|
|
|
|
static void dao_input(void);
|
2010-06-06 23:42:50 +02:00
|
|
|
static void dao_ack_input(void);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2015-08-19 15:50:20 +02:00
|
|
|
static void dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
|
2017-02-07 23:11:36 +01:00
|
|
|
uint8_t lifetime, uint8_t seq_no);
|
2015-08-19 15:50:20 +02:00
|
|
|
|
2011-10-27 12:32:16 +02:00
|
|
|
/* some debug callbacks useful when debugging RPL networks */
|
|
|
|
#ifdef RPL_DEBUG_DIO_INPUT
|
|
|
|
void RPL_DEBUG_DIO_INPUT(uip_ipaddr_t *, rpl_dio_t *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RPL_DEBUG_DAO_OUTPUT
|
|
|
|
void RPL_DEBUG_DAO_OUTPUT(rpl_parent_t *);
|
|
|
|
#endif
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
static uint8_t dao_sequence = RPL_LOLLIPOP_INIT;
|
2011-11-21 15:09:19 +01:00
|
|
|
|
2016-06-20 16:35:09 +02:00
|
|
|
#if RPL_WITH_MULTICAST
|
2011-12-09 13:15:04 +01:00
|
|
|
static uip_mcast6_route_t *mcast_group;
|
|
|
|
#endif
|
2010-06-06 23:42:50 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-03-08 22:36:45 +01:00
|
|
|
/* Initialise RPL ICMPv6 message handlers */
|
|
|
|
UIP_ICMP6_HANDLER(dis_handler, ICMP6_RPL, RPL_CODE_DIS, dis_input);
|
|
|
|
UIP_ICMP6_HANDLER(dio_handler, ICMP6_RPL, RPL_CODE_DIO, dio_input);
|
|
|
|
UIP_ICMP6_HANDLER(dao_handler, ICMP6_RPL, RPL_CODE_DAO, dao_input);
|
|
|
|
UIP_ICMP6_HANDLER(dao_ack_handler, ICMP6_RPL, RPL_CODE_DAO_ACK, dao_ack_input);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-09-22 21:01:55 +02:00
|
|
|
|
2015-08-19 15:50:20 +02:00
|
|
|
#if RPL_WITH_DAO_ACK
|
|
|
|
static uip_ds6_route_t *
|
|
|
|
find_route_entry_by_dao_ack(uint8_t seq)
|
|
|
|
{
|
|
|
|
uip_ds6_route_t *re;
|
|
|
|
re = uip_ds6_route_head();
|
|
|
|
while(re != NULL) {
|
|
|
|
if(re->state.dao_seqno_out == seq && RPL_ROUTE_IS_DAO_PENDING(re)) {
|
|
|
|
/* found it! */
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
re = uip_ds6_route_next(re);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
|
|
|
|
2016-02-01 18:02:33 +01:00
|
|
|
#if RPL_WITH_STORING
|
2015-08-19 15:50:20 +02:00
|
|
|
/* prepare for forwarding of DAO */
|
|
|
|
static uint8_t
|
|
|
|
prepare_for_dao_fwd(uint8_t sequence, uip_ds6_route_t *rep)
|
|
|
|
{
|
|
|
|
/* not pending - or pending but not a retransmission */
|
|
|
|
RPL_LOLLIPOP_INCREMENT(dao_sequence);
|
|
|
|
|
|
|
|
/* set DAO pending and sequence numbers */
|
|
|
|
rep->state.dao_seqno_in = sequence;
|
|
|
|
rep->state.dao_seqno_out = dao_sequence;
|
|
|
|
RPL_ROUTE_SET_DAO_PENDING(rep);
|
|
|
|
return dao_sequence;
|
|
|
|
}
|
2016-02-01 18:02:33 +01:00
|
|
|
#endif /* RPL_WITH_STORING */
|
2015-08-19 15:50:20 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 15:43:53 +02:00
|
|
|
static int
|
|
|
|
get_global_addr(uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
int i;
|
2010-05-01 01:10:45 +02:00
|
|
|
int state;
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
|
2010-05-01 01:10:45 +02:00
|
|
|
state = uip_ds6_if.addr_list[i].state;
|
2010-04-30 15:43:53 +02:00
|
|
|
if(uip_ds6_if.addr_list[i].isused &&
|
|
|
|
(state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
|
2015-10-20 11:18:46 +02:00
|
|
|
if(!uip_is_addr_linklocal(&uip_ds6_if.addr_list[i].ipaddr)) {
|
2010-04-30 15:43:53 +02:00
|
|
|
memcpy(addr, &uip_ds6_if.addr_list[i].ipaddr, sizeof(uip_ipaddr_t));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static uint32_t
|
|
|
|
get32(uint8_t *buffer, int pos)
|
|
|
|
{
|
2017-02-07 23:11:36 +01:00
|
|
|
return ((uint32_t)buffer[pos] << 24 | (uint32_t)buffer[pos + 1] << 16 |
|
|
|
|
(uint32_t)buffer[pos + 2] << 8 | buffer[pos + 3]);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
set32(uint8_t *buffer, int pos, uint32_t value)
|
|
|
|
{
|
|
|
|
buffer[pos++] = value >> 24;
|
|
|
|
buffer[pos++] = (value >> 16) & 0xff;
|
|
|
|
buffer[pos++] = (value >> 8) & 0xff;
|
|
|
|
buffer[pos++] = value & 0xff;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-09-06 17:28:39 +02:00
|
|
|
static uint16_t
|
|
|
|
get16(uint8_t *buffer, int pos)
|
|
|
|
{
|
|
|
|
return (uint16_t)buffer[pos] << 8 | buffer[pos + 1];
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
set16(uint8_t *buffer, int pos, uint16_t value)
|
|
|
|
{
|
|
|
|
buffer[pos++] = value >> 8;
|
|
|
|
buffer[pos++] = value & 0xff;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-08-20 17:09:32 +02:00
|
|
|
uip_ds6_nbr_t *
|
2015-09-20 21:02:30 +02:00
|
|
|
rpl_icmp6_update_nbr_table(uip_ipaddr_t *from, nbr_table_reason_t reason, void *data)
|
2015-08-20 17:09:32 +02:00
|
|
|
{
|
|
|
|
uip_ds6_nbr_t *nbr;
|
|
|
|
|
|
|
|
if((nbr = uip_ds6_nbr_lookup(from)) == NULL) {
|
|
|
|
if((nbr = uip_ds6_nbr_add(from, (uip_lladdr_t *)
|
|
|
|
packetbuf_addr(PACKETBUF_ADDR_SENDER),
|
2015-09-20 21:02:30 +02:00
|
|
|
0, NBR_REACHABLE, reason, data)) != NULL) {
|
2015-08-20 17:09:32 +02:00
|
|
|
PRINTF("RPL: Neighbor added to neighbor cache ");
|
|
|
|
PRINT6ADDR(from);
|
|
|
|
PRINTF(", ");
|
|
|
|
PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
|
|
|
PRINTF("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nbr;
|
2017-02-07 23:11:36 +01:00
|
|
|
}
|
2015-08-20 17:09:32 +02:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 15:43:53 +02:00
|
|
|
static void
|
|
|
|
dis_input(void)
|
|
|
|
{
|
2011-07-11 15:50:51 +02:00
|
|
|
rpl_instance_t *instance;
|
|
|
|
rpl_instance_t *end;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
/* DAG Information Solicitation */
|
|
|
|
PRINTF("RPL: Received a DIS from ");
|
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2013-11-20 14:10:10 +01:00
|
|
|
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
|
|
|
|
instance < end; ++instance) {
|
2012-04-22 00:18:07 +02:00
|
|
|
if(instance->used == 1) {
|
2017-02-07 23:09:04 +01:00
|
|
|
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
|
2011-07-11 15:50:51 +02:00
|
|
|
#if RPL_LEAF_ONLY
|
2017-02-07 23:09:04 +01:00
|
|
|
PRINTF("RPL: LEAF ONLY Multicast DIS will NOT reset DIO timer\n");
|
2011-07-11 15:50:51 +02:00
|
|
|
#else /* !RPL_LEAF_ONLY */
|
|
|
|
PRINTF("RPL: Multicast DIS => reset DIO timer\n");
|
2012-01-04 11:22:11 +01:00
|
|
|
rpl_reset_dio_timer(instance);
|
2011-07-11 15:50:51 +02:00
|
|
|
#endif /* !RPL_LEAF_ONLY */
|
2017-02-07 23:09:04 +01:00
|
|
|
} else {
|
|
|
|
/* Check if this neighbor should be added according to the policy. */
|
2015-09-20 21:02:30 +02:00
|
|
|
if(rpl_icmp6_update_nbr_table(&UIP_IP_BUF->srcipaddr,
|
|
|
|
NBR_TABLE_REASON_RPL_DIS, NULL) == NULL) {
|
|
|
|
PRINTF("RPL: Out of Memory, not sending unicast DIO, DIS from ");
|
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF(", ");
|
|
|
|
PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
|
|
|
PRINTF("\n");
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Unicast DIS, reply to sender\n");
|
|
|
|
dio_output(instance, &UIP_IP_BUF->srcipaddr);
|
|
|
|
}
|
2017-02-07 23:11:36 +01:00
|
|
|
/* } */
|
2011-07-11 15:50:51 +02:00
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
dis_output(uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
unsigned char *buffer;
|
|
|
|
uip_ipaddr_t tmpaddr;
|
|
|
|
|
2014-03-27 16:17:47 +01:00
|
|
|
/*
|
|
|
|
* DAG Information Solicitation - 2 bytes reserved
|
|
|
|
* 0 1 2
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Flags | Reserved | Option(s)...
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
2010-06-06 14:45:55 +02:00
|
|
|
buffer[0] = buffer[1] = 0;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
if(addr == NULL) {
|
2011-01-25 10:55:12 +01:00
|
|
|
uip_create_linklocal_rplnodes_mcast(&tmpaddr);
|
2010-04-30 15:43:53 +02:00
|
|
|
addr = &tmpaddr;
|
|
|
|
}
|
2012-04-22 00:18:07 +02:00
|
|
|
|
|
|
|
PRINTF("RPL: Sending a DIS to ");
|
|
|
|
PRINT6ADDR(addr);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2010-06-06 14:45:55 +02:00
|
|
|
uip_icmp6_send(addr, ICMP6_RPL, RPL_CODE_DIS, 2);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
dio_input(void)
|
|
|
|
{
|
|
|
|
unsigned char *buffer;
|
|
|
|
uint8_t buffer_length;
|
|
|
|
rpl_dio_t dio;
|
|
|
|
uint8_t subopt_type;
|
|
|
|
int i;
|
|
|
|
int len;
|
|
|
|
uip_ipaddr_t from;
|
|
|
|
|
2011-09-05 20:28:50 +02:00
|
|
|
memset(&dio, 0, sizeof(dio));
|
|
|
|
|
2012-02-29 21:59:50 +01:00
|
|
|
/* Set default values in case the DIO configuration option is missing. */
|
|
|
|
dio.dag_intdoubl = RPL_DIO_INTERVAL_DOUBLINGS;
|
|
|
|
dio.dag_intmin = RPL_DIO_INTERVAL_MIN;
|
|
|
|
dio.dag_redund = RPL_DIO_REDUNDANCY;
|
|
|
|
dio.dag_min_hoprankinc = RPL_MIN_HOPRANKINC;
|
|
|
|
dio.dag_max_rankinc = RPL_MAX_RANKINC;
|
2015-11-29 21:48:06 +01:00
|
|
|
dio.ocp = RPL_OF_OCP;
|
2012-02-29 21:59:50 +01:00
|
|
|
dio.default_lifetime = RPL_DEFAULT_LIFETIME;
|
|
|
|
dio.lifetime_unit = RPL_DEFAULT_LIFETIME_UNIT;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
uip_ipaddr_copy(&from, &UIP_IP_BUF->srcipaddr);
|
|
|
|
|
|
|
|
/* DAG Information Object */
|
|
|
|
PRINTF("RPL: Received a DIO from ");
|
|
|
|
PRINT6ADDR(&from);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2012-03-08 00:48:04 +01:00
|
|
|
buffer_length = uip_len - uip_l3_icmp_hdr_len;
|
2011-06-28 14:19:48 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
/* Process the DIO base option. */
|
|
|
|
i = 0;
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
2010-06-02 00:30:02 +02:00
|
|
|
|
|
|
|
dio.instance_id = buffer[i++];
|
|
|
|
dio.version = buffer[i++];
|
2011-09-06 17:28:39 +02:00
|
|
|
dio.rank = get16(buffer, i);
|
2010-06-02 00:30:02 +02:00
|
|
|
i += 2;
|
|
|
|
|
2012-02-29 21:59:50 +01:00
|
|
|
PRINTF("RPL: Incoming DIO (id, ver, rank) = (%u,%u,%u)\n",
|
|
|
|
(unsigned)dio.instance_id,
|
2014-05-30 11:01:20 +02:00
|
|
|
(unsigned)dio.version,
|
2012-02-29 21:59:50 +01:00
|
|
|
(unsigned)dio.rank);
|
2010-06-14 14:44:37 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
dio.grounded = buffer[i] & RPL_DIO_GROUNDED;
|
2010-12-13 11:54:25 +01:00
|
|
|
dio.mop = (buffer[i]& RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT;
|
|
|
|
dio.preference = buffer[i++] & RPL_DIO_PREFERENCE_MASK;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
dio.dtsn = buffer[i++];
|
2010-06-02 00:30:02 +02:00
|
|
|
/* two reserved bytes */
|
|
|
|
i += 2;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
memcpy(&dio.dag_id, buffer + i, sizeof(dio.dag_id));
|
|
|
|
i += sizeof(dio.dag_id);
|
|
|
|
|
2012-02-29 21:59:50 +01:00
|
|
|
PRINTF("RPL: Incoming DIO (dag_id, pref) = (");
|
2011-07-11 15:50:51 +02:00
|
|
|
PRINT6ADDR(&dio.dag_id);
|
2012-02-29 21:59:50 +01:00
|
|
|
PRINTF(", %u)\n", dio.preference);
|
2011-07-11 15:50:51 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
/* Check if there are any DIO suboptions. */
|
|
|
|
for(; i < buffer_length; i += len) {
|
|
|
|
subopt_type = buffer[i];
|
2011-09-05 20:28:50 +02:00
|
|
|
if(subopt_type == RPL_OPTION_PAD1) {
|
2010-04-30 15:43:53 +02:00
|
|
|
len = 1;
|
|
|
|
} else {
|
2010-06-02 00:30:02 +02:00
|
|
|
/* Suboption with a two-byte header + payload */
|
|
|
|
len = 2 + buffer[i + 1];
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
|
2010-10-27 02:46:40 +02:00
|
|
|
if(len + i > buffer_length) {
|
|
|
|
PRINTF("RPL: Invalid DIO packet\n");
|
|
|
|
RPL_STAT(rpl_stats.malformed_msgs++);
|
2015-08-26 16:48:34 +02:00
|
|
|
goto discard;
|
2010-10-27 02:46:40 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 20:28:50 +02:00
|
|
|
PRINTF("RPL: DIO option %u, length: %u\n", subopt_type, len - 2);
|
2011-02-15 01:13:30 +01:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
switch(subopt_type) {
|
2017-02-07 23:11:36 +01:00
|
|
|
case RPL_OPTION_DAG_METRIC_CONTAINER:
|
|
|
|
if(len < 6) {
|
|
|
|
PRINTF("RPL: Invalid DAG MC, len = %d\n", len);
|
|
|
|
RPL_STAT(rpl_stats.malformed_msgs++);
|
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
dio.mc.type = buffer[i + 2];
|
|
|
|
dio.mc.flags = buffer[i + 3] << 1;
|
|
|
|
dio.mc.flags |= buffer[i + 4] >> 7;
|
|
|
|
dio.mc.aggr = (buffer[i + 4] >> 4) & 0x3;
|
|
|
|
dio.mc.prec = buffer[i + 4] & 0xf;
|
|
|
|
dio.mc.length = buffer[i + 5];
|
|
|
|
|
|
|
|
if(dio.mc.type == RPL_DAG_MC_NONE) {
|
|
|
|
/* No metric container: do nothing */
|
|
|
|
} else if(dio.mc.type == RPL_DAG_MC_ETX) {
|
|
|
|
dio.mc.obj.etx = get16(buffer, i + 6);
|
|
|
|
|
|
|
|
PRINTF("RPL: DAG MC: type %u, flags %u, aggr %u, prec %u, length %u, ETX %u\n",
|
|
|
|
(unsigned)dio.mc.type,
|
|
|
|
(unsigned)dio.mc.flags,
|
|
|
|
(unsigned)dio.mc.aggr,
|
|
|
|
(unsigned)dio.mc.prec,
|
|
|
|
(unsigned)dio.mc.length,
|
|
|
|
(unsigned)dio.mc.obj.etx);
|
|
|
|
} else if(dio.mc.type == RPL_DAG_MC_ENERGY) {
|
|
|
|
dio.mc.obj.energy.flags = buffer[i + 6];
|
|
|
|
dio.mc.obj.energy.energy_est = buffer[i + 7];
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Unhandled DAG MC type: %u\n", (unsigned)dio.mc.type);
|
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RPL_OPTION_ROUTE_INFO:
|
|
|
|
if(len < 9) {
|
|
|
|
PRINTF("RPL: Invalid destination prefix option, len = %d\n", len);
|
|
|
|
RPL_STAT(rpl_stats.malformed_msgs++);
|
|
|
|
goto discard;
|
|
|
|
}
|
2011-02-13 23:17:56 +01:00
|
|
|
|
2017-02-07 23:11:36 +01:00
|
|
|
/* The flags field includes the preference value. */
|
|
|
|
dio.destination_prefix.length = buffer[i + 2];
|
|
|
|
dio.destination_prefix.flags = buffer[i + 3];
|
|
|
|
dio.destination_prefix.lifetime = get32(buffer, i + 4);
|
2010-06-02 00:30:02 +02:00
|
|
|
|
2017-02-07 23:11:36 +01:00
|
|
|
if(((dio.destination_prefix.length + 7) / 8) + 8 <= len &&
|
|
|
|
dio.destination_prefix.length <= 128) {
|
|
|
|
PRINTF("RPL: Copying destination prefix\n");
|
|
|
|
memcpy(&dio.destination_prefix.prefix, &buffer[i + 8],
|
|
|
|
(dio.destination_prefix.length + 7) / 8);
|
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Invalid route info option, len = %d\n", len);
|
|
|
|
RPL_STAT(rpl_stats.malformed_msgs++);
|
|
|
|
goto discard;
|
|
|
|
}
|
2010-05-25 21:19:43 +02:00
|
|
|
|
2017-02-07 23:11:36 +01:00
|
|
|
break;
|
|
|
|
case RPL_OPTION_DAG_CONF:
|
|
|
|
if(len != 16) {
|
|
|
|
PRINTF("RPL: Invalid DAG configuration option, len = %d\n", len);
|
|
|
|
RPL_STAT(rpl_stats.malformed_msgs++);
|
|
|
|
goto discard;
|
|
|
|
}
|
2011-02-13 23:17:56 +01:00
|
|
|
|
2017-02-07 23:11:36 +01:00
|
|
|
/* Path control field not yet implemented - at i + 2 */
|
|
|
|
dio.dag_intdoubl = buffer[i + 3];
|
|
|
|
dio.dag_intmin = buffer[i + 4];
|
|
|
|
dio.dag_redund = buffer[i + 5];
|
|
|
|
dio.dag_max_rankinc = get16(buffer, i + 6);
|
|
|
|
dio.dag_min_hoprankinc = get16(buffer, i + 8);
|
|
|
|
dio.ocp = get16(buffer, i + 10);
|
|
|
|
/* buffer + 12 is reserved */
|
|
|
|
dio.default_lifetime = buffer[i + 13];
|
|
|
|
dio.lifetime_unit = get16(buffer, i + 14);
|
|
|
|
PRINTF("RPL: DAG conf:dbl=%d, min=%d red=%d maxinc=%d mininc=%d ocp=%d d_l=%u l_u=%u\n",
|
|
|
|
dio.dag_intdoubl, dio.dag_intmin, dio.dag_redund,
|
|
|
|
dio.dag_max_rankinc, dio.dag_min_hoprankinc, dio.ocp,
|
|
|
|
dio.default_lifetime, dio.lifetime_unit);
|
|
|
|
break;
|
|
|
|
case RPL_OPTION_PREFIX_INFO:
|
|
|
|
if(len != 32) {
|
|
|
|
PRINTF("RPL: Invalid DAG prefix info, len != 32\n");
|
|
|
|
RPL_STAT(rpl_stats.malformed_msgs++);
|
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
dio.prefix_info.length = buffer[i + 2];
|
|
|
|
dio.prefix_info.flags = buffer[i + 3];
|
|
|
|
/* valid lifetime is ingnored for now - at i + 4 */
|
|
|
|
/* preferred lifetime stored in lifetime */
|
|
|
|
dio.prefix_info.lifetime = get32(buffer, i + 8);
|
|
|
|
/* 32-bit reserved at i + 12 */
|
|
|
|
PRINTF("RPL: Copying prefix information\n");
|
|
|
|
memcpy(&dio.prefix_info.prefix, &buffer[i + 16], 16);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PRINTF("RPL: Unsupported suboption type in DIO: %u\n",
|
|
|
|
(unsigned)subopt_type);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 12:32:16 +02:00
|
|
|
#ifdef RPL_DEBUG_DIO_INPUT
|
|
|
|
RPL_DEBUG_DIO_INPUT(&from, &dio);
|
|
|
|
#endif
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_process_dio(&from, &dio);
|
2014-03-08 22:36:45 +01:00
|
|
|
|
2017-02-07 23:11:36 +01:00
|
|
|
discard:
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2011-07-11 15:50:51 +02:00
|
|
|
dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
|
|
|
unsigned char *buffer;
|
|
|
|
int pos;
|
2016-06-03 21:17:05 +02:00
|
|
|
int is_root;
|
2012-02-29 21:59:50 +01:00
|
|
|
rpl_dag_t *dag = instance->current_dag;
|
2011-07-11 15:50:51 +02:00
|
|
|
#if !RPL_LEAF_ONLY
|
2010-04-30 15:43:53 +02:00
|
|
|
uip_ipaddr_t addr;
|
2011-07-11 15:50:51 +02:00
|
|
|
#endif /* !RPL_LEAF_ONLY */
|
|
|
|
|
|
|
|
#if RPL_LEAF_ONLY
|
2014-05-30 11:01:20 +02:00
|
|
|
/* In leaf mode, we only send DIO messages as unicasts in response to
|
2012-04-22 00:18:07 +02:00
|
|
|
unicast DIS messages. */
|
2011-07-11 15:50:51 +02:00
|
|
|
if(uc_addr == NULL) {
|
2013-02-21 00:25:32 +01:00
|
|
|
PRINTF("RPL: LEAF ONLY have multicast addr: skip dio_output\n");
|
2011-07-11 15:50:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* RPL_LEAF_ONLY */
|
|
|
|
|
2010-12-15 20:57:40 +01:00
|
|
|
/* DAG Information Object */
|
2010-04-30 15:43:53 +02:00
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->instance_id;
|
2010-06-02 13:59:51 +02:00
|
|
|
buffer[pos++] = dag->version;
|
2016-06-03 21:17:05 +02:00
|
|
|
is_root = (dag->rank == ROOT_RANK(instance));
|
2011-11-21 15:09:19 +01:00
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
#if RPL_LEAF_ONLY
|
2013-02-21 00:25:32 +01:00
|
|
|
PRINTF("RPL: LEAF ONLY DIO rank set to INFINITE_RANK\n");
|
2011-11-21 14:59:31 +01:00
|
|
|
set16(buffer, pos, INFINITE_RANK);
|
2011-07-11 15:50:51 +02:00
|
|
|
#else /* RPL_LEAF_ONLY */
|
2011-09-06 17:28:39 +02:00
|
|
|
set16(buffer, pos, dag->rank);
|
2011-07-11 15:50:51 +02:00
|
|
|
#endif /* RPL_LEAF_ONLY */
|
2011-09-06 17:28:39 +02:00
|
|
|
pos += 2;
|
2010-06-02 00:30:02 +02:00
|
|
|
|
2010-12-13 10:59:46 +01:00
|
|
|
buffer[pos] = 0;
|
2010-04-30 15:43:53 +02:00
|
|
|
if(dag->grounded) {
|
2010-06-02 00:30:02 +02:00
|
|
|
buffer[pos] |= RPL_DIO_GROUNDED;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2010-12-13 11:54:25 +01:00
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos] |= instance->mop << RPL_DIO_MOP_SHIFT;
|
|
|
|
buffer[pos] |= dag->preference & RPL_DIO_PREFERENCE_MASK;
|
2010-06-02 00:30:02 +02:00
|
|
|
pos++;
|
2010-06-08 18:21:54 +02:00
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->dtsn_out;
|
|
|
|
|
2016-06-03 21:17:05 +02:00
|
|
|
if(RPL_DIO_REFRESH_DAO_ROUTES && is_root && uc_addr == NULL) {
|
2015-05-06 11:35:42 +02:00
|
|
|
/* Request new DAO to refresh route. We do not do this for unicast DIO
|
|
|
|
* in order to avoid DAO messages after a DIS-DIO update,
|
|
|
|
* or upon unicast DIO probing. */
|
|
|
|
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
|
|
|
|
}
|
2010-12-13 11:59:37 +01:00
|
|
|
|
2010-06-02 00:30:02 +02:00
|
|
|
/* reserved 2 bytes */
|
2010-12-13 11:59:37 +01:00
|
|
|
buffer[pos++] = 0; /* flags */
|
|
|
|
buffer[pos++] = 0; /* reserved */
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
memcpy(buffer + pos, &dag->dag_id, sizeof(dag->dag_id));
|
|
|
|
pos += 16;
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
#if !RPL_LEAF_ONLY
|
|
|
|
if(instance->mc.type != RPL_DAG_MC_NONE) {
|
|
|
|
instance->of->update_metric_container(instance);
|
2011-02-15 01:13:30 +01:00
|
|
|
|
2011-09-05 20:28:50 +02:00
|
|
|
buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER;
|
2011-02-15 01:13:30 +01:00
|
|
|
buffer[pos++] = 6;
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->mc.type;
|
|
|
|
buffer[pos++] = instance->mc.flags >> 1;
|
|
|
|
buffer[pos] = (instance->mc.flags & 1) << 7;
|
|
|
|
buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
|
|
|
|
if(instance->mc.type == RPL_DAG_MC_ETX) {
|
2011-02-15 01:13:30 +01:00
|
|
|
buffer[pos++] = 2;
|
2011-11-21 14:59:31 +01:00
|
|
|
set16(buffer, pos, instance->mc.obj.etx);
|
2011-09-06 17:28:39 +02:00
|
|
|
pos += 2;
|
2011-07-11 15:50:51 +02:00
|
|
|
} else if(instance->mc.type == RPL_DAG_MC_ENERGY) {
|
2011-03-15 01:16:20 +01:00
|
|
|
buffer[pos++] = 2;
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->mc.obj.energy.flags;
|
|
|
|
buffer[pos++] = instance->mc.obj.energy.energy_est;
|
2011-02-15 01:13:30 +01:00
|
|
|
} else {
|
|
|
|
PRINTF("RPL: Unable to send DIO because of unhandled DAG MC type %u\n",
|
2017-02-07 23:11:36 +01:00
|
|
|
(unsigned)instance->mc.type);
|
2011-02-15 01:13:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-11-21 15:09:19 +01:00
|
|
|
#endif /* !RPL_LEAF_ONLY */
|
2011-02-15 01:13:30 +01:00
|
|
|
|
2011-09-06 17:28:39 +02:00
|
|
|
/* Always add a DAG configuration option. */
|
2011-09-05 20:28:50 +02:00
|
|
|
buffer[pos++] = RPL_OPTION_DAG_CONF;
|
2010-12-13 11:59:37 +01:00
|
|
|
buffer[pos++] = 14;
|
|
|
|
buffer[pos++] = 0; /* No Auth, PCS = 0 */
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->dio_intdoubl;
|
|
|
|
buffer[pos++] = instance->dio_intmin;
|
|
|
|
buffer[pos++] = instance->dio_redundancy;
|
2011-11-21 14:59:31 +01:00
|
|
|
set16(buffer, pos, instance->max_rankinc);
|
2011-09-06 17:28:39 +02:00
|
|
|
pos += 2;
|
2011-11-21 14:59:31 +01:00
|
|
|
set16(buffer, pos, instance->min_hoprankinc);
|
2011-09-06 17:28:39 +02:00
|
|
|
pos += 2;
|
2010-12-13 11:59:37 +01:00
|
|
|
/* OCP is in the DAG_CONF option */
|
2011-11-21 14:59:31 +01:00
|
|
|
set16(buffer, pos, instance->of->ocp);
|
2011-09-06 17:28:39 +02:00
|
|
|
pos += 2;
|
2010-12-13 11:59:37 +01:00
|
|
|
buffer[pos++] = 0; /* reserved */
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->default_lifetime;
|
2011-11-21 14:59:31 +01:00
|
|
|
set16(buffer, pos, instance->lifetime_unit);
|
2011-09-06 17:28:39 +02:00
|
|
|
pos += 2;
|
2010-06-02 00:30:02 +02:00
|
|
|
|
2011-06-28 17:49:32 +02:00
|
|
|
/* Check if we have a prefix to send also. */
|
2010-06-02 00:30:02 +02:00
|
|
|
if(dag->prefix_info.length > 0) {
|
2011-09-05 20:28:50 +02:00
|
|
|
buffer[pos++] = RPL_OPTION_PREFIX_INFO;
|
2010-06-02 00:30:02 +02:00
|
|
|
buffer[pos++] = 30; /* always 30 bytes + 2 long */
|
|
|
|
buffer[pos++] = dag->prefix_info.length;
|
|
|
|
buffer[pos++] = dag->prefix_info.flags;
|
|
|
|
set32(buffer, pos, dag->prefix_info.lifetime);
|
|
|
|
pos += 4;
|
|
|
|
set32(buffer, pos, dag->prefix_info.lifetime);
|
|
|
|
pos += 4;
|
|
|
|
memset(&buffer[pos], 0, 4);
|
2010-05-25 21:19:43 +02:00
|
|
|
pos += 4;
|
2010-06-14 14:44:37 +02:00
|
|
|
memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
|
2010-06-02 00:30:02 +02:00
|
|
|
pos += 16;
|
2010-06-14 14:44:37 +02:00
|
|
|
PRINTF("RPL: Sending prefix info in DIO for ");
|
2010-06-02 00:30:02 +02:00
|
|
|
PRINT6ADDR(&dag->prefix_info.prefix);
|
2010-05-25 21:19:43 +02:00
|
|
|
PRINTF("\n");
|
|
|
|
} else {
|
2010-06-14 14:44:37 +02:00
|
|
|
PRINTF("RPL: No prefix to announce (len %d)\n",
|
2010-06-02 00:30:02 +02:00
|
|
|
dag->prefix_info.length);
|
2010-05-25 21:19:43 +02:00
|
|
|
}
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
#if RPL_LEAF_ONLY
|
2013-02-21 00:25:32 +01:00
|
|
|
#if (DEBUG) & DEBUG_PRINT
|
|
|
|
if(uc_addr == NULL) {
|
|
|
|
PRINTF("RPL: LEAF ONLY sending unicast-DIO from multicast-DIO\n");
|
|
|
|
}
|
|
|
|
#endif /* DEBUG_PRINT */
|
2011-07-11 15:50:51 +02:00
|
|
|
PRINTF("RPL: Sending unicast-DIO with rank %u to ",
|
2017-02-07 23:11:36 +01:00
|
|
|
(unsigned)dag->rank);
|
2011-07-11 15:50:51 +02:00
|
|
|
PRINT6ADDR(uc_addr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_icmp6_send(uc_addr, ICMP6_RPL, RPL_CODE_DIO, pos);
|
|
|
|
#else /* RPL_LEAF_ONLY */
|
2010-04-30 15:43:53 +02:00
|
|
|
/* Unicast requests get unicast replies! */
|
|
|
|
if(uc_addr == NULL) {
|
2010-05-18 18:43:56 +02:00
|
|
|
PRINTF("RPL: Sending a multicast-DIO with rank %u\n",
|
2017-02-07 23:11:36 +01:00
|
|
|
(unsigned)instance->current_dag->rank);
|
2011-01-25 10:55:12 +01:00
|
|
|
uip_create_linklocal_rplnodes_mcast(&addr);
|
2010-04-30 15:43:53 +02:00
|
|
|
uip_icmp6_send(&addr, ICMP6_RPL, RPL_CODE_DIO, pos);
|
|
|
|
} else {
|
2010-05-25 21:19:43 +02:00
|
|
|
PRINTF("RPL: Sending unicast-DIO with rank %u to ",
|
2017-02-07 23:11:36 +01:00
|
|
|
(unsigned)instance->current_dag->rank);
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINT6ADDR(uc_addr);
|
|
|
|
PRINTF("\n");
|
|
|
|
uip_icmp6_send(uc_addr, ICMP6_RPL, RPL_CODE_DIO, pos);
|
|
|
|
}
|
2011-07-11 15:50:51 +02:00
|
|
|
#endif /* RPL_LEAF_ONLY */
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
2016-02-01 18:02:33 +01:00
|
|
|
dao_input_storing(void)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2016-02-01 18:02:33 +01:00
|
|
|
#if RPL_WITH_STORING
|
2010-06-06 23:42:50 +02:00
|
|
|
uip_ipaddr_t dao_sender_addr;
|
2010-04-30 15:43:53 +02:00
|
|
|
rpl_dag_t *dag;
|
2011-07-11 15:50:51 +02:00
|
|
|
rpl_instance_t *instance;
|
2010-04-30 15:43:53 +02:00
|
|
|
unsigned char *buffer;
|
|
|
|
uint16_t sequence;
|
|
|
|
uint8_t instance_id;
|
2011-07-11 15:50:51 +02:00
|
|
|
uint8_t lifetime;
|
2010-04-30 15:43:53 +02:00
|
|
|
uint8_t prefixlen;
|
2010-06-03 16:49:15 +02:00
|
|
|
uint8_t flags;
|
|
|
|
uint8_t subopt_type;
|
2013-08-11 23:53:36 +02:00
|
|
|
/*
|
2017-02-07 23:11:36 +01:00
|
|
|
uint8_t pathcontrol;
|
|
|
|
uint8_t pathsequence;
|
2013-08-11 23:53:36 +02:00
|
|
|
*/
|
2010-04-30 15:43:53 +02:00
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
uip_ds6_route_t *rep;
|
2010-06-03 16:49:15 +02:00
|
|
|
uint8_t buffer_length;
|
2010-04-30 15:43:53 +02:00
|
|
|
int pos;
|
2010-06-03 16:49:15 +02:00
|
|
|
int len;
|
|
|
|
int i;
|
2010-06-06 23:42:50 +02:00
|
|
|
int learned_from;
|
2014-03-27 15:55:38 +01:00
|
|
|
rpl_parent_t *parent;
|
2013-11-20 15:14:11 +01:00
|
|
|
uip_ds6_nbr_t *nbr;
|
2015-09-23 09:12:35 +02:00
|
|
|
int is_root;
|
2010-06-03 16:49:15 +02:00
|
|
|
|
|
|
|
prefixlen = 0;
|
2014-03-27 15:55:38 +01:00
|
|
|
parent = NULL;
|
2017-04-11 14:25:18 +02:00
|
|
|
memset(&prefix, 0, sizeof(prefix));
|
2010-06-03 16:49:15 +02:00
|
|
|
|
2010-06-06 23:42:50 +02:00
|
|
|
uip_ipaddr_copy(&dao_sender_addr, &UIP_IP_BUF->srcipaddr);
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
2012-03-08 00:48:04 +01:00
|
|
|
buffer_length = uip_len - uip_l3_icmp_hdr_len;
|
2011-07-11 15:50:51 +02:00
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
pos = 0;
|
|
|
|
instance_id = buffer[pos++];
|
2010-06-14 14:44:37 +02:00
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
instance = rpl_get_instance(instance_id);
|
2010-06-14 14:44:37 +02:00
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
lifetime = instance->default_lifetime;
|
2011-06-28 17:08:44 +02:00
|
|
|
|
2010-06-03 16:49:15 +02:00
|
|
|
flags = buffer[pos++];
|
|
|
|
/* reserved */
|
2010-04-30 15:43:53 +02:00
|
|
|
pos++;
|
2010-06-03 16:49:15 +02:00
|
|
|
sequence = buffer[pos++];
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
dag = instance->current_dag;
|
2015-09-23 09:12:35 +02:00
|
|
|
is_root = (dag->rank == ROOT_RANK(instance));
|
|
|
|
|
2014-03-27 16:17:47 +01:00
|
|
|
/* Is the DAG ID present? */
|
2010-06-03 16:49:15 +02:00
|
|
|
if(flags & RPL_DAO_D_FLAG) {
|
2011-07-11 15:50:51 +02:00
|
|
|
if(memcmp(&dag->dag_id, &buffer[pos], sizeof(dag->dag_id))) {
|
2012-02-29 21:59:50 +01:00
|
|
|
PRINTF("RPL: Ignoring a DAO for a DAG different from ours\n");
|
2016-02-01 18:02:33 +01:00
|
|
|
return;
|
2011-07-11 15:50:51 +02:00
|
|
|
}
|
2010-06-03 16:49:15 +02:00
|
|
|
pos += 16;
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2013-08-28 15:12:41 +02:00
|
|
|
learned_from = uip_is_addr_mcast(&dao_sender_addr) ?
|
2017-02-07 23:11:36 +01:00
|
|
|
RPL_ROUTE_FROM_MULTICAST_DAO : RPL_ROUTE_FROM_UNICAST_DAO;
|
2013-08-28 15:12:41 +02:00
|
|
|
|
2015-11-23 13:38:48 +01:00
|
|
|
/* Destination Advertisement Object */
|
|
|
|
PRINTF("RPL: Received a (%s) DAO with sequence number %u from ",
|
2017-02-07 23:11:36 +01:00
|
|
|
learned_from == RPL_ROUTE_FROM_UNICAST_DAO? "unicast": "multicast", sequence);
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINT6ADDR(&dao_sender_addr);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
2013-08-28 15:12:41 +02:00
|
|
|
if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
|
|
|
|
/* Check whether this is a DAO forwarding loop. */
|
2014-03-27 15:55:38 +01:00
|
|
|
parent = rpl_find_parent(dag, &dao_sender_addr);
|
2013-08-28 15:12:41 +02:00
|
|
|
/* check if this is a new DAO registration with an "illegal" rank */
|
|
|
|
/* if we already route to this node it is likely */
|
2014-03-27 15:55:38 +01:00
|
|
|
if(parent != NULL &&
|
|
|
|
DAG_RANK(parent->rank, instance) < DAG_RANK(dag->rank, instance)) {
|
2013-08-28 15:12:41 +02:00
|
|
|
PRINTF("RPL: Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n",
|
2017-02-07 23:11:36 +01:00
|
|
|
DAG_RANK(parent->rank, instance), DAG_RANK(dag->rank, instance));
|
2014-03-27 15:55:38 +01:00
|
|
|
parent->rank = INFINITE_RANK;
|
2014-04-29 16:25:16 +02:00
|
|
|
parent->flags |= RPL_PARENT_FLAG_UPDATED;
|
2016-02-01 18:02:33 +01:00
|
|
|
return;
|
2013-08-28 15:12:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get the DAO from our parent, we also have a loop. */
|
2014-03-27 15:55:38 +01:00
|
|
|
if(parent != NULL && parent == dag->preferred_parent) {
|
2013-08-28 15:12:41 +02:00
|
|
|
PRINTF("RPL: Loop detected when receiving a unicast DAO from our parent\n");
|
2014-03-27 15:55:38 +01:00
|
|
|
parent->rank = INFINITE_RANK;
|
2014-04-29 16:25:16 +02:00
|
|
|
parent->flags |= RPL_PARENT_FLAG_UPDATED;
|
2016-02-01 18:02:33 +01:00
|
|
|
return;
|
2013-08-28 15:12:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 20:28:50 +02:00
|
|
|
/* Check if there are any RPL options present. */
|
2013-08-11 23:53:36 +02:00
|
|
|
for(i = pos; i < buffer_length; i += len) {
|
2010-06-03 16:49:15 +02:00
|
|
|
subopt_type = buffer[i];
|
2011-09-05 20:28:50 +02:00
|
|
|
if(subopt_type == RPL_OPTION_PAD1) {
|
2010-06-03 16:49:15 +02:00
|
|
|
len = 1;
|
|
|
|
} else {
|
2011-09-05 20:28:50 +02:00
|
|
|
/* The option consists of a two-byte header and a payload. */
|
2010-06-03 16:49:15 +02:00
|
|
|
len = 2 + buffer[i + 1];
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-06-03 16:49:15 +02:00
|
|
|
switch(subopt_type) {
|
2017-02-07 23:11:36 +01:00
|
|
|
case RPL_OPTION_TARGET:
|
|
|
|
/* Handle the target option. */
|
|
|
|
prefixlen = buffer[i + 3];
|
|
|
|
memset(&prefix, 0, sizeof(prefix));
|
|
|
|
memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
|
|
|
|
break;
|
|
|
|
case RPL_OPTION_TRANSIT:
|
|
|
|
/* The path sequence and control are ignored. */
|
|
|
|
/* pathcontrol = buffer[i + 3];
|
|
|
|
pathsequence = buffer[i + 4];*/
|
|
|
|
lifetime = buffer[i + 5];
|
|
|
|
/* The parent address is also ignored. */
|
|
|
|
break;
|
2010-06-03 16:49:15 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2011-06-28 17:08:44 +02:00
|
|
|
PRINTF("RPL: DAO lifetime: %u, prefix length: %u prefix: ",
|
2017-02-07 23:11:36 +01:00
|
|
|
(unsigned)lifetime, (unsigned)prefixlen);
|
2010-06-06 14:45:55 +02:00
|
|
|
PRINT6ADDR(&prefix);
|
2010-05-24 18:38:56 +02:00
|
|
|
PRINTF("\n");
|
|
|
|
|
2016-06-20 16:35:09 +02:00
|
|
|
#if RPL_WITH_MULTICAST
|
2011-12-09 13:15:04 +01:00
|
|
|
if(uip_is_addr_mcast_global(&prefix)) {
|
2017-02-07 23:59:17 +01:00
|
|
|
/*
|
|
|
|
* "rep" is used for a unicast route which we don't need now; so set NULL so
|
|
|
|
* that operations on "rep" will be skipped.
|
|
|
|
*/
|
|
|
|
rep = NULL;
|
2011-12-09 13:15:04 +01:00
|
|
|
mcast_group = uip_mcast6_route_add(&prefix);
|
|
|
|
if(mcast_group) {
|
|
|
|
mcast_group->dag = dag;
|
|
|
|
mcast_group->lifetime = RPL_LIFETIME(instance, lifetime);
|
|
|
|
}
|
|
|
|
goto fwd_dao;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-06-28 17:08:44 +02:00
|
|
|
rep = uip_ds6_route_lookup(&prefix);
|
|
|
|
|
2012-02-29 21:59:50 +01:00
|
|
|
if(lifetime == RPL_ZERO_LIFETIME) {
|
2013-08-11 23:42:51 +02:00
|
|
|
PRINTF("RPL: No-Path DAO received\n");
|
2010-12-17 16:24:25 +01:00
|
|
|
/* No-Path DAO received; invoke the route purging routine. */
|
2013-08-11 23:42:51 +02:00
|
|
|
if(rep != NULL &&
|
2015-08-19 15:50:20 +02:00
|
|
|
!RPL_ROUTE_IS_NOPATH_RECEIVED(rep) &&
|
2013-08-11 23:42:51 +02:00
|
|
|
rep->length == prefixlen &&
|
|
|
|
uip_ds6_route_nexthop(rep) != NULL &&
|
|
|
|
uip_ipaddr_cmp(uip_ds6_route_nexthop(rep), &dao_sender_addr)) {
|
2010-05-18 18:43:56 +02:00
|
|
|
PRINTF("RPL: Setting expiration timer for prefix ");
|
|
|
|
PRINT6ADDR(&prefix);
|
|
|
|
PRINTF("\n");
|
2015-08-19 15:50:20 +02:00
|
|
|
RPL_ROUTE_SET_NOPATH_RECEIVED(rep);
|
2015-11-18 14:06:18 +01:00
|
|
|
rep->state.lifetime = RPL_NOPATH_REMOVAL_DELAY;
|
2013-11-20 14:10:10 +01:00
|
|
|
|
2015-11-18 15:25:13 +01:00
|
|
|
/* We forward the incoming No-Path DAO to our parent, if we have
|
2013-11-20 14:10:10 +01:00
|
|
|
one. */
|
|
|
|
if(dag->preferred_parent != NULL &&
|
|
|
|
rpl_get_parent_ipaddr(dag->preferred_parent) != NULL) {
|
2015-08-19 15:50:20 +02:00
|
|
|
uint8_t out_seq;
|
|
|
|
out_seq = prepare_for_dao_fwd(sequence, rep);
|
|
|
|
|
2015-11-18 15:25:13 +01:00
|
|
|
PRINTF("RPL: Forwarding No-path DAO to parent - out_seq:%d",
|
2017-02-07 23:11:36 +01:00
|
|
|
out_seq);
|
2013-11-20 14:10:10 +01:00
|
|
|
PRINT6ADDR(rpl_get_parent_ipaddr(dag->preferred_parent));
|
|
|
|
PRINTF("\n");
|
2015-08-19 15:50:20 +02:00
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
|
|
|
buffer[3] = out_seq; /* add an outgoing seq no before fwd */
|
2013-11-20 14:10:10 +01:00
|
|
|
uip_icmp6_send(rpl_get_parent_ipaddr(dag->preferred_parent),
|
|
|
|
ICMP6_RPL, RPL_CODE_DAO, buffer_length);
|
|
|
|
}
|
2016-03-29 20:05:28 +02:00
|
|
|
}
|
2015-10-02 07:38:52 +02:00
|
|
|
/* independent if we remove or not - ACK the request */
|
|
|
|
if(flags & RPL_DAO_K_FLAG) {
|
|
|
|
/* indicate that we accepted the no-path DAO */
|
2016-03-29 20:05:28 +02:00
|
|
|
uip_clear_buf();
|
2015-10-02 07:38:52 +02:00
|
|
|
dao_ack_output(instance, &dao_sender_addr, sequence,
|
|
|
|
RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
|
2010-05-18 18:43:56 +02:00
|
|
|
}
|
2016-02-01 18:02:33 +01:00
|
|
|
return;
|
2010-05-18 18:43:56 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: Adding DAO route\n");
|
2013-11-20 14:09:11 +01:00
|
|
|
|
2015-08-20 17:09:32 +02:00
|
|
|
/* Update and add neighbor - if no room - fail. */
|
2015-09-22 22:12:06 +02:00
|
|
|
if((nbr = rpl_icmp6_update_nbr_table(&dao_sender_addr, NBR_TABLE_REASON_RPL_DAO, instance)) == NULL) {
|
2015-08-20 17:09:32 +02:00
|
|
|
PRINTF("RPL: Out of Memory, dropping DAO from ");
|
|
|
|
PRINT6ADDR(&dao_sender_addr);
|
|
|
|
PRINTF(", ");
|
|
|
|
PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
|
|
|
|
PRINTF("\n");
|
2015-09-20 21:02:30 +02:00
|
|
|
if(flags & RPL_DAO_K_FLAG) {
|
|
|
|
/* signal the failure to add the node */
|
|
|
|
dao_ack_output(instance, &dao_sender_addr, sequence,
|
2017-02-07 23:11:36 +01:00
|
|
|
is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
|
|
|
|
RPL_DAO_ACK_UNABLE_TO_ACCEPT);
|
2015-09-20 21:02:30 +02:00
|
|
|
}
|
2016-02-01 18:02:33 +01:00
|
|
|
return;
|
2013-11-20 14:09:11 +01:00
|
|
|
}
|
|
|
|
|
2011-11-16 09:05:34 +01:00
|
|
|
rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
|
2010-04-30 15:43:53 +02:00
|
|
|
if(rep == NULL) {
|
2011-11-16 09:05:34 +01:00
|
|
|
RPL_STAT(rpl_stats.mem_overflows++);
|
|
|
|
PRINTF("RPL: Could not add a route after receiving a DAO\n");
|
2015-08-19 15:50:20 +02:00
|
|
|
if(flags & RPL_DAO_K_FLAG) {
|
|
|
|
/* signal the failure to add the node */
|
|
|
|
dao_ack_output(instance, &dao_sender_addr, sequence,
|
2017-02-07 23:11:36 +01:00
|
|
|
is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
|
|
|
|
RPL_DAO_ACK_UNABLE_TO_ACCEPT);
|
2015-08-19 15:50:20 +02:00
|
|
|
}
|
2016-02-01 18:02:33 +01:00
|
|
|
return;
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
|
2015-10-02 07:38:52 +02:00
|
|
|
/* set lifetime and clear NOPATH bit */
|
2011-07-11 15:50:51 +02:00
|
|
|
rep->state.lifetime = RPL_LIFETIME(instance, lifetime);
|
2015-10-02 07:38:52 +02:00
|
|
|
RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep);
|
2011-06-28 17:08:44 +02:00
|
|
|
|
2016-06-20 16:35:09 +02:00
|
|
|
#if RPL_WITH_MULTICAST
|
2011-12-09 13:15:04 +01:00
|
|
|
fwd_dao:
|
|
|
|
#endif
|
|
|
|
|
2010-06-06 23:42:50 +02:00
|
|
|
if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
|
2015-08-19 15:50:20 +02:00
|
|
|
int should_ack = 0;
|
|
|
|
|
|
|
|
if(flags & RPL_DAO_K_FLAG) {
|
2017-02-07 23:59:17 +01:00
|
|
|
if(rep != NULL) {
|
|
|
|
/*
|
|
|
|
* check if this route is already installed and we can ack now!
|
|
|
|
* not pending - and same seq-no means that we can ack.
|
|
|
|
* (e.g. the route is installed already so it will not take any
|
|
|
|
* more room that it already takes - so should be ok!)
|
|
|
|
*/
|
|
|
|
if((!RPL_ROUTE_IS_DAO_PENDING(rep) &&
|
|
|
|
rep->state.dao_seqno_in == sequence) ||
|
|
|
|
dag->rank == ROOT_RANK(instance)) {
|
|
|
|
should_ack = 1;
|
|
|
|
}
|
2015-08-19 15:50:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 00:11:48 +02:00
|
|
|
if(dag->preferred_parent != NULL &&
|
|
|
|
rpl_get_parent_ipaddr(dag->preferred_parent) != NULL) {
|
2015-08-19 15:50:20 +02:00
|
|
|
uint8_t out_seq = 0;
|
2017-02-07 23:59:17 +01:00
|
|
|
if(rep != NULL) {
|
|
|
|
/* if this is pending and we get the same seq no it is a retrans */
|
|
|
|
if(RPL_ROUTE_IS_DAO_PENDING(rep) &&
|
|
|
|
rep->state.dao_seqno_in == sequence) {
|
|
|
|
/* keep the same seq-no as before for parent also */
|
|
|
|
out_seq = rep->state.dao_seqno_out;
|
|
|
|
} else {
|
|
|
|
out_seq = prepare_for_dao_fwd(sequence, rep);
|
|
|
|
}
|
2015-08-19 15:50:20 +02:00
|
|
|
}
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
PRINTF("RPL: Forwarding DAO to parent ");
|
2013-08-11 23:42:51 +02:00
|
|
|
PRINT6ADDR(rpl_get_parent_ipaddr(dag->preferred_parent));
|
2015-08-19 15:50:20 +02:00
|
|
|
PRINTF(" in seq: %d out seq: %d\n", sequence, out_seq);
|
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
|
|
|
buffer[3] = out_seq; /* add an outgoing seq no before fwd */
|
2013-07-03 19:53:51 +02:00
|
|
|
uip_icmp6_send(rpl_get_parent_ipaddr(dag->preferred_parent),
|
2010-10-25 21:49:12 +02:00
|
|
|
ICMP6_RPL, RPL_CODE_DAO, buffer_length);
|
2011-07-11 15:50:51 +02:00
|
|
|
}
|
2015-08-19 15:50:20 +02:00
|
|
|
if(should_ack) {
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: Sending DAO ACK\n");
|
2016-03-29 20:05:28 +02:00
|
|
|
uip_clear_buf();
|
2015-08-19 15:50:20 +02:00
|
|
|
dao_ack_output(instance, &dao_sender_addr, sequence,
|
|
|
|
RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
}
|
2016-02-01 18:02:33 +01:00
|
|
|
#endif /* RPL_WITH_STORING */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
dao_input_nonstoring(void)
|
|
|
|
{
|
|
|
|
#if RPL_WITH_NON_STORING
|
|
|
|
uip_ipaddr_t dao_sender_addr;
|
|
|
|
uip_ipaddr_t dao_parent_addr;
|
|
|
|
rpl_dag_t *dag;
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
unsigned char *buffer;
|
|
|
|
uint16_t sequence;
|
|
|
|
uint8_t instance_id;
|
|
|
|
uint8_t lifetime;
|
|
|
|
uint8_t prefixlen;
|
|
|
|
uint8_t flags;
|
|
|
|
uint8_t subopt_type;
|
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
uint8_t buffer_length;
|
|
|
|
int pos;
|
|
|
|
int len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
prefixlen = 0;
|
|
|
|
|
|
|
|
uip_ipaddr_copy(&dao_sender_addr, &UIP_IP_BUF->srcipaddr);
|
|
|
|
memset(&dao_parent_addr, 0, 16);
|
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
|
|
|
buffer_length = uip_len - uip_l3_icmp_hdr_len;
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
instance_id = buffer[pos++];
|
|
|
|
instance = rpl_get_instance(instance_id);
|
|
|
|
lifetime = instance->default_lifetime;
|
|
|
|
|
|
|
|
flags = buffer[pos++];
|
|
|
|
/* reserved */
|
|
|
|
pos++;
|
|
|
|
sequence = buffer[pos++];
|
|
|
|
|
|
|
|
dag = instance->current_dag;
|
|
|
|
/* Is the DAG ID present? */
|
|
|
|
if(flags & RPL_DAO_D_FLAG) {
|
|
|
|
if(memcmp(&dag->dag_id, &buffer[pos], sizeof(dag->dag_id))) {
|
|
|
|
PRINTF("RPL: Ignoring a DAO for a DAG different from ours\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pos += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if there are any RPL options present. */
|
|
|
|
for(i = pos; i < buffer_length; i += len) {
|
|
|
|
subopt_type = buffer[i];
|
|
|
|
if(subopt_type == RPL_OPTION_PAD1) {
|
|
|
|
len = 1;
|
|
|
|
} else {
|
|
|
|
/* The option consists of a two-byte header and a payload. */
|
|
|
|
len = 2 + buffer[i + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(subopt_type) {
|
2017-02-07 23:11:36 +01:00
|
|
|
case RPL_OPTION_TARGET:
|
|
|
|
/* Handle the target option. */
|
|
|
|
prefixlen = buffer[i + 3];
|
|
|
|
memset(&prefix, 0, sizeof(prefix));
|
|
|
|
memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
|
|
|
|
break;
|
|
|
|
case RPL_OPTION_TRANSIT:
|
|
|
|
/* The path sequence and control are ignored. */
|
|
|
|
/* pathcontrol = buffer[i + 3];
|
|
|
|
pathsequence = buffer[i + 4];*/
|
|
|
|
lifetime = buffer[i + 5];
|
|
|
|
if(len >= 20) {
|
|
|
|
memcpy(&dao_parent_addr, buffer + i + 6, 16);
|
|
|
|
}
|
|
|
|
break;
|
2016-02-01 18:02:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRINTF("RPL: DAO lifetime: %u, prefix length: %u prefix: ",
|
2017-02-07 23:11:36 +01:00
|
|
|
(unsigned)lifetime, (unsigned)prefixlen);
|
2016-02-01 18:02:33 +01:00
|
|
|
PRINT6ADDR(&prefix);
|
|
|
|
PRINTF(", parent: ");
|
|
|
|
PRINT6ADDR(&dao_parent_addr);
|
|
|
|
PRINTF(" \n");
|
|
|
|
|
|
|
|
if(lifetime == RPL_ZERO_LIFETIME) {
|
|
|
|
PRINTF("RPL: No-Path DAO received\n");
|
|
|
|
rpl_ns_expire_parent(dag, &prefix, &dao_parent_addr);
|
|
|
|
} else {
|
|
|
|
if(rpl_ns_update_node(dag, &prefix, &dao_parent_addr, RPL_LIFETIME(instance, lifetime)) == NULL) {
|
|
|
|
PRINTF("RPL: failed to add link\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(flags & RPL_DAO_K_FLAG) {
|
|
|
|
PRINTF("RPL: Sending DAO ACK\n");
|
|
|
|
uip_clear_buf();
|
|
|
|
dao_ack_output(instance, &dao_sender_addr, sequence,
|
2017-02-07 23:11:36 +01:00
|
|
|
RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
|
2016-02-01 18:02:33 +01:00
|
|
|
}
|
|
|
|
#endif /* RPL_WITH_NON_STORING */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
dao_input(void)
|
|
|
|
{
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
uint8_t instance_id;
|
|
|
|
|
|
|
|
/* Destination Advertisement Object */
|
|
|
|
PRINTF("RPL: Received a DAO from ");
|
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF("\n");
|
|
|
|
|
|
|
|
instance_id = UIP_ICMP_PAYLOAD[0];
|
|
|
|
instance = rpl_get_instance(instance_id);
|
|
|
|
if(instance == NULL) {
|
|
|
|
PRINTF("RPL: Ignoring a DAO for an unknown RPL instance(%u)\n",
|
|
|
|
instance_id);
|
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
|
2016-06-08 14:04:47 +02:00
|
|
|
if(RPL_IS_STORING(instance)) {
|
|
|
|
dao_input_storing();
|
|
|
|
} else if(RPL_IS_NON_STORING(instance)) {
|
|
|
|
dao_input_nonstoring();
|
2016-02-01 18:02:33 +01:00
|
|
|
}
|
2015-08-26 16:48:34 +02:00
|
|
|
|
2017-02-07 23:11:36 +01:00
|
|
|
discard:
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-08-19 15:50:20 +02:00
|
|
|
#if RPL_WITH_DAO_ACK
|
|
|
|
static void
|
|
|
|
handle_dao_retransmission(void *ptr)
|
|
|
|
{
|
|
|
|
rpl_parent_t *parent;
|
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
|
2015-08-20 17:09:32 +02:00
|
|
|
parent = ptr;
|
2015-08-19 15:50:20 +02:00
|
|
|
if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
instance = parent->dag->instance;
|
|
|
|
|
|
|
|
if(instance->my_dao_transmissions >= RPL_DAO_MAX_RETRANSMISSIONS) {
|
2015-08-20 17:09:32 +02:00
|
|
|
/* No more retransmissions - give up. */
|
2015-08-19 15:50:20 +02:00
|
|
|
if(instance->lifetime_unit == 0xffff && instance->default_lifetime == 0xff) {
|
2015-08-20 17:09:32 +02:00
|
|
|
/*
|
|
|
|
* ContikiRPL was previously using infinite lifetime for routes
|
|
|
|
* and no DAO_ACK configured. This probably means that the root
|
|
|
|
* and possibly other nodes might be running an old version that
|
|
|
|
* does not support DAO ack. Assume that everything is ok for
|
|
|
|
* now and let the normal repair mechanisms detect any problems.
|
|
|
|
*/
|
2015-08-19 15:50:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-03 21:19:08 +02:00
|
|
|
if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
|
2015-08-20 17:09:32 +02:00
|
|
|
/* Inform the objective function about the timeout. */
|
2015-08-19 15:50:20 +02:00
|
|
|
instance->of->dao_ack_callback(parent, RPL_DAO_ACK_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2015-08-20 17:09:32 +02:00
|
|
|
/* Perform local repair and hope to find another parent. */
|
2015-08-19 15:50:20 +02:00
|
|
|
rpl_local_repair(instance);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-27 14:00:55 +02:00
|
|
|
PRINTF("RPL: will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno,
|
2017-02-07 23:11:36 +01:00
|
|
|
instance->my_dao_transmissions);
|
2015-08-19 15:50:20 +02:00
|
|
|
|
|
|
|
if(get_global_addr(&prefix) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-20 21:02:30 +02:00
|
|
|
ctimer_set(&instance->dao_retransmit_timer,
|
|
|
|
RPL_DAO_RETRANSMISSION_TIMEOUT / 2 +
|
|
|
|
(random_rand() % (RPL_DAO_RETRANSMISSION_TIMEOUT / 2)),
|
2017-02-07 23:11:36 +01:00
|
|
|
handle_dao_retransmission, parent);
|
2015-08-19 15:50:20 +02:00
|
|
|
|
|
|
|
instance->my_dao_transmissions++;
|
|
|
|
dao_output_target_seq(parent, &prefix,
|
2017-02-07 23:11:36 +01:00
|
|
|
instance->default_lifetime, instance->my_dao_seqno);
|
2015-08-19 15:50:20 +02:00
|
|
|
}
|
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 15:43:53 +02:00
|
|
|
void
|
2013-07-25 11:22:38 +02:00
|
|
|
dao_output(rpl_parent_t *parent, uint8_t lifetime)
|
2013-07-25 10:39:39 +02:00
|
|
|
{
|
|
|
|
/* Destination Advertisement Object */
|
|
|
|
uip_ipaddr_t prefix;
|
|
|
|
|
|
|
|
if(get_global_addr(&prefix) == 0) {
|
|
|
|
PRINTF("RPL: No global address set for this node - suppressing DAO\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-19 15:50:20 +02:00
|
|
|
if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-27 14:01:44 +02:00
|
|
|
RPL_LOLLIPOP_INCREMENT(dao_sequence);
|
2016-02-18 22:40:30 +01:00
|
|
|
#if RPL_WITH_DAO_ACK
|
|
|
|
/* set up the state since this will be the first transmission of DAO */
|
|
|
|
/* retransmissions will call directly to dao_output_target_seq */
|
|
|
|
/* keep track of my own sending of DAO for handling ack and loss of ack */
|
|
|
|
if(lifetime != RPL_ZERO_LIFETIME) {
|
|
|
|
rpl_instance_t *instance;
|
|
|
|
instance = parent->dag->instance;
|
|
|
|
|
|
|
|
instance->my_dao_seqno = dao_sequence;
|
|
|
|
instance->my_dao_transmissions = 1;
|
|
|
|
ctimer_set(&instance->dao_retransmit_timer, RPL_DAO_RETRANSMISSION_TIMEOUT,
|
2017-02-07 23:11:36 +01:00
|
|
|
handle_dao_retransmission, parent);
|
2016-02-18 22:40:30 +01:00
|
|
|
}
|
|
|
|
#else
|
2017-02-07 23:11:36 +01:00
|
|
|
/* We know that we have tried to register so now we are assuming
|
|
|
|
that we have a down-link - unless this is a zero lifetime one */
|
2016-03-26 20:12:52 +01:00
|
|
|
parent->dag->instance->has_downward_route = lifetime != RPL_ZERO_LIFETIME;
|
2016-02-18 22:40:30 +01:00
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
|
|
|
|
2013-07-25 11:22:38 +02:00
|
|
|
/* Sending a DAO with own prefix as target */
|
|
|
|
dao_output_target(parent, &prefix, lifetime);
|
2013-07-25 10:39:39 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2013-07-25 11:22:38 +02:00
|
|
|
dao_output_target(rpl_parent_t *parent, uip_ipaddr_t *prefix, uint8_t lifetime)
|
2015-08-19 15:50:20 +02:00
|
|
|
{
|
|
|
|
dao_output_target_seq(parent, prefix, lifetime, dao_sequence);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
|
2017-02-07 23:11:36 +01:00
|
|
|
uint8_t lifetime, uint8_t seq_no)
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
|
|
|
rpl_dag_t *dag;
|
2011-07-11 15:50:51 +02:00
|
|
|
rpl_instance_t *instance;
|
2010-04-30 15:43:53 +02:00
|
|
|
unsigned char *buffer;
|
|
|
|
uint8_t prefixlen;
|
|
|
|
int pos;
|
2016-02-01 18:02:33 +01:00
|
|
|
uip_ipaddr_t *parent_ipaddr = NULL;
|
|
|
|
uip_ipaddr_t *dest_ipaddr = NULL;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
|
|
|
/* Destination Advertisement Object */
|
2012-04-17 23:04:20 +02:00
|
|
|
|
2013-11-20 14:10:39 +01:00
|
|
|
/* If we are in feather mode, we should not send any DAOs */
|
|
|
|
if(rpl_get_mode() == RPL_MODE_FEATHER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-12 00:19:12 +02:00
|
|
|
if(parent == NULL) {
|
|
|
|
PRINTF("RPL dao_output_target error parent NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-01 18:02:33 +01:00
|
|
|
parent_ipaddr = rpl_get_parent_ipaddr(parent);
|
|
|
|
if(parent_ipaddr == NULL) {
|
|
|
|
PRINTF("RPL dao_output_target error parent IP address NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-25 11:22:38 +02:00
|
|
|
dag = parent->dag;
|
2013-08-12 00:19:12 +02:00
|
|
|
if(dag == NULL) {
|
|
|
|
PRINTF("RPL dao_output_target error dag NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
instance = dag->instance;
|
|
|
|
|
2013-08-12 00:19:12 +02:00
|
|
|
if(instance == NULL) {
|
|
|
|
PRINTF("RPL dao_output_target error instance NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(prefix == NULL) {
|
|
|
|
PRINTF("RPL dao_output_target error prefix NULL\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-10-27 12:32:16 +02:00
|
|
|
#ifdef RPL_DEBUG_DAO_OUTPUT
|
2013-07-25 11:22:38 +02:00
|
|
|
RPL_DEBUG_DAO_OUTPUT(parent);
|
2011-10-27 12:32:16 +02:00
|
|
|
#endif
|
|
|
|
|
2010-04-30 15:43:53 +02:00
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
|
|
|
pos = 0;
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos++] = instance->instance_id;
|
|
|
|
buffer[pos] = 0;
|
2012-02-29 21:59:50 +01:00
|
|
|
#if RPL_DAO_SPECIFY_DAG
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[pos] |= RPL_DAO_D_FLAG;
|
2012-02-29 21:59:50 +01:00
|
|
|
#endif /* RPL_DAO_SPECIFY_DAG */
|
2015-08-19 15:50:20 +02:00
|
|
|
#if RPL_WITH_DAO_ACK
|
2016-04-27 14:19:26 +02:00
|
|
|
if(lifetime != RPL_ZERO_LIFETIME) {
|
|
|
|
buffer[pos] |= RPL_DAO_K_FLAG;
|
|
|
|
}
|
2015-08-19 15:50:20 +02:00
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
2011-07-11 15:50:51 +02:00
|
|
|
++pos;
|
2010-06-03 16:49:15 +02:00
|
|
|
buffer[pos++] = 0; /* reserved */
|
2015-08-19 15:50:20 +02:00
|
|
|
buffer[pos++] = seq_no;
|
2012-02-29 21:59:50 +01:00
|
|
|
#if RPL_DAO_SPECIFY_DAG
|
2011-07-11 15:50:51 +02:00
|
|
|
memcpy(buffer + pos, &dag->dag_id, sizeof(dag->dag_id));
|
|
|
|
pos+=sizeof(dag->dag_id);
|
2012-02-29 21:59:50 +01:00
|
|
|
#endif /* RPL_DAO_SPECIFY_DAG */
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2010-06-03 16:49:15 +02:00
|
|
|
/* create target subopt */
|
2013-07-25 10:39:39 +02:00
|
|
|
prefixlen = sizeof(*prefix) * CHAR_BIT;
|
2011-09-05 20:28:50 +02:00
|
|
|
buffer[pos++] = RPL_OPTION_TARGET;
|
2010-06-03 16:49:15 +02:00
|
|
|
buffer[pos++] = 2 + ((prefixlen + 7) / CHAR_BIT);
|
|
|
|
buffer[pos++] = 0; /* reserved */
|
2010-04-30 15:43:53 +02:00
|
|
|
buffer[pos++] = prefixlen;
|
2013-07-25 10:39:39 +02:00
|
|
|
memcpy(buffer + pos, prefix, (prefixlen + 7) / CHAR_BIT);
|
2010-06-03 16:49:15 +02:00
|
|
|
pos += ((prefixlen + 7) / CHAR_BIT);
|
|
|
|
|
2011-06-28 17:08:44 +02:00
|
|
|
/* Create a transit information sub-option. */
|
2011-09-05 20:28:50 +02:00
|
|
|
buffer[pos++] = RPL_OPTION_TRANSIT;
|
2016-02-01 18:02:33 +01:00
|
|
|
buffer[pos++] = (instance->mop != RPL_MOP_NON_STORING) ? 4 : 20;
|
2011-03-01 12:33:34 +01:00
|
|
|
buffer[pos++] = 0; /* flags - ignored */
|
2010-06-03 16:49:15 +02:00
|
|
|
buffer[pos++] = 0; /* path control - ignored */
|
2011-03-01 12:33:34 +01:00
|
|
|
buffer[pos++] = 0; /* path seq - ignored */
|
2011-06-28 17:08:44 +02:00
|
|
|
buffer[pos++] = lifetime;
|
2010-04-30 15:43:53 +02:00
|
|
|
|
2016-02-01 18:02:33 +01:00
|
|
|
if(instance->mop != RPL_MOP_NON_STORING) {
|
|
|
|
/* Send DAO to parent */
|
|
|
|
dest_ipaddr = parent_ipaddr;
|
|
|
|
} else {
|
|
|
|
/* Include parent global IP address */
|
|
|
|
memcpy(buffer + pos, &parent->dag->dag_id, 8); /* Prefix */
|
|
|
|
pos += 8;
|
|
|
|
memcpy(buffer + pos, ((const unsigned char *)parent_ipaddr) + 8, 8); /* Interface identifier */
|
|
|
|
pos += 8;
|
|
|
|
/* Send DAO to root */
|
|
|
|
dest_ipaddr = &parent->dag->dag_id;
|
|
|
|
}
|
|
|
|
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: Sending a %sDAO with sequence number %u, lifetime %u, prefix ",
|
2017-02-07 23:11:36 +01:00
|
|
|
lifetime == RPL_ZERO_LIFETIME ? "No-Path " : "", seq_no, lifetime);
|
2016-02-01 18:02:33 +01:00
|
|
|
|
2013-07-25 10:39:39 +02:00
|
|
|
PRINT6ADDR(prefix);
|
2010-05-18 18:43:56 +02:00
|
|
|
PRINTF(" to ");
|
2016-02-01 18:02:33 +01:00
|
|
|
PRINT6ADDR(dest_ipaddr);
|
|
|
|
PRINTF(" , parent ");
|
|
|
|
PRINT6ADDR(parent_ipaddr);
|
2010-05-18 18:43:56 +02:00
|
|
|
PRINTF("\n");
|
|
|
|
|
2016-02-01 18:02:33 +01:00
|
|
|
if(dest_ipaddr != NULL) {
|
|
|
|
uip_icmp6_send(dest_ipaddr, ICMP6_RPL, RPL_CODE_DAO, pos);
|
2013-08-12 00:11:48 +02:00
|
|
|
}
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-06-06 23:42:50 +02:00
|
|
|
static void
|
|
|
|
dao_ack_input(void)
|
|
|
|
{
|
2015-08-19 15:50:20 +02:00
|
|
|
#if RPL_WITH_DAO_ACK
|
|
|
|
|
|
|
|
uint8_t *buffer;
|
|
|
|
uint8_t instance_id;
|
2010-06-06 23:42:50 +02:00
|
|
|
uint8_t sequence;
|
|
|
|
uint8_t status;
|
2015-08-19 15:50:20 +02:00
|
|
|
rpl_instance_t *instance;
|
|
|
|
rpl_parent_t *parent;
|
2010-06-06 23:42:50 +02:00
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
|
|
|
|
2015-09-20 21:02:30 +02:00
|
|
|
instance_id = buffer[0];
|
2010-06-06 23:42:50 +02:00
|
|
|
sequence = buffer[2];
|
|
|
|
status = buffer[3];
|
|
|
|
|
2015-08-19 15:50:20 +02:00
|
|
|
instance = rpl_get_instance(instance_id);
|
|
|
|
if(instance == NULL) {
|
2015-08-27 20:07:13 +02:00
|
|
|
uip_clear_buf();
|
2015-08-19 15:50:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-03 21:19:08 +02:00
|
|
|
if(RPL_IS_STORING(instance)) {
|
|
|
|
parent = rpl_find_parent(instance->current_dag, &UIP_IP_BUF->srcipaddr);
|
|
|
|
if(parent == NULL) {
|
|
|
|
/* not a known instance - drop the packet and ignore */
|
|
|
|
uip_clear_buf();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parent = NULL;
|
2015-08-19 15:50:20 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: Received a DAO %s with sequence number %d (%d) and status %d from ",
|
2017-02-07 23:11:36 +01:00
|
|
|
status < 128 ? "ACK" : "NACK",
|
|
|
|
sequence, instance->my_dao_seqno, status);
|
2010-06-06 23:42:50 +02:00
|
|
|
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
PRINTF("\n");
|
2015-08-19 15:50:20 +02:00
|
|
|
|
|
|
|
if(sequence == instance->my_dao_seqno) {
|
2016-03-26 20:12:52 +01:00
|
|
|
instance->has_downward_route = status < 128;
|
2015-09-22 21:01:55 +02:00
|
|
|
|
2015-08-19 15:50:20 +02:00
|
|
|
/* always stop the retransmit timer when the ACK arrived */
|
|
|
|
ctimer_stop(&instance->dao_retransmit_timer);
|
|
|
|
|
|
|
|
/* Inform objective function on status of the DAO ACK */
|
2016-06-03 21:19:08 +02:00
|
|
|
if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
|
2015-08-19 15:50:20 +02:00
|
|
|
instance->of->dao_ack_callback(parent, status);
|
|
|
|
}
|
|
|
|
|
2015-09-22 21:01:55 +02:00
|
|
|
#if RPL_REPAIR_ON_DAO_NACK
|
2015-08-19 15:50:20 +02:00
|
|
|
if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
|
2016-03-26 20:12:52 +01:00
|
|
|
/*
|
|
|
|
* Failed the DAO transmission - need to remove the default route.
|
|
|
|
* Trigger a local repair since we can not get our DAO in.
|
|
|
|
*/
|
2015-08-19 15:50:20 +02:00
|
|
|
rpl_local_repair(instance);
|
|
|
|
}
|
2015-09-22 21:01:55 +02:00
|
|
|
#endif
|
|
|
|
|
2016-06-03 21:19:08 +02:00
|
|
|
} else if(RPL_IS_STORING(instance)) {
|
2015-11-23 13:38:48 +01:00
|
|
|
/* this DAO ACK should be forwarded to another recently registered route */
|
2015-08-19 15:50:20 +02:00
|
|
|
uip_ds6_route_t *re;
|
|
|
|
uip_ipaddr_t *nexthop;
|
|
|
|
if((re = find_route_entry_by_dao_ack(sequence)) != NULL) {
|
|
|
|
/* pick the recorded seq no from that node and forward DAO ACK - and
|
|
|
|
clear the pending flag*/
|
|
|
|
RPL_ROUTE_CLEAR_DAO_PENDING(re);
|
|
|
|
|
|
|
|
nexthop = uip_ds6_route_nexthop(re);
|
|
|
|
if(nexthop == NULL) {
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: No next hop to fwd DAO ACK to\n");
|
2015-08-19 15:50:20 +02:00
|
|
|
} else {
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: Fwd DAO ACK to:");
|
2015-09-20 21:02:30 +02:00
|
|
|
PRINT6ADDR(nexthop);
|
|
|
|
PRINTF("\n");
|
2015-08-19 15:50:20 +02:00
|
|
|
buffer[2] = re->state.dao_seqno_in;
|
|
|
|
uip_icmp6_send(nexthop, ICMP6_RPL, RPL_CODE_DAO_ACK, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
|
|
|
|
/* this node did not get in to the routing tables above... - remove */
|
|
|
|
uip_ds6_route_rm(re);
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-27 14:00:55 +02:00
|
|
|
PRINTF("RPL: No route entry found to forward DAO ACK (seqno %u)\n", sequence);
|
2015-08-19 15:50:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
2015-06-15 10:25:58 +02:00
|
|
|
uip_clear_buf();
|
2010-06-06 23:42:50 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2015-08-19 15:50:20 +02:00
|
|
|
dao_ack_output(rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence,
|
2017-02-07 23:11:36 +01:00
|
|
|
uint8_t status)
|
2010-06-06 23:42:50 +02:00
|
|
|
{
|
2015-08-19 15:50:20 +02:00
|
|
|
#if RPL_WITH_DAO_ACK
|
2010-06-06 23:42:50 +02:00
|
|
|
unsigned char *buffer;
|
|
|
|
|
2015-11-23 13:38:48 +01:00
|
|
|
PRINTF("RPL: Sending a DAO %s with sequence number %d to ", status < 128 ? "ACK" : "NACK", sequence);
|
2010-06-06 23:42:50 +02:00
|
|
|
PRINT6ADDR(dest);
|
2015-08-19 15:50:20 +02:00
|
|
|
PRINTF(" with status %d\n", status);
|
2010-06-06 23:42:50 +02:00
|
|
|
|
|
|
|
buffer = UIP_ICMP_PAYLOAD;
|
|
|
|
|
2011-07-11 15:50:51 +02:00
|
|
|
buffer[0] = instance->instance_id;
|
2010-06-06 23:42:50 +02:00
|
|
|
buffer[1] = 0;
|
|
|
|
buffer[2] = sequence;
|
2015-08-19 15:50:20 +02:00
|
|
|
buffer[3] = status;
|
2010-06-06 23:42:50 +02:00
|
|
|
|
|
|
|
uip_icmp6_send(dest, ICMP6_RPL, RPL_CODE_DAO_ACK, 4);
|
2015-08-19 15:50:20 +02:00
|
|
|
#endif /* RPL_WITH_DAO_ACK */
|
2010-06-06 23:42:50 +02:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-04-30 15:43:53 +02:00
|
|
|
void
|
2014-03-08 22:36:45 +01:00
|
|
|
rpl_icmp6_register_handlers()
|
2010-04-30 15:43:53 +02:00
|
|
|
{
|
2014-03-08 22:36:45 +01:00
|
|
|
uip_icmp6_register_input_handler(&dis_handler);
|
|
|
|
uip_icmp6_register_input_handler(&dio_handler);
|
|
|
|
uip_icmp6_register_input_handler(&dao_handler);
|
|
|
|
uip_icmp6_register_input_handler(&dao_ack_handler);
|
2010-04-30 15:43:53 +02:00
|
|
|
}
|
2014-03-08 22:36:45 +01:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2014-05-30 11:01:20 +02:00
|
|
|
|
|
|
|
/** @}*/
|