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
105
106
108
109
110
111
112
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
155
156
157
158
159
160
161
162
163
164
165
172
173
174
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
214
215
216
217
218
219
220
221
222
223
224
225
226
232
233
234
236
237
238
239
240
241
242
243
244
251
252
253
254
255
256
257
258
265
266
267
268
269
270
271
272
273
274
275
276
288
289
290
291
292
293
294
295
296
297
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_packet.h"
#ifndef NX_DISABLE_IPV4...
...
VOID _nx_ip_forward_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
{
NX_IPV4_HEADER *ip_header_ptr;
NX_INTERFACE *outgoing_interface = NX_NULL;
ULONG next_hop_address = 0;
ULONG destination_ip;
ULONG time_to_live;
ULONG fragment_bit;
ULONG status;
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
UINT compute_checksum = 1;
#endif
ULONG checksum;
ULONG old_m;
ULONG new_m;
/* ... */
/* ... */
ip_header_ptr = (NX_IPV4_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
if ((ip_header_ptr -> nx_ip_header_destination_ip & NX_IP_CLASS_D_MASK) == NX_IP_CLASS_D_TYPE)
{
_nx_packet_release(packet_ptr);
return;
}if ((ip_header_ptr -> nx_ip_header_destination_ip & NX_IP_CLASS_D_MASK) == NX_IP_CLASS_D_TYPE) { ... }
if (((ip_header_ptr -> nx_ip_header_source_ip & 0xFFFF0000) == 0xA9FE0000) ||
((ip_header_ptr -> nx_ip_header_destination_ip & 0xFFFF0000) == 0xA9FE0000))
{
_nx_packet_release(packet_ptr);
return;
}if (((ip_header_ptr -> nx_ip_header_source_ip & 0xFFFF0000) == 0xA9FE0000) || ((ip_header_ptr -> nx_ip_header_destination_ip & 0xFFFF0000) == 0xA9FE0000)) { ... }
if (_nx_ip_route_find(ip_ptr, ip_header_ptr -> nx_ip_header_destination_ip, &outgoing_interface, &next_hop_address) == NX_SUCCESS)
{
/* ... */
packet_ptr -> nx_packet_ip_interface = outgoing_interface;
destination_ip = ip_header_ptr -> nx_ip_header_destination_ip;
time_to_live = ((ip_header_ptr -> nx_ip_header_word_2 & NX_IP_TIME_TO_LIVE_MASK) >> NX_IP_TIME_TO_LIVE_SHIFT) - 1;
fragment_bit = (ip_header_ptr -> nx_ip_header_word_1 & NX_DONT_FRAGMENT);
if (!time_to_live)
{
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_receive_packets_dropped++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (!time_to_live) { ... }
ip_header_ptr -> nx_ip_header_word_2 = (ip_header_ptr -> nx_ip_header_word_2 - 0x01000000);
/* ... */
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (packet_ptr -> nx_packet_ip_interface -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM)
{
compute_checksum = 0;
}if (packet_ptr -> nx_packet_ip_interface -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM) { ... }
/* ... */#endif
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (outgoing_interface -> nx_interface_ip_address == destination_ip)
{
packet_ptr -> nx_packet_interface_capability_flag &= (ULONG)(~NX_INTERFACE_CAPABILITY_IPV4_RX_CHECKSUM);
compute_checksum = 1;
}if (outgoing_interface -> nx_interface_ip_address == destination_ip) { ... }
/* ... */#endif
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (compute_checksum)
{
#endif
checksum = ip_header_ptr -> nx_ip_header_word_2 & NX_LOWER_16_MASK;
new_m = (ip_header_ptr -> nx_ip_header_word_2 & 0xFFFF0000) >> 16;
old_m = new_m + 0x0100;
/* ... */
checksum = ((~checksum) & 0xFFFF) + ((~old_m) & 0xFFFF) + new_m;
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
ip_header_ptr -> nx_ip_header_word_2 = ((ip_header_ptr -> nx_ip_header_word_2 & 0xFFFF0000) | ((~checksum) & NX_LOWER_16_MASK));
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
}if (compute_checksum) { ... }
else
{
ip_header_ptr -> nx_ip_header_word_2 = (ip_header_ptr -> nx_ip_header_word_2 & 0xFFFF0000);
packet_ptr -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM;
}else { ... }
#endif
/* ... */
NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_word_0);
NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_word_1);
NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_word_2);
NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_source_ip);
NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_destination_ip);
if (outgoing_interface -> nx_interface_ip_address == destination_ip)
{
_nx_ip_packet_deferred_receive(ip_ptr, packet_ptr);
return;
}if (outgoing_interface -> nx_interface_ip_address == destination_ip) { ... }
else
{
status = _nx_packet_data_adjust(packet_ptr, NX_PHYSICAL_HEADER);
if (status)
{
_nx_packet_release(packet_ptr);
return;
}if (status) { ... }
if (packet_ptr -> nx_packet_length <= packet_ptr -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_ip_mtu_size)
{
_nx_ip_driver_packet_send(ip_ptr, packet_ptr, destination_ip, fragment_bit, next_hop_address);
return;
}if (packet_ptr -> nx_packet_length <= packet_ptr -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_ip_mtu_size) { ... }
#ifndef NX_DISABLE_FRAGMENTATION
else
{
if ((ip_ptr -> nx_ip_fragment_processing) && (!(fragment_bit & NX_DONT_FRAGMENT)))
{
_nx_ip_fragment_forward_packet(ip_ptr, packet_ptr, destination_ip, NX_FRAGMENT_OKAY, next_hop_address);
return;
}if ((ip_ptr -> nx_ip_fragment_processing) && (!(fragment_bit & NX_DONT_FRAGMENT))) { ... }
}else { ... }
/* ... */#endif
}else { ... }
}if (_nx_ip_route_find(ip_ptr, ip_header_ptr -> nx_ip_header_destination_ip, &outgoing_interface, &next_hop_address) == NX_SUCCESS) { ... }
_nx_packet_release(packet_ptr);
return;
}{ ... }
/* ... */#endif