Rework rpl-ext-header.c

This commit is contained in:
Simon Duquennoy 2018-10-18 18:29:37 +02:00
parent 8456c544d8
commit 6c11da58d8
7 changed files with 77 additions and 79 deletions

View File

@ -849,7 +849,7 @@ ext_hdr_options_process(int ext_offset)
* present) is processed. * present) is processed.
*/ */
LOG_DBG("Processing RPL option\n"); LOG_DBG("Processing RPL option\n");
if(!NETSTACK_ROUTING.ext_header_hbh_update(ext_offset, opt_offset)) { if(!NETSTACK_ROUTING.ext_header_hbh_update(UIP_IP_PAYLOAD(ext_offset), opt_offset)) {
LOG_ERR("RPL Option Error: Dropping Packet\n"); LOG_ERR("RPL Option Error: Dropping Packet\n");
return 1; return 1;
} }

View File

@ -118,7 +118,7 @@ ext_header_update(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
ext_header_hbh_update(int ext_offset, int opt_offset) ext_header_hbh_update(uint8_t *ext_buf, int opt_offset)
{ {
return 1; return 1;
} }

View File

@ -131,14 +131,13 @@ struct routing_driver {
* Process and update the routing protocol hob-by-hop * Process and update the routing protocol hob-by-hop
* extention headers of the current uIP packet. * extention headers of the current uIP packet.
* *
* \param ext_offset The offset within the uIP packet where * \param ext_buf A pointer to the ext header buffer
* extension headers start
* \param opt_offset The offset within the extension header where * \param opt_offset The offset within the extension header where
* the option starts * the option starts
* \return 1 in case the packet is valid and to be processed further, * \return 1 in case the packet is valid and to be processed further,
* 0 in case the packet must be dropped. * 0 in case the packet must be dropped.
*/ */
int (* ext_header_hbh_update)(int ext_offset, int opt_offset); int (* ext_header_hbh_update)(uint8_t *ext_buf, int opt_offset);
/** /**
* Process and update SRH in-place, * Process and update SRH in-place,
* i.e. internal address swapping as per RFC6554 * i.e. internal address swapping as per RFC6554

View File

@ -62,34 +62,33 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
rpl_ext_header_hbh_update(int ext_offset, int opt_offset) rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset)
{ {
rpl_instance_t *instance; rpl_instance_t *instance;
int down; int down;
uint16_t sender_rank; uint16_t sender_rank;
uint8_t sender_closer; uint8_t sender_closer;
uip_ds6_route_t *route; uip_ds6_route_t *route;
rpl_parent_t *sender = NULL; rpl_parent_t *sender;
struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)ext_buf;
struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(ext_buf + opt_offset);
if(UIP_HBHO_BUF(ext_offset)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type != UIP_EXT_HDR_OPT_RPL || rpl_opt->opt_type != UIP_EXT_HDR_OPT_RPL
|| UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { || rpl_opt->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n", LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n",
UIP_HBHO_BUF(ext_offset)->len, hbh_hdr->len, rpl_opt->opt_type, rpl_opt->opt_len);
UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type,
UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_len);
return 0; /* Drop */ return 0; /* Drop */
} }
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance); instance = rpl_get_instance(rpl_opt->instance);
if(instance == NULL) { if(instance == NULL) {
LOG_ERR("Unknown instance: %u\n", LOG_ERR("Unknown instance: %u\n", rpl_opt->instance);
UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance);
return 0; return 0;
} }
if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) { if(rpl_opt->flags & RPL_HDR_OPT_FWD_ERR) {
LOG_ERR("Forward error!\n"); LOG_ERR("Forward error!\n");
/* We should try to repair it by removing the neighbor that caused /* We should try to repair it by removing the neighbor that caused
the packet to be forwareded in the first place. We drop any the packet to be forwareded in the first place. We drop any
@ -113,14 +112,14 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset)
return 0; return 0;
} }
down = 0; down = 0;
if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_DOWN) { if(rpl_opt->flags & RPL_HDR_OPT_DOWN) {
down = 1; down = 1;
} }
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->senderrank); sender_rank = UIP_HTONS(rpl_opt->senderrank);
sender = nbr_table_get_from_lladdr(rpl_parents, packetbuf_addr(PACKETBUF_ADDR_SENDER)); sender = nbr_table_get_from_lladdr(rpl_parents, packetbuf_addr(PACKETBUF_ADDR_SENDER));
if(sender != NULL && (UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_RANK_ERR)) { if(sender != NULL && (rpl_opt->flags & RPL_HDR_OPT_RANK_ERR)) {
/* A rank error was signalled, attempt to repair it by updating /* A rank error was signalled, attempt to repair it by updating
* the sender's rank from ext header */ * the sender's rank from ext header */
sender->rank = sender_rank; sender->rank = sender_rank;
@ -150,7 +149,7 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset)
instance->unicast_dio_target = sender; instance->unicast_dio_target = sender;
rpl_schedule_unicast_dio_immediately(instance); rpl_schedule_unicast_dio_immediately(instance);
} }
if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) { if(rpl_opt->flags & RPL_HDR_OPT_RANK_ERR) {
RPL_STAT(rpl_stats.loop_errors++); RPL_STAT(rpl_stats.loop_errors++);
LOG_ERR(" Rank error signalled in RPL option!\n"); LOG_ERR(" Rank error signalled in RPL option!\n");
/* Packet must be dropped and dio trickle timer reset, see RFC6550 - 11.2.2.2 */ /* Packet must be dropped and dio trickle timer reset, see RFC6550 - 11.2.2.2 */
@ -159,7 +158,7 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset)
} }
LOG_WARN("Single error tolerated\n"); LOG_WARN("Single error tolerated\n");
RPL_STAT(rpl_stats.loop_warnings++); RPL_STAT(rpl_stats.loop_warnings++);
UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; rpl_opt->flags |= RPL_HDR_OPT_RANK_ERR;
return 1; return 1;
} }
@ -414,18 +413,18 @@ update_hbh_header(void)
{ {
rpl_instance_t *instance; rpl_instance_t *instance;
rpl_parent_t *parent; rpl_parent_t *parent;
int opt_offset = 2; struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0);
struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(0) + 2);
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && rpl_opt->opt_type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_HBHO_BUF(0)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { || rpl_opt->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("Hop-by-hop extension header has wrong size (%u)\n", LOG_ERR("Hop-by-hop extension header has wrong size (%u)\n", rpl_opt->opt_len);
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len);
return 0; /* Drop */ return 0; /* Drop */
} }
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance); instance = rpl_get_instance(rpl_opt->instance);
if(instance == NULL || !instance->used || !instance->current_dag->joined) { if(instance == NULL || !instance->used || !instance->current_dag->joined) {
LOG_ERR("Unable to add/update hop-by-hop extension header: incorrect instance\n"); LOG_ERR("Unable to add/update hop-by-hop extension header: incorrect instance\n");
return 0; /* Drop */ return 0; /* Drop */
@ -433,17 +432,17 @@ update_hbh_header(void)
LOG_INFO("Updating RPL option\n"); LOG_INFO("Updating RPL option\n");
/* Update sender rank and instance, will update flags next */ /* Update sender rank and instance, will update flags next */
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); rpl_opt->senderrank = UIP_HTONS(instance->current_dag->rank);
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = instance->instance_id; rpl_opt->instance = instance->instance_id;
if(RPL_IS_STORING(instance)) { /* In non-storing mode, downwards traffic does not have the HBH option */ if(RPL_IS_STORING(instance)) { /* In non-storing mode, downwards traffic does not have the HBH option */
/* Check the direction of the down flag, as per Section 11.2.2.3, /* 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 which states that if a packet is going down it should in
general not go back up again. If this happens, a general not go back up again. If this happens, a
RPL_HDR_OPT_FWD_ERR should be flagged. */ RPL_HDR_OPT_FWD_ERR should be flagged. */
if((UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags & RPL_HDR_OPT_DOWN)) { if((rpl_opt->flags & RPL_HDR_OPT_DOWN)) {
if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) {
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags |= RPL_HDR_OPT_FWD_ERR; rpl_opt->flags |= RPL_HDR_OPT_FWD_ERR;
LOG_WARN("RPL forwarding error\n"); LOG_WARN("RPL forwarding error\n");
/* We should send back the packet to the originating parent, /* We should send back the packet to the originating parent,
but it is not feasible yet, so we send a No-Path DAO instead */ but it is not feasible yet, so we send a No-Path DAO instead */
@ -462,11 +461,11 @@ update_hbh_header(void)
if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) {
/* No route was found, so this packet will go towards the RPL /* No route was found, so this packet will go towards the RPL
root. If so, we should not set the down flag. */ root. If so, we should not set the down flag. */
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags &= ~RPL_HDR_OPT_DOWN; rpl_opt->flags &= ~RPL_HDR_OPT_DOWN;
LOG_DBG("RPL option going up\n"); LOG_DBG("RPL option going up\n");
} else { } else {
/* A DAO route was found so we set the down flag. */ /* A DAO route was found so we set the down flag. */
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags |= RPL_HDR_OPT_DOWN; rpl_opt->flags |= RPL_HDR_OPT_DOWN;
LOG_DBG("RPL option going down\n"); LOG_DBG("RPL option going down\n");
} }
} }
@ -479,7 +478,8 @@ update_hbh_header(void)
static int static int
insert_hbh_header(const rpl_instance_t *instance) insert_hbh_header(const rpl_instance_t *instance)
{ {
int opt_offset = 2; struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0);
struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(2));
/* Insert hop-by-hop header */ /* Insert hop-by-hop header */
LOG_DBG("Creating hop-by-hop option\n"); LOG_DBG("Creating hop-by-hop option\n");
@ -493,16 +493,16 @@ insert_hbh_header(const rpl_instance_t *instance)
memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN); memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN);
/* Insert HBH header (as first ext header) */ /* Insert HBH header (as first ext header) */
UIP_HBHO_BUF(0)->next = UIP_IP_BUF->proto; hbh_hdr->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_HBHO; UIP_IP_BUF->proto = UIP_PROTO_HBHO;
/* Initialize HBH option */ /* Initialize HBH option */
UIP_HBHO_BUF(0)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; hbh_hdr->len = (RPL_HOP_BY_HOP_LEN - 8) / 8;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; rpl_opt->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len = RPL_HDR_OPT_LEN; rpl_opt->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags = 0; rpl_opt->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(instance->current_dag->rank); rpl_opt->senderrank = UIP_HTONS(instance->current_dag->rank);
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = instance->instance_id; rpl_opt->instance = instance->instance_id;
uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN);
uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN);

