From: Felix Fietkau Date: Mon, 30 Aug 2010 12:56:25 +0000 (+0200) Subject: improve the reliability of gratuitous arp by sending both request and reply, also... X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=57371a95114800aca0f196a637783c6ce5ab19fc;p=project%2Frelayd.git improve the reliability of gratuitous arp by sending both request and reply, also set the target hardware address to broadcast --- diff --git a/main.c b/main.c index 3196a1e..e2886de 100644 --- a/main.c +++ b/main.c @@ -213,8 +213,8 @@ static void send_arp_reply(struct relayd_interface *rif, const uint8_t spa[4], fill_arp_packet(&pkt, rif, spa, tpa); - pkt.arp.arp_op = htons(ARPOP_REPLY); if (tha) { + pkt.arp.arp_op = htons(ARPOP_REPLY); memcpy(pkt.eth.ether_dhost, tha, ETH_ALEN); memcpy(pkt.arp.arp_tha, tha, ETH_ALEN); @@ -222,8 +222,9 @@ static void send_arp_reply(struct relayd_interface *rif, const uint8_t spa[4], rif->ifname, IP_BUF(pkt.arp.arp_tpa), IP_BUF(pkt.arp.arp_spa), MAC_BUF(pkt.eth.ether_shost)); } else { + pkt.arp.arp_op = htons(ARPOP_REQUEST); memset(pkt.eth.ether_dhost, 0xff, ETH_ALEN); - memset(pkt.arp.arp_tha, 0, ETH_ALEN); + memset(pkt.arp.arp_tha, 0xff, ETH_ALEN); DPRINTF(2, "%s: sending gratuitous ARP: "IP_FMT" is at ("MAC_FMT")\n", rif->ifname, IP_BUF(pkt.arp.arp_tpa), @@ -232,6 +233,20 @@ static void send_arp_reply(struct relayd_interface *rif, const uint8_t spa[4], sendto(rif->fd.fd, &pkt, sizeof(pkt), 0, (struct sockaddr *) &rif->sll, sizeof(rif->sll)); + + if (tha) + return; + + /* + * Gratuitous ARP comes in two flavours, request and reply. + * Some operating systems only accept request, some only reply. + * Let's just send both... + */ + pkt.arp.arp_op = htons(ARPOP_REPLY); + + sendto(rif->fd.fd, &pkt, sizeof(pkt), 0, + (struct sockaddr *) &rif->sll, sizeof(rif->sll)); + } static void host_entry_timeout(struct uloop_timeout *timeout)