]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-ipv6-proxy-ndp.c
network: drop detailed log messages
[thirdparty/systemd.git] / src / network / networkd-ipv6-proxy-ndp.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <netinet/in.h>
4 #include <linux/if.h>
5
6 #include "netlink-util.h"
7 #include "networkd-ipv6-proxy-ndp.h"
8 #include "networkd-link.h"
9 #include "networkd-manager.h"
10 #include "networkd-network.h"
11 #include "networkd-queue.h"
12 #include "socket-util.h"
13 #include "string-util.h"
14
15 void network_adjust_ipv6_proxy_ndp(Network *network) {
16 assert(network);
17
18 if (set_isempty(network->ipv6_proxy_ndp_addresses))
19 return;
20
21 if (!socket_ipv6_is_supported()) {
22 log_once(LOG_WARNING,
23 "%s: IPv6 proxy NDP addresses are set, but IPv6 is not supported by kernel, "
24 "Ignoring IPv6 proxy NDP addresses.", network->filename);
25 network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
26 }
27 }
28
29 static int ipv6_proxy_ndp_address_configure_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
30 int r;
31
32 assert(link);
33 assert(link->static_ipv6_proxy_ndp_messages > 0);
34
35 link->static_ipv6_proxy_ndp_messages--;
36
37 r = sd_netlink_message_get_errno(m);
38 if (r < 0)
39 log_link_message_warning_errno(link, m, r, "Could not add IPv6 proxy ndp address entry, ignoring");
40
41 if (link->static_ipv6_proxy_ndp_messages == 0) {
42 log_link_debug(link, "IPv6 proxy NDP addresses set.");
43 link->static_ipv6_proxy_ndp_configured = true;
44 link_check_ready(link);
45 }
46
47 return 1;
48 }
49
50 /* send a request to the kernel to add an IPv6 Proxy entry to the neighbour table */
51 static int ipv6_proxy_ndp_address_configure(
52 const struct in6_addr *address,
53 Link *link,
54 link_netlink_message_handler_t callback) {
55
56 _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
57 int r;
58
59 assert(address);
60 assert(link);
61 assert(link->manager);
62 assert(link->manager->rtnl);
63 assert(callback);
64
65 /* create new netlink message */
66 r = sd_rtnl_message_new_neigh(link->manager->rtnl, &m, RTM_NEWNEIGH, link->ifindex, AF_INET6);
67 if (r < 0)
68 return r;
69
70 r = sd_rtnl_message_neigh_set_flags(m, NTF_PROXY);
71 if (r < 0)
72 return r;
73
74 r = sd_netlink_message_append_in6_addr(m, NDA_DST, address);
75 if (r < 0)
76 return r;
77
78 r = netlink_call_async(link->manager->rtnl, NULL, m, callback,
79 link_netlink_destroy_callback, link);
80 if (r < 0)
81 return r;
82
83 link_ref(link);
84 return 0;
85 }
86
87 int link_request_static_ipv6_proxy_ndp_addresses(Link *link) {
88 struct in6_addr *address;
89 int r;
90
91 assert(link);
92 assert(link->network);
93
94 link->static_ipv6_proxy_ndp_configured = false;
95
96 SET_FOREACH(address, link->network->ipv6_proxy_ndp_addresses) {
97 r = link_queue_request(link, REQUEST_TYPE_IPV6_PROXY_NDP, address, false,
98 &link->static_ipv6_proxy_ndp_messages,
99 ipv6_proxy_ndp_address_configure_handler, NULL);
100 if (r < 0)
101 return log_link_warning_errno(link, r, "Failed to request IPv6 proxy NDP address: %m");
102 }
103
104 if (link->static_ipv6_proxy_ndp_messages == 0) {
105 link->static_ipv6_proxy_ndp_configured = true;
106 link_check_ready(link);
107 } else {
108 log_link_debug(link, "Setting IPv6 proxy NDP addresses.");
109 link_set_state(link, LINK_STATE_CONFIGURING);
110 }
111
112 return 0;
113 }
114
115 int request_process_ipv6_proxy_ndp_address(Request *req) {
116 Link *link;
117 int r;
118
119 assert(req);
120 assert(req->ipv6_proxy_ndp);
121 assert(req->type == REQUEST_TYPE_IPV6_PROXY_NDP);
122 assert_se(link = req->link);
123
124 if (!link_is_ready_to_configure(link, false))
125 return 0;
126
127 r = ipv6_proxy_ndp_address_configure(req->ipv6_proxy_ndp, link, req->netlink_handler);
128 if (r < 0)
129 return log_link_warning_errno(link, r, "Failed to configure IPv6 proxy NDP address: %m");
130
131 return 1;
132 }
133
134 int config_parse_ipv6_proxy_ndp_address(
135 const char *unit,
136 const char *filename,
137 unsigned line,
138 const char *section,
139 unsigned section_line,
140 const char *lvalue,
141 int ltype,
142 const char *rvalue,
143 void *data,
144 void *userdata) {
145
146 _cleanup_free_ struct in6_addr *address = NULL;
147 Network *network = userdata;
148 union in_addr_union buffer;
149 int r;
150
151 assert(filename);
152 assert(rvalue);
153 assert(network);
154
155 if (isempty(rvalue)) {
156 network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
157 return 0;
158 }
159
160 r = in_addr_from_string(AF_INET6, rvalue, &buffer);
161 if (r < 0) {
162 log_syntax(unit, LOG_WARNING, filename, line, r,
163 "Failed to parse IPv6 proxy NDP address, ignoring: %s", rvalue);
164 return 0;
165 }
166
167 if (in_addr_is_null(AF_INET6, &buffer)) {
168 log_syntax(unit, LOG_WARNING, filename, line, 0,
169 "IPv6 proxy NDP address cannot be the ANY address, ignoring: %s", rvalue);
170 return 0;
171 }
172
173 address = newdup(struct in6_addr, &buffer.in6, 1);
174 if (!address)
175 return log_oom();
176
177 r = set_ensure_put(&network->ipv6_proxy_ndp_addresses, &in6_addr_hash_ops, address);
178 if (r < 0)
179 return log_oom();
180 if (r > 0)
181 TAKE_PTR(address);
182
183 return 0;
184 }