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