]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Don't build IPv6 NA link-level header
authorMartin Schwenke <mschwenke@ddn.com>
Thu, 18 Jun 2026 08:02:47 +0000 (18:02 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 27 Jul 2026 03:44:35 +0000 (03:44 +0000)
The link-level destination address is now setup outside
ip6_na_build(), since it is no longer used in that function.  Group
the parts of it together instead of leaving them scattered.

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
ctdb/tests/UNIT/cunit/system_socket_test_003.sh
ctdb/tests/src/system_socket_test.c

index 66e673fbfb2e797fa93785bdd28acc017f9918f0..94a09456c822e5e7214619b593c26b59ddd76913 100644 (file)
@@ -293,7 +293,7 @@ static inline socklen_t sall_len(struct sockaddr_ll *sll)
 #define ARP_STRUCT_SIZE \
                        sizeof(struct ether_arp)
 
-#define IP6_NA_STRUCT_SIZE sizeof(struct ether_header) + \
+#define IP6_NA_STRUCT_SIZE \
                           sizeof(struct ip6_hdr) + \
                           sizeof(struct nd_neighbor_advert) + \
                           sizeof(struct nd_opt_hdr) + \
@@ -377,11 +377,9 @@ static int ip6_na_build(uint8_t *buffer,
                        size_t buflen,
                        const struct sockaddr_in6 *addr,
                        const struct ether_addr *hwaddr,
-                       struct ether_addr **ether_dhost,
                        size_t *len)
 {
        size_t l = IP6_NA_BUFFER_SIZE;
-       struct ether_header *eh;
        struct ip6_hdr *ip6;
        /*
         * IPv6 all nodes link-level multicast address: (see RFC2373,
@@ -403,15 +401,7 @@ static int ip6_na_build(uint8_t *buffer,
 
        memset(buffer, 0 , l);
 
-       eh = (struct ether_header *)buffer;
-       ret = ip6_ll_multicast_build(eh->ether_dhost, ETH_ALEN);
-       if (ret != 0) {
-               return ret;
-       }
-       memcpy(eh->ether_shost, hwaddr, ETH_ALEN);
-       eh->ether_type = htons(ETHERTYPE_IP6);
-
-       ip6 = (struct ip6_hdr *)(buffer + sizeof(struct ether_header));
+       ip6 = (struct ip6_hdr *)buffer;
        ip6->ip6_vfc  = 6 << 4;
        ip6->ip6_plen = htons(sizeof(struct nd_neighbor_advert) +
                              sizeof(struct nd_opt_hdr) +
@@ -427,7 +417,6 @@ static int ip6_na_build(uint8_t *buffer,
        }
 
        nd_na = (struct nd_neighbor_advert *)(buffer +
-                                             sizeof(struct ether_header) +
                                              sizeof(struct ip6_hdr));
        nd_na->nd_na_type = ND_NEIGHBOR_ADVERT;
        nd_na->nd_na_code = 0;
@@ -436,14 +425,12 @@ static int ip6_na_build(uint8_t *buffer,
 
        /* Option: Target link-layer address */
        nd_oh = (struct nd_opt_hdr *)(buffer +
-                                     sizeof(struct ether_header) +
                                      sizeof(struct ip6_hdr) +
                                      sizeof(struct nd_neighbor_advert));
        nd_oh->nd_opt_type = ND_OPT_TARGET_LINKADDR;
        nd_oh->nd_opt_len = 1;  /* multiple of 8 octets */
 
        ea = (struct ether_addr *)(buffer +
-                                  sizeof(struct ether_header) +
                                   sizeof(struct ip6_hdr) +
                                   sizeof(struct nd_neighbor_advert) +
                                   sizeof(struct nd_opt_hdr));
@@ -453,7 +440,6 @@ static int ip6_na_build(uint8_t *buffer,
                                          ntohs(ip6->ip6_plen),
                                          ip6);
 
-       *ether_dhost = (struct ether_addr *)eh->ether_dhost;
        *len = l;
        return 0;
 }
@@ -475,7 +461,6 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
                },
        };
        struct ether_addr *hwaddr = NULL;
-       struct ether_addr *ether_dhost = NULL;
        size_t len = 0;
        int ret = 0;
 
@@ -593,23 +578,26 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
        case AF_INET6:
                /* Send IPv6 NA */
                sall.sll_protocol = htons(ETH_P_IPV6);
+               ret = ip6_ll_multicast_build(&sall.sll_addr[0], ETH_ALEN);
+               if (ret != 0) {
+                       DBG_ERR("Failed to build IPv6 link-level destination\n");
+                       goto done;
+               }
+
 
                ret = ip6_na_build(buffer,
                                   sizeof(buffer),
                                   &addr->ip6,
                                   hwaddr,
-                                  &ether_dhost,
                                   &len);
                if (ret != 0) {
                        DBG_ERR("Failed to build IPv6 neighbor advertisement\n");
                        goto done;
                }
 
-               memcpy(&sall.sll_addr[0], ether_dhost, sall.sll_halen);
-
                ret = sendto(s,
-                            buffer + sizeof(struct ether_header),
-                            len - sizeof(struct ether_header),
+                            buffer,
+                            len,
                             0,
                             (struct sockaddr *)&sall,
                             sizeof(sall));
index e04c08f4cab867bdbf1d9b7c9843cda5e9c99642..399d808b29dae5249c7255e0d51cd7b5fc696390 100755 (executable)
@@ -27,12 +27,11 @@ arp_test "192.168.1.25" "12:34:56:78:9a:bc" reply
 
 test_case "IPv6 neighbor advertisement"
 ok <<EOF
-000000 33 33 00 00 00 01 12 34 56 78 9a bc 86 dd 60 00
-000010 00 00 00 20 3a ff fe 80 00 00 00 00 00 00 6a f7
-000020 28 ff fe fa d1 36 ff 02 00 00 00 00 00 00 00 00
-000030 00 00 00 00 00 01 88 00 8d e4 20 00 00 00 fe 80
-000040 00 00 00 00 00 00 6a f7 28 ff fe fa d1 36 02 01
-000050 12 34 56 78 9a bc
-000056
+000000 60 00 00 00 00 20 3a ff fe 80 00 00 00 00 00 00
+000010 6a f7 28 ff fe fa d1 36 ff 02 00 00 00 00 00 00
+000020 00 00 00 00 00 00 00 01 88 00 8d e4 20 00 00 00
+000030 fe 80 00 00 00 00 00 00 6a f7 28 ff fe fa d1 36
+000040 02 01 12 34 56 78 9a bc
+000048
 EOF
 arp_test "fe80::6af7:28ff:fefa:d136" "12:34:56:78:9a:bc"
index 498d7d16021bf3610242d04b1e51dc5305cd400f..2dcb1aa651604e3e8e6c38ba8b100d42b4d574b5 100644 (file)
@@ -76,7 +76,7 @@ static void test_arp(const char *addr_str,
                     uint16_t arpop)
 {
        ctdb_sock_addr addr;
-       struct ether_addr *hw, *dhw;
+       struct ether_addr *hw = NULL;
        uint8_t buf[512];
        size_t buflen = sizeof(buf);
        size_t len;
@@ -93,7 +93,7 @@ static void test_arp(const char *addr_str,
                ret = arp_build(buf, buflen, &addr.ip, hw, arpop, &len);
                break;
        case AF_INET6:
-               ret = ip6_na_build(buf, buflen, &addr.ip6, hw, &dhw, &len);
+               ret = ip6_na_build(buf, buflen, &addr.ip6, hw, &len);
                break;
        default:
                abort();