• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.63
/src/network/netdev/tunnel.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <linux/fou.h>
4
#include <linux/if_arp.h>
5
#include <linux/if_tunnel.h>
6
#include <linux/ip.h>
7
#include <linux/ip6_tunnel.h>
8
#include <netinet/in.h>
9

10
#include "af-list.h"
11
#include "alloc-util.h"
12
#include "conf-parser.h"
13
#include "hexdecoct.h"
14
#include "missing_network.h"
15
#include "netlink-util.h"
16
#include "networkd-manager.h"
17
#include "parse-util.h"
18
#include "siphash24.h"
19
#include "string-table.h"
20
#include "string-util.h"
21
#include "tunnel.h"
22

23
#define DEFAULT_IPV6_TTL   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);
62✔
34
DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode);
10✔
35

36
#define HASH_KEY SD_ID128_MAKE(74,c4,de,12,f3,d9,41,34,bb,3d,c1,a4,42,93,50,87)
37

38
static int dhcp4_pd_create_6rd_tunnel_name(Link *link) {
2✔
39
        _cleanup_free_ char *ifname_alloc = NULL;
4✔
40
        uint8_t ipv4masklen, sixrd_prefixlen, *buf, *p;
2✔
41
        struct in_addr ipv4address;
2✔
42
        struct in6_addr sixrd_prefix;
2✔
43
        char ifname[IFNAMSIZ];
2✔
44
        uint64_t result;
2✔
45
        size_t sz;
2✔
46
        int r;
2✔
47

48
        assert(link);
2✔
49
        assert(link->dhcp_lease);
2✔
50

51
        if (link->dhcp4_6rd_tunnel_name)
2✔
52
                return 0; /* Already set. Do not change even if the 6rd option is changed. */
53

54
        r = sd_dhcp_lease_get_address(link->dhcp_lease, &ipv4address);
1✔
55
        if (r < 0)
1✔
56
                return r;
57

58
        r = sd_dhcp_lease_get_6rd(link->dhcp_lease, &ipv4masklen, &sixrd_prefixlen, &sixrd_prefix, NULL, NULL);
1✔
59
        if (r < 0)
1✔
60
                return r;
61

62
        sz = sizeof(uint8_t) * 2 + sizeof(struct in6_addr) + sizeof(struct in_addr);
1✔
63
        buf = newa(uint8_t, sz);
1✔
64
        p = buf;
1✔
65
        p = mempcpy(p, &ipv4masklen, sizeof(uint8_t));
1✔
66
        p = mempcpy(p, &ipv4address, sizeof(struct in_addr));
1✔
67
        p = mempcpy(p, &sixrd_prefixlen, sizeof(uint8_t));
1✔
68
        p = mempcpy(p, &sixrd_prefix, sizeof(struct in6_addr));
1✔
69

70
        result = siphash24(buf, sz, HASH_KEY.bytes);
1✔
71
        memcpy(ifname, "6rd-", STRLEN("6rd-"));
1✔
72
        ifname[STRLEN("6rd-")    ] = urlsafe_base64char(result >> 54);
1✔
73
        ifname[STRLEN("6rd-") + 1] = urlsafe_base64char(result >> 48);
1✔
74
        ifname[STRLEN("6rd-") + 2] = urlsafe_base64char(result >> 42);
1✔
75
        ifname[STRLEN("6rd-") + 3] = urlsafe_base64char(result >> 36);
1✔
76
        ifname[STRLEN("6rd-") + 4] = urlsafe_base64char(result >> 30);
1✔
77
        ifname[STRLEN("6rd-") + 5] = urlsafe_base64char(result >> 24);
1✔
78
        ifname[STRLEN("6rd-") + 6] = urlsafe_base64char(result >> 18);
1✔
79
        ifname[STRLEN("6rd-") + 7] = urlsafe_base64char(result >> 12);
1✔
80
        ifname[STRLEN("6rd-") + 8] = urlsafe_base64char(result >> 6);
1✔
81
        ifname[STRLEN("6rd-") + 9] = urlsafe_base64char(result);
1✔
82
        ifname[STRLEN("6rd-") + 10] = '\0';
1✔
83
        assert_cc(STRLEN("6rd-") + 10 <= IFNAMSIZ);
1✔
84

85
        ifname_alloc = strdup(ifname);
1✔
86
        if (!ifname_alloc)
1✔
87
                return -ENOMEM;
88

89
        link->dhcp4_6rd_tunnel_name = TAKE_PTR(ifname_alloc);
1✔
90
        return 0;
1✔
91
}
92

93
int dhcp4_pd_create_6rd_tunnel(Link *link, link_netlink_message_handler_t callback) {
2✔
94
        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
2✔
95
        uint8_t ipv4masklen, sixrd_prefixlen;
2✔
96
        struct in_addr ipv4address;
2✔
97
        struct in6_addr sixrd_prefix;
2✔
98
        Link *sit = NULL;
2✔
99
        int r;
2✔
100

101
        assert(link);
2✔
102
        assert(link->manager);
2✔
103
        assert(link->manager->rtnl);
2✔
104
        assert(link->dhcp_lease);
2✔
105
        assert(callback);
2✔
106

107
        r = sd_dhcp_lease_get_address(link->dhcp_lease, &ipv4address);
2✔
108
        if (r < 0)
2✔
109
                return r;
110

111
        r = sd_dhcp_lease_get_6rd(link->dhcp_lease, &ipv4masklen, &sixrd_prefixlen, &sixrd_prefix, NULL, NULL);
2✔
112
        if (r < 0)
2✔
113
                return r;
114

115
        r = dhcp4_pd_create_6rd_tunnel_name(link);
2✔
116
        if (r < 0)
2✔
117
                return r;
118

119
        (void) link_get_by_name(link->manager, link->dhcp4_6rd_tunnel_name, &sit);
2✔
120

121
        r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_NEWLINK, sit ? sit->ifindex : 0);
2✔
122
        if (r < 0)
2✔
123
                return r;
124

125
        r = sd_netlink_message_append_string(m, IFLA_IFNAME, link->dhcp4_6rd_tunnel_name);
2✔
126
        if (r < 0)
2✔
127
                return r;
128

129
        r = sd_netlink_message_open_container(m, IFLA_LINKINFO);
2✔
130
        if (r < 0)
