]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-ndisc: make ndisc_send() and icmp6_send() take struct in6_addr 32266/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 14 Apr 2024 05:46:48 +0000 (14:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 14 Apr 2024 21:23:11 +0000 (06:23 +0900)
No functional change, just refactoring.

src/libsystemd-network/fuzz-ndisc-rs.c
src/libsystemd-network/icmp6-util-unix.c
src/libsystemd-network/icmp6-util.c
src/libsystemd-network/icmp6-util.h
src/libsystemd-network/ndisc-option.c
src/libsystemd-network/ndisc-option.h
src/libsystemd-network/sd-ndisc.c
src/libsystemd-network/test-ndisc-send.c

index ae780f4382f3d4e642fa792e81b494cf44eef0b1..54737e4a0608fec4417fce9848223c17ac6ad4ec 100644 (file)
@@ -35,11 +35,6 @@ static void test_with_sd_ndisc(const uint8_t *data, size_t size) {
 }
 
 static void test_with_icmp6_packet(const uint8_t *data, size_t size) {
-        static const struct sockaddr_in6 dst = {
-                .sin6_family = AF_INET6,
-                .sin6_addr = IN6_ADDR_ALL_ROUTERS_MULTICAST,
-        };
-
         _cleanup_close_pair_ int fd_pair[2] = EBADF_PAIR;
         _cleanup_(icmp6_packet_unrefp) ICMP6Packet *packet = NULL;
         _cleanup_set_free_ Set *options = NULL;
@@ -53,7 +48,8 @@ static void test_with_icmp6_packet(const uint8_t *data, size_t size) {
         if (ndisc_parse_options(packet, &options) < 0)
                 return;
 
-        if (ndisc_send(fd_pair[1], &dst, icmp6_packet_get_header(packet), options, /* timestamp = */ 0) < 0)
+        if (ndisc_send(fd_pair[1], &IN6_ADDR_ALL_ROUTERS_MULTICAST,
+                       icmp6_packet_get_header(packet), options, /* timestamp = */ 0) < 0)
                 return;
 
         packet = icmp6_packet_unref(packet);
index c400e4205ec24456b2a6fdfea09774f431f21cef..d6d505717d8ecb366b0b9e8466b4df46995c2e04 100644 (file)
@@ -23,7 +23,7 @@ int icmp6_bind(int ifindex, bool is_router) {
         return test_fd[is_router];
 }
 
-int icmp6_send(int fd, const struct sockaddr_in6 *dst, const struct iovec *iov, size_t n_iov) {
+int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov) {
         return writev(fd, iov, n_iov);
 }
 
index 804da7652e67e81f3a58826a1602efb19a666eae..a28f175b5e5afb5f1f477dbefe3a9310d630c54b 100644 (file)
@@ -91,14 +91,20 @@ int icmp6_bind(int ifindex, bool is_router) {
         return TAKE_FD(s);
 }
 
-int icmp6_send(int fd, const struct sockaddr_in6 *dst, const struct iovec *iov, size_t n_iov) {
+int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov) {
+        struct sockaddr_in6 sa = {
+                .sin6_family = AF_INET6,
+                .sin6_addr = *ASSERT_PTR(dst),
+        };
         struct msghdr msg = {
-                .msg_name = (struct sockaddr_in6*) dst,
+                .msg_name = &sa,
                 .msg_namelen = sizeof(struct sockaddr_in6),
                 .msg_iov = (struct iovec*) iov,
                 .msg_iovlen = n_iov,
         };
 
+        assert(fd >= 0);
+
         if (sendmsg(fd, &msg, 0) < 0)
                 return -errno;
 
index 74acd4124c01f44368b41787a74b9951b55a544a..9e5063f51ba4b7b4c1b17d43f9a6de666d9b67fb 100644 (file)
@@ -25,7 +25,7 @@
          } } } )
 
 int icmp6_bind(int ifindex, bool is_router);
-int icmp6_send(int fd, const struct sockaddr_in6 *dst, const struct iovec *iov, size_t n_iov);
+int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov);
 int icmp6_receive(
                 int fd,
                 void *buffer,
index 96c357ced4c14d908a096e27444af499642604cf..972047b0d18dffe6cb38c7b0b6972b9853064900 100644 (file)
@@ -1399,7 +1399,7 @@ int ndisc_option_get_mac(Set *options, uint8_t type, struct ether_addr *ret) {
         return 0;
 }
 
-int ndisc_send(int fd, const struct sockaddr_in6 *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp) {
+int ndisc_send(int fd, const struct in6_addr *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp) {
         int r;
 
         assert(fd >= 0);
index da52858caa0eb728165131552508e0591a1a4653..d7bd86147b27ae14a8e7055f64c4e034f517cfed 100644 (file)
@@ -327,4 +327,4 @@ static inline int ndisc_option_set_prefix64(
         return ndisc_option_add_prefix64_internal(options, 0, prefixlen, prefix, lifetime, valid_until);
 }
 
-int ndisc_send(int fd, const struct sockaddr_in6 *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp);
+int ndisc_send(int fd, const struct in6_addr *dst, const struct icmp6_hdr *hdr, Set *options, usec_t timestamp);
index faa0ea2701066334d2d726c987b3538158da65aa..b4136563e1f98da83c842b89527d2de361a04a38 100644 (file)
@@ -341,10 +341,6 @@ static int ndisc_recv(sd_event_source *s, int fd, uint32_t revents, void *userda
 }
 
 static int ndisc_send_router_solicitation(sd_ndisc *nd) {
-        static const struct sockaddr_in6 dst = {
-                .sin6_family = AF_INET6,
-                .sin6_addr = IN6_ADDR_ALL_ROUTERS_MULTICAST,
-        };
         static const struct nd_router_solicit header = {
                 .nd_rs_type = ND_ROUTER_SOLICIT,
         };
@@ -360,7 +356,7 @@ static int ndisc_send_router_solicitation(sd_ndisc *nd) {
                         return r;
         }
 
-        return ndisc_send(nd->fd, &dst, &header.nd_rs_hdr, options, USEC_INFINITY);
+        return ndisc_send(nd->fd, &IN6_ADDR_ALL_ROUTERS_MULTICAST, &header.nd_rs_hdr, options, USEC_INFINITY);
 }
 
 static usec_t ndisc_timeout_compute_random(usec_t val) {
index 7b9c0e5f17681912fe6cb8088d8f942d43d91035..1b1b27d63478acf2c132eac03ac1838ac62e1376 100644 (file)
@@ -348,12 +348,7 @@ static int send_icmp6(int fd, const struct icmp6_hdr *hdr) {
                         return r;
         }
 
-        struct sockaddr_in6 dst_sockaddr = {
-                .sin6_family = AF_INET6,
-                .sin6_addr = arg_dest.in6,
-        };
-
-        return ndisc_send(fd, &dst_sockaddr, hdr, options, now(CLOCK_BOOTTIME));
+        return ndisc_send(fd, &arg_dest.in6, hdr, options, now(CLOCK_BOOTTIME));
 }
 
 static int send_router_solicit(int fd) {