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