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