From: Martin Schwenke Date: Thu, 18 Dec 2025 03:07:55 +0000 (+1100) Subject: ctdb-common: Pass hardware address to ip6_na_build() X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=df8dcf31df0de6a71b0d6a86cfa4730ff7d034cd;p=thirdparty%2Fsamba.git ctdb-common: Pass hardware address to ip6_na_build() Use address, length and type in ip6_na_build(). Logically, this generalises the code to handle any hardware address type/length. 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 051455ddb2b..18d77fff671 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -614,7 +614,7 @@ static int ip6_ll_multicast_build(struct sockaddr_ll *in, static int ip6_na_build(uint8_t *buffer, size_t buflen, const struct sockaddr_in6 *addr, - const struct ether_addr *hwaddr, + const struct sockaddr_ll *hardware_addr, size_t *len) { struct ip6_hdr *ip6; @@ -693,8 +693,8 @@ static int ip6_na_build(uint8_t *buffer, * There is probably a cleverer way of writing the following, * but listen to Kernighan's Law and aim for clarity. */ - nd_oh->nd_opt_len = (2 + ETH_ALEN) / 8; - leftover = (2 + ETH_ALEN) % 8; + nd_oh->nd_opt_len = (2 + hardware_addr->sll_halen) / 8; + leftover = (2 + hardware_addr->sll_halen) % 8; padding = 0; if (leftover != 0) { nd_oh->nd_opt_len += 1; @@ -703,8 +703,8 @@ static int ip6_na_build(uint8_t *buffer, p += padding; } - memcpy(p, hwaddr, ETH_ALEN); - p += ETH_ALEN; + memcpy(p, hardware_addr->sll_addr, hardware_addr->sll_halen); + p += hardware_addr->sll_halen; /* * This is either buried down here (with a helpful comment in @@ -715,7 +715,7 @@ static int ip6_na_build(uint8_t *buffer, */ ip6->ip6_plen = htons(sizeof(struct nd_neighbor_advert) + sizeof(struct nd_opt_hdr) + - ETH_ALEN + + hardware_addr->sll_halen + padding); nd_na->nd_na_cksum = ip6_checksum((uint8_t *)nd_na, @@ -738,7 +738,6 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface) struct sockaddr_storage sas = {0}; socklen_t dest_len = 0; uint8_t buffer[MAX(ARP_BUFFER_SIZE, IP6_NA_BUFFER_SIZE)]; - struct ether_addr *hwaddr = NULL; size_t len = 0; int ret = 0; @@ -772,9 +771,6 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface) goto done; } - /* For clarity */ - hwaddr = (struct ether_addr *)hardware_addr_ll->sll_addr; - s = socket(AF_PACKET, SOCK_DGRAM, 0); if (s == -1) { ret = errno; @@ -862,7 +858,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface) ret = ip6_na_build(buffer, sizeof(buffer), &addr->ip6, - hwaddr, + hardware_addr_ll, &len); if (ret != 0) { DBG_ERR("Failed to build IPv6 neighbor advertisement\n"); diff --git a/ctdb/tests/src/system_socket_test.c b/ctdb/tests/src/system_socket_test.c index 58c01ddd148..1841659991c 100644 --- a/ctdb/tests/src/system_socket_test.c +++ b/ctdb/tests/src/system_socket_test.c @@ -97,8 +97,6 @@ static void test_arp(const char *addr_str, ctdb_sock_addr addr; struct sockaddr_storage hardware_addr = {}; struct sockaddr_ll *sall = (struct sockaddr_ll *)&hardware_addr; - /* Temporarily used for IPv6 - it still takes an ethernet address */ - struct ether_addr *hw = (struct ether_addr *)&sall->sll_addr[0]; uint8_t buf[512]; size_t buflen = sizeof(buf); size_t len; @@ -114,7 +112,7 @@ static void test_arp(const char *addr_str, ret = arp_build(buf, buflen, &addr.ip, sall, arpop, &len); break; case AF_INET6: - ret = ip6_na_build(buf, buflen, &addr.ip6, hw, &len); + ret = ip6_na_build(buf, buflen, &addr.ip6, sall, &len); break; default: abort();