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 /* Include necessary system files.  */
26 
27 #include "nx_api.h"
28 #include "nx_ipv6.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nxd_ipv6_stateless_address_autoconfig_disable      PORTABLE C      */
36 /*                                                           6.2.1        */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function disables the IPv6 stateless address auto              */
44 /*    configuration feature if the address has not been configured yet.   */
45 /*                                                                        */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                IP instance pointer           */
50 /*    interface_index                       The interface to operate on   */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    tx_mutex_get                          Obtain a protection mutex     */
59 /*    tx_mutex_put                          Release protection mutex      */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
70 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  03-08-2023     Tiejun Zhou              Modified comment(s), and      */
73 /*                                            fixed compiler warnings,    */
74 /*                                            resulting in version 6.2.1  */
75 /*                                                                        */
76 /**************************************************************************/
_nxd_ipv6_stateless_address_autoconfig_disable(NX_IP * ip_ptr,UINT interface_index)77 UINT  _nxd_ipv6_stateless_address_autoconfig_disable(NX_IP *ip_ptr, UINT interface_index)
78 {
79 
80 
81 #if defined(FEATURE_NX_IPV6) && defined(NX_IPV6_STATELESS_AUTOCONFIG_CONTROL)
82 NX_INTERFACE *interface_ptr;
83 
84 
85     /* Set interface_ptr.  */
86     interface_ptr = &ip_ptr -> nx_ip_interface[interface_index];
87 
88     /* Make sure IPv6 is not already enabled. */
89     if (interface_ptr -> nx_ipv6_stateless_address_autoconfig_status == NX_STATELESS_ADDRESS_AUTOCONFIG_DISABLED)
90     {
91         return(NX_SUCCESS);
92     }
93 
94     /* If trace is enabled, insert this event into the trace buffer.  */
95     NX_TRACE_IN_LINE_INSERT(NXD_TRACE_IPV6_STATELESS_ADDRESS_AUTOCONFIG_DISABLE, ip_ptr, interface_ptr, 0, 0, NX_TRACE_IP_EVENTS, 0, 0);
96 
97     /* Obtain the IP mutex so we can manipulate the internal routing table. */
98     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
99 
100     /* Install IPv6 packet receive processing function pointer */
101     interface_ptr -> nx_ipv6_stateless_address_autoconfig_status = NX_STATELESS_ADDRESS_AUTOCONFIG_DISABLED;
102 
103 #ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
104     /* Reset the RS count. */
105     interface_ptr -> nx_ipv6_rtr_solicitation_count = 0;
106 #endif /* NX_DISABLE_ICMPV6_ROUTER_SOLICITATION */
107 
108     /* Release the IP protection. */
109     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
110 
111     /* Return successful completion.  */
112     return(NX_SUCCESS);
113 #else
114     NX_PARAMETER_NOT_USED(ip_ptr);
115     NX_PARAMETER_NOT_USED(interface_index);
116 
117     return(NX_NOT_SUPPORTED);
118 #endif /* FEATURE_NX_IPV6 && NX_IPV6_STATELESS_AUTOCONFIG_CONTROL */
119 }
120 
121