]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/icmp6-util-unix.c
icmp6-util: merge icmp6_bind_router_{solicitation,advertisement}() into icmp6_bind()
[thirdparty/systemd.git] / src / libsystemd-network / icmp6-util-unix.c
CommitLineData
690afe79
YW
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
9send_ra_t send_ra_function = NULL;
71136404 10int test_fd[2] = EBADF_PAIR;
690afe79
YW
11
12static 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
37c011e7
YW
19int icmp6_bind(int ifindex, bool is_router) {
20 if (!is_router && socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
690afe79
YW
21 return -errno;
22
37c011e7 23 return test_fd[is_router];
690afe79
YW
24}
25
26int 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
33int 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)
fa5a0251 43 triple_timestamp_now(ret_timestamp);
690afe79
YW
44
45 if (ret_sender)
46 *ret_sender = dummy_link_local;
47
48 return 0;
49}