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