]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Simplify filling ARP packet
authorMartin Schwenke <mschwenke@ddn.com>
Tue, 6 Jan 2026 03:12:31 +0000 (14:12 +1100)
committerMartin Schwenke <martins@samba.org>
Mon, 27 Jul 2026 03:44:35 +0000 (03:44 +0000)
Only one field is different between request and reply.  Factor out the
common code so it is above and below a simplified if-statement that
handles just the different field.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Vinit Agnihotri <vagnihot@redhat.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/system_socket.c

index 282f154357157886efa9e5b3548e159ed200cebd..fa939505a102f544cb689377d77e1320d4aa0c49 100644 (file)
@@ -329,20 +329,16 @@ static int arp_build(uint8_t *buffer,
        ah->ar_pro = htons(ETH_P_IP);
        ah->ar_hln = ETH_ALEN;
        ah->ar_pln = sizeof(ea->arp_spa);
+       ah->ar_op = htons(arpop);
 
+       memcpy(ea->arp_sha, hwaddr, ETH_ALEN);
+       memcpy(ea->arp_spa, &addr->sin_addr, sizeof(ea->arp_spa));
        if (arpop == ARPOP_REQUEST) {
-               ah->ar_op  = htons(arpop);
-               memcpy(ea->arp_sha, hwaddr, ETH_ALEN);
-               memcpy(ea->arp_spa, &addr->sin_addr, sizeof(ea->arp_spa));
-               memset(ea->arp_tha, 0, ETH_ALEN);
-               memcpy(ea->arp_tpa, &addr->sin_addr, sizeof(ea->arp_tpa));
+               /* Field must be all 0s - already done by memset() above */
        } else {
-               ah->ar_op  = htons(arpop);
-               memcpy(ea->arp_sha, hwaddr, ETH_ALEN);
-               memcpy(ea->arp_spa, &addr->sin_addr, sizeof(ea->arp_spa));
                memcpy(ea->arp_tha, hwaddr, ETH_ALEN);
-               memcpy(ea->arp_tpa, &addr->sin_addr, sizeof(ea->arp_tpa));
        }
+       memcpy(ea->arp_tpa, &addr->sin_addr, sizeof(ea->arp_tpa));
 
        *ether_dhost = (struct ether_addr *)eh->ether_dhost;
        *len = l;