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 Protocol (IP)                                              */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SOURCE_CODE
24 
25 
26 
27 /* Include necessary system files.  */
28 
29 #include "nx_api.h"
30 #include "nx_ipv6.h"
31 #include "nx_icmpv6.h"
32 
33 #ifdef FEATURE_NX_IPV6
34 
35 
36 /**************************************************************************/
37 /*                                                                        */
38 /*  FUNCTION                                               RELEASE        */
39 /*                                                                        */
40 /*    _nx_ipv6_process_routing_option                     PORTABLE C      */
41 /*                                                           6.1          */
42 /*  AUTHOR                                                                */
43 /*                                                                        */
44 /*    Yuxin Zhou, Microsoft Corporation                                   */
45 /*                                                                        */
46 /*  DESCRIPTION                                                           */
47 /*                                                                        */
48 /*    This function processes the Routing Option header.                  */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    ip_ptr                                Pointer to IP control block   */
53 /*    packet_ptr                            Pointer to packet to process  */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    NX_SUCCESS                             Successful completion        */
58 /*    NX_OPTION_HEADER_ERROR                 Error parsing router option  */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    None                                                                */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    _nx_ipv6_packet_receive                                             */
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), improved */
74 /*                                            packet length verification, */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_nx_ipv6_process_routing_option(NX_IP * ip_ptr,NX_PACKET * packet_ptr)78 UINT _nx_ipv6_process_routing_option(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
79 {
80 
81 NX_IPV6_HEADER_ROUTING_OPTION *option;
82 #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE
83 UINT                           base_offset;
84 #endif
85 
86 
87     /* Add debug information. */
88     NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
89 
90     /* Check packet length is at least sizeof(NX_IPV6_HEADER_ROUTING_OPTION). */
91     if (packet_ptr -> nx_packet_length < sizeof(NX_IPV6_HEADER_ROUTING_OPTION))
92     {
93         return(NX_OPTION_HEADER_ERROR);
94     }
95 
96     /* Set a pointer to the routing header. */
97     /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary  */
98     option = (NX_IPV6_HEADER_ROUTING_OPTION *)(packet_ptr -> nx_packet_prepend_ptr);
99 
100     if (option -> nx_ipv6_header_routing_option_segments_left == 0)
101     {
102         /* Skip the rest of the routing header and continue processing this packet. */
103         return(NX_SUCCESS);
104     }
105 
106     /* According to RFC 5095, Routing Header 0 (described in RFC 2460) has been
107        deprecated.  Therefore discard the packet that has segments left, and send
108        an ICMP Parameter Problem if such feature is enabled. */
109 
110 #ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE
111 
112     /*lint -e{946} -e{947} suppress pointer subtraction, since it is necessary. */
113     base_offset = (UINT)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_ip_header);
114 
115     /*lint -e{835} -e{845} suppress operating on zero. */
116     NX_ICMPV6_SEND_PARAMETER_PROBLEM(ip_ptr, packet_ptr, 0, base_offset + 2);
117 #else
118     NX_PARAMETER_NOT_USED(ip_ptr);
119 #endif
120 
121     /* Return error status, so the caller knows to free the packet. */
122     return(NX_OPTION_HEADER_ERROR);
123 }
124 
125 
126 #endif /*  FEATURE_NX_IPV6 */
127 
128