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