]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/icmp6-util-unix.c
logs-show: use journal_add_matchf() and journal_add_match_pair()
[thirdparty/systemd.git] / src / libsystemd-network / icmp6-util-unix.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <netinet/ip6.h>
4 #include <unistd.h>
5
6 #include "fd-util.h"
7 #include "icmp6-util-unix.h"
8
9 send_ra_t send_ra_function = NULL;
10 int test_fd[2] = EBADF_PAIR;
11
12 static struct in6_addr dummy_link_local = {
13 .s6_addr = {
14 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
15 0x12, 0x34, 0x56, 0xff, 0xfe, 0x78, 0x9a, 0xbc,
16 },
17 };
18
19 int icmp6_bind(int ifindex, bool is_router) {
20 if (!is_router && socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
21 return -errno;
22
23 return test_fd[is_router];
24 }
25
26 int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
27 if (!send_ra_function)
28 return 0;
29
30 return send_ra_function(0);
31 }
32
33 int icmp6_receive(
34 int fd,
35 void *iov_base,
36 size_t iov_len,
37 struct in6_addr *ret_sender,
38 triple_timestamp *ret_timestamp) {
39
40 assert_se(read (fd, iov_base, iov_len) == (ssize_t) iov_len);
41
42 if (ret_timestamp)
43 triple_timestamp_now(ret_timestamp);
44
45 if (ret_sender)
46 *ret_sender = dummy_link_local;
47
48 return 0;
49 }