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 Control Message Protocol (ICMP)                            */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    nx_icmpv6.h                                         PORTABLE C      */
29 /*                                                           6.1          */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Yuxin Zhou, Microsoft Corporation                                   */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the NetX Internet Control Message Protocol (ICMP) */
37 /*    component, including all data types and external references.  It is */
38 /*    assumed that nx_api.h and nx_port.h have already been included.     */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
45 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
46 /*                                            resulting in version 6.1    */
47 /*                                                                        */
48 /**************************************************************************/
49 
50 #ifndef NX_ICMPV6_H
51 #define NX_ICMPV6_H
52 
53 
54 #include "nx_nd_cache.h"
55 #ifdef FEATURE_NX_IPV6
56 
57 
58 
59 
60 /* Define ICMP types and codes.  */
61 
62 #define NX_ICMPV6_DEST_UNREACHABLE_TYPE       1
63 #define NX_ICMPV6_PACKET_TOO_BIG_TYPE         2
64 #define NX_ICMPV6_TIME_EXCEED_TYPE            3
65 #define NX_ICMPV6_PARAMETER_PROBLEM_TYPE      4
66 #define NX_ICMPV6_ECHO_REPLY_TYPE             129
67 #define NX_ICMPV6_ECHO_REQUEST_TYPE           128
68 #define NX_ICMPV6_ROUTER_SOLICITATION_TYPE    133
69 #define NX_ICMPV6_ROUTER_ADVERTISEMENT_TYPE   134
70 #define NX_ICMPV6_NEIGHBOR_SOLICITATION_TYPE  135
71 #define NX_ICMPV6_NEIGHBOR_ADVERTISEMENT_TYPE 136
72 #define NX_ICMPV6_REDIRECT_MESSAGE_TYPE       137
73 
74 
75 
76 #define ICMPV6_OPTION_TYPE_SRC_LINK_ADDR      1
77 #define ICMPV6_OPTION_TYPE_TRG_LINK_ADDR      2
78 #define ICMPV6_OPTION_TYPE_PREFIX_INFO        3
79 /*
80 #define ICMPV6_OPTION_REDIRECTED_HEADER       4
81  */
82 #define ICMPV6_OPTION_TYPE_MTU                5
83 
84 /* Flag indicicatting that the option field should not contain
85    source link layer address. */
86 #define NX_NO_SLLA                            1
87 
88 /* Define symbols for ICMPv6 error code. */
89 /*
90 #defineNX_ICMPV6_NO_ROUTE_TO_DESTINATION_CODE                    0
91 #define NX_ICMPV6_COMMUNICATION_WITH_DESTINATION_PROHIBITED_CODE 1
92 #define NX_ICMPV6_BEYOND_SCOPE_OF_SOURCE_ADDRESS_CODE            2
93 #define NX_ICMPV6_ADDRESS_UNREACHABLE_CODE                       3
94  */
95 #define NX_ICMPV6_DEST_UNREACHABLE_CODE                          4
96 /*
97 #define NX_ICMPV6_SOURCE_ADDRESS_FAILED_I_E_POLICY_CODE          5
98 #define NX_ICMPV6_REJECT_ROUTE_TO_DESTINATION_CODE               6
99  */
100 
101 
102 /* Set host constants as per RFC 2461 Section 10. */
103 
104 #ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
105 
106 /* Define the maximum number of router solicitations a node sends until a router response
107    is received.  If no response is received, the node concludes no router is present.
108    For backward compatibility, the symbol NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS is mapped to
109    NX_ICMPV6_MAX_RTR_SOLICITATIONS. */
110 
111 #ifdef NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS
112 #define NX_ICMPV6_MAX_RTR_SOLICITATIONS        NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS
113 #endif /* NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS  */
114 
115 #ifndef NX_ICMPV6_MAX_RTR_SOLICITATIONS
116 #define NX_ICMPV6_MAX_RTR_SOLICITATIONS        3
117 #ifndef NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS
118 #define NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS     NX_ICMPV6_MAX_RTR_SOLICITATIONS
119 #endif  /* NXDUO_ICMPV6_MAX_RTR_SOLICITATIONS  */
120 #endif  /* NX_ICMPV6_MAX_RTR_SOLICITATIONS  */
121 
122 /* Define the interval between which the host sends router solicitations in seconds. */
123 /* For backward compatibility, convert map NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL to NX_ICMPV6_RTR_SOLICITATION_INTERVAL */
124 
125 #ifdef NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL
126 #define NX_ICMPV6_RTR_SOLICITATION_INTERVAL    NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL
127 #endif /* NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL  */
128 
129 #ifndef NX_ICMPV6_RTR_SOLICITATION_INTERVAL
130 #define NX_ICMPV6_RTR_SOLICITATION_INTERVAL    4
131 #ifndef NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL
132 #define NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL NX_ICMPV6_RTR_SOLICITATION_INTERVAL
133 #endif  /* NXDUO_ICMPV6_RTR_SOLICITATION_INTERVAL  */
134 #endif  /* NX_ICMPV6_RTR_SOLICITATION_INTERVAL  */
135 
136 /* Define the maximum delay for the initial router solicitation in seconds. */
137 #ifndef NX_ICMPV6_RTR_SOLICITATION_DELAY
138 #define NX_ICMPV6_RTR_SOLICITATION_DELAY       1
139 #endif /* NX_ICMPV6_RTR_SOLICITATION_DELAY */
140 
141 #endif
142 
143 
144 /* Define the minimum size path MTUs recommended by RFC 2460. */
145 
146 #define NX_MINIMUM_IPV6_PATH_MTU               1280
147 
148 
149 /* Define basic ICMPv6 packet header data type. */
150 
151 typedef  struct NX_ICMPV6_HEADER_STRUCT
152 {
153 
154     /*  Header field for ICMPv6 message type */
155     UCHAR   nx_icmpv6_header_type;
156 
157     /*  Header field for ICMPv6 message code (type context specific) */
158     UCHAR   nx_icmpv6_header_code;
159 
160     /*  Header field for ICMPv6 header checksum */
161     USHORT  nx_icmpv6_header_checksum;
162 } NX_ICMPV6_HEADER;
163 
164 
165 /* Define ICMPv6 error message type. */
166 
167 typedef struct NX_ICMPV6_ERROR_STRUCT
168 {
169     /* General ICMPv6 header. */
170     NX_ICMPV6_HEADER nx_icmpv6_error_header;
171 
172     /* Pointer to the original IPv6 packet where error is detected. */
173     ULONG            nx_icmpv6_error_pointer;
174 } NX_ICMPV6_ERROR;
175 
176 
177 /* ICMPv6 echo request message type. */
178 
179 typedef struct NX_ICMPV6_ECHO_STRUCT
180 {
181     /* General ICMPv6 header. */
182     NX_ICMPV6_HEADER nx_icmpv6_echo_header;
183 
184     /* Echo request message ID */
185     USHORT           nx_icmpv6_echo_identifier;
186 
187     /* Echo request message sequence number */
188     USHORT           nx_icmpv6_echo_sequence_num;
189 } NX_ICMPV6_ECHO;
190 
191 /* Define the ICMPv6 Neighbor Discovery message type. */
192 
193 typedef struct NX_ICMPV6_ND_STRUCT
194 {
195     /* General ICMPv6 header. */
196     NX_ICMPV6_HEADER nx_icmpv6_nd_header;
197 
198     /* Neighbor Discovery flag. */
199     ULONG            nx_icmpv6_nd_flag;
200 
201     /* Neighbor Discovery taget address. */
202     ULONG            nx_icmpv6_nd_targetAddress[4];
203 } NX_ICMPV6_ND;
204 
205 /* Define the ICMPv6 additional option type. */
206 
207 typedef struct NX_ICMPV6_OPTION_STRUCT
208 {
209     /* Option type. */
210     UCHAR   nx_icmpv6_option_type;
211 
212     /* Size of the option. */
213     UCHAR   nx_icmpv6_option_length;
214 
215     /* Option data. This field is used to retrieve starting address of option. The size is decided by option length. */
216     USHORT  nx_icmpv6_option_data;
217 } NX_ICMPV6_OPTION;
218 
219 
220 /* Define the Prefix option type. */
221 
222 typedef struct NX_ICMPV6_OPTION_PREFIX_STRUCT
223 {
224 
225     /* prefix type. */
226     /*lint -esym(768,NX_ICMPV6_OPTION_PREFIX_STRUCT::nx_icmpv6_option_prefix_type) suppress member not referenced. It is used before type casting from NX_ICMPV6_OPTION. */
227     UCHAR nx_icmpv6_option_prefix_type;
228 
229     /* option lenght. */
230     /*lint -esym(768,NX_ICMPV6_OPTION_PREFIX_STRUCT::nx_icmpv6_option_prefix_optionlength) suppress member not referenced. It is used before type casting from NX_ICMPV6_OPTION. */
231     UCHAR nx_icmpv6_option_prefix_optionlength;
232 
233     /* Prefix length. */
234     UCHAR nx_icmpv6_option_prefix_length;
235 
236     /* Flag. */
237     UCHAR nx_icmpv6_option_prefix_flag;
238 
239     /* Valid life time, in seconds. */
240     ULONG nx_icmpv6_option_prefix_valid_lifetime;
241 
242     /* Preferred life time, in seconds. */
243     ULONG nx_icmpv6_option_prefix_preferred_lifetime;
244 
245     /* Unused  */
246     /*lint -esym(768,NX_ICMPV6_OPTION_PREFIX_STRUCT::nx_icmpv6_option_prefix_reserved) suppress member not referenced. It is reserved for future use. */
247     ULONG nx_icmpv6_option_prefix_reserved;
248 
249     /* Prefix. */
250     ULONG nx_icmpv6_option_prefix[4];
251 } NX_ICMPV6_OPTION_PREFIX;
252 
253 /* Define the MTU option type. */
254 
255 typedef struct NX_ICMPV6_OPTION_MTU_STRUCT
256 {
257 
258     /* prefix type. */
259     /*lint -esym(768,NX_ICMPV6_OPTION_MTU_STRUCT::nx_icmpv6_option_mtu_type) suppress member not referenced. It is used before type casting from NX_ICMPV6_OPTION. */
260     UCHAR nx_icmpv6_option_mtu_type;
261 
262     /* option length. */
263     /*lint -esym(768,NX_ICMPV6_OPTION_MTU_STRUCT::nx_icmpv6_option_mtu_length) suppress member not referenced. It is used before type casting from NX_ICMPV6_OPTION. */
264     UCHAR nx_icmpv6_option_mtu_length;
265 
266     /* Unused  */
267     /*lint -esym(768,NX_ICMPV6_OPTION_MTU_STRUCT::nx_icmpv6_option_mtu_reserved) suppress member not referenced. It is reserved for future use. */
268     USHORT nx_icmpv6_option_mtu_reserved;
269 
270     /* MTU length. */
271     ULONG nx_icmpv6_option_mtu_path_mtu;
272 
273     /* Pointer to the probe message (not the ICMPv6 header)
274        which for path MTU discovery. */
275     UCHAR *nx_icmpv6_option_mtu_message;
276 } NX_ICMPV6_OPTION_MTU;
277 
278 /* Define the Router solicitation message type.  */
279 
280 typedef struct NX_ICMPV6_RS_STRUCT
281 {
282     /* General ICMPv6 header. */
283     NX_ICMPV6_HEADER nx_icmpv6_rs_icmpv6_header;
284 
285     /* Unused; reserved for future use. */
286     ULONG            nx_icmpv6_rs_reserved;
287 } NX_ICMPV6_RS;
288 
289 /* Define the Router advertisement type. */
290 
291 typedef struct NX_ICMPV6_RA_STRUCT
292 {
293     /* General ICMPv6 header. */
294     NX_ICMPV6_HEADER nx_icmpv6_ra_icmpv6_header;
295 
296     /* Hop limit. */
297     UCHAR nx_icmpv6_ra_hop_limit;
298 
299     /* Router advertisement flag. */
300     UCHAR nx_icmpv6_ra_flag;
301 
302     /* Router life time. */
303     USHORT nx_icmpv6_ra_router_lifetime;
304 
305     /* Router reachable time, in millisecond */
306     ULONG nx_icmpv6_ra_reachable_time;
307 
308     /* Local network retrans timer, in millisecond. */
309     ULONG nx_icmpv6_ra_retrans_time;
310 } NX_ICMPV6_RA;
311 
312 
313 /* Define the Redirect Message type. */
314 
315 typedef struct NX_ICMPV6_REDIRECT_MESSAGE_STRUCT
316 {
317     /* General ICMPv6 header. */
318     NX_ICMPV6_HEADER nx_icmpv6_redirect_icmpv6_header;
319 
320     /* Unused field. */
321     /*lint -esym(768,NX_ICMPV6_REDIRECT_MESSAGE_STRUCT::nx_icmpv6_redirect_reserved) suppress member not referenced. It is reserved for future use. */
322     ULONG nx_icmpv6_redirect_reserved;
323 
324     /* Next hop address. */
325     ULONG nx_icmpv6_redirect_target_address[4];
326 
327     /* Redirected host address. */
328     ULONG nx_icmpv6_redirect_destination_address[4];
329 } NX_ICMPV6_REDIRECT_MESSAGE;
330 
331 #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE
332 /* Define macros for sending out ICMPv6 error messages. */
333 #define NX_ICMPV6_SEND_DEST_UNREACHABLE(ip_ptr, packet, code) \
334     _nx_icmpv6_send_error_message((ip_ptr), (packet), (ULONG)((NX_ICMPV6_DEST_UNREACHABLE_TYPE << 24) | ((code) << 16)), 0)
335 
336 #if 0
337 #define NX_ICMPV6_SEND_PACKET_TOO_BIG(ip_ptr, packet, code) \
338     _nx_icmpv6_send_error_message((ip_ptr), (packet), ((NX_ICMPV6_PACKET_TOO_BIG_TYPE << 24) | ((code) << 16)), 0)
339 #endif
340 
341 #define NX_ICMPV6_SEND_TIME_EXCEED(ip_ptr, packet, code) \
342     _nx_icmpv6_send_error_message((ip_ptr), (packet), (ULONG)((NX_ICMPV6_TIME_EXCEED_TYPE << 24) | ((code) << 16)), 0)
343 
344 #define NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet, code, offset) \
345     _nx_icmpv6_send_error_message((ip_ptr), (packet), (ULONG)((NX_ICMPV6_PARAMETER_PROBLEM_TYPE << 24) | ((code) << 16)), (offset))
346 
347 #endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE */
348 
349 /* Define ICMPv6 API function prototypes. */
350 
351 UINT _nx_icmp_ping6(NX_IP *ip_ptr, NXD_ADDRESS *ip_address,
352                     CHAR *data_ptr, ULONG data_size,
353                     NX_PACKET **response_ptr, ULONG wait_option);
354 UINT _nx_icmp_interface_ping6(NX_IP *ip_ptr, NXD_ADDRESS *ip_address,
355                               CHAR *data_ptr, ULONG data_size, NXD_IPV6_ADDRESS *ipv6_address,
356                               NX_PACKET **response_ptr, ULONG wait_option);
357 VOID _nx_icmpv6_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
358 
359 
360 /* Define service for performing the Duplicate Address Detection protocol. */
361 
362 #ifndef NX_DISABLE_IPV6_DAD
363 VOID _nx_icmpv6_perform_DAD(NX_IP *);
364 #endif /* NX_DISABLE_IPV6_DAD */
365 
366 
367 /* Define services for performing minimum Path MTU. */
368 
369 #ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
370 UINT _nx_icmpv6_process_packet_too_big(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
371 VOID _nx_icmpv6_destination_table_periodic_update(NX_IP *ip_ptr);
372 #endif
373 
374 /* Define the destination search table function. */
375 
376 #ifndef NX_DISABLE_ICMPV6_ROUTER_ADVERTISEMENT_PROCESS
377 VOID _nx_icmpv6_process_ra(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
378 UINT _nx_icmpv6_validate_ra(NX_PACKET *packet_ptr);
379 #endif
380 
381 /* Define service for processing redirect packets. */
382 
383 #ifndef NX_DISABLE_ICMPV6_REDIRECT_PROCESS
384 VOID _nx_icmpv6_process_redirect(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
385 #endif /* NX_DISABLE_ICMPV6_REDIRECT_PROCESS */
386 
387 
388 /* Define service for sending ICMPv6 error messages. */
389 
390 #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE
391 VOID _nx_icmpv6_send_error_message(NX_IP *ip_ptr, NX_PACKET *packet, ULONG word1, ULONG pointer);
392 #endif /* NX_DISABLE_ICMPV6_ERROR_MESSAGE */
393 
394 /* Define service for sending router solicitation requests. */
395 
396 #ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
397 UINT _nx_icmpv6_send_rs(NX_IP *ip_ptr, UINT if_index);
398 #endif
399 
400 /* Define internal ICMPv6 handling functions. */
401 
402 VOID _nx_icmpv6_send_queued_packets(NX_IP *ip_ptr, ND_CACHE_ENTRY *nd_entry);
403 UINT _nx_icmpv6_validate_options(NX_ICMPV6_OPTION *option, INT length, INT additional_check);
404 UINT _nxd_ipv6_destination_table_find_next_hop(NX_IP *ip_ptr, ULONG *destination_ip, ULONG *next_hop);
405 UINT _nx_icmpv6_dest_table_find(NX_IP *ip_ptr, ULONG *destination_address, NX_IPV6_DESTINATION_ENTRY **dest_entry_ptr,
406                                 ULONG path_mtu, ULONG mtu_timeout);
407 UINT _nx_icmpv6_dest_table_add(NX_IP *ip_ptr, ULONG *destination_address,
408                                NX_IPV6_DESTINATION_ENTRY **dest_entry_ptr, ULONG *next_hop,
409                                ULONG path_mtu, ULONG mtu_timeout, NXD_IPV6_ADDRESS *ipv6_address);
410 VOID _nx_icmpv6_process_echo_reply(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
411 VOID _nx_icmpv6_process_echo_request(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
412 VOID _nx_icmpv6_process_ns(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
413 VOID _nx_icmpv6_process_na(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
414 VOID _nx_icmpv6_DAD_clear_NDCache_entry(NX_IP *ip_ptr, ULONG *ip_addr);
415 UINT _nx_icmpv6_validate_neighbor_message(NX_PACKET *packet_ptr);
416 VOID _nx_icmpv6_DAD_failure(NX_IP *ip_ptr, NXD_IPV6_ADDRESS *ipv6_address);
417 VOID _nx_icmpv6_send_ns(NX_IP *ip_ptr, ULONG *neighbor_IP_address, INT send_slla, NXD_IPV6_ADDRESS *outgoing_address,
418                         INT sendUnicast, ND_CACHE_ENTRY *NDCacheEntry);
419 #endif /* FEATURE_NX_IPV6 */
420 
421 
422 /* Define external ICMPv6 handling functions. */
423 UINT _nxd_icmpv6_ra_flag_callback_set(NX_IP *ip_ptr, VOID (*icmpv6_ra_flag_callback)(NX_IP *ip_ptr, UINT ra_flag));
424 
425 /* Define error checking shells for API services.  These are only referenced by the application.  */
426 UINT _nxde_icmpv6_ra_flag_callback_set(NX_IP *ip_ptr, VOID (*icmpv6_ra_flag_callback)(NX_IP *ip_ptr, UINT ra_flag));
427 
428 #endif
429 
430