From: Martin Schwenke Date: Tue, 6 Jan 2026 03:12:31 +0000 (+1100) Subject: ctdb-common: Simplify filling ARP packet X-Git-Tag: talloc-2.5.0~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56cadd3ca48e049ba7dcdc0f220edea230c3a6c9;p=thirdparty%2Fsamba.git ctdb-common: Simplify filling ARP packet 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 Reviewed-by: Vinit Agnihotri Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index 282f1543571..fa939505a10 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -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;