1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Neighbor Discovery Cache Management (ND CAHCE)                      */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
27 /*                                                                        */
28 /*    nx_nd_cache.h                                       PORTABLE C      */
29 /*                                                           6.1          */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Yuxin Zhou, Microsoft Corporation                                   */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the basic Application Interface (API) to the      */
37 /*    high-performance NetX IPv6 Neighbor Discovery Cache implementation  */
38 /*    for the ThreadX real-time kernel.  All service prototypes and data  */
39 /*    structure definitions are defined in this file. Please note that    */
40 /*    basic data type definitions and other architecture-specific         */
41 /*    information is contained in the file nx_port.h.                     */
42 /*                                                                        */
43 /*    It is assumed that nx_api.h and nx_port.h have already been         */
44 /*    included.                                                           */
45 /*                                                                        */
46 /*    This header file is for NetX Duo internal use only.  Application    */
47 /*    shall not include this file directly.                               */
48 /*                                                                        */
49 /*  RELEASE HISTORY                                                       */
50 /*                                                                        */
51 /*    DATE              NAME                      DESCRIPTION             */
52 /*                                                                        */
53 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
54 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
55 /*                                            resulting in version 6.1    */
56 /*                                                                        */
57 /**************************************************************************/
58 
59 #ifndef NX_ND_CACHE_H
60 #define NX_ND_CACHE_H
61 
62 
63 #include "nx_ip.h"
64 #include "nx_ipv6.h"
65 
66 #ifdef FEATURE_NX_IPV6
67 
68 
69 /* Symbols used the states of ND entries. */
70 #define ND_CACHE_STATE_INVALID    0
71 #define ND_CACHE_STATE_INCOMPLETE 1
72 #define ND_CACHE_STATE_REACHABLE  2
73 #define ND_CACHE_STATE_STALE      3
74 #define ND_CACHE_STATE_DELAY      4
75 #define ND_CACHE_STATE_PROBE      5
76 #define ND_CACHE_STATE_CREATED    6
77 
78 /*
79  * Define values used for Neighbor Discovery protocol.
80  * The default values are suggested by RFC2461, chapter 10.
81  */
82 
83 
84 #ifndef NX_MAX_MULTICAST_SOLICIT
85 /* Max multicast NS messages */
86 #define NX_MAX_MULTICAST_SOLICIT  3
87 #endif
88 
89 #ifndef NX_MAX_UNICAST_SOLICIT
90 /* Max unicast NS messages. */
91 #define NX_MAX_UNICAST_SOLICIT    3
92 #endif
93 
94 #ifndef NX_REACHABLE_TIME
95 /* Max reachable time, in seconds. */
96 #define NX_REACHABLE_TIME         30
97 #endif
98 
99 #ifndef NX_RETRANS_TIMER
100 /* Max retrans timer, in milliseconds. */
101 #define NX_RETRANS_TIMER          1000
102 #endif
103 
104 #ifndef NX_DELAY_FIRST_PROBE_TIME
105 #define NX_DELAY_FIRST_PROBE_TIME 5
106 #endif
107 
108 /* Declare internal functions */
109 UINT _nx_nd_cache_interface_entries_delete(NX_IP *ip_ptr, UINT index);
110 
111 /* Add en entry to the cache. */
112 UINT _nx_nd_cache_add(NX_IP *ip_ptr, ULONG *dest_ip, NX_INTERFACE *if_index, CHAR *mac, INT IsStatic, INT status, NXD_IPV6_ADDRESS *nxd_interface, ND_CACHE_ENTRY **entry);
113 
114 
115 /* Delete an entry based on IP address. */
116 UINT _nx_nd_cache_delete_internal(NX_IP *ip_ptr, ND_CACHE_ENTRY *entry);
117 
118 /* 100ms periodic update. */
119 VOID _nx_nd_cache_fast_periodic_update(NX_IP *ip_ptr);
120 
121 /* Find cache entry based on neighbor IP address. */
122 UINT _nx_nd_cache_find_entry(NX_IP *ip_ptr, ULONG *dest_ip, ND_CACHE_ENTRY **entry);
123 
124 /* Find cache entry based on neighbor IP address.  If not found, create new entry. */
125 UINT _nx_nd_cache_add_entry(NX_IP *ip_ptr, ULONG *dest_ip, NXD_IPV6_ADDRESS *nxd_address, ND_CACHE_ENTRY **entry);
126 
127 /* Find cache entry based on LLA. */
128 UINT _nx_nd_cache_find_entry_by_mac_addr(NX_IP *ip_ptr, ULONG physical_msw, ULONG physical_lsw, ND_CACHE_ENTRY **entry);
129 
130 /* The real function that invalidates the whole cache. */
131 VOID _nxd_nd_cache_invalidate_internal(NX_IP *ip_ptr);
132 
133 /* One second periodic update. */
134 VOID _nx_nd_cache_slow_periodic_update(NX_IP *ip_ptr);
135 
136 /* Invalidate a given entry from the neighbor discovery table. */
137 VOID _nx_invalidate_destination_entry(NX_IP *ip_ptr, ULONG *next_hop_ip);
138 #endif /* FEATURE_NX_IPV6 */
139 
140 
141 /* Delete an entry based on IP address. */
142 UINT _nxd_nd_cache_entry_delete(NX_IP *ip_ptr, ULONG *dest_ip);
143 UINT _nxde_nd_cache_entry_delete(NX_IP *ip_ptr, ULONG *dest_ip);
144 
145 /* Create an IPv6-MAC mapping to the ND cache entry. */
146 UINT _nxd_nd_cache_entry_set(NX_IP *ip_ptr, ULONG *dest_ip, UINT if_index, CHAR *mac);
147 UINT _nxde_nd_cache_entry_set(NX_IP *ip_ptr, ULONG *dest_ip, UINT if_index, CHAR *mac);
148 
149 /* Invalidate the whole cache. */
150 UINT _nxd_nd_cache_invalidate(NX_IP *ip_ptr);
151 UINT _nxde_nd_cache_invalidate(NX_IP *ip_ptr);
152 
153 UINT _nxd_nd_cache_ip_address_find(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, ULONG physical_msw, ULONG physical_lsw, UINT *if_index);
154 UINT _nxde_nd_cache_ip_address_find(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, ULONG physical_msw, ULONG physical_lsw, UINT *if_index);
155 
156 UINT _nxd_nd_cache_hardware_address_find(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, ULONG *physical_msw, ULONG *physical_lsw, UINT *if_index);
157 UINT _nxde_nd_cache_hardware_address_find(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, ULONG *physical_msw, ULONG *physical_lsw, UINT *if_index);
158 
159 #endif /* NX_ND_CACHE_H */
160 
161