2✔
131
                return r;
132

133
        r = sd_netlink_message_open_container_union(m, IFLA_INFO_DATA, "sit");
2✔
134
        if (r < 0)
2✔
135
                return r;
136

137
        r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &ipv4address);
2✔
138
        if (r < 0)
2✔
139
                return r;
140

141
        r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, 64);
2✔
142
        if (r < 0)
2✔
143
                return r;
144

145
        r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, &sixrd_prefix);
2✔
146
        if (r < 0)
2✔
147
                return r;
148

149
        r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, sixrd_prefixlen);
2✔
150
        if (r < 0)
2✔
151
                return r;
152

153
        struct in_addr relay_prefix = ipv4address;
2✔
154
        (void) in4_addr_mask(&relay_prefix, ipv4masklen);
2✔
155
        r = sd_netlink_message_append_u32(m, IFLA_IPTUN_6RD_RELAY_PREFIX, relay_prefix.s_addr);
2✔
156
        if (r < 0)
2✔
157
                return r;
158

159
        r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, ipv4masklen);
2✔
160
        if (r < 0)
2✔
161
                return r;
162

163
        r = sd_netlink_message_close_container(m);
2✔
164
        if (r < 0)
2✔
165
                return r;
166

167
        r = sd_netlink_message_close_container(m);
2✔
168
        if (r < 0)
2✔
169
                return r;
170

171
        r = netlink_call_async(link->manager->rtnl, NULL, m, callback,
2✔
172
                               link_netlink_destroy_callback, link);
173
        if (r < 0)
2✔
174
                return r;
175

176
        link_ref(link);
2✔
177
        return 0;
178
}
179

180
static int tunnel_get_local_address(Tunnel *t, Link *link, union in_addr_union *ret) {
340✔
181
        assert(t);
340✔
182

183
        if (t->local_type < 0) {
340✔
184
                if (ret)
174✔
185
                        *ret = t->local;
92✔
186
                return 0;
174✔
187
        }
188

189
        return link_get_local_address(link, t->local_type, t->family, NULL, ret);
166✔
190
}
191

192
static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
29✔
193
        assert(m);
29✔
194

195
        union in_addr_union local;
29✔
196
        Tunnel *t = ASSERT_PTR(netdev)->kind == NETDEV_KIND_IPIP ? IPIP(netdev) : SIT(netdev);
29✔
197
        int r;
29✔
198

199
        if (t->external) {
29✔
200
                r = sd_netlink_message_append_flag(m, IFLA_IPTUN_COLLECT_METADATA);
×
UNCOV
201
                if (r < 0)
×
202
                        return r;
29✔
203

204
                /* If external mode is enabled, then the following settings should not be appended. */
UNCOV
205
                return 0;
×
206
        }
207

208
        if (link || t->assign_to_loopback) {
29✔
209
                r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
24✔
210
                if (r < 0)
24✔
211
                        return r;
212
        }
213

214
        r = tunnel_get_local_address(t, link, &local);
29✔
215
        if (r < 0)
29✔
UNCOV
216
                return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
×
217

218
        r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &local.in);
29✔
219
        if (r < 0)
29✔
220
                return r;
221

222
        r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in);
29✔
223
        if (r < 0)
29✔
224
                return r;
225

226
        r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
29✔
227
        if (r < 0)
29✔
228
                return r;
229

230
        r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc);
29✔
231
        if (r < 0)
29✔
232
                return r;
233

234
        if (t->fou_tunnel) {
29✔
235
                r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_TYPE, t->fou_encap_type);
4✔
236
                if (r < 0)
4✔
237
                        return r;
238

239
                r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_SPORT, htobe16(t->encap_src_port));
4✔
240
                if (r < 0)
4✔
241
                        return r;
242

243
                r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_DPORT, htobe16(t->fou_destination_port));
4✔
244
                if (r < 0)
4✔
245
                        return r;
246
        }
247

248
        if (netdev->kind == NETDEV_KIND_SIT) {
29✔
249
                if (t->sixrd_prefixlen > 0) {
17✔
250
                        r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, &t->sixrd_prefix);
2✔
251
                        if (r < 0)
2✔
252
                                return r;
253

254
                        /* u16 is deliberate here, even though we're passing a netmask that can never be
255
                         * >128. The kernel is expecting to receive the prefixlen as a u16.
256
                         */
257
                        r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, t->sixrd_prefixlen);
2✔
258
                        if (r < 0)
2✔
259
                                return r;
260
                }
261

262
                if (t->isatap >= 0) {
17✔
263
                        uint16_t flags = 0;
2✔
264

265
                        SET_FLAG(flags, SIT_ISATAP, t->isatap);
2✔
266

267
                        r = sd_netlink_message_append_u16(m, IFLA_IPTUN_FLAGS, flags);
2✔
268
                        if (r < 0)
2✔
UNCOV
269
                                return r;
×
270
                }
271
        }
272

273
        return 0;
274
}
275

276
static int netdev_gre_erspan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
31✔
277
        union in_addr_union local;
31✔
278
        uint32_t ikey = 0;
31✔
279
        uint32_t okey = 0;
31✔
280
        uint16_t iflags = 0;
31✔
281
        uint16_t oflags = 0;
31✔
282
        Tunnel *t;
31✔
283
        int r;
31✔
284

285
        assert(netdev);
31✔
286
        assert(m);
31✔
287

288
        switch (netdev->kind) {
31✔
289
        case NETDEV_KIND_GRE:
13✔
290
                t = GRE(netdev);
13✔
291
                break;
292
        case NETDEV_KIND_ERSPAN:
12✔
293
                t = ERSPAN(netdev);
12✔
294
                break;
295
        case NETDEV_KIND_GRETAP:
6✔
296
                t = GRETAP(netdev);
6✔
297
                break;
298
        default:
×
UNCOV
299
                assert_not_reached();
×
300
        }
301

302
        if (t->external) {
31✔
303
                r = sd_netlink_message_append_flag(m, IFLA_GRE_COLLECT_METADATA);
×
UNCOV
304
                if (r < 0)
×
305
                        return r;
31✔
306

307
                /* If external mode is enabled, then the following settings should not be appended. */
UNCOV
308
                return 0;
×
309
        }
310

311
        if (link || t->assign_to_loopback) {
31✔
312
                r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
27✔
313
                if (r < 0)
27✔
314
                        return r;
315
        }
