sd-ndisc: make ndisc_send() and icmp6_send() take struct in6_addr

No functional change, just refactoring.
This commit is contained in:
Yu Watanabe
2024-04-14 14:46:48 +09:00
parent 2c28eb0266
commit ac336e754e
8 changed files with 16 additions and 23 deletions

View 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);

View 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);
}

View 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;

View 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,

View 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);

View 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);

View 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) {

View 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) {