improve the reliability of gratuitous arp by sending both request and reply, also...
authorFelix Fietkau <nbd@openwrt.org>
Mon, 30 Aug 2010 12:56:25 +0000 (14:56 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 30 Aug 2010 12:56:25 +0000 (14:56 +0200)
main.c

diff --git a/main.c b/main.c
index 3196a1e..e2886de 100644 (file)
--- 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);
 
 
        fill_arp_packet(&pkt, rif, spa, tpa);
 
-       pkt.arp.arp_op = htons(ARPOP_REPLY);
        if (tha) {
        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);
 
                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 {
                        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.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),
 
                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));
 
        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)
 }
 
 static void host_entry_timeout(struct uloop_timeout *timeout)