Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_packet.h"
#include "nx_icmpv4.h"
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
...
...
_nx_ip_fragment_cleanup(NX_IP *, NX_PACKET *)
...
_nx_ip_fragment_timeout_check(NX_IP *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesnetxduocommon/src/nx_ip_fragment_timeout_check.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Internet Protocol (IP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_ip.h" #include "nx_packet.h" #include "nx_icmpv4.h" #include "nx_ipv6.h" #include "nx_icmpv6.h" 6 includes #ifndef NX_DISABLE_FRAGMENTATION... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_ip_fragment_timeout_cleanup PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This internal function cleans up outstanding IP fragments. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP instance */ /* fragment The head of an IP fragment */ /* that needs to be cleaned. */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _nx_packet_release Release packet */ /* IPv6_Address_Type Find IPv6 address type. */ /* */ /* CALLED BY */ /* */ /* _nx_ip_fragment_timeout_check */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ static VOID _nx_ip_fragment_cleanup(NX_IP *ip_ptr, NX_PACKET *fragment) { NX_PACKET *next_fragment; #if !defined(NX_DISABLE_IPV4) && !defined(NX_DISABLE_ICMPV4_ERROR_MESSAGE) NX_IPV4_HEADER *ipv4_header; #endif /* !NX_DISABLE_IPV4 && !NX_DISABLE_ICMPV4_ERROR_MESSAGE */ #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_ICMPV6_ERROR_MESSAGE) NX_IPV6_HEADER_FRAGMENT_OPTION *fragment_option; NX_IPV6_HEADER *ipv6_header;/* ... */ #endif /* FEATURE_NX_IPV6 && !NX_DISABLE_ICMPV6_ERROR_MESSAGE */ #ifndef NX_DISABLE_IP_INFO /* Increment the re-assembly failures count. */ ip_ptr -> nx_ip_reassembly_failures++;/* ... */ #endif #if !defined(NX_DISABLE_IPV4) && !defined(NX_DISABLE_ICMPV4_ERROR_MESSAGE) /* If ICMPv4 is enabled, send Destination unreachable. */ if (fragment -> nx_packet_ip_version == NX_IP_VERSION_V4) { /* Setup header pointer for this packet. */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ ipv4_header = (NX_IPV4_HEADER *)fragment -> nx_packet_ip_header; /* Time Exceeded Message, RFC 792, P2. */ /* Check if the fragment zero is available. */ if ((ipv4_header -> nx_ip_header_word_1 & NX_IP_OFFSET_MASK) == 0) { /* Send a time exceeded message if fragmented datagram cannot complete the reassembly. */ NX_ICMPV4_SEND_TIME_EXCEED(ip_ptr, fragment, NX_ICMP_FRT_EXCEEDED_CODE); }if ((ipv4_header -> nx_ip_header_word_1 & NX_IP_OFFSET_MASK) == 0) { ... } }if (fragment -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... } /* ... */#endif /* !NX_DISABLE_IPV4 && !NX_DISABLE_ICMPV4_ERROR_MESSAGE */ #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_ICMPV6_ERROR_MESSAGE) /* If the packet is IPv6 type, we need to send out ICMP error message. */ if (fragment -> nx_packet_ip_version == NX_IP_VERSION_V6) { /* Send out ICMP Time Exceeded message, if the first fragment has been received as per RFC2460 4.5 *//* ... */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ fragment_option = (NX_IPV6_HEADER_FRAGMENT_OPTION *)fragment -> nx_packet_prepend_ptr; if ((fragment_option -> nx_ipv6_header_fragment_option_offset_flag & 0xFFF8) == 0) { /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ ipv6_header = (NX_IPV6_HEADER *)fragment -> nx_packet_ip_header; /* First fragment has been received. Send ICMP error message, if the destination is not multicast. *//* ... */ if (!(IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ADDRESS_MULTICAST)) { /* Cover offset flag field. */ NX_CHANGE_USHORT_ENDIAN(fragment_option -> nx_ipv6_header_fragment_option_offset_flag); NX_ICMPV6_SEND_TIME_EXCEED(ip_ptr, fragment, 1); }if (!(IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ADDRESS_MULTICAST)) { ... } }if ((fragment_option -> nx_ipv6_header_fragment_option_offset_flag & 0xFFF8) == 0) { ... } }if (fragment -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... } /* ... */#endif /* FEATURE_NX_IPV6 && !NX_DISABLE_ICMPV6_ERROR_MESSAGE */ /* Walk the chain of fragments for this fragment re-assembly. */ do { #ifndef NX_DISABLE_IP_INFO /* Increment the IP receive packets dropped count. */ ip_ptr -> nx_ip_receive_packets_dropped++;/* ... */ #endif /* Pickup the next fragment. */ next_fragment = fragment -> nx_packet_union_next.nx_packet_fragment_next; /* Reset tcp_queue_next before releasing. */ /*lint -e{923} suppress cast of ULONG to pointer. */ fragment -> nx_packet_union_next.nx_packet_tcp_queue_next = (NX_PACKET *)NX_PACKET_ALLOCATED; /* Release this fragment. */ _nx_packet_release(fragment); /* Reassign the fragment pointer. */ fragment = next_fragment; ...} while (fragment); }{ ... } ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_ip_fragment_timeout_check PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function checks for timeout conditions on the first fragment */ /* in the IP re-assembly list. If the head pointer is the same */ /* between execution of this routine, the head fragment is deleted and */ /* its packets are released. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP instance */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _nx_packet_release Release packet */ /* */ /* CALLED BY */ /* */ /* Application */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ VOID _nx_ip_fragment_timeout_check(NX_IP *ip_ptr) { NX_PACKET *fragment; NX_PACKET *next_fragment; NX_PACKET *previous_fragment = NX_NULL; /* Set a pointer to the head packet of the fragmented packet queue. */ fragment = ip_ptr -> nx_ip_fragment_assembly_head; /* Loop through all the fragmented packets in the queue. */ while (fragment) { /* Check if the timeout has expired. */ if (fragment -> nx_packet_reassembly_time == 0) { /* Timeout occured. */ next_fragment = fragment -> nx_packet_queue_next; /* Remove the packet from the queue and connect the linked list around it. */ if (previous_fragment == NX_NULL) { ip_ptr -> nx_ip_fragment_assembly_head = next_fragment; }if (previous_fragment == NX_NULL) { ... } else { previous_fragment -> nx_packet_queue_next = next_fragment; }else { ... } /* Send out an error message, release the packet fragments in this chain. */ _nx_ip_fragment_cleanup(ip_ptr, fragment); /* If this was the last one in the queue, reset the tail to the previous fragment. *//* ... */ if (fragment == ip_ptr -> nx_ip_fragment_assembly_tail) { ip_ptr -> nx_ip_fragment_assembly_tail = previous_fragment; }if (fragment == ip_ptr -> nx_ip_fragment_assembly_tail) { ... } /* Get the next fragmented packet awaiting assembly. */ fragment = next_fragment; }if (fragment -> nx_packet_reassembly_time == 0) { ... } else { /* Decrement the time remaining to assemble the whole packet. */ fragment -> nx_packet_reassembly_time--; /* Get the next packet fragment. */ previous_fragment = fragment; fragment = fragment -> nx_packet_queue_next; }else { ... } }while (fragment) { ... } }{ ... } #endif/* ... */ /* NX_DISABLE_FRAGMENTATION */