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_invalidate                            PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function invalidates the entire IPv6 Neighbor Discovery cache. */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    ip_ptr                                Pointer to IP instance        */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    NX_SUCCESS                            Successful completion status  */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    tx_mutex_get                          Obtain protection mutex       */
59 /*    tx_mutex_put                          Release protection mutex      */
60 /*    _nxd_nd_cache_invalidate_internal     Actual cache table invalidate */
61 /*                                          service                       */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nxd_nd_cache_invalidate(NX_IP * ip_ptr)76 UINT _nxd_nd_cache_invalidate(NX_IP *ip_ptr)
77 {
78 
79 #ifdef FEATURE_NX_IPV6
80 INT idx;
81 
82     /* If trace is enabled, insert this event into the trace buffer.  */
83     NX_TRACE_IN_LINE_INSERT(NXD_TRACE_ND_CACHE_INVALIDATE, ip_ptr, 0, 0, 0, NX_TRACE_ARP_EVENTS, 0, 0);
84 
85     /* Obtain the protection. */
86     tx_mutex_get(&ip_ptr -> nx_ip_protection, TX_WAIT_FOREVER);
87 
88     /* Invalidate all entries. */
89     for (idx = 0; idx < NX_IPV6_NEIGHBOR_CACHE_SIZE; idx++)
90     {
91         _nx_nd_cache_delete_internal(ip_ptr, &(ip_ptr -> nx_ipv6_nd_cache[idx]));
92     }
93 
94     /* Release the protection. */
95     tx_mutex_put(&ip_ptr -> nx_ip_protection);
96 
97     return(NX_SUCCESS);
98 
99 #else /* !FEATURE_NX_IPV6 */
100 
101     NX_PARAMETER_NOT_USED(ip_ptr);
102 
103     return(NX_NOT_SUPPORTED);
104 
105 #endif /* FEATURE_NX_IPV6 */
106 }
107 
108