]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/link_ip6tnl.c
bridge: vlan: support for per vlan tunnel info
[mirror_iproute2.git] / ip / link_ip6tnl.c
CommitLineData
9d0efc10
ND
1/*
2 * link_ip6tnl.c ip6tnl driver module
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Nicolas Dichtel <nicolas.dichtel@6wind.com>
10 *
11 */
12
13#include <string.h>
14#include <net/if.h>
15#include <sys/types.h>
16#include <sys/socket.h>
17#include <arpa/inet.h>
18
19#include <linux/ip.h>
20#include <linux/if_tunnel.h>
21#include <linux/ip6_tunnel.h>
22#include "rt_names.h"
23#include "utils.h"
24#include "ip_common.h"
25#include "tunnel.h"
26
27#define IP6_FLOWINFO_TCLASS htonl(0x0FF00000)
28#define IP6_FLOWINFO_FLOWLABEL htonl(0x000FFFFF)
29
30#define DEFAULT_TNL_HOP_LIMIT (64)
31
561e650e 32static void print_usage(FILE *f)
9d0efc10 33{
8b471354
PS
34 fprintf(f,
35 "Usage: ... ip6tnl [ mode { ip6ip6 | ipip6 | any } ]\n"
36 " [ remote ADDR ]\n"
37 " [ local ADDR ]\n"
38 " [ dev PHYS_DEV ]\n"
39 " [ encaplimit ELIM ]\n"
40 " [ hoplimit HLIM ]\n"
41 " [ tclass TCLASS ]\n"
42 " [ flowlabel FLOWLABEL ]\n"
43 " [ dscp inherit ]\n"
ad4b1425 44 " [ fwmark MARK ]\n"
8b471354
PS
45 " [ noencap ]\n"
46 " [ encap { fou | gue | none } ]\n"
47 " [ encap-sport PORT ]\n"
48 " [ encap-dport PORT ]\n"
49 " [ [no]encap-csum ]\n"
50 " [ [no]encap-csum6 ]\n"
51 " [ [no]encap-remcsum ]\n"
52 " [ external ]\n"
53 "\n"
54 "Where: ADDR := IPV6_ADDRESS\n"
55 " ELIM := { none | 0..255 }(default=%d)\n"
56 " HLIM := 0..255 (default=%d)\n"
57 " TCLASS := { 0x0..0xff | inherit }\n"
ad4b1425
CG
58 " FLOWLABEL := { 0x0..0xfffff | inherit }\n"
59 " MARK := { 0x0..0xffffffff | inherit }\n",
8b471354
PS
60 IPV6_DEFAULT_TNL_ENCAP_LIMIT, DEFAULT_TNL_HOP_LIMIT
61 );
561e650e 62}
63
64static void usage(void) __attribute__((noreturn));
65static void usage(void)
66{
67 print_usage(stderr);
9d0efc10
ND
68 exit(-1);
69}
70
71static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
72 struct nlmsghdr *n)
73{
d17b136f 74 struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
9d0efc10
ND
75 struct {
76 struct nlmsghdr n;
77 struct ifinfomsg i;
d17b136f
PS
78 } req = {
79 .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
80 .n.nlmsg_flags = NLM_F_REQUEST,
81 .n.nlmsg_type = RTM_GETLINK,
82 .i.ifi_family = preferred_family,
83 .i.ifi_index = ifi->ifi_index,
84 };
86bf43c7 85 struct nlmsghdr *answer = NULL;
9d0efc10
ND
86 struct rtattr *tb[IFLA_MAX + 1];
87 struct rtattr *linkinfo[IFLA_INFO_MAX+1];
88 struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
89 int len;
d17b136f
PS
90 struct in6_addr laddr = {};
91 struct in6_addr raddr = {};
9d0efc10
ND
92 __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
93 __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
94 __u32 flowinfo = 0;
95 __u32 flags = 0;
96 __u32 link = 0;
97 __u8 proto = 0;
73516e12
TH
98 __u16 encaptype = 0;
99 __u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
100 __u16 encapsport = 0;
101 __u16 encapdport = 0;
4bfe6825 102 __u8 metadata = 0;
ad4b1425 103 __u32 fwmark = 0;
9d0efc10 104
9d0efc10 105 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
86bf43c7 106 if (rtnl_talk(&rth, &req.n, &answer) < 0) {
9d0efc10
ND
107get_failed:
108 fprintf(stderr,
109 "Failed to get existing tunnel info.\n");
86bf43c7 110 free(answer);
9d0efc10
ND
111 return -1;
112 }
113
86bf43c7 114 len = answer->nlmsg_len;
9d0efc10
ND
115 len -= NLMSG_LENGTH(sizeof(*ifi));
116 if (len < 0)
117 goto get_failed;
118
86bf43c7 119 parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
9d0efc10
ND
120
121 if (!tb[IFLA_LINKINFO])
122 goto get_failed;
123
124 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
125
126 if (!linkinfo[IFLA_INFO_DATA])
127 goto get_failed;
128
129 parse_rtattr_nested(iptuninfo, IFLA_IPTUN_MAX,
130 linkinfo[IFLA_INFO_DATA]);
131
132 if (iptuninfo[IFLA_IPTUN_LOCAL])
133 memcpy(&laddr, RTA_DATA(iptuninfo[IFLA_IPTUN_LOCAL]),
134 sizeof(laddr));
135
136 if (iptuninfo[IFLA_IPTUN_REMOTE])
137 memcpy(&raddr, RTA_DATA(iptuninfo[IFLA_IPTUN_REMOTE]),
138 sizeof(raddr));
139
140 if (iptuninfo[IFLA_IPTUN_TTL])
141 hop_limit = rta_getattr_u8(iptuninfo[IFLA_IPTUN_TTL]);
142
143 if (iptuninfo[IFLA_IPTUN_ENCAP_LIMIT])
144 encap_limit = rta_getattr_u8(iptuninfo[IFLA_IPTUN_ENCAP_LIMIT]);
145
146 if (iptuninfo[IFLA_IPTUN_FLOWINFO])
147 flowinfo = rta_getattr_u32(iptuninfo[IFLA_IPTUN_FLOWINFO]);
148
149 if (iptuninfo[IFLA_IPTUN_FLAGS])
150 flags = rta_getattr_u32(iptuninfo[IFLA_IPTUN_FLAGS]);
151
152 if (iptuninfo[IFLA_IPTUN_LINK])
153 link = rta_getattr_u32(iptuninfo[IFLA_IPTUN_LINK]);
154
155 if (iptuninfo[IFLA_IPTUN_PROTO])
156 proto = rta_getattr_u8(iptuninfo[IFLA_IPTUN_PROTO]);
4bfe6825
AS
157 if (iptuninfo[IFLA_IPTUN_COLLECT_METADATA])
158 metadata = 1;
ad4b1425
CG
159
160 if (iptuninfo[IFLA_IPTUN_FWMARK])
161 fwmark = rta_getattr_u32(iptuninfo[IFLA_IPTUN_FWMARK]);
86bf43c7
HL
162
163 free(answer);
9d0efc10
ND
164 }
165
166 while (argc > 0) {
167 if (matches(*argv, "mode") == 0) {
168 NEXT_ARG();
169 if (strcmp(*argv, "ipv6/ipv6") == 0 ||
170 strcmp(*argv, "ip6ip6") == 0)
171 proto = IPPROTO_IPV6;
172 else if (strcmp(*argv, "ip/ipv6") == 0 ||
173 strcmp(*argv, "ipv4/ipv6") == 0 ||
174 strcmp(*argv, "ipip6") == 0 ||
175 strcmp(*argv, "ip4ip6") == 0)
176 proto = IPPROTO_IPIP;
177 else if (strcmp(*argv, "any/ipv6") == 0 ||
178 strcmp(*argv, "any") == 0)
179 proto = 0;
180 else
181 invarg("Cannot guess tunnel mode.", *argv);
182 } else if (strcmp(*argv, "remote") == 0) {
183 inet_prefix addr;
56f5daac 184
9d0efc10
ND
185 NEXT_ARG();
186 get_prefix(&addr, *argv, preferred_family);
187 if (addr.family == AF_UNSPEC)
188 invarg("\"remote\" address family is AF_UNSPEC", *argv);
189 memcpy(&raddr, addr.data, addr.bytelen);
190 } else if (strcmp(*argv, "local") == 0) {
191 inet_prefix addr;
56f5daac 192
9d0efc10
ND
193 NEXT_ARG();
194 get_prefix(&addr, *argv, preferred_family);
195 if (addr.family == AF_UNSPEC)
196 invarg("\"local\" address family is AF_UNSPEC", *argv);
197 memcpy(&laddr, addr.data, addr.bytelen);
198 } else if (matches(*argv, "dev") == 0) {
199 NEXT_ARG();
200 link = if_nametoindex(*argv);
201 if (link == 0)
202 invarg("\"dev\" is invalid", *argv);
203 } else if (strcmp(*argv, "hoplimit") == 0 ||
204 strcmp(*argv, "ttl") == 0 ||
205 strcmp(*argv, "hlim") == 0) {
206 __u8 uval;
56f5daac 207
9d0efc10
ND
208 NEXT_ARG();
209 if (get_u8(&uval, *argv, 0))
210 invarg("invalid HLIM", *argv);
211 hop_limit = uval;
73516e12 212 } else if (strcmp(*argv, "encaplimit") == 0) {
9d0efc10
ND
213 NEXT_ARG();
214 if (strcmp(*argv, "none") == 0) {
215 flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
216 } else {
217 __u8 uval;
56f5daac 218
9d0efc10
ND
219 if (get_u8(&uval, *argv, 0) < -1)
220 invarg("invalid ELIM", *argv);
221 encap_limit = uval;
222 flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
223 }
224 } else if (strcmp(*argv, "tclass") == 0 ||
225 strcmp(*argv, "tc") == 0 ||
226 strcmp(*argv, "tos") == 0 ||
227 matches(*argv, "dsfield") == 0) {
228 __u8 uval;
56f5daac 229
9d0efc10
ND
230 NEXT_ARG();
231 flowinfo &= ~IP6_FLOWINFO_TCLASS;
232 if (strcmp(*argv, "inherit") == 0)
233 flags |= IP6_TNL_F_USE_ORIG_TCLASS;
234 else {
235 if (get_u8(&uval, *argv, 16))
236 invarg("invalid TClass", *argv);
237 flowinfo |= htonl((__u32)uval << 20) & IP6_FLOWINFO_TCLASS;
238 flags &= ~IP6_TNL_F_USE_ORIG_TCLASS;
239 }
240 } else if (strcmp(*argv, "flowlabel") == 0 ||
241 strcmp(*argv, "fl") == 0) {
242 __u32 uval;
56f5daac 243
9d0efc10
ND
244 NEXT_ARG();
245 flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
246 if (strcmp(*argv, "inherit") == 0)
247 flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
248 else {
249 if (get_u32(&uval, *argv, 16))
250 invarg("invalid Flowlabel", *argv);
251 if (uval > 0xFFFFF)
252 invarg("invalid Flowlabel", *argv);
253 flowinfo |= htonl(uval) & IP6_FLOWINFO_FLOWLABEL;
254 flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
255 }
256 } else if (strcmp(*argv, "dscp") == 0) {
257 NEXT_ARG();
258 if (strcmp(*argv, "inherit") != 0)
259 invarg("not inherit", *argv);
260 flags |= IP6_TNL_F_RCV_DSCP_COPY;
261 } else if (strcmp(*argv, "fwmark") == 0) {
262 NEXT_ARG();
ad4b1425
CG
263 if (strcmp(*argv, "inherit") == 0) {
264 flags |= IP6_TNL_F_USE_ORIG_FWMARK;
265 fwmark = 0;
266 } else {
267 if (get_u32(&fwmark, *argv, 0))
268 invarg("invalid fwmark\n", *argv);
269 flags &= ~IP6_TNL_F_USE_ORIG_FWMARK;
270 }
73516e12
TH
271 } else if (strcmp(*argv, "noencap") == 0) {
272 encaptype = TUNNEL_ENCAP_NONE;
273 } else if (strcmp(*argv, "encap") == 0) {
274 NEXT_ARG();
275 if (strcmp(*argv, "fou") == 0)
276 encaptype = TUNNEL_ENCAP_FOU;
277 else if (strcmp(*argv, "gue") == 0)
278 encaptype = TUNNEL_ENCAP_GUE;
279 else if (strcmp(*argv, "none") == 0)
280 encaptype = TUNNEL_ENCAP_NONE;
281 else
282 invarg("Invalid encap type.", *argv);
283 } else if (strcmp(*argv, "encap-sport") == 0) {
284 NEXT_ARG();
285 if (strcmp(*argv, "auto") == 0)
286 encapsport = 0;
287 else if (get_u16(&encapsport, *argv, 0))
288 invarg("Invalid source port.", *argv);
289 } else if (strcmp(*argv, "encap-dport") == 0) {
290 NEXT_ARG();
291 if (get_u16(&encapdport, *argv, 0))
292 invarg("Invalid destination port.", *argv);
293 } else if (strcmp(*argv, "encap-csum") == 0) {
294 encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
295 } else if (strcmp(*argv, "noencap-csum") == 0) {
296 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
297 } else if (strcmp(*argv, "encap-udp6-csum") == 0) {
298 encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
299 } else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
300 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
301 } else if (strcmp(*argv, "encap-remcsum") == 0) {
302 encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
303 } else if (strcmp(*argv, "noencap-remcsum") == 0) {
304 encapflags |= ~TUNNEL_ENCAP_FLAG_REMCSUM;
4bfe6825
AS
305 } else if (strcmp(*argv, "external") == 0) {
306 metadata = 1;
9d0efc10
ND
307 } else
308 usage();
309 argc--, argv++;
310 }
311
312 addattr8(n, 1024, IFLA_IPTUN_PROTO, proto);
4bfe6825
AS
313 if (metadata) {
314 addattr_l(n, 1024, IFLA_IPTUN_COLLECT_METADATA, NULL, 0);
315 return 0;
316 }
9d0efc10
ND
317 addattr_l(n, 1024, IFLA_IPTUN_LOCAL, &laddr, sizeof(laddr));
318 addattr_l(n, 1024, IFLA_IPTUN_REMOTE, &raddr, sizeof(raddr));
319 addattr8(n, 1024, IFLA_IPTUN_TTL, hop_limit);
320 addattr8(n, 1024, IFLA_IPTUN_ENCAP_LIMIT, encap_limit);
321 addattr32(n, 1024, IFLA_IPTUN_FLOWINFO, flowinfo);
322 addattr32(n, 1024, IFLA_IPTUN_FLAGS, flags);
323 addattr32(n, 1024, IFLA_IPTUN_LINK, link);
ad4b1425 324 addattr32(n, 1024, IFLA_IPTUN_FWMARK, fwmark);
9d0efc10 325
73516e12
TH
326 addattr16(n, 1024, IFLA_IPTUN_ENCAP_TYPE, encaptype);
327 addattr16(n, 1024, IFLA_IPTUN_ENCAP_FLAGS, encapflags);
328 addattr16(n, 1024, IFLA_IPTUN_ENCAP_SPORT, htons(encapsport));
329 addattr16(n, 1024, IFLA_IPTUN_ENCAP_DPORT, htons(encapdport));
330
9d0efc10
ND
331 return 0;
332}
333
334static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
335{
9d0efc10
ND
336 char s2[64];
337 int flags = 0;
338 __u32 flowinfo = 0;
339
340 if (!tb)
341 return;
342
343 if (tb[IFLA_IPTUN_FLAGS])
344 flags = rta_getattr_u32(tb[IFLA_IPTUN_FLAGS]);
345
346 if (tb[IFLA_IPTUN_FLOWINFO])
347 flowinfo = rta_getattr_u32(tb[IFLA_IPTUN_FLOWINFO]);
348
349 if (tb[IFLA_IPTUN_PROTO]) {
350 switch (rta_getattr_u8(tb[IFLA_IPTUN_PROTO])) {
351 case IPPROTO_IPIP:
1facc1c6 352 print_string(PRINT_ANY, "proto", "%s ", "ipip6");
9d0efc10
ND
353 break;
354 case IPPROTO_IPV6:
1facc1c6 355 print_string(PRINT_ANY, "proto", "%s ", "ip6ip6");
9d0efc10
ND
356 break;
357 case 0:
1facc1c6 358 print_string(PRINT_ANY, "proto", "%s ", "any");
9d0efc10
ND
359 break;
360 }
361 }
362
363 if (tb[IFLA_IPTUN_REMOTE]) {
1facc1c6
JF
364 print_string(PRINT_ANY,
365 "remote",
366 "remote %s ",
367 rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
9d0efc10
ND
368 }
369
370 if (tb[IFLA_IPTUN_LOCAL]) {
1facc1c6
JF
371 print_string(PRINT_ANY,
372 "local",
373 "local %s ",
374 rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
9d0efc10
ND
375 }
376
377 if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
56f5daac 378 unsigned int link = rta_getattr_u32(tb[IFLA_IPTUN_LINK]);
9d0efc10
ND
379 const char *n = if_indextoname(link, s2);
380
381 if (n)
1facc1c6 382 print_string(PRINT_ANY, "link", "dev %s ", n);
9d0efc10 383 else
1facc1c6 384 print_uint(PRINT_ANY, "link_index", "dev %u ", link);
9d0efc10
ND
385 }
386
387 if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
1facc1c6
JF
388 print_bool(PRINT_ANY,
389 "ip6_tnl_f_ign_encap_limit",
390 "encaplimit none ",
391 true);
9d0efc10 392 else if (tb[IFLA_IPTUN_ENCAP_LIMIT])
1facc1c6
JF
393 print_uint(PRINT_ANY,
394 "encap_limit",
395 "encaplimit %u ",
396 rta_getattr_u8(tb[IFLA_IPTUN_ENCAP_LIMIT]));
9d0efc10
ND
397
398 if (tb[IFLA_IPTUN_TTL])
1facc1c6
JF
399 print_uint(PRINT_ANY,
400 "ttl",
401 "hoplimit %u ",
402 rta_getattr_u8(tb[IFLA_IPTUN_TTL]));
9d0efc10
ND
403
404 if (flags & IP6_TNL_F_USE_ORIG_TCLASS)
1facc1c6
JF
405 print_bool(PRINT_ANY,
406 "ip6_tnl_f_use_orig_tclass",
407 "tclass inherit ",
408 true);
9d0efc10
ND
409 else if (tb[IFLA_IPTUN_FLOWINFO]) {
410 __u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS);
411
1facc1c6
JF
412 if (is_json_context()) {
413 SPRINT_BUF(b1);
414
415 snprintf(b1, sizeof(b1), "0x%02x", (__u8)(val >> 20));
416 print_string(PRINT_JSON, "flowinfo_tclass", NULL, b1);
417 } else {
418 printf("tclass 0x%02x ", (__u8)(val >> 20));
419 }
420 }
421
422 if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
423 print_bool(PRINT_ANY,
424 "ip6_tnl_f_use_orig_flowlabel",
425 "flowlabel inherit ",
426 true);
427 } else {
428 if (is_json_context()) {
429 SPRINT_BUF(b1);
430
431 snprintf(b1, sizeof(b1), "0x%05x",
432 ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
433 print_string(PRINT_JSON, "flowlabel", NULL, b1);
434 } else {
435 printf("flowlabel 0x%05x ",
436 ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
437 }
9d0efc10
ND
438 }
439
1facc1c6
JF
440 if (is_json_context()) {
441 SPRINT_BUF(flwinfo);
9d0efc10 442
1facc1c6
JF
443 snprintf(flwinfo, sizeof(flwinfo), "0x%08x", ntohl(flowinfo));
444 print_string(PRINT_JSON, "flowinfo", NULL, flwinfo);
445 } else {
446 printf("(flowinfo 0x%08x) ", ntohl(flowinfo));
447
448 }
9d0efc10
ND
449
450 if (flags & IP6_TNL_F_RCV_DSCP_COPY)
1facc1c6
JF
451 print_bool(PRINT_ANY,
452 "ip6_tnl_f_rcv_dscp_copy",
453 "dscp inherit ",
454 true);
9d0efc10
ND
455
456 if (flags & IP6_TNL_F_MIP6_DEV)
1facc1c6
JF
457 print_bool(PRINT_ANY, "ip6_tnl_f_mip6_dev", "mip6 ", true);
458
459 if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
460 print_bool(PRINT_ANY,
461 "ip6_tnl_f_use_orig_fwmark",
462 "fwmark inherit ",
463 true);
464 } else if (tb[IFLA_IPTUN_FWMARK]) {
465 __u32 fwmark = rta_getattr_u32(tb[IFLA_IPTUN_FWMARK]);
9d0efc10 466
1facc1c6
JF
467 if (fwmark) {
468 SPRINT_BUF(b1);
469
470 snprintf(b1, sizeof(b1), "0x%x", fwmark);
471 print_string(PRINT_ANY, "fwmark", "fwmark %s ", b1);
472 }
473 }
73516e12
TH
474
475 if (tb[IFLA_IPTUN_ENCAP_TYPE] &&
1facc1c6 476 rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
73516e12
TH
477 __u16 type = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_TYPE]);
478 __u16 flags = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_FLAGS]);
479 __u16 sport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_SPORT]);
480 __u16 dport = rta_getattr_u16(tb[IFLA_IPTUN_ENCAP_DPORT]);
481
1facc1c6
JF
482 open_json_object("encap");
483 print_string(PRINT_FP, NULL, "encap ", NULL);
73516e12
TH
484 switch (type) {
485 case TUNNEL_ENCAP_FOU:
1facc1c6 486 print_string(PRINT_ANY, "type", "%s ", "fou");
73516e12
TH
487 break;
488 case TUNNEL_ENCAP_GUE:
1facc1c6 489 print_string(PRINT_ANY, "type", "%s ", "gue");
73516e12
TH
490 break;
491 default:
1facc1c6 492 print_null(PRINT_ANY, "type", "unknown ", NULL);
73516e12
TH
493 break;
494 }
495
1facc1c6
JF
496 if (is_json_context()) {
497 print_uint(PRINT_JSON,
498 "sport",
499 NULL,
500 sport ? ntohs(sport) : 0);
501 print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
502 print_bool(PRINT_JSON, "csum", NULL,
503 flags & TUNNEL_ENCAP_FLAG_CSUM);
504 print_bool(PRINT_JSON, "csum6", NULL,
505 flags & TUNNEL_ENCAP_FLAG_CSUM6);
506 print_bool(PRINT_JSON, "remcsum", NULL,
507 flags & TUNNEL_ENCAP_FLAG_REMCSUM);
508 close_json_object();
509 } else {
510 if (sport == 0)
511 fputs("encap-sport auto ", f);
512 else
513 fprintf(f, "encap-sport %u", ntohs(sport));
73516e12 514
1facc1c6 515 fprintf(f, "encap-dport %u ", ntohs(dport));
73516e12 516
1facc1c6
JF
517 if (flags & TUNNEL_ENCAP_FLAG_CSUM)
518 fputs("encap-csum ", f);
519 else
520 fputs("noencap-csum ", f);
73516e12 521
1facc1c6
JF
522 if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
523 fputs("encap-csum6 ", f);
524 else
525 fputs("noencap-csum6 ", f);
73516e12 526
1facc1c6
JF
527 if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
528 fputs("encap-remcsum ", f);
529 else
530 fputs("noencap-remcsum ", f);
531 }
73516e12 532 }
9d0efc10
ND
533}
534
561e650e 535static void ip6tunnel_print_help(struct link_util *lu, int argc, char **argv,
1facc1c6 536 FILE *f)
561e650e 537{
538 print_usage(f);
539}
540
9d0efc10
ND
541struct link_util ip6tnl_link_util = {
542 .id = "ip6tnl",
543 .maxattr = IFLA_IPTUN_MAX,
544 .parse_opt = ip6tunnel_parse_opt,
545 .print_opt = ip6tunnel_print_opt,
561e650e 546 .print_help = ip6tunnel_print_help,
9d0efc10 547};