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_ipv6.h"
29 #include "nx_nd_cache.h"
30
31 #ifdef FEATURE_NX_IPV6
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* nx_nd_cache_find_entry_by_mac_addr PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* Yuxin Zhou, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This internal function finds an entry in the ND cache that is */
47 /* mapped to the specified MAC address. */
48 /* */
49 /* INPUT */
50 /* */
51 /* ip_ptr Pointer to IP instance */
52 /* physical_msw Physical address, most significant word */
53 /* physical_lsw Physical address, least significant word */
54 /* nd_cache_entry User specified storage space for pointer to*/
55 /* the corresponding ND cache. */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* status NX_SUCCESS: The ND cache entry is located. */
60 /* nd_cache_entry contains valid value. */
61 /* NX_NOT_SUCCESSFUL: The ND cache entry */
62 /* cannot be found, or nd_cache_entry is */
63 /* NULL. */
64 /* */
65 /* CALLS */
66 /* */
67 /* tx_mutex_get Obtain protection mutex */
68 /* tx_mutex_put Release protection mutex */
69 /* */
70 /* CALLED BY */
71 /* */
72 /* _nxd_nd_cache_ip_address_find User level service */
73 /* Application Code */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
80 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* */
83 /**************************************************************************/
_nx_nd_cache_find_entry_by_mac_addr(NX_IP * ip_ptr,ULONG physical_msw,ULONG physical_lsw,ND_CACHE_ENTRY ** nd_cache_entry)84 UINT _nx_nd_cache_find_entry_by_mac_addr(NX_IP *ip_ptr, ULONG physical_msw,
85 ULONG physical_lsw, ND_CACHE_ENTRY **nd_cache_entry)
86 {
87 INT i;
88 ULONG mac_msw, mac_lsw;
89
90 /* Initialize the return value. */
91 *nd_cache_entry = NX_NULL;
92
93 /* Loop to match the physical address. */
94 for (i = 0; i < NX_IPV6_NEIGHBOR_CACHE_SIZE; i++)
95 {
96
97 /* Check the interface pointer. */
98 if (ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_interface_ptr == NX_NULL)
99 {
100 continue;
101 }
102
103 /* Check the ND CACHE status. */
104 if (ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_nd_status == ND_CACHE_STATE_INVALID)
105 {
106 continue;
107 }
108
109 /* Set the physical address. */
110 mac_msw = ((ULONG)ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_mac_addr[0] << 8) | ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_mac_addr[1];
111 mac_lsw = ((ULONG)ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_mac_addr[2] << 24) | ((ULONG)ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_mac_addr[3] << 16) |
112 ((ULONG)ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_mac_addr[4] << 8) | ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_mac_addr[5];
113
114 /* Check the physical address. */
115 if ((mac_msw == physical_msw) && (mac_lsw == physical_lsw))
116 {
117
118 /* Find a match */
119 *nd_cache_entry = &ip_ptr -> nx_ipv6_nd_cache[i];
120
121 return(NX_SUCCESS);
122 }
123 }
124
125 return(NX_NOT_SUCCESSFUL);
126 }
127
128 #endif /* FEATURE_NX_IPV6 */
129
130