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 #ifdef FEATURE_NX_IPV6
30 #include "nx_ip.h"
31 
32 /* Bring in externs for caller checking code.  */
33 
34 NX_CALLER_CHECKING_EXTERNS
35 #endif /* FEATURE_NX_IPV6 */
36 
37 /**************************************************************************/
38 /*                                                                        */
39 /*  FUNCTION                                               RELEASE        */
40 /*                                                                        */
41 /*    _nxde_ipv6_address_set                              PORTABLE C      */
42 /*                                                           6.1          */
43 /*  AUTHOR                                                                */
44 /*                                                                        */
45 /*    Yuxin Zhou, Microsoft Corporation                                   */
46 /*                                                                        */
47 /*  DESCRIPTION                                                           */
48 /*                                                                        */
49 /*    This function checks for errors in the IP address set               */
50 /*    function call.                                                      */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    ip_ptr                                IP control block pointer      */
55 /*    interface_index                       The index to the physical     */
56 /*                                            interface this address      */
57 /*                                            belongs to                  */
58 /*    ip_address                            Pointer to IP address         */
59 /*                                            structure                   */
60 /*    prefix_length                         Prefix length                 */
61 /*    address_index                         Index to the IPv6 address     */
62 /*                                            table                       */
63 /*                                                                        */
64 /*  OUTPUT                                                                */
65 /*                                                                        */
66 /*    status                                Completion status             */
67 /*                                                                        */
68 /*  CALLS                                                                 */
69 /*                                                                        */
70 /*    IPv6_Address_Type                     Find IPv6 address type.       */
71 /*    _nxd_ipv6_address_set                 Actual IP address set function*/
72 /*                                                                        */
73 /*  CALLED BY                                                             */
74 /*                                                                        */
75 /*    Application Code                                                    */
76 /*                                                                        */
77 /*  RELEASE HISTORY                                                       */
78 /*                                                                        */
79 /*    DATE              NAME                      DESCRIPTION             */
80 /*                                                                        */
81 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
82 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
83 /*                                            resulting in version 6.1    */
84 /*                                                                        */
85 /**************************************************************************/
_nxde_ipv6_address_set(NX_IP * ip_ptr,UINT if_index,NXD_ADDRESS * ip_address,ULONG prefix_length,UINT * address_index)86 UINT  _nxde_ipv6_address_set(NX_IP *ip_ptr, UINT if_index, NXD_ADDRESS *ip_address, ULONG prefix_length, UINT *address_index)
87 {
88 #ifdef FEATURE_NX_IPV6
89 
90 UINT  status;
91 ULONG AddressType;
92 
93 
94     /* Check for invalid input pointers.  */
95     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
96     {
97         return(NX_PTR_ERROR);
98     }
99 
100     /* Check for invalid IP addresses.  */
101 
102     /* (Do not apply to autoconfigured linklocal addresses) */
103     if ((ip_address != NULL) && (prefix_length != 10))
104     {
105 
106         /* A non null IP address must have the version set. */
107         if (ip_address -> nxd_ip_version != NX_IP_VERSION_V6)
108         {
109             return(NX_IP_ADDRESS_ERROR);
110         }
111     }
112 
113     if ((if_index >= NX_MAX_PHYSICAL_INTERFACES) ||
114         (ip_ptr -> nx_ip_interface[if_index].nx_interface_valid != NX_TRUE))
115     {
116         return(NX_INVALID_INTERFACE);
117     }
118 
119 
120     /* Make sure the address is unicast address. */
121     /* Find out the type of the incoming IP address. */
122     if (ip_address)
123     {
124         AddressType = IPv6_Address_Type(ip_address -> nxd_ip_address.v6);
125 
126         if ((AddressType & IPV6_ADDRESS_UNICAST) == 0)
127         {
128             return(NX_IP_ADDRESS_ERROR);
129         }
130     }
131 
132     /* Check for appropriate caller.  */
133     NX_INIT_AND_THREADS_CALLER_CHECKING
134 
135     /* Call actual IP address set function.  */
136     status =  _nxd_ipv6_address_set(ip_ptr, if_index, ip_address, prefix_length, address_index);
137 
138     /* Return completion status.  */
139     return(status);
140 
141 #else /* !FEATURE_NX_IPV6 */
142     NX_PARAMETER_NOT_USED(ip_ptr);
143     NX_PARAMETER_NOT_USED(if_index);
144     NX_PARAMETER_NOT_USED(ip_address);
145     NX_PARAMETER_NOT_USED(prefix_length);
146     NX_PARAMETER_NOT_USED(address_index);
147 
148     return(NX_NOT_SUPPORTED);
149 
150 #endif /* FEATURE_NX_IPV6 */
151 }
152 
153