blob: b01b59f323daf229dd2cbdab619031c03eb261ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2025-present Eclipse ThreadX Contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** NetX Component */
/** */
/** Neighbor Discovery Cache */
/** */
/**************************************************************************/
/**************************************************************************/
#define NX_SOURCE_CODE
/* Include necessary system files. */
#include "nx_api.h"
#include "nx_ipv6.h"
#include "nx_nd_cache.h"
#ifdef FEATURE_NX_IPV6
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* nx_nd_cache_find_entry_by_mac_addr PORTABLE C */
/* 6.4.3 */
/* AUTHOR */
/* */
/* Yuxin Zhou, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This internal function finds an entry in the ND cache that is */
/* mapped to the specified MAC address. */
/* */
/* INPUT */
/* */
/* ip_ptr Pointer to IP instance */
/* physical_msw Physical address, most significant word */
/* physical_lsw Physical address, least significant word */
/* nd_cache_entry User specified storage space for pointer to*/
/* the corresponding ND cache. */
/* */
/* OUTPUT */
/* */
/* status NX_SUCCESS: The ND cache entry is located. */
/* nd_cache_entry contains valid value. */
/* NX_NOT_SUCCESSFUL: The ND cache entry */
/* cannot be found, or nd_cache_entry is */
/* NULL. */
/* */
/* CALLS */
/* */
/* tx_mutex_get Obtain protection mutex */
/* tx_mutex_put Release protection mutex */
/* */
/* CALLED BY */
/* */
/* _nxd_nd_cache_ip_address_find User level service */
/* Application Code */
/* */
/**************************************************************************/
UINT _nx_nd_cache_find_entry_by_mac_addr(NX_IP *ip_ptr, ULONG physical_msw,
ULONG physical_lsw, ND_CACHE_ENTRY **nd_cache_entry)
{
INT i;
ULONG mac_msw, mac_lsw;
/* Initialize the return value. */
*nd_cache_entry = NX_NULL;
/* Loop to match the physical address. */
for (i = 0; i < NX_IPV6_NEIGHBOR_CACHE_SIZE; i++)
{
/* Check the interface pointer. */
if (ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_interface_ptr == NX_NULL)
{
continue;
}
/* Check the ND CACHE status. */
if (ip_ptr -> nx_ipv6_nd_cache[i].nx_nd_cache_nd_status == ND_CACHE_STATE_INVALID)
{
continue;
}
/* Set the physical address. */
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];
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) |
((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];
/* Check the physical address. */
if ((mac_msw == physical_msw) && (mac_lsw == physical_lsw))
{
/* Find a match */
*nd_cache_entry = &ip_ptr -> nx_ipv6_nd_cache[i];
return(NX_SUCCESS);
}
}
return(NX_NOT_SUCCESSFUL);
}
#endif /* FEATURE_NX_IPV6 */
|