316

317
        if (netdev->kind == NETDEV_KIND_ERSPAN) {
31✔
318
                r = sd_netlink_message_append_u8(m, IFLA_GRE_ERSPAN_VER, t->erspan_version);
12✔
319
                if (r < 0)
12✔
320
                        return r;
321

322
                if (t->erspan_version == 1) {
12✔
323
                        r = sd_netlink_message_append_u32(m, IFLA_GRE_ERSPAN_INDEX, t->erspan_index);
4✔
324
                        if (r < 0)
4✔
325
                                return r;
326

327
                } else if (t->erspan_version == 2) {
8✔
328
                        r = sd_netlink_message_append_u8(m, IFLA_GRE_ERSPAN_DIR, t->erspan_direction);
4✔
329
                        if (r < 0)
4✔
330
                                return r;
331

332
                        r = sd_netlink_message_append_u16(m, IFLA_GRE_ERSPAN_HWID, t->erspan_hwid);
4✔
333
                        if (r < 0)
4✔
334
                                return r;
335
                }
336
        }
337

338
        r = tunnel_get_local_address(t, link, &local);
31✔
339
        if (r < 0)
31✔
UNCOV
340
                return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
×
341

342
        r = sd_netlink_message_append_in_addr(m, IFLA_GRE_LOCAL, &local.in);
31✔
343
        if (r < 0)
31✔
344
                return r;
345

346
        r = sd_netlink_message_append_in_addr(m, IFLA_GRE_REMOTE, &t->remote.in);
31✔
347
        if (r < 0)
31✔
348
                return r;
349

350
        r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl);
31✔
351
        if (r < 0)
31✔
352
                return r;
353

354
        r = sd_netlink_message_append_u8(m, IFLA_GRE_TOS, t->tos);
31✔
355
        if (r < 0)
31✔
356
                return r;
357

358
        r = sd_netlink_message_append_u8(m, IFLA_GRE_PMTUDISC, t->pmtudisc);
31✔
359
        if (r < 0)
31✔
360
                return r;
361

362
        r = sd_netlink_message_append_u8(m, IFLA_GRE_IGNORE_DF, t->ignore_df);
31✔
363
        if (r < 0)
31✔
364
                return r;
365

366
        if (t->key != 0) {
31✔
367
                ikey = okey = htobe32(t->key);
29✔
368
                iflags |= GRE_KEY;
29✔
369
                oflags |= GRE_KEY;
29✔
370
        }
371

372
        if (t->ikey != 0) {
31✔
373
                ikey = htobe32(t->ikey);
2✔
374
                iflags |= GRE_KEY;
2✔
375
        }
376

377
        if (t->okey != 0) {
31✔
378
                okey = htobe32(t->okey);
2✔
379
                oflags |= GRE_KEY;
2✔
380
        }
381

382
        if (t->gre_erspan_sequence > 0) {
31✔
383
                iflags |= GRE_SEQ;
22✔
384
                oflags |= GRE_SEQ;
22✔
385
        } else if (t->gre_erspan_sequence == 0) {
9✔
386
                iflags &= ~GRE_SEQ;
9✔
387
                oflags &= ~GRE_SEQ;
9✔
388
        }
389

390
        r = sd_netlink_message_append_u32(m, IFLA_GRE_IKEY, ikey);
31✔
391
        if (r < 0)
31✔
392
                return r;
393

394
        r = sd_netlink_message_append_u32(m, IFLA_GRE_OKEY, okey);
31✔
395
        if (r < 0)
31✔
396
                return r;
397

398
        r = sd_netlink_message_append_u16(m, IFLA_GRE_IFLAGS, iflags);
31✔
399
        if (r < 0)
31✔
400
                return r;
401

402
        r = sd_netlink_message_append_u16(m, IFLA_GRE_OFLAGS, oflags);
31✔
403
        if (r < 0)
31✔
404
                return r;
405

406
        if (t->fou_tunnel) {
31✔
407
                r = sd_netlink_message_append_u16(m, IFLA_GRE_ENCAP_TYPE, t->fou_encap_type);
4✔
408
                if (r < 0)
4✔
409
                        return r;
410

411
                r = sd_netlink_message_append_u16(m, IFLA_GRE_ENCAP_SPORT, htobe16(t->encap_src_port));
4✔
412
                if (r < 0)
4✔
413
                        return r;
414

415
                r = sd_netlink_message_append_u16(m, IFLA_GRE_ENCAP_DPORT, htobe16(t->fou_destination_port));
4✔
416
                if (r < 0)
4✔
UNCOV
417
                        return r;
×
418
        }
419

420
        return 0;
421
}
422

423
static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
15✔
424
        union in_addr_union local;
15✔
425
        uint32_t ikey = 0, okey = 0;
15✔
426
        uint16_t iflags = 0, oflags = 0;
15✔
427
        Tunnel *t;
15✔
428
        int r;
15✔
429

430
        assert(netdev);
15✔
431
        assert(m);
15✔
432

433
        if (netdev->kind == NETDEV_KIND_IP6GRE)
15✔
434
                t = IP6GRE(netdev);
11✔
435
        else
436
                t = IP6GRETAP(netdev);
4✔
437

438
        if (t->external) {
15✔
439
                r = sd_netlink_message_append_flag(m, IFLA_GRE_COLLECT_METADATA);
×
UNCOV
440
                if (r < 0)
×
441
                        return r;
15✔
442

443
                /* If external mode is enabled, then the following settings should not be appended. */
UNCOV
444
                return 0;
×
445
        }
446

447
        if (link || t->assign_to_loopback) {
15✔
448
                r = sd_netlink_message_append_u32(m, IFLA_GRE_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
15✔
449
                if (r < 0)
15✔
450
                        return r;
451
        }
452

453
        r = tunnel_get_local_address(t, link, &local);
15✔
454
        if (r < 0)
15✔
UNCOV
455
                return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
×
456

457
        r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_LOCAL, &local.in6);
15✔
458
        if (r < 0)
15✔
459
                return r;
460

461
        r = sd_netlink_message_append_in6_addr(m, IFLA_GRE_REMOTE, &t->remote.in6);
15✔
462
        if (r < 0)
15✔
463
                return r;
464

