54 #include "net/routing/rpl-classic/rpl-private.h" 62 #define DEBUG DEBUG_NONE 67 #define RPL_DIO_GROUNDED 0x80 68 #define RPL_DIO_MOP_SHIFT 3 69 #define RPL_DIO_MOP_MASK 0x38 70 #define RPL_DIO_PREFERENCE_MASK 0x07 72 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 73 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) 74 #define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) 76 static void dis_input(
void);
77 static void dio_input(
void);
78 static void dao_input(
void);
79 static void dao_ack_input(
void);
81 static void dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
82 uint8_t lifetime, uint8_t seq_no);
85 #ifdef RPL_DEBUG_DIO_INPUT 86 void RPL_DEBUG_DIO_INPUT(uip_ipaddr_t *, rpl_dio_t *);
89 #ifdef RPL_DEBUG_DAO_OUTPUT 90 void RPL_DEBUG_DAO_OUTPUT(rpl_parent_t *);
93 static uint8_t dao_sequence = RPL_LOLLIPOP_INIT;
95 #if RPL_WITH_MULTICAST 100 UIP_ICMP6_HANDLER(dis_handler,
ICMP6_RPL, RPL_CODE_DIS, dis_input);
101 UIP_ICMP6_HANDLER(dio_handler,
ICMP6_RPL, RPL_CODE_DIO, dio_input);
102 UIP_ICMP6_HANDLER(dao_handler,
ICMP6_RPL, RPL_CODE_DAO, dao_input);
103 UIP_ICMP6_HANDLER(dao_ack_handler,
ICMP6_RPL, RPL_CODE_DAO_ACK, dao_ack_input);
108 find_route_entry_by_dao_ack(uint8_t seq)
111 re = uip_ds6_route_head();
113 if(re->state.dao_seqno_out == seq && RPL_ROUTE_IS_DAO_PENDING(re)) {
117 re = uip_ds6_route_next(re);
129 RPL_LOLLIPOP_INCREMENT(dao_sequence);
132 rep->state.dao_seqno_in = sequence;
133 rep->state.dao_seqno_out = dao_sequence;
134 RPL_ROUTE_SET_DAO_PENDING(rep);
140 get_global_addr(uip_ipaddr_t *
addr)
144 uip_ipaddr_t *prefix = NULL;
145 uint8_t prefix_length = 0;
148 if(dag != NULL && dag->prefix_info.length != 0) {
149 prefix = &dag->prefix_info.prefix;
150 prefix_length = dag->prefix_info.length;
153 for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
156 state == ADDR_PREFERRED &&
158 (prefix == NULL || uip_ipaddr_prefixcmp(prefix, &
uip_ds6_if.addr_list[i].ipaddr, prefix_length))) {
159 memcpy(addr, &
uip_ds6_if.addr_list[i].ipaddr,
sizeof(uip_ipaddr_t));
167 get32(uint8_t *buffer,
int pos)
169 return ((uint32_t)buffer[pos] << 24 | (uint32_t)buffer[pos + 1] << 16 |
170 (uint32_t)buffer[pos + 2] << 8 | buffer[pos + 3]);
174 set32(uint8_t *buffer,
int pos, uint32_t value)
176 buffer[pos++] = value >> 24;
177 buffer[pos++] = (value >> 16) & 0xff;
178 buffer[pos++] = (value >> 8) & 0xff;
179 buffer[pos++] = value & 0xff;
183 get16(uint8_t *buffer,
int pos)
185 return (uint16_t)buffer[pos] << 8 | buffer[pos + 1];
189 set16(uint8_t *buffer,
int pos, uint16_t value)
191 buffer[pos++] = value >> 8;
192 buffer[pos++] = value & 0xff;
200 if((nbr = uip_ds6_nbr_lookup(from)) == NULL) {
202 packetbuf_addr(PACKETBUF_ADDR_SENDER),
203 0, NBR_REACHABLE, reason, data)) != NULL) {
204 PRINTF(
"RPL: Neighbor added to neighbor cache ");
207 PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
222 PRINTF(
"RPL: Received a DIS from ");
226 for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES;
227 instance < end; ++instance) {
228 if(instance->used == 1) {
231 PRINTF(
"RPL: LEAF ONLY Multicast DIS will NOT reset DIO timer\n");
233 PRINTF(
"RPL: Multicast DIS => reset DIO timer\n");
234 rpl_reset_dio_timer(instance);
239 NBR_TABLE_REASON_RPL_DIS, NULL) == NULL) {
240 PRINTF(
"RPL: Out of Memory, not sending unicast DIO, DIS from ");
243 PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
246 PRINTF(
"RPL: Unicast DIS, reply to sender\n");
257 dis_output(uip_ipaddr_t *addr)
259 unsigned char *buffer;
260 uip_ipaddr_t tmpaddr;
271 buffer = UIP_ICMP_PAYLOAD;
272 buffer[0] = buffer[1] = 0;
279 PRINTF(
"RPL: Sending a DIS to ");
289 unsigned char *buffer;
290 uint8_t buffer_length;
297 memset(&dio, 0,
sizeof(dio));
300 dio.dag_intdoubl = RPL_DIO_INTERVAL_DOUBLINGS;
301 dio.dag_intmin = RPL_DIO_INTERVAL_MIN;
302 dio.dag_redund = RPL_DIO_REDUNDANCY;
303 dio.dag_min_hoprankinc = RPL_MIN_HOPRANKINC;
304 dio.dag_max_rankinc = RPL_MAX_RANKINC;
305 dio.ocp = RPL_OF_OCP;
306 dio.default_lifetime = RPL_DEFAULT_LIFETIME;
307 dio.lifetime_unit = RPL_DEFAULT_LIFETIME_UNIT;
312 PRINTF(
"RPL: Received a DIO from ");
316 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
320 buffer = UIP_ICMP_PAYLOAD;
322 dio.instance_id = buffer[i++];
323 dio.version = buffer[i++];
324 dio.rank = get16(buffer, i);
327 PRINTF(
"RPL: Incoming DIO (id, ver, rank) = (%u,%u,%u)\n",
328 (
unsigned)dio.instance_id,
329 (
unsigned)dio.version,
332 dio.grounded = buffer[i] & RPL_DIO_GROUNDED;
333 dio.mop = (buffer[i]& RPL_DIO_MOP_MASK) >> RPL_DIO_MOP_SHIFT;
334 dio.preference = buffer[i++] & RPL_DIO_PREFERENCE_MASK;
336 dio.dtsn = buffer[i++];
340 memcpy(&dio.dag_id, buffer + i,
sizeof(dio.dag_id));
341 i +=
sizeof(dio.dag_id);
343 PRINTF(
"RPL: Incoming DIO (dag_id, pref) = (");
344 PRINT6ADDR(&dio.dag_id);
345 PRINTF(
", %u)\n", dio.preference);
348 for(; i < buffer_length; i += len) {
349 subopt_type = buffer[i];
350 if(subopt_type == RPL_OPTION_PAD1) {
354 len = 2 + buffer[i + 1];
357 if(len + i > buffer_length) {
358 PRINTF(
"RPL: Invalid DIO packet\n");
359 RPL_STAT(rpl_stats.malformed_msgs++);
363 PRINTF(
"RPL: DIO option %u, length: %u\n", subopt_type, len - 2);
365 switch(subopt_type) {
366 case RPL_OPTION_DAG_METRIC_CONTAINER:
368 PRINTF(
"RPL: Invalid DAG MC, len = %d\n", len);
369 RPL_STAT(rpl_stats.malformed_msgs++);
372 dio.mc.type = buffer[i + 2];
373 dio.mc.flags = buffer[i + 3] << 1;
374 dio.mc.flags |= buffer[i + 4] >> 7;
375 dio.mc.aggr = (buffer[i + 4] >> 4) & 0x3;
376 dio.mc.prec = buffer[i + 4] & 0xf;
377 dio.mc.length = buffer[i + 5];
379 if(dio.mc.type == RPL_DAG_MC_NONE) {
381 }
else if(dio.mc.type == RPL_DAG_MC_ETX) {
382 dio.mc.obj.etx = get16(buffer, i + 6);
384 PRINTF(
"RPL: DAG MC: type %u, flags %u, aggr %u, prec %u, length %u, ETX %u\n",
385 (
unsigned)dio.mc.type,
386 (
unsigned)dio.mc.flags,
387 (
unsigned)dio.mc.aggr,
388 (
unsigned)dio.mc.prec,
389 (
unsigned)dio.mc.length,
390 (
unsigned)dio.mc.obj.etx);
391 }
else if(dio.mc.type == RPL_DAG_MC_ENERGY) {
392 dio.mc.obj.energy.flags = buffer[i + 6];
393 dio.mc.obj.energy.energy_est = buffer[i + 7];
395 PRINTF(
"RPL: Unhandled DAG MC type: %u\n", (
unsigned)dio.mc.type);
399 case RPL_OPTION_ROUTE_INFO:
401 PRINTF(
"RPL: Invalid destination prefix option, len = %d\n", len);
402 RPL_STAT(rpl_stats.malformed_msgs++);
407 dio.destination_prefix.length = buffer[i + 2];
408 dio.destination_prefix.flags = buffer[i + 3];
409 dio.destination_prefix.lifetime = get32(buffer, i + 4);
411 if(((dio.destination_prefix.length + 7) / 8) + 8 <= len &&
412 dio.destination_prefix.length <= 128) {
413 PRINTF(
"RPL: Copying destination prefix\n");
414 memcpy(&dio.destination_prefix.prefix, &buffer[i + 8],
415 (dio.destination_prefix.length + 7) / 8);
417 PRINTF(
"RPL: Invalid route info option, len = %d\n", len);
418 RPL_STAT(rpl_stats.malformed_msgs++);
423 case RPL_OPTION_DAG_CONF:
425 PRINTF(
"RPL: Invalid DAG configuration option, len = %d\n", len);
426 RPL_STAT(rpl_stats.malformed_msgs++);
431 dio.dag_intdoubl = buffer[i + 3];
432 dio.dag_intmin = buffer[i + 4];
433 dio.dag_redund = buffer[i + 5];
434 dio.dag_max_rankinc = get16(buffer, i + 6);
435 dio.dag_min_hoprankinc = get16(buffer, i + 8);
436 dio.ocp = get16(buffer, i + 10);
438 dio.default_lifetime = buffer[i + 13];
439 dio.lifetime_unit = get16(buffer, i + 14);
440 PRINTF(
"RPL: DAG conf:dbl=%d, min=%d red=%d maxinc=%d mininc=%d ocp=%d d_l=%u l_u=%u\n",
441 dio.dag_intdoubl, dio.dag_intmin, dio.dag_redund,
442 dio.dag_max_rankinc, dio.dag_min_hoprankinc, dio.ocp,
443 dio.default_lifetime, dio.lifetime_unit);
445 case RPL_OPTION_PREFIX_INFO:
447 PRINTF(
"RPL: Invalid DAG prefix info, len != 32\n");
448 RPL_STAT(rpl_stats.malformed_msgs++);
451 dio.prefix_info.length = buffer[i + 2];
452 dio.prefix_info.flags = buffer[i + 3];
455 dio.prefix_info.lifetime = get32(buffer, i + 8);
457 PRINTF(
"RPL: Copying prefix information\n");
458 memcpy(&dio.prefix_info.prefix, &buffer[i + 16], 16);
461 PRINTF(
"RPL: Unsupported suboption type in DIO: %u\n",
462 (
unsigned)subopt_type);
466 #ifdef RPL_DEBUG_DIO_INPUT 467 RPL_DEBUG_DIO_INPUT(&from, &dio);
479 unsigned char *buffer;
490 if(uc_addr == NULL) {
491 PRINTF(
"RPL: LEAF ONLY have multicast addr: skip dio_output\n");
499 buffer = UIP_ICMP_PAYLOAD;
500 buffer[pos++] = instance->instance_id;
501 buffer[pos++] = dag->version;
502 is_root = (dag->rank ==
ROOT_RANK(instance));
505 PRINTF(
"RPL: LEAF ONLY DIO rank set to RPL_INFINITE_RANK\n");
506 set16(buffer, pos, RPL_INFINITE_RANK);
508 set16(buffer, pos, dag->rank);
514 buffer[pos] |= RPL_DIO_GROUNDED;
517 buffer[pos] |= instance->mop << RPL_DIO_MOP_SHIFT;
518 buffer[pos] |= dag->preference & RPL_DIO_PREFERENCE_MASK;
521 buffer[pos++] = instance->dtsn_out;
523 if(RPL_DIO_REFRESH_DAO_ROUTES && is_root && uc_addr == NULL) {
527 RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
534 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
538 if(instance->mc.type != RPL_DAG_MC_NONE) {
539 instance->of->update_metric_container(instance);
541 buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER;
543 buffer[pos++] = instance->mc.type;
544 buffer[pos++] = instance->mc.flags >> 1;
545 buffer[pos] = (instance->mc.flags & 1) << 7;
546 buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
547 if(instance->mc.type == RPL_DAG_MC_ETX) {
549 set16(buffer, pos, instance->mc.obj.etx);
551 }
else if(instance->mc.type == RPL_DAG_MC_ENERGY) {
553 buffer[pos++] = instance->mc.obj.energy.flags;
554 buffer[pos++] = instance->mc.obj.energy.energy_est;
556 PRINTF(
"RPL: Unable to send DIO because of unhandled DAG MC type %u\n",
557 (
unsigned)instance->mc.type);
564 buffer[pos++] = RPL_OPTION_DAG_CONF;
567 buffer[pos++] = instance->dio_intdoubl;
568 buffer[pos++] = instance->dio_intmin;
569 buffer[pos++] = instance->dio_redundancy;
570 set16(buffer, pos, instance->max_rankinc);
572 set16(buffer, pos, instance->min_hoprankinc);
575 set16(buffer, pos, instance->of->ocp);
578 buffer[pos++] = instance->default_lifetime;
579 set16(buffer, pos, instance->lifetime_unit);
583 if(dag->prefix_info.length > 0) {
584 buffer[pos++] = RPL_OPTION_PREFIX_INFO;
586 buffer[pos++] = dag->prefix_info.length;
587 buffer[pos++] = dag->prefix_info.flags;
588 set32(buffer, pos, dag->prefix_info.lifetime);
590 set32(buffer, pos, dag->prefix_info.lifetime);
592 memset(&buffer[pos], 0, 4);
594 memcpy(&buffer[pos], &dag->prefix_info.prefix, 16);
596 PRINTF(
"RPL: Sending prefix info in DIO for ");
597 PRINT6ADDR(&dag->prefix_info.prefix);
600 PRINTF(
"RPL: No prefix to announce (len %d)\n",
601 dag->prefix_info.length);
605 #if (DEBUG) & DEBUG_PRINT 606 if(uc_addr == NULL) {
607 PRINTF(
"RPL: LEAF ONLY sending unicast-DIO from multicast-DIO\n");
610 PRINTF(
"RPL: Sending unicast-DIO with rank %u to ",
611 (
unsigned)dag->rank);
617 if(uc_addr == NULL) {
618 PRINTF(
"RPL: Sending a multicast-DIO with rank %u\n",
619 (
unsigned)instance->current_dag->rank);
623 PRINTF(
"RPL: Sending unicast-DIO with rank %u to ",
624 (
unsigned)instance->current_dag->rank);
633 dao_input_storing(
void)
636 uip_ipaddr_t dao_sender_addr;
639 unsigned char *buffer;
652 uint8_t buffer_length;
657 rpl_parent_t *parent;
663 memset(&prefix, 0,
sizeof(prefix));
667 buffer = UIP_ICMP_PAYLOAD;
668 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
671 instance_id = buffer[pos++];
673 instance = rpl_get_instance(instance_id);
675 lifetime = instance->default_lifetime;
677 flags = buffer[pos++];
680 sequence = buffer[pos++];
682 dag = instance->current_dag;
683 is_root = (dag->rank ==
ROOT_RANK(instance));
686 if(flags & RPL_DAO_D_FLAG) {
687 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
688 PRINTF(
"RPL: Ignoring a DAO for a DAG different from ours\n");
695 RPL_ROUTE_FROM_MULTICAST_DAO : RPL_ROUTE_FROM_UNICAST_DAO;
698 PRINTF(
"RPL: Received a (%s) DAO with sequence number %u from ",
699 learned_from == RPL_ROUTE_FROM_UNICAST_DAO?
"unicast":
"multicast", sequence);
700 PRINT6ADDR(&dao_sender_addr);
703 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
705 parent = rpl_find_parent(dag, &dao_sender_addr);
710 PRINTF(
"RPL: Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n",
712 parent->rank = RPL_INFINITE_RANK;
713 parent->flags |= RPL_PARENT_FLAG_UPDATED;
718 if(parent != NULL && parent == dag->preferred_parent) {
719 PRINTF(
"RPL: Loop detected when receiving a unicast DAO from our parent\n");
720 parent->rank = RPL_INFINITE_RANK;
721 parent->flags |= RPL_PARENT_FLAG_UPDATED;
727 for(i = pos; i < buffer_length; i += len) {
728 subopt_type = buffer[i];
729 if(subopt_type == RPL_OPTION_PAD1) {
733 len = 2 + buffer[i + 1];
736 switch(subopt_type) {
737 case RPL_OPTION_TARGET:
739 prefixlen = buffer[i + 3];
740 memset(&prefix, 0,
sizeof(prefix));
741 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
743 case RPL_OPTION_TRANSIT:
747 lifetime = buffer[i + 5];
753 PRINTF(
"RPL: DAO lifetime: %u, prefix length: %u prefix: ",
754 (
unsigned)lifetime, (
unsigned)prefixlen);
758 #if RPL_WITH_MULTICAST 767 mcast_group->
dag = dag;
774 rep = uip_ds6_route_lookup(&prefix);
776 if(lifetime == RPL_ZERO_LIFETIME) {
777 PRINTF(
"RPL: No-Path DAO received\n");
780 !RPL_ROUTE_IS_NOPATH_RECEIVED(rep) &&
781 rep->length == prefixlen &&
782 uip_ds6_route_nexthop(rep) != NULL &&
783 uip_ipaddr_cmp(uip_ds6_route_nexthop(rep), &dao_sender_addr)) {
784 PRINTF(
"RPL: Setting expiration timer for prefix ");
787 RPL_ROUTE_SET_NOPATH_RECEIVED(rep);
788 rep->state.lifetime = RPL_NOPATH_REMOVAL_DELAY;
792 if(dag->preferred_parent != NULL &&
793 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
795 out_seq = prepare_for_dao_fwd(sequence, rep);
797 PRINTF(
"RPL: Forwarding No-path DAO to parent - out_seq:%d",
799 PRINT6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
802 buffer = UIP_ICMP_PAYLOAD;
809 if(flags & RPL_DAO_K_FLAG) {
812 dao_ack_output(instance, &dao_sender_addr, sequence,
813 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
818 PRINTF(
"RPL: Adding DAO route\n");
822 PRINTF(
"RPL: Out of Memory, dropping DAO from ");
823 PRINT6ADDR(&dao_sender_addr);
825 PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER));
827 if(flags & RPL_DAO_K_FLAG) {
829 dao_ack_output(instance, &dao_sender_addr, sequence,
830 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
831 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
836 rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
838 RPL_STAT(rpl_stats.mem_overflows++);
839 PRINTF(
"RPL: Could not add a route after receiving a DAO\n");
840 if(flags & RPL_DAO_K_FLAG) {
842 dao_ack_output(instance, &dao_sender_addr, sequence,
843 is_root ? RPL_DAO_ACK_UNABLE_TO_ADD_ROUTE_AT_ROOT :
844 RPL_DAO_ACK_UNABLE_TO_ACCEPT);
851 RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep);
853 #if RPL_WITH_MULTICAST 857 if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
860 if(flags & RPL_DAO_K_FLAG) {
868 if((!RPL_ROUTE_IS_DAO_PENDING(rep) &&
869 rep->state.dao_seqno_in == sequence) ||
876 if(dag->preferred_parent != NULL &&
877 rpl_parent_get_ipaddr(dag->preferred_parent) != NULL) {
881 if(RPL_ROUTE_IS_DAO_PENDING(rep) &&
882 rep->state.dao_seqno_in == sequence) {
884 out_seq = rep->state.dao_seqno_out;
886 out_seq = prepare_for_dao_fwd(sequence, rep);
890 PRINTF(
"RPL: Forwarding DAO to parent ");
891 PRINT6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent));
892 PRINTF(
" in seq: %d out seq: %d\n", sequence, out_seq);
894 buffer = UIP_ICMP_PAYLOAD;
900 PRINTF(
"RPL: Sending DAO ACK\n");
902 dao_ack_output(instance, &dao_sender_addr, sequence,
903 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
910 dao_input_nonstoring(
void)
912 #if RPL_WITH_NON_STORING 913 uip_ipaddr_t dao_sender_addr;
914 uip_ipaddr_t dao_parent_addr;
917 unsigned char *buffer;
925 uint8_t buffer_length;
933 memset(&dao_parent_addr, 0, 16);
935 buffer = UIP_ICMP_PAYLOAD;
936 buffer_length =
uip_len - uip_l3_icmp_hdr_len;
939 instance_id = buffer[pos++];
940 instance = rpl_get_instance(instance_id);
941 lifetime = instance->default_lifetime;
943 flags = buffer[pos++];
946 sequence = buffer[pos++];
948 dag = instance->current_dag;
950 if(flags & RPL_DAO_D_FLAG) {
951 if(memcmp(&dag->dag_id, &buffer[pos],
sizeof(dag->dag_id))) {
952 PRINTF(
"RPL: Ignoring a DAO for a DAG different from ours\n");
959 for(i = pos; i < buffer_length; i += len) {
960 subopt_type = buffer[i];
961 if(subopt_type == RPL_OPTION_PAD1) {
965 len = 2 + buffer[i + 1];
968 switch(subopt_type) {
969 case RPL_OPTION_TARGET:
971 prefixlen = buffer[i + 3];
972 memset(&prefix, 0,
sizeof(prefix));
973 memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
975 case RPL_OPTION_TRANSIT:
979 lifetime = buffer[i + 5];
981 memcpy(&dao_parent_addr, buffer + i + 6, 16);
987 PRINTF(
"RPL: DAO lifetime: %u, prefix length: %u prefix: ",
988 (
unsigned)lifetime, (
unsigned)prefixlen);
990 PRINTF(
", parent: ");
991 PRINT6ADDR(&dao_parent_addr);
994 if(lifetime == RPL_ZERO_LIFETIME) {
995 PRINTF(
"RPL: No-Path DAO received\n");
999 PRINTF(
"RPL: failed to add link\n");
1004 if(flags & RPL_DAO_K_FLAG) {
1005 PRINTF(
"RPL: Sending DAO ACK\n");
1007 dao_ack_output(instance, &dao_sender_addr, sequence,
1008 RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
1017 uint8_t instance_id;
1020 PRINTF(
"RPL: Received a DAO from ");
1024 instance_id = UIP_ICMP_PAYLOAD[0];
1025 instance = rpl_get_instance(instance_id);
1026 if(instance == NULL) {
1027 PRINTF(
"RPL: Ignoring a DAO for an unknown RPL instance(%u)\n",
1032 if(RPL_IS_STORING(instance)) {
1033 dao_input_storing();
1034 }
else if(RPL_IS_NON_STORING(instance)) {
1035 dao_input_nonstoring();
1042 #if RPL_WITH_DAO_ACK 1044 handle_dao_retransmission(
void *ptr)
1046 rpl_parent_t *parent;
1047 uip_ipaddr_t prefix;
1051 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1054 instance = parent->dag->instance;
1056 if(instance->my_dao_transmissions >= RPL_DAO_MAX_RETRANSMISSIONS) {
1058 if(instance->lifetime_unit == 0xffff && instance->default_lifetime == 0xff) {
1069 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1071 instance->of->dao_ack_callback(parent, RPL_DAO_ACK_TIMEOUT);
1079 PRINTF(
"RPL: will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno,
1080 instance->my_dao_transmissions);
1082 if(get_global_addr(&prefix) == 0) {
1087 RPL_DAO_RETRANSMISSION_TIMEOUT / 2 +
1088 (
random_rand() % (RPL_DAO_RETRANSMISSION_TIMEOUT / 2)),
1089 handle_dao_retransmission, parent);
1091 instance->my_dao_transmissions++;
1092 dao_output_target_seq(parent, &prefix,
1093 instance->default_lifetime, instance->my_dao_seqno);
1098 dao_output(rpl_parent_t *parent, uint8_t lifetime)
1101 uip_ipaddr_t prefix;
1103 if(get_global_addr(&prefix) == 0) {
1104 PRINTF(
"RPL: No global address set for this node - suppressing DAO\n");
1108 if(parent == NULL || parent->dag == NULL || parent->dag->instance == NULL) {
1112 RPL_LOLLIPOP_INCREMENT(dao_sequence);
1113 #if RPL_WITH_DAO_ACK 1117 if(lifetime != RPL_ZERO_LIFETIME) {
1119 instance = parent->dag->instance;
1121 instance->my_dao_seqno = dao_sequence;
1122 instance->my_dao_transmissions = 1;
1123 ctimer_set(&instance->dao_retransmit_timer, RPL_DAO_RETRANSMISSION_TIMEOUT,
1124 handle_dao_retransmission, parent);
1129 parent->dag->instance->has_downward_route = lifetime != RPL_ZERO_LIFETIME;
1133 dao_output_target(parent, &prefix, lifetime);
1137 dao_output_target(rpl_parent_t *parent, uip_ipaddr_t *prefix, uint8_t lifetime)
1139 dao_output_target_seq(parent, prefix, lifetime, dao_sequence);
1143 dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix,
1144 uint8_t lifetime, uint8_t seq_no)
1148 unsigned char *buffer;
1151 uip_ipaddr_t *parent_ipaddr = NULL;
1152 uip_ipaddr_t *dest_ipaddr = NULL;
1161 if(parent == NULL) {
1162 PRINTF(
"RPL dao_output_target error parent NULL\n");
1166 parent_ipaddr = rpl_parent_get_ipaddr(parent);
1167 if(parent_ipaddr == NULL) {
1168 PRINTF(
"RPL dao_output_target error parent IP address NULL\n");
1174 PRINTF(
"RPL dao_output_target error dag NULL\n");
1178 instance = dag->instance;
1180 if(instance == NULL) {
1181 PRINTF(
"RPL dao_output_target error instance NULL\n");
1184 if(prefix == NULL) {
1185 PRINTF(
"RPL dao_output_target error prefix NULL\n");
1188 #ifdef RPL_DEBUG_DAO_OUTPUT 1189 RPL_DEBUG_DAO_OUTPUT(parent);
1192 buffer = UIP_ICMP_PAYLOAD;
1195 buffer[pos++] = instance->instance_id;
1197 #if RPL_DAO_SPECIFY_DAG 1198 buffer[pos] |= RPL_DAO_D_FLAG;
1200 #if RPL_WITH_DAO_ACK 1201 if(lifetime != RPL_ZERO_LIFETIME) {
1202 buffer[pos] |= RPL_DAO_K_FLAG;
1207 buffer[pos++] = seq_no;
1208 #if RPL_DAO_SPECIFY_DAG 1209 memcpy(buffer + pos, &dag->dag_id,
sizeof(dag->dag_id));
1210 pos+=
sizeof(dag->dag_id);
1214 prefixlen =
sizeof(*prefix) * CHAR_BIT;
1215 buffer[pos++] = RPL_OPTION_TARGET;
1216 buffer[pos++] = 2 + ((prefixlen + 7) / CHAR_BIT);
1218 buffer[pos++] = prefixlen;
1219 memcpy(buffer + pos, prefix, (prefixlen + 7) / CHAR_BIT);
1220 pos += ((prefixlen + 7) / CHAR_BIT);
1223 buffer[pos++] = RPL_OPTION_TRANSIT;
1224 buffer[pos++] = (instance->mop != RPL_MOP_NON_STORING) ? 4 : 20;
1228 buffer[pos++] = lifetime;
1230 if(instance->mop != RPL_MOP_NON_STORING) {
1232 dest_ipaddr = parent_ipaddr;
1235 memcpy(buffer + pos, &parent->dag->dag_id, 8);
1237 memcpy(buffer + pos, ((
const unsigned char *)parent_ipaddr) + 8, 8);
1240 dest_ipaddr = &parent->dag->dag_id;
1243 PRINTF(
"RPL: Sending a %sDAO with sequence number %u, lifetime %u, prefix ",
1244 lifetime == RPL_ZERO_LIFETIME ?
"No-Path " :
"", seq_no, lifetime);
1248 PRINT6ADDR(dest_ipaddr);
1249 PRINTF(
" , parent ");
1250 PRINT6ADDR(parent_ipaddr);
1253 if(dest_ipaddr != NULL) {
1261 #if RPL_WITH_DAO_ACK 1264 uint8_t instance_id;
1268 rpl_parent_t *parent;
1270 buffer = UIP_ICMP_PAYLOAD;
1272 instance_id = buffer[0];
1273 sequence = buffer[2];
1276 instance = rpl_get_instance(instance_id);
1277 if(instance == NULL) {
1282 if(RPL_IS_STORING(instance)) {
1283 parent = rpl_find_parent(instance->current_dag, &
UIP_IP_BUF->srcipaddr);
1284 if(parent == NULL) {
1293 if(instance->current_dag->rank ==
ROOT_RANK(instance)) {
1294 PRINTF(
"RPL: DODAG root received a DAO ACK, ignoring it\n");
1299 PRINTF(
"RPL: Received a DAO %s with sequence number %d (%d) and status %d from ",
1300 status < 128 ?
"ACK" :
"NACK",
1301 sequence, instance->my_dao_seqno, status);
1305 if(sequence == instance->my_dao_seqno) {
1306 instance->has_downward_route = status < 128;
1312 if(RPL_IS_STORING(instance) && instance->of->dao_ack_callback) {
1313 instance->of->dao_ack_callback(parent, status);
1316 #if RPL_REPAIR_ON_DAO_NACK 1317 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1326 }
else if(RPL_IS_STORING(instance)) {
1329 uip_ipaddr_t *nexthop;
1330 if((re = find_route_entry_by_dao_ack(sequence)) != NULL) {
1333 RPL_ROUTE_CLEAR_DAO_PENDING(re);
1335 nexthop = uip_ds6_route_nexthop(re);
1336 if(nexthop == NULL) {
1337 PRINTF(
"RPL: No next hop to fwd DAO ACK to\n");
1339 PRINTF(
"RPL: Fwd DAO ACK to:");
1340 PRINT6ADDR(nexthop);
1342 buffer[2] = re->state.dao_seqno_in;
1346 if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) {
1348 uip_ds6_route_rm(re);
1351 PRINTF(
"RPL: No route entry found to forward DAO ACK (seqno %u)\n", sequence);
1359 dao_ack_output(
rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence,
1362 #if RPL_WITH_DAO_ACK 1363 unsigned char *buffer;
1365 PRINTF(
"RPL: Sending a DAO %s with sequence number %d to ", status < 128 ?
"ACK" :
"NACK", sequence);
1367 PRINTF(
" with status %d\n", status);
1369 buffer = UIP_ICMP_PAYLOAD;
1371 buffer[0] = instance->instance_id;
1373 buffer[2] = sequence;
1381 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.
A set of debugging macros for the IP stack
#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.
uip_mcast6_route_t * uip_mcast6_route_add(uip_ipaddr_t *group)
Add a multicast route.
An entry in the nbr cache.