54 #include "net/routing/rpl-classic/rpl-private.h" 64 #define LOG_MODULE "RPL" 65 #define LOG_LEVEL LOG_LEVEL_RPL 68 #define RPL_DIO_GROUNDED 0x80 69 #define RPL_DIO_MOP_SHIFT 3 70 #define RPL_DIO_MOP_MASK 0x38 71 #define RPL_DIO_PREFERENCE_MASK 0x07 74 static void dis_input(
void);
75 static void dio_input(
void);
76 static void dao_input(
void);
77 static void dao_ack_input(
void);
79 static void dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
80 uint8_t lifetime, uint8_t seq_no);
83 #ifdef RPL_DEBUG_DIO_INPUT 84 void RPL_DEBUG_DIO_INPUT(uip_ipaddr_t *, rpl_dio_t *);
87 #ifdef RPL_DEBUG_DAO_OUTPUT 88 void RPL_DEBUG_DAO_OUTPUT(rpl_parent_t *);
91 static uint8_t dao_sequence = RPL_LOLLIPOP_INIT;
93 #if RPL_WITH_MULTICAST 98 UIP_ICMP6_HANDLER(dis_handler,
ICMP6_RPL, RPL_CODE_DIS, dis_input);
99 UIP_ICMP6_HANDLER(dio_handler,
ICMP6_RPL, RPL_CODE_DIO, dio_input);
100 UIP_ICMP6_HANDLER(dao_handler,
ICMP6_RPL, RPL_CODE_DAO, dao_input);
101 UIP_ICMP6_HANDLER(dao_ack_handler,
ICMP6_RPL, RPL_CODE_DAO_ACK, dao_ack_input);
106 find_route_entry_by_dao_ack(uint8_t seq)
109 re = uip_ds6_route_head();
111 if(re->state.dao_seqno_out == seq && RPL_ROUTE_IS_DAO_PENDING(re)) {
115 re = uip_ds6_route_next(re);
127 RPL_LOLLIPOP_INCREMENT(dao_sequence);
130 rep->state.dao_seqno_in = sequence;
131 rep->state.dao_seqno_out = dao_sequence;
132 RPL_ROUTE_SET_DAO_PENDING(rep);
138 get_global_addr(uip_ipaddr_t *
addr)
142 uip_ipaddr_t *prefix = NULL;
143 uint8_t prefix_length = 0;
146 if(dag != NULL && dag->prefix_info.length != 0) {
147 prefix = &dag->prefix_info.prefix;
148 prefix_length = dag->prefix_info.length;
151 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
154 state == ADDR_PREFERRED &&
156 (prefix == NULL || uip_ipaddr_prefixcmp(prefix, &
uip_ds6_if.addr_list[i].ipaddr, prefix_length))) {
157 memcpy(addr, &
uip_ds6_if.addr_list[i].ipaddr,
sizeof(uip_ipaddr_t));
165 get32(uint8_t *buffer,
int pos)
167 return ((uint32_t)buffer[pos] << 24 | (uint32_t)buffer[pos + 1] << 16 |
168 (uint32_t)buffer[pos + 2] << 8 | buffer[pos + 3]);
172 set32(uint8_t *buffer,
int pos, uint32_t value)
174 buffer[pos++] = value >> 24;
175 buffer[pos++] = (value >> 16) & 0xff;
176 buffer[pos++] = (value >> 8) & 0xff;
177 buffer[pos++] = value & 0xff;
181 get16(uint8_t *buffer,
int pos)
183 return (uint16_t)buffer[pos] << 8 | buffer[pos + 1];
187 set16(uint8_t *buffer,
int pos, uint16_t value)
189 buffer[pos++] = value >> 8;
190 buffer[pos++] = value & 0xff;
200 packetbuf_addr(PACKETBUF_ADDR_SENDER),
201 0, NBR_REACHABLE, reason, data)) != NULL) {
202 LOG_INFO(
"Neighbor added to neighbor cache ");
203 LOG_INFO_6ADDR(from);
205 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
220 LOG_INFO(
"Received a DIS from ");
224 for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
225 instance < end; ++instance) {
226 if(instance->used == 1) {
229 LOG_INFO(
"LEAF ONLY Multicast DIS will NOT reset DIO timer\n");
231 LOG_DBG(
"Multicast DIS => reset DIO timer\n");
232 rpl_reset_dio_timer(instance);
237 NBR_TABLE_REASON_RPL_DIS, NULL) == NULL) {
238 LOG_ERR(
"Out of Memory, not sending unicast DIO, DIS from ");
241 LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
244 LOG_DBG(
"Unicast DIS, reply to sender\n");
255 dis_output(uip_ipaddr_t *addr)
257 unsigned char *buffer;
258 uip_ipaddr_t tmpaddr;
269 buffer = UIP_ICMP_PAYLOAD;
270 buffer[0] = buffer[1] = 0;
277 LOG_INFO(
"Sending a DIS to ");
278 LOG_INFO_6ADDR(addr);
287 unsigned char *buffer;
288 uint8_t buffer_length;
295 memset(&dio, 0,
sizeof(dio));
298 dio.dag_intdoubl = RPL_DIO_INTERVAL_DOUBLINGS;
299 dio.dag_intmin = RPL_DIO_INTERVAL_MIN;
300 dio.dag_redund = RPL_DIO_REDUNDANCY;
301 dio.dag_min_hoprankinc = RPL_MIN_HOPRANKINC;
302 dio.dag_max_rankinc = RPL_MAX_RANKINC;
303 dio.ocp = RPL_OF_OCP;
304 dio.default_lifetime = RPL_DEFAULT_LIFETIME;
305 dio.lifetime_unit = RPL_DEFAULT_LIFETIME_UNIT;
310 LOG_INFO(
"Received a DIO from ");
311 LOG_INFO_6ADDR(&from);
314 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
318 buffer = UIP_ICMP_PAYLOAD;
320 dio.instance_id = buffer[i++];
321 dio.version = buffer[i++];
322 dio.rank = get16(buffer, i);
325 LOG_DBG(
"Incoming DIO (id, ver, rank) = (%u,%u,%u)\n",
326 (
unsigned)dio.instance_id,
327 (
unsigned)dio.version,
330 dio.grounded = buffer[i] & RPL_DIO_GROUNDED;
331 dio.mop = (buffer[i]& RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT;
332 dio.preference = buffer[i++] & RPL_DIO_PREFERENCE_MASK;
334 dio.dtsn = buffer[i++];
338 memcpy(&dio.dag_id, buffer + i,
sizeof(dio.dag_id));
339 i +=
sizeof(dio.dag_id);
341 LOG_DBG(
"Incoming DIO (dag_id, pref) = (");
342 LOG_DBG_6ADDR(&dio.dag_id);
343 LOG_DBG_(
", %u)\n", dio.preference);
346 for(; i < buffer_length; i += len) {
347 subopt_type = buffer[i];
348 if(subopt_type == RPL_OPTION_PAD1) {
352 len = 2 + buffer[i + 1];
355 if(len + i > buffer_length) {
356 LOG_WARN(
"Invalid DIO packet\n");
357 RPL_STAT(rpl_stats.malformed_msgs++);
361 LOG_DBG(
"Incoming DIO (option, length) = (%u, %u)\n", subopt_type, len - 2);
363 switch(subopt_type) {
364 case RPL_OPTION_DAG_METRIC_CONTAINER:
366 LOG_WARN(
"Invalid DAG MC, len = %d\n", len);
367 RPL_STAT(rpl_stats.malformed_msgs++);
370 dio.mc.type = buffer[i + 2];
371 dio.mc.flags = buffer[i + 3] << 1;
372 dio.mc.flags |= buffer[i + 4] >> 7;
373 dio.mc.aggr = (buffer[i + 4] >> 4) & 0x3;
374 dio.mc.prec = buffer[i + 4] & 0xf;
375 dio.mc.length = buffer[i + 5];
377 if(dio.mc.type == RPL_DAG_MC_NONE) {
379 }
else if(dio.mc.type == RPL_DAG_MC_ETX) {
380 dio.mc.obj.etx = get16(buffer, i + 6);
382 LOG_DBG(
"DAG MC: type %u, flags %u, aggr %u, prec %u, length %u, ETX %u\n",
383 (
unsigned)dio.mc.type,
384 (
unsigned)dio.mc.flags,
385 (
unsigned)dio.mc.aggr,
386 (
unsigned)dio.mc.prec,
387 (
unsigned)dio.mc.length,
388 (
unsigned)dio.mc.obj.etx);
389 }
else if(dio.mc.type == RPL_DAG_MC_ENERGY) {
390 dio.mc.obj.energy.flags = buffer[i + 6];
391 dio.mc.obj.energy.energy_est = buffer[i + 7];
393 LOG_WARN(
"Unhandled DAG MC type: %u\n", (
unsigned)dio.mc.type);
397 case RPL_OPTION_ROUTE_INFO:
399 LOG_WARN(
"Invalid destination prefix option, len = %d\n", len);
400 RPL_STAT(rpl_stats.malformed_msgs++);
405 dio.destination_prefix.length = buffer[i + 2];
406 dio.destination_prefix.flags = buffer[i + 3];
407 dio.destination_prefix.lifetime = get32(buffer, i + 4);
409 if(((dio.destination_prefix.length + 7) / 8) + 8 <= len &&
410 dio.destination_prefix.length <= 128) {
411 LOG_INFO(
"Copying destination prefix\n");
412 memcpy(&dio.destination_prefix.prefix, &buffer[i + 8],
413 (dio.destination_prefix.length + 7) / 8);
415 LOG_WARN(
"Invalid route info option, len = %d\n", len);
416 RPL_STAT(rpl_stats.malformed_msgs++);
421 case RPL_OPTION_DAG_CONF:
423 LOG_WARN(
"Invalid DAG configuration option, len = %d\n", len);
424 RPL_STAT(rpl_stats.malformed_msgs++);
429 dio.dag_intdoubl = buffer[i + 3];
430 dio.dag_intmin = buffer[i + 4];
431 dio.dag_redund = buffer[i + 5];
432 dio.dag_max_rankinc = get16(buffer, i + 6);
433 dio.dag_min_hoprankinc = get16(buffer, i + 8);
434 dio.ocp = get16(buffer, i + 10);
436 dio.default_lifetime = buffer[i + 13];
437 dio.lifetime_unit = get16(buffer, i + 14);
438 LOG_INFO(
"DAG conf:dbl=%d, min=%d red=%d maxinc=%d mininc=%d ocp=%d d_l=%u l_u=%u\n",
439 dio.dag_intdoubl, dio.dag_intmin, dio.dag_redund,
440 dio.dag_max_rankinc, dio.dag_min_hoprankinc, dio.ocp,
441 dio.default_lifetime, dio.lifetime_unit);
443 case RPL_OPTION_PREFIX_INFO:
445 LOG_WARN(
"Invalid DAG prefix info, len != 32\n");
446 RPL_STAT(rpl_stats.malformed_msgs++);
449 dio.prefix_info.length = buffer[i + 2];
451 if(dio.prefix_info.length >
sizeof(uip_ipaddr_t) * 8) {
452 LOG_WARN(
"Invalid DAG prefix info, len %u > %u\n",
453 dio.prefix_info.length, (
unsigned)(
sizeof(uip_ipaddr_t) * 8));
454 RPL_STAT(rpl_stats.malformed_msgs++);
458 dio.prefix_info.flags = buffer[i + 3];
461 dio.prefix_info.lifetime = get32(buffer, i + 8);
463 LOG_INFO(
"Copying prefix information\n");
464 memcpy(&dio.prefix_info.prefix, &buffer[i + 16], 16);
467 LOG_WARN(
"Unsupported suboption type in DIO: %u\n",
468 (
unsigned)subopt_type);
472 #ifdef RPL_DEBUG_DIO_INPUT 473 RPL_DEBUG_DIO_INPUT(&from, &dio);
485 unsigned char *buffer;
496 if(uc_addr == NULL) {
497 LOG_DBG(
"LEAF ONLY have multicast addr: skip dio_output\n");
505 buffer = UIP_ICMP_PAYLOAD;
506 buffer[pos++] = instance->instance_id;
507 buffer[pos++] = dag->version;
508 is_root = (dag->rank ==
ROOT_RANK(instance));
511 LOG_DBG(
"LEAF ONLY DIO rank set to RPL_INFINITE_RANK\n");
512 set16(buffer, pos, RPL_INFINITE_RANK);
514 set16(buffer, pos, dag->rank);
520 buffer[pos] |= RPL_DIO_GROUNDED;
523 buffer[pos] |= instance->mop << RPL_DIO_MOP_SHIFT;
524 buffer[pos] |= dag->preference & RPL_DIO_PREFERENCE_MASK;
527 buffer[pos++] = instance->dtsn_out;
529 if(RPL_DIO_REFRESH_DAO_ROUTES && is_root && uc_addr == NULL) {
533 RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
540 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
544 if(instance->mc.type != RPL_DAG_MC_NONE) {
545 instance->of->update_metric_container(instance);
547 buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER;
549 buffer[pos++] = instance->mc.type;
550 buffer[pos++] = instance->mc.flags >> 1;
551 buffer[pos] = (instance->mc.flags & 1) << 7;
552 buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
553 if(instance->mc.type == RPL_DAG_MC_ETX) {
555 set16(buffer, pos, instance->mc.obj.etx);
557 }
else if(instance->mc.type == RPL_DAG_MC_ENERGY) {
559 buffer[pos++] = instance->mc.obj.energy.flags;
560 buffer[pos++] = instance->mc.obj.energy.energy_est;
562 LOG_ERR(
"Unable to send DIO because of unhandled DAG MC type %u\n",
563 (
unsigned)instance->mc.type);
570 buffer[pos++] = RPL_OPTION_DAG_CONF;
573 buffer[pos++] = instance->dio_intdoubl;
574 buffer[pos++] = instance->dio_intmin;
575 buffer[pos++] = instance->dio_redundancy;
576 set16(buffer, pos, instance->max_rankinc);
578 set16(buffer, pos, instance->min_hoprankinc);
581 set16(buffer, pos, instance->of->ocp);
584 buffer[pos++] = instance->default_lifetime;
585 set16(buffer, pos, instance->lifetime_unit);
589 if(dag->prefix_info.length > 0) {
590 buffer[pos++] = RPL_OPTION_PREFIX_INFO;
592 buffer[pos++] = dag->prefix_info.length;
593 buffer[pos++] = dag->prefix_info.flags;
594 set32(buffer, pos, dag->prefix_info.lifetime);
596 set32(buffer, pos, dag->prefix_info.lifetime);
598 memset(&buffer[pos], 0, 4);
600 memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
602 LOG_DBG(
"Sending prefix info in DIO for ");
603 LOG_DBG_6ADDR(&dag->prefix_info.prefix);
606 LOG_DBG(
"No prefix to announce (len %d)\n",
607 dag->prefix_info.length);
611 if(LOG_DBG_ENABLED) {
612 if(uc_addr == NULL) {
613 LOG_DBG(
"LEAF ONLY sending unicast-DIO from multicast-DIO\n");
617 LOG_INFO(
"Sending unicast-DIO with rank %u to ",
618 (
unsigned)dag->rank);
619 LOG_INFO_6ADDR(uc_addr);
624 if(uc_addr == NULL) {
625 LOG_INFO(
"Sending a multicast-DIO with rank %u\n",
626 (
unsigned)instance->current_dag->rank);
630 LOG_INFO(
"Sending unicast-DIO with rank %u to ",
631 (
unsigned)instance->current_dag->rank);
632 LOG_INFO_6ADDR(uc_addr);
640 dao_input_storing(
void)
643 uip_ipaddr_t dao_sender_addr;
646 unsigned char *buffer;
659 uint8_t buffer_length;
664 rpl_parent_t *parent;
670 memset(&prefix, 0,
sizeof(prefix));
674 buffer = UIP_ICMP_PAYLOAD;
675 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
678 instance_id = buffer[pos++];
680 instance = rpl_get_instance(instance_id);
682 lifetime = instance->default_lifetime;
684 flags = buffer[pos++];
687 sequence = buffer[pos++];
689 dag = instance->current_dag;
690 is_root = (dag->rank ==
ROOT_RANK(instance));
693 if(flags & RPL_DAO_D_FLAG) {
694 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
695 LOG_INFO(
"Ignoring a DAO for a DAG different from ours\n");
702 RPL_ROUTE_FROM_MULTICAST_DAO : RPL_ROUTE_FROM_UNICAST_DAO;
705 LOG_DBG(
"Received a (%s) DAO with sequence number %u from ",
706 learned_from == RPL_ROUTE_FROM_UNICAST_DAO?
"unicast":
"multicast", sequence);
707 LOG_DBG_6ADDR(&dao_sender_addr);
710 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
712 parent = rpl_find_parent(dag, &dao_sender_addr);
717 LOG_WARN(
"Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n",
719 parent->rank = RPL_INFINITE_RANK;
720 parent->flags |= RPL_PARENT_FLAG_UPDATED;
725 if(parent != NULL && parent == dag->preferred_parent) {
726 LOG_WARN(
"Loop detected when receiving a unicast DAO from our parent\n");
727 parent->rank = RPL_INFINITE_RANK;
728 parent->flags |= RPL_PARENT_FLAG_UPDATED;
734 for(i = pos; i < buffer_length; i += len) {
735 subopt_type = buffer[i];
736 if(subopt_type == RPL_OPTION_PAD1) {
740 len = 2 + buffer[i + 1];
743 switch(subopt_type) {
744 case RPL_OPTION_TARGET:
746 prefixlen = buffer[i + 3];
747 memset(&prefix, 0,
sizeof(prefix));
748 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
750 case RPL_OPTION_TRANSIT:
754 lifetime = buffer[i + 5];
760 LOG_INFO(
"DAO lifetime: %u, prefix length: %u prefix: ",
761 (
unsigned)lifetime, (
unsigned)prefixlen);
762 LOG_INFO_6ADDR(&prefix);
765 #if RPL_WITH_MULTICAST 774 mcast_group->
dag = dag;
781 rep = uip_ds6_route_lookup(&prefix);
783 if(lifetime == RPL_ZERO_LIFETIME) {
784 LOG_INFO(
"No-Path DAO received\n");
787 !RPL_ROUTE_IS_NOPATH_RECEIVED(rep) &&
788 rep->length == prefixlen &&
789 uip_ds6_route_nexthop(rep) != NULL &&
790 uip_ipaddr_cmp(uip_ds6_route_nexthop(rep), &dao_sender_addr)) {
791 LOG_DBG(
"Setting expiration timer for prefix ");
792 LOG_DBG_6ADDR(&prefix);
794 RPL_ROUTE_SET_NOPATH_RECEIVED(rep);
795 rep->state.lifetime = RPL_NOPATH_REMOVAL_DELAY;
799 if(dag->preferred_parent != NULL &&
800 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
802 out_seq = prepare_for_dao_fwd(sequence, rep);
804 LOG_DBG(
"Forwarding No-path DAO to parent - out_seq:%d",
806 LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
809 buffer = UIP_ICMP_PAYLOAD;
816 if(flags & RPL_DAO_K_FLAG) {
819 dao_ack_output(instance, &dao_sender_addr, sequence,
820 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
825 LOG_INFO(
"Adding DAO route\n");
829 LOG_ERR(
"Out of Memory, dropping DAO from ");
830 LOG_ERR_6ADDR(&dao_sender_addr);
832 LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
834 if(flags & RPL_DAO_K_FLAG) {
836 dao_ack_output(instance, &dao_sender_addr, sequence,
837 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
838 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
843 rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
845 RPL_STAT(rpl_stats.mem_overflows++);
846 LOG_ERR(
"Could not add a route after receiving a DAO\n");
847 if(flags & RPL_DAO_K_FLAG) {
849 dao_ack_output(instance, &dao_sender_addr, sequence,
850 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
851 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
858 RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep);
860 #if RPL_WITH_MULTICAST 864 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
867 if(flags & RPL_DAO_K_FLAG) {
875 if((!RPL_ROUTE_IS_DAO_PENDING(rep) &&
876 rep->state.dao_seqno_in == sequence) ||
883 if(dag->preferred_parent != NULL &&
884 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
888 if(RPL_ROUTE_IS_DAO_PENDING(rep) &&
889 rep->state.dao_seqno_in == sequence) {
891 out_seq = rep->state.dao_seqno_out;
893 out_seq = prepare_for_dao_fwd(sequence, rep);
897 LOG_DBG(
"Forwarding DAO to parent ");
898 LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
899 LOG_DBG_(
" in seq: %d out seq: %d\n", sequence, out_seq);
901 buffer = UIP_ICMP_PAYLOAD;
907 LOG_DBG(
"Sending DAO ACK\n");
909 dao_ack_output(instance, &dao_sender_addr, sequence,
910 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
917 dao_input_nonstoring(
void)
919 #if RPL_WITH_NON_STORING 920 uip_ipaddr_t dao_sender_addr;
921 uip_ipaddr_t dao_parent_addr;
924 unsigned char *buffer;
932 uint8_t buffer_length;
938 LOG_INFO(
"Received a DAO from ");
945 memset(&dao_parent_addr, 0, 16);
947 buffer = UIP_ICMP_PAYLOAD;
948 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
951 instance_id = buffer[pos++];
952 instance = rpl_get_instance(instance_id);
953 lifetime = instance->default_lifetime;
955 flags = buffer[pos++];
958 sequence = buffer[pos++];
960 dag = instance->current_dag;
962 if(flags & RPL_DAO_D_FLAG) {
963 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
964 LOG_INFO(
"Ignoring a DAO for a DAG different from ours\n");
971 for(i = pos; i < buffer_length; i += len) {
972 subopt_type = buffer[i];
973 if(subopt_type == RPL_OPTION_PAD1) {
977 len = 2 + buffer[i + 1];
980 switch(subopt_type) {
981 case RPL_OPTION_TARGET:
983 prefixlen = buffer[i + 3];
984 memset(&prefix, 0,
sizeof(prefix));
985 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
987 case RPL_OPTION_TRANSIT:
991 lifetime = buffer[i + 5];
993 memcpy(&dao_parent_addr, buffer + i + 6, 16);
999 LOG_INFO(
"DAO lifetime: %u, prefix length: %u prefix: ",
1000 (
unsigned)lifetime, (
unsigned)prefixlen);
1001 LOG_INFO_6ADDR(&prefix);
1002 LOG_INFO_(
", parent: ");
1003 LOG_INFO_6ADDR(&dao_parent_addr);
1006 if(lifetime == RPL_ZERO_LIFETIME) {
1007 LOG_DBG(
"No-Path DAO received\n");
1011 LOG_WARN(
"DAO failed to add link prefix: ");
1012 LOG_WARN_6ADDR(&prefix);
1013 LOG_WARN_(
", parent: ");
1014 LOG_WARN_6ADDR(&dao_parent_addr);
1020 if(flags & RPL_DAO_K_FLAG) {
1021 LOG_DBG(
"Sending DAO ACK\n");
1023 dao_ack_output(instance, &dao_sender_addr, sequence,
1024 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
1033 uint8_t instance_id;
1036 LOG_INFO(
"Received a DAO from ");
1040 instance_id = UIP_ICMP_PAYLOAD[0];
1041 instance = rpl_get_instance(instance_id);
1042 if(instance == NULL) {
1043 LOG_INFO(
"Ignoring a DAO for an unknown RPL instance(%u)\n",
1048 if(RPL_IS_STORING(instance)) {
1049 dao_input_storing();
1050 }
else if(RPL_IS_NON_STORING(instance)) {
1051 dao_input_nonstoring();
1058 #if RPL_WITH_DAO_ACK 1060 handle_dao_retransmission(
void *ptr)
1062 rpl_parent_t *parent;
1063 uip_ipaddr_t prefix;
1067 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1070 instance = parent->dag->instance;
1072 if(instance->my_dao_transmissions >= RPL_DAO_MAX_RETRANSMISSIONS) {
1074 if(instance->lifetime_unit == 0xffff && instance->default_lifetime == 0xff) {
1085 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1087 instance->of->dao_ack_callback(parent, RPL_DAO_ACK_TIMEOUT);
1095 LOG_INFO(
"will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno,
1096 instance->my_dao_transmissions);
1098 if(get_global_addr(&prefix) == 0) {
1103 RPL_DAO_RETRANSMISSION_TIMEOUT / 2 +
1104 (
random_rand() % (RPL_DAO_RETRANSMISSION_TIMEOUT / 2)),
1105 handle_dao_retransmission, parent);
1107 instance->my_dao_transmissions++;
1108 dao_output_target_seq(parent, &prefix,
1109 instance->default_lifetime, instance->my_dao_seqno);
1114 dao_output(rpl_parent_t *parent, uint8_t lifetime)
1117 uip_ipaddr_t prefix;
1119 if(get_global_addr(&prefix) == 0) {
1120 LOG_ERR(
"No global address set for this node - suppressing DAO\n");
1124 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1128 RPL_LOLLIPOP_INCREMENT(dao_sequence);
1129 #if RPL_WITH_DAO_ACK 1133 if(lifetime != RPL_ZERO_LIFETIME) {
1135 instance = parent->dag->instance;
1137 instance->my_dao_seqno = dao_sequence;
1138 instance->my_dao_transmissions = 1;
1139 ctimer_set(&instance->dao_retransmit_timer, RPL_DAO_RETRANSMISSION_TIMEOUT,
1140 handle_dao_retransmission, parent);
1145 parent->dag->instance->has_downward_route = lifetime != RPL_ZERO_LIFETIME;
1149 dao_output_target(parent, &prefix, lifetime);
1153 dao_output_target(rpl_parent_t *parent, uip_ipaddr_t *prefix, uint8_t lifetime)
1155 dao_output_target_seq(parent, prefix, lifetime, dao_sequence);
1159 dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
1160 uint8_t lifetime, uint8_t seq_no)
1164 unsigned char *buffer;
1167 uip_ipaddr_t *parent_ipaddr = NULL;
1168 uip_ipaddr_t *dest_ipaddr = NULL;
1177 if(parent == NULL) {
1178 LOG_ERR(
"dao_output_target error parent NULL\n");
1182 parent_ipaddr = rpl_parent_get_ipaddr(parent);
1183 if(parent_ipaddr == NULL) {
1184 LOG_ERR(
"dao_output_target error parent IP address NULL\n");
1190 LOG_ERR(
"dao_output_target error dag NULL\n");
1194 instance = dag->instance;
1196 if(instance == NULL) {
1197 LOG_ERR(
"dao_output_target error instance NULL\n");
1200 if(prefix == NULL) {
1201 LOG_ERR(
"dao_output_target error prefix NULL\n");
1204 #ifdef RPL_DEBUG_DAO_OUTPUT 1205 RPL_DEBUG_DAO_OUTPUT(parent);
1208 buffer = UIP_ICMP_PAYLOAD;
1211 buffer[pos++] = instance->instance_id;
1213 #if RPL_DAO_SPECIFY_DAG 1214 buffer[pos] |= RPL_DAO_D_FLAG;
1216 #if RPL_WITH_DAO_ACK 1217 if(lifetime != RPL_ZERO_LIFETIME) {
1218 buffer[pos] |= RPL_DAO_K_FLAG;
1223 buffer[pos++] = seq_no;
1224 #if RPL_DAO_SPECIFY_DAG 1225 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
1226 pos+=
sizeof(dag->dag_id);
1230 prefixlen =
sizeof(*prefix) * CHAR_BIT;
1231 buffer[pos++] = RPL_OPTION_TARGET;
1232 buffer[pos++] = 2 + ((prefixlen + 7) / CHAR_BIT);
1234 buffer[pos++] = prefixlen;
1235 memcpy(buffer + pos, prefix, (prefixlen + 7) / CHAR_BIT);
1236 pos += ((prefixlen + 7) / CHAR_BIT);
1239 buffer[pos++] = RPL_OPTION_TRANSIT;
1240 buffer[pos++] = (instance->mop != RPL_MOP_NON_STORING) ? 4 : 20;
1244 buffer[pos++] = lifetime;
1246 if(instance->mop != RPL_MOP_NON_STORING) {
1248 dest_ipaddr = parent_ipaddr;
1251 memcpy(buffer + pos, &parent->dag->dag_id, 8);
1253 memcpy(buffer + pos, ((
const unsigned char *)parent_ipaddr) + 8, 8);
1256 dest_ipaddr = &parent->dag->dag_id;
1259 LOG_INFO(
"Sending a %sDAO with sequence number %u, lifetime %u, prefix ",
1260 lifetime == RPL_ZERO_LIFETIME ?
"No-Path " :
"", seq_no, lifetime);
1262 LOG_INFO_6ADDR(prefix);
1264 LOG_INFO_6ADDR(dest_ipaddr);
1265 LOG_INFO_(
" , parent ");
1266 LOG_INFO_6ADDR(parent_ipaddr);
1269 if(dest_ipaddr != NULL) {
1277 #if RPL_WITH_DAO_ACK 1280 uint8_t instance_id;
1284 rpl_parent_t *parent;
1286 buffer = UIP_ICMP_PAYLOAD;
1288 instance_id = buffer[0];
1289 sequence = buffer[2];
1292 instance = rpl_get_instance(instance_id);
1293 if(instance == NULL) {
1298 if(RPL_IS_STORING(instance)) {
1299 parent = rpl_find_parent(instance->current_dag, &
UIP_IP_BUF->srcipaddr);
1300 if(parent == NULL) {
1309 if(instance->current_dag->rank ==
ROOT_RANK(instance)) {
1310 LOG_DBG(
"DODAG root received a DAO ACK, ignoring it\n");
1315 LOG_INFO(
"Received a DAO %s with sequence number %d (%d) and status %d from ",
1316 status < 128 ?
"ACK" :
"NACK",
1317 sequence, instance->my_dao_seqno, status);
1321 if(sequence == instance->my_dao_seqno) {
1322 instance->has_downward_route = status < 128;
1328 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1329 instance->of->dao_ack_callback(parent, status);
1332 #if RPL_REPAIR_ON_DAO_NACK 1333 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1342 }
else if(RPL_IS_STORING(instance)) {
1345 const uip_ipaddr_t *nexthop;
1346 if((re = find_route_entry_by_dao_ack(sequence)) != NULL) {
1349 RPL_ROUTE_CLEAR_DAO_PENDING(re);
1351 nexthop = uip_ds6_route_nexthop(re);
1352 if(nexthop == NULL) {
1353 LOG_WARN(
"No next hop to fwd DAO ACK to\n");
1355 LOG_INFO(
"Fwd DAO ACK to:");
1356 LOG_INFO_6ADDR(nexthop);
1358 buffer[2] = re->state.dao_seqno_in;
1362 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1364 uip_ds6_route_rm(re);
1367 LOG_WARN(
"No route entry found to forward DAO ACK (seqno %u)\n", sequence);
1375 dao_ack_output(
rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence,
1378 #if RPL_WITH_DAO_ACK 1379 unsigned char *buffer;
1381 LOG_INFO(
"Sending a DAO %s with sequence number %d to ", status < 128 ?
"ACK" :
"NACK", sequence);
1382 LOG_INFO_6ADDR(dest);
1383 LOG_INFO_(
" with status %d\n", status);
1385 buffer = UIP_ICMP_PAYLOAD;
1387 buffer[0] = instance->instance_id;
1389 buffer[2] = sequence;
1397 rpl_icmp6_register_handlers()
#define UIP_IP_BUF
Direct access to IPv6 header.
Header for the Contiki/uIP interface.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
Header file for ICMPv6 message and error handing (RFC 4443)
static uip_ds6_nbr_t * nbr
Pointer to llao option in uip_buf.
#define ROOT_RANK
Rank of a root node.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
#define uip_is_addr_mcast_global(a)
is address a global multicast address (FFxE::/16), a is of type uip_ip6addr_t*
enum rpl_mode rpl_get_mode(void)
Get the RPL mode.
#define RPL_LIFETIME(lifetime)
Compute lifetime, accounting for the lifetime unit.
void uip_sr_expire_parent(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent)
Expires a given child-parent link.
Header file for IPv6-related data structures.
An entry in the routing table.
This header file contains configuration directives for uIPv6 multicast support.
#define DAG_RANK(fixpt_rank)
Return DAG RANK as per RFC 6550 (rank divided by min_hoprankinc)
void * dag
Pointer to an rpl_dag_t struct.
uip_ds6_nbr_t * uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr)
Get the neighbor cache associated with a specified IPv6 address.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
rpl_dag_t * rpl_get_any_dag(void)
Returns pointer to any DAG (for compatibility with legagy RPL code)
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
uint32_t lifetime
Entry lifetime seconds.
An entry in the multicast routing table.
uip_ds6_nbr_t * rpl_icmp6_update_nbr_table(uip_ipaddr_t *from, nbr_table_reason_t reason, void *data)
Updates IPv6 neighbor cache on incoming link-local RPL ICMPv6 messages.
#define uip_is_addr_mcast(a)
is address a multicast address, see RFC 4291 a is of type uip_ipaddr_t*
Header file for the uIP TCP/IP stack.
uip_ds6_nbr_t * uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, const uip_lladdr_t *lladdr, uint8_t isrouter, uint8_t state, nbr_table_reason_t reason, void *data)
Add a neighbor cache for a specified IPv6 address, which is associated with a specified link-layer ad...
Header file for IPv6 Neighbor discovery (RFC 4861)
uip_ds6_netif_t uip_ds6_if
The single interface.
uip_sr_node_t * uip_sr_update_node(void *graph, const uip_ipaddr_t *child, const uip_ipaddr_t *parent, uint32_t lifetime)
Updates a child-parent link.
void rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
Processes incoming DIO.
void uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
Register a handler which can handle a specific ICMPv6 message type.
Header file for the Packet buffer (packetbuf) management
#define uip_create_linklocal_rplnodes_mcast(addr)
Set IP address addr to the link-local, all-rpl-nodes multicast address.
void rpl_local_repair(const char *str)
Triggers a RPL local repair.
void uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len)
Send an icmpv6 message.
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC 4291 i.e.
Header file for the logging system
uip_mcast6_route_t * uip_mcast6_route_add(uip_ipaddr_t *group)
Add a multicast route.
The default nbr_table entry (when UIP_DS6_NBR_MULTI_IPV6_ADDRS is disabled), that implements nbr cach...