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_ipv6.h"
31 #endif /* FEATURE_NX_IPV6 */
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _nxd_nd_cache_entry_set PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* Yuxin Zhou, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function creates an entry with the specified IPv6 address and */
47 /* hardware MAC address mapping and adds it to the Neighbor Discovery */
48 /* (ND) cache. */
49 /* */
50 /* INPUT */
51 /* */
52 /* ip_ptr Pointer to the IP instance */
53 /* dest_ip Pointer to the IP address */
54 /* to add (map) */
55 /* interface_index Index to the network */
56 /* interface */
57 /* mac Pointer to the MAC address to */
58 /* be added (map) */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* status Completion status */
63 /* */
64 /* CALLS */
65 /* */
66 /* _nx_nd_cache_add Actual function to add an */
67 /* entry to the cache. */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application Code */
72 /* */
73 /* RELEASE HISTORY */
74 /* */
75 /* DATE NAME DESCRIPTION */
76 /* */
77 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
78 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
79 /* resulting in version 6.1 */
80 /* */
81 /**************************************************************************/
_nxd_nd_cache_entry_set(NX_IP * ip_ptr,ULONG * dest_ip,UINT interface_index,CHAR * mac)82 UINT _nxd_nd_cache_entry_set(NX_IP *ip_ptr, ULONG *dest_ip, UINT interface_index, CHAR *mac)
83 {
84 #ifdef FEATURE_NX_IPV6
85
86 ND_CACHE_ENTRY *nd_cache_entry;
87 UINT status;
88
89
90 /* If trace is enabled, insert this event into the trace buffer. */
91 NX_TRACE_IN_LINE_INSERT(NXD_TRACE_ND_CACHE_ENTRY_SET, dest_ip[3], ((mac[0] << 16) | mac[1]), ((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5]),
92 0, NX_TRACE_ARP_EVENTS, 0, 0);
93
94 /* Call the actual cache entry add service. */
95 status = _nx_nd_cache_add(ip_ptr, dest_ip, ip_ptr -> nx_ipv6_address[interface_index].nxd_ipv6_address_attached, mac, 1, ND_CACHE_STATE_REACHABLE, &(ip_ptr -> nx_ipv6_address[interface_index]), &nd_cache_entry);
96
97 return(status);
98
99 #else /* !FEATURE_NX_IPV6 */
100 NX_PARAMETER_NOT_USED(ip_ptr);
101 NX_PARAMETER_NOT_USED(dest_ip);
102 NX_PARAMETER_NOT_USED(interface_index);
103 NX_PARAMETER_NOT_USED(mac);
104
105 return(NX_NOT_SUPPORTED);
106
107 #endif /* FEATURE_NX_IPV6 */
108 }
109
110