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
108
109
110
111
112
113
114
115
116
117
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
141
142
143
144
145
146
147
148
149
150
155
156
157
158
169
170
171
172
174
175
176
177
178
179
180
181
182
183
185
186
187
188
191
192
193
194
195
196
197
198
199
200
201
202
203
204
211
212
213
214
215
216
217
218
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
275
276
277
278
283
284
285
286
287
288
289
290
299
300
301
302
303
304
305
306
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
332
333
334
335
336
337
338
339
340
342
343
344
345
346
347
348
349
350
356
357
358
359
360
361
362
363
364
365
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
403
404
408
409
410
411
412
413
414
415
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
#ifdef FEATURE_NX_IPV6
...
VOID _nx_icmpv6_process_na(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
{
ND_CACHE_ENTRY *nd_entry = NX_NULL;
NX_ICMPV6_ND *nd_ptr = (NX_ICMPV6_ND *)(packet_ptr -> nx_packet_prepend_ptr);
NX_ICMPV6_OPTION *option_ptr = NX_NULL;
INT error = 0;
INT lla_same = 0;
UINT option_length;
NX_IPV6_HEADER *ipv6_header_ptr;
#ifndef NX_DISABLE_IPV6_DAD
UINT i;
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
NX_IPV6_ADDRESS_CHANGE_ENDIAN(nd_ptr -> nx_icmpv6_nd_targetAddress);
NX_CHANGE_ULONG_ENDIAN(nd_ptr -> nx_icmpv6_nd_flag);
if (_nx_icmpv6_validate_neighbor_message(packet_ptr) != NX_SUCCESS)
{
error = 1;
}if (_nx_icmpv6_validate_neighbor_message(packet_ptr) != NX_SUCCESS) { ... }
else
{
ipv6_header_ptr = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_ip_header;
option_ptr = (NX_ICMPV6_OPTION *)NX_UCHAR_POINTER_ADD(nd_ptr, sizeof(NX_ICMPV6_ND));
option_length = (UINT)packet_ptr -> nx_packet_length - (UINT)sizeof(NX_ICMPV6_ND);
while (option_length > 0)
{
if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_TRG_LINK_ADDR)
{
break;
}if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_TRG_LINK_ADDR) { ... }
option_length -= ((UINT)(option_ptr -> nx_icmpv6_option_length) << 3);
option_ptr = (NX_ICMPV6_OPTION *)NX_UCHAR_POINTER_ADD(option_ptr, ((option_ptr -> nx_icmpv6_option_length) << 3));
}while (option_length > 0) { ... }
if (option_length == 0)
{
option_ptr = NX_NULL;
}if (option_length == 0) { ... }
if ((ipv6_header_ptr -> nx_ip_header_destination_ip[0] & (ULONG)0xFF000000) == (ULONG)0xFF000000)
{
if (!option_ptr)
{
error = 1;
}if (!option_ptr) { ... }
}if ((ipv6_header_ptr -> nx_ip_header_destination_ip[0] & (ULONG)0xFF000000) == (ULONG)0xFF000000) { ... }
#ifndef NX_DISABLE_IPV6_DAD
/* ... */
for (i = 0; i < NX_MAX_IPV6_ADDRESSES; i++)
{
if (CHECK_IPV6_ADDRESSES_SAME(ip_ptr -> nx_ipv6_address[i].nxd_ipv6_address,
nd_ptr -> nx_icmpv6_nd_targetAddress))
{
if (ip_ptr -> nx_ipv6_address[i].nxd_ipv6_address_state == NX_IPV6_ADDR_STATE_TENTATIVE)
{
/* ... */
_nx_icmpv6_DAD_failure(ip_ptr, &ip_ptr -> nx_ipv6_address[i]);
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_icmp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (ip_ptr -> nx_ipv6_address[i].nxd_ipv6_address_state == NX_IPV6_ADDR_STATE_TENTATIVE) { ... }
break;
}if (CHECK_IPV6_ADDRESSES_SAME(ip_ptr -> nx_ipv6_address[i].nxd_ipv6_address, nd_ptr -> nx_icmpv6_nd_targetAddress)) { ... }
}for (i = 0; i < NX_MAX_IPV6_ADDRESSES; i++) { ... }
/* ... */#endif
if (_nx_nd_cache_find_entry(ip_ptr, nd_ptr -> nx_icmpv6_nd_targetAddress, &nd_entry) != NX_SUCCESS)
{
/* ... */
error = 1;
}if (_nx_nd_cache_find_entry(ip_ptr, nd_ptr -> nx_icmpv6_nd_targetAddress, &nd_entry) != NX_SUCCESS) { ... }
}else { ... }
if (error)
{
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_icmp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (error) { ... }
if (option_ptr)
{
USHORT *new_lla, *lla;
new_lla = (USHORT *)&option_ptr -> nx_icmpv6_option_data;
lla = (USHORT *)nd_entry -> nx_nd_cache_mac_addr;
if ((new_lla[0] == lla[0]) && (new_lla[1] == lla[1]) && (new_lla[2] == lla[2]))
{
lla_same = 1;
}if ((new_lla[0] == lla[0]) && (new_lla[1] == lla[1]) && (new_lla[2] == lla[2])) { ... }
}if (option_ptr) { ... }
if (nd_ptr -> nx_icmpv6_nd_flag & 0x80000000)
{
if (nd_entry -> nx_nd_cache_is_router == NX_NULL)
{
NX_IPV6_DEFAULT_ROUTER_ENTRY *rt_entry;
rt_entry =
_nxd_ipv6_find_default_router_from_address(ip_ptr, nd_ptr -> nx_icmpv6_nd_targetAddress);
if (rt_entry)
{
nd_entry -> nx_nd_cache_is_router = rt_entry;
rt_entry -> nx_ipv6_default_router_entry_neighbor_cache_ptr = (VOID *)nd_entry;
}if (rt_entry) { ... }
}if (nd_entry -> nx_nd_cache_is_router == NX_NULL) { ... }
}if (nd_ptr -> nx_icmpv6_nd_flag & 0x80000000) { ... }
else
{
/* ... */
if (nd_entry -> nx_nd_cache_is_router)
{
NXD_ADDRESS router_address;
UINT clear_router_flag = 1;
if (option_ptr && !lla_same)
{
if ((nd_ptr -> nx_icmpv6_nd_flag & 0x20000000) == 0)
{
clear_router_flag = 0;
}if ((nd_ptr -> nx_icmpv6_nd_flag & 0x20000000) == 0) { ... }
}if (option_ptr && !lla_same) { ... }
if (clear_router_flag)
{
/* ... */
nd_entry -> nx_nd_cache_is_router -> nx_ipv6_default_router_entry_neighbor_cache_ptr = NX_NULL;
router_address.nxd_ip_version = NX_IP_VERSION_V6;
router_address.nxd_ip_address.v6[0] = nd_ptr -> nx_icmpv6_nd_targetAddress[0];
router_address.nxd_ip_address.v6[1] = nd_ptr -> nx_icmpv6_nd_targetAddress[1];
router_address.nxd_ip_address.v6[2] = nd_ptr -> nx_icmpv6_nd_targetAddress[2];
router_address.nxd_ip_address.v6[3] = nd_ptr -> nx_icmpv6_nd_targetAddress[3];
_nxd_ipv6_default_router_delete(ip_ptr, &router_address);
nd_entry -> nx_nd_cache_is_router = NX_NULL;
}if (clear_router_flag) { ... }
}if (nd_entry -> nx_nd_cache_is_router) { ... }
}else { ... }
/* ... */
if ((nd_entry -> nx_nd_cache_nd_status == ND_CACHE_STATE_INCOMPLETE) ||
(nd_entry -> nx_nd_cache_nd_status == ND_CACHE_STATE_CREATED))
{
if (option_ptr)
{
/* ... */
_nx_nd_cache_add(ip_ptr, nd_ptr -> nx_icmpv6_nd_targetAddress,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached,
(CHAR *)&option_ptr -> nx_icmpv6_option_data, 0,
nd_ptr -> nx_icmpv6_nd_flag & 0x40000000 ? ND_CACHE_STATE_REACHABLE : ND_CACHE_STATE_STALE,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr, &nd_entry);
if (nd_entry -> nx_nd_cache_packet_waiting_head)
{
_nx_icmpv6_send_queued_packets(ip_ptr, nd_entry);
}if (nd_entry -> nx_nd_cache_packet_waiting_head) { ... }
}if (option_ptr) { ... }
_nx_packet_release(packet_ptr);
return;
}if ((nd_entry -> nx_nd_cache_nd_status == ND_CACHE_STATE_INCOMPLETE) || (nd_entry -> nx_nd_cache_nd_status == ND_CACHE_STATE_CREATED)) { ... }
if ((nd_ptr -> nx_icmpv6_nd_flag & 0x20000000) == 0 && option_ptr && (!lla_same))
{
/* ... */
if (nd_entry -> nx_nd_cache_nd_status == ND_CACHE_STATE_REACHABLE)
{
nd_entry -> nx_nd_cache_nd_status = ND_CACHE_STATE_STALE;
nd_entry -> nx_nd_cache_timer_tick = 0;
}if (nd_entry -> nx_nd_cache_nd_status == ND_CACHE_STATE_REACHABLE) { ... }
}if ((nd_ptr -> nx_icmpv6_nd_flag & 0x20000000) == 0 && option_ptr && (!lla_same)) { ... }
else
{
if (option_ptr && !lla_same)
{
USHORT *new_lla, *lla;
new_lla = (USHORT *)&option_ptr -> nx_icmpv6_option_data;
lla = (USHORT *)nd_entry -> nx_nd_cache_mac_addr;
lla[0] = new_lla[0];
lla[1] = new_lla[1];
lla[2] = new_lla[2];
}if (option_ptr && !lla_same) { ... }
if (nd_ptr -> nx_icmpv6_nd_flag & 0x40000000)
{
nd_entry -> nx_nd_cache_nd_status = ND_CACHE_STATE_REACHABLE;
nd_entry -> nx_nd_cache_timer_tick = ip_ptr -> nx_ipv6_reachable_timer;
...}
else if (option_ptr && (!lla_same))
{
nd_entry -> nx_nd_cache_nd_status = ND_CACHE_STATE_STALE;
nd_entry -> nx_nd_cache_timer_tick = 0;
...}
}else { ... }
_nx_packet_release(packet_ptr);
return;
}_nx_icmpv6_process_na (NX_IP *ip_ptr, NX_PACKET *packet_ptr) { ... }
/* ... */
#endif