mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
Refactored header management.
This commit is contained in:
parent
5c0100c979
commit
ac869185c0
@ -36,7 +36,10 @@
|
||||
* \file
|
||||
* Management of extension headers for ContikiRPL.
|
||||
*
|
||||
* \author Vincent Brillault <vincent.brillault@imag.fr>
|
||||
* \author Vincent Brillault <vincent.brillault@imag.fr>,
|
||||
* Joakim Eriksson <joakime@sics.se>,
|
||||
* Niclas Finne <nfi@sics.se>,
|
||||
* Nicolas Tsiftes <nvt@sics.se>.
|
||||
*/
|
||||
|
||||
#include "net/uip.h"
|
||||
@ -54,7 +57,7 @@
|
||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_OP_BY_OP_LEN])
|
||||
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
|
||||
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
||||
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
||||
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
||||
@ -120,13 +123,35 @@ rpl_verify_header(int uip_ext_opt_offset)
|
||||
return 0;
|
||||
}
|
||||
/************************************************************************/
|
||||
static void
|
||||
set_rpl_opt(unsigned uip_ext_opt_offset)
|
||||
{
|
||||
uint8_t temp_len;
|
||||
|
||||
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
|
||||
memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN);
|
||||
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
|
||||
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
|
||||
UIP_HBHO_BUF->len = RPL_HOP_BY_HOP_LEN - 8;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->flags = 0 ;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->instance = 0 ;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = 0 ;
|
||||
uip_len += RPL_HOP_BY_HOP_LEN;
|
||||
temp_len = UIP_IP_BUF->len[1];
|
||||
UIP_IP_BUF->len[1] += UIP_HBHO_BUF->len + 8;
|
||||
if(UIP_IP_BUF->len[1] < temp_len) {
|
||||
UIP_IP_BUF->len[0]++;
|
||||
}
|
||||
}
|
||||
/************************************************************************/
|
||||
void
|
||||
rpl_update_header_empty(void)
|
||||
{
|
||||
rpl_instance_t *instance;
|
||||
int uip_ext_opt_offset;
|
||||
int last_uip_ext_len;
|
||||
u8_t temp_len;
|
||||
|
||||
last_uip_ext_len = uip_ext_len;
|
||||
uip_ext_len = 0;
|
||||
@ -136,7 +161,7 @@ rpl_update_header_empty(void)
|
||||
|
||||
switch(UIP_IP_BUF->proto) {
|
||||
case UIP_PROTO_HBHO:
|
||||
if(UIP_HBHO_BUF->len != RPL_OP_BY_OP_LEN - 8) {
|
||||
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;
|
||||
@ -149,28 +174,13 @@ rpl_update_header_empty(void)
|
||||
break;
|
||||
default:
|
||||
PRINTF("RPL: No hop-by-hop option found, creating it\n");
|
||||
if(uip_len + RPL_OP_BY_OP_LEN > UIP_LINK_MTU) {
|
||||
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_LINK_MTU) {
|
||||
PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n");
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
return;
|
||||
}
|
||||
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
|
||||
memset(UIP_HBHO_BUF, 0, RPL_OP_BY_OP_LEN);
|
||||
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
|
||||
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
|
||||
UIP_HBHO_BUF->len = RPL_OP_BY_OP_LEN - 8;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->flags = 0;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->instance = 0;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = 0;
|
||||
uip_len += RPL_OP_BY_OP_LEN;
|
||||
temp_len = UIP_IP_BUF->len[1];
|
||||
UIP_IP_BUF->len[1] += UIP_HBHO_BUF->len + 8;
|
||||
if(UIP_IP_BUF->len[1] < temp_len) {
|
||||
UIP_IP_BUF->len[0]++;
|
||||
}
|
||||
uip_ext_len = last_uip_ext_len + RPL_OP_BY_OP_LEN;
|
||||
set_rpl_opt(uip_ext_opt_offset);
|
||||
uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -199,7 +209,7 @@ rpl_update_header_final(uip_ipaddr_t *addr)
|
||||
uip_ext_opt_offset = 2;
|
||||
|
||||
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO) {
|
||||
if(UIP_HBHO_BUF->len != RPL_OP_BY_OP_LEN - 8) {
|
||||
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 0;
|
||||
@ -225,86 +235,11 @@ rpl_update_header_final(uip_ipaddr_t *addr)
|
||||
return 0;
|
||||
}
|
||||
/************************************************************************/
|
||||
int
|
||||
rpl_add_header(rpl_instance_t *instance, int down)
|
||||
{
|
||||
int uip_ext_opt_offset;
|
||||
int last_uip_ext_len;
|
||||
u8_t temp_len;
|
||||
|
||||
last_uip_ext_len = uip_ext_len;
|
||||
uip_ext_len = 0;
|
||||
uip_ext_opt_offset = 2;
|
||||
|
||||
if(instance == NULL || !instance->used || !instance->current_dag->joined) {
|
||||
PRINTF("Unable to add RPL hop-by-hop extension header: incorrect instance\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_OP_BY_OP_LEN - 8) {
|
||||
PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n");
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PRINTF("RPL: No hop-by-hop option found, creating it\n");
|
||||
if(uip_len + RPL_OP_BY_OP_LEN >UIP_LINK_MTU) {
|
||||
PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n");
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
return 0;
|
||||
}
|
||||
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
|
||||
memset(UIP_HBHO_BUF, 0, RPL_OP_BY_OP_LEN);
|
||||
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
|
||||
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
|
||||
UIP_HBHO_BUF->len = RPL_OP_BY_OP_LEN - 8;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->flags = RPL_HDR_OPT_DOWN & (down << RPL_HDR_OPT_DOWN_SHIFT);
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = instance->current_dag->rank;
|
||||
uip_len += RPL_OP_BY_OP_LEN;
|
||||
temp_len = UIP_IP_BUF->len[1];
|
||||
UIP_IP_BUF->len[1] += UIP_HBHO_BUF->len + 8;
|
||||
if(UIP_IP_BUF->len[1] < temp_len) {
|
||||
UIP_IP_BUF->len[0]++;
|
||||
}
|
||||
uip_ext_len = last_uip_ext_len + RPL_OP_BY_OP_LEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
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->opt_type = UIP_EXT_HDR_OPT_RPL;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->flags = RPL_HDR_OPT_DOWN&(down<<RPL_HDR_OPT_DOWN_SHIFT);
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = instance->current_dag->rank;
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
return 1;
|
||||
default:
|
||||
PRINTF("RPL: Multi Hop-by-hop options not implemented\n");
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/************************************************************************/
|
||||
int
|
||||
rpl_add_header_root(void)
|
||||
{
|
||||
return rpl_add_header(default_instance, 1);
|
||||
}
|
||||
/************************************************************************/
|
||||
void
|
||||
rpl_remove_header(void)
|
||||
{
|
||||
int last_uip_ext_len;
|
||||
u8_t temp_len;
|
||||
uint8_t temp_len;
|
||||
|
||||
last_uip_ext_len = uip_ext_len;
|
||||
uip_ext_len = 0;
|
||||
@ -327,11 +262,11 @@ rpl_remove_header(void)
|
||||
}
|
||||
}
|
||||
/************************************************************************/
|
||||
u8_t
|
||||
uint8_t
|
||||
rpl_invert_header(void)
|
||||
{
|
||||
u8_t uip_ext_opt_offset;
|
||||
u8_t last_uip_ext_len;
|
||||
uint8_t uip_ext_opt_offset;
|
||||
uint8_t last_uip_ext_len;
|
||||
|
||||
last_uip_ext_len = uip_ext_len;
|
||||
uip_ext_len = 0;
|
||||
@ -353,7 +288,7 @@ rpl_invert_header(void)
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->flags ^= RPL_HDR_OPT_DOWN;
|
||||
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank;
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
return RPL_OP_BY_OP_LEN;
|
||||
return RPL_HOP_BY_HOP_LEN;
|
||||
default:
|
||||
PRINTF("RPL: Multi Hop-by-hop options not implemented\n");
|
||||
uip_ext_len = last_uip_ext_len;
|
||||
|
@ -94,6 +94,16 @@
|
||||
#define RPL_DAO_K_FLAG 0x80 /* DAO ACK requested */
|
||||
#define RPL_DAO_D_FLAG 0x40 /* DODAG ID present */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* RPL IPv6 extension header option. */
|
||||
#define RPL_HDR_OPT_LEN 4
|
||||
#define RPL_HOP_BY_HOP_LEN (RPL_HDR_OPT_LEN + 2 + 2)
|
||||
#define RPL_HDR_OPT_DOWN 0x80
|
||||
#define RPL_HDR_OPT_DOWN_SHIFT 7
|
||||
#define RPL_HDR_OPT_RANK_ERR 0x40
|
||||
#define RPL_HDR_OPT_RANK_ERR_SHIFT 6
|
||||
#define RPL_HDR_OPT_FWD_ERR 0x20
|
||||
#define RPL_HDR_OPT_FWD_ERR_SHIFT 5
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Default values for RPL constants and variables. */
|
||||
|
||||
/* The default value for the DAO timer. */
|
||||
@ -250,12 +260,6 @@ void dis_output(uip_ipaddr_t *addr);
|
||||
void dio_output(rpl_instance_t *, uip_ipaddr_t *uc_addr);
|
||||
void dao_output(rpl_parent_t *, uint8_t lifetime);
|
||||
void dao_ack_output(rpl_instance_t *, uip_ipaddr_t *, uint8_t);
|
||||
void uip_rpl_input(void);
|
||||
|
||||
/* RPL Header Option */
|
||||
int rpl_verify_header(int uip_ext_opt_offset);
|
||||
void rpl_update_header_empty();
|
||||
int rpl_update_header_final(uip_ipaddr_t *addr);
|
||||
|
||||
/* RPL logic functions. */
|
||||
void rpl_join_dag(uip_ipaddr_t *from, rpl_dio_t *dio);
|
||||
|
@ -144,17 +144,6 @@ typedef uint16_t rpl_ocp_t;
|
||||
((B > RPL_LOLLIPOP_CIRCULAR_REGION )?\
|
||||
1:\
|
||||
RPL_LOLLIPOP_GREATER_THAN_LOCAL(A,B)))
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* RPL IPv6 extension header option. */
|
||||
#define RPL_HDR_OPT_LEN 4
|
||||
#define RPL_OP_BY_OP_LEN RPL_HDR_OPT_LEN+2+2
|
||||
#define RPL_HDR_OPT_DOWN 0x80
|
||||
#define RPL_HDR_OPT_DOWN_SHIFT 7
|
||||
#define RPL_HDR_OPT_RANK_ERR 0x40
|
||||
#define RPL_HDR_OPT_RANK_ERR_SHIFT 6
|
||||
#define RPL_HDR_OPT_FWD_ERR 0x20
|
||||
#define RPL_HDR_OPT_FWD_ERR_SHIFT 5
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* DAG Metric Container Object Types, to be confirmed by IANA. */
|
||||
#define RPL_DAG_MC_NONE 0 /* Local identifier for empty MC */
|
||||
@ -334,6 +323,7 @@ struct rpl_instance {
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Public RPL functions. */
|
||||
void rpl_init(void);
|
||||
void uip_rpl_input(void);
|
||||
rpl_dag_t *rpl_set_root(uint8_t instance_id, uip_ipaddr_t * dag_id);
|
||||
int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len);
|
||||
int rpl_repair_root(uint8_t instance_id);
|
||||
@ -341,9 +331,10 @@ int rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from);
|
||||
rpl_dag_t *rpl_get_any_dag(void);
|
||||
rpl_dag_t *rpl_get_dodag(uint8_t instance_id, uip_ipaddr_t *dag_id);
|
||||
rpl_instance_t *rpl_get_instance(uint8_t instance_id);
|
||||
int rpl_add_header(rpl_instance_t *instance, int down);
|
||||
int rpl_add_header_root(void);
|
||||
void rpl_update_header_empty(void);
|
||||
int rpl_update_header_final(uip_ipaddr_t *addr);
|
||||
int rpl_verify_header(int);
|
||||
void rpl_remove_header(void);
|
||||
u8_t rpl_invert_header(void);
|
||||
uint8_t rpl_invert_header(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RPL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user