]> git.proxmox.com Git - mirror_iproute2.git/blame - ip/link_gre6.c
ip: Consolidate ip, xdp and lwtunnel parse/dump prototypes in ip_common.h
[mirror_iproute2.git] / ip / link_gre6.c
CommitLineData
af89576d 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
561e650e 33static void print_usage(FILE *f)
af89576d 34{
8b471354 35 fprintf(f,
8595cc40 36 "Usage: ... { ip6gre | ip6gretap | ip6erspan} [ remote ADDR ]\n"
8b471354
PS
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"
ad4b1425 46 " [ fwmark MARK ]\n"
8b471354
PS
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"
1e4be52b 55 " [ erspan_ver version ]\n"
8595cc40 56 " [ erspan IDX ]\n"
1e4be52b
WT
57 " [ erspan_dir { ingress | egress } ]\n"
58 " [ erspan_hwid hwid ]\n"
59 " [ external ]\n"
8b471354
PS
60 "\n"
61 "Where: ADDR := IPV6_ADDRESS\n"
62 " TTL := { 0..255 } (default=%d)\n"
63 " KEY := { DOTTED_QUAD | NUMBER }\n"
64 " ELIM := { none | 0..255 }(default=%d)\n"
65 " TCLASS := { 0x0..0xff | inherit }\n"
ad4b1425
CG
66 " FLOWLABEL := { 0x0..0xfffff | inherit }\n"
67 " MARK := { 0x0..0xffffffff | inherit }\n",
8b471354
PS
68 DEFAULT_TNL_HOP_LIMIT, IPV6_DEFAULT_TNL_ENCAP_LIMIT
69 );
561e650e 70}
71
72static void usage(void) __attribute__((noreturn));
73static void usage(void)
74{
75 print_usage(stderr);
af89576d 76 exit(-1);
77}
78
79static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
80 struct nlmsghdr *n)
81{
d17b136f 82 struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
af89576d 83 struct {
84 struct nlmsghdr n;
85 struct ifinfomsg i;
d17b136f
PS
86 } req = {
87 .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
88 .n.nlmsg_flags = NLM_F_REQUEST,
89 .n.nlmsg_type = RTM_GETLINK,
90 .i.ifi_family = preferred_family,
91 .i.ifi_index = ifi->ifi_index,
92 };
08ede25f 93 struct nlmsghdr *answer;
af89576d 94 struct rtattr *tb[IFLA_MAX + 1];
95 struct rtattr *linkinfo[IFLA_INFO_MAX+1];
96 struct rtattr *greinfo[IFLA_GRE_MAX + 1];
97 __u16 iflags = 0;
98 __u16 oflags = 0;
1f44b937
SP
99 __be32 ikey = 0;
100 __be32 okey = 0;
af89576d 101 struct in6_addr raddr = IN6ADDR_ANY_INIT;
102 struct in6_addr laddr = IN6ADDR_ANY_INIT;
56f5daac
SH
103 unsigned int link = 0;
104 unsigned int flowinfo = 0;
105 unsigned int flags = 0;
af89576d 106 __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
107 __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
0b2fbb73
TH
108 __u16 encaptype = 0;
109 __u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
110 __u16 encapsport = 0;
111 __u16 encapdport = 0;
6231c5be 112 __u8 metadata = 0;
af89576d 113 int len;
ad4b1425 114 __u32 fwmark = 0;
8595cc40 115 __u32 erspan_idx = 0;
28976362
WT
116 __u8 erspan_ver = 0;
117 __u8 erspan_dir = 0;
118 __u16 erspan_hwid = 0;
af89576d 119
120 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
86bf43c7 121 if (rtnl_talk(&rth, &req.n, &answer) < 0) {
af89576d 122get_failed:
123 fprintf(stderr,
124 "Failed to get existing tunnel info.\n");
125 return -1;
126 }
127
86bf43c7 128 len = answer->nlmsg_len;
af89576d 129 len -= NLMSG_LENGTH(sizeof(*ifi));
130 if (len < 0)
131 goto get_failed;
132
86bf43c7 133 parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len);
af89576d 134
135 if (!tb[IFLA_LINKINFO])
136 goto get_failed;
137
138 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
139
140 if (!linkinfo[IFLA_INFO_DATA])
141 goto get_failed;
142
143 parse_rtattr_nested(greinfo, IFLA_GRE_MAX,
144 linkinfo[IFLA_INFO_DATA]);
145
146 if (greinfo[IFLA_GRE_IKEY])
147 ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
148
149 if (greinfo[IFLA_GRE_OKEY])
150 okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]);
151
152 if (greinfo[IFLA_GRE_IFLAGS])
153 iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]);
154
155 if (greinfo[IFLA_GRE_OFLAGS])
156 oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
157
158 if (greinfo[IFLA_GRE_LOCAL])
159 memcpy(&laddr, RTA_DATA(greinfo[IFLA_GRE_LOCAL]), sizeof(laddr));
160
161 if (greinfo[IFLA_GRE_REMOTE])
162 memcpy(&raddr, RTA_DATA(greinfo[IFLA_GRE_REMOTE]), sizeof(raddr));
163
164 if (greinfo[IFLA_GRE_TTL])
165 hop_limit = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
166
167 if (greinfo[IFLA_GRE_LINK])
168 link = rta_getattr_u32(greinfo[IFLA_GRE_LINK]);
169
170 if (greinfo[IFLA_GRE_ENCAP_LIMIT])
171 encap_limit = rta_getattr_u8(greinfo[IFLA_GRE_ENCAP_LIMIT]);
172
173 if (greinfo[IFLA_GRE_FLOWINFO])
174 flowinfo = rta_getattr_u32(greinfo[IFLA_GRE_FLOWINFO]);
175
176 if (greinfo[IFLA_GRE_FLAGS])
177 flags = rta_getattr_u32(greinfo[IFLA_GRE_FLAGS]);
0b2fbb73
TH
178
179 if (greinfo[IFLA_GRE_ENCAP_TYPE])
180 encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
181
182 if (greinfo[IFLA_GRE_ENCAP_FLAGS])
183 encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
184
185 if (greinfo[IFLA_GRE_ENCAP_SPORT])
186 encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
187
6231c5be
WT
188 if (greinfo[IFLA_GRE_COLLECT_METADATA])
189 metadata = 1;
190
0b2fbb73
TH
191 if (greinfo[IFLA_GRE_ENCAP_DPORT])
192 encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
ad4b1425
CG
193
194 if (greinfo[IFLA_GRE_FWMARK])
195 fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]);
86bf43c7 196
8595cc40
WT
197 if (greinfo[IFLA_GRE_ERSPAN_INDEX])
198 erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]);
199
28976362
WT
200 if (greinfo[IFLA_GRE_ERSPAN_VER])
201 erspan_ver = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_VER]);
202
203 if (greinfo[IFLA_GRE_ERSPAN_DIR])
204 erspan_dir = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_DIR]);
205
206 if (greinfo[IFLA_GRE_ERSPAN_HWID])
207 erspan_hwid = rta_getattr_u16(greinfo[IFLA_GRE_ERSPAN_HWID]);
208
86bf43c7 209 free(answer);
af89576d 210 }
211
212 while (argc > 0) {
213 if (!matches(*argv, "key")) {
af89576d 214 NEXT_ARG();
215 iflags |= GRE_KEY;
216 oflags |= GRE_KEY;
1f44b937 217 ikey = okey = tnl_parse_key("key", *argv);
af89576d 218 } else if (!matches(*argv, "ikey")) {
af89576d 219 NEXT_ARG();
220 iflags |= GRE_KEY;
1f44b937 221 ikey = tnl_parse_key("ikey", *argv);
af89576d 222 } else if (!matches(*argv, "okey")) {
af89576d 223 NEXT_ARG();
224 oflags |= GRE_KEY;
1f44b937 225 okey = tnl_parse_key("okey", *argv);
af89576d 226 } else if (!matches(*argv, "seq")) {
227 iflags |= GRE_SEQ;
228 oflags |= GRE_SEQ;
229 } else if (!matches(*argv, "iseq")) {
230 iflags |= GRE_SEQ;
231 } else if (!matches(*argv, "oseq")) {
232 oflags |= GRE_SEQ;
233 } else if (!matches(*argv, "csum")) {
234 iflags |= GRE_CSUM;
235 oflags |= GRE_CSUM;
236 } else if (!matches(*argv, "icsum")) {
237 iflags |= GRE_CSUM;
238 } else if (!matches(*argv, "ocsum")) {
239 oflags |= GRE_CSUM;
240 } else if (!matches(*argv, "remote")) {
241 inet_prefix addr;
56f5daac 242
af89576d 243 NEXT_ARG();
9aceaad7 244 get_addr(&addr, *argv, AF_INET6);
af89576d 245 memcpy(&raddr, &addr.data, sizeof(raddr));
246 } else if (!matches(*argv, "local")) {
247 inet_prefix addr;
56f5daac 248
af89576d 249 NEXT_ARG();
9aceaad7 250 get_addr(&addr, *argv, AF_INET6);
af89576d 251 memcpy(&laddr, &addr.data, sizeof(laddr));
252 } else if (!matches(*argv, "dev")) {
253 NEXT_ARG();
7a14358b 254 link = ll_name_to_index(*argv);
0cb6bb51
CW
255 if (link == 0) {
256 fprintf(stderr, "Cannot find device \"%s\"\n",
257 *argv);
af89576d 258 exit(-1);
0cb6bb51 259 }
af89576d 260 } else if (!matches(*argv, "ttl") ||
c4743c4d
SP
261 !matches(*argv, "hoplimit") ||
262 !matches(*argv, "hlim")) {
af89576d 263 NEXT_ARG();
c4743c4d
SP
264 if (strcmp(*argv, "inherit") != 0) {
265 if (get_u8(&hop_limit, *argv, 0))
266 invarg("invalid HLIM\n", *argv);
267 } else
268 hop_limit = 0;
af89576d 269 } else if (!matches(*argv, "tos") ||
270 !matches(*argv, "tclass") ||
271 !matches(*argv, "dsfield")) {
272 __u8 uval;
56f5daac 273
af89576d 274 NEXT_ARG();
afdf9277 275 flowinfo &= ~IP6_FLOWINFO_TCLASS;
af89576d 276 if (strcmp(*argv, "inherit") == 0)
277 flags |= IP6_TNL_F_USE_ORIG_TCLASS;
278 else {
279 if (get_u8(&uval, *argv, 16))
280 invarg("invalid TClass", *argv);
281 flowinfo |= htonl((__u32)uval << 20) & IP6_FLOWINFO_TCLASS;
282 flags &= ~IP6_TNL_F_USE_ORIG_TCLASS;
283 }
284 } else if (strcmp(*argv, "flowlabel") == 0 ||
285 strcmp(*argv, "fl") == 0) {
286 __u32 uval;
56f5daac 287
af89576d 288 NEXT_ARG();
afdf9277 289 flowinfo &= ~IP6_FLOWINFO_FLOWLABEL;
af89576d 290 if (strcmp(*argv, "inherit") == 0)
291 flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
292 else {
293 if (get_u32(&uval, *argv, 16))
294 invarg("invalid Flowlabel", *argv);
295 if (uval > 0xFFFFF)
296 invarg("invalid Flowlabel", *argv);
297 flowinfo |= htonl(uval) & IP6_FLOWINFO_FLOWLABEL;
298 flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
299 }
300 } else if (strcmp(*argv, "dscp") == 0) {
301 NEXT_ARG();
302 if (strcmp(*argv, "inherit") != 0)
303 invarg("not inherit", *argv);
304 flags |= IP6_TNL_F_RCV_DSCP_COPY;
0b2fbb73
TH
305 } else if (strcmp(*argv, "noencap") == 0) {
306 encaptype = TUNNEL_ENCAP_NONE;
307 } else if (strcmp(*argv, "encap") == 0) {
308 NEXT_ARG();
309 if (strcmp(*argv, "fou") == 0)
310 encaptype = TUNNEL_ENCAP_FOU;
311 else if (strcmp(*argv, "gue") == 0)
312 encaptype = TUNNEL_ENCAP_GUE;
313 else if (strcmp(*argv, "none") == 0)
314 encaptype = TUNNEL_ENCAP_NONE;
315 else
316 invarg("Invalid encap type.", *argv);
317 } else if (strcmp(*argv, "encap-sport") == 0) {
318 NEXT_ARG();
319 if (strcmp(*argv, "auto") == 0)
320 encapsport = 0;
321 else if (get_u16(&encapsport, *argv, 0))
322 invarg("Invalid source port.", *argv);
323 } else if (strcmp(*argv, "encap-dport") == 0) {
324 NEXT_ARG();
325 if (get_u16(&encapdport, *argv, 0))
326 invarg("Invalid destination port.", *argv);
327 } else if (strcmp(*argv, "encap-csum") == 0) {
328 encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
329 } else if (strcmp(*argv, "noencap-csum") == 0) {
330 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
331 } else if (strcmp(*argv, "encap-udp6-csum") == 0) {
332 encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
333 } else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
334 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
335 } else if (strcmp(*argv, "encap-remcsum") == 0) {
336 encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
337 } else if (strcmp(*argv, "noencap-remcsum") == 0) {
338 encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
6231c5be
WT
339 } else if (strcmp(*argv, "external") == 0) {
340 metadata = 1;
ad4b1425
CG
341 } else if (strcmp(*argv, "fwmark") == 0) {
342 NEXT_ARG();
343 if (strcmp(*argv, "inherit") == 0) {
344 flags |= IP6_TNL_F_USE_ORIG_FWMARK;
345 fwmark = 0;
346 } else {
347 if (get_u32(&fwmark, *argv, 0))
348 invarg("invalid fwmark\n", *argv);
349 flags &= ~IP6_TNL_F_USE_ORIG_FWMARK;
350 }
a11b7b71
ND
351 } else if (strcmp(*argv, "encaplimit") == 0) {
352 NEXT_ARG();
353 if (strcmp(*argv, "none") == 0) {
354 flags |= IP6_TNL_F_IGN_ENCAP_LIMIT;
355 } else {
356 __u8 uval;
357
56708ae7 358 if (get_u8(&uval, *argv, 0))
a11b7b71
ND
359 invarg("invalid ELIM", *argv);
360 encap_limit = uval;
361 flags &= ~IP6_TNL_F_IGN_ENCAP_LIMIT;
362 }
8595cc40
WT
363 } else if (strcmp(*argv, "erspan") == 0) {
364 NEXT_ARG();
365 if (get_u32(&erspan_idx, *argv, 0))
366 invarg("invalid erspan index\n", *argv);
367 if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0)
368 invarg("erspan index must be > 0 and <= 20-bit\n", *argv);
28976362
WT
369 } else if (strcmp(*argv, "erspan_ver") == 0) {
370 NEXT_ARG();
371 if (get_u8(&erspan_ver, *argv, 0))
372 invarg("invalid erspan version\n", *argv);
373 if (erspan_ver != 1 && erspan_ver != 2)
374 invarg("erspan version must be 1 or 2\n", *argv);
375 } else if (strcmp(*argv, "erspan_dir") == 0) {
376 NEXT_ARG();
377 if (matches(*argv, "ingress") == 0)
378 erspan_dir = 0;
379 else if (matches(*argv, "egress") == 0)
380 erspan_dir = 1;
381 else
382 invarg("Invalid erspan direction.", *argv);
383 } else if (strcmp(*argv, "erspan_hwid") == 0) {
384 NEXT_ARG();
385 if (get_u16(&erspan_hwid, *argv, 0))
386 invarg("invalid erspan hwid\n", *argv);
af89576d 387 } else
388 usage();
389 argc--; argv++;
390 }
391
6231c5be
WT
392 if (!metadata) {
393 addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
394 addattr32(n, 1024, IFLA_GRE_OKEY, okey);
395 addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
396 addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
397 addattr_l(n, 1024, IFLA_GRE_LOCAL, &laddr, sizeof(laddr));
398 addattr_l(n, 1024, IFLA_GRE_REMOTE, &raddr, sizeof(raddr));
399 if (link)
400 addattr32(n, 1024, IFLA_GRE_LINK, link);
401 addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
402 addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
403 addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
404 addattr32(n, 1024, IFLA_GRE_FLAGS, flags);
405 addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark);
28976362
WT
406 if (erspan_ver) {
407 addattr8(n, 1024, IFLA_GRE_ERSPAN_VER, erspan_ver);
408 if (erspan_ver == 1 && erspan_idx != 0) {
de54cdd3
SP
409 addattr32(n, 1024,
410 IFLA_GRE_ERSPAN_INDEX, erspan_idx);
411 } else if (erspan_ver == 2) {
412 addattr8(n, 1024,
413 IFLA_GRE_ERSPAN_DIR, erspan_dir);
414 addattr16(n, 1024,
415 IFLA_GRE_ERSPAN_HWID, erspan_hwid);
28976362
WT
416 }
417 }
6231c5be
WT
418 addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
419 addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
420 addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
421 addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
422 } else {
423 addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0);
424 }
0b2fbb73 425
af89576d 426 return 0;
427}
428
429static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
430{
af89576d 431 char s2[64];
56f5daac
SH
432 unsigned int iflags = 0;
433 unsigned int oflags = 0;
434 unsigned int flags = 0;
090524f8 435 __u32 flowinfo = 0;
375560c4 436 __u8 ttl = 0;
af89576d 437
438 if (!tb)
439 return;
440
6231c5be 441 if (tb[IFLA_GRE_COLLECT_METADATA]) {
00ff4b8e 442 print_bool(PRINT_ANY, "external", "external", true);
6231c5be
WT
443 return;
444 }
445
af89576d 446 if (tb[IFLA_GRE_FLAGS])
447 flags = rta_getattr_u32(tb[IFLA_GRE_FLAGS]);
448
449 if (tb[IFLA_GRE_FLOWINFO])
35893864 450 flowinfo = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
af89576d 451
b761fc41
SP
452 tnl_print_endpoint("remote", tb[IFLA_GRE_REMOTE], AF_INET6);
453 tnl_print_endpoint("local", tb[IFLA_GRE_LOCAL], AF_INET6);
af89576d 454
45d3a6ef 455 if (tb[IFLA_GRE_LINK]) {
56f5daac 456 unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
af89576d 457
45d3a6ef
SP
458 if (link) {
459 print_string(PRINT_ANY, "link", "dev %s ",
460 ll_index_to_name(link));
461 }
af89576d 462 }
463
375560c4
SP
464 if (tb[IFLA_GRE_TTL])
465 ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]);
466 if (is_json_context() || ttl)
467 print_uint(PRINT_ANY, "ttl", "hoplimit %u ", ttl);
468 else
469 print_string(PRINT_FP, NULL, "hoplimit %s ", "inherit");
6856fb65 470
e3945d92 471 if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT) {
6856fb65
JF
472 print_bool(PRINT_ANY,
473 "ip6_tnl_f_ign_encap_limit",
474 "encaplimit none ",
475 true);
e3945d92
SP
476 } else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
477 __u8 val = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
af89576d 478
e3945d92 479 print_uint(PRINT_ANY, "encap_limit", "encaplimit %u ", val);
af89576d 480 }
481
2e706e12 482 if (flags & IP6_TNL_F_USE_ORIG_TCLASS) {
6856fb65 483 print_bool(PRINT_ANY,
2e706e12
SH
484 "ip6_tnl_f_use_orig_tclass",
485 "tclass inherit ",
6856fb65 486 true);
090524f8
SP
487 } else if (tb[IFLA_GRE_FLOWINFO]) {
488 __u32 val = ntohl(flowinfo & IP6_FLOWINFO_TCLASS) >> 20;
6856fb65 489
090524f8
SP
490 snprintf(s2, sizeof(s2), "0x%02x", val);
491 print_string(PRINT_ANY, "tclass", "tclass %s ", s2);
6856fb65 492 }
af89576d 493
763cf495 494 if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL) {
2e706e12 495 print_bool(PRINT_ANY,
763cf495
SP
496 "ip6_tnl_f_use_orig_flowlabel",
497 "flowlabel inherit ",
2e706e12 498 true);
763cf495
SP
499 } else if (tb[IFLA_GRE_FLOWINFO]) {
500 __u32 val = ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL);
2e706e12 501
763cf495
SP
502 snprintf(s2, sizeof(s2), "0x%05x", val);
503 print_string(PRINT_ANY, "flowlabel", "flowlabel %s ", s2);
2e706e12 504 }
af89576d 505
506 if (flags & IP6_TNL_F_RCV_DSCP_COPY)
6856fb65
JF
507 print_bool(PRINT_ANY,
508 "ip6_tnl_f_rcv_dscp_copy",
509 "dscp inherit ",
510 true);
af89576d 511
512 if (tb[IFLA_GRE_IFLAGS])
513 iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
514
515 if (tb[IFLA_GRE_OFLAGS])
516 oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]);
517
518 if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
519 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
6856fb65 520 print_string(PRINT_ANY, "ikey", "ikey %s ", s2);
af89576d 521 }
522
523 if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
524 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
6856fb65 525 print_string(PRINT_ANY, "okey", "okey %s ", s2);
af89576d 526 }
527
528 if (iflags & GRE_SEQ)
6856fb65 529 print_bool(PRINT_ANY, "iseq", "iseq ", true);
af89576d 530 if (oflags & GRE_SEQ)
6856fb65 531 print_bool(PRINT_ANY, "oseq", "oseq ", true);
af89576d 532 if (iflags & GRE_CSUM)
6856fb65 533 print_bool(PRINT_ANY, "icsum", "icsum ", true);
af89576d 534 if (oflags & GRE_CSUM)
6856fb65 535 print_bool(PRINT_ANY, "ocsum", "ocsum ", true);
0b2fbb73 536
e97ad3d2 537 if (flags & IP6_TNL_F_USE_ORIG_FWMARK) {
6856fb65
JF
538 print_bool(PRINT_ANY,
539 "ip6_tnl_f_use_orig_fwmark",
540 "fwmark inherit ",
541 true);
e97ad3d2 542 } else if (tb[IFLA_GRE_FWMARK]) {
6856fb65
JF
543 __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]);
544
545 if (fwmark) {
e97ad3d2
SP
546 print_0xhex(PRINT_ANY,
547 "fwmark", "fwmark 0x%x ", fwmark);
6856fb65
JF
548 }
549 }
ad4b1425 550
8595cc40
WT
551 if (tb[IFLA_GRE_ERSPAN_INDEX]) {
552 __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]);
3cb92eb9
SP
553 print_uint(PRINT_ANY,
554 "erspan_index", "erspan_index %u ", erspan_idx);
28976362
WT
555 }
556
557 if (tb[IFLA_GRE_ERSPAN_VER]) {
558 __u8 erspan_ver = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_VER]);
559
560 print_uint(PRINT_ANY, "erspan_ver", "erspan_ver %u ", erspan_ver);
561 }
562
563 if (tb[IFLA_GRE_ERSPAN_DIR]) {
564 __u8 erspan_dir = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_DIR]);
565
566 if (erspan_dir == 0)
567 print_string(PRINT_ANY, "erspan_dir",
568 "erspan_dir ingress ", NULL);
569 else
570 print_string(PRINT_ANY, "erspan_dir",
571 "erspan_dir egress ", NULL);
572 }
573
574 if (tb[IFLA_GRE_ERSPAN_HWID]) {
575 __u16 erspan_hwid = rta_getattr_u16(tb[IFLA_GRE_ERSPAN_HWID]);
576
577 print_hex(PRINT_ANY, "erspan_hwid", "erspan_hwid 0x%x ", erspan_hwid);
8595cc40
WT
578 }
579
bad76e6b
SP
580 tnl_print_encap(tb,
581 IFLA_GRE_ENCAP_TYPE,
582 IFLA_GRE_ENCAP_FLAGS,
583 IFLA_GRE_ENCAP_SPORT,
584 IFLA_GRE_ENCAP_DPORT);
af89576d 585}
586
561e650e 587static void gre_print_help(struct link_util *lu, int argc, char **argv,
de54cdd3 588 FILE *f)
561e650e 589{
590 print_usage(f);
591}
592
af89576d 593struct link_util ip6gre_link_util = {
594 .id = "ip6gre",
595 .maxattr = IFLA_GRE_MAX,
596 .parse_opt = gre_parse_opt,
597 .print_opt = gre_print_opt,
561e650e 598 .print_help = gre_print_help,
af89576d 599};
600
601struct link_util ip6gretap_link_util = {
602 .id = "ip6gretap",
603 .maxattr = IFLA_GRE_MAX,
604 .parse_opt = gre_parse_opt,
605 .print_opt = gre_print_opt,
561e650e 606 .print_help = gre_print_help,
af89576d 607};
8595cc40
WT
608
609struct link_util ip6erspan_link_util = {
610 .id = "ip6erspan",
611 .maxattr = IFLA_GRE_MAX,
612 .parse_opt = gre_parse_opt,
613 .print_opt = gre_print_opt,
614 .print_help = gre_print_help,
615};