- 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:
Vincent Brillault 2011-07-11 16:53:02 +02:00
parent dc9cbe647d
commit f4b804ed9f
4 changed files with 157 additions and 34 deletions

View file

@ -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) {

View file

@ -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
@ -78,7 +89,7 @@ uip_icmp6_echo_request_input(void)
PRINTF("to"); PRINTF("to");
PRINT6ADDR(&UIP_IP_BUF->destipaddr); PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n"); PRINTF("\n");
/* IP header */ /* IP header */
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit; UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
@ -92,30 +103,54 @@ uip_icmp6_echo_request_input(void)
} }
if(uip_ext_len > 0) { if(uip_ext_len > 0) {
/* If there were extension headers*/ #if UIP_CONF_IPV6_RPL
UIP_IP_BUF->proto = UIP_PROTO_ICMP6; if ((temp_ext_len=rpl_invert_header())) {
uip_len -= uip_ext_len; /* If there were other extension headers*/
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); if (uip_ext_len != temp_ext_len) {
/* move the echo request payload (starting after the icmp header) uip_len -= (uip_ext_len - temp_ext_len);
* to the new location in the reply. UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
* The shift is equal to the length of the extension headers present UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
* Note: UIP_ICMP_BUF still points to the echo request at this stage /* move the echo request payload (starting after the icmp header)
*/ * to the new location in the reply.
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len, * The shift is equal to the length of the remaining extension headers present
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN, * Note: UIP_ICMP_BUF still points to the echo request at this stage
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN)); */
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*/
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
uip_len -= uip_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 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,
(uint8_t *)UIP_ICMP_BUF + 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;
UIP_ICMP_BUF->icmpchksum = 0; UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
PRINTF("Sending Echo Reply to"); PRINTF("Sending Echo Reply to");
PRINT6ADDR(&UIP_IP_BUF->destipaddr); PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("from"); PRINTF("from");
@ -127,29 +162,45 @@ 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_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){ if (uip_ext_len) {
uip_len = 0; if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
return; uip_len = 0;
return;
}
} else {
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
uip_len = 0;
return;
}
} }
/* remember data of original packet before shifting */ #if UIP_CONF_IPV6_RPL
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr); uip_ext_len = rpl_invert_header();
#else /* UIP_CONF_IPV6_RPL */
uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN; uip_ext_len = 0;
#endif /* UIP_CONF_IPV6_RPL */
if(uip_len > UIP_LINK_MTU)
uip_len = UIP_LINK_MTU;
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + UIP_ICMP6_ERROR_LEN, /* remember data of original packet before shifting */
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - UIP_ICMP6_ERROR_LEN); uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN;
if(uip_len > UIP_LINK_MTU)
uip_len = UIP_LINK_MTU;
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_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;
UIP_IP_BUF->proto = UIP_PROTO_ICMP6; if (uip_ext_len) {
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
} else {
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
@ -158,7 +209,7 @@ uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
uip_len = 0; uip_len = 0;
return; return;
} }
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr); uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
if(uip_is_addr_mcast(&tmp_ipaddr)){ if(uip_is_addr_mcast(&tmp_ipaddr)){
@ -176,7 +227,7 @@ uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr); uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
#endif #endif
} }
UIP_ICMP_BUF->type = type; UIP_ICMP_BUF->type = type;
UIP_ICMP_BUF->icode = code; UIP_ICMP_BUF->icode = code;
UIP_ICMP6_ERROR_BUF->param = uip_htonl(param); UIP_ICMP6_ERROR_BUF->param = uip_htonl(param);

View file

@ -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 */
/** @} */ /** @} */
/** @{ */ /** @{ */

View file

@ -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