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 #include "nx_packet.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _nx_arp_gratuitous_send PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Yuxin Zhou, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function goes through all the physical interfaces to transmit */ 45 /* gratuitous ARP message as long as the interface IP address is */ 46 /* valid. If a response is received at a later time, the supplied */ 47 /* response handler is called. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* ip_ptr Pointer to IP instance */ 52 /* response_handler Pointer to function to handle */ 53 /* Gratuitous ARP response */ 54 /* */ 55 /* OUTPUT */ 56 /* */ 57 /* NX_SUCCESS Successful completion status */ 58 /* */ 59 /* CALLS */ 60 /* */ 61 /* _nx_arp_announce_send Send ARP announce */ 62 /* tx_mutex_get Get protection mutex */ 63 /* tx_mutex_put Put protection mutex */ 64 /* */ 65 /* CALLED BY */ 66 /* */ 67 /* Application Code */ 68 /* */ 69 /* RELEASE HISTORY */ 70 /* */ 71 /* DATE NAME DESCRIPTION */ 72 /* */ 73 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 74 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 75 /* resulting in version 6.1 */ 76 /* */ 77 /**************************************************************************/ _nx_arp_gratuitous_send(NX_IP * ip_ptr,VOID (* response_handler)(NX_IP * ip_ptr,NX_PACKET * packet_ptr))78UINT _nx_arp_gratuitous_send(NX_IP *ip_ptr, VOID (*response_handler)(NX_IP *ip_ptr, NX_PACKET *packet_ptr)) 79 { 80 81 #ifndef NX_DISABLE_IPV4 82 ULONG i; 83 84 /* Get mutex protection. */ 85 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER); 86 87 /* Save the response handler in the IP structure. */ 88 ip_ptr -> nx_ip_arp_gratuitous_response_handler = response_handler; 89 90 /* Release mutex protection. */ 91 tx_mutex_put(&(ip_ptr -> nx_ip_protection)); 92 93 /* Loop to send ARP announce for all interfaces. */ 94 for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++) 95 { 96 97 /* Skip the entry the IP address is invalid */ 98 /*lint -e{539} suppress positive indentation. */ 99 if (ip_ptr -> nx_ip_interface[i].nx_interface_ip_address == 0) 100 { 101 continue; 102 } 103 104 /* Send ARP announce. */ 105 _nx_arp_announce_send(ip_ptr, i); 106 } 107 108 /* Return a successful completion. */ 109 return(NX_SUCCESS); 110 #else /* NX_DISABLE_IPV4 */ 111 NX_PARAMETER_NOT_USED(ip_ptr); 112 NX_PARAMETER_NOT_USED(response_handler); 113 114 return(NX_NOT_SUPPORTED); 115 #endif /* !NX_DISABLE_IPV4 */ 116 } 117 118