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_entry_delete PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function removes a previously setup static IP to hardware */
45 /* mapping and returns the associated ARP entry back to the dynamic */
46 /* ARP pool. */
47 /* */
48 /* INPUT */
49 /* */
50 /* ip_ptr IP instance pointer */
51 /* ip_address IP Address binding to delete */
52 /* physical_msw Physical address MSW */
53 /* physical_lsw Physical address LSW */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* status Completion status */
58 /* */
59 /* CALLS */
60 /* */
61 /* tx_mutex_get Obtain protection mutex */
62 /* _nx_arp_static_entry_delete_internal Internal ARP entry delete */
63 /* tx_mutex_put Release protection mutex */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* _nx_arp_static_entries_delete Delete all static entries */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
75 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* */
78 /**************************************************************************/
_nx_arp_static_entry_delete(NX_IP * ip_ptr,ULONG ip_address,ULONG physical_msw,ULONG physical_lsw)79 UINT _nx_arp_static_entry_delete(NX_IP *ip_ptr, ULONG ip_address,
80 ULONG physical_msw, ULONG physical_lsw)
81 {
82
83 #ifndef NX_DISABLE_IPV4
84 NX_ARP *arp_entry;
85 UINT status;
86
87
88 /* If trace is enabled, insert this event into the trace buffer. */
89 NX_TRACE_IN_LINE_INSERT(NX_TRACE_ARP_STATIC_ENTRY_DELETE, ip_ptr, ip_address, physical_msw, physical_lsw, NX_TRACE_ARP_EVENTS, 0, 0);
90
91 /* Obtain protection on this IP instance for access into the ARP static
92 list. */
93 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
94
95 /* Search the static list for a matching IP and hardware mapping. */
96 arp_entry = ip_ptr -> nx_ip_arp_static_list;
97 while (arp_entry)
98 {
99
100 /* Determine if we have a match. */
101 if ((arp_entry -> nx_arp_ip_address == ip_address) &&
102 (arp_entry -> nx_arp_physical_address_msw == physical_msw) &&
103 (arp_entry -> nx_arp_physical_address_lsw == physical_lsw))
104 {
105
106 /* Yes, we have found the ARP entry we are looking for. */
107 break;
108 }
109 else
110 {
111
112 /* Determine if we are at the end of the list. */
113 if (arp_entry -> nx_arp_pool_next == ip_ptr -> nx_ip_arp_static_list)
114 {
115
116 /* Set the arp_entry to NULL to signify nothing was found and get
117 out of the search loop. */
118 arp_entry = NX_NULL;
119 break;
120 }
121 else
122 {
123
124 /* Just move to the next ARP entry on the static list. */
125 arp_entry = arp_entry -> nx_arp_pool_next;
126 }
127 }
128 }
129
130 /* At this point the ARP entry pointer determines whether or not anything was found
131 on the static list. */
132 if (arp_entry)
133 {
134
135 /* The static entry was found. It needs to be unlinked from the active
136 list and the static list and re-linked to the end of the dynamic list. */
137 _nx_arp_static_entry_delete_internal(ip_ptr, arp_entry);
138
139 /* Setup the return status. */
140 status = NX_SUCCESS;
141 }
142 else
143 {
144
145 /* Indicate the entry was not found. */
146 status = NX_ENTRY_NOT_FOUND;
147 }
148
149 /* Release the protection on the ARP list. */
150 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
151
152 /* Return status to the caller. */
153 return(status);
154 #else /* NX_DISABLE_IPV4 */
155 NX_PARAMETER_NOT_USED(ip_ptr);
156 NX_PARAMETER_NOT_USED(ip_address);
157 NX_PARAMETER_NOT_USED(physical_msw);
158 NX_PARAMETER_NOT_USED(physical_lsw);
159
160 return(NX_NOT_SUPPORTED);
161 #endif /* !NX_DISABLE_IPV4 */
162 }
163
164