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