465
        r = sd_netlink_message_append_u8(m, IFLA_GRE_TTL, t->ttl);
15✔
466
        if (r < 0)
15✔
467
                return r;
468

469
        if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) {
15✔
470
                r = sd_netlink_message_append_u32(m, IFLA_GRE_FLOWINFO, t->ipv6_flowlabel);
×
UNCOV
471
                if (r < 0)
×
472
                        return r;
473
        }
474

475
        r = sd_netlink_message_append_u32(m, IFLA_GRE_FLAGS, t->flags);
15✔
476
        if (r < 0)
15✔
477
                return r;
478

479
        if (t->key != 0) {
15✔
480
                ikey = okey = htobe32(t->key);
×
481
                iflags |= GRE_KEY;
×
UNCOV
482
                oflags |= GRE_KEY;
×
483
        }
484

485
        if (t->ikey != 0) {
15✔
486
                ikey = htobe32(t->ikey);
×
UNCOV
487
                iflags |= GRE_KEY;
×
488
        }
489

490
        if (t->okey != 0) {
15✔
491
                okey = htobe32(t->okey);
×
UNCOV
492
                oflags |= GRE_KEY;
×
493
        }
494

495
        r = sd_netlink_message_append_u32(m, IFLA_GRE_IKEY, ikey);
15✔
496
        if (r < 0)
15✔
497
                return r;
498

499
        r = sd_netlink_message_append_u32(m, IFLA_GRE_OKEY, okey);
15✔
500
        if (r < 0)
15✔
501
                return r;
502

503
        r = sd_netlink_message_append_u16(m, IFLA_GRE_IFLAGS, iflags);
15✔
504
        if (r < 0)
15✔
505
                return r;
506

507
        r = sd_netlink_message_append_u16(m, IFLA_GRE_OFLAGS, oflags);
15✔
508
        if (r < 0)
15✔
UNCOV
509
                return r;
×
510

511
        return 0;
512
}
513

514
static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
14✔
515
        assert(netdev);
14✔
516
        assert(m);
14✔
517

518
        union in_addr_union local;
14✔
519
        uint32_t ikey, okey;
14✔
520
        Tunnel *t = netdev->kind == NETDEV_KIND_VTI ? VTI(netdev) : VTI6(netdev);
14✔
521
        int r;
14✔
522

523
        if (link || t->assign_to_loopback) {
14✔
524
                r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
14✔
525
                if (r < 0)
14✔
526
                        return r;
14✔
527
        }
528

529
        if (t->key != 0)
14✔
UNCOV
530
                ikey = okey = htobe32(t->key);
×
531
        else {
532
                ikey = htobe32(t->ikey);
14✔
533
                okey = htobe32(t->okey);
14✔
534
        }
535

536
        r = sd_netlink_message_append_u32(m, IFLA_VTI_IKEY, ikey);
14✔
537
        if (r < 0)
14✔
538
                return r;
539

540
        r = sd_netlink_message_append_u32(m, IFLA_VTI_OKEY, okey);
14✔
541
        if (r < 0)
14✔
542
                return r;
543

544
        r = tunnel_get_local_address(t, link, &local);
14✔
545
        if (r < 0)
14✔
UNCOV
546
                return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
×
547

548
        r = netlink_message_append_in_addr_union(m, IFLA_VTI_LOCAL, t->family, &local);
14✔
549
        if (r < 0)
14✔
550
                return r;
551

552
        r = netlink_message_append_in_addr_union(m, IFLA_VTI_REMOTE, t->family, &t->remote);
14✔
553
        if (r < 0)
14✔
UNCOV
554
                return r;
×
555

556
        return 0;
557
}
558

559
static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
11✔
560
        assert(netdev);
11✔
561
        assert(m);
11✔
562

563
        union in_addr_union local;
11✔
564
        uint8_t proto;
11✔
565
        Tunnel *t = IP6TNL(netdev);
11✔
566
        int r;
11✔
567

568
        switch (t->ip6tnl_mode) {
11✔
569
        case NETDEV_IP6_TNL_MODE_IP6IP6:
570
                proto = IPPROTO_IPV6;
571
                break;
572
        case NETDEV_IP6_TNL_MODE_IPIP6:
×
573
                proto = IPPROTO_IPIP;
×
574
                break;
×
UNCOV
575
        case NETDEV_IP6_TNL_MODE_ANYIP6:
×
576
        default:
UNCOV
577
                proto = 0;
×
578
        }
579

580
        r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, proto);
11✔
581
        if (r < 0)
11✔
582
                return r;
11✔
583

584
        if (t->external) {
11✔
585
                r = sd_netlink_message_append_flag(m, IFLA_IPTUN_COLLECT_METADATA);
2✔
586
                if (r < 0)
2✔
587
                        return r;
588

589
                /* If external mode is enabled, then the following settings should not be appended. */
590
                return 0;
2✔
591
        }
592

593
        if (link || t->assign_to_loopback) {
9✔
594
                r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
9✔
595
                if (r < 0)
9✔
596
                        return r;
597
        }
598

599
        r = tunnel_get_local_address(t, link, &local);
9✔
600
        if (r < 0)
9✔
UNCOV
601
                return log_netdev_error_errno(netdev, r, "Could not find local address: %m");
×
602

603
        r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_LOCAL, &local.in6);
9✔
604
        if (r < 0)
9✔
605
                return r;
606

607
        r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in6);
9✔
608
        if (r < 0)
9✔
609
                return r;
610

611
        r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
9✔
612
        if (r < 0)
9✔
613
                return r;
614

615
        if (t->ipv6_flowlabel != _NETDEV_IPV6_FLOWLABEL_INVALID) {
9✔
616
                r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLOWINFO, t->ipv6_flowlabel);
×
UNCOV
617
                if (r < 0)
×
618
                        return r;
619
        }
620

621
        if (t->copy_dscp)
9✔
UNCOV
622
                t->flags |= IP6_TNL_F_RCV_DSCP_COPY;
×
623

624
        if (t->allow_localremote >= 0)
9✔
UNCOV
625
                SET_FLAG(t->flags, IP6_TNL_F_ALLOW_LOCAL_REMOTE, t->allow_localremote);
×
626

627
        r = sd_netlink_message_append_u32(m, IFLA_IPTUN_FLAGS, t->flags);
9✔
628
        if (r < 0)
