blob: d00db1f8919dbec834e05e4905b173b65af89f20 [file] [log] [blame]
xeb@mail.ruaf895762013-09-28 11:32:51 +04001/*
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
vadimk561e6502014-09-30 08:17:31 +030033static void print_usage(FILE *f)
34{
35 fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
36 fprintf(f, " type { ip6gre | ip6gretap } [ remote ADDR ] [ local ADDR ]\n");
37 fprintf(f, " [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
38 fprintf(f, " [ hoplimit TTL ] [ encaplimit ELIM ]\n");
39 fprintf(f, " [ tclass TCLASS ] [ flowlabel FLOWLABEL ]\n");
40 fprintf(f, " [ dscp inherit ] [ dev PHYS_DEV ]\n");
Tom Herbert0b2fbb72016-08-04 13:34:56 -070041 fprintf(f, " [ noencap ] [ encap { fou | gue | none } ]\n");
42 fprintf(f, " [ encap-sport PORT ] [ encap-dport PORT ]\n");
43 fprintf(f, " [ [no]encap-csum ] [ [no]encap-csum6 ] [ [no]encap-remcsum ]\n");
vadimk561e6502014-09-30 08:17:31 +030044 fprintf(f, "\n");
45 fprintf(f, "Where: NAME := STRING\n");
46 fprintf(f, " ADDR := IPV6_ADDRESS\n");
47 fprintf(f, " TTL := { 0..255 } (default=%d)\n",
48 DEFAULT_TNL_HOP_LIMIT);
49 fprintf(f, " KEY := { DOTTED_QUAD | NUMBER }\n");
50 fprintf(f, " ELIM := { none | 0..255 }(default=%d)\n",
51 IPV6_DEFAULT_TNL_ENCAP_LIMIT);
52 fprintf(f, " TCLASS := { 0x0..0xff | inherit }\n");
53 fprintf(f, " FLOWLABEL := { 0x0..0xfffff | inherit }\n");
54}
55
xeb@mail.ruaf895762013-09-28 11:32:51 +040056static void usage(void) __attribute__((noreturn));
57static void usage(void)
58{
vadimk561e6502014-09-30 08:17:31 +030059 print_usage(stderr);
xeb@mail.ruaf895762013-09-28 11:32:51 +040060 exit(-1);
61}
62
63static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
64 struct nlmsghdr *n)
65{
Phil Sutterd17b1362016-07-18 16:48:42 +020066 struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
xeb@mail.ruaf895762013-09-28 11:32:51 +040067 struct {
68 struct nlmsghdr n;
69 struct ifinfomsg i;
70 char buf[1024];
Phil Sutterd17b1362016-07-18 16:48:42 +020071 } req = {
72 .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)),
73 .n.nlmsg_flags = NLM_F_REQUEST,
74 .n.nlmsg_type = RTM_GETLINK,
75 .i.ifi_family = preferred_family,
76 .i.ifi_index = ifi->ifi_index,
77 };
xeb@mail.ruaf895762013-09-28 11:32:51 +040078 struct rtattr *tb[IFLA_MAX + 1];
79 struct rtattr *linkinfo[IFLA_INFO_MAX+1];
80 struct rtattr *greinfo[IFLA_GRE_MAX + 1];
81 __u16 iflags = 0;
82 __u16 oflags = 0;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -070083 unsigned int ikey = 0;
84 unsigned int okey = 0;
xeb@mail.ruaf895762013-09-28 11:32:51 +040085 struct in6_addr raddr = IN6ADDR_ANY_INIT;
86 struct in6_addr laddr = IN6ADDR_ANY_INIT;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -070087 unsigned int link = 0;
88 unsigned int flowinfo = 0;
89 unsigned int flags = 0;
xeb@mail.ruaf895762013-09-28 11:32:51 +040090 __u8 hop_limit = DEFAULT_TNL_HOP_LIMIT;
91 __u8 encap_limit = IPV6_DEFAULT_TNL_ENCAP_LIMIT;
Tom Herbert0b2fbb72016-08-04 13:34:56 -070092 __u16 encaptype = 0;
93 __u16 encapflags = TUNNEL_ENCAP_FLAG_CSUM6;
94 __u16 encapsport = 0;
95 __u16 encapdport = 0;
xeb@mail.ruaf895762013-09-28 11:32:51 +040096 int len;
97
98 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
Stephen Hemmingerc079e122015-05-27 12:26:14 -070099 if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0) {
xeb@mail.ruaf895762013-09-28 11:32:51 +0400100get_failed:
101 fprintf(stderr,
102 "Failed to get existing tunnel info.\n");
103 return -1;
104 }
105
106 len = req.n.nlmsg_len;
107 len -= NLMSG_LENGTH(sizeof(*ifi));
108 if (len < 0)
109 goto get_failed;
110
111 parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
112
113 if (!tb[IFLA_LINKINFO])
114 goto get_failed;
115
116 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
117
118 if (!linkinfo[IFLA_INFO_DATA])
119 goto get_failed;
120
121 parse_rtattr_nested(greinfo, IFLA_GRE_MAX,
122 linkinfo[IFLA_INFO_DATA]);
123
124 if (greinfo[IFLA_GRE_IKEY])
125 ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
126
127 if (greinfo[IFLA_GRE_OKEY])
128 okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]);
129
130 if (greinfo[IFLA_GRE_IFLAGS])
131 iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]);
132
133 if (greinfo[IFLA_GRE_OFLAGS])
134 oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
135
136 if (greinfo[IFLA_GRE_LOCAL])
137 memcpy(&laddr, RTA_DATA(greinfo[IFLA_GRE_LOCAL]), sizeof(laddr));
138
139 if (greinfo[IFLA_GRE_REMOTE])
140 memcpy(&raddr, RTA_DATA(greinfo[IFLA_GRE_REMOTE]), sizeof(raddr));
141
142 if (greinfo[IFLA_GRE_TTL])
143 hop_limit = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
144
145 if (greinfo[IFLA_GRE_LINK])
146 link = rta_getattr_u32(greinfo[IFLA_GRE_LINK]);
147
148 if (greinfo[IFLA_GRE_ENCAP_LIMIT])
149 encap_limit = rta_getattr_u8(greinfo[IFLA_GRE_ENCAP_LIMIT]);
150
151 if (greinfo[IFLA_GRE_FLOWINFO])
152 flowinfo = rta_getattr_u32(greinfo[IFLA_GRE_FLOWINFO]);
153
154 if (greinfo[IFLA_GRE_FLAGS])
155 flags = rta_getattr_u32(greinfo[IFLA_GRE_FLAGS]);
Tom Herbert0b2fbb72016-08-04 13:34:56 -0700156
157 if (greinfo[IFLA_GRE_ENCAP_TYPE])
158 encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
159
160 if (greinfo[IFLA_GRE_ENCAP_FLAGS])
161 encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
162
163 if (greinfo[IFLA_GRE_ENCAP_SPORT])
164 encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
165
166 if (greinfo[IFLA_GRE_ENCAP_DPORT])
167 encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
xeb@mail.ruaf895762013-09-28 11:32:51 +0400168 }
169
170 while (argc > 0) {
171 if (!matches(*argv, "key")) {
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700172 unsigned int uval;
xeb@mail.ruaf895762013-09-28 11:32:51 +0400173
174 NEXT_ARG();
175 iflags |= GRE_KEY;
176 oflags |= GRE_KEY;
177 if (strchr(*argv, '.'))
178 uval = get_addr32(*argv);
179 else {
180 if (get_unsigned(&uval, *argv, 0) < 0) {
181 fprintf(stderr,
182 "Invalid value for \"key\"\n");
183 exit(-1);
184 }
185 uval = htonl(uval);
186 }
187
188 ikey = okey = uval;
189 } else if (!matches(*argv, "ikey")) {
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700190 unsigned int uval;
xeb@mail.ruaf895762013-09-28 11:32:51 +0400191
192 NEXT_ARG();
193 iflags |= GRE_KEY;
194 if (strchr(*argv, '.'))
195 uval = get_addr32(*argv);
196 else {
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700197 if (get_unsigned(&uval, *argv, 0) < 0) {
xeb@mail.ruaf895762013-09-28 11:32:51 +0400198 fprintf(stderr, "invalid value of \"ikey\"\n");
199 exit(-1);
200 }
201 uval = htonl(uval);
202 }
203 ikey = uval;
204 } else if (!matches(*argv, "okey")) {
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700205 unsigned int uval;
xeb@mail.ruaf895762013-09-28 11:32:51 +0400206
207 NEXT_ARG();
208 oflags |= GRE_KEY;
209 if (strchr(*argv, '.'))
210 uval = get_addr32(*argv);
211 else {
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700212 if (get_unsigned(&uval, *argv, 0) < 0) {
xeb@mail.ruaf895762013-09-28 11:32:51 +0400213 fprintf(stderr, "invalid value of \"okey\"\n");
214 exit(-1);
215 }
216 uval = htonl(uval);
217 }
218 okey = uval;
219 } else if (!matches(*argv, "seq")) {
220 iflags |= GRE_SEQ;
221 oflags |= GRE_SEQ;
222 } else if (!matches(*argv, "iseq")) {
223 iflags |= GRE_SEQ;
224 } else if (!matches(*argv, "oseq")) {
225 oflags |= GRE_SEQ;
226 } else if (!matches(*argv, "csum")) {
227 iflags |= GRE_CSUM;
228 oflags |= GRE_CSUM;
229 } else if (!matches(*argv, "icsum")) {
230 iflags |= GRE_CSUM;
231 } else if (!matches(*argv, "ocsum")) {
232 oflags |= GRE_CSUM;
233 } else if (!matches(*argv, "remote")) {
234 inet_prefix addr;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700235
xeb@mail.ruaf895762013-09-28 11:32:51 +0400236 NEXT_ARG();
237 get_prefix(&addr, *argv, preferred_family);
238 if (addr.family == AF_UNSPEC)
239 invarg("\"remote\" address family is AF_UNSPEC", *argv);
240 memcpy(&raddr, &addr.data, sizeof(raddr));
241 } else if (!matches(*argv, "local")) {
242 inet_prefix addr;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700243
xeb@mail.ruaf895762013-09-28 11:32:51 +0400244 NEXT_ARG();
245 get_prefix(&addr, *argv, preferred_family);
246 if (addr.family == AF_UNSPEC)
247 invarg("\"local\" address family is AF_UNSPEC", *argv);
248 memcpy(&laddr, &addr.data, sizeof(laddr));
249 } else if (!matches(*argv, "dev")) {
250 NEXT_ARG();
251 link = if_nametoindex(*argv);
Cong Wang0cb6bb52014-06-03 16:06:45 -0700252 if (link == 0) {
253 fprintf(stderr, "Cannot find device \"%s\"\n",
254 *argv);
xeb@mail.ruaf895762013-09-28 11:32:51 +0400255 exit(-1);
Cong Wang0cb6bb52014-06-03 16:06:45 -0700256 }
xeb@mail.ruaf895762013-09-28 11:32:51 +0400257 } else if (!matches(*argv, "ttl") ||
258 !matches(*argv, "hoplimit")) {
259 __u8 uval;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700260
xeb@mail.ruaf895762013-09-28 11:32:51 +0400261 NEXT_ARG();
262 if (get_u8(&uval, *argv, 0))
263 invarg("invalid TTL", *argv);
264 hop_limit = uval;
265 } else if (!matches(*argv, "tos") ||
266 !matches(*argv, "tclass") ||
267 !matches(*argv, "dsfield")) {
268 __u8 uval;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700269
xeb@mail.ruaf895762013-09-28 11:32:51 +0400270 NEXT_ARG();
271 if (strcmp(*argv, "inherit") == 0)
272 flags |= IP6_TNL_F_USE_ORIG_TCLASS;
273 else {
274 if (get_u8(&uval, *argv, 16))
275 invarg("invalid TClass", *argv);
276 flowinfo |= htonl((__u32)uval << 20) & IP6_FLOWINFO_TCLASS;
277 flags &= ~IP6_TNL_F_USE_ORIG_TCLASS;
278 }
279 } else if (strcmp(*argv, "flowlabel") == 0 ||
280 strcmp(*argv, "fl") == 0) {
281 __u32 uval;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700282
xeb@mail.ruaf895762013-09-28 11:32:51 +0400283 NEXT_ARG();
284 if (strcmp(*argv, "inherit") == 0)
285 flags |= IP6_TNL_F_USE_ORIG_FLOWLABEL;
286 else {
287 if (get_u32(&uval, *argv, 16))
288 invarg("invalid Flowlabel", *argv);
289 if (uval > 0xFFFFF)
290 invarg("invalid Flowlabel", *argv);
291 flowinfo |= htonl(uval) & IP6_FLOWINFO_FLOWLABEL;
292 flags &= ~IP6_TNL_F_USE_ORIG_FLOWLABEL;
293 }
294 } else if (strcmp(*argv, "dscp") == 0) {
295 NEXT_ARG();
296 if (strcmp(*argv, "inherit") != 0)
297 invarg("not inherit", *argv);
298 flags |= IP6_TNL_F_RCV_DSCP_COPY;
Tom Herbert0b2fbb72016-08-04 13:34:56 -0700299 } else if (strcmp(*argv, "noencap") == 0) {
300 encaptype = TUNNEL_ENCAP_NONE;
301 } else if (strcmp(*argv, "encap") == 0) {
302 NEXT_ARG();
303 if (strcmp(*argv, "fou") == 0)
304 encaptype = TUNNEL_ENCAP_FOU;
305 else if (strcmp(*argv, "gue") == 0)
306 encaptype = TUNNEL_ENCAP_GUE;
307 else if (strcmp(*argv, "none") == 0)
308 encaptype = TUNNEL_ENCAP_NONE;
309 else
310 invarg("Invalid encap type.", *argv);
311 } else if (strcmp(*argv, "encap-sport") == 0) {
312 NEXT_ARG();
313 if (strcmp(*argv, "auto") == 0)
314 encapsport = 0;
315 else if (get_u16(&encapsport, *argv, 0))
316 invarg("Invalid source port.", *argv);
317 } else if (strcmp(*argv, "encap-dport") == 0) {
318 NEXT_ARG();
319 if (get_u16(&encapdport, *argv, 0))
320 invarg("Invalid destination port.", *argv);
321 } else if (strcmp(*argv, "encap-csum") == 0) {
322 encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
323 } else if (strcmp(*argv, "noencap-csum") == 0) {
324 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
325 } else if (strcmp(*argv, "encap-udp6-csum") == 0) {
326 encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
327 } else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
328 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6;
329 } else if (strcmp(*argv, "encap-remcsum") == 0) {
330 encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
331 } else if (strcmp(*argv, "noencap-remcsum") == 0) {
332 encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM;
xeb@mail.ruaf895762013-09-28 11:32:51 +0400333 } else
334 usage();
335 argc--; argv++;
336 }
337
338 addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
339 addattr32(n, 1024, IFLA_GRE_OKEY, okey);
340 addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
341 addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
342 addattr_l(n, 1024, IFLA_GRE_LOCAL, &laddr, sizeof(laddr));
343 addattr_l(n, 1024, IFLA_GRE_REMOTE, &raddr, sizeof(raddr));
344 if (link)
345 addattr32(n, 1024, IFLA_GRE_LINK, link);
346 addattr_l(n, 1024, IFLA_GRE_TTL, &hop_limit, 1);
347 addattr_l(n, 1024, IFLA_GRE_ENCAP_LIMIT, &encap_limit, 1);
348 addattr_l(n, 1024, IFLA_GRE_FLOWINFO, &flowinfo, 4);
349 addattr_l(n, 1024, IFLA_GRE_FLAGS, &flowinfo, 4);
350
Tom Herbert0b2fbb72016-08-04 13:34:56 -0700351 addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
352 addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
353 addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
354 addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
355
xeb@mail.ruaf895762013-09-28 11:32:51 +0400356 return 0;
357}
358
359static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
360{
xeb@mail.ruaf895762013-09-28 11:32:51 +0400361 char s2[64];
362 const char *local = "any";
363 const char *remote = "any";
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700364 unsigned int iflags = 0;
365 unsigned int oflags = 0;
366 unsigned int flags = 0;
367 unsigned int flowinfo = 0;
xeb@mail.ruaf895762013-09-28 11:32:51 +0400368 struct in6_addr in6_addr_any = IN6ADDR_ANY_INIT;
369
370 if (!tb)
371 return;
372
373 if (tb[IFLA_GRE_FLAGS])
374 flags = rta_getattr_u32(tb[IFLA_GRE_FLAGS]);
375
376 if (tb[IFLA_GRE_FLOWINFO])
377 flags = rta_getattr_u32(tb[IFLA_GRE_FLOWINFO]);
378
379 if (tb[IFLA_GRE_REMOTE]) {
380 struct in6_addr addr;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700381
xeb@mail.ruaf895762013-09-28 11:32:51 +0400382 memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
383
384 if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
Phil Suttera418e452016-03-22 19:35:15 +0100385 remote = format_host(AF_INET6, sizeof(addr), &addr);
xeb@mail.ruaf895762013-09-28 11:32:51 +0400386 }
387
388 fprintf(f, "remote %s ", remote);
389
390 if (tb[IFLA_GRE_LOCAL]) {
391 struct in6_addr addr;
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700392
xeb@mail.ruaf895762013-09-28 11:32:51 +0400393 memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
394
395 if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
Phil Suttera418e452016-03-22 19:35:15 +0100396 local = format_host(AF_INET6, sizeof(addr), &addr);
xeb@mail.ruaf895762013-09-28 11:32:51 +0400397 }
398
399 fprintf(f, "local %s ", local);
400
401 if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
Stephen Hemminger56f5daa2016-03-21 11:52:19 -0700402 unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
xeb@mail.ruaf895762013-09-28 11:32:51 +0400403 const char *n = if_indextoname(link, s2);
404
405 if (n)
406 fprintf(f, "dev %s ", n);
407 else
408 fprintf(f, "dev %u ", link);
409 }
410
411 if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
412 fprintf(f, "hoplimit %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
413
414 if (flags & IP6_TNL_F_IGN_ENCAP_LIMIT)
415 fprintf(f, "encaplimit none ");
416 else if (tb[IFLA_GRE_ENCAP_LIMIT]) {
417 int encap_limit = rta_getattr_u8(tb[IFLA_GRE_ENCAP_LIMIT]);
418
419 fprintf(f, "encaplimit %d ", encap_limit);
420 }
421
422 if (flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
423 fprintf(f, "flowlabel inherit ");
424 else
425 fprintf(f, "flowlabel 0x%05x ", ntohl(flowinfo & IP6_FLOWINFO_FLOWLABEL));
426
427 if (flags & IP6_TNL_F_RCV_DSCP_COPY)
428 fprintf(f, "dscp inherit ");
429
430 if (tb[IFLA_GRE_IFLAGS])
431 iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
432
433 if (tb[IFLA_GRE_OFLAGS])
434 oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]);
435
436 if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
437 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
438 fprintf(f, "ikey %s ", s2);
439 }
440
441 if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
442 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
443 fprintf(f, "okey %s ", s2);
444 }
445
446 if (iflags & GRE_SEQ)
447 fputs("iseq ", f);
448 if (oflags & GRE_SEQ)
449 fputs("oseq ", f);
450 if (iflags & GRE_CSUM)
451 fputs("icsum ", f);
452 if (oflags & GRE_CSUM)
453 fputs("ocsum ", f);
Tom Herbert0b2fbb72016-08-04 13:34:56 -0700454
455 if (tb[IFLA_GRE_ENCAP_TYPE] &&
456 rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
457 __u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
458 __u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
459 __u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
460 __u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
461
462 fputs("encap ", f);
463 switch (type) {
464 case TUNNEL_ENCAP_FOU:
465 fputs("fou ", f);
466 break;
467 case TUNNEL_ENCAP_GUE:
468 fputs("gue ", f);
469 break;
470 default:
471 fputs("unknown ", f);
472 break;
473 }
474
475 if (sport == 0)
476 fputs("encap-sport auto ", f);
477 else
478 fprintf(f, "encap-sport %u", ntohs(sport));
479
480 fprintf(f, "encap-dport %u ", ntohs(dport));
481
482 if (flags & TUNNEL_ENCAP_FLAG_CSUM)
483 fputs("encap-csum ", f);
484 else
485 fputs("noencap-csum ", f);
486
487 if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
488 fputs("encap-csum6 ", f);
489 else
490 fputs("noencap-csum6 ", f);
491
492 if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
493 fputs("encap-remcsum ", f);
494 else
495 fputs("noencap-remcsum ", f);
496 }
xeb@mail.ruaf895762013-09-28 11:32:51 +0400497}
498
vadimk561e6502014-09-30 08:17:31 +0300499static void gre_print_help(struct link_util *lu, int argc, char **argv,
500 FILE *f)
501{
502 print_usage(f);
503}
504
xeb@mail.ruaf895762013-09-28 11:32:51 +0400505struct link_util ip6gre_link_util = {
506 .id = "ip6gre",
507 .maxattr = IFLA_GRE_MAX,
508 .parse_opt = gre_parse_opt,
509 .print_opt = gre_print_opt,
vadimk561e6502014-09-30 08:17:31 +0300510 .print_help = gre_print_help,
xeb@mail.ruaf895762013-09-28 11:32:51 +0400511};
512
513struct link_util ip6gretap_link_util = {
514 .id = "ip6gretap",
515 .maxattr = IFLA_GRE_MAX,
516 .parse_opt = gre_parse_opt,
517 .print_opt = gre_print_opt,
vadimk561e6502014-09-30 08:17:31 +0300518 .print_help = gre_print_help,
xeb@mail.ruaf895762013-09-28 11:32:51 +0400519};