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