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