1*5d5fbe79SDavid van Moolenbroek /** 2*5d5fbe79SDavid van Moolenbroek * @file 3*5d5fbe79SDavid van Moolenbroek * 4*5d5fbe79SDavid van Moolenbroek * IPv6 fragmentation and reassembly. 5*5d5fbe79SDavid van Moolenbroek */ 6*5d5fbe79SDavid van Moolenbroek 7*5d5fbe79SDavid van Moolenbroek /* 8*5d5fbe79SDavid van Moolenbroek * Copyright (c) 2010 Inico Technologies Ltd. 9*5d5fbe79SDavid van Moolenbroek * All rights reserved. 10*5d5fbe79SDavid van Moolenbroek * 11*5d5fbe79SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without modification, 12*5d5fbe79SDavid van Moolenbroek * are permitted provided that the following conditions are met: 13*5d5fbe79SDavid van Moolenbroek * 14*5d5fbe79SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright notice, 15*5d5fbe79SDavid van Moolenbroek * this list of conditions and the following disclaimer. 16*5d5fbe79SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright notice, 17*5d5fbe79SDavid van Moolenbroek * this list of conditions and the following disclaimer in the documentation 18*5d5fbe79SDavid van Moolenbroek * and/or other materials provided with the distribution. 19*5d5fbe79SDavid van Moolenbroek * 3. The name of the author may not be used to endorse or promote products 20*5d5fbe79SDavid van Moolenbroek * derived from this software without specific prior written permission. 21*5d5fbe79SDavid van Moolenbroek * 22*5d5fbe79SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23*5d5fbe79SDavid van Moolenbroek * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24*5d5fbe79SDavid van Moolenbroek * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25*5d5fbe79SDavid van Moolenbroek * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26*5d5fbe79SDavid van Moolenbroek * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27*5d5fbe79SDavid van Moolenbroek * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28*5d5fbe79SDavid van Moolenbroek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29*5d5fbe79SDavid van Moolenbroek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30*5d5fbe79SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31*5d5fbe79SDavid van Moolenbroek * OF SUCH DAMAGE. 32*5d5fbe79SDavid van Moolenbroek * 33*5d5fbe79SDavid van Moolenbroek * This file is part of the lwIP TCP/IP stack. 34*5d5fbe79SDavid van Moolenbroek * 35*5d5fbe79SDavid van Moolenbroek * Author: Ivan Delamer <delamer@inicotech.com> 36*5d5fbe79SDavid van Moolenbroek * 37*5d5fbe79SDavid van Moolenbroek * 38*5d5fbe79SDavid van Moolenbroek * Please coordinate changes and requests with Ivan Delamer 39*5d5fbe79SDavid van Moolenbroek * <delamer@inicotech.com> 40*5d5fbe79SDavid van Moolenbroek */ 41*5d5fbe79SDavid van Moolenbroek #ifndef LWIP_HDR_IP6_FRAG_H 42*5d5fbe79SDavid van Moolenbroek #define LWIP_HDR_IP6_FRAG_H 43*5d5fbe79SDavid van Moolenbroek 44*5d5fbe79SDavid van Moolenbroek #include "lwip/opt.h" 45*5d5fbe79SDavid van Moolenbroek #include "lwip/pbuf.h" 46*5d5fbe79SDavid van Moolenbroek #include "lwip/ip6_addr.h" 47*5d5fbe79SDavid van Moolenbroek #include "lwip/ip6.h" 48*5d5fbe79SDavid van Moolenbroek #include "lwip/netif.h" 49*5d5fbe79SDavid van Moolenbroek 50*5d5fbe79SDavid van Moolenbroek #ifdef __cplusplus 51*5d5fbe79SDavid van Moolenbroek extern "C" { 52*5d5fbe79SDavid van Moolenbroek #endif 53*5d5fbe79SDavid van Moolenbroek 54*5d5fbe79SDavid van Moolenbroek 55*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6 && LWIP_IPV6_REASS /* don't build if not configured for use in lwipopts.h */ 56*5d5fbe79SDavid van Moolenbroek 57*5d5fbe79SDavid van Moolenbroek /** The IPv6 reassembly timer interval in milliseconds. */ 58*5d5fbe79SDavid van Moolenbroek #define IP6_REASS_TMR_INTERVAL 1000 59*5d5fbe79SDavid van Moolenbroek 60*5d5fbe79SDavid van Moolenbroek /** IP6_FRAG_COPYHEADER==1: for platforms where sizeof(void*) > 4, "struct 61*5d5fbe79SDavid van Moolenbroek * ip6_reass_helper" is too large to be stored in the IPv6 fragment header, and 62*5d5fbe79SDavid van Moolenbroek * will bleed into the header before it, which may be the IPv6 header or an 63*5d5fbe79SDavid van Moolenbroek * extension header. This means that for each first fragment packet, we need to 64*5d5fbe79SDavid van Moolenbroek * 1) make a copy of some IPv6 header fields (src+dest) that we need later on, 65*5d5fbe79SDavid van Moolenbroek * just in case we do overwrite part of the IPv6 header, and 2) make a copy of 66*5d5fbe79SDavid van Moolenbroek * the header data that we overwrote, so that we can restore it before either 67*5d5fbe79SDavid van Moolenbroek * completing reassembly or sending an ICMPv6 reply. The last part is true even 68*5d5fbe79SDavid van Moolenbroek * if this setting is disabled, but if it is enabled, we need to save a bit 69*5d5fbe79SDavid van Moolenbroek * more data (up to the size of a pointer) because we overwrite more. */ 70*5d5fbe79SDavid van Moolenbroek #ifndef IPV6_FRAG_COPYHEADER 71*5d5fbe79SDavid van Moolenbroek #define IPV6_FRAG_COPYHEADER 0 72*5d5fbe79SDavid van Moolenbroek #endif 73*5d5fbe79SDavid van Moolenbroek 74*5d5fbe79SDavid van Moolenbroek /* With IPV6_FRAG_COPYHEADER==1, a helper structure may (or, depending on the 75*5d5fbe79SDavid van Moolenbroek * presence of extensions, may not) overwrite part of the IP header. Therefore, 76*5d5fbe79SDavid van Moolenbroek * we copy the fields that we need from the IP header for as long as the helper 77*5d5fbe79SDavid van Moolenbroek * structure may still be in place. This is easier than temporarily restoring 78*5d5fbe79SDavid van Moolenbroek * those fields in the IP header each time we need to perform checks on them. */ 79*5d5fbe79SDavid van Moolenbroek #if IPV6_FRAG_COPYHEADER 80*5d5fbe79SDavid van Moolenbroek #define IPV6_FRAG_SRC(ipr) ((ipr)->src) 81*5d5fbe79SDavid van Moolenbroek #define IPV6_FRAG_DEST(ipr) ((ipr)->dest) 82*5d5fbe79SDavid van Moolenbroek #else /* IPV6_FRAG_COPYHEADER */ 83*5d5fbe79SDavid van Moolenbroek #define IPV6_FRAG_SRC(ipr) ((ipr)->iphdr->src) 84*5d5fbe79SDavid van Moolenbroek #define IPV6_FRAG_DEST(ipr) ((ipr)->iphdr->dest) 85*5d5fbe79SDavid van Moolenbroek #endif /* IPV6_FRAG_COPYHEADER */ 86*5d5fbe79SDavid van Moolenbroek 87*5d5fbe79SDavid van Moolenbroek /** IPv6 reassembly helper struct. 88*5d5fbe79SDavid van Moolenbroek * This is exported because memp needs to know the size. 89*5d5fbe79SDavid van Moolenbroek */ 90*5d5fbe79SDavid van Moolenbroek struct ip6_reassdata { 91*5d5fbe79SDavid van Moolenbroek struct ip6_reassdata *next; 92*5d5fbe79SDavid van Moolenbroek struct pbuf *p; 93*5d5fbe79SDavid van Moolenbroek struct ip6_hdr *iphdr; /* pointer to the first (original) IPv6 header */ 94*5d5fbe79SDavid van Moolenbroek #if IPV6_FRAG_COPYHEADER 95*5d5fbe79SDavid van Moolenbroek ip6_addr_p_t src; /* copy of the source address in the IP header */ 96*5d5fbe79SDavid van Moolenbroek ip6_addr_p_t dest; /* copy of the destination address in the IP header */ 97*5d5fbe79SDavid van Moolenbroek /* This buffer (for the part of the original header that we overwrite) will 98*5d5fbe79SDavid van Moolenbroek * be slightly oversized, but we cannot compute the exact size from here. */ 99*5d5fbe79SDavid van Moolenbroek u8_t orig_hdr[sizeof(struct ip6_frag_hdr) + sizeof(void*)]; 100*5d5fbe79SDavid van Moolenbroek #else /* IPV6_FRAG_COPYHEADER */ 101*5d5fbe79SDavid van Moolenbroek /* In this case we still need the buffer, for sending ICMPv6 replies. */ 102*5d5fbe79SDavid van Moolenbroek u8_t orig_hdr[sizeof(struct ip6_frag_hdr)]; 103*5d5fbe79SDavid van Moolenbroek #endif /* IPV6_FRAG_COPYHEADER */ 104*5d5fbe79SDavid van Moolenbroek u32_t identification; 105*5d5fbe79SDavid van Moolenbroek u16_t datagram_len; 106*5d5fbe79SDavid van Moolenbroek u8_t nexth; 107*5d5fbe79SDavid van Moolenbroek u8_t timer; 108*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6_SCOPES 109*5d5fbe79SDavid van Moolenbroek u8_t src_zone; /* zone of original packet's source address */ 110*5d5fbe79SDavid van Moolenbroek u8_t dest_zone; /* zone of original packet's destination address */ 111*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6_SCOPES */ 112*5d5fbe79SDavid van Moolenbroek }; 113*5d5fbe79SDavid van Moolenbroek 114*5d5fbe79SDavid van Moolenbroek #define ip6_reass_init() /* Compatibility define */ 115*5d5fbe79SDavid van Moolenbroek void ip6_reass_tmr(void); 116*5d5fbe79SDavid van Moolenbroek struct pbuf *ip6_reass(struct pbuf *p); 117*5d5fbe79SDavid van Moolenbroek 118*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6 && LWIP_IPV6_REASS */ 119*5d5fbe79SDavid van Moolenbroek 120*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6 && LWIP_IPV6_FRAG /* don't build if not configured for use in lwipopts.h */ 121*5d5fbe79SDavid van Moolenbroek 122*5d5fbe79SDavid van Moolenbroek #ifndef LWIP_PBUF_CUSTOM_REF_DEFINED 123*5d5fbe79SDavid van Moolenbroek #define LWIP_PBUF_CUSTOM_REF_DEFINED 124*5d5fbe79SDavid van Moolenbroek /** A custom pbuf that holds a reference to another pbuf, which is freed 125*5d5fbe79SDavid van Moolenbroek * when this custom pbuf is freed. This is used to create a custom PBUF_REF 126*5d5fbe79SDavid van Moolenbroek * that points into the original pbuf. */ 127*5d5fbe79SDavid van Moolenbroek struct pbuf_custom_ref { 128*5d5fbe79SDavid van Moolenbroek /** 'base class' */ 129*5d5fbe79SDavid van Moolenbroek struct pbuf_custom pc; 130*5d5fbe79SDavid van Moolenbroek /** pointer to the original pbuf that is referenced */ 131*5d5fbe79SDavid van Moolenbroek struct pbuf *original; 132*5d5fbe79SDavid van Moolenbroek }; 133*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */ 134*5d5fbe79SDavid van Moolenbroek 135*5d5fbe79SDavid van Moolenbroek err_t ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest); 136*5d5fbe79SDavid van Moolenbroek 137*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6 && LWIP_IPV6_FRAG */ 138*5d5fbe79SDavid van Moolenbroek 139*5d5fbe79SDavid van Moolenbroek 140*5d5fbe79SDavid van Moolenbroek #ifdef __cplusplus 141*5d5fbe79SDavid van Moolenbroek } 142*5d5fbe79SDavid van Moolenbroek #endif 143*5d5fbe79SDavid van Moolenbroek 144*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_HDR_IP6_FRAG_H */ 145