]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/link_gre6.c
0a82eaecf2cdd861b6b2401cbca3f36a293e8f00
[mirror_iproute2.git] / ip / link_gre6.c
1 /*
2 * link_gre6.c gre 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: Dmitry Kozlov <xeb@mail.ru>
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
23 #include "rt_names.h"
24 #include "utils.h"
25 #include "ip_common.h"
26 #include "tunnel.h"
27
28 #define IP6_FLOWINFO_TCLASS htonl(0x0FF00000)
29 #define IP6_FLOWINFO_FLOWLABEL htonl(0x000FFFFF)
30
31 #define DEFAULT_TNL_HOP_LIMIT (64)
32
33 static void print_usage(FILE *f)
34 {
35 fprintf(f,
36 "Usage: ... { ip6gre | ip6gretap | ip6erspan} [ remote ADDR ]\n"
37 " [ local ADDR ]\n"
38 " [ [i|o]seq ]\n"
39 " [ [i|o]key KEY ]\n"
40 " [ [i|o]csum ]\n"
41 " [ hoplimit TTL ]\n"
42 " [ encaplimit ELIM ]\n"
43 " [ tclass TCLASS ]\n"
44 " [ flowlabel FLOWLABEL ]\n"
45 " [ dscp inherit ]\n"
46 " [ fwmark MARK ]\n"
47 " [ dev PHYS_DEV ]\n"
48 " [ noencap ]\n"
49 " [ encap { fou | gue | none } ]\n"
50 " [ encap-sport PORT ]\n"
51 " [ encap-dport PORT ]\n"
52 " [ [no]encap-csum ]\n"
53 " [ [no]encap-csum6 ]\n"
54 " [ [no]encap-remcsum ]\n"
55 " [ erspan IDX ]\n"
56 "\n"
57 "Where: ADDR := IPV6_ADDRESS\n"
58 " TTL := { 0..255 } (default=%d)\n"
59 " KEY := { DOTTED_QUAD | NUMBER }\n"
60 " ELIM := { none | 0..255 }(default=%d)\n"
61 " TCLASS := { 0x0..0xff | inherit }\n"
62 " FLOWLABEL := { 0x0..0xfffff | inherit }\n"
63 " MARK := { 0x0..0xffffffff | inherit }\n",
64 DEFAULT_TNL_HOP_LIMIT, IPV6_DEFAULT_TNL_ENCAP_LIMIT
65 );
66 }
67
68 static void usage(void) __attribute__((noreturn));
69 static void usage(void)
70 {
71 print_usage(stderr);
72 exit(-1);
73 }
74
75 static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
76 struct nlmsghdr *n)
77 {
78 struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
79 struct {
80 struct nlmsghdr n;
81 struct ifinfomsg i;
82 } req = {
83 .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
84 .n.nlmsg_flags = NLM_F_REQUEST,
85 .n.nlmsg_type = RTM_GETLINK,
86 .i.ifi_family = preferred_family,
87 .i.ifi_index = ifi->ifi_index,
88 };
89 struct nlmsghdr *answer = NULL;
90 struct rtattr *tb[IFLA_MAX + 1];
91 struct rtattr *linkinfo[IFLA_INFO_MAX+1];
92 struct rtattr *greinfo[IFLA_GRE_MAX + 1];
93 __u16 iflags = 0;
94 __u16 oflags = 0;
95 unsigned int ikey = 0;
96 unsigned int okey = 0;
97 struct in6_addr raddr = IN6ADDR_ANY_INIT;
98 struct in6_addr laddr = IN6ADDR_ANY_INIT;
99 unsigned int link = 0;
100 unsigned int flowinfo = 0;
101 unsigned int flags = 0;
102 __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
103 __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
104 __u16 encaptype = 0;
105 __u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
106 __u16 encapsport = 0;
107 __u16 encapdport = 0;
108 int len;
109 __u32 fwmark = 0;
110 __u32 erspan_idx = 0;
111
112 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
113 if (rtnl_talk(&rth, &req.n, &answer) < 0) {
114 get_failed:
115 fprintf(stderr,
116 "Failed to get existing tunnel info.\n");
117 free(answer);
118 return -1;
119 }
120
121 len = answer->nlmsg_len;
122 len -= NLMSG_LENGTH(sizeof(*ifi));
123 if (len < 0)
124 goto get_failed;
125
126 parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
127
128 if (!tb[IFLA_LINKINFO])
129 goto get_failed;
130
131 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
132
133 if (!linkinfo[IFLA_INFO_DATA])
134 goto get_failed;
135
136 parse_rtattr_nested(greinfo, IFLA_GRE_MAX,
137 linkinfo[IFLA_INFO_DATA]);
138
139 if (greinfo[IFLA_GRE_IKEY])
140 ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
141
142 if (greinfo[IFLA_GRE_OKEY])
143 okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]);
144
145 if (greinfo[IFLA_GRE_IFLAGS])
146 iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]);
147
148 if (greinfo[IFLA_GRE_OFLAGS])
149 oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
150
151 if (greinfo[IFLA_GRE_LOCAL])
152 memcpy(&laddr, RTA_DATA(greinfo[IFLA_GRE_LOCAL]), sizeof(laddr));
153
154 if (greinfo[IFLA_GRE_REMOTE])
155 memcpy(&raddr, RTA_DATA(greinfo[IFLA_GRE_REMOTE]), sizeof(raddr));
156
157 if (greinfo[IFLA_GRE_TTL])
158 hop_limit = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
159
160 if (greinfo[IFLA_GRE_LINK])
161 link = rta_getattr_u32(greinfo[IFLA_GRE_LINK]);
162
163 if (greinfo[IFLA_GRE_ENCAP_LIMIT])
164 encap_limit = rta_getattr_u8(greinfo[IFLA_GRE_ENCAP_LIMIT]);
165
166 if (greinfo[IFLA_GRE_FLOWINFO])
167 flowinfo = rta_getattr_u32(greinfo[IFLA_GRE_FLOWINFO]);
168
169 if (greinfo[IFLA_GRE_FLAGS])
170 flags = rta_getattr_u32(greinfo[IFLA_GRE_FLAGS]);
171
172 if (greinfo[IFLA_GRE_ENCAP_TYPE])
173 encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
174
175 if (greinfo[IFLA_GRE_ENCAP_FLAGS])
176 encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
177
178 if (greinfo[IFLA_GRE_ENCAP_SPORT])
179 encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
180
181 if (greinfo[IFLA_GRE_ENCAP_DPORT])
182 encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
183
184 if (greinfo[IFLA_GRE_FWMARK])
185 fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]);
186
187 if (greinfo[IFLA_GRE_ERSPAN_INDEX])
188 erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]);
189
190 free(answer);
191 }
192
193 while (argc > 0) {
194 if (!matches(*argv, "key")) {
195 unsigned int uval;
196
197 NEXT_ARG();
198 iflags |= GRE_KEY;
199 oflags |= GRE_KEY;
200 if (strchr(*argv, '.'))
201 uval = get_addr32(*argv);
202 else {
203 if (get_unsigned(&uval, *argv, 0) < 0) {
204 fprintf(stderr,
205 "Invalid value for \"key\"\n");
206 exit(-1);
207 }
208 uval = htonl(uval);
209 }
210
211 ikey = okey = uval;
212 } else if (!matches(*argv, "ikey")) {
213 unsigned int uval;
214
215 NEXT_ARG();
216 iflags |= GRE_KEY;
217 if (strchr(*argv, '.'))
218 uval = get_addr32(*argv);
219 else {
220 if (get_unsigned(&uval, *argv, 0) < 0) {
221 fprintf(stderr, "invalid value of \"ikey\"\n");
222 exit(-1);
223 }
224 uval = htonl(uval);
225 }
226 ikey = uval;
227 } else if (!matches(*argv, "okey")) {
228 unsigned int uval;
229
230 NEXT_ARG();
231 oflags |= GRE_KEY;
232 if (strchr(*argv, '.'))
233 uval = get_addr32(*argv);
234 else {
235 if (get_unsigned(&uval, *argv, 0) < 0) {
236 fprintf(stderr, "invalid value of \"okey\"\n");
237 exit(-1);
238 }
239 uval = htonl(uval);
240 }
241 okey = uval;
242 } else if (!matches(*argv, "seq")) {
243 iflags |= GRE_SEQ;
244 oflags |= GRE_SEQ;
245 } else if (!matches(*argv, "iseq")) {
246 iflags |= GRE_SEQ;
247 } else if (!matches(*argv, "oseq")) {
248 oflags |= GRE_SEQ;
249 } else if (!matches(*argv, "csum")) {
250 iflags |= GRE_CSUM;
251 oflags |= GRE_CSUM;
252 } else if (!matches(*argv, "icsum")) {
253 iflags |= GRE_CSUM;
254 } else if (!matches(*argv, "ocsum")) {
255 oflags |= GRE_CSUM;
256 } else if (!matches(*argv, "remote")) {
257 inet_prefix addr;
258
259 NEXT_ARG();
260 get_prefix(&addr, *argv, preferred_family);
261 if (addr.family == AF_UNSPEC)
262 invarg("\"remote\" address family is AF_UNSPEC", *argv);
263 memcpy(&raddr, &addr.data, sizeof(raddr));
264 } else if (!matches(*argv, "local")) {
265 inet_prefix addr;
266
267 NEXT_ARG();
268 get_prefix(&addr, *argv, preferred_family);
269 if (addr.family == AF_UNSPEC)
270 invarg("\"local\" address family is AF_UNSPEC", *argv);
271 memcpy(&laddr, &addr.data, sizeof(laddr));
272 } else if (!matches(*argv, "dev")) {
273 NEXT_ARG();
274 link = if_nametoindex(*argv);
275 if (link == 0) {
276 fprintf(stderr, "Cannot find device \"%s\"\n",
277 *argv);
278 exit(-1);
279 }
280 } else if (!matches(*argv, "ttl") ||
281 !matches(*argv, "hoplimit")) {
282 __u8 uval;
283
284 NEXT_ARG();
285 if (get_u8(&uval, *argv, 0))
286 invarg("invalid TTL", *argv);
287 hop_limit = uval;
288 } else if (!matches(*argv, "tos") ||
289 !matches(*argv, "tclass") ||
290 !matches(*argv, "dsfield")) {
291 __u8 uval;
292
293 NEXT_ARG();
294 if (strcmp(*argv, "inherit") == 0)
295 flags |= IP6_TNL_F_USE_ORIG_TCLASS;
296 else {
297 if (get_u8(&uval, *argv, 16))
298 invarg("invalid TClass", *argv);
299 flowinfo &= ~IP6_FLOWINFO_TCLASS;
300 flowinfo |= htonl((__u32)uval << 20) & IP6_FLOWINFO_TCLASS;
301 flags &= ~IP6_TNL_F_USE_ORIG_TCLASS;
302 }
303 } else if (strcmp(*argv, "flowlabel") == 0 ||
304 strcmp(*argv, "fl") == 0) {
305 __u32 uval;
306
307 NEXT_ARG();
308 if (strcmp(*argv, "inherit") == 0)
309 flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
310 else {
311 if (get_u32(&uval, *argv, 16))
312 invarg("invalid Flowlabel", *argv);
313 if (uval > 0xFFFFF)
314 invarg("invalid Flowlabel", *argv);
315 flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
316 flowinfo |= htonl(uval) & IP6_FLOWINFO_FLOWLABEL;
317 flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
318 }
319 } else if (strcmp(*argv, "dscp") == 0) {
320 NEXT_ARG();
321 if (strcmp(*argv, "inherit") != 0)
322 invarg("not inherit", *argv);
323 flags |= IP6_TNL_F_RCV_DSCP_COPY;
324 } else if (strcmp(*argv, "noencap") == 0) {
325 encaptype = TUNNEL_ENCAP_NONE;
326 } else if (strcmp(*argv, "encap") == 0) {
327 NEXT_ARG();
328 if (strcmp(*argv, "fou") == 0)
329 encaptype = TUNNEL_ENCAP_FOU;
330 else if (strcmp(*argv, "gue") == 0)
331 encaptype = TUNNEL_ENCAP_GUE;
332 else if (strcmp(*argv, "none") == 0)
333 encaptype = TUNNEL_ENCAP_NONE;
334 else
335 invarg("Invalid encap type.", *argv);
336 } else if (strcmp(*argv, "encap-sport") == 0) {
337 NEXT_ARG();
338 if (strcmp(*argv, "auto") == 0)
339 encapsport = 0;
340 else if (get_u16(&encapsport, *argv, 0))
341 invarg("Invalid source port.", *argv);
342 } else if (strcmp(*argv, "encap-dport") == 0) {
343 NEXT_ARG();
344 if (get_u16(&encapdport, *argv, 0))
345 invarg("Invalid destination port.", *argv);
346 } else if (strcmp(*argv, "encap-csum") == 0) {
347 encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
348 } else if (strcmp(*argv, "noencap-csum") == 0) {
349 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
350 } else if (strcmp(*argv, "encap-udp6-csum") == 0) {
351 encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
352 } else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
353 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
354 } else if (strcmp(*argv, "encap-remcsum") == 0) {
355 encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
356 } else if (strcmp(*argv, "noencap-remcsum") == 0) {
357 encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
358 } else if (strcmp(*argv, "fwmark") == 0) {
359 NEXT_ARG();
360 if (strcmp(*argv, "inherit") == 0) {
361 flags |= IP6_TNL_F_USE_ORIG_FWMARK;
362 fwmark = 0;
363 } else {
364 if (get_u32(&fwmark, *argv, 0))
365 invarg("invalid fwmark\n", *argv);
366 flags &= ~IP6_TNL_F_USE_ORIG_FWMARK;
367 }
368 } else if (strcmp(*argv, "encaplimit") == 0) {
369 NEXT_ARG();
370 if (strcmp(*argv, "none") == 0) {
371 flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
372 } else {
373 __u8 uval;
374
375 if (get_u8(&uval, *argv, 0))
376 invarg("invalid ELIM", *argv);
377 encap_limit = uval;
378 flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
379 }
380 } else if (strcmp(*argv, "erspan") == 0) {
381 NEXT_ARG();
382 if (get_u32(&erspan_idx, *argv, 0))
383 invarg("invalid erspan index\n", *argv);
384 if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0)
385 invarg("erspan index must be > 0 and <= 20-bit\n", *argv);
386 } else
387 usage();
388 argc--; argv++;
389 }
390
391 addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
392 addattr32(n, 1024, IFLA_GRE_OKEY, okey);
393 addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
394 addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
395 addattr_l(n, 1024, IFLA_GRE_LOCAL, &laddr, sizeof(laddr));
396 addattr_l(n, 1024, IFLA_GRE_REMOTE, &raddr, sizeof(raddr));
397 if (link)
398 addattr32(n, 1024, IFLA_GRE_LINK, link);
399 addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
400 addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
401 addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
402 addattr32(n, 1024, IFLA_GRE_FLAGS, flags);
403 addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark);
404 if (erspan_idx != 0)
405 addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx);
406
407 addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
408 addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
409 addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
410 addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
411
412 return 0;
413 }
414
415 static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
416 {
417 char s2[64];
418 const char *local = "any";
419 const char *remote = "any";
420 unsigned int iflags = 0;
421 unsigned int oflags = 0;
422 unsigned int flags = 0;
423 unsigned int flowinfo = 0;
424 struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
425
426 if (!tb)
427 return;
428
429 if (tb[IFLA_GRE_FLAGS])
430 flags = rta_getattr_u32(tb[IFLA_GRE_FLAGS]);
431
432 if (tb[IFLA_GRE_FLOWINFO])
433 flowinfo = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
434
435 if (tb[IFLA_GRE_REMOTE]) {
436 struct in6_addr addr;
437
438 memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
439
440 if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
441 remote = format_host(AF_INET6, sizeof(addr), &addr);
442 }
443
444 print_string(PRINT_ANY, "remote", "remote %s ", remote);
445
446 if (tb[IFLA_GRE_LOCAL]) {
447 struct in6_addr addr;
448
449 memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
450
451 if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
452 local = format_host(AF_INET6, sizeof(addr), &addr);
453 }
454
455 print_string(PRINT_ANY, "local", "local %s ", local);
456
457 if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
458 unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
459 const char *n = if_indextoname(link, s2);
460
461 if (n)
462 print_string(PRINT_ANY, "link", "dev %s ", n);
463 else
464 print_uint(PRINT_ANY, "link_index", "dev %u ", link);
465 }
466
467 if (tb[IFLA_GRE_TTL]) {
468 __u8 ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
469
470 if (ttl)
471 print_int(PRINT_ANY, "ttl", "hoplimit %d ", ttl);
472 else
473 print_int(PRINT_JSON, "ttl", NULL, ttl);
474 }
475
476 if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
477 print_bool(PRINT_ANY,
478 "ip6_tnl_f_ign_encap_limit",
479 "encaplimit none ",
480 true);
481 else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
482 int encap_limit = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
483
484 print_int(PRINT_ANY,
485 "encap_limit",
486 "encaplimit %d ",
487 encap_limit);
488 }
489
490 if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
491 print_bool(PRINT_ANY,
492 "ip6_tnl_f_use_orig_flowlabel",
493 "flowlabel inherit ",
494 true);
495 } else {
496 if (is_json_context()) {
497 SPRINT_BUF(b1);
498
499 snprintf(b1, sizeof(b1), "0x%05x",
500 ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
501 print_string(PRINT_JSON, "flowlabel", NULL, b1);
502
503 } else {
504 fprintf(f, "flowlabel 0x%05x ",
505 ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
506 }
507 }
508
509 if (flags & IP6_TNL_F_USE_ORIG_TCLASS) {
510 print_bool(PRINT_ANY,
511 "ip6_tnl_f_use_orig_tclass",
512 "tclass inherit ",
513 true);
514 } else {
515 if (is_json_context()) {
516 SPRINT_BUF(b1);
517
518 snprintf(b1, sizeof(b1), "0x%05x",
519 ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20);
520 print_string(PRINT_JSON, "tclass", NULL, b1);
521 } else {
522 fprintf(f, "tclass 0x%02x ",
523 ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20);
524 }
525 }
526
527 if (flags & IP6_TNL_F_RCV_DSCP_COPY)
528 print_bool(PRINT_ANY,
529 "ip6_tnl_f_rcv_dscp_copy",
530 "dscp inherit ",
531 true);
532
533 if (tb[IFLA_GRE_IFLAGS])
534 iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
535
536 if (tb[IFLA_GRE_OFLAGS])
537 oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]);
538
539 if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
540 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
541 print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
542 }
543
544 if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
545 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
546 print_string(PRINT_ANY, "okey", "okey %s ", s2);
547 }
548
549 if (iflags & GRE_SEQ)
550 print_bool(PRINT_ANY, "iseq", "iseq ", true);
551 if (oflags & GRE_SEQ)
552 print_bool(PRINT_ANY, "oseq", "oseq ", true);
553 if (iflags & GRE_CSUM)
554 print_bool(PRINT_ANY, "icsum", "icsum ", true);
555 if (oflags & GRE_CSUM)
556 print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
557
558 if (flags & IP6_TNL_F_USE_ORIG_FWMARK)
559 print_bool(PRINT_ANY,
560 "ip6_tnl_f_use_orig_fwmark",
561 "fwmark inherit ",
562 true);
563 else if (tb[IFLA_GRE_FWMARK]) {
564 __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
565
566 if (fwmark) {
567 snprintf(s2, sizeof(s2), "0x%x", fwmark);
568
569 print_string(PRINT_ANY, "fwmark", "fwmark %s ", s2);
570 }
571 }
572
573 if (tb[IFLA_GRE_ERSPAN_INDEX]) {
574 __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]);
575 fprintf(f, "erspan_index %u ", erspan_idx);
576 }
577
578 if (tb[IFLA_GRE_ENCAP_TYPE] &&
579 rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
580 __u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
581 __u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
582 __u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
583 __u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
584
585 open_json_object("encap");
586
587 print_string(PRINT_FP, NULL, "encap ", NULL);
588 switch (type) {
589 case TUNNEL_ENCAP_FOU:
590 print_string(PRINT_ANY, "type", "%s ", "fou");
591 break;
592 case TUNNEL_ENCAP_GUE:
593 print_string(PRINT_ANY, "type", "%s ", "gue");
594 break;
595 default:
596 print_null(PRINT_ANY, "type", "unknown ", NULL);
597 break;
598 }
599
600 if (is_json_context()) {
601 print_uint(PRINT_JSON,
602 "sport",
603 NULL,
604 sport ? ntohs(sport) : 0);
605 print_uint(PRINT_JSON, "dport", NULL, ntohs(dport));
606 print_bool(PRINT_JSON, "csum", NULL,
607 flags & TUNNEL_ENCAP_FLAG_CSUM);
608 print_bool(PRINT_JSON, "csum6", NULL,
609 flags & TUNNEL_ENCAP_FLAG_CSUM6);
610 print_bool(PRINT_JSON, "remcsum", NULL,
611 flags & TUNNEL_ENCAP_FLAG_REMCSUM);
612 close_json_object();
613 } else {
614 if (sport == 0)
615 fputs("encap-sport auto ", f);
616 else
617 fprintf(f, "encap-sport %u", ntohs(sport));
618
619 fprintf(f, "encap-dport %u ", ntohs(dport));
620
621 if (flags & TUNNEL_ENCAP_FLAG_CSUM)
622 fputs("encap-csum ", f);
623 else
624 fputs("noencap-csum ", f);
625
626 if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
627 fputs("encap-csum6 ", f);
628 else
629 fputs("noencap-csum6 ", f);
630
631 if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
632 fputs("encap-remcsum ", f);
633 else
634 fputs("noencap-remcsum ", f);
635 }
636 }
637 }
638
639 static void gre_print_help(struct link_util *lu, int argc, char **argv,
640 FILE *f)
641 {
642 print_usage(f);
643 }
644
645 struct link_util ip6gre_link_util = {
646 .id = "ip6gre",
647 .maxattr = IFLA_GRE_MAX,
648 .parse_opt = gre_parse_opt,
649 .print_opt = gre_print_opt,
650 .print_help = gre_print_help,
651 };
652
653 struct link_util ip6gretap_link_util = {
654 .id = "ip6gretap",
655 .maxattr = IFLA_GRE_MAX,
656 .parse_opt = gre_parse_opt,
657 .print_opt = gre_print_opt,
658 .print_help = gre_print_help,
659 };
660
661 struct link_util ip6erspan_link_util = {
662 .id = "ip6erspan",
663 .maxattr = IFLA_GRE_MAX,
664 .parse_opt = gre_parse_opt,
665 .print_opt = gre_print_opt,
666 .print_help = gre_print_help,
667 };