void rpl_update_header_empty(void) { rpl_instance_t *instance; int uip_ext_opt_offset; int last_uip_ext_len; last_uip_ext_len = uip_ext_len; uip_ext_len = 0; uip_ext_opt_offset = 2; PRINTF("RPL: Verifying the presence of the RPL header option\n"); switch(UIP_IP_BUF->proto) { case UIP_PROTO_HBHO: if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n"); uip_ext_len = last_uip_ext_len; return; } instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); if(instance == NULL || !instance->used || !instance->current_dag->joined) { PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect instance\n"); return; } break; default: PRINTF("RPL: No hop-by-hop option found, creating it\n"); if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) { PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n"); uip_ext_len = last_uip_ext_len; return; } set_rpl_opt(uip_ext_opt_offset); uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; return; } switch(UIP_EXT_HDR_OPT_BUF->type) { case UIP_EXT_HDR_OPT_RPL: PRINTF("RPL: Updating RPL option\n"); UIP_EXT_HDR_OPT_RPL_BUF->senderrank=instance->current_dag->rank; uip_ext_len = last_uip_ext_len; return; default: PRINTF("RPL: Multi Hop-by-hop options not implemented\n"); uip_ext_len = last_uip_ext_len; return; } }
/*---------------------------------------------------------------------------*/ void rpl_update_header_empty(void) { rpl_instance_t *instance; int uip_ext_opt_offset; int last_uip_ext_len; last_uip_ext_len = uip_ext_len; uip_ext_len = 0; uip_ext_opt_offset = 2; PRINTF("RPL: Verifying the presence of the RPL header option\n"); switch(UIP_IP_BUF->proto) { case UIP_PROTO_HBHO: if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n"); uip_ext_len = last_uip_ext_len; return; } instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); if(instance == NULL || !instance->used || !instance->current_dag->joined) { PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect instance\n"); return; } break; default: PRINTF("RPL: No hop-by-hop option found, creating it\n"); if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE) { PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n"); uip_ext_len = last_uip_ext_len; return; } set_rpl_opt(uip_ext_opt_offset); uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; return; } switch(UIP_EXT_HDR_OPT_BUF->type) { case UIP_EXT_HDR_OPT_RPL: PRINTF("RPL: Updating RPL option\n"); UIP_EXT_HDR_OPT_RPL_BUF->senderrank = instance->current_dag->rank; /* Check the direction of the down flag, as per Section 11.2.2.3, which states that if a packet is going down it should in general not go back up again. If this happens, a RPL_HDR_OPT_FWD_ERR should be flagged. */ if((UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN)) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_FWD_ERR; PRINTF("RPL forwarding error\n"); } } else { /* Set the down extension flag correctly as described in Section 11.2 of RFC6550. If the packet progresses along a DAO route, the down flag should be set. */ if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { /* No route was found, so this packet will go towards the RPL root. If so, we should not set the down flag. */ UIP_EXT_HDR_OPT_RPL_BUF->flags &= ~RPL_HDR_OPT_DOWN; PRINTF("RPL option going up\n"); } else { /* A DAO route was found so we set the down flag. */ UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_DOWN; PRINTF("RPL option going down\n"); } } uip_ext_len = last_uip_ext_len; return; default: PRINTF("RPL: Multi Hop-by-hop options not implemented\n"); uip_ext_len = last_uip_ext_len; return; } }
/*---------------------------------------------------------------------------*/ int rpl_update_header_empty(void) { rpl_instance_t *instance; int uip_ext_opt_offset; int last_uip_ext_len; rpl_parent_t *parent; last_uip_ext_len = uip_ext_len; uip_ext_len = 0; uip_ext_opt_offset = 2; PRINTF("RPL: Verifying the presence of the RPL header option\n"); switch(UIP_IP_BUF->proto) { case UIP_PROTO_HBHO: if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) { PRINTF("RPL: Hop-by-hop extension header has wrong size\n"); uip_ext_len = last_uip_ext_len; return 0; } if(UIP_EXT_HDR_OPT_RPL_BUF->opt_type != UIP_EXT_HDR_OPT_RPL) { PRINTF("RPL: Non RPL Hop-by-hop option support not implemented\n"); uip_ext_len = last_uip_ext_len; return 0; } if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { PRINTF("RPL: RPL Hop-by-hop option has wrong length\n"); uip_ext_len = last_uip_ext_len; return 0; } instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); if(instance == NULL || !instance->used || !instance->current_dag->joined) { PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect instance\n"); return 0; } break; default: #if RPL_INSERT_HBH_OPTION PRINTF("RPL: No hop-by-hop option found, creating it\n"); 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; } set_rpl_opt(uip_ext_opt_offset); uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN; #endif return 0; } switch(UIP_EXT_HDR_OPT_BUF->type) { case UIP_EXT_HDR_OPT_RPL: PRINTF("RPL: Updating RPL option\n"); UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank); /* Check the direction of the down flag, as per Section 11.2.2.3, which states that if a packet is going down it should in general not go back up again. If this happens, a RPL_HDR_OPT_FWD_ERR should be flagged. */ if((UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN)) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_FWD_ERR; PRINTF("RPL forwarding error\n"); /* We should send back the packet to the originating parent, but it is not feasible yet, so we send a No-Path DAO instead */ PRINTF("RPL generate No-Path DAO\n"); parent = rpl_get_parent((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); if(parent != NULL) { dao_output_target(parent, &UIP_IP_BUF->destipaddr, RPL_ZERO_LIFETIME); } /* Drop packet */ return 1; } } else { /* Set the down extension flag correctly as described in Section 11.2 of RFC6550. If the packet progresses along a DAO route, the down flag should be set. */ if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { /* No route was found, so this packet will go towards the RPL root. If so, we should not set the down flag. */ UIP_EXT_HDR_OPT_RPL_BUF->flags &= ~RPL_HDR_OPT_DOWN; PRINTF("RPL option going up\n"); } else { /* A DAO route was found so we set the down flag. */ UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_DOWN; PRINTF("RPL option going down\n"); } } uip_ext_len = last_uip_ext_len; return 0; default: PRINTF("RPL: Multi Hop-by-hop options not implemented\n"); uip_ext_len = last_uip_ext_len; return 0; } }