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 /** NetX Component */ 16 /** */ 17 /** Internet Control Message Protocol (ICMP) */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define NX_SOURCE_CODE 23 /* Include necessary system files. */ 24 25 #include "nx_api.h" 26 #include "nx_ipv6.h" 27 #include "nx_icmpv6.h" 28 29 #ifdef FEATURE_NX_IPV6 30 31 32 #ifndef NX_DISABLE_ICMPV6_ROUTER_ADVERTISEMENT_PROCESS 33 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* _nx_icmpv6_validate_ra PORTABLE C */ 39 /* 6.1 */ 40 /* AUTHOR */ 41 /* */ 42 /* Yuxin Zhou, Microsoft Corporation */ 43 /* */ 44 /* DESCRIPTION */ 45 /* */ 46 /* This function validates incoming router advertisement messages. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* packet_ptr ICMP packet pointer */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* NX_SUCCESS Successful completion (no */ 55 /* option fields to validate) */ 56 /* NX_NOT_SUCCESSFUL Invalid ICMP header data */ 57 /* */ 58 /* CALLS */ 59 /* */ 60 /* IPv6_Address_Type Find IP address type. */ 61 /* _nx_icmpv6_validate_options Validate option field. */ 62 /* */ 63 /* CALLED BY */ 64 /* */ 65 /* _nx_icmpv6_process_ra Main ICMP packet pocess */ 66 /* */ 67 /* RELEASE HISTORY */ 68 /* */ 69 /* DATE NAME DESCRIPTION */ 70 /* */ 71 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 72 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 73 /* resulting in version 6.1 */ 74 /* */ 75 /**************************************************************************/ _nx_icmpv6_validate_ra(NX_PACKET * packet_ptr)76UINT _nx_icmpv6_validate_ra(NX_PACKET *packet_ptr) 77 { 78 79 NX_IPV6_HEADER *ipv6_header; 80 NX_ICMPV6_RA *header_ptr; 81 NX_ICMPV6_OPTION *option_ptr; 82 INT option_length; 83 ULONG source_address_type, dest_address_type; 84 85 86 /* Set a pointer to he ICMP message header. */ 87 /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ 88 header_ptr = (NX_ICMPV6_RA *)packet_ptr -> nx_packet_prepend_ptr; 89 90 /* Set a pointer to the IPv6 header. */ 91 /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ 92 ipv6_header = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_ip_header; 93 94 source_address_type = IPv6_Address_Type(ipv6_header -> nx_ip_header_source_ip); 95 dest_address_type = IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip); 96 97 /* Validate the IP header information. */ 98 99 /* The source address must be the link local router address. RFC2461 4.2 */ 100 if ((source_address_type & IPV6_ADDRESS_LINKLOCAL) != IPV6_ADDRESS_LINKLOCAL) 101 { 102 103 return(NX_NOT_SUCCESSFUL); 104 } 105 106 /* IP destination address must be multicast address or solicited sender link local address. */ 107 if ((dest_address_type != (ULONG)(IPV6_ADDRESS_LINKLOCAL | IPV6_ADDRESS_UNICAST)) && 108 (dest_address_type != (ULONG)(IPV6_ALL_NODE_MCAST | IPV6_ADDRESS_MULTICAST))) 109 { 110 111 return(NX_NOT_SUCCESSFUL); 112 } 113 114 /* The IP header hop limit must be 255 */ 115 if ((ipv6_header -> nx_ip_header_word_1 & 0xFF) != 0xFF) 116 { 117 118 return(NX_NOT_SUCCESSFUL); 119 } 120 121 /* Validate ICMP fields */ 122 if (header_ptr -> nx_icmpv6_ra_icmpv6_header.nx_icmpv6_header_code != 0) 123 { 124 125 return(NX_NOT_SUCCESSFUL); 126 } 127 128 /* Locate the option field. */ 129 /*lint -e{923} suppress cast between pointer and ULONG, since it is necessary */ 130 option_ptr = (NX_ICMPV6_OPTION *)NX_UCHAR_POINTER_ADD(header_ptr, sizeof(NX_ICMPV6_RA)); 131 option_length = (INT)(packet_ptr -> nx_packet_length - sizeof(NX_ICMPV6_RA)); 132 133 /* Check for options (if there is a non zero option length ICMPv6 header field). */ 134 if (option_length) 135 { 136 137 /* Validate option field(s). */ 138 return(_nx_icmpv6_validate_options(option_ptr, option_length, NX_NULL)); 139 } 140 141 return(NX_SUCCESS); 142 } 143 144 145 #endif /* NX_DISABLE_ICMPV6_ROUTER_ADVERTISEMENT_PROCESS */ 146 147 #endif /* FEATURE_NX_IPV6 */ 148 149