Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_ipv6.h"
#include "nx_icmp.h"
#include "nx_packet.h"
#include "nx_ipsec.h"
...
...
_nx_ip_dispatch_process(NX_IP *, NX_PACKET *, UINT)
Files
loading...
CodeScopeSTM32 Libraries and Samplesnetxduocommon/src/nx_ip_dispatch_process.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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
268
269
270
271
272
273
274
275
276
277
278
279
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
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
353
354
355
356
357
358
359
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Internet Protocol (IP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_ip.h" #include "nx_ipv6.h" #include "nx_icmp.h" #include "nx_packet.h" 5 includes #ifdef NX_IPSEC_ENABLE #include "nx_ipsec.h" #endif ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_ip_dispatch_process PORTABLE C */ /* 6.1.9 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function goes through IP header and option fields, and */ /* dispatches into various process routines depending on the header */ /* options. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP instance */ /* packet_ptr Incoming IP packet */ /* protocol The first protocol immediately*/ /* following IP header */ /* */ /* OUTPUT */ /* */ /* Status 0: do not drop packet */ /* 1: drop packet */ /* */ /* CALLS */ /* */ /* [nx_ip_icmpv6_packet_process] ICMPv6 header process */ /* [nx_ip_tcp_packet_receive] TCP packet process */ /* [nx_ip_udp_packet_receive] UDP packet process */ /* ICMP ping request */ /* _nx_ipv6_process_hop_by_hop_option IPv6 hop by hop option */ /* process */ /* NX_ICMPV6_SEND_PARAMETER_PROBELM Send ICMP parameter problem */ /* _nx_ipv6_process_routing_option IPv6 routing option process */ /* _nx_ipv6_process_fragment_option IPv6 fragment option process */ /* [nx_ipsec_authentication_header_receive] */ /* IPSec authentication header */ /* process */ /* [nx_ipsec_encapsulating_security_payload_receive */ /* IPSec encapsulating security */ /* payload process */ /* (ip_icmp_packet_receive) Receive a ICMP packet */ /* (ip_igmp_packet_receive) Receive a IGMP packet */ /* */ /* CALLED BY */ /* */ /* Application Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), fixed */ /* destination header check, */ /* resulting in version 6.1 */ /* 10-15-2021 Yuxin Zhou Modified comment(s), expanded */ /* protocols support for raw */ /* packet, */ /* resulting in version 6.1.9 */ /* */... /**************************************************************************/ UINT _nx_ip_dispatch_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT protocol) { UINT drop_packet; #ifdef FEATURE_NX_IPV6 NXD_IPV6_ADDRESS *incoming_addr; UINT next_option_offset; #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE UINT nx_packet_option_offset; #endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE *//* ... */ #endif /* FEATURE_NX_IPV6 */ #ifdef NX_IPSEC_ENABLE UINT ret; ULONG next_protocol = 0; NXD_ADDRESS src_addr, dest_addr; #ifndef NX_DISABLE_IPV4 NX_IPV4_HEADER *ipv4_header; #endif /* NX_DISABLE_IPV4 */ #ifdef FEATURE_NX_IPV6 NX_IPV6_HEADER *ipv6_header; NX_ICMPV6_HEADER *icmp_header_ptr;/* ... */ #endif /* FEATURE_NX_IPV6 *//* ... */ #endif /* NX_IPSEC_ENABLE */ /* Initialize local variables. */ drop_packet = 0; #ifdef FEATURE_NX_IPV6 next_option_offset = (UINT)sizeof(NX_IPV6_HEADER); incoming_addr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr;/* ... */ #endif /* FEATURE_NX_IPV6 */ /* Parse all options in the packet till we're done or an error is encountered. */ while (!drop_packet) { /* Add debug information. */ NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr); #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_ICMPV6_ERROR_MESSAGE) /* Set a local variable for convenience. */ nx_packet_option_offset = packet_ptr -> nx_packet_option_offset;/* ... */ #endif /* defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_ICMPV6_ERROR_MESSAGE) */ switch (protocol) { #ifdef FEATURE_NX_IPV6 case NX_PROTOCOL_NEXT_HEADER_HOP_BY_HOP: /* This should be the first header; if it is not, this is a malformed packet. */ if (packet_ptr -> nx_packet_option_state >= (UCHAR)HOP_BY_HOP_HEADER) { drop_packet = 1; #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 1, nx_packet_option_offset); #endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE */ }if (packet_ptr -> nx_packet_option_state >= (UCHAR)HOP_BY_HOP_HEADER) { ... } else { /* Start the option header handling. */ packet_ptr -> nx_packet_option_state = (UCHAR)HOP_BY_HOP_HEADER; /* Dispatch packet to the Option handler. */ drop_packet = _nx_ipv6_process_hop_by_hop_option(ip_ptr, packet_ptr); }else { ... } break; case NX_PROTOCOL_NEXT_HEADER_HOP_BY_HOP: case NX_PROTOCOL_NEXT_HEADER_DESTINATION: /* Invalid header option if we have already processed 1 destination option. */ if (packet_ptr -> nx_packet_destination_header >= 1) { /* If we already have processed one destination option, we expect this to be the second one. *//* ... */ if ((packet_ptr -> nx_packet_option_state < (UCHAR)DESTINATION_HEADER_1) || (packet_ptr -> nx_packet_destination_header > 1)) { drop_packet = 1; }if ((packet_ptr -> nx_packet_option_state < (UCHAR)DESTINATION_HEADER_1) || (packet_ptr -> nx_packet_destination_header > 1)) { ... } else { packet_ptr -> nx_packet_option_state = (UCHAR)DESTINATION_HEADER_2; }else { ... } }if (packet_ptr -> nx_packet_destination_header >= 1) { ... } else { /* This is the first time we encounter a destination header option. */ /* If we are before the routing header option, this must be the 1st one. Otherwise, it must be the 2nd one. *//* ... */ if (packet_ptr -> nx_packet_option_state < (UCHAR)ROUTING_HEADER) { packet_ptr -> nx_packet_option_state = (UCHAR)DESTINATION_HEADER_1; }if (packet_ptr -> nx_packet_option_state < (UCHAR)ROUTING_HEADER) { ... } else { packet_ptr -> nx_packet_option_state = (UCHAR)DESTINATION_HEADER_2; }else { ... } }else { ... } packet_ptr -> nx_packet_destination_header++; if (!drop_packet) { /* Proceed with hop by hop handling if there are no errors. */ drop_packet = _nx_ipv6_process_hop_by_hop_option(ip_ptr, packet_ptr); }if (!drop_packet) { ... } #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE else { /* Return an error message to the sender of the packet. */ NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 1, nx_packet_option_offset); }else { ... } /* ... */#endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE */ break; case NX_PROTOCOL_NEXT_HEADER_DESTINATION: case NX_PROTOCOL_NEXT_HEADER_ROUTING: if (packet_ptr -> nx_packet_option_state >= (UCHAR)ROUTING_HEADER) { #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 1, nx_packet_option_offset); #endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE */ drop_packet = 1; }if (packet_ptr -> nx_packet_option_state >= (UCHAR)ROUTING_HEADER) { ... } else { packet_ptr -> nx_packet_option_state = (UCHAR)ROUTING_HEADER; drop_packet = _nx_ipv6_process_routing_option(ip_ptr, packet_ptr); }else { ... } break; case NX_PROTOCOL_NEXT_HEADER_ROUTING: case NX_PROTOCOL_NEXT_HEADER_FRAGMENT: #ifndef NX_DISABLE_FRAGMENTATION if (packet_ptr -> nx_packet_option_state >= (UCHAR)FRAGMENT_HEADER) { #endif /* NX_DISABLE_FRAGMENTATION */ #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 1, nx_packet_option_offset); #endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE */ drop_packet = 1; #ifndef NX_DISABLE_FRAGMENTATION }if (packet_ptr -> nx_packet_option_state >= (UCHAR)FRAGMENT_HEADER) { ... } else { packet_ptr -> nx_packet_option_state = (UCHAR)FRAGMENT_HEADER; #ifdef NX_ENABLE_LOW_WATERMARK if (packet_ptr -> nx_packet_pool_owner -> nx_packet_pool_available >= packet_ptr -> nx_packet_pool_owner -> nx_packet_pool_low_watermark)/* ... */ #endif { drop_packet = _nx_ipv6_process_fragment_option(ip_ptr, packet_ptr); ...} #ifdef NX_ENABLE_LOW_WATERMARK else { drop_packet = NX_POOL_ERROR; }else { ... } /* ... */#endif if (drop_packet != NX_CONTINUE) { /* Special case: do not further process the packet here. Once all fragments are received, we will continue processing the headers. *//* ... */ return(drop_packet); }if (drop_packet != NX_CONTINUE) { ... } else { /* Continue processing the packet. */ drop_packet = 0; }else { ... } }else { ... } #endif /* NX_DISABLE_FRAGMENTATION */ break; case NX_PROTOCOL_NEXT_HEADER_FRAGMENT: case NX_PROTOCOL_NO_NEXT_HEADER: drop_packet = 1; break; /* ... */ #endif /* FEATURE_NX_IPV6 */ case NX_PROTOCOL_NEXT_HEADER_AUTHENTICATION: #ifdef NX_IPSEC_ENABLE if (ip_ptr -> nx_ip_ipsec_authentication_header_receive == NX_NULL) { /* If IPsec is not enabled by the application, drop the packet. */ return(1); }if (ip_ptr -> nx_ip_ipsec_authentication_header_receive == NX_NULL) { ... } else { ret = ip_ptr -> nx_ip_ipsec_authentication_header_receive(ip_ptr, packet_ptr, &next_protocol, &packet_ptr); if (ret == NX_SUCCESS) { /* Indicate that IPSec consumed the packet. */ return(0); }if (ret == NX_SUCCESS) { ... } if (ret != NX_IPSEC_PKT_CONT) { return(1); }if (ret != NX_IPSEC_PKT_CONT) { ... } /* Continue processing the packet if status = NX_IPSEC_PKT_CONT */ }else { ... } /* ... */#else /* NX_IPSEC_ENABLE */ /* Drop this packet if IPsec module is not present. */ drop_packet = 1;/* ... */ #endif /* NX_IPSEC_ENABLE */ break; case NX_PROTOCOL_NEXT_HEADER_AUTHENTICATION: case NX_PROTOCOL_NEXT_HEADER_ENCAP_SECURITY: #ifdef NX_IPSEC_ENABLE if (ip_ptr -> nx_ip_ipsec_encapsulating_security_payload_receive == NX_NULL) { /* If IPsec is not enabled by the application, drop the packet. */ return(1); }if (ip_ptr -> nx_ip_ipsec_encapsulating_security_payload_receive == NX_NULL) { ... } else { ret = ip_ptr -> nx_ip_ipsec_encapsulating_security_payload_receive(ip_ptr, packet_ptr, &next_protocol, &packet_ptr); if (ret == NX_SUCCESS) { /* Indicate IPSec consumed the packet. */ return(0); }if (ret == NX_SUCCESS) { ... } if (ret != NX_IPSEC_PKT_CONT) { return(1); }if (ret != NX_IPSEC_PKT_CONT) { ... } /* Continue processing the packet if status = NX_IPSEC_PKT_CONT */ }else { ... } break; /* ... */ #else /* NX_IPSEC_ENABLE */ /* Drop this packet if IPsec module is not present. */ return(1);/* ... */ #endif /* NX_IPSEC_ENABLE */ case NX_PROTOCOL_NEXT_HEADER_ENCAP_SECURITY: default: /* Not part of the IP headers. */ #ifdef NX_IPSEC_ENABLE /* Check ingress_sa for packet that is not ESP or AH. */ if (packet_ptr -> nx_packet_ipsec_sa_ptr == NX_NULL) { /* Get source and destination address. */ #ifdef FEATURE_NX_IPV6 if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ipv6_header = (NX_IPV6_HEADER *)(packet_ptr -> nx_packet_ip_header); src_addr.nxd_ip_version = NX_IP_VERSION_V6; dest_addr.nxd_ip_version = NX_IP_VERSION_V6; COPY_IPV6_ADDRESS(ipv6_header -> nx_ip_header_source_ip, src_addr.nxd_ip_address.v6); COPY_IPV6_ADDRESS(ipv6_header -> nx_ip_header_destination_ip, dest_addr.nxd_ip_address.v6); }if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... } else #endif /* FEATURE_NX_IPV6 */ { #ifndef NX_DISABLE_IPV4 ipv4_header = (NX_IPV4_HEADER *)(packet_ptr -> nx_packet_ip_header); src_addr.nxd_ip_version = NX_IP_VERSION_V4; dest_addr.nxd_ip_version = NX_IP_VERSION_V4; src_addr.nxd_ip_address.v4 = ipv4_header -> nx_ip_header_source_ip; dest_addr.nxd_ip_address.v4 = ipv4_header -> nx_ip_header_destination_ip;/* ... */ #endif /* NX_DISABLE_IPV4 */ }else { ... } if (_nx_ipsec_sa_ingress_lookup(ip_ptr, &src_addr, &dest_addr, 0, (UCHAR)protocol, NX_NULL, packet_ptr -> nx_packet_prepend_ptr) != NX_IPSEC_TRAFFIC_BYPASS) { #ifdef FEATURE_NX_IPV6 /* Check whether it is a NA packet. */ if (protocol == NX_PROTOCOL_ICMPV6) { /* Bypass NA packet. */ icmp_header_ptr = (NX_ICMPV6_HEADER *)packet_ptr -> nx_packet_prepend_ptr; if (icmp_header_ptr -> nx_icmpv6_header_type != NX_ICMPV6_NEIGHBOR_ADVERTISEMENT_TYPE) { return(NX_INVALID_PACKET); }if (icmp_header_ptr -> nx_icmpv6_header_type != NX_ICMPV6_NEIGHBOR_ADVERTISEMENT_TYPE) { ... } }if (protocol == NX_PROTOCOL_ICMPV6) { ... } else { #endif /* FEATURE_NX_IPV6 */ return(NX_INVALID_PACKET); #ifdef FEATURE_NX_IPV6 }else { ... } #endif /* FEATURE_NX_IPV6 */ }if (_nx_ipsec_sa_ingress_lookup(ip_ptr, &src_addr, &dest_addr, 0, (UCHAR)protocol, NX_NULL, packet_ptr -> nx_packet_prepend_ptr) != NX_IPSEC_TRAFFIC_BYPASS) { ... } }if (packet_ptr -> nx_packet_ipsec_sa_ptr == NX_NULL) { ... } /* For IPsec tunnel mode, next protocol is checked here. */ else if (((NX_IPSEC_SA *)(packet_ptr -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_sa_mode == NX_IPSEC_TUNNEL_MODE) { if (_nx_ipsec_sa_ingress_selector_check(packet_ptr -> nx_packet_prepend_ptr, (UCHAR)protocol, ((NX_IPSEC_SA *)(packet_ptr -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_selector_ptr) == NX_IPSEC_TRAFFIC_DROP) { _nx_packet_release(packet_ptr); /* Consume the packet */ return(NX_INVALID_PACKET); }if (_nx_ipsec_sa_ingress_selector_check(packet_ptr -> nx_packet_prepend_ptr, (UCHAR)protocol, ((NX_IPSEC_SA *)(packet_ptr -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_selector_ptr) == NX_IPSEC_TRAFFIC_DROP) { ... } }else if (((NX_IPSEC_SA *)(packet_ptr -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_sa_mode == NX_IPSEC_TUNNEL_MODE) { ... } /* ... */#endif /* NX_IPSEC_ENABLE */ #if defined(NX_ENABLE_IP_RAW_PACKET_ALL_STACK) && defined(NX_ENABLE_IP_RAW_PACKET_FILTER) if ((ip_ptr -> nx_ip_raw_ip_processing) && (ip_ptr -> nx_ip_raw_packet_filter)) { /* Let RAW packet filter handler filter all incoming packets. */ if ((ip_ptr -> nx_ip_raw_ip_processing)(ip_ptr, protocol << 16, packet_ptr) == NX_SUCCESS) { /* No need to free the packet as it is consumed by the raw process */ return(0); }if ((ip_ptr -> nx_ip_raw_ip_processing)(ip_ptr, protocol << 16, packet_ptr) == NX_SUCCESS) { ... } }if ((ip_ptr -> nx_ip_raw_ip_processing) && (ip_ptr -> nx_ip_raw_packet_filter)) { ... } /* ... */#endif /* defined(NX_ENABLE_IP_RAW_PACKET_ALL_STACK) && defined(NX_ENABLE_IP_RAW_PACKET_FILTER) */ if (protocol == NX_PROTOCOL_TCP) { #ifdef FEATURE_NX_IPV6 if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) || ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) && (incoming_addr -> nxd_ipv6_address_state == NX_IPV6_ADDR_STATE_VALID))) { #endif /* FEATURE_NX_IPV6 */ /* Check that the host is enabled for TCP. */ if (ip_ptr -> nx_ip_tcp_packet_receive) { /* Dispatch the packet to the TCP packet handler. */ (ip_ptr -> nx_ip_tcp_packet_receive)(ip_ptr, packet_ptr); /* No need to free the packet as it is consumed by TCP packet receive. */ return(0); }if (ip_ptr -> nx_ip_tcp_packet_receive) { ... } #ifdef FEATURE_NX_IPV6 }if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) || ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) && (incoming_addr -> nxd_ipv6_address_state == NX_IPV6_ADDR_STATE_VALID))) { ... } #endif /* FEATURE_NX_IPV6 */ /* TCP is not enabled. Drop the packet. */ drop_packet = 1; }if (protocol == NX_PROTOCOL_TCP) { ... } #ifdef FEATURE_NX_IPV6 else if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) && (protocol == NX_PROTOCOL_ICMPV6)) { /* Check that ICMPv6 is enabled for this IP instance. */ if (ip_ptr -> nx_ip_icmpv6_packet_process != NX_NULL) { /* Forward to the ICMPv6 packet handler. */ ip_ptr -> nx_ip_icmpv6_packet_process(ip_ptr, packet_ptr); /* no need to free packet as it is consumed by ICMP packet receive. */ return(0); }if (ip_ptr -> nx_ip_icmpv6_packet_process != NX_NULL) { ... } /* ICMPv6 is not enabled. Drop the packet. */ drop_packet = 1; }else if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) && (protocol == NX_PROTOCOL_ICMPV6)) { ... } /* ... */#endif /* FEATURE_NX_IPV6 */ #ifndef NX_DISABLE_IPV4 else if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) && (protocol == NX_PROTOCOL_ICMP)) { /* Check that ICMP is enabled for this IP instance. */ if (ip_ptr -> nx_ip_icmp_packet_receive != NX_NULL) { /* Yes, a ICMP packet is present, dispatch to the appropriate ICMP handler if present. *//* ... */ ip_ptr -> nx_ip_icmp_packet_receive(ip_ptr, packet_ptr); return(0); }if (ip_ptr -> nx_ip_icmp_packet_receive != NX_NULL) { ... } /* ICMP is not enabled. Drop the packet. */ drop_packet = 1; }else if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) && (protocol == NX_PROTOCOL_ICMP)) { ... } else if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) && (protocol == NX_PROTOCOL_IGMP)) { if (ip_ptr -> nx_ip_igmp_packet_receive != NX_NULL) { /* Yes, a IGMP packet is present, dispatch to the appropriate ICMP handler if present. *//* ... */ ip_ptr -> nx_ip_igmp_packet_receive(ip_ptr, packet_ptr); return(0); }if (ip_ptr -> nx_ip_igmp_packet_receive != NX_NULL) { ... } /* IGMP is not enabled. Drop the packet. */ drop_packet = 1; }else if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) && (protocol == NX_PROTOCOL_IGMP)) { ... } /* ... */#endif /* NX_DISABLE_IPV4 */ else if (protocol == NX_PROTOCOL_UDP) { #ifdef FEATURE_NX_IPV6 if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) || ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) && (incoming_addr -> nxd_ipv6_address_state == NX_IPV6_ADDR_STATE_VALID))) { #endif /* FEATURE_NX_IPV6 */ /* Check the host is enabled for UDP packet handling. */ if (ip_ptr -> nx_ip_udp_packet_receive) { /* Dispatch the packet to the UDP handler. */ (ip_ptr -> nx_ip_udp_packet_receive)(ip_ptr, packet_ptr); /* No need to free the packet as it is consumed by UDP packet receive. */ return(0); }if (ip_ptr -> nx_ip_udp_packet_receive) { ... } #ifdef FEATURE_NX_IPV6 }if ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) || ((packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) && (incoming_addr -> nxd_ipv6_address_state == NX_IPV6_ADDR_STATE_VALID))) { ... } #endif /* FEATURE_NX_IPV6 */ /* UDP is not enabled. Drop the packet. */ drop_packet = 1; }else if (protocol == NX_PROTOCOL_UDP) { ... } else { if (ip_ptr -> nx_ip_raw_ip_processing) { #if defined(NX_ENABLE_IP_RAW_PACKET_ALL_STACK) && defined(NX_ENABLE_IP_RAW_PACKET_FILTER) if (ip_ptr -> nx_ip_raw_packet_filter == NX_NULL) #endif /* defined(NX_ENABLE_IP_RAW_PACKET_ALL_STACK) && defined(NX_ENABLE_IP_RAW_PACKET_FILTER) */ { if ((ip_ptr -> nx_ip_raw_ip_processing)(ip_ptr, protocol << 16, packet_ptr) == NX_SUCCESS) { /* No need to free the packet as it is consumed by the raw process */ return(0); }if ((ip_ptr -> nx_ip_raw_ip_processing)(ip_ptr, protocol << 16, packet_ptr) == NX_SUCCESS) { ... } ...} }if (ip_ptr -> nx_ip_raw_ip_processing) { ... } #if !defined(NX_DISABLE_IPV4) && !defined(NX_DISABLE_ICMPV4_ERROR_MESSAGE) /* Unknown protocol, send ICMP Destination protocol unreachable. */ if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { NX_ICMPV4_SEND_DEST_UNREACHABLE(ip_ptr, packet_ptr, NX_ICMP_PROTOCOL_UNREACH_CODE); }if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... } /* ... */#endif /* !NX_DISABLE_IPV4 && !NX_DISABLE_ICMPV4_ERROR_MESSAGE */ #ifdef FEATURE_NX_IPV6 /* Unknown option. Send ICMP Parameter problem and discard the packet. */ /* RFC 2460, page 7 */ #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 1, nx_packet_option_offset); }if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... } /* ... */#endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE *//* ... */ #endif /* FEATURE_NX_IPV6 */ #ifndef NX_DISABLE_IP_INFO /* Increment the IP unknown protocol count. */ ip_ptr -> nx_ip_unknown_protocols_received++; /* ... */ #endif /* NX_DISABLE_IP_INFO */ drop_packet = 1; }else { ... } break;default }switch (protocol) { ... } /* If the previous header is processed without errors, move on to the next optional header. *//* ... */ if (!drop_packet) { #ifdef FEATURE_NX_IPV6 NX_IPV6_HEADER_OPTION *option; ULONG option_hdr_len;/* ... */ #endif /* FEATURE_NX_IPV6 */ #ifdef NX_IPSEC_ENABLE if (protocol == NX_PROTOCOL_NEXT_HEADER_ENCAP_SECURITY || protocol == NX_PROTOCOL_NEXT_HEADER_AUTHENTICATION) { /* After ESP and AH processing, ESP and AH hdr are removed. */ protocol = next_protocol; continue; }if (protocol == NX_PROTOCOL_NEXT_HEADER_ENCAP_SECURITY || protocol == NX_PROTOCOL_NEXT_HEADER_AUTHENTICATION) { ... } /* ... */#endif /* NX_IPSEC_ENABLE */ #ifdef FEATURE_NX_IPV6 if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { /* Find the option we just processed. */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ option = (NX_IPV6_HEADER_OPTION *)packet_ptr -> nx_packet_prepend_ptr; /* Check the protocol. */ if (protocol == NX_PROTOCOL_NEXT_HEADER_FRAGMENT) { /* Fixed length for fragment option, the field of option length is reserved. */ option_hdr_len = sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION); }if (protocol == NX_PROTOCOL_NEXT_HEADER_FRAGMENT) { ... } else { /* Compute the current option length. */ /* For other IPv6 optional headers, hdr_ext_len is expressed in 64-bit words. */ option_hdr_len = (ULONG)((option -> nx_ipv6_header_option_ext_length + 1) << 3); }else { ... } /* Obtain the next option header type. */ protocol = option -> nx_ipv6_header_option_next_header; if (((ALIGN_TYPE)(packet_ptr -> nx_packet_prepend_ptr) + option_hdr_len) < (ALIGN_TYPE)(packet_ptr -> nx_packet_append_ptr)) { /* Advance to the next header. */ packet_ptr -> nx_packet_prepend_ptr += option_hdr_len; packet_ptr -> nx_packet_length -= option_hdr_len; }if (((ALIGN_TYPE)(packet_ptr -> nx_packet_prepend_ptr) + option_hdr_len) < (ALIGN_TYPE)(packet_ptr -> nx_packet_append_ptr)) { ... } else { drop_packet = 1; }else { ... } /* Advance the nx_packet_option_offset as well. Option Offset is used when constructing ICMPv6 parameter problem message. *//* ... */ packet_ptr -> nx_packet_option_offset = (USHORT)next_option_offset; /*lint -e{946} -e{947} suppress pointer subtraction, since it is necessary. */ next_option_offset = (UINT)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_ip_header); }if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... } /* ... */#endif /* FEATURE_NX_IPV6 */ }if (!drop_packet) { ... } else { #ifndef NX_DISABLE_IP_INFO /* Decrement the number of packets delivered. */ ip_ptr -> nx_ip_total_packets_delivered--; /* Decrement the IP packet bytes received (not including the header). */ ip_ptr -> nx_ip_total_bytes_received -= packet_ptr -> nx_packet_length; /* Increment the IP receive packets dropped count. */ ip_ptr -> nx_ip_receive_packets_dropped++;/* ... */ #endif /* NX_DISABLE_IP_INFO */ }else { ... } }while (!drop_packet) { ... } return(drop_packet); }{ ... }