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 73 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 74 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) 75 #define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) 77 static void dis_input(
void);
78 static void dio_input(
void);
79 static void dao_input(
void);
80 static void dao_ack_input(
void);
82 static void dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
83 uint8_t lifetime, uint8_t seq_no);
86 #ifdef RPL_DEBUG_DIO_INPUT 87 void RPL_DEBUG_DIO_INPUT(uip_ipaddr_t *, rpl_dio_t *);
90 #ifdef RPL_DEBUG_DAO_OUTPUT 91 void RPL_DEBUG_DAO_OUTPUT(rpl_parent_t *);
94 static uint8_t dao_sequence = RPL_LOLLIPOP_INIT;
96 #if RPL_WITH_MULTICAST 101 UIP_ICMP6_HANDLER(dis_handler,
ICMP6_RPL, RPL_CODE_DIS, dis_input);
102 UIP_ICMP6_HANDLER(dio_handler,
ICMP6_RPL, RPL_CODE_DIO, dio_input);
103 UIP_ICMP6_HANDLER(dao_handler,
ICMP6_RPL, RPL_CODE_DAO, dao_input);
104 UIP_ICMP6_HANDLER(dao_ack_handler,
ICMP6_RPL, RPL_CODE_DAO_ACK, dao_ack_input);
109 find_route_entry_by_dao_ack(uint8_t seq)
112 re = uip_ds6_route_head();
114 if(re->state.dao_seqno_out == seq && RPL_ROUTE_IS_DAO_PENDING(re)) {
118 re = uip_ds6_route_next(re);
130 RPL_LOLLIPOP_INCREMENT(dao_sequence);
133 rep->state.dao_seqno_in = sequence;
134 rep->state.dao_seqno_out = dao_sequence;
135 RPL_ROUTE_SET_DAO_PENDING(rep);
141 get_global_addr(uip_ipaddr_t *
addr)
145 uip_ipaddr_t *prefix = NULL;
146 uint8_t prefix_length = 0;
149 if(dag != NULL && dag->prefix_info.length != 0) {
150 prefix = &dag->prefix_info.prefix;
151 prefix_length = dag->prefix_info.length;
154 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
157 state == ADDR_PREFERRED &&
159 (prefix == NULL || uip_ipaddr_prefixcmp(prefix, &
uip_ds6_if.addr_list[i].ipaddr, prefix_length))) {
160 memcpy(addr, &
uip_ds6_if.addr_list[i].ipaddr,
sizeof(uip_ipaddr_t));
168 get32(uint8_t *buffer,
int pos)
170 return ((uint32_t)buffer[pos] << 24 | (uint32_t)buffer[pos + 1] << 16 |
171 (uint32_t)buffer[pos + 2] << 8 | buffer[pos + 3]);
175 set32(uint8_t *buffer,
int pos, uint32_t value)
177 buffer[pos++] = value >> 24;
178 buffer[pos++] = (value >> 16) & 0xff;
179 buffer[pos++] = (value >> 8) & 0xff;
180 buffer[pos++] = value & 0xff;
184 get16(uint8_t *buffer,
int pos)
186 return (uint16_t)buffer[pos] << 8 | buffer[pos + 1];
190 set16(uint8_t *buffer,
int pos, uint16_t value)
192 buffer[pos++] = value >> 8;
193 buffer[pos++] = value & 0xff;
201 if((nbr = uip_ds6_nbr_lookup(from)) == NULL) {
203 packetbuf_addr(PACKETBUF_ADDR_SENDER),
204 0, NBR_REACHABLE, reason, data)) != NULL) {
205 LOG_INFO(
"Neighbor added to neighbor cache ");
206 LOG_INFO_6ADDR(from);
208 LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
223 LOG_INFO(
"Received a DIS from ");
227 for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
228 instance < end; ++instance) {
229 if(instance->used == 1) {
232 LOG_INFO(
"LEAF ONLY Multicast DIS will NOT reset DIO timer\n");
234 LOG_DBG(
"Multicast DIS => reset DIO timer\n");
235 rpl_reset_dio_timer(instance);
240 NBR_TABLE_REASON_RPL_DIS, NULL) == NULL) {
241 LOG_ERR(
"Out of Memory, not sending unicast DIO, DIS from ");
244 LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
247 LOG_DBG(
"Unicast DIS, reply to sender\n");
258 dis_output(uip_ipaddr_t *addr)
260 unsigned char *buffer;
261 uip_ipaddr_t tmpaddr;
272 buffer = UIP_ICMP_PAYLOAD;
273 buffer[0] = buffer[1] = 0;
280 LOG_INFO(
"Sending a DIS to ");
281 LOG_INFO_6ADDR(addr);
290 unsigned char *buffer;
291 uint8_t buffer_length;
298 memset(&dio, 0,
sizeof(dio));
301 dio.dag_intdoubl = RPL_DIO_INTERVAL_DOUBLINGS;
302 dio.dag_intmin = RPL_DIO_INTERVAL_MIN;
303 dio.dag_redund = RPL_DIO_REDUNDANCY;
304 dio.dag_min_hoprankinc = RPL_MIN_HOPRANKINC;
305 dio.dag_max_rankinc = RPL_MAX_RANKINC;
306 dio.ocp = RPL_OF_OCP;
307 dio.default_lifetime = RPL_DEFAULT_LIFETIME;
308 dio.lifetime_unit = RPL_DEFAULT_LIFETIME_UNIT;
313 LOG_INFO(
"Received a DIO from ");
314 LOG_INFO_6ADDR(&from);
317 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
321 buffer = UIP_ICMP_PAYLOAD;
323 dio.instance_id = buffer[i++];
324 dio.version = buffer[i++];
325 dio.rank = get16(buffer, i);
328 LOG_DBG(
"Incoming DIO (id, ver, rank) = (%u,%u,%u)\n",
329 (
unsigned)dio.instance_id,
330 (
unsigned)dio.version,
333 dio.grounded = buffer[i] & RPL_DIO_GROUNDED;
334 dio.mop = (buffer[i]& RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT;
335 dio.preference = buffer[i++] & RPL_DIO_PREFERENCE_MASK;
337 dio.dtsn = buffer[i++];
341 memcpy(&dio.dag_id, buffer + i,
sizeof(dio.dag_id));
342 i +=
sizeof(dio.dag_id);
344 LOG_DBG(
"Incoming DIO (dag_id, pref) = (");
345 LOG_DBG_6ADDR(&dio.dag_id);
346 LOG_DBG_(
", %u)\n", dio.preference);
349 for(; i < buffer_length; i += len) {
350 subopt_type = buffer[i];
351 if(subopt_type == RPL_OPTION_PAD1) {
355 len = 2 + buffer[i + 1];
358 if(len + i > buffer_length) {
359 LOG_WARN(
"Invalid DIO packet\n");
360 RPL_STAT(rpl_stats.malformed_msgs++);
364 LOG_DBG(
"Incoming DIO (option, length) = (%u, %u)\n", subopt_type, len - 2);
366 switch(subopt_type) {
367 case RPL_OPTION_DAG_METRIC_CONTAINER:
369 LOG_WARN(
"Invalid DAG MC, len = %d\n", len);
370 RPL_STAT(rpl_stats.malformed_msgs++);
373 dio.mc.type = buffer[i + 2];
374 dio.mc.flags = buffer[i + 3] << 1;
375 dio.mc.flags |= buffer[i + 4] >> 7;
376 dio.mc.aggr = (buffer[i + 4] >> 4) & 0x3;
377 dio.mc.prec = buffer[i + 4] & 0xf;
378 dio.mc.length = buffer[i + 5];
380 if(dio.mc.type == RPL_DAG_MC_NONE) {
382 }
else if(dio.mc.type == RPL_DAG_MC_ETX) {
383 dio.mc.obj.etx = get16(buffer, i + 6);
385 LOG_DBG(
"DAG MC: type %u, flags %u, aggr %u, prec %u, length %u, ETX %u\n",
386 (
unsigned)dio.mc.type,
387 (
unsigned)dio.mc.flags,
388 (
unsigned)dio.mc.aggr,
389 (
unsigned)dio.mc.prec,
390 (
unsigned)dio.mc.length,
391 (
unsigned)dio.mc.obj.etx);
392 }
else if(dio.mc.type == RPL_DAG_MC_ENERGY) {
393 dio.mc.obj.energy.flags = buffer[i + 6];
394 dio.mc.obj.energy.energy_est = buffer[i + 7];
396 LOG_WARN(
"Unhandled DAG MC type: %u\n", (
unsigned)dio.mc.type);
400 case RPL_OPTION_ROUTE_INFO:
402 LOG_WARN(
"Invalid destination prefix option, len = %d\n", len);
403 RPL_STAT(rpl_stats.malformed_msgs++);
408 dio.destination_prefix.length = buffer[i + 2];
409 dio.destination_prefix.flags = buffer[i + 3];
410 dio.destination_prefix.lifetime = get32(buffer, i + 4);
412 if(((dio.destination_prefix.length + 7) / 8) + 8 <= len &&
413 dio.destination_prefix.length <= 128) {
414 LOG_INFO(
"Copying destination prefix\n");
415 memcpy(&dio.destination_prefix.prefix, &buffer[i + 8],
416 (dio.destination_prefix.length + 7) / 8);
418 LOG_WARN(
"Invalid route info option, len = %d\n", len);
419 RPL_STAT(rpl_stats.malformed_msgs++);
424 case RPL_OPTION_DAG_CONF:
426 LOG_WARN(
"Invalid DAG configuration option, len = %d\n", len);
427 RPL_STAT(rpl_stats.malformed_msgs++);
432 dio.dag_intdoubl = buffer[i + 3];
433 dio.dag_intmin = buffer[i + 4];
434 dio.dag_redund = buffer[i + 5];
435 dio.dag_max_rankinc = get16(buffer, i + 6);
436 dio.dag_min_hoprankinc = get16(buffer, i + 8);
437 dio.ocp = get16(buffer, i + 10);
439 dio.default_lifetime = buffer[i + 13];
440 dio.lifetime_unit = get16(buffer, i + 14);
441 LOG_INFO(
"DAG conf:dbl=%d, min=%d red=%d maxinc=%d mininc=%d ocp=%d d_l=%u l_u=%u\n",
442 dio.dag_intdoubl, dio.dag_intmin, dio.dag_redund,
443 dio.dag_max_rankinc, dio.dag_min_hoprankinc, dio.ocp,
444 dio.default_lifetime, dio.lifetime_unit);
446 case RPL_OPTION_PREFIX_INFO:
448 LOG_WARN(
"Invalid DAG prefix info, len != 32\n");
449 RPL_STAT(rpl_stats.malformed_msgs++);
452 dio.prefix_info.length = buffer[i + 2];
453 dio.prefix_info.flags = buffer[i + 3];
456 dio.prefix_info.lifetime = get32(buffer, i + 8);
458 LOG_INFO(
"Copying prefix information\n");
459 memcpy(&dio.prefix_info.prefix, &buffer[i + 16], 16);
462 LOG_WARN(
"Unsupported suboption type in DIO: %u\n",
463 (
unsigned)subopt_type);
467 #ifdef RPL_DEBUG_DIO_INPUT 468 RPL_DEBUG_DIO_INPUT(&from, &dio);
480 unsigned char *buffer;
491 if(uc_addr == NULL) {
492 LOG_DBG(
"LEAF ONLY have multicast addr: skip dio_output\n");
500 buffer = UIP_ICMP_PAYLOAD;
501 buffer[pos++] = instance->instance_id;
502 buffer[pos++] = dag->version;
503 is_root = (dag->rank ==
ROOT_RANK(instance));
506 LOG_DBG(
"LEAF ONLY DIO rank set to RPL_INFINITE_RANK\n");
507 set16(buffer, pos, RPL_INFINITE_RANK);
509 set16(buffer, pos, dag->rank);
515 buffer[pos] |= RPL_DIO_GROUNDED;
518 buffer[pos] |= instance->mop << RPL_DIO_MOP_SHIFT;
519 buffer[pos] |= dag->preference & RPL_DIO_PREFERENCE_MASK;
522 buffer[pos++] = instance->dtsn_out;
524 if(RPL_DIO_REFRESH_DAO_ROUTES && is_root && uc_addr == NULL) {
528 RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
535 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
539 if(instance->mc.type != RPL_DAG_MC_NONE) {
540 instance->of->update_metric_container(instance);
542 buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER;
544 buffer[pos++] = instance->mc.type;
545 buffer[pos++] = instance->mc.flags >> 1;
546 buffer[pos] = (instance->mc.flags & 1) << 7;
547 buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
548 if(instance->mc.type == RPL_DAG_MC_ETX) {
550 set16(buffer, pos, instance->mc.obj.etx);
552 }
else if(instance->mc.type == RPL_DAG_MC_ENERGY) {
554 buffer[pos++] = instance->mc.obj.energy.flags;
555 buffer[pos++] = instance->mc.obj.energy.energy_est;
557 LOG_ERR(
"Unable to send DIO because of unhandled DAG MC type %u\n",
558 (
unsigned)instance->mc.type);
565 buffer[pos++] = RPL_OPTION_DAG_CONF;
568 buffer[pos++] = instance->dio_intdoubl;
569 buffer[pos++] = instance->dio_intmin;
570 buffer[pos++] = instance->dio_redundancy;
571 set16(buffer, pos, instance->max_rankinc);
573 set16(buffer, pos, instance->min_hoprankinc);
576 set16(buffer, pos, instance->of->ocp);
579 buffer[pos++] = instance->default_lifetime;
580 set16(buffer, pos, instance->lifetime_unit);
584 if(dag->prefix_info.length > 0) {
585 buffer[pos++] = RPL_OPTION_PREFIX_INFO;
587 buffer[pos++] = dag->prefix_info.length;
588 buffer[pos++] = dag->prefix_info.flags;
589 set32(buffer, pos, dag->prefix_info.lifetime);
591 set32(buffer, pos, dag->prefix_info.lifetime);
593 memset(&buffer[pos], 0, 4);
595 memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
597 LOG_DBG(
"Sending prefix info in DIO for ");
598 LOG_DBG_6ADDR(&dag->prefix_info.prefix);
601 LOG_DBG(
"No prefix to announce (len %d)\n",
602 dag->prefix_info.length);
606 if(LOG_DBG_ENABLED) {
607 if(uc_addr == NULL) {
608 LOG_DBG(
"LEAF ONLY sending unicast-DIO from multicast-DIO\n");
612 LOG_INFO(
"Sending unicast-DIO with rank %u to ",
613 (
unsigned)dag->rank);
614 LOG_INFO_6ADDR(uc_addr);
619 if(uc_addr == NULL) {
620 LOG_INFO(
"Sending a multicast-DIO with rank %u\n",
621 (
unsigned)instance->current_dag->rank);
625 LOG_INFO(
"Sending unicast-DIO with rank %u to ",
626 (
unsigned)instance->current_dag->rank);
627 LOG_INFO_6ADDR(uc_addr);
635 dao_input_storing(
void)
638 uip_ipaddr_t dao_sender_addr;
641 unsigned char *buffer;
654 uint8_t buffer_length;
659 rpl_parent_t *parent;
665 memset(&prefix, 0,
sizeof(prefix));
669 buffer = UIP_ICMP_PAYLOAD;
670 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
673 instance_id = buffer[pos++];
675 instance = rpl_get_instance(instance_id);
677 lifetime = instance->default_lifetime;
679 flags = buffer[pos++];
682 sequence = buffer[pos++];
684 dag = instance->current_dag;
685 is_root = (dag->rank ==
ROOT_RANK(instance));
688 if(flags & RPL_DAO_D_FLAG) {
689 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
690 LOG_INFO(
"Ignoring a DAO for a DAG different from ours\n");
697 RPL_ROUTE_FROM_MULTICAST_DAO : RPL_ROUTE_FROM_UNICAST_DAO;
700 LOG_DBG(
"Received a (%s) DAO with sequence number %u from ",
701 learned_from == RPL_ROUTE_FROM_UNICAST_DAO?
"unicast":
"multicast", sequence);
702 LOG_DBG_6ADDR(&dao_sender_addr);
705 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
707 parent = rpl_find_parent(dag, &dao_sender_addr);
712 LOG_WARN(
"Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n",
714 parent->rank = RPL_INFINITE_RANK;
715 parent->flags |= RPL_PARENT_FLAG_UPDATED;
720 if(parent != NULL && parent == dag->preferred_parent) {
721 LOG_WARN(
"Loop detected when receiving a unicast DAO from our parent\n");
722 parent->rank = RPL_INFINITE_RANK;
723 parent->flags |= RPL_PARENT_FLAG_UPDATED;
729 for(i = pos; i < buffer_length; i += len) {
730 subopt_type = buffer[i];
731 if(subopt_type == RPL_OPTION_PAD1) {
735 len = 2 + buffer[i + 1];
738 switch(subopt_type) {
739 case RPL_OPTION_TARGET:
741 prefixlen = buffer[i + 3];
742 memset(&prefix, 0,
sizeof(prefix));
743 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
745 case RPL_OPTION_TRANSIT:
749 lifetime = buffer[i + 5];
755 LOG_INFO(
"DAO lifetime: %u, prefix length: %u prefix: ",
756 (
unsigned)lifetime, (
unsigned)prefixlen);
757 LOG_INFO_6ADDR(&prefix);
760 #if RPL_WITH_MULTICAST 769 mcast_group->
dag = dag;
776 rep = uip_ds6_route_lookup(&prefix);
778 if(lifetime == RPL_ZERO_LIFETIME) {
779 LOG_INFO(
"No-Path DAO received\n");
782 !RPL_ROUTE_IS_NOPATH_RECEIVED(rep) &&
783 rep->length == prefixlen &&
784 uip_ds6_route_nexthop(rep) != NULL &&
785 uip_ipaddr_cmp(uip_ds6_route_nexthop(rep), &dao_sender_addr)) {
786 LOG_DBG(
"Setting expiration timer for prefix ");
787 LOG_DBG_6ADDR(&prefix);
789 RPL_ROUTE_SET_NOPATH_RECEIVED(rep);
790 rep->state.lifetime = RPL_NOPATH_REMOVAL_DELAY;
794 if(dag->preferred_parent != NULL &&
795 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
797 out_seq = prepare_for_dao_fwd(sequence, rep);
799 LOG_DBG(
"Forwarding No-path DAO to parent - out_seq:%d",
801 LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
804 buffer = UIP_ICMP_PAYLOAD;
811 if(flags & RPL_DAO_K_FLAG) {
814 dao_ack_output(instance, &dao_sender_addr, sequence,
815 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
820 LOG_INFO(
"Adding DAO route\n");
824 LOG_ERR(
"Out of Memory, dropping DAO from ");
825 LOG_ERR_6ADDR(&dao_sender_addr);
827 LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
829 if(flags & RPL_DAO_K_FLAG) {
831 dao_ack_output(instance, &dao_sender_addr, sequence,
832 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
833 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
838 rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
840 RPL_STAT(rpl_stats.mem_overflows++);
841 LOG_ERR(
"Could not add a route after receiving a DAO\n");
842 if(flags & RPL_DAO_K_FLAG) {
844 dao_ack_output(instance, &dao_sender_addr, sequence,
845 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
846 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
853 RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep);
855 #if RPL_WITH_MULTICAST 859 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
862 if(flags & RPL_DAO_K_FLAG) {
870 if((!RPL_ROUTE_IS_DAO_PENDING(rep) &&
871 rep->state.dao_seqno_in == sequence) ||
878 if(dag->preferred_parent != NULL &&
879 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
883 if(RPL_ROUTE_IS_DAO_PENDING(rep) &&
884 rep->state.dao_seqno_in == sequence) {
886 out_seq = rep->state.dao_seqno_out;
888 out_seq = prepare_for_dao_fwd(sequence, rep);
892 LOG_DBG(
"Forwarding DAO to parent ");
893 LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
894 LOG_DBG_(
" in seq: %d out seq: %d\n", sequence, out_seq);
896 buffer = UIP_ICMP_PAYLOAD;
902 LOG_DBG(
"Sending DAO ACK\n");
904 dao_ack_output(instance, &dao_sender_addr, sequence,
905 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
912 dao_input_nonstoring(
void)
914 #if RPL_WITH_NON_STORING 915 uip_ipaddr_t dao_sender_addr;
916 uip_ipaddr_t dao_parent_addr;
919 unsigned char *buffer;
927 uint8_t buffer_length;
933 LOG_INFO(
"Received a DAO from ");
940 memset(&dao_parent_addr, 0, 16);
942 buffer = UIP_ICMP_PAYLOAD;
943 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
946 instance_id = buffer[pos++];
947 instance = rpl_get_instance(instance_id);
948 lifetime = instance->default_lifetime;
950 flags = buffer[pos++];
953 sequence = buffer[pos++];
955 dag = instance->current_dag;
957 if(flags & RPL_DAO_D_FLAG) {
958 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
959 LOG_INFO(
"Ignoring a DAO for a DAG different from ours\n");
966 for(i = pos; i < buffer_length; i += len) {
967 subopt_type = buffer[i];
968 if(subopt_type == RPL_OPTION_PAD1) {
972 len = 2 + buffer[i + 1];
975 switch(subopt_type) {
976 case RPL_OPTION_TARGET:
978 prefixlen = buffer[i + 3];
979 memset(&prefix, 0,
sizeof(prefix));
980 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
982 case RPL_OPTION_TRANSIT:
986 lifetime = buffer[i + 5];
988 memcpy(&dao_parent_addr, buffer + i + 6, 16);
994 LOG_INFO(
"DAO lifetime: %u, prefix length: %u prefix: ",
995 (
unsigned)lifetime, (
unsigned)prefixlen);
996 LOG_INFO_6ADDR(&prefix);
997 LOG_INFO_(
", parent: ");
998 LOG_INFO_6ADDR(&dao_parent_addr);
1001 if(lifetime == RPL_ZERO_LIFETIME) {
1002 LOG_DBG(
"No-Path DAO received\n");
1006 LOG_WARN(
"DAO failed to add link prefix: ");
1007 LOG_WARN_6ADDR(&prefix);
1008 LOG_WARN_(
", parent: ");
1009 LOG_WARN_6ADDR(&dao_parent_addr);
1015 if(flags & RPL_DAO_K_FLAG) {
1016 LOG_DBG(
"Sending DAO ACK\n");
1018 dao_ack_output(instance, &dao_sender_addr, sequence,
1019 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
1028 uint8_t instance_id;
1031 LOG_INFO(
"Received a DAO from ");
1035 instance_id = UIP_ICMP_PAYLOAD[0];
1036 instance = rpl_get_instance(instance_id);
1037 if(instance == NULL) {
1038 LOG_INFO(
"Ignoring a DAO for an unknown RPL instance(%u)\n",
1043 if(RPL_IS_STORING(instance)) {
1044 dao_input_storing();
1045 }
else if(RPL_IS_NON_STORING(instance)) {
1046 dao_input_nonstoring();
1053 #if RPL_WITH_DAO_ACK 1055 handle_dao_retransmission(
void *ptr)
1057 rpl_parent_t *parent;
1058 uip_ipaddr_t prefix;
1062 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1065 instance = parent->dag->instance;
1067 if(instance->my_dao_transmissions >= RPL_DAO_MAX_RETRANSMISSIONS) {
1069 if(instance->lifetime_unit == 0xffff && instance->default_lifetime == 0xff) {
1080 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1082 instance->of->dao_ack_callback(parent, RPL_DAO_ACK_TIMEOUT);
1090 LOG_INFO(
"will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno,
1091 instance->my_dao_transmissions);
1093 if(get_global_addr(&prefix) == 0) {
1098 RPL_DAO_RETRANSMISSION_TIMEOUT / 2 +
1099 (
random_rand() % (RPL_DAO_RETRANSMISSION_TIMEOUT / 2)),
1100 handle_dao_retransmission, parent);
1102 instance->my_dao_transmissions++;
1103 dao_output_target_seq(parent, &prefix,
1104 instance->default_lifetime, instance->my_dao_seqno);
1109 dao_output(rpl_parent_t *parent, uint8_t lifetime)
1112 uip_ipaddr_t prefix;
1114 if(get_global_addr(&prefix) == 0) {
1115 LOG_ERR(
"No global address set for this node - suppressing DAO\n");
1119 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1123 RPL_LOLLIPOP_INCREMENT(dao_sequence);
1124 #if RPL_WITH_DAO_ACK 1128 if(lifetime != RPL_ZERO_LIFETIME) {
1130 instance = parent->dag->instance;
1132 instance->my_dao_seqno = dao_sequence;
1133 instance->my_dao_transmissions = 1;
1134 ctimer_set(&instance->dao_retransmit_timer, RPL_DAO_RETRANSMISSION_TIMEOUT,
1135 handle_dao_retransmission, parent);
1140 parent->dag->instance->has_downward_route = lifetime != RPL_ZERO_LIFETIME;
1144 dao_output_target(parent, &prefix, lifetime);
1148 dao_output_target(rpl_parent_t *parent, uip_ipaddr_t *prefix, uint8_t lifetime)
1150 dao_output_target_seq(parent, prefix, lifetime, dao_sequence);
1154 dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
1155 uint8_t lifetime, uint8_t seq_no)
1159 unsigned char *buffer;
1162 uip_ipaddr_t *parent_ipaddr = NULL;
1163 uip_ipaddr_t *dest_ipaddr = NULL;
1172 if(parent == NULL) {
1173 LOG_ERR(
"dao_output_target error parent NULL\n");
1177 parent_ipaddr = rpl_parent_get_ipaddr(parent);
1178 if(parent_ipaddr == NULL) {
1179 LOG_ERR(
"dao_output_target error parent IP address NULL\n");
1185 LOG_ERR(
"dao_output_target error dag NULL\n");
1189 instance = dag->instance;
1191 if(instance == NULL) {
1192 LOG_ERR(
"dao_output_target error instance NULL\n");
1195 if(prefix == NULL) {
1196 LOG_ERR(
"dao_output_target error prefix NULL\n");
1199 #ifdef RPL_DEBUG_DAO_OUTPUT 1200 RPL_DEBUG_DAO_OUTPUT(parent);
1203 buffer = UIP_ICMP_PAYLOAD;
1206 buffer[pos++] = instance->instance_id;
1208 #if RPL_DAO_SPECIFY_DAG 1209 buffer[pos] |= RPL_DAO_D_FLAG;
1211 #if RPL_WITH_DAO_ACK 1212 if(lifetime != RPL_ZERO_LIFETIME) {
1213 buffer[pos] |= RPL_DAO_K_FLAG;
1218 buffer[pos++] = seq_no;
1219 #if RPL_DAO_SPECIFY_DAG 1220 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
1221 pos+=
sizeof(dag->dag_id);
1225 prefixlen =
sizeof(*prefix) * CHAR_BIT;
1226 buffer[pos++] = RPL_OPTION_TARGET;
1227 buffer[pos++] = 2 + ((prefixlen + 7) / CHAR_BIT);
1229 buffer[pos++] = prefixlen;
1230 memcpy(buffer + pos, prefix, (prefixlen + 7) / CHAR_BIT);
1231 pos += ((prefixlen + 7) / CHAR_BIT);
1234 buffer[pos++] = RPL_OPTION_TRANSIT;
1235 buffer[pos++] = (instance->mop != RPL_MOP_NON_STORING) ? 4 : 20;
1239 buffer[pos++] = lifetime;
1241 if(instance->mop != RPL_MOP_NON_STORING) {
1243 dest_ipaddr = parent_ipaddr;
1246 memcpy(buffer + pos, &parent->dag->dag_id, 8);
1248 memcpy(buffer + pos, ((
const unsigned char *)parent_ipaddr) + 8, 8);
1251 dest_ipaddr = &parent->dag->dag_id;
1254 LOG_INFO(
"Sending a %sDAO with sequence number %u, lifetime %u, prefix ",
1255 lifetime == RPL_ZERO_LIFETIME ?
"No-Path " :
"", seq_no, lifetime);
1257 LOG_INFO_6ADDR(prefix);
1259 LOG_INFO_6ADDR(dest_ipaddr);
1260 LOG_INFO_(
" , parent ");
1261 LOG_INFO_6ADDR(parent_ipaddr);
1264 if(dest_ipaddr != NULL) {
1272 #if RPL_WITH_DAO_ACK 1275 uint8_t instance_id;
1279 rpl_parent_t *parent;
1281 buffer = UIP_ICMP_PAYLOAD;
1283 instance_id = buffer[0];
1284 sequence = buffer[2];
1287 instance = rpl_get_instance(instance_id);
1288 if(instance == NULL) {
1293 if(RPL_IS_STORING(instance)) {
1294 parent = rpl_find_parent(instance->current_dag, &
UIP_IP_BUF->srcipaddr);
1295 if(parent == NULL) {
1304 if(instance->current_dag->rank ==
ROOT_RANK(instance)) {
1305 LOG_DBG(
"DODAG root received a DAO ACK, ignoring it\n");
1310 LOG_INFO(
"Received a DAO %s with sequence number %d (%d) and status %d from ",
1311 status < 128 ?
"ACK" :
"NACK",
1312 sequence, instance->my_dao_seqno, status);
1316 if(sequence == instance->my_dao_seqno) {
1317 instance->has_downward_route = status < 128;
1323 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1324 instance->of->dao_ack_callback(parent, status);
1327 #if RPL_REPAIR_ON_DAO_NACK 1328 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1337 }
else if(RPL_IS_STORING(instance)) {
1340 uip_ipaddr_t *nexthop;
1341 if((re = find_route_entry_by_dao_ack(sequence)) != NULL) {
1344 RPL_ROUTE_CLEAR_DAO_PENDING(re);
1346 nexthop = uip_ds6_route_nexthop(re);
1347 if(nexthop == NULL) {
1348 LOG_WARN(
"No next hop to fwd DAO ACK to\n");
1350 LOG_INFO(
"Fwd DAO ACK to:");
1351 LOG_INFO_6ADDR(nexthop);
1353 buffer[2] = re->state.dao_seqno_in;
1357 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1359 uip_ds6_route_rm(re);
1362 LOG_WARN(
"No route entry found to forward DAO ACK (seqno %u)\n", sequence);
1370 dao_ack_output(
rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence,
1373 #if RPL_WITH_DAO_ACK 1374 unsigned char *buffer;
1376 LOG_INFO(
"Sending a DAO %s with sequence number %d to ", status < 128 ?
"ACK" :
"NACK", sequence);
1377 LOG_INFO_6ADDR(dest);
1378 LOG_INFO_(
" with status %d\n", status);
1380 buffer = UIP_ICMP_PAYLOAD;
1382 buffer[0] = instance->instance_id;
1384 buffer[2] = sequence;
1392 rpl_icmp6_register_handlers()
#define UIP_IP_BUF
Pointer to IP 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.
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)
Neighbor Cache basic routines.
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.
An entry in the nbr cache.