1
10
13
14
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
110
111
112
113
114
115
116
119
120
121
122
123
124
125
126
127
128
135
136
137
138
139
140
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
182
183
184
185
186
187
188
189
190
191
192
193
194
199
204
205
206
207
208
209
211
212
216
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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
269
270
271
277
278
279
281
282
283
284
285
286
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
317
318
319
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
357
358
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
396
397
398
399
400
401
402
403
404
405
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_packet.h"
#ifndef NX_DISABLE_FRAGMENTATION...
...
VOID _nx_ip_fragment_packet(struct NX_IP_DRIVER_STRUCT *driver_req_ptr)
{
#ifndef NX_DISABLE_IPV4
UINT status;
ULONG checksum;
ULONG temp;
UCHAR *source_ptr;
ULONG remaining_bytes;
ULONG fragment_size;
ULONG copy_size;
ULONG copy_remaining_size;
ULONG fragment_offset = 0;
NX_IP_DRIVER driver_request;
NX_PACKET *source_packet;
NX_PACKET *fragment_packet;
NX_IPV4_HEADER *source_header_ptr;
NX_IPV4_HEADER *fragment_header_ptr;
NX_IP *ip_ptr;
#if defined(NX_DISABLE_IP_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY)
UINT compute_checksum = 1;
#endif
#ifdef NX_DISABLE_IP_TX_CHECKSUM
compute_checksum = 0;
#endif
/* ... */
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
source_packet = driver_req_ptr -> nx_ip_driver_packet;
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
source_header_ptr = (NX_IPV4_HEADER *)source_packet -> nx_packet_prepend_ptr;
/* ... */
NX_CHANGE_ULONG_ENDIAN(source_header_ptr -> nx_ip_header_word_0);
NX_CHANGE_ULONG_ENDIAN(source_header_ptr -> nx_ip_header_word_1);
NX_CHANGE_ULONG_ENDIAN(source_header_ptr -> nx_ip_header_word_2);
NX_CHANGE_ULONG_ENDIAN(source_header_ptr -> nx_ip_header_source_ip);
NX_CHANGE_ULONG_ENDIAN(source_header_ptr -> nx_ip_header_destination_ip);
remaining_bytes = (source_packet -> nx_packet_length - (ULONG)sizeof(NX_IPV4_HEADER));
source_ptr = source_packet -> nx_packet_prepend_ptr + sizeof(NX_IPV4_HEADER);
fragment_size = source_packet -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_ip_mtu_size - (ULONG)sizeof(NX_IPV4_HEADER);
fragment_size = (fragment_size / NX_IP_ALIGN_FRAGS) * NX_IP_ALIGN_FRAGS;
/* ... */
while (remaining_bytes)
{
status = _nx_packet_allocate(ip_ptr -> nx_ip_default_packet_pool, &fragment_packet,
NX_IPv4_PACKET, TX_NO_WAIT);
if (status)
{
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_fragment_failures++;
ip_ptr -> nx_ip_send_packets_dropped++;
ip_ptr -> nx_ip_transmit_resource_errors++;/* ... */
#endif
/* ... */
_nx_packet_transmit_release(driver_req_ptr -> nx_ip_driver_packet);
return;
}if (status) { ... }
NX_PACKET_DEBUG(__FILE__, __LINE__, fragment_packet);
fragment_packet -> nx_packet_address.nx_packet_interface_ptr = driver_req_ptr -> nx_ip_driver_packet -> nx_packet_address.nx_packet_interface_ptr;
if (remaining_bytes > fragment_size)
{
copy_remaining_size = fragment_size;
remaining_bytes -= fragment_size;
}if (remaining_bytes > fragment_size) { ... }
else
{
copy_remaining_size = remaining_bytes;
remaining_bytes = 0;
}else { ... }
while (copy_remaining_size)
{
/* ... */
if (copy_remaining_size > (ULONG)(source_packet -> nx_packet_append_ptr - source_ptr))
{
copy_size = (ULONG)(source_packet -> nx_packet_append_ptr - source_ptr);
}if (copy_remaining_size > (ULONG)(source_packet -> nx_packet_append_ptr - source_ptr)) { ... }
else
{
copy_size = copy_remaining_size;
}else { ... }
status = _nx_packet_data_append(fragment_packet, source_ptr, copy_size, ip_ptr -> nx_ip_default_packet_pool, NX_NO_WAIT);
if (status)
{
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_fragment_failures++;
ip_ptr -> nx_ip_send_packets_dropped++;
ip_ptr -> nx_ip_transmit_resource_errors++;/* ... */
#endif
/* ... */
_nx_packet_transmit_release(driver_req_ptr -> nx_ip_driver_packet);
_nx_packet_release(fragment_packet);
return;
}if (status) { ... }
copy_remaining_size -= copy_size;
if (copy_size == (ULONG)(source_packet -> nx_packet_append_ptr - source_ptr))
{
if (source_packet -> nx_packet_next)
{
source_packet = source_packet -> nx_packet_next;
source_ptr = source_packet -> nx_packet_prepend_ptr;
}if (source_packet -> nx_packet_next) { ... }
else if (remaining_bytes)
{
/* ... */
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_invalid_transmit_packets++;
ip_ptr -> nx_ip_fragment_failures++;/* ... */
#endif
/* ... */
_nx_packet_transmit_release(driver_req_ptr -> nx_ip_driver_packet);
_nx_packet_release(fragment_packet);
return;
}else if (remaining_bytes) { ... }
}if (copy_size == (ULONG)(source_packet -> nx_packet_append_ptr - source_ptr)) { ... }
else
{
source_ptr += copy_size;
}else { ... }
}while (copy_remaining_size) { ... }
fragment_packet -> nx_packet_prepend_ptr = fragment_packet -> nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER);
fragment_packet -> nx_packet_length += (ULONG)sizeof(NX_IPV4_HEADER);
fragment_header_ptr = (NX_IPV4_HEADER *)fragment_packet -> nx_packet_prepend_ptr;
fragment_header_ptr -> nx_ip_header_word_0 = (source_header_ptr -> nx_ip_header_word_0 & ~NX_LOWER_16_MASK) |
fragment_packet -> nx_packet_length;
fragment_header_ptr -> nx_ip_header_word_1 = source_header_ptr -> nx_ip_header_word_1 | (fragment_offset / 8);
fragment_header_ptr -> nx_ip_header_word_2 = source_header_ptr -> nx_ip_header_word_2 & ~NX_LOWER_16_MASK;
fragment_header_ptr -> nx_ip_header_source_ip = source_header_ptr -> nx_ip_header_source_ip;
fragment_header_ptr -> nx_ip_header_destination_ip = source_header_ptr -> nx_ip_header_destination_ip;
if (remaining_bytes)
{
fragment_header_ptr -> nx_ip_header_word_1 = fragment_header_ptr -> nx_ip_header_word_1 | NX_IP_MORE_FRAGMENT;
}if (remaining_bytes) { ... }
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (fragment_packet -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM)
{
compute_checksum = 0;
}if (fragment_packet -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM) { ... }
/* ... */#endif
#if defined(NX_DISABLE_IP_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY)
if (compute_checksum)
#endif
{
temp = fragment_header_ptr -> nx_ip_header_word_0;
checksum = (temp >> NX_SHIFT_BY_16) + (temp & NX_LOWER_16_MASK);
temp = fragment_header_ptr -> nx_ip_header_word_1;
checksum += (temp >> NX_SHIFT_BY_16) + (temp & NX_LOWER_16_MASK);
temp = fragment_header_ptr -> nx_ip_header_word_2;
checksum += (temp >> NX_SHIFT_BY_16);
temp = fragment_header_ptr -> nx_ip_header_source_ip;
checksum += (temp >> NX_SHIFT_BY_16) + (temp & NX_LOWER_16_MASK);
temp = fragment_header_ptr -> nx_ip_header_destination_ip;
checksum += (temp >> NX_SHIFT_BY_16) + (temp & NX_LOWER_16_MASK);
checksum = (checksum >> NX_SHIFT_BY_16) + (checksum & NX_LOWER_16_MASK);
checksum = (checksum >> NX_SHIFT_BY_16) + (checksum & NX_LOWER_16_MASK);
fragment_header_ptr -> nx_ip_header_word_2 = fragment_header_ptr -> nx_ip_header_word_2 | (NX_LOWER_16_MASK & (~checksum));
...}
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
else
{
fragment_packet -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM;
}else { ... }
/* ... */#endif
/* ... */
NX_CHANGE_ULONG_ENDIAN(fragment_header_ptr -> nx_ip_header_word_0);
NX_CHANGE_ULONG_ENDIAN(fragment_header_ptr -> nx_ip_header_word_1);
NX_CHANGE_ULONG_ENDIAN(fragment_header_ptr -> nx_ip_header_word_2);
NX_CHANGE_ULONG_ENDIAN(fragment_header_ptr -> nx_ip_header_source_ip);
NX_CHANGE_ULONG_ENDIAN(fragment_header_ptr -> nx_ip_header_destination_ip);
#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 += fragment_packet -> nx_packet_length - (ULONG)sizeof(NX_IPV4_HEADER);/* ... */
#endif
driver_request.nx_ip_driver_packet = fragment_packet;
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_IO_DRIVER_PACKET_SEND, ip_ptr, fragment_packet, fragment_packet -> nx_packet_length, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
NX_PACKET_DEBUG(__FILE__, __LINE__, fragment_packet);
(fragment_packet -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_link_driver_entry)(&driver_request);
fragment_offset += fragment_size;
}while (remaining_bytes) { ... }
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_successful_fragment_requests++;/* ... */
#endif
_nx_packet_transmit_release(driver_req_ptr -> nx_ip_driver_packet);/* ... */
#else
NX_PARAMETER_NOT_USED(driver_req_ptr);
#endif
}{ ... }
#endif/* ... */