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