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 /**   Address Resolution Protocol (ARP)                                   */
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_arp.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_arp_dynamic_entries_invalidate                  PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function invalidates all ARP dynamic entries currently in      */
44 /*    the ARP cache.                                                      */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    ip_ptr                                IP instance pointer           */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    status                                Completion status             */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    tx_mutex_get                          Obtain protection mutex       */
57 /*    tx_mutex_put                          Release protection mutex      */
58 /*    _nx_arp_dynamic_entry_delete          Delete dynamic ARP entry      */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    Application Code                                                    */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
69 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_nx_arp_dynamic_entries_invalidate(NX_IP * ip_ptr)73 UINT  _nx_arp_dynamic_entries_invalidate(NX_IP *ip_ptr)
74 {
75 
76 #ifndef NX_DISABLE_IPV4
77 NX_ARP *arp_entry;
78 
79 
80     /* If trace is enabled, insert this event into the trace buffer.  */
81     NX_TRACE_IN_LINE_INSERT(NX_TRACE_ARP_DYNAMIC_ENTRIES_INVALIDATE, ip_ptr, ip_ptr -> nx_ip_arp_dynamic_active_count, 0, 0, NX_TRACE_ARP_EVENTS, 0, 0);
82 
83     /* Obtain protection on this IP instance for access into the ARP dynamic
84        list.  */
85     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
86 
87     /* Setup pointers to the starting and ending ARP entries in the dynamic list.  */
88     arp_entry = ip_ptr -> nx_ip_arp_dynamic_list;
89 
90     /* Walk through the dynamic ARP list until there are no more active entries.  */
91     while ((arp_entry) && (ip_ptr -> nx_ip_arp_dynamic_active_count))
92     {
93 
94         /* Remove from the dynamic list. */
95         _nx_arp_dynamic_entry_delete(ip_ptr, arp_entry);
96 
97         /* Cleanup the nx_arp_ip_interface field. */
98         arp_entry -> nx_arp_ip_interface = NX_NULL;
99 
100         /* Determine if we are at the end of the dynamic list.  */
101         if (arp_entry -> nx_arp_pool_next != ip_ptr -> nx_ip_arp_dynamic_list)
102         {
103 
104             /* No, simply move to the next dynamic entry.  */
105             arp_entry =  arp_entry -> nx_arp_pool_next;
106         }
107         else
108         {
109 
110             /* Yes, we are at the end of the dynamic list, break out of the loop.  */
111             break;
112         }
113     }
114 
115     /* Release the mutex.  */
116     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
117 
118     /* Return successful status to the caller.  */
119     return(NX_SUCCESS);
120 #else /* NX_DISABLE_IPV4  */
121     NX_PARAMETER_NOT_USED(ip_ptr);
122 
123     return(NX_NOT_SUPPORTED);
124 #endif /* !NX_DISABLE_IPV4  */
125 }
126 
127