]>
Commit | Line | Data |
---|---|---|
237d9e82 HX |
1 | /* |
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> | |
237d9e82 HX |
15 | #include <sys/types.h> |
16 | #include <sys/socket.h> | |
17 | #include <arpa/inet.h> | |
18 | ||
1957a322 SH |
19 | #include <linux/ip.h> |
20 | #include <linux/if_tunnel.h> | |
237d9e82 HX |
21 | #include "rt_names.h" |
22 | #include "utils.h" | |
23 | #include "ip_common.h" | |
24 | #include "tunnel.h" | |
25 | ||
561e650e | 26 | static void print_usage(FILE *f) |
27 | { | |
8b471354 | 28 | fprintf(f, |
9a1381d5 | 29 | "Usage: ... { gre | gretap | erspan } [ remote ADDR ]\n" |
8b471354 PS |
30 | " [ local ADDR ]\n" |
31 | " [ [i|o]seq ]\n" | |
32 | " [ [i|o]key KEY ]\n" | |
33 | " [ [i|o]csum ]\n" | |
34 | " [ ttl TTL ]\n" | |
35 | " [ tos TOS ]\n" | |
36 | " [ [no]pmtudisc ]\n" | |
adbb2965 | 37 | " [ [no]ignore-df ]\n" |
8b471354 PS |
38 | " [ dev PHYS_DEV ]\n" |
39 | " [ noencap ]\n" | |
40 | " [ encap { fou | gue | none } ]\n" | |
41 | " [ encap-sport PORT ]\n" | |
42 | " [ encap-dport PORT ]\n" | |
43 | " [ [no]encap-csum ]\n" | |
44 | " [ [no]encap-csum6 ]\n" | |
45 | " [ [no]encap-remcsum ]\n" | |
b760a882 | 46 | " [ external ]\n" |
ad4b1425 | 47 | " [ fwmark MARK ]\n" |
9a1381d5 | 48 | " [ erspan IDX ]\n" |
8b471354 PS |
49 | "\n" |
50 | "Where: ADDR := { IP_ADDRESS | any }\n" | |
51 | " TOS := { NUMBER | inherit }\n" | |
52 | " TTL := { 1..255 | inherit }\n" | |
53 | " KEY := { DOTTED_QUAD | NUMBER }\n" | |
ad4b1425 | 54 | " MARK := { 0x0..0xffffffff }\n" |
8b471354 | 55 | ); |
561e650e | 56 | } |
57 | ||
237d9e82 HX |
58 | static void usage(void) __attribute__((noreturn)); |
59 | static void usage(void) | |
60 | { | |
561e650e | 61 | print_usage(stderr); |
237d9e82 HX |
62 | exit(-1); |
63 | } | |
64 | ||
65 | static int gre_parse_opt(struct link_util *lu, int argc, char **argv, | |
66 | struct nlmsghdr *n) | |
67 | { | |
d17b136f | 68 | struct ifinfomsg *ifi = (struct ifinfomsg *)(n + 1); |
72c771b2 HX |
69 | struct { |
70 | struct nlmsghdr n; | |
71 | struct ifinfomsg i; | |
d17b136f PS |
72 | } req = { |
73 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)), | |
74 | .n.nlmsg_flags = NLM_F_REQUEST, | |
75 | .n.nlmsg_type = RTM_GETLINK, | |
76 | .i.ifi_family = preferred_family, | |
77 | .i.ifi_index = ifi->ifi_index, | |
78 | }; | |
08ede25f | 79 | struct nlmsghdr *answer; |
72c771b2 HX |
80 | struct rtattr *tb[IFLA_MAX + 1]; |
81 | struct rtattr *linkinfo[IFLA_INFO_MAX+1]; | |
82 | struct rtattr *greinfo[IFLA_GRE_MAX + 1]; | |
237d9e82 HX |
83 | __u16 iflags = 0; |
84 | __u16 oflags = 0; | |
1f44b937 SP |
85 | __be32 ikey = 0; |
86 | __be32 okey = 0; | |
56f5daac SH |
87 | unsigned int saddr = 0; |
88 | unsigned int daddr = 0; | |
89 | unsigned int link = 0; | |
72c771b2 HX |
90 | __u8 pmtudisc = 1; |
91 | __u8 ttl = 0; | |
92 | __u8 tos = 0; | |
93 | int len; | |
80c24b09 TH |
94 | __u16 encaptype = 0; |
95 | __u16 encapflags = 0; | |
96 | __u16 encapsport = 0; | |
97 | __u16 encapdport = 0; | |
926b39e1 | 98 | __u8 metadata = 0; |
adbb2965 | 99 | __u8 ignore_df = 0; |
ad4b1425 | 100 | __u32 fwmark = 0; |
9a1381d5 | 101 | __u32 erspan_idx = 0; |
72c771b2 HX |
102 | |
103 | if (!(n->nlmsg_flags & NLM_F_CREATE)) { | |
86bf43c7 | 104 | if (rtnl_talk(&rth, &req.n, &answer) < 0) { |
72c771b2 HX |
105 | get_failed: |
106 | fprintf(stderr, | |
107 | "Failed to get existing tunnel info.\n"); | |
108 | return -1; | |
109 | } | |
110 | ||
86bf43c7 | 111 | len = answer->nlmsg_len; |
72c771b2 HX |
112 | len -= NLMSG_LENGTH(sizeof(*ifi)); |
113 | if (len < 0) | |
114 | goto get_failed; | |
115 | ||
86bf43c7 | 116 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len); |
72c771b2 HX |
117 | |
118 | if (!tb[IFLA_LINKINFO]) | |
119 | goto get_failed; | |
120 | ||
121 | parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]); | |
122 | ||
123 | if (!linkinfo[IFLA_INFO_DATA]) | |
124 | goto get_failed; | |
125 | ||
126 | parse_rtattr_nested(greinfo, IFLA_GRE_MAX, | |
127 | linkinfo[IFLA_INFO_DATA]); | |
128 | ||
129 | if (greinfo[IFLA_GRE_IKEY]) | |
ff24746c | 130 | ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]); |
72c771b2 HX |
131 | |
132 | if (greinfo[IFLA_GRE_OKEY]) | |
ff24746c | 133 | okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]); |
72c771b2 HX |
134 | |
135 | if (greinfo[IFLA_GRE_IFLAGS]) | |
ff24746c | 136 | iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]); |
72c771b2 HX |
137 | |
138 | if (greinfo[IFLA_GRE_OFLAGS]) | |
ff24746c | 139 | oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]); |
72c771b2 HX |
140 | |
141 | if (greinfo[IFLA_GRE_LOCAL]) | |
ff24746c | 142 | saddr = rta_getattr_u32(greinfo[IFLA_GRE_LOCAL]); |
72c771b2 HX |
143 | |
144 | if (greinfo[IFLA_GRE_REMOTE]) | |
ff24746c | 145 | daddr = rta_getattr_u32(greinfo[IFLA_GRE_REMOTE]); |
72c771b2 HX |
146 | |
147 | if (greinfo[IFLA_GRE_PMTUDISC]) | |
ff24746c | 148 | pmtudisc = rta_getattr_u8( |
72c771b2 HX |
149 | greinfo[IFLA_GRE_PMTUDISC]); |
150 | ||
151 | if (greinfo[IFLA_GRE_TTL]) | |
ff24746c | 152 | ttl = rta_getattr_u8(greinfo[IFLA_GRE_TTL]); |
72c771b2 HX |
153 | |
154 | if (greinfo[IFLA_GRE_TOS]) | |
ff24746c | 155 | tos = rta_getattr_u8(greinfo[IFLA_GRE_TOS]); |
72c771b2 HX |
156 | |
157 | if (greinfo[IFLA_GRE_LINK]) | |
a6addd5c | 158 | link = rta_getattr_u32(greinfo[IFLA_GRE_LINK]); |
80c24b09 TH |
159 | |
160 | if (greinfo[IFLA_GRE_ENCAP_TYPE]) | |
161 | encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]); | |
162 | if (greinfo[IFLA_GRE_ENCAP_FLAGS]) | |
163 | encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]); | |
164 | if (greinfo[IFLA_GRE_ENCAP_SPORT]) | |
165 | encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]); | |
166 | if (greinfo[IFLA_GRE_ENCAP_DPORT]) | |
167 | encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]); | |
926b39e1 PA |
168 | |
169 | if (greinfo[IFLA_GRE_COLLECT_METADATA]) | |
170 | metadata = 1; | |
ad4b1425 | 171 | |
adbb2965 PP |
172 | if (greinfo[IFLA_GRE_IGNORE_DF]) |
173 | ignore_df = | |
174 | !!rta_getattr_u8(greinfo[IFLA_GRE_IGNORE_DF]); | |
175 | ||
ad4b1425 CG |
176 | if (greinfo[IFLA_GRE_FWMARK]) |
177 | fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]); | |
9a1381d5 WT |
178 | |
179 | if (greinfo[IFLA_GRE_ERSPAN_INDEX]) | |
180 | erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]); | |
86bf43c7 HL |
181 | |
182 | free(answer); | |
72c771b2 | 183 | } |
237d9e82 HX |
184 | |
185 | while (argc > 0) { | |
186 | if (!matches(*argv, "key")) { | |
237d9e82 HX |
187 | NEXT_ARG(); |
188 | iflags |= GRE_KEY; | |
189 | oflags |= GRE_KEY; | |
1f44b937 | 190 | ikey = okey = tnl_parse_key("key", *argv); |
237d9e82 | 191 | } else if (!matches(*argv, "ikey")) { |
237d9e82 HX |
192 | NEXT_ARG(); |
193 | iflags |= GRE_KEY; | |
1f44b937 | 194 | ikey = tnl_parse_key("ikey", *argv); |
237d9e82 | 195 | } else if (!matches(*argv, "okey")) { |
237d9e82 HX |
196 | NEXT_ARG(); |
197 | oflags |= GRE_KEY; | |
1f44b937 | 198 | okey = tnl_parse_key("okey", *argv); |
237d9e82 HX |
199 | } else if (!matches(*argv, "seq")) { |
200 | iflags |= GRE_SEQ; | |
201 | oflags |= GRE_SEQ; | |
202 | } else if (!matches(*argv, "iseq")) { | |
203 | iflags |= GRE_SEQ; | |
204 | } else if (!matches(*argv, "oseq")) { | |
205 | oflags |= GRE_SEQ; | |
206 | } else if (!matches(*argv, "csum")) { | |
207 | iflags |= GRE_CSUM; | |
208 | oflags |= GRE_CSUM; | |
209 | } else if (!matches(*argv, "icsum")) { | |
210 | iflags |= GRE_CSUM; | |
211 | } else if (!matches(*argv, "ocsum")) { | |
212 | oflags |= GRE_CSUM; | |
213 | } else if (!matches(*argv, "nopmtudisc")) { | |
72c771b2 | 214 | pmtudisc = 0; |
237d9e82 | 215 | } else if (!matches(*argv, "pmtudisc")) { |
72c771b2 | 216 | pmtudisc = 1; |
237d9e82 HX |
217 | } else if (!matches(*argv, "remote")) { |
218 | NEXT_ARG(); | |
57daab1e | 219 | daddr = get_addr32(*argv); |
237d9e82 HX |
220 | } else if (!matches(*argv, "local")) { |
221 | NEXT_ARG(); | |
57daab1e | 222 | saddr = get_addr32(*argv); |
237d9e82 | 223 | } else if (!matches(*argv, "dev")) { |
237d9e82 | 224 | NEXT_ARG(); |
ea71beac | 225 | link = if_nametoindex(*argv); |
0cb6bb51 CW |
226 | if (link == 0) { |
227 | fprintf(stderr, "Cannot find device \"%s\"\n", | |
228 | *argv); | |
237d9e82 | 229 | exit(-1); |
0cb6bb51 | 230 | } |
237d9e82 HX |
231 | } else if (!matches(*argv, "ttl") || |
232 | !matches(*argv, "hoplimit")) { | |
56f5daac | 233 | unsigned int uval; |
237d9e82 HX |
234 | |
235 | NEXT_ARG(); | |
236 | if (strcmp(*argv, "inherit") != 0) { | |
237 | if (get_unsigned(&uval, *argv, 0)) | |
238 | invarg("invalid TTL\n", *argv); | |
239 | if (uval > 255) | |
240 | invarg("TTL must be <= 255\n", *argv); | |
241 | ttl = uval; | |
079e6781 RS |
242 | } else |
243 | ttl = 0; | |
237d9e82 HX |
244 | } else if (!matches(*argv, "tos") || |
245 | !matches(*argv, "tclass") || | |
246 | !matches(*argv, "dsfield")) { | |
247 | __u32 uval; | |
237d9e82 HX |
248 | |
249 | NEXT_ARG(); | |
250 | if (strcmp(*argv, "inherit") != 0) { | |
251 | if (rtnl_dsfield_a2n(&uval, *argv)) | |
252 | invarg("bad TOS value", *argv); | |
253 | tos = uval; | |
254 | } else | |
255 | tos = 1; | |
80c24b09 TH |
256 | } else if (strcmp(*argv, "noencap") == 0) { |
257 | encaptype = TUNNEL_ENCAP_NONE; | |
258 | } else if (strcmp(*argv, "encap") == 0) { | |
259 | NEXT_ARG(); | |
260 | if (strcmp(*argv, "fou") == 0) | |
261 | encaptype = TUNNEL_ENCAP_FOU; | |
262 | else if (strcmp(*argv, "gue") == 0) | |
263 | encaptype = TUNNEL_ENCAP_GUE; | |
264 | else if (strcmp(*argv, "none") == 0) | |
265 | encaptype = TUNNEL_ENCAP_NONE; | |
266 | else | |
267 | invarg("Invalid encap type.", *argv); | |
268 | } else if (strcmp(*argv, "encap-sport") == 0) { | |
269 | NEXT_ARG(); | |
270 | if (strcmp(*argv, "auto") == 0) | |
271 | encapsport = 0; | |
272 | else if (get_u16(&encapsport, *argv, 0)) | |
273 | invarg("Invalid source port.", *argv); | |
274 | } else if (strcmp(*argv, "encap-dport") == 0) { | |
275 | NEXT_ARG(); | |
276 | if (get_u16(&encapdport, *argv, 0)) | |
277 | invarg("Invalid destination port.", *argv); | |
278 | } else if (strcmp(*argv, "encap-csum") == 0) { | |
279 | encapflags |= TUNNEL_ENCAP_FLAG_CSUM; | |
280 | } else if (strcmp(*argv, "noencap-csum") == 0) { | |
281 | encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM; | |
282 | } else if (strcmp(*argv, "encap-udp6-csum") == 0) { | |
283 | encapflags |= TUNNEL_ENCAP_FLAG_CSUM6; | |
284 | } else if (strcmp(*argv, "noencap-udp6-csum") == 0) { | |
147ade01 | 285 | encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6; |
858dbb20 TH |
286 | } else if (strcmp(*argv, "encap-remcsum") == 0) { |
287 | encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM; | |
288 | } else if (strcmp(*argv, "noencap-remcsum") == 0) { | |
147ade01 | 289 | encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM; |
926b39e1 PA |
290 | } else if (strcmp(*argv, "external") == 0) { |
291 | metadata = 1; | |
adbb2965 PP |
292 | } else if (strcmp(*argv, "ignore-df") == 0) { |
293 | ignore_df = 1; | |
294 | } else if (strcmp(*argv, "noignore-df") == 0) { | |
295 | /* | |
296 | *only the lsb is significant, use 2 for presence | |
297 | */ | |
298 | ignore_df = 2; | |
ad4b1425 CG |
299 | } else if (strcmp(*argv, "fwmark") == 0) { |
300 | NEXT_ARG(); | |
301 | if (get_u32(&fwmark, *argv, 0)) | |
302 | invarg("invalid fwmark\n", *argv); | |
9a1381d5 WT |
303 | } else if (strcmp(*argv, "erspan") == 0) { |
304 | NEXT_ARG(); | |
305 | if (get_u32(&erspan_idx, *argv, 0)) | |
306 | invarg("invalid erspan index\n", *argv); | |
307 | if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0) | |
308 | invarg("erspan index must be > 0 and <= 20-bit\n", *argv); | |
0612519e | 309 | } else |
237d9e82 HX |
310 | usage(); |
311 | argc--; argv++; | |
312 | } | |
313 | ||
314 | if (!ikey && IN_MULTICAST(ntohl(daddr))) { | |
315 | ikey = daddr; | |
316 | iflags |= GRE_KEY; | |
317 | } | |
318 | if (!okey && IN_MULTICAST(ntohl(daddr))) { | |
319 | okey = daddr; | |
320 | oflags |= GRE_KEY; | |
321 | } | |
322 | if (IN_MULTICAST(ntohl(daddr)) && !saddr) { | |
14645ec2 | 323 | fprintf(stderr, "A broadcast tunnel requires a source address.\n"); |
237d9e82 HX |
324 | return -1; |
325 | } | |
326 | ||
df217d5d JB |
327 | if (!metadata) { |
328 | addattr32(n, 1024, IFLA_GRE_IKEY, ikey); | |
329 | addattr32(n, 1024, IFLA_GRE_OKEY, okey); | |
330 | addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2); | |
331 | addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2); | |
332 | addattr_l(n, 1024, IFLA_GRE_LOCAL, &saddr, 4); | |
333 | addattr_l(n, 1024, IFLA_GRE_REMOTE, &daddr, 4); | |
334 | addattr_l(n, 1024, IFLA_GRE_PMTUDISC, &pmtudisc, 1); | |
335 | if (link) | |
336 | addattr32(n, 1024, IFLA_GRE_LINK, link); | |
337 | addattr_l(n, 1024, IFLA_GRE_TTL, &ttl, 1); | |
338 | addattr_l(n, 1024, IFLA_GRE_TOS, &tos, 1); | |
ad4b1425 | 339 | addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark); |
9a1381d5 WT |
340 | if (erspan_idx != 0) |
341 | addattr32(n, 1024, IFLA_GRE_ERSPAN_INDEX, erspan_idx); | |
df217d5d JB |
342 | } else { |
343 | addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0); | |
344 | } | |
237d9e82 | 345 | |
80c24b09 TH |
346 | addattr16(n, 1024, IFLA_GRE_ENCAP_TYPE, encaptype); |
347 | addattr16(n, 1024, IFLA_GRE_ENCAP_FLAGS, encapflags); | |
348 | addattr16(n, 1024, IFLA_GRE_ENCAP_SPORT, htons(encapsport)); | |
349 | addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport)); | |
350 | ||
adbb2965 PP |
351 | if (ignore_df) |
352 | addattr8(n, 1024, IFLA_GRE_IGNORE_DF, ignore_df & 1); | |
353 | ||
237d9e82 HX |
354 | return 0; |
355 | } | |
356 | ||
7c337e2c | 357 | static void gre_print_direct_opt(FILE *f, struct rtattr *tb[]) |
237d9e82 | 358 | { |
237d9e82 HX |
359 | char s2[64]; |
360 | const char *local = "any"; | |
361 | const char *remote = "any"; | |
56f5daac SH |
362 | unsigned int iflags = 0; |
363 | unsigned int oflags = 0; | |
375560c4 | 364 | __u8 ttl = 0; |
3caa526c | 365 | __u8 tos = 0; |
237d9e82 | 366 | |
237d9e82 | 367 | if (tb[IFLA_GRE_REMOTE]) { |
56f5daac | 368 | unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]); |
237d9e82 HX |
369 | |
370 | if (addr) | |
a418e451 | 371 | remote = format_host(AF_INET, 4, &addr); |
237d9e82 HX |
372 | } |
373 | ||
e2d45883 | 374 | print_string(PRINT_ANY, "remote", "remote %s ", remote); |
237d9e82 HX |
375 | |
376 | if (tb[IFLA_GRE_LOCAL]) { | |
56f5daac | 377 | unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]); |
237d9e82 HX |
378 | |
379 | if (addr) | |
a418e451 | 380 | local = format_host(AF_INET, 4, &addr); |
237d9e82 HX |
381 | } |
382 | ||
e2d45883 | 383 | print_string(PRINT_ANY, "local", "local %s ", local); |
237d9e82 | 384 | |
45d3a6ef | 385 | if (tb[IFLA_GRE_LINK]) { |
56f5daac | 386 | unsigned int link = rta_getattr_u32(tb[IFLA_GRE_LINK]); |
237d9e82 | 387 | |
45d3a6ef SP |
388 | if (link) { |
389 | print_string(PRINT_ANY, "link", "dev %s ", | |
390 | ll_index_to_name(link)); | |
391 | } | |
237d9e82 HX |
392 | } |
393 | ||
375560c4 SP |
394 | if (tb[IFLA_GRE_TTL]) |
395 | ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]); | |
396 | if (is_json_context() || ttl) | |
397 | print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl); | |
398 | else | |
e2d45883 | 399 | print_string(PRINT_FP, NULL, "ttl %s ", "inherit"); |
237d9e82 | 400 | |
3caa526c SP |
401 | if (tb[IFLA_GRE_TOS]) |
402 | tos = rta_getattr_u8(tb[IFLA_GRE_TOS]); | |
403 | if (tos) { | |
404 | if (is_json_context() || tos != 1) | |
405 | print_0xhex(PRINT_ANY, "tos", "tos 0x%x ", tos); | |
406 | else | |
407 | print_string(PRINT_FP, NULL, "tos %s ", "inherit"); | |
237d9e82 HX |
408 | } |
409 | ||
e2d45883 JF |
410 | if (tb[IFLA_GRE_PMTUDISC]) { |
411 | if (!rta_getattr_u8(tb[IFLA_GRE_PMTUDISC])) | |
412 | print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false); | |
413 | else | |
414 | print_bool(PRINT_JSON, "pmtudisc", NULL, true); | |
415 | } | |
237d9e82 HX |
416 | |
417 | if (tb[IFLA_GRE_IFLAGS]) | |
ff24746c | 418 | iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]); |
237d9e82 HX |
419 | |
420 | if (tb[IFLA_GRE_OFLAGS]) | |
ff24746c | 421 | oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]); |
237d9e82 | 422 | |
71816553 | 423 | if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) { |
237d9e82 | 424 | inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2)); |
e2d45883 | 425 | print_string(PRINT_ANY, "ikey", "ikey %s ", s2); |
237d9e82 HX |
426 | } |
427 | ||
71816553 | 428 | if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) { |
237d9e82 | 429 | inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2)); |
e2d45883 | 430 | print_string(PRINT_ANY, "okey", "okey %s ", s2); |
237d9e82 HX |
431 | } |
432 | ||
433 | if (iflags & GRE_SEQ) | |
e2d45883 | 434 | print_bool(PRINT_ANY, "iseq", "iseq ", true); |
237d9e82 | 435 | if (oflags & GRE_SEQ) |
e2d45883 | 436 | print_bool(PRINT_ANY, "oseq", "oseq ", true); |
237d9e82 | 437 | if (iflags & GRE_CSUM) |
e2d45883 | 438 | print_bool(PRINT_ANY, "icsum", "icsum ", true); |
237d9e82 | 439 | if (oflags & GRE_CSUM) |
e2d45883 JF |
440 | print_bool(PRINT_ANY, "ocsum", "ocsum ", true); |
441 | ||
442 | if (tb[IFLA_GRE_FWMARK]) { | |
443 | __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]); | |
444 | ||
445 | if (fwmark) { | |
e97ad3d2 SP |
446 | print_0xhex(PRINT_ANY, |
447 | "fwmark", "fwmark 0x%x ", fwmark); | |
e2d45883 | 448 | } |
ad4b1425 | 449 | } |
7c337e2c | 450 | } |
80c24b09 | 451 | |
7c337e2c JB |
452 | static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) |
453 | { | |
454 | if (!tb) | |
455 | return; | |
456 | ||
457 | if (!tb[IFLA_GRE_COLLECT_METADATA]) | |
458 | gre_print_direct_opt(f, tb); | |
459 | else | |
e2d45883 | 460 | print_bool(PRINT_ANY, "external", "external ", true); |
926b39e1 | 461 | |
adbb2965 | 462 | if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF])) |
e2d45883 | 463 | print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true); |
adbb2965 | 464 | |
9a1381d5 WT |
465 | if (tb[IFLA_GRE_ERSPAN_INDEX]) { |
466 | __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]); | |
467 | ||
2a8d0f6e SP |
468 | print_uint(PRINT_ANY, |
469 | "erspan_index", "erspan_index %u ", erspan_idx); | |
9a1381d5 WT |
470 | } |
471 | ||
bad76e6b SP |
472 | tnl_print_encap(tb, |
473 | IFLA_GRE_ENCAP_TYPE, | |
474 | IFLA_GRE_ENCAP_FLAGS, | |
475 | IFLA_GRE_ENCAP_SPORT, | |
476 | IFLA_GRE_ENCAP_DPORT); | |
237d9e82 HX |
477 | } |
478 | ||
561e650e | 479 | static void gre_print_help(struct link_util *lu, int argc, char **argv, |
e2d45883 | 480 | FILE *f) |
561e650e | 481 | { |
482 | print_usage(f); | |
483 | } | |
484 | ||
237d9e82 HX |
485 | struct link_util gre_link_util = { |
486 | .id = "gre", | |
487 | .maxattr = IFLA_GRE_MAX, | |
488 | .parse_opt = gre_parse_opt, | |
489 | .print_opt = gre_print_opt, | |
561e650e | 490 | .print_help = gre_print_help, |
237d9e82 HX |
491 | }; |
492 | ||
493 | struct link_util gretap_link_util = { | |
494 | .id = "gretap", | |
495 | .maxattr = IFLA_GRE_MAX, | |
496 | .parse_opt = gre_parse_opt, | |
497 | .print_opt = gre_print_opt, | |
561e650e | 498 | .print_help = gre_print_help, |
237d9e82 | 499 | }; |
9a1381d5 WT |
500 | |
501 | struct link_util erspan_link_util = { | |
502 | .id = "erspan", | |
503 | .maxattr = IFLA_GRE_MAX, | |
504 | .parse_opt = gre_parse_opt, | |
505 | .print_opt = gre_print_opt, | |
506 | .print_help = gre_print_help, | |
507 | }; |