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_static_entries_delete                       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function deletes all ARP static 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_static_entry_delete           Delete a static 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_static_entries_delete(NX_IP * ip_ptr)74 UINT  _nx_arp_static_entries_delete(NX_IP *ip_ptr)
75 {
76 
77 #ifndef NX_DISABLE_IPV4
78 #ifdef TX_ENABLE_EVENT_TRACE
79 TX_TRACE_BUFFER_ENTRY *trace_event;
80 ULONG                  trace_timestamp;
81 ULONG                  deleted_count =  0;
82 #endif
83 
84 
85     /* If trace is enabled, insert this event into the trace buffer.  */
86     NX_TRACE_IN_LINE_INSERT(NX_TRACE_ARP_STATIC_ENTRIES_DELETE, ip_ptr, 0, 0, 0, NX_TRACE_ARP_EVENTS, &trace_event, &trace_timestamp);
87 
88     /* Obtain protection on this IP instance for access into the ARP static
89        list.  */
90     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
91 
92     /* Traverse the static list until it is exhausted.  */
93     while (ip_ptr -> nx_ip_arp_static_list)
94     {
95 
96         /* Otherwise, delete the static entry delete routine.  Note that the delete routine
97            will modify the list head pointer used above. */
98         _nx_arp_static_entry_delete_internal(ip_ptr, ip_ptr -> nx_ip_arp_static_list);
99 
100 #ifdef TX_ENABLE_EVENT_TRACE
101 
102         /* Increment the deleted count.  */
103         deleted_count++;
104 #endif
105     }
106 
107     /* Update the trace event with the status.  */
108     NX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, NX_TRACE_ARP_STATIC_ENTRIES_DELETE, 0, deleted_count, 0, 0);
109 
110     /* Release the mutex.  */
111     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
112 
113     /* Return status to the caller.  */
114     return(NX_SUCCESS);
115 #else /* NX_DISABLE_IPV4  */
116     NX_PARAMETER_NOT_USED(ip_ptr);
117 
118     return(NX_NOT_SUPPORTED);
119 #endif /* !NX_DISABLE_IPV4  */
120 }
121 
122