]> git.proxmox.com Git - systemd.git/blame - src/network/networkd-netdev-tunnel.c
Merge tag 'upstream/229'
[systemd.git] / src / network / networkd-netdev-tunnel.c
CommitLineData
5eef597e
MP
1/***
2 This file is part of systemd.
3
e735f4d4 4 Copyright 2014 Susant Sahani
5eef597e
MP
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
5eef597e
MP
20#include <arpa/inet.h>
21#include <net/if.h>
22#include <linux/ip.h>
23#include <linux/if_tunnel.h>
e735f4d4 24#include <linux/ip6_tunnel.h>
5eef597e 25
86f210e9 26#include "sd-netlink.h"
db2df898
MP
27
28#include "conf-parser.h"
29#include "missing.h"
5eef597e 30#include "networkd-link.h"
db2df898
MP
31#include "networkd-netdev-tunnel.h"
32#include "parse-util.h"
33#include "string-table.h"
34#include "string-util.h"
5eef597e 35#include "util.h"
5eef597e 36
e735f4d4 37#define DEFAULT_TNL_HOP_LIMIT 64
7035cd9e 38#define IP6_FLOWINFO_FLOWLABEL htonl(0x000FFFFF)
e735f4d4
MP
39
40static 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
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
86f210e9 49static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
5eef597e
MP
50 Tunnel *t = IPIP(netdev);
51 int r;
52
53 assert(netdev);
54 assert(link);
55 assert(m);
56 assert(t);
4c89c718 57 assert(t->family == AF_INET || t->family != -1);
5eef597e 58
86f210e9 59 r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
e3bff60a
MP
60 if (r < 0)
61 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
5eef597e 62
86f210e9 63 r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
e3bff60a
MP
64 if (r < 0)
65 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
5eef597e 66
86f210e9 67 r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in);
e3bff60a
MP
68 if (r < 0)
69 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
5eef597e 70
86f210e9 71 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
e3bff60a
MP
72 if (r < 0)
73 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
5eef597e 74
86f210e9 75 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc);
e3bff60a
MP
76 if (r < 0)
77 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m");
f47781d8 78
5eef597e
MP
79 return r;
80}
81
86f210e9 82static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
5eef597e
MP
83 Tunnel *t = SIT(netdev);
84 int r;
85
86 assert(netdev);
87 assert(link);
88 assert(m);
89 assert(t);
4c89c718 90 assert(t->family == AF_INET || t->family != -1);
5eef597e 91
86f210e9 92 r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
e3bff60a
MP
93 if (r < 0)
94 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
5eef597e 95
86f210e9 96 r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
e3bff60a
MP
97 if (r < 0)
98 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
5eef597e 99
86f210e9 100 r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in);
e3bff60a
MP
101 if (r < 0)
102 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
5eef597e 103
86f210e9 104 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
e3bff60a
MP
105 if (r < 0)
106 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
5eef597e 107
86f210e9 108 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc);
e3bff60a
MP
109 if (r < 0)
110 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m");
f47781d8 111
5eef597e
MP
112 return r;
113}
114
86f210e9 115static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
e735f4d4 116 Tunnel *t;
5eef597e
MP
117 int r;
118
119 assert(netdev);
e735f4d4
MP
120
121 if (netdev->kind == NETDEV_KIND_GRE)
e3bff60a 122 t = GRE(netdev);
e735f4d4 123 else
e3bff60a 124 t = GRETAP(netdev);
e735f4d4 125
5eef597e 126 assert(t);
4c89c718 127 assert(t->family == AF_INET || t->family != -1);
e735f4d4
MP
128 assert(link);
129 assert(m);
5eef597e 130
86f210e9 131 r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
e3bff60a
MP
132 if (r < 0)
133 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
5eef597e 134
86f210e9 135 r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &t->local.in);
e3bff60a
MP
136 if (r < 0)
137 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
5eef597e 138
86f210e9 139 r = sd_netlink_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in);
e3bff60a
MP
140 if (r < 0)
141 log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m");
5eef597e 142
86f210e9 143 r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl);
e3bff60a
MP
144 if (r < 0)
145 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m");
5eef597e 146
86f210e9 147 r = sd_netlink_message_append_u8(m, IFLA_GRE_TOS, t->tos);
e3bff60a
MP
148 if (r < 0)
149 log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TOS attribute: %m");
5eef597e 150
86f210e9 151 r = sd_netlink_message_append_u8(m, IFLA_GRE_PMTUDISC, t->pmtudisc);
e3bff60a
MP
152 if (r < 0)
153 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_PMTUDISC attribute: %m");
f47781d8 154
5eef597e
MP
155 return r;
156}
157
86f210e9 158static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
e735f4d4
MP
159 Tunnel *t;
160 int r;
161
162 assert(netdev);
163
164 if (netdev->kind == NETDEV_KIND_IP6GRE)
e3bff60a 165 t = IP6GRE(netdev);
e735f4d4 166 else
e3bff60a 167 t = IP6GRETAP(netdev);
e735f4d4
MP
168
169 assert(t);
170 assert(t->family == AF_INET6);
171 assert(link);
172 assert(m);
173
86f210e9 174 r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link->ifindex);
e3bff60a
MP
175 if (r < 0)
176 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LINK attribute: %m");
e735f4d4 177
86f210e9 178 r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &t->local.in6);
e3bff60a
MP
179 if (r < 0)
180 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_LOCAL attribute: %m");
e735f4d4 181
86f210e9 182 r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_REMOTE, &t->remote.in6);
e3bff60a
MP
183 if (r < 0)
184 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_REMOTE attribute: %m");
e735f4d4 185
86f210e9 186 r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl);
e3bff60a
MP
187 if (r < 0)
188 return log_netdev_error_errno(netdev, r, "Could not append IFLA_GRE_TTL attribute: %m");
e735f4d4 189
7035cd9e
MP
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
e735f4d4
MP
200 return r;
201}
202
86f210e9 203static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
5eef597e
MP
204 Tunnel *t = VTI(netdev);
205 int r;
206
207 assert(netdev);
208 assert(link);
209 assert(m);
210 assert(t);
211 assert(t->family == AF_INET);
212
86f210e9 213 r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
e3bff60a
MP
214 if (r < 0)
215 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
5eef597e 216
86f210e9 217 r = sd_netlink_message_append_in_addr(m, IFLA_VTI_LOCAL, &t->local.in);
e3bff60a
MP
218 if (r < 0)
219 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
5eef597e 220
86f210e9 221 r = sd_netlink_message_append_in_addr(m, IFLA_VTI_REMOTE, &t->remote.in);
e3bff60a
MP
222 if (r < 0)
223 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
224
225 return r;
226}
227
86f210e9 228static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
e3bff60a
MP
229 Tunnel *t = VTI6(netdev);
230 int r;
231
232 assert(netdev);
233 assert(link);
234 assert(m);
235 assert(t);
236 assert(t->family == AF_INET6);
237
86f210e9 238 r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
e3bff60a
MP
239 if (r < 0)
240 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
241
86f210e9 242 r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_LOCAL, &t->local.in6);
e3bff60a
MP
243 if (r < 0)
244 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
245
86f210e9 246 r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_REMOTE, &t->remote.in6);
e3bff60a
MP
247 if (r < 0)
248 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
5eef597e
MP
249
250 return r;
251}
252
86f210e9 253static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
e735f4d4
MP
254 Tunnel *t = IP6TNL(netdev);
255 uint8_t proto;
256 int r;
257
258 assert(netdev);
259 assert(link);
260 assert(m);
261 assert(t);
262 assert(t->family == AF_INET6);
263
86f210e9 264 r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
e3bff60a
MP
265 if (r < 0)
266 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
e735f4d4 267
86f210e9 268 r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &t->local.in6);
e3bff60a
MP
269 if (r < 0)
270 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
e735f4d4 271
86f210e9 272 r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in6);
e3bff60a
MP
273 if (r < 0)
274 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
e735f4d4 275
86f210e9 276 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
e3bff60a
MP
277 if (r < 0)
278 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
e735f4d4 279
7035cd9e
MP
280 if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) {
281 r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLOWINFO, t->ipv6_flowlabel);
282 if (r < 0)
283 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLOWINFO attribute: %m");
284 }
285
286 if (t->copy_dscp)
287 t->flags |= IP6_TNL_F_RCV_DSCP_COPY;
288
d9dfd233
MP
289 if (t->encap_limit != IPV6_DEFAULT_TNL_ENCAP_LIMIT) {
290 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_ENCAP_LIMIT, t->encap_limit);
291 if (r < 0)
292 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_LIMIT attribute: %m");
293 }
294
7035cd9e
MP
295 r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLAGS, t->flags);
296 if (r < 0)
297 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m");
298
e735f4d4
MP
299 switch (t->ip6tnl_mode) {
300 case NETDEV_IP6_TNL_MODE_IP6IP6:
301 proto = IPPROTO_IPV6;
302 break;
303 case NETDEV_IP6_TNL_MODE_IPIP6:
304 proto = IPPROTO_IPIP;
305 break;
306 case NETDEV_IP6_TNL_MODE_ANYIP6:
307 default:
308 proto = 0;
309 break;
310 }
311
86f210e9 312 r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, proto);
e3bff60a
MP
313 if (r < 0)
314 return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_MODE attribute: %m");
e735f4d4
MP
315
316 return r;
317}
318
5eef597e
MP
319static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
320 Tunnel *t = NULL;
321
322 assert(netdev);
323 assert(filename);
324
325 switch (netdev->kind) {
326 case NETDEV_KIND_IPIP:
327 t = IPIP(netdev);
328 break;
329 case NETDEV_KIND_SIT:
330 t = SIT(netdev);
331 break;
332 case NETDEV_KIND_GRE:
333 t = GRE(netdev);
334 break;
e735f4d4
MP
335 case NETDEV_KIND_GRETAP:
336 t = GRETAP(netdev);
337 break;
338 case NETDEV_KIND_IP6GRE:
339 t = IP6GRE(netdev);
340 break;
341 case NETDEV_KIND_IP6GRETAP:
342 t = IP6GRETAP(netdev);
343 break;
5eef597e
MP
344 case NETDEV_KIND_VTI:
345 t = VTI(netdev);
346 break;
e3bff60a
MP
347 case NETDEV_KIND_VTI6:
348 t = VTI6(netdev);
349 break;
e735f4d4
MP
350 case NETDEV_KIND_IP6TNL:
351 t = IP6TNL(netdev);
352 break;
5eef597e
MP
353 default:
354 assert_not_reached("Invalid tunnel kind");
355 }
356
357 assert(t);
358
4c89c718 359 if (t->family != AF_INET && t->family != AF_INET6 && t->family != 0) {
e3bff60a
MP
360 log_warning("Tunnel with invalid address family configured in %s. Ignoring", filename);
361 return -EINVAL;
5eef597e
MP
362 }
363
e735f4d4
MP
364 if (netdev->kind == NETDEV_KIND_IP6TNL) {
365 if (t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID) {
366 log_warning("IP6 Tunnel without mode configured in %s. Ignoring", filename);
367 return -EINVAL;
368 }
369 }
370
5eef597e
MP
371 return 0;
372}
373
374int config_parse_tunnel_address(const char *unit,
375 const char *filename,
376 unsigned line,
377 const char *section,
378 unsigned section_line,
379 const char *lvalue,
380 int ltype,
381 const char *rvalue,
382 void *data,
383 void *userdata) {
384 Tunnel *t = userdata;
385 union in_addr_union *addr = data, buffer;
386 int r, f;
387
388 assert(filename);
389 assert(lvalue);
390 assert(rvalue);
391 assert(data);
392
4c89c718
MP
393 if (streq(rvalue, "any")) {
394 t->family = 0;
5eef597e 395 return 0;
4c89c718 396 } else {
5eef597e 397
4c89c718
MP
398 r = in_addr_from_string_auto(rvalue, &f, &buffer);
399 if (r < 0) {
400 log_syntax(unit, LOG_ERR, filename, line, r, "Tunnel address is invalid, ignoring assignment: %s", rvalue);
401 return 0;
402 }
403
404 if (t->family != AF_UNSPEC && t->family != f) {
405 log_syntax(unit, LOG_ERR, filename, line, 0, "Tunnel addresses incompatible, ignoring assignment: %s", rvalue);
406 return 0;
407 }
5eef597e
MP
408 }
409
410 t->family = f;
411 *addr = buffer;
412
413 return 0;
414}
415
7035cd9e
MP
416int 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;
7035cd9e
MP
428 int k = 0;
429 int r;
430
431 assert(filename);
432 assert(lvalue);
433 assert(rvalue);
434 assert(ipv6_flowlabel);
435
5fd56512 436 if (streq(rvalue, "inherit")) {
7035cd9e
MP
437 *ipv6_flowlabel = IP6_FLOWINFO_FLOWLABEL;
438 t->flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
439 } else {
5fd56512 440 r = config_parse_int(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &k, userdata);
6300502b
MP
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;
7035cd9e
MP
449 }
450 }
451
452 return 0;
453}
454
d9dfd233
MP
455int 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) {
6300502b 478 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse Tunnel Encapsulation Limit option, ignoring: %s", rvalue);
d9dfd233
MP
479 return 0;
480 }
481
482 if (k > 255 || k < 0)
6300502b 483 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid Tunnel Encapsulation value, ignoring: %d", k);
d9dfd233
MP
484 else {
485 t->encap_limit = k;
486 t->flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
487 }
488 }
489
490 return 0;
491}
492
5eef597e
MP
493static void ipip_init(NetDev *n) {
494 Tunnel *t = IPIP(n);
495
496 assert(n);
497 assert(t);
498
499 t->pmtudisc = true;
4c89c718 500 t->family = -1;
5eef597e
MP
501}
502
503static void sit_init(NetDev *n) {
504 Tunnel *t = SIT(n);
505
506 assert(n);
507 assert(t);
508
509 t->pmtudisc = true;
4c89c718 510 t->family = -1;
5eef597e
MP
511}
512
513static void vti_init(NetDev *n) {
e3bff60a 514 Tunnel *t;
5eef597e
MP
515
516 assert(n);
e3bff60a
MP
517
518 if (n->kind == NETDEV_KIND_VTI)
519 t = VTI(n);
520 else
521 t = VTI6(n);
522
5eef597e
MP
523 assert(t);
524
525 t->pmtudisc = true;
526}
527
528static void gre_init(NetDev *n) {
e735f4d4 529 Tunnel *t;
5eef597e
MP
530
531 assert(n);
e735f4d4
MP
532
533 if (n->kind == NETDEV_KIND_GRE)
534 t = GRE(n);
535 else
536 t = GRETAP(n);
537
5eef597e
MP
538 assert(t);
539
540 t->pmtudisc = true;
4c89c718 541 t->family = -1;
5eef597e
MP
542}
543
e735f4d4
MP
544static void ip6gre_init(NetDev *n) {
545 Tunnel *t;
546
547 assert(n);
548
549 if (n->kind == NETDEV_KIND_IP6GRE)
550 t = IP6GRE(n);
551 else
552 t = IP6GRETAP(n);
553
554 assert(t);
555
556 t->ttl = DEFAULT_TNL_HOP_LIMIT;
557}
558
559static void ip6tnl_init(NetDev *n) {
560 Tunnel *t = IP6TNL(n);
561
562 assert(n);
563 assert(t);
564
565 t->ttl = DEFAULT_TNL_HOP_LIMIT;
566 t->encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
567 t->ip6tnl_mode = _NETDEV_IP6_TNL_MODE_INVALID;
7035cd9e 568 t->ipv6_flowlabel = _NETDEV_IPV6_FLOWLABEL_INVALID;
e735f4d4
MP
569}
570
5eef597e
MP
571const NetDevVTable ipip_vtable = {
572 .object_size = sizeof(Tunnel),
573 .init = ipip_init,
574 .sections = "Match\0NetDev\0Tunnel\0",
575 .fill_message_create = netdev_ipip_fill_message_create,
576 .create_type = NETDEV_CREATE_STACKED,
577 .config_verify = netdev_tunnel_verify,
578};
579
580const NetDevVTable sit_vtable = {
581 .object_size = sizeof(Tunnel),
582 .init = sit_init,
583 .sections = "Match\0NetDev\0Tunnel\0",
584 .fill_message_create = netdev_sit_fill_message_create,
585 .create_type = NETDEV_CREATE_STACKED,
586 .config_verify = netdev_tunnel_verify,
587};
588
589const NetDevVTable vti_vtable = {
590 .object_size = sizeof(Tunnel),
591 .init = vti_init,
592 .sections = "Match\0NetDev\0Tunnel\0",
593 .fill_message_create = netdev_vti_fill_message_create,
594 .create_type = NETDEV_CREATE_STACKED,
595 .config_verify = netdev_tunnel_verify,
596};
597
e3bff60a
MP
598const NetDevVTable vti6_vtable = {
599 .object_size = sizeof(Tunnel),
600 .init = vti_init,
601 .sections = "Match\0NetDev\0Tunnel\0",
602 .fill_message_create = netdev_vti6_fill_message_create,
603 .create_type = NETDEV_CREATE_STACKED,
604 .config_verify = netdev_tunnel_verify,
605};
606
5eef597e
MP
607const NetDevVTable gre_vtable = {
608 .object_size = sizeof(Tunnel),
609 .init = gre_init,
610 .sections = "Match\0NetDev\0Tunnel\0",
611 .fill_message_create = netdev_gre_fill_message_create,
612 .create_type = NETDEV_CREATE_STACKED,
613 .config_verify = netdev_tunnel_verify,
614};
e735f4d4
MP
615
616const NetDevVTable gretap_vtable = {
617 .object_size = sizeof(Tunnel),
618 .init = gre_init,
619 .sections = "Match\0NetDev\0Tunnel\0",
620 .fill_message_create = netdev_gre_fill_message_create,
621 .create_type = NETDEV_CREATE_STACKED,
622 .config_verify = netdev_tunnel_verify,
623};
624
625const NetDevVTable ip6gre_vtable = {
626 .object_size = sizeof(Tunnel),
627 .init = ip6gre_init,
628 .sections = "Match\0NetDev\0Tunnel\0",
629 .fill_message_create = netdev_ip6gre_fill_message_create,
630 .create_type = NETDEV_CREATE_STACKED,
631 .config_verify = netdev_tunnel_verify,
632};
633
634const NetDevVTable ip6gretap_vtable = {
635 .object_size = sizeof(Tunnel),
636 .init = ip6gre_init,
637 .sections = "Match\0NetDev\0Tunnel\0",
638 .fill_message_create = netdev_ip6gre_fill_message_create,
639 .create_type = NETDEV_CREATE_STACKED,
640 .config_verify = netdev_tunnel_verify,
641};
642
643const NetDevVTable ip6tnl_vtable = {
644 .object_size = sizeof(Tunnel),
645 .init = ip6tnl_init,
646 .sections = "Match\0NetDev\0Tunnel\0",
647 .fill_message_create = netdev_ip6tnl_fill_message_create,
648 .create_type = NETDEV_CREATE_STACKED,
649 .config_verify = netdev_tunnel_verify,
650};