]>
Commit | Line | Data |
---|---|---|
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> | |
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 "rt_names.h" | |
22 | #include "utils.h" | |
23 | #include "ip_common.h" | |
24 | #include "tunnel.h" | |
25 | ||
26 | static void gre_print_help(struct link_util *lu, int argc, char **argv, FILE *f) | |
27 | { | |
28 | fprintf(f, | |
29 | "Usage: ... %-9s [ remote ADDR ]\n" | |
30 | " [ local ADDR ]\n" | |
31 | " [ [no][i|o]seq ]\n" | |
32 | " [ [i|o]key KEY | no[i|o]key ]\n" | |
33 | " [ [no][i|o]csum ]\n" | |
34 | " [ ttl TTL ]\n" | |
35 | " [ tos TOS ]\n" | |
36 | " [ [no]pmtudisc ]\n" | |
37 | " [ [no]ignore-df ]\n" | |
38 | " [ dev PHYS_DEV ]\n" | |
39 | " [ fwmark MARK ]\n" | |
40 | " [ external ]\n" | |
41 | " [ noencap ]\n" | |
42 | " [ encap { fou | gue | none } ]\n" | |
43 | " [ encap-sport PORT ]\n" | |
44 | " [ encap-dport PORT ]\n" | |
45 | " [ [no]encap-csum ]\n" | |
46 | " [ [no]encap-csum6 ]\n" | |
47 | " [ [no]encap-remcsum ]\n" | |
48 | " [ erspan_ver version ]\n" | |
49 | " [ erspan IDX ]\n" | |
50 | " [ erspan_dir { ingress | egress } ]\n" | |
51 | " [ erspan_hwid hwid ]\n" | |
52 | "\n" | |
53 | "Where: ADDR := { IP_ADDRESS | any }\n" | |
54 | " TOS := { NUMBER | inherit }\n" | |
55 | " TTL := { 1..255 | inherit }\n" | |
56 | " KEY := { DOTTED_QUAD | NUMBER }\n" | |
57 | " MARK := { 0x0..0xffffffff }\n", | |
58 | lu->id); | |
59 | } | |
60 | ||
61 | static int gre_parse_opt(struct link_util *lu, int argc, char **argv, | |
62 | struct nlmsghdr *n) | |
63 | { | |
64 | struct ifinfomsg *ifi = NLMSG_DATA(n); | |
65 | struct { | |
66 | struct nlmsghdr n; | |
67 | struct ifinfomsg i; | |
68 | } req = { | |
69 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)), | |
70 | .n.nlmsg_flags = NLM_F_REQUEST, | |
71 | .n.nlmsg_type = RTM_GETLINK, | |
72 | .i.ifi_family = preferred_family, | |
73 | .i.ifi_index = ifi->ifi_index, | |
74 | }; | |
75 | struct nlmsghdr *answer; | |
76 | struct rtattr *tb[IFLA_MAX + 1]; | |
77 | struct rtattr *linkinfo[IFLA_INFO_MAX+1]; | |
78 | struct rtattr *greinfo[IFLA_GRE_MAX + 1]; | |
79 | int len; | |
80 | __u16 iflags = 0; | |
81 | __u16 oflags = 0; | |
82 | __be32 ikey = 0; | |
83 | __be32 okey = 0; | |
84 | inet_prefix saddr, daddr; | |
85 | __u8 pmtudisc = 1; | |
86 | __u8 ignore_df = 0; | |
87 | __u8 tos = 0; | |
88 | __u8 ttl = 0; | |
89 | __u32 link = 0; | |
90 | __u16 encaptype = 0; | |
91 | __u16 encapflags = 0; | |
92 | __u16 encapsport = 0; | |
93 | __u16 encapdport = 0; | |
94 | __u8 metadata = 0; | |
95 | __u32 fwmark = 0; | |
96 | __u32 erspan_idx = 0; | |
97 | __u8 erspan_ver = 0; | |
98 | __u8 erspan_dir = 0; | |
99 | __u16 erspan_hwid = 0; | |
100 | ||
101 | inet_prefix_reset(&saddr); | |
102 | inet_prefix_reset(&daddr); | |
103 | ||
104 | if (!(n->nlmsg_flags & NLM_F_CREATE)) { | |
105 | const struct rtattr *rta; | |
106 | ||
107 | if (rtnl_talk(&rth, &req.n, &answer) < 0) { | |
108 | get_failed: | |
109 | fprintf(stderr, | |
110 | "Failed to get existing tunnel info.\n"); | |
111 | return -1; | |
112 | } | |
113 | ||
114 | len = answer->nlmsg_len; | |
115 | len -= NLMSG_LENGTH(sizeof(*ifi)); | |
116 | if (len < 0) | |
117 | goto get_failed; | |
118 | ||
119 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(NLMSG_DATA(answer)), len); | |
120 | ||
121 | if (!tb[IFLA_LINKINFO]) | |
122 | goto get_failed; | |
123 | ||
124 | parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]); | |
125 | ||
126 | if (!linkinfo[IFLA_INFO_DATA]) | |
127 | goto get_failed; | |
128 | ||
129 | parse_rtattr_nested(greinfo, IFLA_GRE_MAX, | |
130 | linkinfo[IFLA_INFO_DATA]); | |
131 | ||
132 | rta = greinfo[IFLA_GRE_LOCAL]; | |
133 | if (rta && get_addr_rta(&saddr, rta, AF_INET)) | |
134 | goto get_failed; | |
135 | ||
136 | rta = greinfo[IFLA_GRE_REMOTE]; | |
137 | if (rta && get_addr_rta(&daddr, rta, AF_INET)) | |
138 | goto get_failed; | |
139 | ||
140 | if (greinfo[IFLA_GRE_IKEY]) | |
141 | ikey = rta_getattr_u32(greinfo[IFLA_GRE_IKEY]); | |
142 | ||
143 | if (greinfo[IFLA_GRE_OKEY]) | |
144 | okey = rta_getattr_u32(greinfo[IFLA_GRE_OKEY]); | |
145 | ||
146 | if (greinfo[IFLA_GRE_IFLAGS]) | |
147 | iflags = rta_getattr_u16(greinfo[IFLA_GRE_IFLAGS]); | |
148 | ||
149 | if (greinfo[IFLA_GRE_OFLAGS]) | |
150 | oflags = rta_getattr_u16(greinfo[IFLA_GRE_OFLAGS]); | |
151 | ||
152 | if (greinfo[IFLA_GRE_PMTUDISC]) | |
153 | pmtudisc = rta_getattr_u8( | |
154 | greinfo[IFLA_GRE_PMTUDISC]); | |
155 | ||
156 | if (greinfo[IFLA_GRE_IGNORE_DF]) | |
157 | ignore_df = | |
158 | !!rta_getattr_u8(greinfo[IFLA_GRE_IGNORE_DF]); | |
159 | ||
160 | if (greinfo[IFLA_GRE_TOS]) | |
161 | tos = rta_getattr_u8(greinfo[IFLA_GRE_TOS]); | |
162 | ||
163 | if (greinfo[IFLA_GRE_TTL]) | |
164 | ttl = rta_getattr_u8(greinfo[IFLA_GRE_TTL]); | |
165 | ||
166 | if (greinfo[IFLA_GRE_LINK]) | |
167 | link = rta_getattr_u32(greinfo[IFLA_GRE_LINK]); | |
168 | ||
169 | if (greinfo[IFLA_GRE_ENCAP_TYPE]) | |
170 | encaptype = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_TYPE]); | |
171 | ||
172 | if (greinfo[IFLA_GRE_ENCAP_FLAGS]) | |
173 | encapflags = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_FLAGS]); | |
174 | ||
175 | if (greinfo[IFLA_GRE_ENCAP_SPORT]) | |
176 | encapsport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_SPORT]); | |
177 | ||
178 | if (greinfo[IFLA_GRE_ENCAP_DPORT]) | |
179 | encapdport = rta_getattr_u16(greinfo[IFLA_GRE_ENCAP_DPORT]); | |
180 | ||
181 | if (greinfo[IFLA_GRE_COLLECT_METADATA]) | |
182 | metadata = 1; | |
183 | ||
184 | if (greinfo[IFLA_GRE_FWMARK]) | |
185 | fwmark = rta_getattr_u32(greinfo[IFLA_GRE_FWMARK]); | |
186 | ||
187 | if (greinfo[IFLA_GRE_ERSPAN_INDEX]) | |
188 | erspan_idx = rta_getattr_u32(greinfo[IFLA_GRE_ERSPAN_INDEX]); | |
189 | ||
190 | if (greinfo[IFLA_GRE_ERSPAN_VER]) | |
191 | erspan_ver = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_VER]); | |
192 | ||
193 | if (greinfo[IFLA_GRE_ERSPAN_DIR]) | |
194 | erspan_dir = rta_getattr_u8(greinfo[IFLA_GRE_ERSPAN_DIR]); | |
195 | ||
196 | if (greinfo[IFLA_GRE_ERSPAN_HWID]) | |
197 | erspan_hwid = rta_getattr_u16(greinfo[IFLA_GRE_ERSPAN_HWID]); | |
198 | ||
199 | free(answer); | |
200 | } | |
201 | ||
202 | while (argc > 0) { | |
203 | if (!matches(*argv, "key")) { | |
204 | NEXT_ARG(); | |
205 | iflags |= GRE_KEY; | |
206 | oflags |= GRE_KEY; | |
207 | ikey = okey = tnl_parse_key("key", *argv); | |
208 | } else if (!matches(*argv, "nokey")) { | |
209 | iflags &= ~GRE_KEY; | |
210 | oflags &= ~GRE_KEY; | |
211 | ikey = okey = 0; | |
212 | } else if (!matches(*argv, "ikey")) { | |
213 | NEXT_ARG(); | |
214 | iflags |= GRE_KEY; | |
215 | ikey = tnl_parse_key("ikey", *argv); | |
216 | } else if (!matches(*argv, "noikey")) { | |
217 | iflags &= ~GRE_KEY; | |
218 | ikey = 0; | |
219 | } else if (!matches(*argv, "okey")) { | |
220 | NEXT_ARG(); | |
221 | oflags |= GRE_KEY; | |
222 | okey = tnl_parse_key("okey", *argv); | |
223 | } else if (!matches(*argv, "nookey")) { | |
224 | oflags &= ~GRE_KEY; | |
225 | okey = 0; | |
226 | } else if (!matches(*argv, "seq")) { | |
227 | iflags |= GRE_SEQ; | |
228 | oflags |= GRE_SEQ; | |
229 | } else if (!matches(*argv, "noseq")) { | |
230 | iflags &= ~GRE_SEQ; | |
231 | oflags &= ~GRE_SEQ; | |
232 | } else if (!matches(*argv, "iseq")) { | |
233 | iflags |= GRE_SEQ; | |
234 | } else if (!matches(*argv, "noiseq")) { | |
235 | iflags &= ~GRE_SEQ; | |
236 | } else if (!matches(*argv, "oseq")) { | |
237 | oflags |= GRE_SEQ; | |
238 | } else if (!matches(*argv, "nooseq")) { | |
239 | oflags &= ~GRE_SEQ; | |
240 | } else if (!matches(*argv, "csum")) { | |
241 | iflags |= GRE_CSUM; | |
242 | oflags |= GRE_CSUM; | |
243 | } else if (!matches(*argv, "nocsum")) { | |
244 | iflags &= ~GRE_CSUM; | |
245 | oflags &= ~GRE_CSUM; | |
246 | } else if (!matches(*argv, "icsum")) { | |
247 | iflags |= GRE_CSUM; | |
248 | } else if (!matches(*argv, "noicsum")) { | |
249 | iflags &= ~GRE_CSUM; | |
250 | } else if (!matches(*argv, "ocsum")) { | |
251 | oflags |= GRE_CSUM; | |
252 | } else if (!matches(*argv, "noocsum")) { | |
253 | oflags &= ~GRE_CSUM; | |
254 | } else if (!matches(*argv, "nopmtudisc")) { | |
255 | pmtudisc = 0; | |
256 | } else if (!matches(*argv, "pmtudisc")) { | |
257 | pmtudisc = 1; | |
258 | } else if (!matches(*argv, "remote")) { | |
259 | NEXT_ARG(); | |
260 | get_addr(&daddr, *argv, AF_INET); | |
261 | } else if (!matches(*argv, "local")) { | |
262 | NEXT_ARG(); | |
263 | get_addr(&saddr, *argv, AF_INET); | |
264 | } else if (!matches(*argv, "dev")) { | |
265 | NEXT_ARG(); | |
266 | link = ll_name_to_index(*argv); | |
267 | if (!link) | |
268 | exit(nodev(*argv)); | |
269 | } else if (!matches(*argv, "ttl") || | |
270 | !matches(*argv, "hoplimit") || | |
271 | !matches(*argv, "hlim")) { | |
272 | NEXT_ARG(); | |
273 | if (strcmp(*argv, "inherit") != 0) { | |
274 | if (get_u8(&ttl, *argv, 0)) | |
275 | invarg("invalid TTL\n", *argv); | |
276 | } else | |
277 | ttl = 0; | |
278 | } else if (!matches(*argv, "tos") || | |
279 | !matches(*argv, "tclass") || | |
280 | !matches(*argv, "dsfield")) { | |
281 | __u32 uval; | |
282 | ||
283 | NEXT_ARG(); | |
284 | if (strcmp(*argv, "inherit") != 0) { | |
285 | if (rtnl_dsfield_a2n(&uval, *argv)) | |
286 | invarg("bad TOS value", *argv); | |
287 | tos = uval; | |
288 | } else | |
289 | tos = 1; | |
290 | } else if (strcmp(*argv, "noencap") == 0) { | |
291 | encaptype = TUNNEL_ENCAP_NONE; | |
292 | } else if (strcmp(*argv, "encap") == 0) { | |
293 | NEXT_ARG(); | |
294 | if (strcmp(*argv, "fou") == 0) | |
295 | encaptype = TUNNEL_ENCAP_FOU; | |
296 | else if (strcmp(*argv, "gue") == 0) | |
297 | encaptype = TUNNEL_ENCAP_GUE; | |
298 | else if (strcmp(*argv, "none") == 0) | |
299 | encaptype = TUNNEL_ENCAP_NONE; | |
300 | else | |
301 | invarg("Invalid encap type.", *argv); | |
302 | } else if (strcmp(*argv, "encap-sport") == 0) { | |
303 | NEXT_ARG(); | |
304 | if (strcmp(*argv, "auto") == 0) | |
305 | encapsport = 0; | |
306 | else if (get_u16(&encapsport, *argv, 0)) | |
307 | invarg("Invalid source port.", *argv); | |
308 | } else if (strcmp(*argv, "encap-dport") == 0) { | |
309 | NEXT_ARG(); | |
310 | if (get_u16(&encapdport, *argv, 0)) | |
311 | invarg("Invalid destination port.", *argv); | |
312 | } else if (strcmp(*argv, "encap-csum") == 0) { | |
313 | encapflags |= TUNNEL_ENCAP_FLAG_CSUM; | |
314 | } else if (strcmp(*argv, "noencap-csum") == 0) { | |
315 | encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM; | |
316 | } else if (strcmp(*argv, "encap-udp6-csum") == 0) { | |
317 | encapflags |= TUNNEL_ENCAP_FLAG_CSUM6; | |
318 | } else if (strcmp(*argv, "noencap-udp6-csum") == 0) { | |
319 | encapflags &= ~TUNNEL_ENCAP_FLAG_CSUM6; | |
320 | } else if (strcmp(*argv, "encap-remcsum") == 0) { | |
321 | encapflags |= TUNNEL_ENCAP_FLAG_REMCSUM; | |
322 | } else if (strcmp(*argv, "noencap-remcsum") == 0) { | |
323 | encapflags &= ~TUNNEL_ENCAP_FLAG_REMCSUM; | |
324 | } else if (strcmp(*argv, "external") == 0) { | |
325 | metadata = 1; | |
326 | } else if (strcmp(*argv, "ignore-df") == 0) { | |
327 | ignore_df = 1; | |
328 | } else if (strcmp(*argv, "noignore-df") == 0) { | |
329 | /* | |
330 | *only the lsb is significant, use 2 for presence | |
331 | */ | |
332 | ignore_df = 2; | |
333 | } else if (strcmp(*argv, "fwmark") == 0) { | |
334 | NEXT_ARG(); | |
335 | if (get_u32(&fwmark, *argv, 0)) | |
336 | invarg("invalid fwmark\n", *argv); | |
337 | } else if (strcmp(*argv, "erspan") == 0) { | |
338 | NEXT_ARG(); | |
339 | if (get_u32(&erspan_idx, *argv, 0)) | |
340 | invarg("invalid erspan index\n", *argv); | |
341 | if (erspan_idx & ~((1<<20) - 1) || erspan_idx == 0) | |
342 | invarg("erspan index must be > 0 and <= 20-bit\n", *argv); | |
343 | } else if (strcmp(*argv, "erspan_ver") == 0) { | |
344 | NEXT_ARG(); | |
345 | if (get_u8(&erspan_ver, *argv, 0)) | |
346 | invarg("invalid erspan version\n", *argv); | |
347 | if (erspan_ver != 1 && erspan_ver != 2) | |
348 | invarg("erspan version must be 1 or 2\n", *argv); | |
349 | } else if (strcmp(*argv, "erspan_dir") == 0) { | |
350 | NEXT_ARG(); | |
351 | if (matches(*argv, "ingress") == 0) | |
352 | erspan_dir = 0; | |
353 | else if (matches(*argv, "egress") == 0) | |
354 | erspan_dir = 1; | |
355 | else | |
356 | invarg("Invalid erspan direction.", *argv); | |
357 | } else if (strcmp(*argv, "erspan_hwid") == 0) { | |
358 | NEXT_ARG(); | |
359 | if (get_u16(&erspan_hwid, *argv, 0)) | |
360 | invarg("invalid erspan hwid\n", *argv); | |
361 | } else { | |
362 | gre_print_help(lu, argc, argv, stderr); | |
363 | return -1; | |
364 | } | |
365 | argc--; argv++; | |
366 | } | |
367 | ||
368 | if (is_addrtype_inet_multi(&daddr)) { | |
369 | if (!ikey) { | |
370 | ikey = daddr.data[0]; | |
371 | iflags |= GRE_KEY; | |
372 | } | |
373 | if (!okey) { | |
374 | okey = daddr.data[0]; | |
375 | oflags |= GRE_KEY; | |
376 | } | |
377 | if (!is_addrtype_inet_not_unspec(&saddr)) { | |
378 | fprintf(stderr, | |
379 | "A broadcast tunnel requires a source address.\n"); | |
380 | return -1; | |
381 | } | |
382 | } | |
383 | ||
384 | if (metadata) { | |
385 | addattr_l(n, 1024, IFLA_GRE_COLLECT_METADATA, NULL, 0); | |
386 | return 0; | |
387 | } | |
388 | ||
389 | addattr32(n, 1024, IFLA_GRE_IKEY, ikey); | |
390 | addattr32(n, 1024, IFLA_GRE_OKEY, okey); | |
391 | addattr_l(n, 1024, IFLA_GRE_IFLAGS, &iflags, 2); | |
392 | addattr_l(n, 1024, IFLA_GRE_OFLAGS, &oflags, 2); | |
393 | if (is_addrtype_inet_not_unspec(&saddr)) | |
394 | addattr_l(n, 1024, IFLA_GRE_LOCAL, saddr.data, saddr.bytelen); | |
395 | if (is_addrtype_inet_not_unspec(&daddr)) | |
396 | addattr_l(n, 1024, IFLA_GRE_REMOTE, daddr.data, daddr.bytelen); | |
397 | addattr_l(n, 1024, IFLA_GRE_PMTUDISC, &pmtudisc, 1); | |
398 | if (ignore_df) | |
399 | addattr8(n, 1024, IFLA_GRE_IGNORE_DF, ignore_df & 1); | |
400 | addattr_l(n, 1024, IFLA_GRE_TOS, &tos, 1); | |
401 | if (link) | |
402 | addattr32(n, 1024, IFLA_GRE_LINK, link); | |
403 | addattr_l(n, 1024, IFLA_GRE_TTL, &ttl, 1); | |
404 | addattr32(n, 1024, IFLA_GRE_FWMARK, fwmark); | |
405 | if (erspan_ver) { | |
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); | |
409 | } else if (erspan_ver == 2) { | |
410 | addattr8(n, 1024, IFLA_GRE_ERSPAN_DIR, erspan_dir); | |
411 | addattr16(n, 1024, IFLA_GRE_ERSPAN_HWID, erspan_hwid); | |
412 | } | |
413 | } | |
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)); | |
418 | ||
419 | return 0; | |
420 | } | |
421 | ||
422 | static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) | |
423 | { | |
424 | char s2[64]; | |
425 | __u16 iflags = 0; | |
426 | __u16 oflags = 0; | |
427 | __u8 ttl = 0; | |
428 | __u8 tos = 0; | |
429 | ||
430 | if (!tb) | |
431 | return; | |
432 | ||
433 | if (tb[IFLA_GRE_COLLECT_METADATA]) { | |
434 | print_bool(PRINT_ANY, "external", "external ", true); | |
435 | return; | |
436 | } | |
437 | ||
438 | tnl_print_endpoint("remote", tb[IFLA_GRE_REMOTE], AF_INET); | |
439 | tnl_print_endpoint("local", tb[IFLA_GRE_LOCAL], AF_INET); | |
440 | ||
441 | if (tb[IFLA_GRE_LINK]) { | |
442 | __u32 link = rta_getattr_u32(tb[IFLA_GRE_LINK]); | |
443 | ||
444 | if (link) { | |
445 | print_string(PRINT_ANY, "link", "dev %s ", | |
446 | ll_index_to_name(link)); | |
447 | } | |
448 | } | |
449 | ||
450 | if (tb[IFLA_GRE_TTL]) | |
451 | ttl = rta_getattr_u8(tb[IFLA_GRE_TTL]); | |
452 | if (is_json_context() || ttl) | |
453 | print_uint(PRINT_ANY, "ttl", "ttl %u ", ttl); | |
454 | else | |
455 | print_string(PRINT_FP, NULL, "ttl %s ", "inherit"); | |
456 | ||
457 | if (tb[IFLA_GRE_TOS]) | |
458 | tos = rta_getattr_u8(tb[IFLA_GRE_TOS]); | |
459 | if (tos) { | |
460 | if (is_json_context() || tos != 1) | |
461 | print_0xhex(PRINT_ANY, "tos", "tos %#llx ", tos); | |
462 | else | |
463 | print_string(PRINT_FP, NULL, "tos %s ", "inherit"); | |
464 | } | |
465 | ||
466 | if (tb[IFLA_GRE_PMTUDISC]) { | |
467 | if (!rta_getattr_u8(tb[IFLA_GRE_PMTUDISC])) | |
468 | print_bool(PRINT_ANY, "pmtudisc", "nopmtudisc ", false); | |
469 | else | |
470 | print_bool(PRINT_JSON, "pmtudisc", NULL, true); | |
471 | } | |
472 | ||
473 | if (tb[IFLA_GRE_IGNORE_DF] && rta_getattr_u8(tb[IFLA_GRE_IGNORE_DF])) | |
474 | print_bool(PRINT_ANY, "ignore_df", "ignore-df ", true); | |
475 | ||
476 | if (tb[IFLA_GRE_IFLAGS]) | |
477 | iflags = rta_getattr_u16(tb[IFLA_GRE_IFLAGS]); | |
478 | ||
479 | if (tb[IFLA_GRE_OFLAGS]) | |
480 | oflags = rta_getattr_u16(tb[IFLA_GRE_OFLAGS]); | |
481 | ||
482 | if ((iflags & GRE_KEY) && tb[IFLA_GRE_IKEY]) { | |
483 | inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_IKEY]), s2, sizeof(s2)); | |
484 | print_string(PRINT_ANY, "ikey", "ikey %s ", s2); | |
485 | } | |
486 | ||
487 | if ((oflags & GRE_KEY) && tb[IFLA_GRE_OKEY]) { | |
488 | inet_ntop(AF_INET, RTA_DATA(tb[IFLA_GRE_OKEY]), s2, sizeof(s2)); | |
489 | print_string(PRINT_ANY, "okey", "okey %s ", s2); | |
490 | } | |
491 | ||
492 | if (iflags & GRE_SEQ) | |
493 | print_bool(PRINT_ANY, "iseq", "iseq ", true); | |
494 | if (oflags & GRE_SEQ) | |
495 | print_bool(PRINT_ANY, "oseq", "oseq ", true); | |
496 | if (iflags & GRE_CSUM) | |
497 | print_bool(PRINT_ANY, "icsum", "icsum ", true); | |
498 | if (oflags & GRE_CSUM) | |
499 | print_bool(PRINT_ANY, "ocsum", "ocsum ", true); | |
500 | ||
501 | if (tb[IFLA_GRE_FWMARK]) { | |
502 | __u32 fwmark = rta_getattr_u32(tb[IFLA_GRE_FWMARK]); | |
503 | ||
504 | if (fwmark) { | |
505 | print_0xhex(PRINT_ANY, | |
506 | "fwmark", "fwmark %#llx ", fwmark); | |
507 | } | |
508 | } | |
509 | ||
510 | if (tb[IFLA_GRE_ERSPAN_INDEX]) { | |
511 | __u32 erspan_idx = rta_getattr_u32(tb[IFLA_GRE_ERSPAN_INDEX]); | |
512 | ||
513 | print_uint(PRINT_ANY, | |
514 | "erspan_index", "erspan_index %u ", erspan_idx); | |
515 | } | |
516 | ||
517 | if (tb[IFLA_GRE_ERSPAN_VER]) { | |
518 | __u8 erspan_ver = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_VER]); | |
519 | ||
520 | print_uint(PRINT_ANY, | |
521 | "erspan_ver", "erspan_ver %u ", erspan_ver); | |
522 | } | |
523 | ||
524 | if (tb[IFLA_GRE_ERSPAN_DIR]) { | |
525 | __u8 erspan_dir = rta_getattr_u8(tb[IFLA_GRE_ERSPAN_DIR]); | |
526 | ||
527 | if (erspan_dir == 0) | |
528 | print_string(PRINT_ANY, "erspan_dir", | |
529 | "erspan_dir ingress ", NULL); | |
530 | else | |
531 | print_string(PRINT_ANY, "erspan_dir", | |
532 | "erspan_dir egress ", NULL); | |
533 | } | |
534 | ||
535 | if (tb[IFLA_GRE_ERSPAN_HWID]) { | |
536 | __u16 erspan_hwid = rta_getattr_u16(tb[IFLA_GRE_ERSPAN_HWID]); | |
537 | ||
538 | print_0xhex(PRINT_ANY, | |
539 | "erspan_hwid", "erspan_hwid %#llx ", erspan_hwid); | |
540 | } | |
541 | ||
542 | tnl_print_encap(tb, | |
543 | IFLA_GRE_ENCAP_TYPE, | |
544 | IFLA_GRE_ENCAP_FLAGS, | |
545 | IFLA_GRE_ENCAP_SPORT, | |
546 | IFLA_GRE_ENCAP_DPORT); | |
547 | } | |
548 | ||
549 | struct link_util gre_link_util = { | |
550 | .id = "gre", | |
551 | .maxattr = IFLA_GRE_MAX, | |
552 | .parse_opt = gre_parse_opt, | |
553 | .print_opt = gre_print_opt, | |
554 | .print_help = gre_print_help, | |
555 | }; | |
556 | ||
557 | struct link_util gretap_link_util = { | |
558 | .id = "gretap", | |
559 | .maxattr = IFLA_GRE_MAX, | |
560 | .parse_opt = gre_parse_opt, | |
561 | .print_opt = gre_print_opt, | |
562 | .print_help = gre_print_help, | |
563 | }; | |
564 | ||
565 | struct link_util erspan_link_util = { | |
566 | .id = "erspan", | |
567 | .maxattr = IFLA_GRE_MAX, | |
568 | .parse_opt = gre_parse_opt, | |
569 | .print_opt = gre_print_opt, | |
570 | .print_help = gre_print_help, | |
571 | }; |