Removed need for global uip_ext_opt_offset

This commit is contained in:
Simon Duquennoy 2018-10-17 23:35:58 +02:00
parent d4bc09e002
commit 4018b31123
1 changed files with 11 additions and 13 deletions

View File

@ -130,8 +130,6 @@ uint8_t uip_ext_bitmap = 0;
* a header * a header
*/ */
uint8_t uip_ext_len = 0; uint8_t uip_ext_len = 0;
/** \brief length of the header options read */
uint8_t uip_ext_opt_offset = 0;
/** \brief The final protocol after IPv6 extension headers: /** \brief The final protocol after IPv6 extension headers:
* UIP_PROTO_TCP, UIP_PROTO_UDP or UIP_PROTO_ICMP6 */ * UIP_PROTO_TCP, UIP_PROTO_UDP or UIP_PROTO_ICMP6 */
uint8_t uip_last_proto = 0; uint8_t uip_last_proto = 0;
@ -839,9 +837,9 @@ ext_hdr_options_process(void)
* 8 bytes, excluding the first 8 bytes * 8 bytes, excluding the first 8 bytes
* length field in an option : the length of data in the option * length field in an option : the length of data in the option
*/ */
uip_ext_opt_offset = 2; uint8_t ext_opt_offset = 2;
while(uip_ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) { while(ext_opt_offset < ((UIP_EXT_BUF(uip_ext_len)->len << 3) + 8)) {
switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type) { switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type) {
/* /*
* for now we do not support any options except padding ones * for now we do not support any options except padding ones
* PAD1 does not make sense as the header must be 8bytes aligned, * PAD1 does not make sense as the header must be 8bytes aligned,
@ -849,11 +847,11 @@ ext_hdr_options_process(void)
*/ */
case UIP_EXT_HDR_OPT_PAD1: case UIP_EXT_HDR_OPT_PAD1:
LOG_DBG("Processing PAD1 option\n"); LOG_DBG("Processing PAD1 option\n");
uip_ext_opt_offset += 1; ext_opt_offset += 1;
break; break;
case UIP_EXT_HDR_OPT_PADN: case UIP_EXT_HDR_OPT_PADN:
LOG_DBG("Processing PADN option\n"); LOG_DBG("Processing PADN option\n");
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(uip_ext_len, uip_ext_opt_offset)->opt_len + 2; ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF(uip_ext_len, ext_opt_offset)->opt_len + 2;
break; break;
case UIP_EXT_HDR_OPT_RPL: case UIP_EXT_HDR_OPT_RPL:
/* Fixes situation when a node that is not using RPL /* Fixes situation when a node that is not using RPL
@ -864,11 +862,11 @@ ext_hdr_options_process(void)
* Using this fix, the header is ignored, and the next header (if * Using this fix, the header is ignored, and the next header (if
* present) is processed. * present) is processed.
*/ */
if(!NETSTACK_ROUTING.ext_header_hbh_update(uip_ext_len, uip_ext_opt_offset)) { if(!NETSTACK_ROUTING.ext_header_hbh_update(uip_ext_len, ext_opt_offset)) {
LOG_ERR("RPL Option Error: Dropping Packet\n"); LOG_ERR("RPL Option Error: Dropping Packet\n");
return 1; return 1;
} }
uip_ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len) + 2; ext_opt_offset += (UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->len) + 2;
return 0; return 0;
default: default:
/* /*
@ -884,8 +882,8 @@ ext_hdr_options_process(void)
* Problem, Code 2, message to the packet's Source Address, * Problem, Code 2, message to the packet's Source Address,
* pointing to the unrecognized Option Type. * pointing to the unrecognized Option Type.
*/ */
LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type); LOG_DBG("MSB %x\n", UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type);
switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->type & 0xC0) { switch(UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->type & 0xC0) {
case 0: case 0:
break; break;
case 0x40: case 0x40:
@ -896,11 +894,11 @@ ext_hdr_options_process(void)
} }
case 0x80: case 0x80:
uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, uip_icmp6_error_output(ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION,
(uint32_t)UIP_IPH_LEN + uip_ext_len + uip_ext_opt_offset); (uint32_t)UIP_IPH_LEN + uip_ext_len + ext_opt_offset);
return 2; return 2;
} }
/* in the cases were we did not discard, update ext_opt* */ /* in the cases were we did not discard, update ext_opt* */
uip_ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, uip_ext_opt_offset)->len + 2; ext_opt_offset += UIP_EXT_HDR_OPT_BUF(uip_ext_len, ext_opt_offset)->len + 2;
break; break;
} }
} }