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 /*  FUNCTION                                               RELEASE        */
42 /*                                                                        */
43 /*    _nxde_nd_cache_ip_address_find                      PORTABLE C      */
44 /*                                                           6.1          */
45 /*  AUTHOR                                                                */
46 /*                                                                        */
47 /*    Yuxin Zhou, Microsoft Corporation                                   */
48 /*                                                                        */
49 /*  DESCRIPTION                                                           */
50 /*                                                                        */
51 /*    This function performs error checking in finding ND cache entry.    */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    ip_ptr                                Pointer to IP instance        */
56 /*    ip_address                            Pointer to the IP address     */
57 /*                                            to search for               */
58 /*    physical_msw                          Physical address, most        */
59 /*                                            significant word            */
60 /*    physical_lsw                          Physical address, least       */
61 /*                                            significant word            */
62 /*    interface_index                       Index to the network          */
63 /*                                            interface through which the */
64 /*                                            node is reachable.          */
65 /*                                                                        */
66 /*  OUTPUT                                                                */
67 /*                                                                        */
68 /*    status                                Completion status             */
69 /*                                                                        */
70 /*  CALLS                                                                 */
71 /*                                                                        */
72 /*    _nxd_ipv6_nd_cache_ip_address_find    Find entry by mac address.    */
73 /*                                                                        */
74 /*  CALLED BY                                                             */
75 /*                                                                        */
76 /*    Application Code                                                    */
77 /*                                                                        */
78 /*  RELEASE HISTORY                                                       */
79 /*                                                                        */
80 /*    DATE              NAME                      DESCRIPTION             */
81 /*                                                                        */
82 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
83 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
84 /*                                            resulting in version 6.1    */
85 /*                                                                        */
86 /**************************************************************************/
_nxde_nd_cache_ip_address_find(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,ULONG physical_msw,ULONG physical_lsw,UINT * interface_index)87 UINT  _nxde_nd_cache_ip_address_find(NX_IP *ip_ptr,
88                                      NXD_ADDRESS *ip_address,
89                                      ULONG physical_msw,
90                                      ULONG physical_lsw,
91                                      UINT *interface_index)
92 {
93 #ifdef FEATURE_NX_IPV6
94 
95     /* Check for invalid input pointers.  */
96     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
97     {
98         return(NX_PTR_ERROR);
99     }
100 
101     /* Check for valid address pointer. */
102     if (ip_address == NX_NULL)
103     {
104         return(NX_PTR_ERROR);
105     }
106 
107     if (interface_index == NX_NULL)
108     {
109         return(NX_PTR_ERROR);
110     }
111 
112     /* Check for valid MAC hardware address input. */
113     if ((physical_msw == 0) && (physical_lsw == 0))
114     {
115         return(NX_INVALID_PARAMETERS);
116     }
117 
118     /* Check for appropriate caller.  */
119     NX_THREADS_ONLY_CALLER_CHECKING
120 
121     /* Call the actual service and return completion status. */
122     return(_nxd_nd_cache_ip_address_find(ip_ptr, ip_address, physical_msw, physical_lsw, interface_index));
123 
124 #else /* !FEATURE_NX_IPV6 */
125     NX_PARAMETER_NOT_USED(ip_ptr);
126     NX_PARAMETER_NOT_USED(ip_address);
127     NX_PARAMETER_NOT_USED(physical_msw);
128     NX_PARAMETER_NOT_USED(physical_lsw);
129     NX_PARAMETER_NOT_USED(interface_index);
130 
131     return(NX_NOT_SUPPORTED);
132 
133 #endif /* FEATURE_NX_IPV6 */
134 }
135 
136