Webserver+3d print
cyclone_tcp/ipv4/ipv4_frag.h@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file ipv4_frag.h |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief IPv4 fragmentation and reassembly |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | #ifndef _IPV4_FRAG_H |
Sergunb | 0:8918a71cdbe9 | 30 | #define _IPV4_FRAG_H |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 33 | #include "core/net.h" |
Sergunb | 0:8918a71cdbe9 | 34 | #include "ipv4/ipv4.h" |
Sergunb | 0:8918a71cdbe9 | 35 | |
Sergunb | 0:8918a71cdbe9 | 36 | //IPv4 fragmentation support |
Sergunb | 0:8918a71cdbe9 | 37 | #ifndef IPV4_FRAG_SUPPORT |
Sergunb | 0:8918a71cdbe9 | 38 | #define IPV4_FRAG_SUPPORT DISABLED |
Sergunb | 0:8918a71cdbe9 | 39 | #elif (IPV4_FRAG_SUPPORT != ENABLED && IPV4_FRAG_SUPPORT != DISABLED) |
Sergunb | 0:8918a71cdbe9 | 40 | #error IPV4_FRAG_SUPPORT parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 41 | #endif |
Sergunb | 0:8918a71cdbe9 | 42 | |
Sergunb | 0:8918a71cdbe9 | 43 | //Reassembly algorithm tick interval |
Sergunb | 0:8918a71cdbe9 | 44 | #ifndef IPV4_FRAG_TICK_INTERVAL |
Sergunb | 0:8918a71cdbe9 | 45 | #define IPV4_FRAG_TICK_INTERVAL 1000 |
Sergunb | 0:8918a71cdbe9 | 46 | #elif (IPV4_FRAG_TICK_INTERVAL < 10) |
Sergunb | 0:8918a71cdbe9 | 47 | #error IPV4_FRAG_TICK_INTERVAL parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 48 | #endif |
Sergunb | 0:8918a71cdbe9 | 49 | |
Sergunb | 0:8918a71cdbe9 | 50 | //Maximum number of fragmented packets the host will accept |
Sergunb | 0:8918a71cdbe9 | 51 | //and hold in the reassembly queue simultaneously |
Sergunb | 0:8918a71cdbe9 | 52 | #ifndef IPV4_MAX_FRAG_DATAGRAMS |
Sergunb | 0:8918a71cdbe9 | 53 | #define IPV4_MAX_FRAG_DATAGRAMS 4 |
Sergunb | 0:8918a71cdbe9 | 54 | #elif (IPV4_MAX_FRAG_DATAGRAMS < 1) |
Sergunb | 0:8918a71cdbe9 | 55 | #error IPV4_MAX_FRAG_DATAGRAMS parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 56 | #endif |
Sergunb | 0:8918a71cdbe9 | 57 | |
Sergunb | 0:8918a71cdbe9 | 58 | //Maximum datagram size the host will accept when reassembling fragments |
Sergunb | 0:8918a71cdbe9 | 59 | #ifndef IPV4_MAX_FRAG_DATAGRAM_SIZE |
Sergunb | 0:8918a71cdbe9 | 60 | #define IPV4_MAX_FRAG_DATAGRAM_SIZE 8192 |
Sergunb | 0:8918a71cdbe9 | 61 | #elif (IPV4_MAX_FRAG_DATAGRAM_SIZE < 576) |
Sergunb | 0:8918a71cdbe9 | 62 | #error IPV4_MAX_FRAG_DATAGRAM_SIZE parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 63 | #endif |
Sergunb | 0:8918a71cdbe9 | 64 | |
Sergunb | 0:8918a71cdbe9 | 65 | //Maximum time an IPv4 fragment can spend waiting to be reassembled |
Sergunb | 0:8918a71cdbe9 | 66 | #ifndef IPV4_FRAG_TIME_TO_LIVE |
Sergunb | 0:8918a71cdbe9 | 67 | #define IPV4_FRAG_TIME_TO_LIVE 15000 |
Sergunb | 0:8918a71cdbe9 | 68 | #elif (IPV4_FRAG_TIME_TO_LIVE < 1000) |
Sergunb | 0:8918a71cdbe9 | 69 | #error IPV4_FRAG_TIME_TO_LIVE parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 70 | #endif |
Sergunb | 0:8918a71cdbe9 | 71 | |
Sergunb | 0:8918a71cdbe9 | 72 | //Infinity is implemented by a very large integer |
Sergunb | 0:8918a71cdbe9 | 73 | #define IPV4_INFINITY 0xFFFF |
Sergunb | 0:8918a71cdbe9 | 74 | |
Sergunb | 0:8918a71cdbe9 | 75 | |
Sergunb | 0:8918a71cdbe9 | 76 | //CodeWarrior or Win32 compiler? |
Sergunb | 0:8918a71cdbe9 | 77 | #if defined(__CWCC__) || defined(_WIN32) |
Sergunb | 0:8918a71cdbe9 | 78 | #pragma pack(push, 1) |
Sergunb | 0:8918a71cdbe9 | 79 | #endif |
Sergunb | 0:8918a71cdbe9 | 80 | |
Sergunb | 0:8918a71cdbe9 | 81 | |
Sergunb | 0:8918a71cdbe9 | 82 | /** |
Sergunb | 0:8918a71cdbe9 | 83 | * @brief Hole descriptor |
Sergunb | 0:8918a71cdbe9 | 84 | **/ |
Sergunb | 0:8918a71cdbe9 | 85 | |
Sergunb | 0:8918a71cdbe9 | 86 | typedef __start_packed struct |
Sergunb | 0:8918a71cdbe9 | 87 | { |
Sergunb | 0:8918a71cdbe9 | 88 | uint16_t first; |
Sergunb | 0:8918a71cdbe9 | 89 | uint16_t last; |
Sergunb | 0:8918a71cdbe9 | 90 | uint16_t next; |
Sergunb | 0:8918a71cdbe9 | 91 | } __end_packed Ipv4HoleDesc; |
Sergunb | 0:8918a71cdbe9 | 92 | |
Sergunb | 0:8918a71cdbe9 | 93 | |
Sergunb | 0:8918a71cdbe9 | 94 | //CodeWarrior or Win32 compiler? |
Sergunb | 0:8918a71cdbe9 | 95 | #if defined(__CWCC__) || defined(_WIN32) |
Sergunb | 0:8918a71cdbe9 | 96 | #pragma pack(pop) |
Sergunb | 0:8918a71cdbe9 | 97 | #endif |
Sergunb | 0:8918a71cdbe9 | 98 | |
Sergunb | 0:8918a71cdbe9 | 99 | |
Sergunb | 0:8918a71cdbe9 | 100 | /** |
Sergunb | 0:8918a71cdbe9 | 101 | * @brief Reassembly buffer |
Sergunb | 0:8918a71cdbe9 | 102 | **/ |
Sergunb | 0:8918a71cdbe9 | 103 | |
Sergunb | 0:8918a71cdbe9 | 104 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 105 | { |
Sergunb | 0:8918a71cdbe9 | 106 | uint_t chunkCount; |
Sergunb | 0:8918a71cdbe9 | 107 | uint_t maxChunkCount; |
Sergunb | 0:8918a71cdbe9 | 108 | ChunkDesc chunk[N(IPV4_MAX_FRAG_DATAGRAM_SIZE) + 1]; |
Sergunb | 0:8918a71cdbe9 | 109 | } Ipv4ReassemblyBuffer; |
Sergunb | 0:8918a71cdbe9 | 110 | |
Sergunb | 0:8918a71cdbe9 | 111 | |
Sergunb | 0:8918a71cdbe9 | 112 | /** |
Sergunb | 0:8918a71cdbe9 | 113 | * @brief Fragmented packet descriptor |
Sergunb | 0:8918a71cdbe9 | 114 | **/ |
Sergunb | 0:8918a71cdbe9 | 115 | |
Sergunb | 0:8918a71cdbe9 | 116 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 117 | { |
Sergunb | 0:8918a71cdbe9 | 118 | systime_t timestamp; ///<Time at which the first fragment was received |
Sergunb | 0:8918a71cdbe9 | 119 | size_t headerLength; ///<Length of the header |
Sergunb | 0:8918a71cdbe9 | 120 | size_t dataLength; ///<Length of the payload |
Sergunb | 0:8918a71cdbe9 | 121 | uint16_t firstHole; ///<Index of the first hole |
Sergunb | 0:8918a71cdbe9 | 122 | Ipv4ReassemblyBuffer buffer; ///<Buffer containing the reassembled datagram |
Sergunb | 0:8918a71cdbe9 | 123 | } Ipv4FragDesc; |
Sergunb | 0:8918a71cdbe9 | 124 | |
Sergunb | 0:8918a71cdbe9 | 125 | |
Sergunb | 0:8918a71cdbe9 | 126 | //Tick counter to handle periodic operations |
Sergunb | 0:8918a71cdbe9 | 127 | extern systime_t ipv4FragTickCounter; |
Sergunb | 0:8918a71cdbe9 | 128 | |
Sergunb | 0:8918a71cdbe9 | 129 | //IPv4 datagram fragmentation and reassembly |
Sergunb | 0:8918a71cdbe9 | 130 | error_t ipv4FragmentDatagram(NetInterface *interface, Ipv4PseudoHeader *pseudoHeader, |
Sergunb | 0:8918a71cdbe9 | 131 | uint16_t id, const NetBuffer *payload, size_t payloadOffset, uint8_t timeToLive); |
Sergunb | 0:8918a71cdbe9 | 132 | |
Sergunb | 0:8918a71cdbe9 | 133 | void ipv4ReassembleDatagram(NetInterface *interface, |
Sergunb | 0:8918a71cdbe9 | 134 | const Ipv4Header *packet, size_t length); |
Sergunb | 0:8918a71cdbe9 | 135 | |
Sergunb | 0:8918a71cdbe9 | 136 | void ipv4FragTick(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 137 | |
Sergunb | 0:8918a71cdbe9 | 138 | Ipv4FragDesc *ipv4SearchFragQueue(NetInterface *interface, const Ipv4Header *packet); |
Sergunb | 0:8918a71cdbe9 | 139 | void ipv4FlushFragQueue(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 140 | |
Sergunb | 0:8918a71cdbe9 | 141 | Ipv4HoleDesc *ipv4FindHole(Ipv4FragDesc *frag, uint16_t offset); |
Sergunb | 0:8918a71cdbe9 | 142 | void ipv4DumpHoleList(Ipv4FragDesc *frag); |
Sergunb | 0:8918a71cdbe9 | 143 | |
Sergunb | 0:8918a71cdbe9 | 144 | #endif |
Sergunb | 0:8918a71cdbe9 | 145 |