9✔
629
                return r;
630

631
        if (t->encap_limit != 0) {
9✔
632
                r = sd_netlink_message_append_u8(m, IFLA_IPTUN_ENCAP_LIMIT, t->encap_limit);
9✔
633
                if (r < 0)
9✔
UNCOV
634
                        return r;
×
635
        }
636

637
        return 0;
638
}
639

640
static int netdev_tunnel_is_ready_to_create(NetDev *netdev, Link *link) {
254✔
641
        assert(netdev);
254✔
642

643
        Tunnel *t = ASSERT_PTR(TUNNEL(netdev));
254✔
644

645
        if (t->independent)
254✔
646
                return true;
647

648
        return tunnel_get_local_address(t, link, NULL) >= 0;
242✔
649
}
650

651
static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
97✔
652
        assert(netdev);
97✔
653
        assert(filename);
97✔
654

655
        Tunnel *t = ASSERT_PTR(TUNNEL(netdev));
97✔
656

657
        if (netdev->kind == NETDEV_KIND_IP6TNL &&
97✔
658
            t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID)
10✔
UNCOV
659
                return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
×
660
                                              "ip6tnl without mode configured in %s. Ignoring", filename);
661

662
        if (t->external) {
97✔
663
                if (IN_SET(netdev->kind, NETDEV_KIND_VTI, NETDEV_KIND_VTI6))
2✔
UNCOV
664
                        log_netdev_debug(netdev, "vti/vti6 tunnel do not support external mode, ignoring.");
×
665
                else {
666
                        /* tunnel with external mode does not require underlying interface. */
667
                        t->independent = true;
2✔
668

669
                        /* tunnel with external mode does not require any settings checked below. */
670
                        return 0;
2✔
671
                }
672
        }
673

674
        if (IN_SET(netdev->kind, NETDEV_KIND_VTI, NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE, NETDEV_KIND_GRETAP, NETDEV_KIND_ERSPAN)) {
95✔
675
                if (!IN_SET(t->family, AF_UNSPEC, AF_INET))
66✔
UNCOV
676
                        return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
×
677
                                                      "%s tunnel without a local/remote IPv4 address configured in %s, ignoring.",
678
                                                      netdev_kind_to_string(netdev->kind), filename);
679

680
                t->family = AF_INET; /* For netlink_message_append_in_addr_union(). */
66✔
681
        }
682

683
        if (IN_SET(netdev->kind, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP)) {
95✔
684
                if (!IN_SET(t->family, AF_UNSPEC, AF_INET6))
29✔
UNCOV
685
                        return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
×
686
                                                      "%s tunnel without a local/remote IPv6 address configured in %s, ignoring,",
687
                                                      netdev_kind_to_string(netdev->kind), filename);
688
                t->family = AF_INET6; /* For netlink_message_append_in_addr_union(). */
29✔
689
        }
690

691
        if (t->fou_tunnel && t->fou_destination_port <= 0)
95✔
UNCOV
692
                return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
×
693
                                              "FooOverUDP missing port configured in %s. Ignoring", filename);
694

695
        if (t->assign_to_loopback)
95✔
696
                t->independent = true;
1✔
697

698
        if (t->independent && t->local_type >= 0)
95✔
UNCOV
699
                return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
×
700
                                              "The local address cannot be '%s' when Independent= or AssignToLoopback= is enabled, ignoring.",
701
                                              strna(netdev_local_address_type_to_string(t->local_type)));
702

703
        if (t->pmtudisc > 0 && t->ignore_df)
95✔
UNCOV
704
                return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
×
705
                                              "IgnoreDontFragment= cannot be enabled when DiscoverPathMTU= is enabled");
706
        if (t->pmtudisc < 0)
95✔
707
                t->pmtudisc = !t->ignore_df;
95✔
708
        return 0;
709
}
710

711
static bool tunnel_needs_reconfigure(NetDev *netdev, NetDevLocalAddressType type) {
131✔
712
        assert(type >= 0 && type < _NETDEV_LOCAL_ADDRESS_TYPE_MAX);
131✔
713

714
        Tunnel *t = ASSERT_PTR(TUNNEL(netdev));
131✔
715

716
        return t->local_type == type;
131✔
717
}
718

719
static int unset_local(Tunnel *t) {
32✔
720
        assert(t);
32✔
721

722
        /* Unset the previous assignment. */
723
        t->local = IN_ADDR_NULL;
32✔
724
        t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
32✔
725

726
        /* If the remote address is not specified, also clear the address family. */
727
        if (!in_addr_is_set(t->family, &t->remote))
32✔
728
                t->family = AF_UNSPEC;
32✔
729

730
        return 0;
32✔
731
}
732

733
int config_parse_tunnel_local_address(
95✔
734
                const char *unit,
735
                const char *filename,
736
                unsigned line,
737
                const char *section,
738
                unsigned section_line,
739
                const char *lvalue,
740
                int ltype,
741
                const char *rvalue,
742
                void *data,
743
                void *userdata) {
744

745
        union in_addr_union buffer = IN_ADDR_NULL;
95✔
746
        NetDevLocalAddressType type;
95✔
747
        Tunnel *t = ASSERT_PTR(userdata);
95✔
748
        int r, f;
95✔
749

750
        assert(filename);
95✔
751
        assert(lvalue);
95✔
752
        assert(rvalue);
95✔
753

754
        if (isempty(rvalue) || streq(rvalue, "any"))
95✔
755
                return unset_local(t);
32✔
756

757
        type = netdev_local_address_type_from_string(rvalue);
63✔
758
        if (IN_SET(type, NETDEV_LOCAL_ADDRESS_IPV4LL, NETDEV_LOCAL_ADDRESS_DHCP4))
63✔
759
                f = AF_INET;
1✔
760
        else if (IN_SET(type, NETDEV_LOCAL_ADDRESS_IPV6LL, NETDEV_LOCAL_ADDRESS_DHCP6, NETDEV_LOCAL_ADDRESS_SLAAC))
62✔
761
                f = AF_INET6;
2✔
762
        else {
763
                type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
60✔
764
                r = in_addr_from_string_auto(rvalue, &f, &buffer);
60✔
765
                if (r < 0) {
60✔
766
                        log_syntax(unit, LOG_WARNING, filename, line, r,
2✔
767
                                   "Tunnel address \"%s\" invalid, ignoring assignment: %m", rvalue);
768
                        return 0;
2✔
769
                }
770

771
                if (in_addr_is_null(f, &buffer))
58✔
UNCOV
772
                        return unset_local(t);
×
773
        }
774

775
        if (t->family != AF_UNSPEC && t->family != f) {
61✔
UNCOV
776
                log_syntax(unit, LOG_WARNING, filename, line, 0,
×
777
                           "Address family does not match the previous assignment, ignoring assignment: %s", rvalue);
UNCOV
778
                return 0;
×
779
        }
780

781
        t->family = f;
61✔
782
        t->local = buffer;
61✔
783
        t->local_type = type;
61✔
784
        return 0;
61✔
785
}
786

