1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 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 24 25 /* Include necessary system files. */ 26 27 #include "nx_api.h" 28 #include "nx_ipv6.h" 29 #include "nx_icmpv6.h" 30 31 #ifdef FEATURE_NX_IPV6 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _nx_icmpv6_validate_options PORTABLE C */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* Yuxin Zhou, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function validates ICMPv6 additional options. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* option Pointer to ICMPv6 option */ 50 /* length Length of the Option field */ 51 /* additional_check Whether or not caller wishes to */ 52 /* perform additoinal verification */ 53 /* */ 54 /* OUTPUT */ 55 /* */ 56 /* NX_SUCCESS Options are valid */ 57 /* NX_NOT_SUCCESS Options are invalid */ 58 /* */ 59 /* CALLS */ 60 /* */ 61 /* None */ 62 /* */ 63 /* CALLED BY */ 64 /* */ 65 /* _nx_icmpv6_validate_neighbor_messages */ 66 /* _nx_icmpv6_validate_ra */ 67 /* */ 68 /* RELEASE HISTORY */ 69 /* */ 70 /* DATE NAME DESCRIPTION */ 71 /* */ 72 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 73 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 74 /* resulting in version 6.1 */ 75 /* */ 76 /**************************************************************************/ _nx_icmpv6_validate_options(NX_ICMPV6_OPTION * option,INT length,INT additional_check)77UINT _nx_icmpv6_validate_options(NX_ICMPV6_OPTION *option, INT length, INT additional_check) 78 { 79 80 UINT option_len; 81 82 /* Parse all option headers from the ICMPv6 header. */ 83 while (length > 0) 84 { 85 /* Verify that the option length is not zero. */ 86 if (option -> nx_icmpv6_option_length == 0) 87 { 88 return(NX_NOT_SUCCESSFUL); 89 } 90 91 /* Also check for NO SOURCE LINK LAYER ADDRESS. */ 92 if ((additional_check == NX_NO_SLLA) && 93 (option -> nx_icmpv6_option_type == 1)) 94 { 95 96 return(NX_NOT_SUCCESSFUL); 97 } 98 99 /* Get the next option. */ 100 option_len = ((UINT)option -> nx_icmpv6_option_length) << 3; 101 length -= (INT)option_len; 102 103 /*lint -e{923} suppress cast between pointer and ULONG, since it is necessary */ 104 option = (NX_ICMPV6_OPTION *)NX_UCHAR_POINTER_ADD(option, option_len); 105 } 106 107 if (length < 0) 108 { 109 110 /* Invalid packet length. */ 111 return(NX_NOT_SUCCESSFUL); 112 } 113 114 return(NX_SUCCESS); 115 } 116 117 #endif /* FEATURE_NX_IPV6 */ 118 119