1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** NetX Component */
17 /** */
18 /** Internet Protocol (IP) */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define NX_SOURCE_CODE
24
25
26
27 /* Include necessary system files. */
28
29 #include "nx_api.h"
30 #include "nx_ipv6.h"
31 #include "nx_icmpv6.h"
32
33 #ifdef FEATURE_NX_IPV6
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _nx_ipv6_option_error PORTABLE C */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* Yuxin Zhou, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function handles an invalid Options header packet by examining */
48 /* the option header option type's most significant bits and */
49 /* determining if an error message is sent and if the rest of the */
50 /* packet should be processed or discarded. */
51 /* */
52 /* INPUT */
53 /* */
54 /* ip_ptr Pointer to IP control block */
55 /* packet_ptr Pointer to packet to send */
56 /* option_type The type of option */
57 /* offset Where the error occurs */
58 /* */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* NX_SUCCESS Skip this option; no errors */
63 /* NX_OPTION_HEADER_ERROR Error; Drop the entire packet*/
64 /* */
65 /* CALLS */
66 /* */
67 /* None */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* _nx_ipv6_process_hop_by_hop_option */
72 /* */
73 /* RELEASE HISTORY */
74 /* */
75 /* DATE NAME DESCRIPTION */
76 /* */
77 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
78 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
79 /* resulting in version 6.1 */
80 /* */
81 /**************************************************************************/
_nx_ipv6_option_error(NX_IP * ip_ptr,NX_PACKET * packet_ptr,UCHAR option_type,UINT offset)82 UINT _nx_ipv6_option_error(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UCHAR option_type, UINT offset)
83 {
84
85 UINT rv = NX_SUCCESS;
86
87 /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */
88 NX_IPV6_HEADER *ip_header_ptr = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_ip_header;
89
90 /* Top 2 bits of the option type indicate how we shall process this option
91 in case of an error. */
92 switch (option_type >> 6)
93 {
94
95 case 3: /* Discard the packet and send ICMP Parameter Problem to unicast address */
96 if ((ip_header_ptr -> nx_ip_header_destination_ip[0] & (ULONG)0xFF000000) == (ULONG)0xFF000000)
97 {
98
99 /* If the destination address is a multicast address, we discard the packet. */
100 rv = NX_OPTION_HEADER_ERROR;
101 break;
102 }
103 /*
104 No need to break here: execute the next two cases:
105 (1) transmit ICMP error message
106 (2) release the packet.
107 */
108
109 /*lint -e{825} suppress fallthrough, since it is necessary. */ /* fallthrough */
110 case 2: /* Discard the packet and send ICMP Parameter Problem */
111
112 #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE
113
114 NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 2, (ULONG)(offset + sizeof(NX_IPV6_HEADER)));
115 #else
116 NX_PARAMETER_NOT_USED(ip_ptr);
117 NX_PARAMETER_NOT_USED(offset);
118 #endif
119
120 /* No break here. Execute the next statement to release the packet. */
121
122 /*lint -e{825} suppress fallthrough, since it is necessary. */ /* fallthrough */
123 case 1: /* Discard the packet */
124
125 /* Error status - Drop the packet */
126 rv = NX_OPTION_HEADER_ERROR;
127 break;
128
129 case 0: /* Skip over this option and continue processing the rest of the packet. */
130 default:
131 break;
132 }
133
134 return(rv);
135 }
136
137
138 #endif /* FEATURE_NX_IPV6 */
139
140