787
static int unset_remote(Tunnel *t) {
31✔
788
        assert(t);
31✔
789

790
        /* Unset the previous assignment. */
791
        t->remote = IN_ADDR_NULL;
31✔
792

793
        /* If the local address is not specified, also clear the address family. */
794
        if (t->local_type == _NETDEV_LOCAL_ADDRESS_TYPE_INVALID &&
31✔
795
            !in_addr_is_set(t->family, &t->local))
30✔
796
                t->family = AF_UNSPEC;
10✔
797

798
        return 0;
31✔
799
}
800

801
int config_parse_tunnel_remote_address(
93✔
802
                const char *unit,
803
                const char *filename,
804
                unsigned line,
805
                const char *section,
806
                unsigned section_line,
807
                const char *lvalue,
808
                int ltype,
809
                const char *rvalue,
810
                void *data,
811
                void *userdata) {
812

813
        union in_addr_union buffer;
93✔
814
        Tunnel *t = ASSERT_PTR(userdata);
93✔
815
        int r, f;
93✔
816

817
        assert(filename);
93✔
818
        assert(lvalue);
93✔
819
        assert(rvalue);
93✔
820

821
        if (isempty(rvalue) || streq(rvalue, "any"))
93✔
822
                return unset_remote(t);
31✔
823

824
        r = in_addr_from_string_auto(rvalue, &f, &buffer);
62✔
825
        if (r < 0) {
62✔
UNCOV
826
                log_syntax(unit, LOG_WARNING, filename, line, r,
×
827
                           "Tunnel address \"%s\" invalid, ignoring assignment: %m", rvalue);
UNCOV
828
                return 0;
×
829
        }
830

831
        if (in_addr_is_null(f, &buffer))
62✔
UNCOV
832
                return unset_remote(t);
×
833

834
        if (t->family != AF_UNSPEC && t->family != f) {
62✔
UNCOV
835
                log_syntax(unit, LOG_WARNING, filename, line, 0,
×
836
                           "Address family does not match the previous assignment, ignoring assignment: %s", rvalue);
UNCOV
837
                return 0;
×
838
        }
839

840
        t->family = f;
62✔
841
        t->remote = buffer;
62✔
842
        return 0;
62✔
843
}
844

845
int config_parse_tunnel_key(
33✔
846
                const char *unit,
847
                const char *filename,
848
                unsigned line,
849
                const char *section,
850
                unsigned section_line,
851
                const char *lvalue,
852
                int ltype,
853
                const char *rvalue,
854
                void *data,
855
                void *userdata) {
856

857
        uint32_t *dest = ASSERT_PTR(data), k;
33✔
858
        union in_addr_union buffer;
33✔
859
        int r;
33✔
860

861
        assert(filename);
33✔
862
        assert(rvalue);
33✔
863

864
        r = in_addr_from_string(AF_INET, rvalue, &buffer);
33✔
865
        if (r < 0) {
33✔
866
                r = safe_atou32(rvalue, &k);
25✔
867
                if (r < 0) {
25✔
UNCOV
868
                        log_syntax(unit, LOG_WARNING, filename, line, r,
×
869
                                   "Failed to parse tunnel key ignoring assignment: %s", rvalue);
UNCOV
870
                        return 0;
×
871
                }
872
        } else
873
                k = be32toh(buffer.in.s_addr);
8✔
874

875
        *dest = k;
33✔
876
        return 0;
33✔
877
}
878

UNCOV
879
int config_parse_ipv6_flowlabel(
×
880
                const char* unit,
881
                const char *filename,
882
                unsigned line,
883
                const char *section,
884
                unsigned section_line,
885
                const char *lvalue,
886
                int ltype,
887
                const char *rvalue,
888
                void *data,
889
                void *userdata) {
890

891
        Tunnel *t = ASSERT_PTR(userdata);
×
892
        uint32_t k;
×
UNCOV
893
        int r;
×
894

895
        assert(filename);
×
UNCOV
896
        assert(rvalue);
×
897

898
        if (streq(rvalue, "inherit")) {
×
899
                t->ipv6_flowlabel = IP6_FLOWINFO_FLOWLABEL;
×
900
                t->flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
×
UNCOV
901
                return 0;
×
902
        }
903

UNCOV
904
        r = config_parse_uint32_bounded(
×
905
                        unit, filename, line, section, section_line, lvalue, rvalue,
906
                        0, 0xFFFFF, true,
907
                        &k);
UNCOV
908
        if (r <= 0)
×
909
                return r;
910
        t->ipv6_flowlabel = htobe32(k) & IP6_FLOWINFO_FLOWLABEL;
×
UNCOV
911
        t->flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
×
912

UNCOV
913
        return 0;
×
914
}
915

UNCOV
916
int config_parse_encap_limit(
×
917
                const char* unit,
918
                const char *filename,
919
                unsigned line,
920
                const char *section,
921
                unsigned section_line,
922
                const char *lvalue,
923
                int ltype,
924
                const char *rvalue,
925
                void *data,
926
                void *userdata) {
927

928
        assert(filename);
×
UNCOV
929
        assert(rvalue);
×
930

931
        Tunnel *t = ASSERT_PTR(userdata);
×
UNCOV
932
        int r;
×
933

934
        if (streq(rvalue, "none")) {
×
935
                t->encap_limit = 0;
×
936
                t->flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
×
UNCOV
937
                return 0;
×
938
        }
939

UNCOV
940
        r = config_parse_uint8_bounded(
×
941
                        unit, filename, line, section, section_line, lvalue, rvalue,
942
                        0, UINT8_MAX, true,
943
                        &t->encap_limit);
UNCOV
944
        if (r <= 0)
×
945
                return r;
UNCOV
946
        t->flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
×
947

UNCOV
948
        return 0;
×
949
}
950

