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