Debian Codegraph @

src/libsystemd-network/icmp6-test-util.c

raw
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 int test_ifindex = 42;
13
14 static struct in6_addr dummy_link_local = {
15 .s6_addr = {
16 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
17 0x12, 0x34, 0x56, 0xff, 0xfe, 0x78, 0x9a, 0xbc,
18 },
19 };
20
21 int icmp6_bind(int ifindex, bool is_router) {
22 test_ifindex = ifindex;
23
24 if (!is_router && socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
25 return -errno;
26
27 return test_fd[is_router];
28 }
29
30 int icmp6_send(int fd, const struct in6_addr *dst, const struct iovec *iov, size_t n_iov) {
31 return writev(fd, iov, n_iov);
32 }
33
34 int icmp6_receive(
35 int fd,
36 void *buffer,
37 size_t size,
38 struct in6_addr *ret_sender,
39 int *ret_ifindex,
40 triple_timestamp *ret_timestamp) {
41
42 assert_se(read(fd, buffer, size) == (ssize_t) size);
43
44 if (ret_timestamp)
45 triple_timestamp_now(ret_timestamp);
46
47 if (ret_sender)
48 *ret_sender = dummy_link_local;
49
50 if (ret_ifindex)
51 *ret_ifindex = test_ifindex;
52
53 return 0;
54 }