951
int config_parse_6rd_prefix(
2✔
952
                const char* unit,
953
                const char *filename,
954
                unsigned line,
955
                const char *section,
956
                unsigned section_line,
957
                const char *lvalue,
958
                int ltype,
959
                const char *rvalue,
960
                void *data,
961
                void *userdata) {
962

963
        Tunnel *t = userdata;
2✔
964
        union in_addr_union p;
2✔
965
        uint8_t l;
2✔
966
        int r;
2✔
967

968
        assert(filename);
2✔
969
        assert(lvalue);
2✔
970
        assert(rvalue);
2✔
971

972
        r = in_addr_prefix_from_string(rvalue, AF_INET6, &p, &l);
2✔
973
        if (r < 0) {
2✔
974
                log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 6rd prefix \"%s\", ignoring: %m", rvalue);
×
UNCOV
975
                return 0;
×
976
        }
977
        if (l == 0) {
2✔
978
                log_syntax(unit, LOG_WARNING, filename, line, 0, "6rd prefix length of \"%s\" must be greater than zero, ignoring", rvalue);
×
UNCOV
979
                return 0;
×
980
        }
981

982
        t->sixrd_prefix = p.in6;
2✔
983
        t->sixrd_prefixlen = l;
2✔
984

985
        return 0;
2✔
986
}
987

988
int config_parse_erspan_version(
12✔
989
                const char* unit,
990
                const char *filename,
991
                unsigned line,
992
                const char *section,
993
                unsigned section_line,
994
                const char *lvalue,
995
                int ltype,
996
                const char *rvalue,
997
                void *data,
998
                void *userdata) {
999

1000
        assert(filename);
12✔
1001
        assert(lvalue);
12✔
1002
        assert(rvalue);
12✔
1003

1004
        uint8_t *v = ASSERT_PTR(data);
12✔
1005

1006
        if (isempty(rvalue)) {
12✔
1007
                *v = 1; /* defaults to 1 */
×
UNCOV
1008
                return 0;
×
1009
        }
1010

1011
        return config_parse_uint8_bounded(
12✔
1012
                        unit, filename, line, section, section_line, lvalue, rvalue,
1013
                        0, 2, true,
1014
                        v);
1015
}
1016

1017
int config_parse_erspan_index(
12✔
1018
                const char* unit,
1019
                const char *filename,
1020
                unsigned line,
1021
                const char *section,
1022
                unsigned section_line,
1023
                const char *lvalue,
1024
                int ltype,
1025
                const char *rvalue,
1026
                void *data,
1027
                void *userdata) {
1028

1029
        assert(filename);
12✔
1030
        assert(lvalue);
12✔
1031
        assert(rvalue);
12✔
1032

1033
        uint32_t *v = ASSERT_PTR(data);
12✔
1034

1035
        if (isempty(rvalue)) {
12✔
1036
                *v = 0; /* defaults to 0 */
×
UNCOV
1037
                return 0;
×
1038
        }
1039

1040
        return config_parse_uint32_bounded(
12✔
1041
                        unit, filename, line, section, section_line, lvalue, rvalue,
1042
                        0, 0x100000 - 1, true,
1043
                        v);
1044
}
1045

1046
int config_parse_erspan_direction(
12✔
1047
                const char* unit,
1048
                const char *filename,
1049
                unsigned line,
1050
                const char *section,
1051
                unsigned section_line,
1052
                const char *lvalue,
1053
                int ltype,
1054
                const char *rvalue,
1055
                void *data,
1056
                void *userdata) {
1057

1058
        assert(filename);
12✔
1059
        assert(lvalue);
12✔
1060
        assert(rvalue);
12✔
1061

1062
        uint8_t *v = ASSERT_PTR(data);
12✔
1063

1064
        if (isempty(rvalue) || streq(rvalue, "ingress"))
24✔
1065
                *v = 0; /* defaults to ingress */
6✔
1066
        else if (streq(rvalue, "egress"))
6✔
1067
                *v = 1;
6✔
1068
        else
UNCOV
1069
                log_syntax(unit, LOG_WARNING, filename, line, 0,
×
1070
                           "Invalid erspan direction \"%s\", which must be \"ingress\" or \"egress\", ignoring.", rvalue);
1071

1072
        return 0;
12✔
1073
}
1074

1075
int config_parse_erspan_hwid(
12✔
1076
                const char* unit,
1077
                const char *filename,
1078
                unsigned line,
1079
                const char *section,
1080
                unsigned section_line,
1081
                const char *lvalue,
1082
                int ltype,
1083
                const char *rvalue,
1084
                void *data,
1085
                void *userdata) {
1086

1087
        assert(filename);
12✔
1088
        assert(lvalue);
12✔
1089
        assert(rvalue);
12✔
1090

1091
        uint16_t *v = ASSERT_PTR(data);
12✔
1092

1093
        if (isempty(rvalue)) {
12✔
1094
                *v = 0; /* defaults to 0 */
×
UNCOV
1095
                return 0;
×
1096
        }
1097

1098
        return config_parse_uint16_bounded(
12✔
1099
                        unit, filename, line, section, section_line, lvalue, rvalue,
1100
                        0, 63, true,
1101
                        v);
1102
}
1103

1104
static void netdev_tunnel_init(NetDev *netdev) {
97✔
1105
        Tunnel *t = ASSERT_PTR(TUNNEL(netdev));
97✔
1106

1107
        t->local_type = _NETDEV_LOCAL_ADDRESS_TYPE_INVALID;
97✔
1108
        t->pmtudisc = -1;
97✔
1109
        t->fou_encap_type = NETDEV_FOO_OVER_UDP_ENCAP_DIRECT;
97✔
1110
        t->isatap = -1;
97✔
1111
        t->gre_erspan_sequence = -1;
97✔
1112
        t->encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
97✔
1113
        t->ip6tnl_mode = _NETDEV_IP6_TNL_MODE_INVALID;
97✔
1114
        t->ipv6_flowlabel = _NETDEV_IPV6_FLOWLABEL_INVALID;
97✔
1115
        t->allow_localremote = -1;
97✔
1116
        t->erspan_version = 1;
97✔
1117

1118
        if (IN_SET(netdev->kind, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP, NETDEV_KIND_IP6TNL))
97✔
1119
                t->ttl = DEFAULT_IPV6_TTL;
25✔
1120
}
97✔
1121

