Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ipv4_frag.h Source File

ipv4_frag.h

Go to the documentation of this file.
00001 /**
00002  * @file ipv4_frag.h
00003  * @brief IPv4 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 _IPV4_FRAG_H
00030 #define _IPV4_FRAG_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 #include "ipv4/ipv4.h"
00035 
00036 //IPv4 fragmentation support
00037 #ifndef IPV4_FRAG_SUPPORT
00038    #define IPV4_FRAG_SUPPORT DISABLED
00039 #elif (IPV4_FRAG_SUPPORT != ENABLED && IPV4_FRAG_SUPPORT != DISABLED)
00040    #error IPV4_FRAG_SUPPORT parameter is not valid
00041 #endif
00042 
00043 //Reassembly algorithm tick interval
00044 #ifndef IPV4_FRAG_TICK_INTERVAL
00045    #define IPV4_FRAG_TICK_INTERVAL 1000
00046 #elif (IPV4_FRAG_TICK_INTERVAL < 10)
00047    #error IPV4_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 IPV4_MAX_FRAG_DATAGRAMS
00053    #define IPV4_MAX_FRAG_DATAGRAMS 4
00054 #elif (IPV4_MAX_FRAG_DATAGRAMS < 1)
00055    #error IPV4_MAX_FRAG_DATAGRAMS parameter is not valid
00056 #endif
00057 
00058 //Maximum datagram size the host will accept when reassembling fragments
00059 #ifndef IPV4_MAX_FRAG_DATAGRAM_SIZE
00060    #define IPV4_MAX_FRAG_DATAGRAM_SIZE 8192
00061 #elif (IPV4_MAX_FRAG_DATAGRAM_SIZE < 576)
00062    #error IPV4_MAX_FRAG_DATAGRAM_SIZE parameter is not valid
00063 #endif
00064 
00065 //Maximum time an IPv4 fragment can spend waiting to be reassembled
00066 #ifndef IPV4_FRAG_TIME_TO_LIVE
00067    #define IPV4_FRAG_TIME_TO_LIVE 15000
00068 #elif (IPV4_FRAG_TIME_TO_LIVE < 1000)
00069    #error IPV4_FRAG_TIME_TO_LIVE parameter is not valid
00070 #endif
00071 
00072 //Infinity is implemented by a very large integer
00073 #define IPV4_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 Ipv4HoleDesc;
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(IPV4_MAX_FRAG_DATAGRAM_SIZE) + 1];
00109 } Ipv4ReassemblyBuffer;
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    size_t headerLength;         ///<Length of the header
00120    size_t dataLength;           ///<Length of the payload
00121    uint16_t firstHole;          ///<Index of the first hole
00122    Ipv4ReassemblyBuffer buffer; ///<Buffer containing the reassembled datagram
00123 } Ipv4FragDesc;
00124 
00125 
00126 //Tick counter to handle periodic operations
00127 extern systime_t ipv4FragTickCounter;
00128 
00129 //IPv4 datagram fragmentation and reassembly
00130 error_t ipv4FragmentDatagram(NetInterface *interface, Ipv4PseudoHeader *pseudoHeader,
00131    uint16_t id, const NetBuffer *payload, size_t payloadOffset, uint8_t timeToLive);
00132 
00133 void ipv4ReassembleDatagram(NetInterface *interface,
00134    const Ipv4Header *packet, size_t length);
00135 
00136 void ipv4FragTick(NetInterface *interface);
00137 
00138 Ipv4FragDesc *ipv4SearchFragQueue(NetInterface *interface, const Ipv4Header *packet);
00139 void ipv4FlushFragQueue(NetInterface *interface);
00140 
00141 Ipv4HoleDesc *ipv4FindHole(Ipv4FragDesc *frag, uint16_t offset);
00142 void ipv4DumpHoleList(Ipv4FragDesc *frag);
00143 
00144 #endif
00145