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 /** Internet Protocol (IP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24 /* Include necessary system files. */
25
26 #include "nx_api.h"
27 #include "nx_arp.h"
28
29 #ifndef NX_DISABLE_IPV4
30 /**************************************************************************/
31 /* */
32 /* FUNCTION RELEASE */
33 /* */
34 /* _nx_arp_interface_entries_delete PORTABLE C */
35 /* 6.1 */
36 /* AUTHOR */
37 /* */
38 /* Yuxin Zhou, Microsoft Corporation */
39 /* */
40 /* DESCRIPTION */
41 /* */
42 /* This function removes ARP entries associated with the interface */
43 /* specified by index from the IP's arp table. */
44 /* */
45 /* INPUT */
46 /* */
47 /* ip_ptr Pointer to IP control block */
48 /* index IP interface index */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* status Completion status */
53 /* */
54 /* CALLS */
55 /* */
56 /* tx_mutex_get Obtain protection mutex */
57 /* _nx_arp_dynamic_entry_delete Delete dynamic ARP entry */
58 /* _nx_arp_static_entry_delete_internal Internal static ARP entry */
59 /* delete function */
60 /* tx_mutex_put release protection mutex */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
71 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_nx_arp_interface_entries_delete(NX_IP * ip_ptr,UINT index)75 UINT _nx_arp_interface_entries_delete(NX_IP *ip_ptr, UINT index)
76 {
77
78 NX_ARP *arp_entry;
79 NX_ARP *next_arp_entry;
80 NX_ARP *last_arp_entry;
81 NX_INTERFACE *interface_ptr;
82
83 interface_ptr = &(ip_ptr -> nx_ip_interface[index]);
84
85 /* Obtain protection on this IP instance for access into the ARP dynamic list. */
86 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
87
88 /* Begain remove ARP entries from the dynamic list. */
89
90 /* Setup pointers to the starting and ending ARP entries in the dynamic list. */
91 arp_entry = ip_ptr -> nx_ip_arp_dynamic_list;
92
93 /* Walk through the dynamic ARP list until there are no more active entries. */
94 while ((arp_entry) && (ip_ptr -> nx_ip_arp_dynamic_active_count))
95 {
96
97 /* Yes, there is one or more dynamic entries. */
98 /* Determine if this ARP entry is for the specified interface. */
99 if (arp_entry -> nx_arp_ip_interface == interface_ptr)
100 {
101
102 _nx_arp_dynamic_entry_delete(ip_ptr, arp_entry);
103
104 /* Cleanup the nx_arp_ip_interface filed. */
105 arp_entry -> nx_arp_ip_interface = NX_NULL;
106 }
107
108 /* Determine if we are at the end of the dynamic list. */
109 if (arp_entry -> nx_arp_pool_next != ip_ptr -> nx_ip_arp_dynamic_list)
110 {
111 /* No, simply move to the next dynamic entry. */
112 arp_entry = arp_entry -> nx_arp_pool_next;
113 }
114 else
115 {
116 /* Yes, we are at the end of the dynamic list, break out of the loop. */
117 break;
118 }
119 }
120
121 /* End remove ARP entries from the dynamic list. */
122
123 /* Begain remove ARP entries from the static list. */
124
125 /* Setup pointers to the starting/ending ARP entry in the static list. */
126 next_arp_entry = ip_ptr -> nx_ip_arp_static_list;
127 if (next_arp_entry)
128 {
129
130 /* Pick up the last ARP entry. */
131 last_arp_entry = next_arp_entry -> nx_arp_pool_previous;
132
133 /* Walk through the static ARP list until there are no more active entries. */
134 while (next_arp_entry)
135 {
136
137 /* Yes, there is one or more static ARP entries. */
138 arp_entry = next_arp_entry;
139
140 /* Move to the next pakcet in the queue. */
141 next_arp_entry = next_arp_entry -> nx_arp_pool_next;
142
143 if (arp_entry -> nx_arp_ip_interface == interface_ptr)
144 {
145
146 /* The static entry was found. It needs to be unlinked from the active
147 list and the static list and re-linked to the end of the dynamic list. */
148 _nx_arp_static_entry_delete_internal(ip_ptr, arp_entry);
149 }
150
151 if (arp_entry == last_arp_entry)
152 {
153 break;
154 }
155 }
156 }
157
158 /* End remove ARP entries from the static list. */
159
160 /* Release the mutex. */
161 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
162
163 /* Return successful status to the caller. */
164 return(NX_SUCCESS);
165 }
166 #endif /* !NX_DISABLE_IPV4 */
167
168