diff --git a/os/net/app-layer/coap/coap.h b/os/net/app-layer/coap/coap.h index 9d88886af..616f67d5c 100644 --- a/os/net/app-layer/coap/coap.h +++ b/os/net/app-layer/coap/coap.h @@ -46,7 +46,7 @@ /* sanity check for configured values */ #define COAP_MAX_PACKET_SIZE (COAP_MAX_HEADER_SIZE + REST_MAX_CHUNK_SIZE) -#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_IPH_LEN - UIP_UDPH_LEN) +#if COAP_MAX_PACKET_SIZE > (UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPH_LEN - UIP_UDPH_LEN) #error "UIP_CONF_BUFFER_SIZE too small for REST_MAX_CHUNK_SIZE" #endif diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 4509c3e08..060699e93 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -123,7 +123,7 @@ /* NOTE: In the multiple-reassembly context there is only room for the header / first fragment */ #define SICSLOWPAN_IP_BUF(buf) ((struct uip_ip_hdr *)buf) #define SICSLOWPAN_UDP_BUF(buf) ((struct uip_udp_hdr *)&buf[UIP_IPH_LEN]) -#define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_LLIPH_LEN]) +#define SICSLOWPAN_IPPAYLOAD_BUF(buf) (&buf[UIP_IPH_LEN]) #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index d6207400b..e096ce44b 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -472,12 +472,7 @@ output_fallback(void) #ifdef UIP_FALLBACK_INTERFACE LOG_INFO("fallback: removing ext hdrs & setting proto %d %d\n", uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40)); - if(uip_ext_len > 0) { - uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40); - remove_ext_hdr(); - /* This should be copied from the ext header... */ - UIP_IP_BUF->proto = proto; - } + remove_ext_hdr(); /* Inform the other end that the destination is not reachable. If it's * not informed routes might get lost unexpectedly until there's a need * to send a new packet to the peer */ diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index 4ae366d2f..72384414a 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -523,6 +523,7 @@ uip_connect(const uip_ipaddr_t *ripaddr, uint16_t rport) void remove_ext_hdr(void) { + int last_uip_ext_len; /* Remove ext header before TCP/UDP processing. */ if(uip_ext_len > 0) { LOG_DBG("Cutting ext-header before processing (extlen: %d, uiplen: %d)\n", @@ -532,15 +533,17 @@ remove_ext_hdr(void) uip_clear_buf(); return; } - memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + uip_ext_len, - uip_len - UIP_IPH_LEN - uip_ext_len); + last_uip_ext_len = uip_ext_len; + uip_ext_len = 0; + UIP_IP_BUF->proto = UIP_EXT_BUF->next; + memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF + last_uip_ext_len, + uip_len - UIP_IPH_LEN - last_uip_ext_len); - uip_len -= uip_ext_len; + uip_len -= last_uip_ext_len; /* Update the IP length. */ UIP_IP_BUF->len[0] = (uip_len - UIP_IPH_LEN) >> 8; UIP_IP_BUF->len[1] = (uip_len - UIP_IPH_LEN) & 0xff; - uip_ext_len = 0; } } /*---------------------------------------------------------------------------*/ @@ -1494,7 +1497,6 @@ uip_process(uint8_t flag) udp_input: remove_ext_hdr(); - UIP_IP_BUF->proto = UIP_PROTO_UDP; LOG_INFO("Receiving UDP packet\n"); @@ -1607,7 +1609,6 @@ uip_process(uint8_t flag) tcp_input: remove_ext_hdr(); - UIP_IP_BUF->proto = UIP_PROTO_TCP; UIP_STAT(++uip_stat.tcp.recv); LOG_INFO("Receiving TCP packet\n"); diff --git a/os/net/rpl-classic/rpl-dag.c b/os/net/rpl-classic/rpl-dag.c index 4649f31e7..aeed6194e 100644 --- a/os/net/rpl-classic/rpl-dag.c +++ b/os/net/rpl-classic/rpl-dag.c @@ -764,22 +764,17 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) old_rank = instance->current_dag->rank; last_parent = instance->current_dag->preferred_parent; - best_dag = instance->current_dag; - if(best_dag->rank != ROOT_RANK(instance)) { - if(rpl_select_parent(p->dag) != NULL) { - if(p->dag != best_dag) { - best_dag = instance->of->best_dag(best_dag, p->dag); - } - } else if(p->dag == best_dag) { - best_dag = NULL; - for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) { - if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != RPL_INFINITE_RANK) { - if(best_dag == NULL) { - best_dag = dag; - } else { - best_dag = instance->of->best_dag(best_dag, dag); - } - } + if(instance->current_dag->rank != ROOT_RANK(instance)) { + rpl_select_parent(p->dag); + } + + best_dag = NULL; + for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) { + if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != RPL_INFINITE_RANK) { + if(best_dag == NULL) { + best_dag = dag; + } else { + best_dag = instance->of->best_dag(best_dag, dag); } } } diff --git a/os/net/rpl-classic/rpl-ext-header.c b/os/net/rpl-classic/rpl-ext-header.c index 0c1f8076a..a0fdb0eb4 100644 --- a/os/net/rpl-classic/rpl-ext-header.c +++ b/os/net/rpl-classic/rpl-ext-header.c @@ -408,7 +408,7 @@ insert_srh_header(void) path_len, cmpri, cmpre, ext_len, padding); /* Check if there is enough space to store the extension header */ - if(uip_len + ext_len > UIP_BUFSIZE) { + if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) { PRINTF("RPL: Packet too long: impossible to add source routing header (%u bytes)\n", ext_len); return 0; } @@ -553,7 +553,7 @@ insert_hbh_header(const rpl_instance_t *instance) /* Insert hop-by-hop header */ PRINTF("RPL: Creating hop-by-hop option\n"); - if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) { + if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) { PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n"); uip_ext_len = last_uip_ext_len; return 0; diff --git a/os/net/rpl-classic/rpl-ns.h b/os/net/rpl-classic/rpl-ns.h index f6ae4c2c6..dcc7e584a 100644 --- a/os/net/rpl-classic/rpl-ns.h +++ b/os/net/rpl-classic/rpl-ns.h @@ -56,6 +56,7 @@ typedef struct rpl_ns_node { struct rpl_ns_node *next; uint32_t lifetime; + rpl_dag_t *dag; /* Store only IPv6 link identifiers as all nodes in the DAG share the same prefix */ unsigned char link_identifier[8]; struct rpl_ns_node *parent; diff --git a/os/net/rpl-classic/rpl-timers.c b/os/net/rpl-classic/rpl-timers.c index 56eda7abc..7742a5fcc 100644 --- a/os/net/rpl-classic/rpl-timers.c +++ b/os/net/rpl-classic/rpl-timers.c @@ -457,11 +457,29 @@ get_probing_target(rpl_dag_t *dag) return probing_target; } /*---------------------------------------------------------------------------*/ +static rpl_dag_t * +get_next_dag(rpl_instance_t *instance) +{ + rpl_dag_t *dag = NULL; + int new_dag = instance->last_dag; + do { + new_dag++; + if(new_dag >= RPL_MAX_DAG_PER_INSTANCE) { + new_dag = 0; + } + if(instance->dag_table[new_dag].used) { + dag = &instance->dag_table[new_dag]; + } + } while(new_dag != instance->last_dag && dag == NULL); + instance->last_dag = new_dag; + return dag; +} +/*---------------------------------------------------------------------------*/ static void handle_probing_timer(void *ptr) { rpl_instance_t *instance = (rpl_instance_t *)ptr; - rpl_parent_t *probing_target = RPL_PROBING_SELECT_FUNC(instance->current_dag); + rpl_parent_t *probing_target = RPL_PROBING_SELECT_FUNC(get_next_dag(instance)); uip_ipaddr_t *target_ipaddr = rpl_parent_get_ipaddr(probing_target); /* Perform probing */ diff --git a/os/net/rpl-classic/rpl.h b/os/net/rpl-classic/rpl.h index 185bcbef2..2fe9f1dbf 100644 --- a/os/net/rpl-classic/rpl.h +++ b/os/net/rpl-classic/rpl.h @@ -252,6 +252,7 @@ struct rpl_instance { #if RPL_WITH_PROBING struct ctimer probing_timer; rpl_parent_t *urgent_probing_target; + int last_dag; #endif /* RPL_WITH_PROBING */ struct ctimer dio_timer; struct ctimer dao_timer; diff --git a/os/net/rpl-lite/rpl-ext-header.c b/os/net/rpl-lite/rpl-ext-header.c index e71e6c1f6..96455e85c 100644 --- a/os/net/rpl-lite/rpl-ext-header.c +++ b/os/net/rpl-lite/rpl-ext-header.c @@ -302,7 +302,7 @@ insert_srh_header(void) path_len, cmpri, cmpre, ext_len, padding); /* Check if there is enough space to store the extension header */ - if(uip_len + ext_len > UIP_BUFSIZE) { + if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) { LOG_ERR("packet too long: impossible to add source routing header (%u bytes)\n", ext_len); return 0; } @@ -464,7 +464,7 @@ insert_hbh_header(void) /* Insert hop-by-hop header */ LOG_INFO("creating hop-by-hop option\n"); - if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) { + if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) { LOG_ERR("packet too long: impossible to add hop-by-hop option\n"); uip_ext_len = last_uip_ext_len; return 0; diff --git a/os/services/ip64/ip64-dhcpc.c b/os/services/ip64/ip64-dhcpc.c index 81d97490d..8e8e286f8 100644 --- a/os/services/ip64/ip64-dhcpc.c +++ b/os/services/ip64/ip64-dhcpc.c @@ -61,7 +61,7 @@ struct dhcp_msg { uint8_t options[312]; }; -#if (UIP_BUFSIZE - UIP_UDPIP_HLEN) < 548 +#if (UIP_BUFSIZE - UIP_LLH_LEN - UIP_UDPIP_HLEN) < 548 #error UIP_CONF_BUFFER_SIZE may be too small to accomodate DHCPv4 packets #error Increase UIP_CONF_BUFFER_SIZE in your project-conf.h, or contiki-conf.h #error A good size is 600 bytes