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 #include "nx_packet.h"
31 
32 #ifndef NX_DISABLE_IPV4
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _nx_arp_dynamic_entry_delete                        PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Yuxin Zhou, Microsoft Corporation                                   */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function deletes the ARP entry pointed to by the caller. Note  */
46 /*    the caller should already have searched the ARP list to verify a    */
47 /*    valid ARP entry to delete.  Also, it is assumed the caller already  */
48 /*    has obtained the IP protection mutex before invoking this service.  */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    ip_ptr                                IP instance of APR table      */
53 /*    arp_ptr                               ARP entry to delete           */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _nx_packet_transmit_release           Release the transmitted packet*/
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Internal                                                            */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_arp_dynamic_entry_delete(NX_IP * ip_ptr,NX_ARP * arp_ptr)76 UINT  _nx_arp_dynamic_entry_delete(NX_IP *ip_ptr, NX_ARP *arp_ptr)
77 {
78 
79 TX_INTERRUPT_SAVE_AREA
80 NX_PACKET *packet_ptr, *next_packet_ptr;
81 
82 
83     /* Determine if this ARP entry is already active.  */
84     if (arp_ptr -> nx_arp_active_list_head)
85     {
86 
87         /* Remove this dynamic ARP entry from the associated list.  */
88 
89         /* Disable interrupts.  */
90         TX_DISABLE
91 
92         /* Determine if this is the only ARP entry on the list.  */
93         if (arp_ptr == arp_ptr -> nx_arp_active_next)
94         {
95 
96             /* Remove the entry from the list.  */
97             *(arp_ptr -> nx_arp_active_list_head) =  NX_NULL;
98         }
99         else
100         {
101 
102             /* Remove the entry from a list of more than one entry.  */
103 
104             /* Update the list head pointer.  */
105             if (*(arp_ptr -> nx_arp_active_list_head) == arp_ptr)
106             {
107                 *(arp_ptr -> nx_arp_active_list_head) =  arp_ptr -> nx_arp_active_next;
108             }
109 
110             /* Update the links of the adjacent ARP entries.  */
111             (arp_ptr -> nx_arp_active_next) -> nx_arp_active_previous = arp_ptr -> nx_arp_active_previous;
112             (arp_ptr -> nx_arp_active_previous) -> nx_arp_active_next =  arp_ptr -> nx_arp_active_next;
113         }
114 
115         /* No longer active, clear the active list head.  */
116         arp_ptr -> nx_arp_active_list_head =  NX_NULL;
117 
118         /* Decrease the number of active ARP entries.  */
119         ip_ptr -> nx_ip_arp_dynamic_active_count--;
120 
121         /* Pickup the queued packets head pointer.  */
122         next_packet_ptr =  arp_ptr -> nx_arp_packets_waiting;
123 
124         /* Clear the queued packets head pointer.  */
125         arp_ptr -> nx_arp_packets_waiting =  NX_NULL;
126 
127         /* Restore interrupts.  */
128         TX_RESTORE
129 
130         /* Loop to remove all queued packets.  */
131         while (next_packet_ptr)
132         {
133 
134             /* Pickup the packet pointer at the head of the queue.  */
135             packet_ptr =  next_packet_ptr;
136 
137             /* Move to the next packet in the queue.  */
138             next_packet_ptr =  next_packet_ptr -> nx_packet_queue_next;
139 
140             /* Clear the next packet queue pointer.  */
141             packet_ptr -> nx_packet_queue_next =  NX_NULL;
142 
143 #ifndef NX_DISABLE_IP_INFO
144 
145             /* Increment the IP send packets dropped count.  */
146             ip_ptr -> nx_ip_send_packets_dropped++;
147 #endif
148 
149             /* Release the packet that was queued from the previous ARP entry.  */
150             _nx_packet_transmit_release(packet_ptr);
151         }
152     }
153 
154     return(NX_SUCCESS);
155 }
156 #endif /* !NX_DISABLE_IPV4  */
157 
158