Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ipv6_frag.h Source File

ipv6_frag.h

Go to the documentation of this file.
00001 /**
00002  * @file ipv6_frag.h
00003  * @brief IPv6 fragmentation and reassembly
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _IPV6_FRAG_H
00030 #define _IPV6_FRAG_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "ipv6/ipv6.h"
00035 
00036 //IPv6 fragmentation support
00037 #ifndef IPV6_FRAG_SUPPORT
00038    #define IPV6_FRAG_SUPPORT DISABLED
00039 #elif (IPV6_FRAG_SUPPORT != ENABLED && IPV6_FRAG_SUPPORT != DISABLED)
00040    #error IPV6_FRAG_SUPPORT parameter is not valid
00041 #endif
00042 
00043 //Reassembly algorithm tick interval
00044 #ifndef IPV6_FRAG_TICK_INTERVAL
00045    #define IPV6_FRAG_TICK_INTERVAL 1000
00046 #elif (IPV6_FRAG_TICK_INTERVAL < 10)
00047    #error IPV6_FRAG_TICK_INTERVAL parameter is not valid
00048 #endif
00049 
00050 //Maximum number of fragmented packets the host will accept
00051 //and hold in the reassembly queue simultaneously
00052 #ifndef IPV6_MAX_FRAG_DATAGRAMS
00053    #define IPV6_MAX_FRAG_DATAGRAMS 4
00054 #elif (IPV6_MAX_FRAG_DATAGRAMS < 1)
00055    #error IPV6_MAX_FRAG_DATAGRAMS parameter is not valid
00056 #endif
00057 
00058 //Maximum datagram size the host will accept when reassembling fragments
00059 #ifndef IPV6_MAX_FRAG_DATAGRAM_SIZE
00060    #define IPV6_MAX_FRAG_DATAGRAM_SIZE 8192
00061 #elif (IPV6_MAX_FRAG_DATAGRAM_SIZE < 1280)
00062    #error IPV6_MAX_FRAG_DATAGRAM_SIZE parameter is not valid
00063 #endif
00064 
00065 //Maximum time an IPv6 fragment can spend waiting to be reassembled
00066 #ifndef IPV6_FRAG_TIME_TO_LIVE
00067    #define IPV6_FRAG_TIME_TO_LIVE 15000
00068 #elif (IPV6_FRAG_TIME_TO_LIVE < 1000)
00069    #error IPV6_FRAG_TIME_TO_LIVE parameter is not valid
00070 #endif
00071 
00072 //Infinity is implemented by a very large integer
00073 #define IPV6_INFINITY 0xFFFF
00074 
00075 
00076 //CodeWarrior or Win32 compiler?
00077 #if defined(__CWCC__) || defined(_WIN32)
00078    #pragma pack(push, 1)
00079 #endif
00080 
00081 
00082 /**
00083  * @brief Hole descriptor
00084  **/
00085 
00086 typedef __start_packed struct
00087 {
00088    uint16_t first;
00089    uint16_t last;
00090    uint16_t next;
00091 } __end_packed Ipv6HoleDesc;
00092 
00093 
00094 //CodeWarrior or Win32 compiler?
00095 #if defined(__CWCC__) || defined(_WIN32)
00096    #pragma pack(pop)
00097 #endif
00098 
00099 
00100 /**
00101  * @brief Reassembly buffer
00102  **/
00103 
00104 typedef struct
00105 {
00106    uint_t chunkCount;
00107    uint_t maxChunkCount;
00108    ChunkDesc chunk[N(IPV6_MAX_FRAG_DATAGRAM_SIZE) + 1];
00109 } Ipv6ReassemblyBuffer;
00110 
00111 
00112 /**
00113  * @brief Fragmented packet descriptor
00114  **/
00115 
00116 typedef struct
00117 {
00118    systime_t timestamp;         ///<Time at which the first fragment was received
00119    uint32_t identification;     ///<Fragment identification field
00120    size_t unfragPartLength;     ///<Length of the unfragmentable part
00121    size_t fragPartLength;       ///<Length of the fragmentable part
00122    uint16_t firstHole;          ///<Index of the first hole
00123    Ipv6ReassemblyBuffer buffer; ///<Buffer containing the reassembled datagram
00124 } Ipv6FragDesc;
00125 
00126 
00127 //Tick counter to handle periodic operations
00128 extern systime_t ipv6FragTickCounter;
00129 
00130 //IPv6 datagram fragmentation and reassembly
00131 error_t ipv6FragmentDatagram(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
00132    const NetBuffer *payload, size_t payloadOffset, size_t pathMtu, uint8_t hopLimit);
00133 
00134 void ipv6ParseFragmentHeader(NetInterface *interface, const NetBuffer *ipPacket,
00135    size_t ipPacketOffset, size_t fragHeaderOffset, size_t nextHeaderOffset);
00136 
00137 void ipv6FragTick(NetInterface *interface);
00138 
00139 Ipv6FragDesc *ipv6SearchFragQueue(NetInterface *interface,
00140    Ipv6Header *packet, Ipv6FragmentHeader *header);
00141 
00142 void ipv6FlushFragQueue(NetInterface *interface);
00143 
00144 Ipv6HoleDesc *ipv6FindHole(Ipv6FragDesc *frag, uint16_t offset);
00145 void ipv6DumpHoleList(Ipv6FragDesc *frag);
00146 
00147 #endif
00148