Add support of RPL Option (http://tools.ietf.org/html/draft-ietf-6man-rpl-option-03):
- Auto-insersion when forwarding messages - Delete messages with 2 rank errors Not supported yet : - Routing depending on InstanceID - DAO inconsistency loop recovery - Full UDP or TCP support (Bugs in µIPv6) - Real Option Type (TBD by IANA)
This commit is contained in:
parent
dc9cbe647d
commit
f4b804ed9f
|
@ -80,7 +80,8 @@ extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
|
||||||
#endif
|
#endif
|
||||||
#if UIP_CONF_IPV6_RPL
|
#if UIP_CONF_IPV6_RPL
|
||||||
void rpl_init(void);
|
void rpl_init(void);
|
||||||
#endif
|
int rpl_update_header_final(uip_ipaddr_t *addr);
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
process_event_t tcpip_event;
|
process_event_t tcpip_event;
|
||||||
#if UIP_CONF_ICMP6
|
#if UIP_CONF_ICMP6
|
||||||
process_event_t tcpip_icmp6_event;
|
process_event_t tcpip_icmp6_event;
|
||||||
|
@ -590,6 +591,12 @@ tcpip_ipv6_output(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* end of next hop determination */
|
/* end of next hop determination */
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
if (rpl_update_header_final(nexthop)) {
|
||||||
|
uip_len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
if((nbr = uip_ds6_nbr_lookup(nexthop)) == NULL) {
|
if((nbr = uip_ds6_nbr_lookup(nexthop)) == NULL) {
|
||||||
// printf("add1 %d\n", nexthop->u8[15]);
|
// printf("add1 %d\n", nexthop->u8[15]);
|
||||||
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE)) == NULL) {
|
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE)) == NULL) {
|
||||||
|
|
|
@ -60,14 +60,25 @@
|
||||||
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
||||||
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||||
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
||||||
|
#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
/** \brief temporary IP address */
|
/** \brief temporary IP address */
|
||||||
static uip_ipaddr_t tmp_ipaddr;
|
static uip_ipaddr_t tmp_ipaddr;
|
||||||
|
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
int rpl_invert_header(void);
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uip_icmp6_echo_request_input(void)
|
uip_icmp6_echo_request_input(void)
|
||||||
{
|
{
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
u8_t temp_ext_len;
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
/*
|
/*
|
||||||
* we send an echo reply. It is trivial if there was no extension
|
* we send an echo reply. It is trivial if there was no extension
|
||||||
* headers in the request otherwise we need to remove the extension
|
* headers in the request otherwise we need to remove the extension
|
||||||
|
@ -92,6 +103,26 @@ uip_icmp6_echo_request_input(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uip_ext_len > 0) {
|
if(uip_ext_len > 0) {
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
if ((temp_ext_len=rpl_invert_header())) {
|
||||||
|
/* If there were other extension headers*/
|
||||||
|
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
|
||||||
|
if (uip_ext_len != temp_ext_len) {
|
||||||
|
uip_len -= (uip_ext_len - temp_ext_len);
|
||||||
|
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
|
||||||
|
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
|
||||||
|
/* move the echo request payload (starting after the icmp header)
|
||||||
|
* to the new location in the reply.
|
||||||
|
* The shift is equal to the length of the remaining extension headers present
|
||||||
|
* Note: UIP_ICMP_BUF still points to the echo request at this stage
|
||||||
|
*/
|
||||||
|
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - (uip_ext_len - temp_ext_len),
|
||||||
|
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
|
||||||
|
(uip_len - UIP_IPH_LEN - temp_ext_len - UIP_ICMPH_LEN));
|
||||||
|
}
|
||||||
|
uip_ext_len=temp_ext_len;
|
||||||
|
} else {
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
/* If there were extension headers*/
|
/* If there were extension headers*/
|
||||||
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
||||||
uip_len -= uip_ext_len;
|
uip_len -= uip_ext_len;
|
||||||
|
@ -105,11 +136,15 @@ uip_icmp6_echo_request_input(void)
|
||||||
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
|
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
|
||||||
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
|
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
|
||||||
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
|
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
|
||||||
|
uip_ext_len = 0;
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
}
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
}
|
}
|
||||||
/* Below is important for the correctness of UIP_ICMP_BUF and the
|
/* Below is important for the correctness of UIP_ICMP_BUF and the
|
||||||
* checksum
|
* checksum
|
||||||
*/
|
*/
|
||||||
uip_ext_len = 0;
|
|
||||||
/* Note: now UIP_ICMP_BUF points to the beginning of the echo reply */
|
/* Note: now UIP_ICMP_BUF points to the beginning of the echo reply */
|
||||||
UIP_ICMP_BUF->type = ICMP6_ECHO_REPLY;
|
UIP_ICMP_BUF->type = ICMP6_ECHO_REPLY;
|
||||||
UIP_ICMP_BUF->icode = 0;
|
UIP_ICMP_BUF->icode = 0;
|
||||||
|
@ -127,13 +162,25 @@ uip_icmp6_echo_request_input(void)
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
|
uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
|
||||||
uip_ext_len = 0;
|
|
||||||
|
|
||||||
/* check if originating packet is not an ICMP error*/
|
/* check if originating packet is not an ICMP error*/
|
||||||
|
if (uip_ext_len) {
|
||||||
|
if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
|
||||||
|
uip_len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
|
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
|
||||||
uip_len = 0;
|
uip_len = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
uip_ext_len = rpl_invert_header();
|
||||||
|
#else /* UIP_CONF_IPV6_RPL */
|
||||||
|
uip_ext_len = 0;
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
/* remember data of original packet before shifting */
|
/* remember data of original packet before shifting */
|
||||||
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
|
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
|
||||||
|
@ -143,13 +190,17 @@ uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
|
||||||
if(uip_len > UIP_LINK_MTU)
|
if(uip_len > UIP_LINK_MTU)
|
||||||
uip_len = UIP_LINK_MTU;
|
uip_len = UIP_LINK_MTU;
|
||||||
|
|
||||||
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + UIP_ICMP6_ERROR_LEN,
|
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN,
|
||||||
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - UIP_ICMP6_ERROR_LEN);
|
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN);
|
||||||
|
|
||||||
UIP_IP_BUF->vtc = 0x60;
|
UIP_IP_BUF->vtc = 0x60;
|
||||||
UIP_IP_BUF->tcflow = 0;
|
UIP_IP_BUF->tcflow = 0;
|
||||||
UIP_IP_BUF->flow = 0;
|
UIP_IP_BUF->flow = 0;
|
||||||
|
if (uip_ext_len) {
|
||||||
|
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
|
||||||
|
} else {
|
||||||
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
|
||||||
|
}
|
||||||
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
|
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
|
||||||
|
|
||||||
/* the source should not be unspecified nor multicast, the check for
|
/* the source should not be unspecified nor multicast, the check for
|
||||||
|
|
|
@ -1770,6 +1770,17 @@ typedef struct uip_ext_hdr_opt_padn {
|
||||||
u8_t opt_len;
|
u8_t opt_len;
|
||||||
} uip_ext_hdr_opt_padn;
|
} uip_ext_hdr_opt_padn;
|
||||||
|
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
/* RPL option */
|
||||||
|
typedef struct uip_ext_hdr_opt_rpl {
|
||||||
|
u8_t opt_type;
|
||||||
|
u8_t opt_len;
|
||||||
|
u8_t flags;
|
||||||
|
u8_t instance;
|
||||||
|
u16_t senderrank;
|
||||||
|
} uip_ext_hdr_opt_rpl;
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
/* TCP header */
|
/* TCP header */
|
||||||
struct uip_tcp_hdr {
|
struct uip_tcp_hdr {
|
||||||
u16_t srcport;
|
u16_t srcport;
|
||||||
|
@ -1840,6 +1851,10 @@ struct uip_udp_hdr {
|
||||||
/** \brief Destination and Hop By Hop extension headers option types */
|
/** \brief Destination and Hop By Hop extension headers option types */
|
||||||
#define UIP_EXT_HDR_OPT_PAD1 0
|
#define UIP_EXT_HDR_OPT_PAD1 0
|
||||||
#define UIP_EXT_HDR_OPT_PADN 1
|
#define UIP_EXT_HDR_OPT_PADN 1
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
#define UIP_EXT_HDR_OPT_RPL 0x63
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/** @{ */
|
/** @{ */
|
||||||
|
|
|
@ -96,6 +96,8 @@
|
||||||
|
|
||||||
#if UIP_CONF_IPV6_RPL
|
#if UIP_CONF_IPV6_RPL
|
||||||
void uip_rpl_input(void);
|
void uip_rpl_input(void);
|
||||||
|
void rpl_update_header_empty(void);
|
||||||
|
int rpl_verify_header(int uip_ext_opt_offset);
|
||||||
#endif /* UIP_CONF_IPV6_RPL */
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
#if UIP_LOGGING == 1
|
#if UIP_LOGGING == 1
|
||||||
|
@ -163,6 +165,9 @@ u8_t uip_ext_opt_offset = 0;
|
||||||
#define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len])
|
#define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_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_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_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
|
||||||
/** @} */
|
/** @} */
|
||||||
/** \name Buffer variables
|
/** \name Buffer variables
|
||||||
|
@ -827,6 +832,16 @@ ext_hdr_options_process() {
|
||||||
PRINTF("Processing PADN option\n");
|
PRINTF("Processing PADN option\n");
|
||||||
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2;
|
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2;
|
||||||
break;
|
break;
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
case UIP_EXT_HDR_OPT_RPL:
|
||||||
|
PRINTF("Processing RPL option\n");
|
||||||
|
if (rpl_verify_header(uip_ext_opt_offset)) {
|
||||||
|
PRINTF("RPL Option Error : Dropping Packet");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
uip_ext_opt_offset += (UIP_EXT_HDR_OPT_RPL_BUF->opt_len) + 2;
|
||||||
|
return 0;
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
* check the two highest order bits of the option
|
* check the two highest order bits of the option
|
||||||
|
@ -1078,6 +1093,35 @@ uip_process(u8_t flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UIP_CONF_ROUTER
|
#if UIP_CONF_ROUTER
|
||||||
|
/*
|
||||||
|
* Next header field processing. In IPv6, we can have extension headers,
|
||||||
|
* if present, the Hop-by-Hop Option must be processed before forwarding
|
||||||
|
* the packet.
|
||||||
|
*/
|
||||||
|
uip_next_hdr = &UIP_IP_BUF->proto;
|
||||||
|
uip_ext_len = 0;
|
||||||
|
uip_ext_bitmap = 0;
|
||||||
|
if (*uip_next_hdr == UIP_PROTO_HBHO) {
|
||||||
|
#if UIP_CONF_IPV6_CHECKS
|
||||||
|
uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_HBHO;
|
||||||
|
#endif /*UIP_CONF_IPV6_CHECKS*/
|
||||||
|
switch(ext_hdr_options_process()) {
|
||||||
|
case 0:
|
||||||
|
/*continue*/
|
||||||
|
uip_next_hdr = &UIP_EXT_BUF->next;
|
||||||
|
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
/*silently discard*/
|
||||||
|
goto drop;
|
||||||
|
case 2:
|
||||||
|
/* send icmp error message (created in ext_hdr_options_process)
|
||||||
|
* and discard*/
|
||||||
|
goto send;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TBD Some Parameter problem messages */
|
/* TBD Some Parameter problem messages */
|
||||||
if(!uip_ds6_is_my_addr(&UIP_IP_BUF->destipaddr) &&
|
if(!uip_ds6_is_my_addr(&UIP_IP_BUF->destipaddr) &&
|
||||||
!uip_ds6_is_my_maddr(&UIP_IP_BUF->destipaddr)) {
|
!uip_ds6_is_my_maddr(&UIP_IP_BUF->destipaddr)) {
|
||||||
|
@ -1101,6 +1145,11 @@ uip_process(u8_t flag)
|
||||||
UIP_STAT(++uip_stat.ip.drop);
|
UIP_STAT(++uip_stat.ip.drop);
|
||||||
goto send;
|
goto send;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UIP_CONF_IPV6_RPL
|
||||||
|
rpl_update_header_empty();
|
||||||
|
#endif /* UIP_CONF_IPV6_RPL */
|
||||||
|
|
||||||
UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1;
|
UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1;
|
||||||
PRINTF("Forwarding packet to ");
|
PRINTF("Forwarding packet to ");
|
||||||
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
|
||||||
|
@ -1131,7 +1180,6 @@ uip_process(u8_t flag)
|
||||||
UIP_STAT(++uip_stat.ip.drop);
|
UIP_STAT(++uip_stat.ip.drop);
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
#endif /* UIP_CONF_ROUTER */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Next header field processing. In IPv6, we can have extension headers,
|
* Next header field processing. In IPv6, we can have extension headers,
|
||||||
|
@ -1140,6 +1188,8 @@ uip_process(u8_t flag)
|
||||||
uip_next_hdr = &UIP_IP_BUF->proto;
|
uip_next_hdr = &UIP_IP_BUF->proto;
|
||||||
uip_ext_len = 0;
|
uip_ext_len = 0;
|
||||||
uip_ext_bitmap = 0;
|
uip_ext_bitmap = 0;
|
||||||
|
#endif /* UIP_CONF_ROUTER */
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
switch(*uip_next_hdr){
|
switch(*uip_next_hdr){
|
||||||
#if UIP_TCP
|
#if UIP_TCP
|
||||||
|
|
Loading…
Reference in a new issue