1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-06 13:17:44 +03:00

icmp6-util: several cleanups for icmp6_receive()

- Rename the argument for storing the sender address,
- allow to call it with NULL for ret_xyz,
- reduce needless copy of timestamp when the message does not have
  timestamp.

(cherry picked from commit 5121163832)
(cherry picked from commit 811edcef2d)
This commit is contained in:
Yu Watanabe 2023-09-04 17:00:31 +09:00 committed by Luca Boccassi
parent 9f545c1aea
commit bd96e3ace7
5 changed files with 47 additions and 20 deletions

View File

@ -24,12 +24,17 @@ int icmp6_bind_router_advertisement(int index) {
return -ENOSYS;
}
int icmp6_receive(int fd, void *iov_base, size_t iov_len,
struct in6_addr *dst, triple_timestamp *timestamp) {
int icmp6_receive(
int fd,
void *iov_base,
size_t iov_len,
struct in6_addr *ret_sender,
triple_timestamp *ret_timestamp) {
assert_se(read(fd, iov_base, iov_len) == (ssize_t) iov_len);
if (timestamp)
triple_timestamp_get(timestamp);
if (ret_timestamp)
triple_timestamp_get(ret_timestamp);
return 0;
}

View File

@ -144,8 +144,12 @@ int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
return 0;
}
int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *ret_dst,
triple_timestamp *ret_timestamp) {
int icmp6_receive(
int fd,
void *buffer,
size_t size,
struct in6_addr *ret_sender,
triple_timestamp *ret_timestamp) {
/* This needs to be initialized with zero. See #20741. */
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(int)) + /* ttl */
@ -204,10 +208,14 @@ int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *ret_dst,
triple_timestamp_from_realtime(&t, timeval_load((struct timeval*) CMSG_DATA(cmsg)));
}
if (!triple_timestamp_is_set(&t))
triple_timestamp_get(&t);
if (ret_timestamp) {
if (triple_timestamp_is_set(&t))
*ret_timestamp = t;
else
triple_timestamp_get(ret_timestamp);
}
*ret_dst = addr;
*ret_timestamp = t;
if (ret_sender)
*ret_sender = addr;
return 0;
}

View File

@ -20,5 +20,9 @@
int icmp6_bind_router_solicitation(int ifindex);
int icmp6_bind_router_advertisement(int ifindex);
int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr);
int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *ret_dst,
triple_timestamp *ret_timestamp);
int icmp6_receive(
int fd,
void *buffer,
size_t size,
struct in6_addr *ret_sender,
triple_timestamp *ret_timestamp);

View File

@ -223,12 +223,17 @@ int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
return 0;
}
int icmp6_receive(int fd, void *iov_base, size_t iov_len,
struct in6_addr *dst, triple_timestamp *timestamp) {
int icmp6_receive(
int fd,
void *iov_base,
size_t iov_len,
struct in6_addr *ret_sender,
triple_timestamp *ret_timestamp) {
assert_se(read (fd, iov_base, iov_len) == (ssize_t)iov_len);
if (timestamp)
triple_timestamp_get(timestamp);
if (ret_timestamp)
triple_timestamp_get(ret_timestamp);
return 0;
}

View File

@ -176,12 +176,17 @@ int icmp6_bind_router_advertisement(int ifindex) {
return -ENOSYS;
}
int icmp6_receive(int fd, void *iov_base, size_t iov_len,
struct in6_addr *dst, triple_timestamp *timestamp) {
int icmp6_receive(
int fd,
void *iov_base,
size_t iov_len,
struct in6_addr *ret_sender,
triple_timestamp *ret_timestamp) {
assert_se(read (fd, iov_base, iov_len) == (ssize_t)iov_len);
if (timestamp)
triple_timestamp_get(timestamp);
if (ret_timestamp)
triple_timestamp_get(ret_timestamp);
return 0;
}