ipv6_frag.h
Go to the documentation of this file.
1 /**
2  * @file ipv6_frag.h
3  * @brief IPv6 fragmentation and reassembly
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _IPV6_FRAG_H
30 #define _IPV6_FRAG_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "ipv6/ipv6.h"
35 
36 //IPv6 fragmentation support
37 #ifndef IPV6_FRAG_SUPPORT
38  #define IPV6_FRAG_SUPPORT ENABLED
39 #elif (IPV6_FRAG_SUPPORT != ENABLED && IPV6_FRAG_SUPPORT != DISABLED)
40  #error IPV6_FRAG_SUPPORT parameter is not valid
41 #endif
42 
43 //Support for overlapping fragments
44 #ifndef IPV6_OVERLAPPING_FRAG_SUPPORT
45  #define IPV6_OVERLAPPING_FRAG_SUPPORT ENABLED
46 #elif (IPV6_OVERLAPPING_FRAG_SUPPORT != ENABLED && IPV6_OVERLAPPING_FRAG_SUPPORT != DISABLED)
47  #error IPV6_OVERLAPPING_FRAG_SUPPORT parameter is not valid
48 #endif
49 
50 //Reassembly algorithm tick interval
51 #ifndef IPV6_FRAG_TICK_INTERVAL
52  #define IPV6_FRAG_TICK_INTERVAL 1000
53 #elif (IPV6_FRAG_TICK_INTERVAL < 10)
54  #error IPV6_FRAG_TICK_INTERVAL parameter is not valid
55 #endif
56 
57 //Maximum number of fragmented packets the host will accept
58 //and hold in the reassembly queue simultaneously
59 #ifndef IPV6_MAX_FRAG_DATAGRAMS
60  #define IPV6_MAX_FRAG_DATAGRAMS 4
61 #elif (IPV6_MAX_FRAG_DATAGRAMS < 1)
62  #error IPV6_MAX_FRAG_DATAGRAMS parameter is not valid
63 #endif
64 
65 //Maximum datagram size the host will accept when reassembling fragments
66 #ifndef IPV6_MAX_FRAG_DATAGRAM_SIZE
67  #define IPV6_MAX_FRAG_DATAGRAM_SIZE 8192
68 #elif (IPV6_MAX_FRAG_DATAGRAM_SIZE < 1280)
69  #error IPV6_MAX_FRAG_DATAGRAM_SIZE parameter is not valid
70 #endif
71 
72 //Maximum time an IPv6 fragment can spend waiting to be reassembled
73 #ifndef IPV6_FRAG_TIME_TO_LIVE
74  #define IPV6_FRAG_TIME_TO_LIVE 15000
75 #elif (IPV6_FRAG_TIME_TO_LIVE < 1000)
76  #error IPV6_FRAG_TIME_TO_LIVE parameter is not valid
77 #endif
78 
79 //Infinity is implemented by a very large integer
80 #define IPV6_INFINITY 0xFFFF
81 
82 //C++ guard
83 #ifdef __cplusplus
84  extern "C" {
85 #endif
86 
87 
88 //CodeWarrior or Win32 compiler?
89 #if defined(__CWCC__) || defined(_WIN32)
90  #pragma pack(push, 1)
91 #endif
92 
93 
94 /**
95  * @brief Hole descriptor
96  **/
97 
98 typedef __start_packed struct
99 {
100  uint16_t first;
101  uint16_t last;
102  uint16_t next;
104 
105 
106 //CodeWarrior or Win32 compiler?
107 #if defined(__CWCC__) || defined(_WIN32)
108  #pragma pack(pop)
109 #endif
110 
111 
112 /**
113  * @brief Reassembly buffer
114  **/
115 
116 typedef struct
117 {
122 
123 
124 /**
125  * @brief Fragmented packet descriptor
126  **/
127 
128 typedef struct
129 {
130  systime_t timestamp; ///<Time at which the first fragment was received
131  uint32_t identification; ///<Fragment identification field
132  size_t unfragPartLength; ///<Length of the unfragmentable part
133  size_t fragPartLength; ///<Length of the fragmentable part
134  uint16_t firstHole; ///<Index of the first hole
135  Ipv6ReassemblyBuffer buffer; ///<Buffer containing the reassembled datagram
136 } Ipv6FragDesc;
137 
138 
139 //Tick counter to handle periodic operations
141 
142 //IPv6 datagram fragmentation and reassembly
144  const NetBuffer *payload, size_t payloadOffset, size_t pathMtu, uint8_t hopLimit);
145 
147  size_t ipPacketOffset, size_t fragHeaderOffset, size_t nextHeaderOffset);
148 
149 void ipv6FragTick(NetInterface *interface);
150 
152  Ipv6Header *packet, Ipv6FragmentHeader *header);
153 
154 void ipv6FlushFragQueue(NetInterface *interface);
155 
156 Ipv6HoleDesc *ipv6FindHole(Ipv6FragDesc *frag, uint16_t offset);
157 void ipv6DumpHoleList(Ipv6FragDesc *frag);
158 
159 //C++ guard
160 #ifdef __cplusplus
161  }
162 #endif
163 
164 #endif
uint32_t systime_t
Definition: compiler_port.h:44
TCP/IP stack core.
void ipv6ParseFragmentHeader(NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t fragHeaderOffset, size_t nextHeaderOffset)
Parse Fragment header and reassemble original datagram.
Definition: ipv6_frag.c:172
Fragmented packet descriptor.
Definition: ipv6_frag.h:128
#define Ipv6FragmentHeader
Definition: ipv6.h:37
error_t ipv6FragmentDatagram(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *payload, size_t payloadOffset, size_t pathMtu, uint8_t hopLimit)
Fragment IPv6 datagram into smaller packets.
Definition: ipv6_frag.c:59
void ipv6FlushFragQueue(NetInterface *interface)
Flush IPv6 reassembly queue.
Definition: ipv6_frag.c:695
Ipv6ReassemblyBuffer buffer
Buffer containing the reassembled datagram.
Definition: ipv6_frag.h:135
Reassembly buffer.
Definition: ipv6_frag.h:116
__start_packed struct @192 Ipv6HoleDesc
Hole descriptor.
uint16_t last
Definition: ipv6_frag.h:101
uint32_t identification
Fragment identification field.
Definition: ipv6_frag.h:131
uint16_t first
Definition: ipv6_frag.h:100
systime_t timestamp
Time at which the first fragment was received.
Definition: ipv6_frag.h:130
uint8_t ipPacket[]
Definition: ndp.h:427
Ipv6HoleDesc * ipv6FindHole(Ipv6FragDesc *frag, uint16_t offset)
Retrieve hole descriptor.
Definition: ipv6_frag.c:716
size_t fragPartLength
Length of the fragmentable part.
Definition: ipv6_frag.h:133
Ipv6FragDesc * ipv6SearchFragQueue(NetInterface *interface, Ipv6Header *packet, Ipv6FragmentHeader *header)
Search for a matching datagram in the reassembly queue.
Definition: ipv6_frag.c:592
#define Ipv6PseudoHeader
Definition: ipv6.h:40
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
uint16_t next
Definition: ipv6_frag.h:102
size_t unfragPartLength
Length of the unfragmentable part.
Definition: ipv6_frag.h:132
IPv6 (Internet Protocol Version 6)
void ipv6FragTick(NetInterface *interface)
Fragment reassembly timeout handler.
Definition: ipv6_frag.c:524
__start_packed struct _Ipv4Header __end_packed
#define N(size)
Definition: net_mem.h:62
error_t
Error codes.
Definition: error.h:40
unsigned int uint_t
Definition: compiler_port.h:43
#define NetInterface
Definition: net.h:34
systime_t ipv6FragTickCounter
Definition: ipv6_frag.c:45
void ipv6DumpHoleList(Ipv6FragDesc *frag)
Dump hole descriptor list.
Definition: ipv6_frag.c:728
uint16_t firstHole
Index of the first hole.
Definition: ipv6_frag.h:134
#define Ipv6Header
Definition: ipv6.h:34
#define IPV6_MAX_FRAG_DATAGRAM_SIZE
Definition: ipv6_frag.h:67
Structure describing a chunk of data.
Definition: net_mem.h:74