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