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