1
10
11
12
13
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
113
114
115
116
117
118
119
120
121
122
123
126
127
128
129
130
131
132
133
134
135
136
137
141
142
143
144
145
146
147
148
149
153
154
155
156
157
158
159
160
161
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
213
214
215
222
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
269
270
271
272
273
274
275
276
277
278
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
314
315
316
317
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
342
353
354
355
356
357
358
359
360
361
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
389
390
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
454
455
456
460
461
462
463
464
465
466
467
468
469
471
472
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
535
536
541
542
546
547
548
549
552
553
554
555
556
557
558
559
561
562
563
564
565
566
567
568
569
570
574
575
576
577
578
579
580
581
582
583
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
#include "nx_ip.h"
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
5 includes
#ifdef FEATURE_NX_IPV6
#ifndef NX_DISABLE_ICMPV6_ROUTER_ADVERTISEMENT_PROCESS
...
VOID _nx_icmpv6_process_ra(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
{
INT router_type;
INT packet_length;
INT prefix_length;
UINT i;
UINT status;
ULONG time_val;
ND_CACHE_ENTRY *nd_entry;
NX_ICMPV6_HEADER *header_ptr;
NX_ICMPV6_RA *ra_ptr;
NX_ICMPV6_OPTION *option_ptr;
NX_ICMPV6_OPTION_PREFIX *prefix_ptr;
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
NX_ICMPV6_OPTION_MTU *mtu_ptr = NULL;
#endif
NX_INTERFACE *if_ptr;
NX_IPV6_HEADER *ipv6_header;
NX_IPV6_DEFAULT_ROUTER_ENTRY *rt_entry;
#ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
UINT interface_index;
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
nd_entry = NX_NULL;
header_ptr = (NX_ICMPV6_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
if (_nx_icmpv6_validate_ra(packet_ptr) != NX_SUCCESS)
{
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_icmp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (_nx_icmpv6_validate_ra(packet_ptr) != NX_SUCCESS) { ... }
ra_ptr = (NX_ICMPV6_RA *)header_ptr;
if (ip_ptr -> nx_icmpv6_ra_flag_callback)
{
ip_ptr -> nx_icmpv6_ra_flag_callback(ip_ptr, (UINT)ra_ptr -> nx_icmpv6_ra_flag);
}if (ip_ptr -> nx_icmpv6_ra_flag_callback) { ... }
ipv6_header = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_ip_header;
if_ptr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached;
/* ... */
if (ra_ptr -> nx_icmpv6_ra_router_lifetime == 0)
{
NXD_ADDRESS router_address;
/* ... */
router_address.nxd_ip_version = NX_IP_VERSION_V6;
router_address.nxd_ip_address.v6[0] = ipv6_header -> nx_ip_header_source_ip[0];
router_address.nxd_ip_address.v6[1] = ipv6_header -> nx_ip_header_source_ip[1];
router_address.nxd_ip_address.v6[2] = ipv6_header -> nx_ip_header_source_ip[2];
router_address.nxd_ip_address.v6[3] = ipv6_header -> nx_ip_header_source_ip[3];
_nxd_ipv6_default_router_delete(ip_ptr, &router_address);
}if (ra_ptr -> nx_icmpv6_ra_router_lifetime == 0) { ... }
if (ra_ptr -> nx_icmpv6_ra_retrans_time)
{
time_val = ra_ptr -> nx_icmpv6_ra_retrans_time;
NX_CHANGE_ULONG_ENDIAN(time_val);
ip_ptr -> nx_ipv6_retrans_timer_ticks = time_val * NX_IP_FAST_TIMER_RATE / 1000;
if (ip_ptr -> nx_ipv6_retrans_timer_ticks == 0)
{
ip_ptr -> nx_ipv6_retrans_timer_ticks = 1;
}if (ip_ptr -> nx_ipv6_retrans_timer_ticks == 0) { ... }
}if (ra_ptr -> nx_icmpv6_ra_retrans_time) { ... }
if (ra_ptr -> nx_icmpv6_ra_reachable_time)
{
time_val = ra_ptr -> nx_icmpv6_ra_reachable_time;
NX_CHANGE_ULONG_ENDIAN(time_val);
ip_ptr -> nx_ipv6_reachable_timer = time_val / 1000;
if (ip_ptr -> nx_ipv6_reachable_timer == 0)
{
ip_ptr -> nx_ipv6_reachable_timer = 1;
}if (ip_ptr -> nx_ipv6_reachable_timer == 0) { ... }
}if (ra_ptr -> nx_icmpv6_ra_reachable_time) { ... }
if (IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ALL_NODE_MCAST)
{
/* ... */
router_type = NX_IPV6_ROUTE_TYPE_UNSOLICITATED;
}if (IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ALL_NODE_MCAST) { ... }
else
{
router_type = NX_IPV6_ROUTE_TYPE_SOLICITATED;
}else { ... }
packet_length = (INT)packet_ptr -> nx_packet_length - (INT)sizeof(NX_ICMPV6_RA);
option_ptr = (NX_ICMPV6_OPTION *)NX_UCHAR_POINTER_ADD(ra_ptr, sizeof(NX_ICMPV6_RA));
while (packet_length > 0)
{
if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_PREFIX_INFO)
{
if ((UINT)(option_ptr -> nx_icmpv6_option_length << 3) < sizeof(NX_ICMPV6_OPTION_PREFIX))
{
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_icmp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if ((UINT)(option_ptr -> nx_icmpv6_option_length << 3) < sizeof(NX_ICMPV6_OPTION_PREFIX)) { ... }
prefix_ptr = (NX_ICMPV6_OPTION_PREFIX *)option_ptr;
NX_IPV6_ADDRESS_CHANGE_ENDIAN(prefix_ptr -> nx_icmpv6_option_prefix);
if ((prefix_ptr -> nx_icmpv6_option_prefix[0] & (ULONG)0xFFC00000) == (ULONG)0xFE800000)
{
/* ... */
packet_length -= (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));
continue;
}if ((prefix_ptr -> nx_icmpv6_option_prefix[0] & (ULONG)0xFFC00000) == (ULONG)0xFE800000) { ... }
/* ... */
NX_CHANGE_ULONG_ENDIAN(prefix_ptr -> nx_icmpv6_option_prefix_valid_lifetime);
NX_CHANGE_ULONG_ENDIAN(prefix_ptr -> nx_icmpv6_option_prefix_preferred_lifetime);
if (prefix_ptr -> nx_icmpv6_option_prefix_preferred_lifetime > prefix_ptr -> nx_icmpv6_option_prefix_valid_lifetime)
{
packet_length -= (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));
continue;
}if (prefix_ptr -> nx_icmpv6_option_prefix_preferred_lifetime > prefix_ptr -> nx_icmpv6_option_prefix_valid_lifetime) { ... }
if (prefix_ptr -> nx_icmpv6_option_prefix_flag & 0x80)
{
prefix_length = prefix_ptr -> nx_icmpv6_option_prefix_length;
if (prefix_ptr -> nx_icmpv6_option_prefix_valid_lifetime == 0)
{
_nx_ipv6_prefix_list_delete(ip_ptr, prefix_ptr -> nx_icmpv6_option_prefix, prefix_length);
}if (prefix_ptr -> nx_icmpv6_option_prefix_valid_lifetime == 0) { ... }
else
{
/* ... */
status = _nx_ipv6_prefix_list_add_entry(ip_ptr, prefix_ptr -> nx_icmpv6_option_prefix,
(ULONG)prefix_length, prefix_ptr -> nx_icmpv6_option_prefix_valid_lifetime);
if ((prefix_ptr -> nx_icmpv6_option_prefix_flag & 0x40) &&
(prefix_ptr -> nx_icmpv6_option_prefix_length == (128 - NX_IPV6_HOST_ID_LENGTH)) &&
(status == NX_SUCCESS))
{
UINT first_unused = NX_MAX_IPV6_ADDRESSES;
ULONG word2, word3;
ULONG address[4];
NXD_IPV6_ADDRESS *ipv6_address;
/* ... */
for (i = 0; i < NX_MAX_IPV6_ADDRESSES; i++)
{
if (ip_ptr -> nx_ipv6_address[i].nxd_ipv6_address_valid == NX_FALSE)
{
first_unused = i;
break;
}if (ip_ptr -> nx_ipv6_address[i].nxd_ipv6_address_valid == NX_FALSE) { ... }
}for (i = 0; i < NX_MAX_IPV6_ADDRESSES; i++) { ... }
if ((first_unused != NX_MAX_IPV6_ADDRESSES)
#ifdef NX_IPV6_STATELESS_AUTOCONFIG_CONTROL
&& (if_ptr -> nx_ipv6_stateless_address_autoconfig_status == NX_STATELESS_ADDRESS_AUTOCONFIG_ENABLED)
#endif
)
{
/* ... */
ipv6_address = &ip_ptr -> nx_ipv6_address[first_unused];
word2 = if_ptr -> nx_interface_physical_address_msw << 16 |
((if_ptr -> nx_interface_physical_address_lsw & 0xFF000000) >> 16) | 0xFF;
word2 = (word2 & 0xFDFFFFFF) | (~(word2 | 0xFDFFFFFF));
word3 = (if_ptr -> nx_interface_physical_address_lsw & 0x00FFFFFF) | 0xFE000000;
ipv6_address -> nxd_ipv6_address_valid = NX_TRUE;
ipv6_address -> nxd_ipv6_address_type = NX_IP_VERSION_V6;
ipv6_address -> nxd_ipv6_address_attached = if_ptr;
ipv6_address -> nxd_ipv6_address[0] = prefix_ptr -> nx_icmpv6_option_prefix[0];
ipv6_address -> nxd_ipv6_address[1] = prefix_ptr -> nx_icmpv6_option_prefix[1];
ipv6_address -> nxd_ipv6_address[2] = word2;
ipv6_address -> nxd_ipv6_address[3] = word3;
ipv6_address -> nxd_ipv6_address_next = if_ptr -> nxd_interface_ipv6_address_list_head;
if_ptr -> nxd_interface_ipv6_address_list_head = ipv6_address;
#ifndef NX_DISABLE_IPV6_DAD
ipv6_address -> nxd_ipv6_address_state = NX_IPV6_ADDR_STATE_TENTATIVE;/* ... */
#else
ipv6_address -> nxd_ipv6_address_state = NX_IPV6_ADDR_STATE_VALID;/* ... */
#endif
SET_SOLICITED_NODE_MULTICAST_ADDRESS(address, ipv6_address -> nxd_ipv6_address);
_nx_ipv6_multicast_join(ip_ptr, address, ipv6_address -> nxd_ipv6_address_attached);
ipv6_address -> nxd_ipv6_address_prefix_length = (UCHAR)prefix_length;
ipv6_address -> nxd_ipv6_address_ConfigurationMethod = NX_IPV6_ADDRESS_BASED_ON_INTERFACE;
#ifndef NX_DISABLE_IPV6_DAD
ipv6_address -> nxd_ipv6_address_DupAddrDetectTransmit = NX_IPV6_DAD_TRANSMITS - 1;
#endif
#ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
if (ip_ptr -> nx_ipv6_address_change_notify)
{
interface_index = if_ptr -> nx_interface_index;
(ip_ptr -> nx_ipv6_address_change_notify)(ip_ptr, NX_IPV6_ADDRESS_STATELESS_AUTO_CONFIG, interface_index,
first_unused, &ipv6_address -> nxd_ipv6_address[0]);
}if (ip_ptr -> nx_ipv6_address_change_notify) { ... }
/* ... */#endif
}if ((first_unused != NX_MAX_IPV6_ADDRESSES) #ifdef NX_IPV6_STATELESS_AUTOCONFIG_CONTROL && (if_ptr -> nx_ipv6_stateless_address_autoconfig_status == NX_STATELESS_ADDRESS_AUTOCONFIG_ENABLED) #endif /* NX_IPV6_STATELESS_AUTOCONFIG_CONTROL */) { ... }
}if ((prefix_ptr -> nx_icmpv6_option_prefix_flag & 0x40) && (prefix_ptr -> nx_icmpv6_option_prefix_length == (128 - NX_IPV6_HOST_ID_LENGTH)) && (status == NX_SUCCESS)) { ... }
}else { ... }
}if (prefix_ptr -> nx_icmpv6_option_prefix_flag & 0x80) { ... }
}if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_PREFIX_INFO) { ... }
else if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_SRC_LINK_ADDR)
{
status = _nx_nd_cache_find_entry(ip_ptr, ipv6_header -> nx_ip_header_source_ip, &nd_entry);
if (status != NX_SUCCESS)
{
_nx_nd_cache_add(ip_ptr, ipv6_header -> nx_ip_header_source_ip, if_ptr,
(CHAR *)&option_ptr -> nx_icmpv6_option_data, 0, ND_CACHE_STATE_STALE,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr, &nd_entry);
}if (status != NX_SUCCESS) { ... }
else
{
/* ... */
ULONG mac_msw, mac_lsw, new_msw, new_lsw;
UCHAR *new_mac = (UCHAR *)&option_ptr -> nx_icmpv6_option_data;
mac_msw = ((ULONG)(nd_entry -> nx_nd_cache_mac_addr[0]) << 8) | (nd_entry -> nx_nd_cache_mac_addr[1]);
mac_lsw = ((ULONG)(nd_entry -> nx_nd_cache_mac_addr[2]) << 24) | ((ULONG)(nd_entry -> nx_nd_cache_mac_addr[3]) << 16) |
((ULONG)(nd_entry -> nx_nd_cache_mac_addr[4]) << 8) | nd_entry -> nx_nd_cache_mac_addr[5];
new_msw = ((ULONG)(new_mac[0]) << 8) | (new_mac[1]);
new_lsw = ((ULONG)(new_mac[2]) << 24) | ((ULONG)(new_mac[3]) << 16) | ((ULONG)(new_mac[4]) << 8) | new_mac[5];
if ((mac_msw != new_msw) || (mac_lsw != new_lsw))
{
/* ... */
for (i = 0; i < 6; i++)
{
nd_entry -> nx_nd_cache_mac_addr[i] = new_mac[i];
}for (i = 0; i < 6; i++) { ... }
nd_entry -> nx_nd_cache_nd_status = ND_CACHE_STATE_STALE;
nd_entry -> nx_nd_cache_interface_ptr = if_ptr;
}if ((mac_msw != new_msw) || (mac_lsw != new_lsw)) { ... }
/* ... */
if (nd_entry -> nx_nd_cache_packet_waiting_head)
{
_nx_icmpv6_send_queued_packets(ip_ptr, nd_entry);
...}
}else { ... }
}else if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_SRC_LINK_ADDR) { ... }
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
else if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_MTU)
{
NX_IPV6_DESTINATION_ENTRY *dest_entry_ptr;
UINT mtu_size;
mtu_ptr = (NX_ICMPV6_OPTION_MTU *)option_ptr;
mtu_size = mtu_ptr -> nx_icmpv6_option_mtu_path_mtu;
NX_CHANGE_ULONG_ENDIAN(mtu_size);
if (mtu_size > if_ptr -> nx_interface_ip_mtu_size)
{
mtu_size = if_ptr -> nx_interface_ip_mtu_size;
}if (mtu_size > if_ptr -> nx_interface_ip_mtu_size) { ... }
_nx_icmpv6_dest_table_add(ip_ptr, ipv6_header -> nx_ip_header_source_ip, &dest_entry_ptr,
ipv6_header -> nx_ip_header_source_ip ,
mtu_size, NX_WAIT_FOREVER,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr);
}else if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_MTU) { ... }
/* ... */#endif
packet_length -= (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 (packet_length > 0) { ... }
if (ra_ptr -> nx_icmpv6_ra_router_lifetime)
{
NX_CHANGE_USHORT_ENDIAN(ra_ptr -> nx_icmpv6_ra_router_lifetime);
_nxd_ipv6_default_router_add_internal(ip_ptr, ipv6_header -> nx_ip_header_source_ip,
ra_ptr -> nx_icmpv6_ra_router_lifetime, if_ptr,
router_type, &rt_entry);
/* ... */
if (rt_entry && nd_entry)
{
rt_entry -> nx_ipv6_default_router_entry_neighbor_cache_ptr = (void *)nd_entry;
nd_entry -> nx_nd_cache_is_router = rt_entry;
}if (rt_entry && nd_entry) { ... }
if (ra_ptr -> nx_icmpv6_ra_hop_limit)
{
ip_ptr -> nx_ipv6_hop_limit = ra_ptr -> nx_icmpv6_ra_hop_limit;
}if (ra_ptr -> nx_icmpv6_ra_hop_limit) { ... }
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
/* ... */
if (mtu_ptr == 0)
{
NX_IPV6_DESTINATION_ENTRY *dest_entry_ptr;
/* ... */
_nx_icmpv6_dest_table_add(ip_ptr, ipv6_header -> nx_ip_header_source_ip, &dest_entry_ptr,
ipv6_header -> nx_ip_header_source_ip,
if_ptr -> nx_interface_ip_mtu_size, NX_WAIT_FOREVER,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr);
}if (mtu_ptr == 0) { ... }
/* ... */#endif
}if (ra_ptr -> nx_icmpv6_ra_router_lifetime) { ... }
#ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
if_ptr -> nx_ipv6_rtr_solicitation_count = 0;
/* ... */
#endif
_nx_packet_release(packet_ptr);
}_nx_icmpv6_process_ra (NX_IP *ip_ptr, NX_PACKET *packet_ptr) { ... }
/* ... */
#endif
/* ... */
#endif