/src/systemd/src/libsystemd-network/icmp6-test-util.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | |
3 | | #include <sys/uio.h> |
4 | | #include <unistd.h> |
5 | | |
6 | | #include "fd-util.h" |
7 | | #include "icmp6-test-util.h" |
8 | | #include "icmp6-util.h" |
9 | | #include "time-util.h" |
10 | | |
11 | | int test_fd[2] = EBADF_PAIR; |
12 | | |
13 | | static struct in6_addr dummy_link_local = { |
14 | | .s6_addr = { |
15 | | 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
16 | | 0x12, 0x34, 0x56, 0xff, 0xfe, 0x78, 0x9a, 0xbc, |
17 | | }, |
18 | | }; |
19 | | |
20 | 6.09k | int icmp6_bind(int ifindex, bool is_router) { |
21 | 6.09k | if (!is_router && socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0) |
22 | 0 | return -errno; |
23 | | |
24 | 6.09k | return test_fd[is_router]; |
25 | 6.09k | } |
26 | | |
27 | 7.92k | int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov) { |
28 | 7.92k | return writev(fd, iov, n_iov); |
29 | 7.92k | } |
30 | | |
31 | | int icmp6_receive( |
32 | | int fd, |
33 | | void *iov_base, |
34 | | size_t iov_len, |
35 | | struct in6_addr *ret_sender, |
36 | 11.8k | triple_timestamp *ret_timestamp) { |
37 | | |
38 | 11.8k | assert_se(read (fd, iov_base, iov_len) == (ssize_t) iov_len); |
39 | | |
40 | 11.8k | if (ret_timestamp) |
41 | 11.8k | triple_timestamp_now(ret_timestamp); |
42 | | |
43 | 11.8k | if (ret_sender) |
44 | 11.8k | *ret_sender = dummy_link_local; |
45 | | |
46 | 11.8k | return 0; |
47 | 11.8k | } |