]>
Commit | Line | Data |
---|---|---|
7951dea2 SS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
855ee1a1 | 6 | Copyright 2014 Susant Sahani |
7951dea2 SS |
7 | |
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
7951dea2 SS |
22 | #include <arpa/inet.h> |
23 | #include <net/if.h> | |
24 | #include <linux/ip.h> | |
25 | #include <linux/if_tunnel.h> | |
855ee1a1 | 26 | #include <linux/ip6_tunnel.h> |
7951dea2 | 27 | |
1c4baffc | 28 | #include "sd-netlink.h" |
07630cea LP |
29 | |
30 | #include "conf-parser.h" | |
31 | #include "missing.h" | |
0b1831c2 | 32 | #include "networkd-link.h" |
6bedfcbb LP |
33 | #include "networkd-netdev-tunnel.h" |
34 | #include "parse-util.h" | |
07630cea | 35 | #include "string-util.h" |
7951dea2 SS |
36 | #include "util.h" |
37 | ||
855ee1a1 | 38 | #define DEFAULT_TNL_HOP_LIMIT 64 |
407af9dd | 39 | #define IP6_FLOWINFO_FLOWLABEL htonl(0x000FFFFF) |
855ee1a1 SS |
40 | |
41 | static const char* const ip6tnl_mode_table[_NETDEV_IP6_TNL_MODE_MAX] = { | |
42 | [NETDEV_IP6_TNL_MODE_IP6IP6] = "ip6ip6", | |
73b23bea | 43 | [NETDEV_IP6_TNL_MODE_IPIP6] = "ipip6", |
855ee1a1 SS |
44 | [NETDEV_IP6_TNL_MODE_ANYIP6] = "any", |
45 | }; | |
46 | ||
47 | DEFINE_STRING_TABLE_LOOKUP(ip6tnl_mode, Ip6TnlMode); | |
48 | DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode, "Failed to parse ip6 tunnel Mode"); | |
49 | ||
1c4baffc | 50 | static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 | 51 | Tunnel *t = IPIP(netdev); |
7951dea2 SS |
52 | int r; |
53 | ||
3be1d7e0 | 54 | assert(netdev); |
7951dea2 | 55 | assert(link); |
7951dea2 | 56 | assert(m); |
aa9f1140 TG |
57 | assert(t); |
58 | assert(t->family == AF_INET); | |
7951dea2 | 59 | |
1c4baffc | 60 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); |
5289f3ff SS |
61 | if (r < 0) |
62 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
7951dea2 | 63 | |
1c4baffc | 64 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); |
5289f3ff SS |
65 | if (r < 0) |
66 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
7951dea2 | 67 | |
1c4baffc | 68 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in); |
5289f3ff SS |
69 | if (r < 0) |
70 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
7951dea2 | 71 | |
1c4baffc | 72 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); |
5289f3ff SS |
73 | if (r < 0) |
74 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); | |
9ae70211 | 75 | |
1c4baffc | 76 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc); |
5289f3ff SS |
77 | if (r < 0) |
78 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m"); | |
9243e967 | 79 | |
7951dea2 SS |
80 | return r; |
81 | } | |
82 | ||
1c4baffc | 83 | static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 | 84 | Tunnel *t = SIT(netdev); |
abf446af SS |
85 | int r; |
86 | ||
3be1d7e0 | 87 | assert(netdev); |
abf446af | 88 | assert(link); |
abf446af | 89 | assert(m); |
aa9f1140 TG |
90 | assert(t); |
91 | assert(t->family == AF_INET); | |
abf446af | 92 | |
1c4baffc | 93 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); |
5289f3ff SS |
94 | if (r < 0) |
95 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
abf446af | 96 | |
1c4baffc | 97 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in); |
5289f3ff SS |
98 | if (r < 0) |
99 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
abf446af | 100 | |
1c4baffc | 101 | r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in); |
5289f3ff SS |
102 | if (r < 0) |
103 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
abf446af | 104 | |
1c4baffc | 105 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); |
5289f3ff SS |
106 | if (r < 0) |
107 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); | |
a9f434cf | 108 | |
1c4baffc | 109 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc); |
5289f3ff SS |
110 | if (r < 0) |
111 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m"); | |
436b910f | 112 | |
abf446af SS |
113 | return r; |
114 | } | |
115 | ||
1c4baffc | 116 | static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
1af2536a | 117 | Tunnel *t; |
8bb088c5 SS |
118 | int r; |
119 | ||
3be1d7e0 | 120 | assert(netdev); |
1af2536a SS |
121 | |
122 | if (netdev->kind == NETDEV_KIND_GRE) | |
5289f3ff | 123 | t = GRE(netdev); |
1af2536a | 124 | else |
5289f3ff | 125 | t = GRETAP(netdev); |
1af2536a | 126 | |
aa9f1140 TG |
127 | assert(t); |
128 | assert(t->family == AF_INET); | |
1af2536a SS |
129 | assert(link); |
130 | assert(m); | |
8bb088c5 | 131 | |
1c4baffc | 132 | r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); |
5289f3ff SS |
133 | if (r < 0) |
134 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); | |
8bb088c5 | 135 | |
1c4baffc | 136 | r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in); |
5289f3ff SS |
137 | if (r < 0) |
138 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m"); | |
8bb088c5 | 139 | |
1c4baffc | 140 | r = sd_netlink_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in); |
5289f3ff SS |
141 | if (r < 0) |
142 | log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m"); | |
8bb088c5 | 143 | |
1c4baffc | 144 | r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl); |
5289f3ff SS |
145 | if (r < 0) |
146 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m"); | |
8bb088c5 | 147 | |
1c4baffc | 148 | r = sd_netlink_message_append_u8(m, IFLA_GRE_TOS, t->tos); |
5289f3ff SS |
149 | if (r < 0) |
150 | log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TOS attribute: %m"); | |
8bb088c5 | 151 | |
1c4baffc | 152 | r = sd_netlink_message_append_u8(m, IFLA_GRE_PMTUDISC, t->pmtudisc); |
5289f3ff SS |
153 | if (r < 0) |
154 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_PMTUDISC attribute: %m"); | |
9243e967 | 155 | |
8bb088c5 SS |
156 | return r; |
157 | } | |
158 | ||
1c4baffc | 159 | static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
b16492f8 SS |
160 | Tunnel *t; |
161 | int r; | |
162 | ||
163 | assert(netdev); | |
164 | ||
165 | if (netdev->kind == NETDEV_KIND_IP6GRE) | |
5289f3ff | 166 | t = IP6GRE(netdev); |
b16492f8 | 167 | else |
5289f3ff | 168 | t = IP6GRETAP(netdev); |
b16492f8 SS |
169 | |
170 | assert(t); | |
171 | assert(t->family == AF_INET6); | |
172 | assert(link); | |
173 | assert(m); | |
174 | ||
1c4baffc | 175 | r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex); |
5289f3ff SS |
176 | if (r < 0) |
177 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m"); | |
b16492f8 | 178 | |
1c4baffc | 179 | r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6); |
5289f3ff SS |
180 | if (r < 0) |
181 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m"); | |
b16492f8 | 182 | |
1c4baffc | 183 | r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_REMOTE, &t->remote.in6); |
5289f3ff SS |
184 | if (r < 0) |
185 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m"); | |
b16492f8 | 186 | |
1c4baffc | 187 | r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl); |
5289f3ff SS |
188 | if (r < 0) |
189 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m"); | |
b16492f8 | 190 | |
54a9d20c SS |
191 | if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) { |
192 | r = sd_netlink_message_append_u32(m, IFLA_GRE_FLOWINFO, t->ipv6_flowlabel); | |
193 | if (r < 0) | |
194 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_FLOWINFO attribute: %m"); | |
195 | } | |
196 | ||
197 | r = sd_netlink_message_append_u32(m, IFLA_GRE_FLAGS, t->flags); | |
198 | if (r < 0) | |
199 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_FLAGS attribute: %m"); | |
200 | ||
b16492f8 SS |
201 | return r; |
202 | } | |
203 | ||
1c4baffc | 204 | static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
aa9f1140 | 205 | Tunnel *t = VTI(netdev); |
a613382b SS |
206 | int r; |
207 | ||
3be1d7e0 | 208 | assert(netdev); |
a613382b | 209 | assert(link); |
a613382b | 210 | assert(m); |
aa9f1140 TG |
211 | assert(t); |
212 | assert(t->family == AF_INET); | |
a613382b | 213 | |
1c4baffc | 214 | r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); |
5289f3ff SS |
215 | if (r < 0) |
216 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
a613382b | 217 | |
1c4baffc | 218 | r = sd_netlink_message_append_in_addr(m, IFLA_VTI_LOCAL, &t->local.in); |
5289f3ff SS |
219 | if (r < 0) |
220 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
a613382b | 221 | |
1c4baffc | 222 | r = sd_netlink_message_append_in_addr(m, IFLA_VTI_REMOTE, &t->remote.in); |
5289f3ff SS |
223 | if (r < 0) |
224 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
a613382b | 225 | |
a613382b SS |
226 | return r; |
227 | } | |
8bb088c5 | 228 | |
1c4baffc | 229 | static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
9011ce77 SS |
230 | Tunnel *t = VTI6(netdev); |
231 | int r; | |
232 | ||
233 | assert(netdev); | |
234 | assert(link); | |
235 | assert(m); | |
236 | assert(t); | |
237 | assert(t->family == AF_INET6); | |
238 | ||
1c4baffc | 239 | r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex); |
9011ce77 SS |
240 | if (r < 0) |
241 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
242 | ||
1c4baffc | 243 | r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_LOCAL, &t->local.in6); |
9011ce77 SS |
244 | if (r < 0) |
245 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
246 | ||
1c4baffc | 247 | r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_REMOTE, &t->remote.in6); |
9011ce77 SS |
248 | if (r < 0) |
249 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
250 | ||
251 | return r; | |
252 | } | |
253 | ||
1c4baffc | 254 | static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { |
855ee1a1 SS |
255 | Tunnel *t = IP6TNL(netdev); |
256 | uint8_t proto; | |
257 | int r; | |
258 | ||
259 | assert(netdev); | |
260 | assert(link); | |
261 | assert(m); | |
262 | assert(t); | |
263 | assert(t->family == AF_INET6); | |
264 | ||
1c4baffc | 265 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex); |
5289f3ff SS |
266 | if (r < 0) |
267 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m"); | |
855ee1a1 | 268 | |
1c4baffc | 269 | r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6); |
5289f3ff SS |
270 | if (r < 0) |
271 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m"); | |
855ee1a1 | 272 | |
1c4baffc | 273 | r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in6); |
5289f3ff SS |
274 | if (r < 0) |
275 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m"); | |
855ee1a1 | 276 | |
1c4baffc | 277 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl); |
5289f3ff SS |
278 | if (r < 0) |
279 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m"); | |
855ee1a1 | 280 | |
407af9dd SS |
281 | if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) { |
282 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLOWINFO, t->ipv6_flowlabel); | |
283 | if (r < 0) | |
284 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLOWINFO attribute: %m"); | |
285 | } | |
286 | ||
a9b70f9d | 287 | if (t->copy_dscp) |
ec2a3e3a SS |
288 | t->flags |= IP6_TNL_F_RCV_DSCP_COPY; |
289 | ||
b4828886 SS |
290 | if (t->encap_limit != IPV6_DEFAULT_TNL_ENCAP_LIMIT) { |
291 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_ENCAP_LIMIT, t->encap_limit); | |
292 | if (r < 0) | |
293 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_LIMIT attribute: %m"); | |
294 | } | |
295 | ||
407af9dd SS |
296 | r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLAGS, t->flags); |
297 | if (r < 0) | |
298 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m"); | |
299 | ||
855ee1a1 SS |
300 | switch (t->ip6tnl_mode) { |
301 | case NETDEV_IP6_TNL_MODE_IP6IP6: | |
302 | proto = IPPROTO_IPV6; | |
303 | break; | |
304 | case NETDEV_IP6_TNL_MODE_IPIP6: | |
305 | proto = IPPROTO_IPIP; | |
306 | break; | |
307 | case NETDEV_IP6_TNL_MODE_ANYIP6: | |
308 | default: | |
309 | proto = 0; | |
310 | break; | |
311 | } | |
312 | ||
1c4baffc | 313 | r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, proto); |
5289f3ff SS |
314 | if (r < 0) |
315 | return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_MODE attribute: %m"); | |
855ee1a1 SS |
316 | |
317 | return r; | |
318 | } | |
319 | ||
3be1d7e0 | 320 | static int netdev_tunnel_verify(NetDev *netdev, const char *filename) { |
aa9f1140 TG |
321 | Tunnel *t = NULL; |
322 | ||
7951dea2 | 323 | assert(netdev); |
3be1d7e0 | 324 | assert(filename); |
7951dea2 | 325 | |
aa9f1140 TG |
326 | switch (netdev->kind) { |
327 | case NETDEV_KIND_IPIP: | |
328 | t = IPIP(netdev); | |
329 | break; | |
330 | case NETDEV_KIND_SIT: | |
331 | t = SIT(netdev); | |
332 | break; | |
333 | case NETDEV_KIND_GRE: | |
334 | t = GRE(netdev); | |
335 | break; | |
1af2536a SS |
336 | case NETDEV_KIND_GRETAP: |
337 | t = GRETAP(netdev); | |
338 | break; | |
b16492f8 SS |
339 | case NETDEV_KIND_IP6GRE: |
340 | t = IP6GRE(netdev); | |
341 | break; | |
342 | case NETDEV_KIND_IP6GRETAP: | |
343 | t = IP6GRETAP(netdev); | |
344 | break; | |
aa9f1140 TG |
345 | case NETDEV_KIND_VTI: |
346 | t = VTI(netdev); | |
347 | break; | |
9011ce77 SS |
348 | case NETDEV_KIND_VTI6: |
349 | t = VTI6(netdev); | |
350 | break; | |
855ee1a1 SS |
351 | case NETDEV_KIND_IP6TNL: |
352 | t = IP6TNL(netdev); | |
353 | break; | |
aa9f1140 TG |
354 | default: |
355 | assert_not_reached("Invalid tunnel kind"); | |
356 | } | |
357 | ||
358 | assert(t); | |
359 | ||
aa9f1140 | 360 | if (t->remote.in.s_addr == INADDR_ANY) { |
5289f3ff SS |
361 | log_warning("Tunnel without remote address configured in %s. Ignoring", filename); |
362 | return -EINVAL; | |
7951dea2 SS |
363 | } |
364 | ||
855ee1a1 | 365 | if (t->family != AF_INET && t->family != AF_INET6) { |
5289f3ff SS |
366 | log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename); |
367 | return -EINVAL; | |
7951dea2 SS |
368 | } |
369 | ||
855ee1a1 SS |
370 | if (netdev->kind == NETDEV_KIND_IP6TNL) { |
371 | if (t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID) { | |
372 | log_warning("IP6 Tunnel without mode configured in %s. Ignoring", filename); | |
373 | return -EINVAL; | |
374 | } | |
375 | } | |
376 | ||
7951dea2 SS |
377 | return 0; |
378 | } | |
6ef892fc TG |
379 | |
380 | int config_parse_tunnel_address(const char *unit, | |
381 | const char *filename, | |
382 | unsigned line, | |
383 | const char *section, | |
384 | unsigned section_line, | |
385 | const char *lvalue, | |
386 | int ltype, | |
387 | const char *rvalue, | |
388 | void *data, | |
389 | void *userdata) { | |
aa9f1140 | 390 | Tunnel *t = userdata; |
44e7b949 LP |
391 | union in_addr_union *addr = data, buffer; |
392 | int r, f; | |
6ef892fc TG |
393 | |
394 | assert(filename); | |
395 | assert(lvalue); | |
396 | assert(rvalue); | |
397 | assert(data); | |
398 | ||
44e7b949 | 399 | r = in_addr_from_string_auto(rvalue, &f, &buffer); |
6ef892fc | 400 | if (r < 0) { |
12ca818f | 401 | log_syntax(unit, LOG_ERR, filename, line, r, "Tunnel address is invalid, ignoring assignment: %s", rvalue); |
6ef892fc TG |
402 | return 0; |
403 | } | |
404 | ||
44e7b949 | 405 | if (t->family != AF_UNSPEC && t->family != f) { |
12ca818f | 406 | log_syntax(unit, LOG_ERR, filename, line, 0, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue); |
44e7b949 LP |
407 | return 0; |
408 | } | |
409 | ||
410 | t->family = f; | |
411 | *addr = buffer; | |
412 | ||
6ef892fc TG |
413 | return 0; |
414 | } | |
3be1d7e0 | 415 | |
407af9dd SS |
416 | int config_parse_ipv6_flowlabel(const char* unit, |
417 | const char *filename, | |
418 | unsigned line, | |
419 | const char *section, | |
420 | unsigned section_line, | |
421 | const char *lvalue, | |
422 | int ltype, | |
423 | const char *rvalue, | |
424 | void *data, | |
425 | void *userdata) { | |
426 | IPv6FlowLabel *ipv6_flowlabel = data; | |
427 | Tunnel *t = userdata; | |
407af9dd SS |
428 | int k = 0; |
429 | int r; | |
430 | ||
431 | assert(filename); | |
432 | assert(lvalue); | |
433 | assert(rvalue); | |
434 | assert(ipv6_flowlabel); | |
435 | ||
6870b415 | 436 | if (streq(rvalue, "inherit")) { |
407af9dd SS |
437 | *ipv6_flowlabel = IP6_FLOWINFO_FLOWLABEL; |
438 | t->flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL; | |
439 | } else { | |
6870b415 | 440 | r = config_parse_int(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &k, userdata); |
12ca818f LP |
441 | if (r < 0) |
442 | return r; | |
443 | ||
444 | if (k > 0xFFFFF) | |
445 | log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse IPv6 flowlabel option, ignoring: %s", rvalue); | |
446 | else { | |
447 | *ipv6_flowlabel = htonl(k) & IP6_FLOWINFO_FLOWLABEL; | |
448 | t->flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL; | |
407af9dd SS |
449 | } |
450 | } | |
451 | ||
452 | return 0; | |
453 | } | |
454 | ||
b4828886 SS |
455 | int config_parse_encap_limit(const char* unit, |
456 | const char *filename, | |
457 | unsigned line, | |
458 | const char *section, | |
459 | unsigned section_line, | |
460 | const char *lvalue, | |
461 | int ltype, | |
462 | const char *rvalue, | |
463 | void *data, | |
464 | void *userdata) { | |
465 | Tunnel *t = userdata; | |
466 | int k = 0; | |
467 | int r; | |
468 | ||
469 | assert(filename); | |
470 | assert(lvalue); | |
471 | assert(rvalue); | |
472 | ||
473 | if (streq(rvalue, "none")) | |
474 | t->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT; | |
475 | else { | |
476 | r = safe_atoi(rvalue, &k); | |
477 | if (r < 0) { | |
12ca818f | 478 | log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse Tunnel Encapsulation Limit option, ignoring: %s", rvalue); |
b4828886 SS |
479 | return 0; |
480 | } | |
481 | ||
482 | if (k > 255 || k < 0) | |
12ca818f | 483 | log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid Tunnel Encapsulation value, ignoring: %d", k); |
b4828886 SS |
484 | else { |
485 | t->encap_limit = k; | |
486 | t->flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT; | |
487 | } | |
488 | } | |
489 | ||
490 | return 0; | |
491 | } | |
492 | ||
aa9f1140 TG |
493 | static void ipip_init(NetDev *n) { |
494 | Tunnel *t = IPIP(n); | |
495 | ||
496 | assert(n); | |
497 | assert(t); | |
498 | ||
499 | t->pmtudisc = true; | |
500 | } | |
501 | ||
502 | static void sit_init(NetDev *n) { | |
503 | Tunnel *t = SIT(n); | |
504 | ||
505 | assert(n); | |
506 | assert(t); | |
507 | ||
508 | t->pmtudisc = true; | |
509 | } | |
510 | ||
511 | static void vti_init(NetDev *n) { | |
7185d805 | 512 | Tunnel *t; |
aa9f1140 TG |
513 | |
514 | assert(n); | |
9011ce77 SS |
515 | |
516 | if (n->kind == NETDEV_KIND_VTI) | |
7185d805 | 517 | t = VTI(n); |
9011ce77 SS |
518 | else |
519 | t = VTI6(n); | |
520 | ||
aa9f1140 TG |
521 | assert(t); |
522 | ||
523 | t->pmtudisc = true; | |
524 | } | |
525 | ||
526 | static void gre_init(NetDev *n) { | |
1af2536a | 527 | Tunnel *t; |
aa9f1140 TG |
528 | |
529 | assert(n); | |
1af2536a SS |
530 | |
531 | if (n->kind == NETDEV_KIND_GRE) | |
532 | t = GRE(n); | |
533 | else | |
534 | t = GRETAP(n); | |
535 | ||
aa9f1140 TG |
536 | assert(t); |
537 | ||
538 | t->pmtudisc = true; | |
539 | } | |
540 | ||
b16492f8 SS |
541 | static void ip6gre_init(NetDev *n) { |
542 | Tunnel *t; | |
543 | ||
544 | assert(n); | |
545 | ||
546 | if (n->kind == NETDEV_KIND_IP6GRE) | |
547 | t = IP6GRE(n); | |
548 | else | |
549 | t = IP6GRETAP(n); | |
550 | ||
551 | assert(t); | |
552 | ||
553 | t->ttl = DEFAULT_TNL_HOP_LIMIT; | |
554 | } | |
555 | ||
855ee1a1 SS |
556 | static void ip6tnl_init(NetDev *n) { |
557 | Tunnel *t = IP6TNL(n); | |
558 | ||
559 | assert(n); | |
560 | assert(t); | |
561 | ||
562 | t->ttl = DEFAULT_TNL_HOP_LIMIT; | |
563 | t->encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT; | |
564 | t->ip6tnl_mode = _NETDEV_IP6_TNL_MODE_INVALID; | |
407af9dd | 565 | t->ipv6_flowlabel = _NETDEV_IPV6_FLOWLABEL_INVALID; |
855ee1a1 SS |
566 | } |
567 | ||
3be1d7e0 | 568 | const NetDevVTable ipip_vtable = { |
aa9f1140 TG |
569 | .object_size = sizeof(Tunnel), |
570 | .init = ipip_init, | |
571 | .sections = "Match\0NetDev\0Tunnel\0", | |
572 | .fill_message_create = netdev_ipip_fill_message_create, | |
573 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
574 | .config_verify = netdev_tunnel_verify, |
575 | }; | |
576 | ||
577 | const NetDevVTable sit_vtable = { | |
aa9f1140 TG |
578 | .object_size = sizeof(Tunnel), |
579 | .init = sit_init, | |
580 | .sections = "Match\0NetDev\0Tunnel\0", | |
581 | .fill_message_create = netdev_sit_fill_message_create, | |
582 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
583 | .config_verify = netdev_tunnel_verify, |
584 | }; | |
585 | ||
586 | const NetDevVTable vti_vtable = { | |
aa9f1140 TG |
587 | .object_size = sizeof(Tunnel), |
588 | .init = vti_init, | |
589 | .sections = "Match\0NetDev\0Tunnel\0", | |
590 | .fill_message_create = netdev_vti_fill_message_create, | |
591 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
592 | .config_verify = netdev_tunnel_verify, |
593 | }; | |
594 | ||
9011ce77 SS |
595 | const NetDevVTable vti6_vtable = { |
596 | .object_size = sizeof(Tunnel), | |
597 | .init = vti_init, | |
598 | .sections = "Match\0NetDev\0Tunnel\0", | |
599 | .fill_message_create = netdev_vti6_fill_message_create, | |
600 | .create_type = NETDEV_CREATE_STACKED, | |
601 | .config_verify = netdev_tunnel_verify, | |
602 | }; | |
603 | ||
3be1d7e0 | 604 | const NetDevVTable gre_vtable = { |
aa9f1140 TG |
605 | .object_size = sizeof(Tunnel), |
606 | .init = gre_init, | |
607 | .sections = "Match\0NetDev\0Tunnel\0", | |
608 | .fill_message_create = netdev_gre_fill_message_create, | |
609 | .create_type = NETDEV_CREATE_STACKED, | |
3be1d7e0 TG |
610 | .config_verify = netdev_tunnel_verify, |
611 | }; | |
1af2536a SS |
612 | |
613 | const NetDevVTable gretap_vtable = { | |
614 | .object_size = sizeof(Tunnel), | |
615 | .init = gre_init, | |
616 | .sections = "Match\0NetDev\0Tunnel\0", | |
617 | .fill_message_create = netdev_gre_fill_message_create, | |
618 | .create_type = NETDEV_CREATE_STACKED, | |
619 | .config_verify = netdev_tunnel_verify, | |
620 | }; | |
855ee1a1 | 621 | |
b16492f8 SS |
622 | const NetDevVTable ip6gre_vtable = { |
623 | .object_size = sizeof(Tunnel), | |
624 | .init = ip6gre_init, | |
625 | .sections = "Match\0NetDev\0Tunnel\0", | |
626 | .fill_message_create = netdev_ip6gre_fill_message_create, | |
627 | .create_type = NETDEV_CREATE_STACKED, | |
628 | .config_verify = netdev_tunnel_verify, | |
629 | }; | |
630 | ||
631 | const NetDevVTable ip6gretap_vtable = { | |
632 | .object_size = sizeof(Tunnel), | |
633 | .init = ip6gre_init, | |
634 | .sections = "Match\0NetDev\0Tunnel\0", | |
635 | .fill_message_create = netdev_ip6gre_fill_message_create, | |
636 | .create_type = NETDEV_CREATE_STACKED, | |
637 | .config_verify = netdev_tunnel_verify, | |
638 | }; | |
639 | ||
855ee1a1 SS |
640 | const NetDevVTable ip6tnl_vtable = { |
641 | .object_size = sizeof(Tunnel), | |
642 | .init = ip6tnl_init, | |
643 | .sections = "Match\0NetDev\0Tunnel\0", | |
644 | .fill_message_create = netdev_ip6tnl_fill_message_create, | |
645 | .create_type = NETDEV_CREATE_STACKED, | |
646 | .config_verify = netdev_tunnel_verify, | |
647 | }; |