1
10
11
12
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
109
110
115
116
117
118
119
120
121
122
123
124
125
127
128
129
130
131
132
133
134
135
136
137
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
162
165
168
171
174
177
180
182
183
188
189
190
191
192
193
194
195
209
210
211
212
213
214
215
216
221
222
223
228
229
230
236
237
238
239
240
241
242
243
...
...
#define NX_SOURCE_CODE
#include "tx_api.h"
#include "nx_api.h"
#include "nx_ipv6.h"
#if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_FRAGMENTATION)
#define PACKET_MORE_TO_COPY 1
#define PACKET_ADD_BUFFER 2
#define PACKET_COPY_DONE 4
...
UINT _nx_ipv6_packet_copy(NX_PACKET *source_pkt_head, NX_PACKET *dest_pkt_head, UINT size)
{
UINT bytes_remaining;
NX_PACKET *source_pkt, *dest_pkt;
UINT bytes_to_copy;
ULONG *source_ptr, *dest_ptr;
UCHAR *source_byte, *dest_byte;
UINT flag;
bytes_remaining = size;
source_pkt = source_pkt_head -> nx_packet_last;
dest_pkt = dest_pkt_head -> nx_packet_last;
while (bytes_remaining > 0)
{
if ((source_pkt == NX_NULL) || (dest_pkt == NX_NULL))
{
return(NX_NOT_SUCCESSFUL);
}if ((source_pkt == NX_NULL) || (dest_pkt == NX_NULL)) { ... }
/* ... */
bytes_to_copy = bytes_remaining;
flag = PACKET_COPY_DONE;
if (bytes_to_copy > (UINT)(source_pkt -> nx_packet_append_ptr - source_pkt -> nx_packet_prepend_ptr))
{
/* ... */
bytes_to_copy = (UINT)(source_pkt -> nx_packet_append_ptr - source_pkt -> nx_packet_prepend_ptr);
flag = PACKET_MORE_TO_COPY;
}if (bytes_to_copy > (UINT)(source_pkt -> nx_packet_append_ptr - source_pkt -> nx_packet_prepend_ptr)) { ... }
if (bytes_to_copy > (UINT)(dest_pkt -> nx_packet_data_end - dest_pkt -> nx_packet_append_ptr))
{
/* ... */
bytes_to_copy = (UINT)(dest_pkt -> nx_packet_data_end - dest_pkt -> nx_packet_append_ptr);
flag = PACKET_ADD_BUFFER;
}if (bytes_to_copy > (UINT)(dest_pkt -> nx_packet_data_end - dest_pkt -> nx_packet_append_ptr)) { ... }
dest_ptr = (ULONG *)dest_pkt -> nx_packet_append_ptr;
dest_pkt -> nx_packet_append_ptr += bytes_to_copy;
dest_pkt -> nx_packet_length -= bytes_to_copy;
source_ptr = (ULONG *)source_pkt -> nx_packet_prepend_ptr;
source_pkt -> nx_packet_prepend_ptr += bytes_to_copy;
while (bytes_to_copy)
{
switch (bytes_to_copy >> 2)
{
default:
*dest_ptr++ = *source_ptr++;
default
case 7:
*dest_ptr++ = *source_ptr++;
case 7:
case 6:
*dest_ptr++ = *source_ptr++;
case 6:
case 5:
*dest_ptr++ = *source_ptr++;
case 5:
case 4:
*dest_ptr++ = *source_ptr++;
case 4:
case 3:
*dest_ptr++ = *source_ptr++;
case 3:
case 2:
*dest_ptr++ = *source_ptr++;
case 2:
case 1:
*dest_ptr++ = *source_ptr++;case 1:
}switch (bytes_to_copy >> 2) { ... }
if (bytes_to_copy >= 32)
{
bytes_to_copy -= 32;
bytes_remaining -= 32;
}if (bytes_to_copy >= 32) { ... }
else
{
source_byte = (UCHAR *)source_ptr;
dest_byte = (UCHAR *)dest_ptr;
switch (bytes_to_copy & 3)
{
case 3:
*dest_byte++ = *source_byte++;
case 3:
case 2:
*dest_byte++ = *source_byte++;
case 2:
case 1:
*dest_byte++ = *source_byte++;
break;case 1:
default:
break;default
}switch (bytes_to_copy & 3) { ... }
bytes_remaining -= bytes_to_copy;
bytes_to_copy = 0;
}else { ... }
}while (bytes_to_copy) { ... }
if (flag & PACKET_MORE_TO_COPY)
{
source_pkt_head -> nx_packet_last = source_pkt -> nx_packet_next;
source_pkt = source_pkt_head -> nx_packet_last;
}if (flag & PACKET_MORE_TO_COPY) { ... }
if (flag & PACKET_ADD_BUFFER)
{
dest_pkt_head -> nx_packet_last = dest_pkt -> nx_packet_next;
dest_pkt = dest_pkt -> nx_packet_next;
}if (flag & PACKET_ADD_BUFFER) { ... }
if (flag & PACKET_COPY_DONE)
{
break;
}if (flag & PACKET_COPY_DONE) { ... }
}while (bytes_remaining > 0) { ... }
return(NX_SUCCESS);
}_nx_ipv6_packet_copy (NX_PACKET *source_pkt_head, NX_PACKET *dest_pkt_head, UINT size) { ... }
/* ... */
#endif