1
10
11
12
18
19
20
21
22
23
24
25
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
115
116
117
118
119
120
121
124
125
126
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
150
151
152
153
154
155
156
157
168
169
170
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
193
194
195
196
197
198
199
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
221
222
223
224
229
230
231
232
233
235
236
237
238
239
240
244
245
246
247
248
249
250
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
276
279
280
281
287
292
293
294
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
318
319
321
322
323
324
325
326
327
328
329
333
337
338
339
340
341
342
343
344
345
346
347
348
352
353
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
412
416
417
418
419
420
421
...
...
#define NX_SOURCE_CODE
#include "tx_api.h"
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_ipv6.h"
#include "nx_packet.h"
5 includes
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
#include "nx_icmpv6.h"
#endif
#if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_FRAGMENTATION)
...
VOID _nx_ipv6_fragment_process(struct NX_IP_DRIVER_STRUCT *driver_req_ptr, UINT mtu)
{
NX_PACKET *first_fragment, *source_packet, *previous_packet;
UCHAR *fragmentable_ptr, *last_header_location;
UINT packet_length, unfragmentable_size;
ULONG packet_id;
NX_IP_DRIVER driver_request;
NX_IP *ip_ptr;
UCHAR next_header;
UCHAR hdr_ext_len;
UINT fragment_offset = 0;
INT error = 0;
NX_IPV6_HEADER_FRAGMENT_OPTION *fragment_option;
INT last_fragment = 0;
NX_IPV6_HEADER *ipv6_header;
ULONG word_1;
ULONG val;
NX_PACKET_POOL *pool_ptr;
first_fragment = NX_NULL;
/* ... */
driver_request = *driver_req_ptr;
ip_ptr = driver_req_ptr -> nx_ip_driver_ptr;
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_total_fragment_requests++;/* ... */
#endif
/* ... */
packet_id = ip_ptr -> nx_ip_packet_id++;
NX_CHANGE_ULONG_ENDIAN(packet_id);
source_packet = driver_req_ptr -> nx_ip_driver_packet;
source_packet -> nx_packet_last = source_packet;
source_packet -> nx_packet_ip_header = source_packet -> nx_packet_prepend_ptr;
pool_ptr = source_packet -> nx_packet_pool_owner;
NX_PACKET_DEBUG(__FILE__, __LINE__, source_packet);
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (source_packet -> nx_packet_interface_capability_flag)
{
_nx_ip_packet_checksum_compute(source_packet);
}if (source_packet -> nx_packet_interface_capability_flag) { ... }
/* ... */#endif
fragmentable_ptr = source_packet -> nx_packet_prepend_ptr + sizeof(NX_IPV6_HEADER);
last_header_location = (source_packet -> nx_packet_prepend_ptr + 6);
next_header = *last_header_location;
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
/* ... */
if (mtu < NX_MINIMUM_IPV6_PATH_MTU)
{
mtu = NX_MINIMUM_IPV6_PATH_MTU;
}if (mtu < NX_MINIMUM_IPV6_PATH_MTU) { ... }
/* ... */
#endif
/* ... */
while ((next_header == NX_PROTOCOL_NEXT_HEADER_HOP_BY_HOP) ||
(next_header == NX_PROTOCOL_NEXT_HEADER_ROUTING))
{
hdr_ext_len = *(fragmentable_ptr + 1);
last_header_location = fragmentable_ptr;
next_header = *fragmentable_ptr;
fragmentable_ptr = NX_UCHAR_POINTER_ADD(fragmentable_ptr, ((hdr_ext_len + 1) << 3));
}while ((next_header == NX_PROTOCOL_NEXT_HEADER_HOP_BY_HOP) || (next_header == NX_PROTOCOL_NEXT_HEADER_ROUTING)) { ... }
*last_header_location = NX_PROTOCOL_NEXT_HEADER_FRAGMENT;
/* ... */
unfragmentable_size = (UINT)((ALIGN_TYPE)fragmentable_ptr - (ALIGN_TYPE)source_packet -> nx_packet_prepend_ptr);
packet_length = (UINT)(source_packet -> nx_packet_length - unfragmentable_size);
/* ... */
while (packet_length)
{
NX_PACKET *new_packet;
UINT fragment_size;
UINT remaining_bytes;
UINT nx_packet_size;
/* ... */
fragment_size = (mtu - unfragmentable_size) & 0xFFF8;
fragment_size -= (ULONG)sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION);
if (fragment_size >= packet_length)
{
fragment_size = packet_length;
last_fragment = 1;
}if (fragment_size >= packet_length) { ... }
packet_length -= fragment_size;
/* ... */
remaining_bytes = fragment_size + unfragmentable_size + (UINT)sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION) + NX_PHYSICAL_HEADER;
nx_packet_size = (UINT)((pool_ptr -> nx_packet_pool_payload_size) & 0xFFFC);
if (nx_packet_size > (mtu + NX_PHYSICAL_HEADER))
{
nx_packet_size = (mtu + NX_PHYSICAL_HEADER);
}if (nx_packet_size > (mtu + NX_PHYSICAL_HEADER)) { ... }
do
{
if (_nx_packet_allocate(pool_ptr, &new_packet,
0, TX_NO_WAIT))
{
error = 1;
break;
}if (_nx_packet_allocate(pool_ptr, &new_packet, 0, TX_NO_WAIT)) { ... }
NX_PACKET_DEBUG(__FILE__, __LINE__, new_packet);
new_packet -> nx_packet_ip_version = NX_IP_VERSION_V6;
if (first_fragment == NX_NULL)
{
first_fragment = new_packet;
first_fragment -> nx_packet_last = new_packet;
}if (first_fragment == NX_NULL) { ... }
else
{
first_fragment -> nx_packet_last -> nx_packet_next = new_packet;
first_fragment -> nx_packet_last = new_packet;
}else { ... }
/* ... */
if (nx_packet_size > remaining_bytes)
{
new_packet -> nx_packet_length = remaining_bytes;
remaining_bytes = 0;
}if (nx_packet_size > remaining_bytes) { ... }
else
{
new_packet -> nx_packet_length = nx_packet_size;
remaining_bytes -= nx_packet_size;
}else { ... }
...} while (remaining_bytes);
if (error)
{
break;
}if (error) { ... }
previous_packet = source_packet -> nx_packet_last;
source_packet -> nx_packet_last = source_packet;
source_packet -> nx_packet_prepend_ptr = source_packet -> nx_packet_ip_header;
first_fragment -> nx_packet_last = first_fragment;
first_fragment -> nx_packet_prepend_ptr += NX_PHYSICAL_HEADER;
first_fragment -> nx_packet_append_ptr += NX_PHYSICAL_HEADER;
if (_nx_ipv6_packet_copy(source_packet, first_fragment, unfragmentable_size))
{
break;
}if (_nx_ipv6_packet_copy(source_packet, first_fragment, unfragmentable_size)) { ... }
/* ... */
fragment_option = (NX_IPV6_HEADER_FRAGMENT_OPTION *)first_fragment -> nx_packet_last -> nx_packet_append_ptr;
first_fragment -> nx_packet_append_ptr += sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION);
first_fragment -> nx_packet_length += (ULONG)sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION);
fragment_option -> nx_ipv6_header_fragment_option_reserved = 0;
fragment_option -> nx_ipv6_header_fragment_option_next_header = next_header;
if (!last_fragment)
{
fragment_option -> nx_ipv6_header_fragment_option_offset_flag = (USHORT)(fragment_offset + 1);
}if (!last_fragment) { ... }
else
{
fragment_option -> nx_ipv6_header_fragment_option_offset_flag = (USHORT)fragment_offset;
}else { ... }
NX_CHANGE_USHORT_ENDIAN(fragment_option -> nx_ipv6_header_fragment_option_offset_flag);
fragment_option -> nx_ipv6_header_fragment_option_packet_id = packet_id;
source_packet -> nx_packet_last = previous_packet;
source_packet -> nx_packet_last -> nx_packet_prepend_ptr = fragmentable_ptr;
if (_nx_ipv6_packet_copy(source_packet, first_fragment, fragment_size))
{
break;
}if (_nx_ipv6_packet_copy(source_packet, first_fragment, fragment_size)) { ... }
/* ... */
ipv6_header = (NX_IPV6_HEADER *)first_fragment -> nx_packet_prepend_ptr;
val = ipv6_header -> nx_ip_header_word_1;
NX_CHANGE_ULONG_ENDIAN(val);
val = val & 0x0000FFFF;
word_1 = (ULONG)(((fragment_size + unfragmentable_size - sizeof(NX_IPV6_HEADER)) + sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION)) << 16);
word_1 = val | word_1;
NX_CHANGE_ULONG_ENDIAN(word_1);
ipv6_header -> nx_ip_header_word_1 = word_1;
fragmentable_ptr = source_packet -> nx_packet_last -> nx_packet_prepend_ptr;
fragment_offset += fragment_size;
first_fragment -> nx_packet_length = unfragmentable_size + fragment_size;
first_fragment -> nx_packet_length += (ULONG)sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION);
driver_request.nx_ip_driver_packet = first_fragment;
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_total_fragments_sent++;
ip_ptr -> nx_ip_total_packets_sent++;
ip_ptr -> nx_ip_total_bytes_sent += first_fragment -> nx_packet_length - (ULONG)sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION);/* ... */
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, source_packet);
(source_packet -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached -> nx_interface_link_driver_entry)(&driver_request);
first_fragment = NX_NULL;
}while (packet_length) { ... }
_nx_packet_transmit_release(source_packet);
/* ... */
if (first_fragment)
{
_nx_packet_release(first_fragment);
}if (first_fragment) { ... }
return;
}_nx_ipv6_fragment_process (struct NX_IP_DRIVER_STRUCT *driver_req_ptr, UINT mtu) { ... }
/* ... */
#endif