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 /**   Neighbor Discovery Cache                                            */
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_nd_cache.h"
29 #ifdef FEATURE_NX_IPV6
30 #include "nx_ip.h"
31 #include "nx_ipv6.h"
32 
33 /* Bring in externs for caller checking code.  */
34 NX_CALLER_CHECKING_EXTERNS
35 
36 
37 #endif /* FEATURE_NX_IPV6 */
38 
39 
40 /**************************************************************************/
41 /*                                                                        */
42 /*  FUNCTION                                               RELEASE        */
43 /*                                                                        */
44 /*    _nxde_nd_cache_hardware_address_find                PORTABLE C      */
45 /*                                                           6.1          */
46 /*  AUTHOR                                                                */
47 /*                                                                        */
48 /*    Yuxin Zhou, Microsoft Corporation                                   */
49 /*                                                                        */
50 /*  DESCRIPTION                                                           */
51 /*                                                                        */
52 /*    This function performs error checking on the service for finding a  */
53 /*    neighbor discovery (ND) cache entry service.                        */
54 /*                                                                        */
55 /*  INPUT                                                                 */
56 /*                                                                        */
57 /*    ip_ptr                                IP instance pointer           */
58 /*    ip_address                            Pointer to the IP address to  */
59 /*                                            search for                  */
60 /*    physical_msw                          Physical address, most        */
61 /*                                            signifcant word             */
62 /*    physical_lsw                          Physical address, least       */
63 /*                                            signifcant word             */
64 /*    interface_index                       Pointer to interface through  */
65 /*                                            which the neighbor can be   */
66 /*                                            reached.                    */
67 /*                                                                        */
68 /*  OUTPUT                                                                */
69 /*                                                                        */
70 /*    status                                Completion status             */
71 /*                                                                        */
72 /*  CALLS                                                                 */
73 /*                                                                        */
74 /*    _nxd_nd_cache_hardware_address_find  Find entry by IP address       */
75 /*                                                                        */
76 /*  CALLED BY                                                             */
77 /*                                                                        */
78 /*    Application Code                                                    */
79 /*                                                                        */
80 /*  RELEASE HISTORY                                                       */
81 /*                                                                        */
82 /*    DATE              NAME                      DESCRIPTION             */
83 /*                                                                        */
84 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
85 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
86 /*                                            resulting in version 6.1    */
87 /*                                                                        */
88 /**************************************************************************/
_nxde_nd_cache_hardware_address_find(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,ULONG * physical_msw,ULONG * physical_lsw,UINT * interface_index)89 UINT  _nxde_nd_cache_hardware_address_find(NX_IP *ip_ptr,
90                                            NXD_ADDRESS *ip_address,
91                                            ULONG *physical_msw,
92                                            ULONG *physical_lsw,
93                                            UINT *interface_index)
94 {
95 #ifdef FEATURE_NX_IPV6
96 
97     /* Check for invalid input pointers.  */
98     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
99     {
100         return(NX_PTR_ERROR);
101     }
102 
103     /* Check for invalid IP and MAC address input*/
104     if ((ip_address == NX_NULL) || (physical_msw == NX_NULL) || (physical_lsw == NX_NULL))
105     {
106         return(NX_PTR_ERROR);
107     }
108 
109     /* Check the address is an IPv6 address. */
110     if (ip_address -> nxd_ip_version != NX_IP_VERSION_V6)
111     {
112         return(NX_INVALID_PARAMETERS);
113     }
114 
115     if (interface_index == NX_NULL)
116     {
117         return(NX_PTR_ERROR);
118     }
119 
120     /* Check for appropriate caller.  */
121     NX_THREADS_ONLY_CALLER_CHECKING
122 
123     /* Call the actual service and return completion status. */
124     return(_nxd_nd_cache_hardware_address_find(ip_ptr, ip_address, physical_msw, physical_lsw, interface_index));
125 
126 #else /* !FEATURE_NX_IPV6 */
127     NX_PARAMETER_NOT_USED(ip_ptr);
128     NX_PARAMETER_NOT_USED(ip_address);
129     NX_PARAMETER_NOT_USED(physical_msw);
130     NX_PARAMETER_NOT_USED(physical_lsw);
131     NX_PARAMETER_NOT_USED(interface_index);
132 
133     return(NX_NOT_SUPPORTED);
134 
135 #endif /* FEATURE_NX_IPV6 */
136 }
137 
138