View File

@ -275,7 +275,7 @@ rpl_dag_t *rpl_get_dag(const uip_ipaddr_t *addr);
rpl_dag_t *rpl_get_any_dag(void); rpl_dag_t *rpl_get_any_dag(void);
rpl_instance_t *rpl_get_instance(uint8_t instance_id); rpl_instance_t *rpl_get_instance(uint8_t instance_id);
int rpl_ext_header_update(void); int rpl_ext_header_update(void);
int rpl_ext_header_hbh_update(int, int); int rpl_ext_header_hbh_update(uint8_t *, int);
void rpl_insert_header(void); void rpl_insert_header(void);
void rpl_ext_header_remove(void); void rpl_ext_header_remove(void);
const struct link_stats *rpl_get_parent_link_stats(rpl_parent_t *p); const struct link_stats *rpl_get_parent_link_stats(rpl_parent_t *p);

View File

@ -299,7 +299,7 @@ insert_srh_header(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
rpl_ext_header_hbh_update(int ext_offset, int opt_offset) rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset)
{ {
int down; int down;
int rank_error_signaled; int rank_error_signaled;
@ -307,32 +307,31 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset)
uint16_t sender_rank; uint16_t sender_rank;
uint8_t sender_closer; uint8_t sender_closer;
rpl_nbr_t *sender; rpl_nbr_t *sender;
uint8_t opt_type = UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_type; struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)ext_buf;
uint8_t opt_len = UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->opt_len; struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(ext_buf + opt_offset);
if(UIP_HBHO_BUF(ext_offset)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| opt_type != UIP_EXT_HDR_OPT_RPL || rpl_opt->opt_type != UIP_EXT_HDR_OPT_RPL
|| opt_len != RPL_HDR_OPT_LEN) { || rpl_opt->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("hop-by-hop extension header has wrong size or type (%u %u %u)\n", LOG_ERR("hop-by-hop extension header has wrong size or type (%u %u %u)\n",
UIP_HBHO_BUF(ext_offset)->len, opt_type, opt_len); hbh_hdr->len, rpl_opt->opt_type, rpl_opt->opt_len);
return 0; /* Drop */ return 0; /* Drop */
} }
if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance) { if(!curr_instance.used || curr_instance.instance_id != rpl_opt->instance) {
LOG_ERR("unknown instance: %u\n", LOG_ERR("unknown instance: %u\n", rpl_opt->instance);
UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->instance);
return 0; /* Drop */ return 0; /* Drop */
} }
if(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_FWD_ERR) { if(rpl_opt->flags & RPL_HDR_OPT_FWD_ERR) {
LOG_ERR("forward error!\n"); LOG_ERR("forward error!\n");
return 0; /* Drop */ return 0; /* Drop */
} }
down = (UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_DOWN) ? 1 : 0; down = (rpl_opt->flags & RPL_HDR_OPT_DOWN) ? 1 : 0;
sender_rank = UIP_HTONS(UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->senderrank); sender_rank = UIP_HTONS(rpl_opt->senderrank);
sender = nbr_table_get_from_lladdr(rpl_neighbors, packetbuf_addr(PACKETBUF_ADDR_SENDER)); sender = nbr_table_get_from_lladdr(rpl_neighbors, packetbuf_addr(PACKETBUF_ADDR_SENDER));
rank_error_signaled = (UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0; rank_error_signaled = (rpl_opt->flags & RPL_HDR_OPT_RANK_ERR) ? 1 : 0;
sender_closer = sender_rank < curr_instance.dag.rank; sender_closer = sender_rank < curr_instance.dag.rank;
loop_detected = (down && !sender_closer) || (!down && sender_closer); loop_detected = (down && !sender_closer) || (!down && sender_closer);
@ -346,7 +345,7 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset)
if(loop_detected) { if(loop_detected) {
/* Set forward error flag */ /* Set forward error flag */
UIP_EXT_HDR_OPT_RPL_BUF(ext_offset, opt_offset)->flags |= RPL_HDR_OPT_RANK_ERR; rpl_opt->flags |= RPL_HDR_OPT_RANK_ERR;
} }
return rpl_process_hbh(sender, sender_rank, loop_detected, rank_error_signaled); return rpl_process_hbh(sender, sender_rank, loop_detected, rank_error_signaled);
@ -358,25 +357,25 @@ rpl_ext_header_hbh_update(int ext_offset, int opt_offset)
static int static int
update_hbh_header(void) update_hbh_header(void)
{ {
int opt_offset = 2; struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0);
struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(2));
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type == UIP_EXT_HDR_OPT_RPL) { if(UIP_IP_BUF->proto == UIP_PROTO_HBHO && rpl_opt->opt_type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_HBHO_BUF(0)->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) if(hbh_hdr->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8)
|| UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len != RPL_HDR_OPT_LEN) { || rpl_opt->opt_len != RPL_HDR_OPT_LEN) {
LOG_ERR("hop-by-hop extension header has wrong size (%u)\n", LOG_ERR("hop-by-hop extension header has wrong size (%u)\n", rpl_opt->opt_len);
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len);
return 0; /* Drop */ return 0; /* Drop */
} }
if(!curr_instance.used || curr_instance.instance_id != UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance) { if(!curr_instance.used || curr_instance.instance_id != rpl_opt->instance) {
LOG_ERR("unable to add/update hop-by-hop extension header: incorrect instance\n"); LOG_ERR("unable to add/update hop-by-hop extension header: incorrect instance\n");
return 0; /* Drop */ return 0; /* Drop */
} }
/* Update sender rank and instance, will update flags next */ /* Update sender rank and instance, will update flags next */
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); rpl_opt->senderrank = UIP_HTONS(curr_instance.dag.rank);
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; rpl_opt->instance = curr_instance.instance_id;
} }
return 1; return 1;
@ -389,7 +388,8 @@ update_hbh_header(void)
static int static int
insert_hbh_header(void) insert_hbh_header(void)
{ {
int opt_offset = 2; struct uip_hbho_hdr *hbh_hdr = (struct uip_hbho_hdr *)UIP_IP_PAYLOAD(0);
struct uip_ext_hdr_opt_rpl *rpl_opt = (struct uip_ext_hdr_opt_rpl *)(UIP_IP_PAYLOAD(2));
/* Insert hop-by-hop header */ /* Insert hop-by-hop header */
LOG_INFO("creating hop-by-hop option\n"); LOG_INFO("creating hop-by-hop option\n");
@ -403,16 +403,16 @@ insert_hbh_header(void)
memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN); memset(UIP_IP_PAYLOAD(0), 0, RPL_HOP_BY_HOP_LEN);
/* Insert HBH header (as first ext header) */ /* Insert HBH header (as first ext header) */
UIP_HBHO_BUF(0)->next = UIP_IP_BUF->proto; hbh_hdr->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_HBHO; UIP_IP_BUF->proto = UIP_PROTO_HBHO;
/* Initialize HBH option */ /* Initialize HBH option */
UIP_HBHO_BUF(0)->len = (RPL_HOP_BY_HOP_LEN - 8) / 8; hbh_hdr->len = (RPL_HOP_BY_HOP_LEN - 8) / 8;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_type = UIP_EXT_HDR_OPT_RPL; rpl_opt->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->opt_len = RPL_HDR_OPT_LEN; rpl_opt->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->flags = 0; rpl_opt->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->senderrank = UIP_HTONS(curr_instance.dag.rank); rpl_opt->senderrank = UIP_HTONS(curr_instance.dag.rank);
UIP_EXT_HDR_OPT_RPL_BUF(0, opt_offset)->instance = curr_instance.instance_id; rpl_opt->instance = curr_instance.instance_id;
uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN); uipbuf_add_ext_hdr(RPL_HOP_BY_HOP_LEN);
uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN); uipbuf_set_len_field(UIP_IP_BUF, uip_len - UIP_IPH_LEN);

View File

@ -63,14 +63,13 @@ int rpl_ext_header_srh_update(void);
* Process and update the RPL hop-by-hop extension headers of * Process and update the RPL hop-by-hop extension headers of
* the current uIP packet. * the current uIP packet.
* *
* \param ext_offset The offset within the uIP packet where * \param ext_buf A pointer to the ext header buffer
* extension headers start
* \param opt_offset The offset within the extension header where * \param opt_offset The offset within the extension header where
* the option starts * the option starts
* \return 1 in case the packet is valid and to be processed further, * \return 1 in case the packet is valid and to be processed further,
* 0 in case the packet must be dropped. * 0 in case the packet must be dropped.
*/ */
int rpl_ext_header_hbh_update(int ext_offset, int opt_offset); int rpl_ext_header_hbh_update(uint8_t *ext_buf, int opt_offset);
/** /**
* Adds/updates all RPL extension headers to current uIP packet. * Adds/updates all RPL extension headers to current uIP packet.