blob: 193726109ee6b0c74cf9a112c1b1940a43fcb123 [file] [log] [blame]
Herbert Xu237d9e82008-10-09 15:08:24 +08001/*
2 * link_gre.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: Herbert Xu <herbert@gondor.apana.org.au>
10 *
11 */
12
13#include <string.h>
14#include <net/if.h>
Herbert Xu237d9e82008-10-09 15:08:24 +080015#include <sys/types.h>
16#include <sys/socket.h>
17#include <arpa/inet.h>
18
Stephen Hemminger1957a322009-03-24 15:40:54 -070019#include <linux/ip.h>
20#include <linux/if_tunnel.h>
Herbert Xu237d9e82008-10-09 15:08:24 +080021#include "rt_names.h"
22#include "utils.h"
23#include "ip_common.h"
24#include "tunnel.h"
25
vadimk561e6502014-09-30 08:17:31 +030026static void print_usage(FILE *f)
27{
28 fprintf(f, "Usage: ip link { add | set | change | replace | del } NAME\n");
29 fprintf(f, " type { gre | gretap } [ remote ADDR ] [ local ADDR ]\n");
30 fprintf(f, " [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
31 fprintf(f, " [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n");
Tom Herbert80c24b02014-11-05 10:06:26 -080032 fprintf(f, " [ noencap ] [ encap { fou | gue | none } ]\n");
33 fprintf(f, " [ encap-sport PORT ] [ encap-dport PORT ]\n");
Tom Herbert858dbb22015-01-29 08:51:58 -080034 fprintf(f, " [ [no]encap-csum ] [ [no]encap-csum6 ] [ [no]encap-remcsum ]\n");
vadimk561e6502014-09-30 08:17:31 +030035 fprintf(f, "\n");
36 fprintf(f, "Where: NAME := STRING\n");
37 fprintf(f, " ADDR := { IP_ADDRESS | any }\n");
38 fprintf(f, " TOS := { NUMBER | inherit }\n");
39 fprintf(f, " TTL := { 1..255 | inherit }\n");
40 fprintf(f, " KEY := { DOTTED_QUAD | NUMBER }\n");
41}
42
Herbert Xu237d9e82008-10-09 15:08:24 +080043static void usage(void) __attribute__((noreturn));
44static void usage(void)
45{
vadimk561e6502014-09-30 08:17:31 +030046 print_usage(stderr);
Herbert Xu237d9e82008-10-09 15:08:24 +080047 exit(-1);
48}
49
50static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
51 struct nlmsghdr *n)
52{
Herbert Xu72c771b2009-01-06 18:27:52 -080053 struct {
54 struct nlmsghdr n;
55 struct ifinfomsg i;
Jetchko Jekovbde5baa2015-05-21 16:32:24 +020056 char buf[16384];
Herbert Xu72c771b2009-01-06 18:27:52 -080057 } req;
58 struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1);
59 struct rtattr *tb[IFLA_MAX + 1];
60 struct rtattr *linkinfo[IFLA_INFO_MAX+1];
61 struct rtattr *greinfo[IFLA_GRE_MAX + 1];
Herbert Xu237d9e82008-10-09 15:08:24 +080062 __u16 iflags = 0;
63 __u16 oflags = 0;
64 unsigned ikey = 0;
65 unsigned okey = 0;
66 unsigned saddr = 0;
67 unsigned daddr = 0;
Herbert Xu72c771b2009-01-06 18:27:52 -080068 unsigned link = 0;
69 __u8 pmtudisc = 1;
70 __u8 ttl = 0;
71 __u8 tos = 0;
72 int len;
Tom Herbert80c24b02014-11-05 10:06:26 -080073 __u16 encaptype = 0;
74 __u16 encapflags = 0;
75 __u16 encapsport = 0;
76 __u16 encapdport = 0;
Herbert Xu72c771b2009-01-06 18:27:52 -080077
78 if (!(n->nlmsg_flags & NLM_F_CREATE)) {
79 memset(&req, 0, sizeof(req));
80
81 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi));
82 req.n.nlmsg_flags = NLM_F_REQUEST;
83 req.n.nlmsg_type = RTM_GETLINK;
84 req.i.ifi_family = preferred_family;
85 req.i.ifi_index = ifi->ifi_index;
86
Stephen Hemmingercd70f3f2011-12-28 10:37:12 -080087 if (rtnl_talk(&rth, &req.n, 0, 0, &req.n) < 0) {
Herbert Xu72c771b2009-01-06 18:27:52 -080088get_failed:
89 fprintf(stderr,
90 "Failed to get existing tunnel info.\n");
91 return -1;
92 }
93
94 len = req.n.nlmsg_len;
95 len -= NLMSG_LENGTH(sizeof(*ifi));
96 if (len < 0)
97 goto get_failed;
98
99 parse_rtattr(tb, IFLA_MAX, IFLA_RTA(&req.i), len);
100
101 if (!tb[IFLA_LINKINFO])
102 goto get_failed;
103
104 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
105
106 if (!linkinfo[IFLA_INFO_DATA])
107 goto get_failed;
108
109 parse_rtattr_nested(greinfo, IFLA_GRE_MAX,
110 linkinfo[IFLA_INFO_DATA]);
111
112 if (greinfo[IFLA_GRE_IKEY])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700113 ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800114
115 if (greinfo[IFLA_GRE_OKEY])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700116 okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800117
118 if (greinfo[IFLA_GRE_IFLAGS])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700119 iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800120
121 if (greinfo[IFLA_GRE_OFLAGS])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700122 oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800123
124 if (greinfo[IFLA_GRE_LOCAL])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700125 saddr = rta_getattr_u32(greinfo[IFLA_GRE_LOCAL]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800126
127 if (greinfo[IFLA_GRE_REMOTE])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700128 daddr = rta_getattr_u32(greinfo[IFLA_GRE_REMOTE]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800129
130 if (greinfo[IFLA_GRE_PMTUDISC])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700131 pmtudisc = rta_getattr_u8(
Herbert Xu72c771b2009-01-06 18:27:52 -0800132 greinfo[IFLA_GRE_PMTUDISC]);
133
134 if (greinfo[IFLA_GRE_TTL])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700135 ttl = rta_getattr_u8(greinfo[IFLA_GRE_TTL]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800136
137 if (greinfo[IFLA_GRE_TOS])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700138 tos = rta_getattr_u8(greinfo[IFLA_GRE_TOS]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800139
140 if (greinfo[IFLA_GRE_LINK])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700141 link = rta_getattr_u8(greinfo[IFLA_GRE_LINK]);
Tom Herbert80c24b02014-11-05 10:06:26 -0800142
143 if (greinfo[IFLA_GRE_ENCAP_TYPE])
144 encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]);
145 if (greinfo[IFLA_GRE_ENCAP_FLAGS])
146 encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]);
147 if (greinfo[IFLA_GRE_ENCAP_SPORT])
148 encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]);
149 if (greinfo[IFLA_GRE_ENCAP_DPORT])
150 encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]);
Herbert Xu72c771b2009-01-06 18:27:52 -0800151 }
Herbert Xu237d9e82008-10-09 15:08:24 +0800152
153 while (argc > 0) {
154 if (!matches(*argv, "key")) {
155 unsigned uval;
156
157 NEXT_ARG();
158 iflags |= GRE_KEY;
159 oflags |= GRE_KEY;
160 if (strchr(*argv, '.'))
161 uval = get_addr32(*argv);
162 else {
163 if (get_unsigned(&uval, *argv, 0) < 0) {
164 fprintf(stderr,
Kees van Reeuwijk14645ec2013-02-08 03:32:36 +0000165 "Invalid value for \"key\": \"%s\"; it should be an unsigned integer\n", *argv);
Herbert Xu237d9e82008-10-09 15:08:24 +0800166 exit(-1);
167 }
168 uval = htonl(uval);
169 }
170
171 ikey = okey = uval;
172 } else if (!matches(*argv, "ikey")) {
173 unsigned uval;
174
175 NEXT_ARG();
176 iflags |= GRE_KEY;
177 if (strchr(*argv, '.'))
178 uval = get_addr32(*argv);
179 else {
180 if (get_unsigned(&uval, *argv, 0)<0) {
Kees van Reeuwijk14645ec2013-02-08 03:32:36 +0000181 fprintf(stderr, "invalid value for \"ikey\": \"%s\"; it should be an unsigned integer\n", *argv);
Herbert Xu237d9e82008-10-09 15:08:24 +0800182 exit(-1);
183 }
184 uval = htonl(uval);
185 }
186 ikey = uval;
187 } else if (!matches(*argv, "okey")) {
188 unsigned uval;
189
190 NEXT_ARG();
191 oflags |= GRE_KEY;
192 if (strchr(*argv, '.'))
193 uval = get_addr32(*argv);
194 else {
195 if (get_unsigned(&uval, *argv, 0)<0) {
Kees van Reeuwijk14645ec2013-02-08 03:32:36 +0000196 fprintf(stderr, "invalid value for \"okey\": \"%s\"; it should be an unsigned integer\n", *argv);
Herbert Xu237d9e82008-10-09 15:08:24 +0800197 exit(-1);
198 }
199 uval = htonl(uval);
200 }
201 okey = uval;
202 } else if (!matches(*argv, "seq")) {
203 iflags |= GRE_SEQ;
204 oflags |= GRE_SEQ;
205 } else if (!matches(*argv, "iseq")) {
206 iflags |= GRE_SEQ;
207 } else if (!matches(*argv, "oseq")) {
208 oflags |= GRE_SEQ;
209 } else if (!matches(*argv, "csum")) {
210 iflags |= GRE_CSUM;
211 oflags |= GRE_CSUM;
212 } else if (!matches(*argv, "icsum")) {
213 iflags |= GRE_CSUM;
214 } else if (!matches(*argv, "ocsum")) {
215 oflags |= GRE_CSUM;
216 } else if (!matches(*argv, "nopmtudisc")) {
Herbert Xu72c771b2009-01-06 18:27:52 -0800217 pmtudisc = 0;
Herbert Xu237d9e82008-10-09 15:08:24 +0800218 } else if (!matches(*argv, "pmtudisc")) {
Herbert Xu72c771b2009-01-06 18:27:52 -0800219 pmtudisc = 1;
Herbert Xu237d9e82008-10-09 15:08:24 +0800220 } else if (!matches(*argv, "remote")) {
221 NEXT_ARG();
222 if (strcmp(*argv, "any"))
223 daddr = get_addr32(*argv);
224 } else if (!matches(*argv, "local")) {
225 NEXT_ARG();
226 if (strcmp(*argv, "any"))
227 saddr = get_addr32(*argv);
228 } else if (!matches(*argv, "dev")) {
Herbert Xu237d9e82008-10-09 15:08:24 +0800229 NEXT_ARG();
Stephen Hemmingerea71bea2010-11-28 10:35:28 -0800230 link = if_nametoindex(*argv);
Cong Wang0cb6bb52014-06-03 16:06:45 -0700231 if (link == 0) {
232 fprintf(stderr, "Cannot find device \"%s\"\n",
233 *argv);
Herbert Xu237d9e82008-10-09 15:08:24 +0800234 exit(-1);
Cong Wang0cb6bb52014-06-03 16:06:45 -0700235 }
Herbert Xu237d9e82008-10-09 15:08:24 +0800236 } else if (!matches(*argv, "ttl") ||
237 !matches(*argv, "hoplimit")) {
238 unsigned uval;
Herbert Xu237d9e82008-10-09 15:08:24 +0800239
240 NEXT_ARG();
241 if (strcmp(*argv, "inherit") != 0) {
242 if (get_unsigned(&uval, *argv, 0))
243 invarg("invalid TTL\n", *argv);
244 if (uval > 255)
245 invarg("TTL must be <= 255\n", *argv);
246 ttl = uval;
Herbert Xu237d9e82008-10-09 15:08:24 +0800247 }
248 } else if (!matches(*argv, "tos") ||
249 !matches(*argv, "tclass") ||
250 !matches(*argv, "dsfield")) {
251 __u32 uval;
Herbert Xu237d9e82008-10-09 15:08:24 +0800252
253 NEXT_ARG();
254 if (strcmp(*argv, "inherit") != 0) {
255 if (rtnl_dsfield_a2n(&uval, *argv))
256 invarg("bad TOS value", *argv);
257 tos = uval;
258 } else
259 tos = 1;
Tom Herbert80c24b02014-11-05 10:06:26 -0800260 } else if (strcmp(*argv, "noencap") == 0) {
261 encaptype = TUNNEL_ENCAP_NONE;
262 } else if (strcmp(*argv, "encap") == 0) {
263 NEXT_ARG();
264 if (strcmp(*argv, "fou") == 0)
265 encaptype = TUNNEL_ENCAP_FOU;
266 else if (strcmp(*argv, "gue") == 0)
267 encaptype = TUNNEL_ENCAP_GUE;
268 else if (strcmp(*argv, "none") == 0)
269 encaptype = TUNNEL_ENCAP_NONE;
270 else
271 invarg("Invalid encap type.", *argv);
272 } else if (strcmp(*argv, "encap-sport") == 0) {
273 NEXT_ARG();
274 if (strcmp(*argv, "auto") == 0)
275 encapsport = 0;
276 else if (get_u16(&encapsport, *argv, 0))
277 invarg("Invalid source port.", *argv);
278 } else if (strcmp(*argv, "encap-dport") == 0) {
279 NEXT_ARG();
280 if (get_u16(&encapdport, *argv, 0))
281 invarg("Invalid destination port.", *argv);
282 } else if (strcmp(*argv, "encap-csum") == 0) {
283 encapflags |= TUNNEL_ENCAP_FLAG_CSUM;
284 } else if (strcmp(*argv, "noencap-csum") == 0) {
285 encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM;
286 } else if (strcmp(*argv, "encap-udp6-csum") == 0) {
287 encapflags |= TUNNEL_ENCAP_FLAG_CSUM6;
288 } else if (strcmp(*argv, "noencap-udp6-csum") == 0) {
289 encapflags |= ~TUNNEL_ENCAP_FLAG_CSUM6;
Tom Herbert858dbb22015-01-29 08:51:58 -0800290 } else if (strcmp(*argv, "encap-remcsum") == 0) {
291 encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM;
292 } else if (strcmp(*argv, "noencap-remcsum") == 0) {
293 encapflags |= ~TUNNEL_ENCAP_FLAG_REMCSUM;
Stephen Hemminger06125192014-02-17 10:55:31 -0800294 } else
Herbert Xu237d9e82008-10-09 15:08:24 +0800295 usage();
296 argc--; argv++;
297 }
298
299 if (!ikey && IN_MULTICAST(ntohl(daddr))) {
300 ikey = daddr;
301 iflags |= GRE_KEY;
302 }
303 if (!okey && IN_MULTICAST(ntohl(daddr))) {
304 okey = daddr;
305 oflags |= GRE_KEY;
306 }
307 if (IN_MULTICAST(ntohl(daddr)) && !saddr) {
Kees van Reeuwijk14645ec2013-02-08 03:32:36 +0000308 fprintf(stderr, "A broadcast tunnel requires a source address.\n");
Herbert Xu237d9e82008-10-09 15:08:24 +0800309 return -1;
310 }
311
312 addattr32(n, 1024, IFLA_GRE_IKEY, ikey);
313 addattr32(n, 1024, IFLA_GRE_OKEY, okey);
314 addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2);
315 addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2);
316 addattr_l(n, 1024, IFLA_GRE_LOCAL, &saddr, 4);
317 addattr_l(n, 1024, IFLA_GRE_REMOTE, &daddr, 4);
Herbert Xu72c771b2009-01-06 18:27:52 -0800318 addattr_l(n, 1024, IFLA_GRE_PMTUDISC, &pmtudisc, 1);
319 if (link)
320 addattr32(n, 1024, IFLA_GRE_LINK, link);
321 addattr_l(n, 1024, IFLA_GRE_TTL, &ttl, 1);
322 addattr_l(n, 1024, IFLA_GRE_TOS, &tos, 1);
Herbert Xu237d9e82008-10-09 15:08:24 +0800323
Tom Herbert80c24b02014-11-05 10:06:26 -0800324 addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype);
325 addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags);
326 addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport));
327 addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
328
Herbert Xu237d9e82008-10-09 15:08:24 +0800329 return 0;
330}
331
332static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
333{
334 char s1[1024];
335 char s2[64];
336 const char *local = "any";
337 const char *remote = "any";
338 unsigned iflags = 0;
339 unsigned oflags = 0;
340
341 if (!tb)
342 return;
343
344 if (tb[IFLA_GRE_REMOTE]) {
Stephen Hemmingerff247462012-04-10 08:47:55 -0700345 unsigned addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
Herbert Xu237d9e82008-10-09 15:08:24 +0800346
347 if (addr)
348 remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
349 }
350
351 fprintf(f, "remote %s ", remote);
352
353 if (tb[IFLA_GRE_LOCAL]) {
Stephen Hemmingerff247462012-04-10 08:47:55 -0700354 unsigned addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
Herbert Xu237d9e82008-10-09 15:08:24 +0800355
356 if (addr)
357 local = format_host(AF_INET, 4, &addr, s1, sizeof(s1));
358 }
359
360 fprintf(f, "local %s ", local);
361
Stephen Hemmingerff247462012-04-10 08:47:55 -0700362 if (tb[IFLA_GRE_LINK] && rta_getattr_u32(tb[IFLA_GRE_LINK])) {
363 unsigned link = rta_getattr_u32(tb[IFLA_GRE_LINK]);
Stephen Hemmingerea71bea2010-11-28 10:35:28 -0800364 const char *n = if_indextoname(link, s2);
Herbert Xu237d9e82008-10-09 15:08:24 +0800365
366 if (n)
367 fprintf(f, "dev %s ", n);
368 else
369 fprintf(f, "dev %u ", link);
370 }
371
Stephen Hemmingerff247462012-04-10 08:47:55 -0700372 if (tb[IFLA_GRE_TTL] && rta_getattr_u8(tb[IFLA_GRE_TTL]))
373 fprintf(f, "ttl %d ", rta_getattr_u8(tb[IFLA_GRE_TTL]));
Herbert Xu237d9e82008-10-09 15:08:24 +0800374 else
375 fprintf(f, "ttl inherit ");
376
Stephen Hemmingerff247462012-04-10 08:47:55 -0700377 if (tb[IFLA_GRE_TOS] && rta_getattr_u8(tb[IFLA_GRE_TOS])) {
378 int tos = rta_getattr_u8(tb[IFLA_GRE_TOS]);
Herbert Xu237d9e82008-10-09 15:08:24 +0800379
380 fputs("tos ", f);
381 if (tos == 1)
382 fputs("inherit ", f);
383 else
384 fprintf(f, "0x%x ", tos);
385 }
386
387 if (tb[IFLA_GRE_PMTUDISC] &&
Stephen Hemmingerff247462012-04-10 08:47:55 -0700388 !rta_getattr_u8(tb[IFLA_GRE_PMTUDISC]))
Herbert Xu237d9e82008-10-09 15:08:24 +0800389 fputs("nopmtudisc ", f);
390
391 if (tb[IFLA_GRE_IFLAGS])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700392 iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]);
Herbert Xu237d9e82008-10-09 15:08:24 +0800393
394 if (tb[IFLA_GRE_OFLAGS])
Stephen Hemmingerff247462012-04-10 08:47:55 -0700395 oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]);
Herbert Xu237d9e82008-10-09 15:08:24 +0800396
Stephen Hemminger71816552012-03-19 17:18:49 -0700397 if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) {
Herbert Xu237d9e82008-10-09 15:08:24 +0800398 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2));
399 fprintf(f, "ikey %s ", s2);
400 }
401
Stephen Hemminger71816552012-03-19 17:18:49 -0700402 if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) {
Herbert Xu237d9e82008-10-09 15:08:24 +0800403 inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2));
Stephen Hemminger71816552012-03-19 17:18:49 -0700404 fprintf(f, "okey %s ", s2);
Herbert Xu237d9e82008-10-09 15:08:24 +0800405 }
406
407 if (iflags & GRE_SEQ)
408 fputs("iseq ", f);
409 if (oflags & GRE_SEQ)
410 fputs("oseq ", f);
411 if (iflags & GRE_CSUM)
412 fputs("icsum ", f);
413 if (oflags & GRE_CSUM)
414 fputs("ocsum ", f);
Tom Herbert80c24b02014-11-05 10:06:26 -0800415
416 if (tb[IFLA_GRE_ENCAP_TYPE] &&
417 *(__u16 *)RTA_DATA(tb[IFLA_GRE_ENCAP_TYPE]) != TUNNEL_ENCAP_NONE) {
418 __u16 type = rta_getattr_u16(tb[IFLA_GRE_ENCAP_TYPE]);
419 __u16 flags = rta_getattr_u16(tb[IFLA_GRE_ENCAP_FLAGS]);
420 __u16 sport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_SPORT]);
421 __u16 dport = rta_getattr_u16(tb[IFLA_GRE_ENCAP_DPORT]);
422
423 fputs("encap ", f);
424 switch (type) {
425 case TUNNEL_ENCAP_FOU:
426 fputs("fou ", f);
427 break;
428 case TUNNEL_ENCAP_GUE:
429 fputs("gue ", f);
430 break;
431 default:
432 fputs("unknown ", f);
433 break;
434 }
435
436 if (sport == 0)
437 fputs("encap-sport auto ", f);
438 else
439 fprintf(f, "encap-sport %u", ntohs(sport));
440
441 fprintf(f, "encap-dport %u ", ntohs(dport));
442
443 if (flags & TUNNEL_ENCAP_FLAG_CSUM)
444 fputs("encap-csum ", f);
445 else
446 fputs("noencap-csum ", f);
447
448 if (flags & TUNNEL_ENCAP_FLAG_CSUM6)
449 fputs("encap-csum6 ", f);
450 else
451 fputs("noencap-csum6 ", f);
Tom Herbert858dbb22015-01-29 08:51:58 -0800452
453 if (flags & TUNNEL_ENCAP_FLAG_REMCSUM)
454 fputs("encap-remcsum ", f);
455 else
456 fputs("noencap-remcsum ", f);
Tom Herbert80c24b02014-11-05 10:06:26 -0800457 }
Herbert Xu237d9e82008-10-09 15:08:24 +0800458}
459
vadimk561e6502014-09-30 08:17:31 +0300460static void gre_print_help(struct link_util *lu, int argc, char **argv,
461 FILE *f)
462{
463 print_usage(f);
464}
465
Herbert Xu237d9e82008-10-09 15:08:24 +0800466struct link_util gre_link_util = {
467 .id = "gre",
468 .maxattr = IFLA_GRE_MAX,
469 .parse_opt = gre_parse_opt,
470 .print_opt = gre_print_opt,
vadimk561e6502014-09-30 08:17:31 +0300471 .print_help = gre_print_help,
Herbert Xu237d9e82008-10-09 15:08:24 +0800472};
473
474struct link_util gretap_link_util = {
475 .id = "gretap",
476 .maxattr = IFLA_GRE_MAX,
477 .parse_opt = gre_parse_opt,
478 .print_opt = gre_print_opt,
vadimk561e6502014-09-30 08:17:31 +0300479 .print_help = gre_print_help,
Herbert Xu237d9e82008-10-09 15:08:24 +0800480};