1122
static bool tunnel_can_set_mac(NetDev *netdev, const struct hw_addr_data *hw_addr) {
×
1123
        assert(IN_SET(netdev->kind, NETDEV_KIND_GRETAP, NETDEV_KIND_IP6GRETAP, NETDEV_KIND_ERSPAN));
×
UNCOV
1124
        return true;
×
1125
}
1126

1127
const NetDevVTable ipip_vtable = {
1128
        .object_size = sizeof(Tunnel),
1129
        .init = netdev_tunnel_init,
1130
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1131
        .fill_message_create = netdev_ipip_sit_fill_message_create,
1132
        .create_type = NETDEV_CREATE_STACKED,
1133
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1134
        .config_verify = netdev_tunnel_verify,
1135
        .needs_reconfigure = tunnel_needs_reconfigure,
1136
        .iftype = ARPHRD_TUNNEL,
1137
};
1138

1139
const NetDevVTable sit_vtable = {
1140
        .object_size = sizeof(Tunnel),
1141
        .init = netdev_tunnel_init,
1142
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1143
        .fill_message_create = netdev_ipip_sit_fill_message_create,
1144
        .create_type = NETDEV_CREATE_STACKED,
1145
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1146
        .config_verify = netdev_tunnel_verify,
1147
        .needs_reconfigure = tunnel_needs_reconfigure,
1148
        .iftype = ARPHRD_SIT,
1149
};
1150

1151
const NetDevVTable vti_vtable = {
1152
        .object_size = sizeof(Tunnel),
1153
        .init = netdev_tunnel_init,
1154
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1155
        .fill_message_create = netdev_vti_fill_message_create,
1156
        .create_type = NETDEV_CREATE_STACKED,
1157
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1158
        .config_verify = netdev_tunnel_verify,
1159
        .needs_reconfigure = tunnel_needs_reconfigure,
1160
        .iftype = ARPHRD_TUNNEL,
1161
};
1162

1163
const NetDevVTable vti6_vtable = {
1164
        .object_size = sizeof(Tunnel),
1165
        .init = netdev_tunnel_init,
1166
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1167
        .fill_message_create = netdev_vti_fill_message_create,
1168
        .create_type = NETDEV_CREATE_STACKED,
1169
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1170
        .config_verify = netdev_tunnel_verify,
1171
        .needs_reconfigure = tunnel_needs_reconfigure,
1172
        .iftype = ARPHRD_TUNNEL6,
1173
};
1174

1175
const NetDevVTable gre_vtable = {
1176
        .object_size = sizeof(Tunnel),
1177
        .init = netdev_tunnel_init,
1178
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1179
        .fill_message_create = netdev_gre_erspan_fill_message_create,
1180
        .create_type = NETDEV_CREATE_STACKED,
1181
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1182
        .config_verify = netdev_tunnel_verify,
1183
        .needs_reconfigure = tunnel_needs_reconfigure,
1184
        .iftype = ARPHRD_IPGRE,
1185
};
1186

1187
const NetDevVTable gretap_vtable = {
1188
        .object_size = sizeof(Tunnel),
1189
        .init = netdev_tunnel_init,
1190
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1191
        .fill_message_create = netdev_gre_erspan_fill_message_create,
1192
        .create_type = NETDEV_CREATE_STACKED,
1193
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1194
        .config_verify = netdev_tunnel_verify,
1195
        .needs_reconfigure = tunnel_needs_reconfigure,
1196
        .can_set_mac = tunnel_can_set_mac,
1197
        .iftype = ARPHRD_ETHER,
1198
        .generate_mac = true,
1199
};
1200

1201
const NetDevVTable ip6gre_vtable = {
1202
        .object_size = sizeof(Tunnel),
1203
        .init = netdev_tunnel_init,
1204
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1205
        .fill_message_create = netdev_ip6gre_fill_message_create,
1206
        .create_type = NETDEV_CREATE_STACKED,
1207
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1208
        .config_verify = netdev_tunnel_verify,
1209
        .needs_reconfigure = tunnel_needs_reconfigure,
1210
        .iftype = ARPHRD_IP6GRE,
1211
};
1212

1213
const NetDevVTable ip6gretap_vtable = {
1214
        .object_size = sizeof(Tunnel),
1215
        .init = netdev_tunnel_init,
1216
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1217
        .fill_message_create = netdev_ip6gre_fill_message_create,
1218
        .create_type = NETDEV_CREATE_STACKED,
1219
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1220
        .config_verify = netdev_tunnel_verify,
1221
        .needs_reconfigure = tunnel_needs_reconfigure,
1222
        .can_set_mac = tunnel_can_set_mac,
1223
        .iftype = ARPHRD_ETHER,
1224
        .generate_mac = true,
1225
};
1226

1227
const NetDevVTable ip6tnl_vtable = {
1228
        .object_size = sizeof(Tunnel),
1229
        .init = netdev_tunnel_init,
1230
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1231
        .fill_message_create = netdev_ip6tnl_fill_message_create,
1232
        .create_type = NETDEV_CREATE_STACKED,
1233
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1234
        .config_verify = netdev_tunnel_verify,
1235
        .needs_reconfigure = tunnel_needs_reconfigure,
1236
        .iftype = ARPHRD_TUNNEL6,
1237
};
1238

1239
const NetDevVTable erspan_vtable = {
1240
        .object_size = sizeof(Tunnel),
1241
        .init = netdev_tunnel_init,
1242
        .sections = NETDEV_COMMON_SECTIONS "Tunnel\0",
1243
        .fill_message_create = netdev_gre_erspan_fill_message_create,
1244
        .create_type = NETDEV_CREATE_STACKED,
1245
        .is_ready_to_create = netdev_tunnel_is_ready_to_create,
1246
        .config_verify = netdev_tunnel_verify,
1247
        .needs_reconfigure = tunnel_needs_reconfigure,
1248
        .can_set_mac = tunnel_can_set_mac,
1249
        .iftype = ARPHRD_ETHER,
1250
        .generate_mac = true,
1251
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc