2 * link_gre6.c gre driver module
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.
9 * Authors: Dmitry Kozlov <xeb@mail.ru>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <arpa/inet.h>
20 #include <linux/if_tunnel.h>
21 #include <linux/ip6_tunnel.h>
25 #include "ip_common.h"
28 #define IP6_FLOWINFO_TCLASS htonl(0x0FF00000)
29 #define IP6_FLOWINFO_FLOWLABEL htonl(0x000FFFFF)
31 #define DEFAULT_TNL_HOP_LIMIT (64)
33 static void print_usage(FILE *f
)
36 "Usage: ... { ip6gre | ip6gretap | ip6erspan} [ remote ADDR ]\n"
42 " [ encaplimit ELIM ]\n"
43 " [ tclass TCLASS ]\n"
44 " [ flowlabel FLOWLABEL ]\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_ver version ]\n"
57 " [ erspan_dir { ingress | egress } ]\n"
58 " [ erspan_hwid hwid ]\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"
66 " FLOWLABEL := { 0x0..0xfffff | inherit }\n"
67 " MARK := { 0x0..0xffffffff | inherit }\n",
68 DEFAULT_TNL_HOP_LIMIT
, IPV6_DEFAULT_TNL_ENCAP_LIMIT
72 static void usage(void) __attribute__((noreturn
));
73 static void usage(void)
79 static int gre_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
82 struct ifinfomsg
*ifi
= (struct ifinfomsg
*)(n
+ 1);
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
,
93 struct nlmsghdr
*answer
;
94 struct rtattr
*tb
[IFLA_MAX
+ 1];
95 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+1];
96 struct rtattr
*greinfo
[IFLA_GRE_MAX
+ 1];
101 struct in6_addr raddr
= IN6ADDR_ANY_INIT
;
102 struct in6_addr laddr
= IN6ADDR_ANY_INIT
;
103 unsigned int link
= 0;
104 unsigned int flowinfo
= 0;
105 unsigned int flags
= 0;
106 __u8 hop_limit
= DEFAULT_TNL_HOP_LIMIT
;
107 __u8 encap_limit
= IPV6_DEFAULT_TNL_ENCAP_LIMIT
;
109 __u16 encapflags
= TUNNEL_ENCAP_FLAG_CSUM6
;
110 __u16 encapsport
= 0;
111 __u16 encapdport
= 0;
115 __u32 erspan_idx
= 0;
118 __u16 erspan_hwid
= 0;
120 if (!(n
->nlmsg_flags
& NLM_F_CREATE
)) {
121 if (rtnl_talk(&rth
, &req
.n
, &answer
) < 0) {
124 "Failed to get existing tunnel info.\n");
128 len
= answer
->nlmsg_len
;
129 len
-= NLMSG_LENGTH(sizeof(*ifi
));
133 parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(NLMSG_DATA(answer
)), len
);
135 if (!tb
[IFLA_LINKINFO
])
138 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
140 if (!linkinfo
[IFLA_INFO_DATA
])
143 parse_rtattr_nested(greinfo
, IFLA_GRE_MAX
,
144 linkinfo
[IFLA_INFO_DATA
]);
146 if (greinfo
[IFLA_GRE_IKEY
])
147 ikey
= rta_getattr_u32(greinfo
[IFLA_GRE_IKEY
]);
149 if (greinfo
[IFLA_GRE_OKEY
])
150 okey
= rta_getattr_u32(greinfo
[IFLA_GRE_OKEY
]);
152 if (greinfo
[IFLA_GRE_IFLAGS
])
153 iflags
= rta_getattr_u16(greinfo
[IFLA_GRE_IFLAGS
]);
155 if (greinfo
[IFLA_GRE_OFLAGS
])
156 oflags
= rta_getattr_u16(greinfo
[IFLA_GRE_OFLAGS
]);
158 if (greinfo
[IFLA_GRE_LOCAL
])
159 memcpy(&laddr
, RTA_DATA(greinfo
[IFLA_GRE_LOCAL
]), sizeof(laddr
));
161 if (greinfo
[IFLA_GRE_REMOTE
])
162 memcpy(&raddr
, RTA_DATA(greinfo
[IFLA_GRE_REMOTE
]), sizeof(raddr
));
164 if (greinfo
[IFLA_GRE_TTL
])
165 hop_limit
= rta_getattr_u8(greinfo
[IFLA_GRE_TTL
]);
167 if (greinfo
[IFLA_GRE_LINK
])
168 link
= rta_getattr_u32(greinfo
[IFLA_GRE_LINK
]);
170 if (greinfo
[IFLA_GRE_ENCAP_LIMIT
])
171 encap_limit
= rta_getattr_u8(greinfo
[IFLA_GRE_ENCAP_LIMIT
]);
173 if (greinfo
[IFLA_GRE_FLOWINFO
])
174 flowinfo
= rta_getattr_u32(greinfo
[IFLA_GRE_FLOWINFO
]);
176 if (greinfo
[IFLA_GRE_FLAGS
])
177 flags
= rta_getattr_u32(greinfo
[IFLA_GRE_FLAGS
]);
179 if (greinfo
[IFLA_GRE_ENCAP_TYPE
])
180 encaptype
= rta_getattr_u16(greinfo
[IFLA_GRE_ENCAP_TYPE
]);
182 if (greinfo
[IFLA_GRE_ENCAP_FLAGS
])
183 encapflags
= rta_getattr_u16(greinfo
[IFLA_GRE_ENCAP_FLAGS
]);
185 if (greinfo
[IFLA_GRE_ENCAP_SPORT
])
186 encapsport
= rta_getattr_u16(greinfo
[IFLA_GRE_ENCAP_SPORT
]);
188 if (greinfo
[IFLA_GRE_COLLECT_METADATA
])
191 if (greinfo
[IFLA_GRE_ENCAP_DPORT
])
192 encapdport
= rta_getattr_u16(greinfo
[IFLA_GRE_ENCAP_DPORT
]);
194 if (greinfo
[IFLA_GRE_FWMARK
])
195 fwmark
= rta_getattr_u32(greinfo
[IFLA_GRE_FWMARK
]);
197 if (greinfo
[IFLA_GRE_ERSPAN_INDEX
])
198 erspan_idx
= rta_getattr_u32(greinfo
[IFLA_GRE_ERSPAN_INDEX
]);
200 if (greinfo
[IFLA_GRE_ERSPAN_VER
])
201 erspan_ver
= rta_getattr_u8(greinfo
[IFLA_GRE_ERSPAN_VER
]);
203 if (greinfo
[IFLA_GRE_ERSPAN_DIR
])
204 erspan_dir
= rta_getattr_u8(greinfo
[IFLA_GRE_ERSPAN_DIR
]);
206 if (greinfo
[IFLA_GRE_ERSPAN_HWID
])
207 erspan_hwid
= rta_getattr_u16(greinfo
[IFLA_GRE_ERSPAN_HWID
]);
213 if (!matches(*argv
, "key")) {
217 ikey
= okey
= tnl_parse_key("key", *argv
);
218 } else if (!matches(*argv
, "ikey")) {
221 ikey
= tnl_parse_key("ikey", *argv
);
222 } else if (!matches(*argv
, "okey")) {
225 okey
= tnl_parse_key("okey", *argv
);
226 } else if (!matches(*argv
, "seq")) {
229 } else if (!matches(*argv
, "iseq")) {
231 } else if (!matches(*argv
, "oseq")) {
233 } else if (!matches(*argv
, "csum")) {
236 } else if (!matches(*argv
, "icsum")) {
238 } else if (!matches(*argv
, "ocsum")) {
240 } else if (!matches(*argv
, "remote")) {
244 get_addr(&addr
, *argv
, AF_INET6
);
245 memcpy(&raddr
, &addr
.data
, sizeof(raddr
));
246 } else if (!matches(*argv
, "local")) {
250 get_addr(&addr
, *argv
, AF_INET6
);
251 memcpy(&laddr
, &addr
.data
, sizeof(laddr
));
252 } else if (!matches(*argv
, "dev")) {
254 link
= if_nametoindex(*argv
);
256 fprintf(stderr
, "Cannot find device \"%s\"\n",
260 } else if (!matches(*argv
, "ttl") ||
261 !matches(*argv
, "hoplimit")) {
265 if (get_u8(&uval
, *argv
, 0))
266 invarg("invalid TTL", *argv
);
268 } else if (!matches(*argv
, "tos") ||
269 !matches(*argv
, "tclass") ||
270 !matches(*argv
, "dsfield")) {
274 flowinfo
&= ~IP6_FLOWINFO_TCLASS
;
275 if (strcmp(*argv
, "inherit") == 0)
276 flags
|= IP6_TNL_F_USE_ORIG_TCLASS
;
278 if (get_u8(&uval
, *argv
, 16))
279 invarg("invalid TClass", *argv
);
280 flowinfo
|= htonl((__u32
)uval
<< 20) & IP6_FLOWINFO_TCLASS
;
281 flags
&= ~IP6_TNL_F_USE_ORIG_TCLASS
;
283 } else if (strcmp(*argv
, "flowlabel") == 0 ||
284 strcmp(*argv
, "fl") == 0) {
288 flowinfo
&= ~IP6_FLOWINFO_FLOWLABEL
;
289 if (strcmp(*argv
, "inherit") == 0)
290 flags
|= IP6_TNL_F_USE_ORIG_FLOWLABEL
;
292 if (get_u32(&uval
, *argv
, 16))
293 invarg("invalid Flowlabel", *argv
);
295 invarg("invalid Flowlabel", *argv
);
296 flowinfo
|= htonl(uval
) & IP6_FLOWINFO_FLOWLABEL
;
297 flags
&= ~IP6_TNL_F_USE_ORIG_FLOWLABEL
;
299 } else if (strcmp(*argv
, "dscp") == 0) {
301 if (strcmp(*argv
, "inherit") != 0)
302 invarg("not inherit", *argv
);
303 flags
|= IP6_TNL_F_RCV_DSCP_COPY
;
304 } else if (strcmp(*argv
, "noencap") == 0) {
305 encaptype
= TUNNEL_ENCAP_NONE
;
306 } else if (strcmp(*argv
, "encap") == 0) {
308 if (strcmp(*argv
, "fou") == 0)
309 encaptype
= TUNNEL_ENCAP_FOU
;
310 else if (strcmp(*argv
, "gue") == 0)
311 encaptype
= TUNNEL_ENCAP_GUE
;
312 else if (strcmp(*argv
, "none") == 0)
313 encaptype
= TUNNEL_ENCAP_NONE
;
315 invarg("Invalid encap type.", *argv
);
316 } else if (strcmp(*argv
, "encap-sport") == 0) {
318 if (strcmp(*argv
, "auto") == 0)
320 else if (get_u16(&encapsport
, *argv
, 0))
321 invarg("Invalid source port.", *argv
);
322 } else if (strcmp(*argv
, "encap-dport") == 0) {
324 if (get_u16(&encapdport
, *argv
, 0))
325 invarg("Invalid destination port.", *argv
);
326 } else if (strcmp(*argv
, "encap-csum") == 0) {
327 encapflags
|= TUNNEL_ENCAP_FLAG_CSUM
;
328 } else if (strcmp(*argv
, "noencap-csum") == 0) {
329 encapflags
&= ~TUNNEL_ENCAP_FLAG_CSUM
;
330 } else if (strcmp(*argv
, "encap-udp6-csum") == 0) {
331 encapflags
|= TUNNEL_ENCAP_FLAG_CSUM6
;
332 } else if (strcmp(*argv
, "noencap-udp6-csum") == 0) {
333 encapflags
&= ~TUNNEL_ENCAP_FLAG_CSUM6
;
334 } else if (strcmp(*argv
, "encap-remcsum") == 0) {
335 encapflags
|= TUNNEL_ENCAP_FLAG_REMCSUM
;
336 } else if (strcmp(*argv
, "noencap-remcsum") == 0) {
337 encapflags
&= ~TUNNEL_ENCAP_FLAG_REMCSUM
;
338 } else if (strcmp(*argv
, "external") == 0) {
340 } else if (strcmp(*argv
, "fwmark") == 0) {
342 if (strcmp(*argv
, "inherit") == 0) {
343 flags
|= IP6_TNL_F_USE_ORIG_FWMARK
;
346 if (get_u32(&fwmark
, *argv
, 0))
347 invarg("invalid fwmark\n", *argv
);
348 flags
&= ~IP6_TNL_F_USE_ORIG_FWMARK
;
350 } else if (strcmp(*argv
, "encaplimit") == 0) {
352 if (strcmp(*argv
, "none") == 0) {
353 flags
|= IP6_TNL_F_IGN_ENCAP_LIMIT
;
357 if (get_u8(&uval
, *argv
, 0))
358 invarg("invalid ELIM", *argv
);
360 flags
&= ~IP6_TNL_F_IGN_ENCAP_LIMIT
;
362 } else if (strcmp(*argv
, "erspan") == 0) {
364 if (get_u32(&erspan_idx
, *argv
, 0))
365 invarg("invalid erspan index\n", *argv
);
366 if (erspan_idx
& ~((1<<20) - 1) || erspan_idx
== 0)
367 invarg("erspan index must be > 0 and <= 20-bit\n", *argv
);
368 } else if (strcmp(*argv
, "erspan_ver") == 0) {
370 if (get_u8(&erspan_ver
, *argv
, 0))
371 invarg("invalid erspan version\n", *argv
);
372 if (erspan_ver
!= 1 && erspan_ver
!= 2)
373 invarg("erspan version must be 1 or 2\n", *argv
);
374 } else if (strcmp(*argv
, "erspan_dir") == 0) {
376 if (matches(*argv
, "ingress") == 0)
378 else if (matches(*argv
, "egress") == 0)
381 invarg("Invalid erspan direction.", *argv
);
382 } else if (strcmp(*argv
, "erspan_hwid") == 0) {
384 if (get_u16(&erspan_hwid
, *argv
, 0))
385 invarg("invalid erspan hwid\n", *argv
);
392 addattr32(n
, 1024, IFLA_GRE_IKEY
, ikey
);
393 addattr32(n
, 1024, IFLA_GRE_OKEY
, okey
);
394 addattr_l(n
, 1024, IFLA_GRE_IFLAGS
, &iflags
, 2);
395 addattr_l(n
, 1024, IFLA_GRE_OFLAGS
, &oflags
, 2);
396 addattr_l(n
, 1024, IFLA_GRE_LOCAL
, &laddr
, sizeof(laddr
));
397 addattr_l(n
, 1024, IFLA_GRE_REMOTE
, &raddr
, sizeof(raddr
));
399 addattr32(n
, 1024, IFLA_GRE_LINK
, link
);
400 addattr_l(n
, 1024, IFLA_GRE_TTL
, &hop_limit
, 1);
401 addattr_l(n
, 1024, IFLA_GRE_ENCAP_LIMIT
, &encap_limit
, 1);
402 addattr_l(n
, 1024, IFLA_GRE_FLOWINFO
, &flowinfo
, 4);
403 addattr32(n
, 1024, IFLA_GRE_FLAGS
, flags
);
404 addattr32(n
, 1024, IFLA_GRE_FWMARK
, fwmark
);
406 addattr8(n
, 1024, IFLA_GRE_ERSPAN_VER
, erspan_ver
);
407 if (erspan_ver
== 1 && erspan_idx
!= 0) {
408 addattr32(n
, 1024, IFLA_GRE_ERSPAN_INDEX
, erspan_idx
);
410 addattr8(n
, 1024, IFLA_GRE_ERSPAN_DIR
, erspan_dir
);
411 addattr16(n
, 1024, IFLA_GRE_ERSPAN_HWID
, erspan_hwid
);
414 addattr16(n
, 1024, IFLA_GRE_ENCAP_TYPE
, encaptype
);
415 addattr16(n
, 1024, IFLA_GRE_ENCAP_FLAGS
, encapflags
);
416 addattr16(n
, 1024, IFLA_GRE_ENCAP_SPORT
, htons(encapsport
));
417 addattr16(n
, 1024, IFLA_GRE_ENCAP_DPORT
, htons(encapdport
));
419 addattr_l(n
, 1024, IFLA_GRE_COLLECT_METADATA
, NULL
, 0);
425 static void gre_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
428 const char *local
= "any";
429 const char *remote
= "any";
430 unsigned int iflags
= 0;
431 unsigned int oflags
= 0;
432 unsigned int flags
= 0;
434 struct in6_addr in6_addr_any
= IN6ADDR_ANY_INIT
;
440 if (tb
[IFLA_GRE_COLLECT_METADATA
]) {
441 print_bool(PRINT_ANY
, "collect_metadata", "external", true);
445 if (tb
[IFLA_GRE_FLAGS
])
446 flags
= rta_getattr_u32(tb
[IFLA_GRE_FLAGS
]);
448 if (tb
[IFLA_GRE_FLOWINFO
])
449 flowinfo
= rta_getattr_u32(tb
[IFLA_GRE_FLOWINFO
]);
451 if (tb
[IFLA_GRE_REMOTE
]) {
452 struct in6_addr addr
;
454 memcpy(&addr
, RTA_DATA(tb
[IFLA_GRE_REMOTE
]), sizeof(addr
));
456 if (memcmp(&addr
, &in6_addr_any
, sizeof(addr
)))
457 remote
= format_host(AF_INET6
, sizeof(addr
), &addr
);
460 print_string(PRINT_ANY
, "remote", "remote %s ", remote
);
462 if (tb
[IFLA_GRE_LOCAL
]) {
463 struct in6_addr addr
;
465 memcpy(&addr
, RTA_DATA(tb
[IFLA_GRE_LOCAL
]), sizeof(addr
));
467 if (memcmp(&addr
, &in6_addr_any
, sizeof(addr
)))
468 local
= format_host(AF_INET6
, sizeof(addr
), &addr
);
471 print_string(PRINT_ANY
, "local", "local %s ", local
);
473 if (tb
[IFLA_GRE_LINK
]) {
474 unsigned int link
= rta_getattr_u32(tb
[IFLA_GRE_LINK
]);
477 print_string(PRINT_ANY
, "link", "dev %s ",
478 ll_index_to_name(link
));
482 if (tb
[IFLA_GRE_TTL
])
483 ttl
= rta_getattr_u8(tb
[IFLA_GRE_TTL
]);
484 if (is_json_context() || ttl
)
485 print_uint(PRINT_ANY
, "ttl", "hoplimit %u ", ttl
);
487 print_string(PRINT_FP
, NULL
, "hoplimit %s ", "inherit");
489 if (flags
& IP6_TNL_F_IGN_ENCAP_LIMIT
) {
490 print_bool(PRINT_ANY
,
491 "ip6_tnl_f_ign_encap_limit",
494 } else if (tb
[IFLA_GRE_ENCAP_LIMIT
]) {
495 __u8 val
= rta_getattr_u8(tb
[IFLA_GRE_ENCAP_LIMIT
]);
497 print_uint(PRINT_ANY
, "encap_limit", "encaplimit %u ", val
);
500 if (flags
& IP6_TNL_F_USE_ORIG_TCLASS
) {
501 print_bool(PRINT_ANY
,
502 "ip6_tnl_f_use_orig_tclass",
505 } else if (tb
[IFLA_GRE_FLOWINFO
]) {
506 __u32 val
= ntohl(flowinfo
& IP6_FLOWINFO_TCLASS
) >> 20;
508 snprintf(s2
, sizeof(s2
), "0x%02x", val
);
509 print_string(PRINT_ANY
, "tclass", "tclass %s ", s2
);
512 if (flags
& IP6_TNL_F_USE_ORIG_FLOWLABEL
) {
513 print_bool(PRINT_ANY
,
514 "ip6_tnl_f_use_orig_flowlabel",
515 "flowlabel inherit ",
517 } else if (tb
[IFLA_GRE_FLOWINFO
]) {
518 __u32 val
= ntohl(flowinfo
& IP6_FLOWINFO_FLOWLABEL
);
520 snprintf(s2
, sizeof(s2
), "0x%05x", val
);
521 print_string(PRINT_ANY
, "flowlabel", "flowlabel %s ", s2
);
524 if (flags
& IP6_TNL_F_RCV_DSCP_COPY
)
525 print_bool(PRINT_ANY
,
526 "ip6_tnl_f_rcv_dscp_copy",
530 if (tb
[IFLA_GRE_IFLAGS
])
531 iflags
= rta_getattr_u16(tb
[IFLA_GRE_IFLAGS
]);
533 if (tb
[IFLA_GRE_OFLAGS
])
534 oflags
= rta_getattr_u16(tb
[IFLA_GRE_OFLAGS
]);
536 if ((iflags
& GRE_KEY
) && tb
[IFLA_GRE_IKEY
]) {
537 inet_ntop(AF_INET
, RTA_DATA(tb
[IFLA_GRE_IKEY
]), s2
, sizeof(s2
));
538 print_string(PRINT_ANY
, "ikey", "ikey %s ", s2
);
541 if ((oflags
& GRE_KEY
) && tb
[IFLA_GRE_OKEY
]) {
542 inet_ntop(AF_INET
, RTA_DATA(tb
[IFLA_GRE_OKEY
]), s2
, sizeof(s2
));
543 print_string(PRINT_ANY
, "okey", "okey %s ", s2
);
546 if (iflags
& GRE_SEQ
)
547 print_bool(PRINT_ANY
, "iseq", "iseq ", true);
548 if (oflags
& GRE_SEQ
)
549 print_bool(PRINT_ANY
, "oseq", "oseq ", true);
550 if (iflags
& GRE_CSUM
)
551 print_bool(PRINT_ANY
, "icsum", "icsum ", true);
552 if (oflags
& GRE_CSUM
)
553 print_bool(PRINT_ANY
, "ocsum", "ocsum ", true);
555 if (flags
& IP6_TNL_F_USE_ORIG_FWMARK
) {
556 print_bool(PRINT_ANY
,
557 "ip6_tnl_f_use_orig_fwmark",
560 } else if (tb
[IFLA_GRE_FWMARK
]) {
561 __u32 fwmark
= rta_getattr_u32(tb
[IFLA_GRE_FWMARK
]);
564 print_0xhex(PRINT_ANY
,
565 "fwmark", "fwmark 0x%x ", fwmark
);
569 if (tb
[IFLA_GRE_ERSPAN_INDEX
]) {
570 __u32 erspan_idx
= rta_getattr_u32(tb
[IFLA_GRE_ERSPAN_INDEX
]);
571 print_uint(PRINT_ANY
, "erspan_index", "erspan_index %u ", erspan_idx
);
574 if (tb
[IFLA_GRE_ERSPAN_VER
]) {
575 __u8 erspan_ver
= rta_getattr_u8(tb
[IFLA_GRE_ERSPAN_VER
]);
577 print_uint(PRINT_ANY
, "erspan_ver", "erspan_ver %u ", erspan_ver
);
580 if (tb
[IFLA_GRE_ERSPAN_DIR
]) {
581 __u8 erspan_dir
= rta_getattr_u8(tb
[IFLA_GRE_ERSPAN_DIR
]);
584 print_string(PRINT_ANY
, "erspan_dir",
585 "erspan_dir ingress ", NULL
);
587 print_string(PRINT_ANY
, "erspan_dir",
588 "erspan_dir egress ", NULL
);
591 if (tb
[IFLA_GRE_ERSPAN_HWID
]) {
592 __u16 erspan_hwid
= rta_getattr_u16(tb
[IFLA_GRE_ERSPAN_HWID
]);
594 print_hex(PRINT_ANY
, "erspan_hwid", "erspan_hwid 0x%x ", erspan_hwid
);
597 if (tb
[IFLA_GRE_ENCAP_TYPE
] &&
598 rta_getattr_u16(tb
[IFLA_GRE_ENCAP_TYPE
]) != TUNNEL_ENCAP_NONE
) {
599 __u16 type
= rta_getattr_u16(tb
[IFLA_GRE_ENCAP_TYPE
]);
600 __u16 flags
= rta_getattr_u16(tb
[IFLA_GRE_ENCAP_FLAGS
]);
601 __u16 sport
= rta_getattr_u16(tb
[IFLA_GRE_ENCAP_SPORT
]);
602 __u16 dport
= rta_getattr_u16(tb
[IFLA_GRE_ENCAP_DPORT
]);
604 open_json_object("encap");
606 print_string(PRINT_FP
, NULL
, "encap ", NULL
);
608 case TUNNEL_ENCAP_FOU
:
609 print_string(PRINT_ANY
, "type", "%s ", "fou");
611 case TUNNEL_ENCAP_GUE
:
612 print_string(PRINT_ANY
, "type", "%s ", "gue");
615 print_null(PRINT_ANY
, "type", "unknown ", NULL
);
619 if (is_json_context()) {
620 print_uint(PRINT_JSON
,
623 sport
? ntohs(sport
) : 0);
624 print_uint(PRINT_JSON
, "dport", NULL
, ntohs(dport
));
625 print_bool(PRINT_JSON
, "csum", NULL
,
626 flags
& TUNNEL_ENCAP_FLAG_CSUM
);
627 print_bool(PRINT_JSON
, "csum6", NULL
,
628 flags
& TUNNEL_ENCAP_FLAG_CSUM6
);
629 print_bool(PRINT_JSON
, "remcsum", NULL
,
630 flags
& TUNNEL_ENCAP_FLAG_REMCSUM
);
634 fputs("encap-sport auto ", f
);
636 fprintf(f
, "encap-sport %u", ntohs(sport
));
642 IFLA_GRE_ENCAP_FLAGS
,
643 IFLA_GRE_ENCAP_SPORT
,
644 IFLA_GRE_ENCAP_DPORT
);
647 static void gre_print_help(struct link_util
*lu
, int argc
, char **argv
,
653 struct link_util ip6gre_link_util
= {
655 .maxattr
= IFLA_GRE_MAX
,
656 .parse_opt
= gre_parse_opt
,
657 .print_opt
= gre_print_opt
,
658 .print_help
= gre_print_help
,
661 struct link_util ip6gretap_link_util
= {
663 .maxattr
= IFLA_GRE_MAX
,
664 .parse_opt
= gre_parse_opt
,
665 .print_opt
= gre_print_opt
,
666 .print_help
= gre_print_help
,
669 struct link_util ip6erspan_link_util
= {
671 .maxattr
= IFLA_GRE_MAX
,
672 .parse_opt
= gre_parse_opt
,
673 .print_opt
= gre_print_opt
,
674 .print_help
= gre_print_help
,