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