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];
450 dio.prefix_info.flags = buffer[i + 3];
453 dio.prefix_info.lifetime = get32(buffer, i + 8);
455 LOG_INFO(
"Copying prefix information\n");
456 memcpy(&dio.prefix_info.prefix, &buffer[i + 16], 16);
459 LOG_WARN(
"Unsupported suboption type in DIO: %u\n",
460 (
unsigned)subopt_type);
464 #ifdef RPL_DEBUG_DIO_INPUT 465 RPL_DEBUG_DIO_INPUT(&from, &dio);
477 unsigned char *buffer;
488 if(uc_addr == NULL) {
489 LOG_DBG(
"LEAF ONLY have multicast addr: skip dio_output\n");
497 buffer = UIP_ICMP_PAYLOAD;
498 buffer[pos++] = instance->instance_id;
499 buffer[pos++] = dag->version;
500 is_root = (dag->rank ==
ROOT_RANK(instance));
503 LOG_DBG(
"LEAF ONLY DIO rank set to RPL_INFINITE_RANK\n");
504 set16(buffer, pos, RPL_INFINITE_RANK);
506 set16(buffer, pos, dag->rank);
512 buffer[pos] |= RPL_DIO_GROUNDED;
515 buffer[pos] |= instance->mop << RPL_DIO_MOP_SHIFT;
516 buffer[pos] |= dag->preference & RPL_DIO_PREFERENCE_MASK;
519 buffer[pos++] = instance->dtsn_out;
521 if(RPL_DIO_REFRESH_DAO_ROUTES && is_root && uc_addr == NULL) {
525 RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
532 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
536 if(instance->mc.type != RPL_DAG_MC_NONE) {
537 instance->of->update_metric_container(instance);
539 buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER;
541 buffer[pos++] = instance->mc.type;
542 buffer[pos++] = instance->mc.flags >> 1;
543 buffer[pos] = (instance->mc.flags & 1) << 7;
544 buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
545 if(instance->mc.type == RPL_DAG_MC_ETX) {
547 set16(buffer, pos, instance->mc.obj.etx);
549 }
else if(instance->mc.type == RPL_DAG_MC_ENERGY) {
551 buffer[pos++] = instance->mc.obj.energy.flags;
552 buffer[pos++] = instance->mc.obj.energy.energy_est;
554 LOG_ERR(
"Unable to send DIO because of unhandled DAG MC type %u\n",
555 (
unsigned)instance->mc.type);
562 buffer[pos++] = RPL_OPTION_DAG_CONF;
565 buffer[pos++] = instance->dio_intdoubl;
566 buffer[pos++] = instance->dio_intmin;
567 buffer[pos++] = instance->dio_redundancy;
568 set16(buffer, pos, instance->max_rankinc);
570 set16(buffer, pos, instance->min_hoprankinc);
573 set16(buffer, pos, instance->of->ocp);
576 buffer[pos++] = instance->default_lifetime;
577 set16(buffer, pos, instance->lifetime_unit);
581 if(dag->prefix_info.length > 0) {
582 buffer[pos++] = RPL_OPTION_PREFIX_INFO;
584 buffer[pos++] = dag->prefix_info.length;
585 buffer[pos++] = dag->prefix_info.flags;
586 set32(buffer, pos, dag->prefix_info.lifetime);
588 set32(buffer, pos, dag->prefix_info.lifetime);
590 memset(&buffer[pos], 0, 4);
592 memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
594 LOG_DBG(
"Sending prefix info in DIO for ");
595 LOG_DBG_6ADDR(&dag->prefix_info.prefix);
598 LOG_DBG(
"No prefix to announce (len %d)\n",
599 dag->prefix_info.length);
603 if(LOG_DBG_ENABLED) {
604 if(uc_addr == NULL) {
605 LOG_DBG(
"LEAF ONLY sending unicast-DIO from multicast-DIO\n");
609 LOG_INFO(
"Sending unicast-DIO with rank %u to ",
610 (
unsigned)dag->rank);
611 LOG_INFO_6ADDR(uc_addr);
616 if(uc_addr == NULL) {
617 LOG_INFO(
"Sending a multicast-DIO with rank %u\n",
618 (
unsigned)instance->current_dag->rank);
622 LOG_INFO(
"Sending unicast-DIO with rank %u to ",
623 (
unsigned)instance->current_dag->rank);
624 LOG_INFO_6ADDR(uc_addr);
632 dao_input_storing(
void)
635 uip_ipaddr_t dao_sender_addr;
638 unsigned char *buffer;
651 uint8_t buffer_length;
656 rpl_parent_t *parent;
662 memset(&prefix, 0,
sizeof(prefix));
666 buffer = UIP_ICMP_PAYLOAD;
667 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
670 instance_id = buffer[pos++];
672 instance = rpl_get_instance(instance_id);
674 lifetime = instance->default_lifetime;
676 flags = buffer[pos++];
679 sequence = buffer[pos++];
681 dag = instance->current_dag;
682 is_root = (dag->rank ==
ROOT_RANK(instance));
685 if(flags & RPL_DAO_D_FLAG) {
686 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
687 LOG_INFO(
"Ignoring a DAO for a DAG different from ours\n");
694 RPL_ROUTE_FROM_MULTICAST_DAO : RPL_ROUTE_FROM_UNICAST_DAO;
697 LOG_DBG(
"Received a (%s) DAO with sequence number %u from ",
698 learned_from == RPL_ROUTE_FROM_UNICAST_DAO?
"unicast":
"multicast", sequence);
699 LOG_DBG_6ADDR(&dao_sender_addr);
702 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
704 parent = rpl_find_parent(dag, &dao_sender_addr);
709 LOG_WARN(
"Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n",
711 parent->rank = RPL_INFINITE_RANK;
712 parent->flags |= RPL_PARENT_FLAG_UPDATED;
717 if(parent != NULL && parent == dag->preferred_parent) {
718 LOG_WARN(
"Loop detected when receiving a unicast DAO from our parent\n");
719 parent->rank = RPL_INFINITE_RANK;
720 parent->flags |= RPL_PARENT_FLAG_UPDATED;
726 for(i = pos; i < buffer_length; i += len) {
727 subopt_type = buffer[i];
728 if(subopt_type == RPL_OPTION_PAD1) {
732 len = 2 + buffer[i + 1];
735 switch(subopt_type) {
736 case RPL_OPTION_TARGET:
738 prefixlen = buffer[i + 3];
739 memset(&prefix, 0,
sizeof(prefix));
740 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
742 case RPL_OPTION_TRANSIT:
746 lifetime = buffer[i + 5];
752 LOG_INFO(
"DAO lifetime: %u, prefix length: %u prefix: ",
753 (
unsigned)lifetime, (
unsigned)prefixlen);
754 LOG_INFO_6ADDR(&prefix);
757 #if RPL_WITH_MULTICAST 766 mcast_group->
dag = dag;
773 rep = uip_ds6_route_lookup(&prefix);
775 if(lifetime == RPL_ZERO_LIFETIME) {
776 LOG_INFO(
"No-Path DAO received\n");
779 !RPL_ROUTE_IS_NOPATH_RECEIVED(rep) &&
780 rep->length == prefixlen &&
781 uip_ds6_route_nexthop(rep) != NULL &&
782 uip_ipaddr_cmp(uip_ds6_route_nexthop(rep), &dao_sender_addr)) {
783 LOG_DBG(
"Setting expiration timer for prefix ");
784 LOG_DBG_6ADDR(&prefix);
786 RPL_ROUTE_SET_NOPATH_RECEIVED(rep);
787 rep->state.lifetime = RPL_NOPATH_REMOVAL_DELAY;
791 if(dag->preferred_parent != NULL &&
792 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
794 out_seq = prepare_for_dao_fwd(sequence, rep);
796 LOG_DBG(
"Forwarding No-path DAO to parent - out_seq:%d",
798 LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
801 buffer = UIP_ICMP_PAYLOAD;
808 if(flags & RPL_DAO_K_FLAG) {
811 dao_ack_output(instance, &dao_sender_addr, sequence,
812 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
817 LOG_INFO(
"Adding DAO route\n");
821 LOG_ERR(
"Out of Memory, dropping DAO from ");
822 LOG_ERR_6ADDR(&dao_sender_addr);
824 LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
826 if(flags & RPL_DAO_K_FLAG) {
828 dao_ack_output(instance, &dao_sender_addr, sequence,
829 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
830 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
835 rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
837 RPL_STAT(rpl_stats.mem_overflows++);
838 LOG_ERR(
"Could not add a route after receiving a DAO\n");
839 if(flags & RPL_DAO_K_FLAG) {
841 dao_ack_output(instance, &dao_sender_addr, sequence,
842 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
843 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
850 RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep);
852 #if RPL_WITH_MULTICAST 856 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
859 if(flags & RPL_DAO_K_FLAG) {
867 if((!RPL_ROUTE_IS_DAO_PENDING(rep) &&
868 rep->state.dao_seqno_in == sequence) ||
875 if(dag->preferred_parent != NULL &&
876 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
880 if(RPL_ROUTE_IS_DAO_PENDING(rep) &&
881 rep->state.dao_seqno_in == sequence) {
883 out_seq = rep->state.dao_seqno_out;
885 out_seq = prepare_for_dao_fwd(sequence, rep);
889 LOG_DBG(
"Forwarding DAO to parent ");
890 LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
891 LOG_DBG_(
" in seq: %d out seq: %d\n", sequence, out_seq);
893 buffer = UIP_ICMP_PAYLOAD;
899 LOG_DBG(
"Sending DAO ACK\n");
901 dao_ack_output(instance, &dao_sender_addr, sequence,
902 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
909 dao_input_nonstoring(
void)
911 #if RPL_WITH_NON_STORING 912 uip_ipaddr_t dao_sender_addr;
913 uip_ipaddr_t dao_parent_addr;
916 unsigned char *buffer;
924 uint8_t buffer_length;
930 LOG_INFO(
"Received a DAO from ");
937 memset(&dao_parent_addr, 0, 16);
939 buffer = UIP_ICMP_PAYLOAD;
940 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
943 instance_id = buffer[pos++];
944 instance = rpl_get_instance(instance_id);
945 lifetime = instance->default_lifetime;
947 flags = buffer[pos++];
950 sequence = buffer[pos++];
952 dag = instance->current_dag;
954 if(flags & RPL_DAO_D_FLAG) {
955 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
956 LOG_INFO(
"Ignoring a DAO for a DAG different from ours\n");
963 for(i = pos; i < buffer_length; i += len) {
964 subopt_type = buffer[i];
965 if(subopt_type == RPL_OPTION_PAD1) {
969 len = 2 + buffer[i + 1];
972 switch(subopt_type) {
973 case RPL_OPTION_TARGET:
975 prefixlen = buffer[i + 3];
976 memset(&prefix, 0,
sizeof(prefix));
977 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
979 case RPL_OPTION_TRANSIT:
983 lifetime = buffer[i + 5];
985 memcpy(&dao_parent_addr, buffer + i + 6, 16);
991 LOG_INFO(
"DAO lifetime: %u, prefix length: %u prefix: ",
992 (
unsigned)lifetime, (
unsigned)prefixlen);
993 LOG_INFO_6ADDR(&prefix);
994 LOG_INFO_(
", parent: ");
995 LOG_INFO_6ADDR(&dao_parent_addr);
998 if(lifetime == RPL_ZERO_LIFETIME) {
999 LOG_DBG(
"No-Path DAO received\n");
1003 LOG_WARN(
"DAO failed to add link prefix: ");
1004 LOG_WARN_6ADDR(&prefix);
1005 LOG_WARN_(
", parent: ");
1006 LOG_WARN_6ADDR(&dao_parent_addr);
1012 if(flags & RPL_DAO_K_FLAG) {
1013 LOG_DBG(
"Sending DAO ACK\n");
1015 dao_ack_output(instance, &dao_sender_addr, sequence,
1016 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
1025 uint8_t instance_id;
1028 LOG_INFO(
"Received a DAO from ");
1032 instance_id = UIP_ICMP_PAYLOAD[0];
1033 instance = rpl_get_instance(instance_id);
1034 if(instance == NULL) {
1035 LOG_INFO(
"Ignoring a DAO for an unknown RPL instance(%u)\n",
1040 if(RPL_IS_STORING(instance)) {
1041 dao_input_storing();
1042 }
else if(RPL_IS_NON_STORING(instance)) {
1043 dao_input_nonstoring();
1050 #if RPL_WITH_DAO_ACK 1052 handle_dao_retransmission(
void *ptr)
1054 rpl_parent_t *parent;
1055 uip_ipaddr_t prefix;
1059 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1062 instance = parent->dag->instance;
1064 if(instance->my_dao_transmissions >= RPL_DAO_MAX_RETRANSMISSIONS) {
1066 if(instance->lifetime_unit == 0xffff && instance->default_lifetime == 0xff) {
1077 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1079 instance->of->dao_ack_callback(parent, RPL_DAO_ACK_TIMEOUT);
1087 LOG_INFO(
"will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno,
1088 instance->my_dao_transmissions);
1090 if(get_global_addr(&prefix) == 0) {
1095 RPL_DAO_RETRANSMISSION_TIMEOUT / 2 +
1096 (
random_rand() % (RPL_DAO_RETRANSMISSION_TIMEOUT / 2)),
1097 handle_dao_retransmission, parent);
1099 instance->my_dao_transmissions++;
1100 dao_output_target_seq(parent, &prefix,
1101 instance->default_lifetime, instance->my_dao_seqno);
1106 dao_output(rpl_parent_t *parent, uint8_t lifetime)
1109 uip_ipaddr_t prefix;
1111 if(get_global_addr(&prefix) == 0) {
1112 LOG_ERR(
"No global address set for this node - suppressing DAO\n");
1116 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1120 RPL_LOLLIPOP_INCREMENT(dao_sequence);
1121 #if RPL_WITH_DAO_ACK 1125 if(lifetime != RPL_ZERO_LIFETIME) {
1127 instance = parent->dag->instance;
1129 instance->my_dao_seqno = dao_sequence;
1130 instance->my_dao_transmissions = 1;
1131 ctimer_set(&instance->dao_retransmit_timer, RPL_DAO_RETRANSMISSION_TIMEOUT,
1132 handle_dao_retransmission, parent);
1137 parent->dag->instance->has_downward_route = lifetime != RPL_ZERO_LIFETIME;
1141 dao_output_target(parent, &prefix, lifetime);
1145 dao_output_target(rpl_parent_t *parent, uip_ipaddr_t *prefix, uint8_t lifetime)
1147 dao_output_target_seq(parent, prefix, lifetime, dao_sequence);
1151 dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
1152 uint8_t lifetime, uint8_t seq_no)
1156 unsigned char *buffer;
1159 uip_ipaddr_t *parent_ipaddr = NULL;
1160 uip_ipaddr_t *dest_ipaddr = NULL;
1169 if(parent == NULL) {
1170 LOG_ERR(
"dao_output_target error parent NULL\n");
1174 parent_ipaddr = rpl_parent_get_ipaddr(parent);
1175 if(parent_ipaddr == NULL) {
1176 LOG_ERR(
"dao_output_target error parent IP address NULL\n");
1182 LOG_ERR(
"dao_output_target error dag NULL\n");
1186 instance = dag->instance;
1188 if(instance == NULL) {
1189 LOG_ERR(
"dao_output_target error instance NULL\n");
1192 if(prefix == NULL) {
1193 LOG_ERR(
"dao_output_target error prefix NULL\n");
1196 #ifdef RPL_DEBUG_DAO_OUTPUT 1197 RPL_DEBUG_DAO_OUTPUT(parent);
1200 buffer = UIP_ICMP_PAYLOAD;
1203 buffer[pos++] = instance->instance_id;
1205 #if RPL_DAO_SPECIFY_DAG 1206 buffer[pos] |= RPL_DAO_D_FLAG;
1208 #if RPL_WITH_DAO_ACK 1209 if(lifetime != RPL_ZERO_LIFETIME) {
1210 buffer[pos] |= RPL_DAO_K_FLAG;
1215 buffer[pos++] = seq_no;
1216 #if RPL_DAO_SPECIFY_DAG 1217 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
1218 pos+=
sizeof(dag->dag_id);
1222 prefixlen =
sizeof(*prefix) * CHAR_BIT;
1223 buffer[pos++] = RPL_OPTION_TARGET;
1224 buffer[pos++] = 2 + ((prefixlen + 7) / CHAR_BIT);
1226 buffer[pos++] = prefixlen;
1227 memcpy(buffer + pos, prefix, (prefixlen + 7) / CHAR_BIT);
1228 pos += ((prefixlen + 7) / CHAR_BIT);
1231 buffer[pos++] = RPL_OPTION_TRANSIT;
1232 buffer[pos++] = (instance->mop != RPL_MOP_NON_STORING) ? 4 : 20;
1236 buffer[pos++] = lifetime;
1238 if(instance->mop != RPL_MOP_NON_STORING) {
1240 dest_ipaddr = parent_ipaddr;
1243 memcpy(buffer + pos, &parent->dag->dag_id, 8);
1245 memcpy(buffer + pos, ((
const unsigned char *)parent_ipaddr) + 8, 8);
1248 dest_ipaddr = &parent->dag->dag_id;
1251 LOG_INFO(
"Sending a %sDAO with sequence number %u, lifetime %u, prefix ",
1252 lifetime == RPL_ZERO_LIFETIME ?
"No-Path " :
"", seq_no, lifetime);
1254 LOG_INFO_6ADDR(prefix);
1256 LOG_INFO_6ADDR(dest_ipaddr);
1257 LOG_INFO_(
" , parent ");
1258 LOG_INFO_6ADDR(parent_ipaddr);
1261 if(dest_ipaddr != NULL) {
1269 #if RPL_WITH_DAO_ACK 1272 uint8_t instance_id;
1276 rpl_parent_t *parent;
1278 buffer = UIP_ICMP_PAYLOAD;
1280 instance_id = buffer[0];
1281 sequence = buffer[2];
1284 instance = rpl_get_instance(instance_id);
1285 if(instance == NULL) {
1290 if(RPL_IS_STORING(instance)) {
1291 parent = rpl_find_parent(instance->current_dag, &
UIP_IP_BUF->srcipaddr);
1292 if(parent == NULL) {
1301 if(instance->current_dag->rank ==
ROOT_RANK(instance)) {
1302 LOG_DBG(
"DODAG root received a DAO ACK, ignoring it\n");
1307 LOG_INFO(
"Received a DAO %s with sequence number %d (%d) and status %d from ",
1308 status < 128 ?
"ACK" :
"NACK",
1309 sequence, instance->my_dao_seqno, status);
1313 if(sequence == instance->my_dao_seqno) {
1314 instance->has_downward_route = status < 128;
1320 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1321 instance->of->dao_ack_callback(parent, status);
1324 #if RPL_REPAIR_ON_DAO_NACK 1325 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1334 }
else if(RPL_IS_STORING(instance)) {
1337 uip_ipaddr_t *nexthop;
1338 if((re = find_route_entry_by_dao_ack(sequence)) != NULL) {
1341 RPL_ROUTE_CLEAR_DAO_PENDING(re);
1343 nexthop = uip_ds6_route_nexthop(re);
1344 if(nexthop == NULL) {
1345 LOG_WARN(
"No next hop to fwd DAO ACK to\n");
1347 LOG_INFO(
"Fwd DAO ACK to:");
1348 LOG_INFO_6ADDR(nexthop);
1350 buffer[2] = re->state.dao_seqno_in;
1354 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1356 uip_ds6_route_rm(re);
1359 LOG_WARN(
"No route entry found to forward DAO ACK (seqno %u)\n", sequence);
1367 dao_ack_output(
rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence,
1370 #if RPL_WITH_DAO_ACK 1371 unsigned char *buffer;
1373 LOG_INFO(
"Sending a DAO %s with sequence number %d to ", status < 128 ?
"ACK" :
"NACK", sequence);
1374 LOG_INFO_6ADDR(dest);
1375 LOG_INFO_(
" with status %d\n", status);
1377 buffer = UIP_ICMP_PAYLOAD;
1379 buffer[0] = instance->instance_id;
1381 buffer[2] = sequence;
1389 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...