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