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-2019 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 1.9.6
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 ENABLED
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 //CodeWarrior or Win32 compiler?
91 #if defined(__CWCC__) || defined(_WIN32)
92  #pragma pack(push, 1)
93 #endif
94 
95 
96 /**
97  * @brief Hole descriptor
98  **/
99 
100 typedef __start_packed struct
101 {
102  uint16_t first;
103  uint16_t last;
104  uint16_t next;
106 
107 
108 //CodeWarrior or Win32 compiler?
109 #if defined(__CWCC__) || defined(_WIN32)
110  #pragma pack(pop)
111 #endif
112 
113 
114 /**
115  * @brief Reassembly buffer
116  **/
117 
118 typedef struct
119 {
124 
125 
126 /**
127  * @brief Fragmented packet descriptor
128  **/
129 
130 typedef struct
131 {
132  systime_t timestamp; ///<Time at which the first fragment was received
133  uint32_t identification; ///<Fragment identification field
134  size_t unfragPartLength; ///<Length of the unfragmentable part
135  size_t fragPartLength; ///<Length of the fragmentable part
136  uint16_t firstHole; ///<Index of the first hole
137  Ipv6ReassemblyBuffer buffer; ///<Buffer containing the reassembled datagram
138 } Ipv6FragDesc;
139 
140 
141 //Tick counter to handle periodic operations
143 
144 //IPv6 datagram fragmentation and reassembly
146  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *payload,
147  size_t payloadOffset, size_t pathMtu, uint_t flags);
148 
150  size_t ipPacketOffset, size_t fragHeaderOffset, size_t nextHeaderOffset);
151 
152 void ipv6FragTick(NetInterface *interface);
153 
155  Ipv6Header *packet, Ipv6FragmentHeader *header);
156 
157 void ipv6FlushFragQueue(NetInterface *interface);
158 
159 Ipv6HoleDesc *ipv6FindHole(Ipv6FragDesc *frag, uint16_t offset);
160 void ipv6DumpHoleList(Ipv6FragDesc *frag);
161 
162 //C++ guard
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif
IPv6 (Internet Protocol Version 6)
systime_t timestamp
Time at which the first fragment was received.
Definition: ipv6_frag.h:132
uint16_t next
Definition: ipv6_frag.h:104
systime_t ipv6FragTickCounter
Definition: ipv6_frag.c:47
size_t unfragPartLength
Length of the unfragmentable part.
Definition: ipv6_frag.h:134
uint16_t last
Definition: ipv6_frag.h:103
void ipv6FragTick(NetInterface *interface)
Fragment reassembly timeout handler.
Definition: ipv6_frag.c:527
size_t fragPartLength
Length of the fragmentable part.
Definition: ipv6_frag.h:135
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
#define Ipv6Header
Definition: ipv6.h:36
uint16_t first
Definition: ipv6_frag.h:102
#define N(size)
Definition: net_mem.h:64
uint8_t ipPacket[]
Definition: ndp.h:430
error_t ipv6FragmentDatagram(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *payload, size_t payloadOffset, size_t pathMtu, uint_t flags)
Fragment IPv6 datagram into smaller packets.
Definition: ipv6_frag.c:61
uint16_t firstHole
Index of the first hole.
Definition: ipv6_frag.h:136
Reassembly buffer.
Definition: ipv6_frag.h:118
error_t
Error codes.
Definition: error.h:42
Structure describing a chunk of data.
Definition: net_mem.h:76
Ipv6FragDesc * ipv6SearchFragQueue(NetInterface *interface, Ipv6Header *packet, Ipv6FragmentHeader *header)
Search for a matching datagram in the reassembly queue.
Definition: ipv6_frag.c:595
#define Ipv6PseudoHeader
Definition: ipv6.h:42
Ipv6HoleDesc * ipv6FindHole(Ipv6FragDesc *frag, uint16_t offset)
Retrieve hole descriptor.
Definition: ipv6_frag.c:719
#define NetInterface
Definition: net.h:36
#define IPV6_MAX_FRAG_DATAGRAM_SIZE
Definition: ipv6_frag.h:69
__start_packed struct _Ipv4Header __end_packed
Fragmented packet descriptor.
Definition: ipv6_frag.h:130
__start_packed struct @188 Ipv6HoleDesc
Hole descriptor.
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:175
uint8_t flags
Definition: tcp.h:314
#define Ipv6FragmentHeader
Definition: ipv6.h:39
Ipv6ReassemblyBuffer buffer
Buffer containing the reassembled datagram.
Definition: ipv6_frag.h:137
void ipv6DumpHoleList(Ipv6FragDesc *frag)
Dump hole descriptor list.
Definition: ipv6_frag.c:731
void ipv6FlushFragQueue(NetInterface *interface)
Flush IPv6 reassembly queue.
Definition: ipv6_frag.c:698
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
uint32_t systime_t
Definition: compiler_port.h:46
uint32_t identification
Fragment identification field.
Definition: ipv6_frag.h:133