1195972f6Sopenharmony_ci/** 2195972f6Sopenharmony_ci * @file 3195972f6Sopenharmony_ci * 4195972f6Sopenharmony_ci * IPv6 fragmentation and reassembly. 5195972f6Sopenharmony_ci */ 6195972f6Sopenharmony_ci 7195972f6Sopenharmony_ci/* 8195972f6Sopenharmony_ci * Copyright (c) 2010 Inico Technologies Ltd. 9195972f6Sopenharmony_ci * All rights reserved. 10195972f6Sopenharmony_ci * 11195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 12195972f6Sopenharmony_ci * are permitted provided that the following conditions are met: 13195972f6Sopenharmony_ci * 14195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, 15195972f6Sopenharmony_ci * this list of conditions and the following disclaimer. 16195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, 17195972f6Sopenharmony_ci * this list of conditions and the following disclaimer in the documentation 18195972f6Sopenharmony_ci * and/or other materials provided with the distribution. 19195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote products 20195972f6Sopenharmony_ci * derived from this software without specific prior written permission. 21195972f6Sopenharmony_ci * 22195972f6Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23195972f6Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24195972f6Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25195972f6Sopenharmony_ci * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26195972f6Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27195972f6Sopenharmony_ci * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28195972f6Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29195972f6Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30195972f6Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31195972f6Sopenharmony_ci * OF SUCH DAMAGE. 32195972f6Sopenharmony_ci * 33195972f6Sopenharmony_ci * This file is part of the lwIP TCP/IP stack. 34195972f6Sopenharmony_ci * 35195972f6Sopenharmony_ci * Author: Ivan Delamer <delamer@inicotech.com> 36195972f6Sopenharmony_ci * 37195972f6Sopenharmony_ci * 38195972f6Sopenharmony_ci * Please coordinate changes and requests with Ivan Delamer 39195972f6Sopenharmony_ci * <delamer@inicotech.com> 40195972f6Sopenharmony_ci */ 41195972f6Sopenharmony_ci#ifndef LWIP_HDR_IP6_FRAG_H 42195972f6Sopenharmony_ci#define LWIP_HDR_IP6_FRAG_H 43195972f6Sopenharmony_ci 44195972f6Sopenharmony_ci#include "lwip/opt.h" 45195972f6Sopenharmony_ci#include "lwip/pbuf.h" 46195972f6Sopenharmony_ci#include "lwip/ip6_addr.h" 47195972f6Sopenharmony_ci#include "lwip/ip6.h" 48195972f6Sopenharmony_ci#include "lwip/netif.h" 49195972f6Sopenharmony_ci 50195972f6Sopenharmony_ci#ifdef __cplusplus 51195972f6Sopenharmony_ciextern "C" { 52195972f6Sopenharmony_ci#endif 53195972f6Sopenharmony_ci 54195972f6Sopenharmony_ci 55195972f6Sopenharmony_ci#if LWIP_IPV6 && LWIP_IPV6_REASS /* don't build if not configured for use in lwipopts.h */ 56195972f6Sopenharmony_ci 57195972f6Sopenharmony_ci/** The IPv6 reassembly timer interval in milliseconds. */ 58195972f6Sopenharmony_ci#define IP6_REASS_TMR_INTERVAL 1000 59195972f6Sopenharmony_ci 60195972f6Sopenharmony_ci/** IP6_FRAG_COPYHEADER==1: for platforms where sizeof(void*) > 4, "struct 61195972f6Sopenharmony_ci * ip6_reass_helper" is too large to be stored in the IPv6 fragment header, and 62195972f6Sopenharmony_ci * will bleed into the header before it, which may be the IPv6 header or an 63195972f6Sopenharmony_ci * extension header. This means that for each first fragment packet, we need to 64195972f6Sopenharmony_ci * 1) make a copy of some IPv6 header fields (src+dest) that we need later on, 65195972f6Sopenharmony_ci * just in case we do overwrite part of the IPv6 header, and 2) make a copy of 66195972f6Sopenharmony_ci * the header data that we overwrote, so that we can restore it before either 67195972f6Sopenharmony_ci * completing reassembly or sending an ICMPv6 reply. The last part is true even 68195972f6Sopenharmony_ci * if this setting is disabled, but if it is enabled, we need to save a bit 69195972f6Sopenharmony_ci * more data (up to the size of a pointer) because we overwrite more. */ 70195972f6Sopenharmony_ci#ifndef IPV6_FRAG_COPYHEADER 71195972f6Sopenharmony_ci#define IPV6_FRAG_COPYHEADER 0 72195972f6Sopenharmony_ci#endif 73195972f6Sopenharmony_ci 74195972f6Sopenharmony_ci/* With IPV6_FRAG_COPYHEADER==1, a helper structure may (or, depending on the 75195972f6Sopenharmony_ci * presence of extensions, may not) overwrite part of the IP header. Therefore, 76195972f6Sopenharmony_ci * we copy the fields that we need from the IP header for as long as the helper 77195972f6Sopenharmony_ci * structure may still be in place. This is easier than temporarily restoring 78195972f6Sopenharmony_ci * those fields in the IP header each time we need to perform checks on them. */ 79195972f6Sopenharmony_ci#if IPV6_FRAG_COPYHEADER 80195972f6Sopenharmony_ci#define IPV6_FRAG_SRC(ipr) ((ipr)->src) 81195972f6Sopenharmony_ci#define IPV6_FRAG_DEST(ipr) ((ipr)->dest) 82195972f6Sopenharmony_ci#else /* IPV6_FRAG_COPYHEADER */ 83195972f6Sopenharmony_ci#define IPV6_FRAG_SRC(ipr) ((ipr)->iphdr->src) 84195972f6Sopenharmony_ci#define IPV6_FRAG_DEST(ipr) ((ipr)->iphdr->dest) 85195972f6Sopenharmony_ci#endif /* IPV6_FRAG_COPYHEADER */ 86195972f6Sopenharmony_ci 87195972f6Sopenharmony_ci/** IPv6 reassembly helper struct. 88195972f6Sopenharmony_ci * This is exported because memp needs to know the size. 89195972f6Sopenharmony_ci */ 90195972f6Sopenharmony_cistruct ip6_reassdata { 91195972f6Sopenharmony_ci struct ip6_reassdata *next; 92195972f6Sopenharmony_ci struct pbuf *p; 93195972f6Sopenharmony_ci struct ip6_hdr *iphdr; /* pointer to the first (original) IPv6 header */ 94195972f6Sopenharmony_ci#if IPV6_FRAG_COPYHEADER 95195972f6Sopenharmony_ci ip6_addr_p_t src; /* copy of the source address in the IP header */ 96195972f6Sopenharmony_ci ip6_addr_p_t dest; /* copy of the destination address in the IP header */ 97195972f6Sopenharmony_ci /* This buffer (for the part of the original header that we overwrite) will 98195972f6Sopenharmony_ci * be slightly oversized, but we cannot compute the exact size from here. */ 99195972f6Sopenharmony_ci u8_t orig_hdr[sizeof(struct ip6_frag_hdr) + sizeof(void*)]; 100195972f6Sopenharmony_ci#else /* IPV6_FRAG_COPYHEADER */ 101195972f6Sopenharmony_ci /* In this case we still need the buffer, for sending ICMPv6 replies. */ 102195972f6Sopenharmony_ci u8_t orig_hdr[sizeof(struct ip6_frag_hdr)]; 103195972f6Sopenharmony_ci#endif /* IPV6_FRAG_COPYHEADER */ 104195972f6Sopenharmony_ci u32_t identification; 105195972f6Sopenharmony_ci u16_t datagram_len; 106195972f6Sopenharmony_ci u8_t nexth; 107195972f6Sopenharmony_ci u8_t timer; 108195972f6Sopenharmony_ci#if LWIP_IPV6_SCOPES 109195972f6Sopenharmony_ci u8_t src_zone; /* zone of original packet's source address */ 110195972f6Sopenharmony_ci u8_t dest_zone; /* zone of original packet's destination address */ 111195972f6Sopenharmony_ci#endif /* LWIP_IPV6_SCOPES */ 112195972f6Sopenharmony_ci}; 113195972f6Sopenharmony_ci 114195972f6Sopenharmony_ci#define ip6_reass_init() /* Compatibility define */ 115195972f6Sopenharmony_civoid ip6_reass_tmr(void); 116195972f6Sopenharmony_cistruct pbuf *ip6_reass(struct pbuf *p); 117195972f6Sopenharmony_ci 118195972f6Sopenharmony_ci#if LWIP_LOWPOWER 119195972f6Sopenharmony_ciu32_t ip6_reass_tmr_tick(void); 120195972f6Sopenharmony_ci#endif 121195972f6Sopenharmony_ci 122195972f6Sopenharmony_ci#endif /* LWIP_IPV6 && LWIP_IPV6_REASS */ 123195972f6Sopenharmony_ci 124195972f6Sopenharmony_ci#if LWIP_IPV6 && LWIP_IPV6_FRAG /* don't build if not configured for use in lwipopts.h */ 125195972f6Sopenharmony_ci 126195972f6Sopenharmony_ci#ifndef LWIP_PBUF_CUSTOM_REF_DEFINED 127195972f6Sopenharmony_ci#define LWIP_PBUF_CUSTOM_REF_DEFINED 128195972f6Sopenharmony_ci/** A custom pbuf that holds a reference to another pbuf, which is freed 129195972f6Sopenharmony_ci * when this custom pbuf is freed. This is used to create a custom PBUF_REF 130195972f6Sopenharmony_ci * that points into the original pbuf. */ 131195972f6Sopenharmony_cistruct pbuf_custom_ref { 132195972f6Sopenharmony_ci /** 'base class' */ 133195972f6Sopenharmony_ci struct pbuf_custom pc; 134195972f6Sopenharmony_ci /** pointer to the original pbuf that is referenced */ 135195972f6Sopenharmony_ci struct pbuf *original; 136195972f6Sopenharmony_ci}; 137195972f6Sopenharmony_ci#endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */ 138195972f6Sopenharmony_ci 139195972f6Sopenharmony_cierr_t ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest); 140195972f6Sopenharmony_ci 141195972f6Sopenharmony_ci#endif /* LWIP_IPV6 && LWIP_IPV6_FRAG */ 142195972f6Sopenharmony_ci 143195972f6Sopenharmony_ci 144195972f6Sopenharmony_ci#ifdef __cplusplus 145195972f6Sopenharmony_ci} 146195972f6Sopenharmony_ci#endif 147195972f6Sopenharmony_ci 148195972f6Sopenharmony_ci#endif /* LWIP_HDR_IP6_FRAG_H */ 149