]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iplink_vxlan.c
vxlan: Make id optional when modifying a link
[mirror_iproute2.git] / ip / iplink_vxlan.c
1 /*
2 * iplink_vxlan.c VXLAN device support
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: Stephen Hemminger <shemminger@vyatta.com
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <net/if.h>
16 #include <linux/ip.h>
17 #include <linux/if_link.h>
18 #include <arpa/inet.h>
19
20 #include "rt_names.h"
21 #include "utils.h"
22 #include "ip_common.h"
23
24 #define VXLAN_ATTRSET(attrs, type) (((attrs) & (1L << (type))) != 0)
25
26 static void print_explain(FILE *f)
27 {
28 fprintf(f,
29 "Usage: ... vxlan id VNI\n"
30 " [ { group | remote } IP_ADDRESS ]\n"
31 " [ local ADDR ]\n"
32 " [ ttl TTL ]\n"
33 " [ tos TOS ]\n"
34 " [ flowlabel LABEL ]\n"
35 " [ dev PHYS_DEV ]\n"
36 " [ dstport PORT ]\n"
37 " [ srcport MIN MAX ]\n"
38 " [ [no]learning ]\n"
39 " [ [no]proxy ]\n"
40 " [ [no]rsc ]\n"
41 " [ [no]l2miss ]\n"
42 " [ [no]l3miss ]\n"
43 " [ ageing SECONDS ]\n"
44 " [ maxaddress NUMBER ]\n"
45 " [ [no]udpcsum ]\n"
46 " [ [no]udp6zerocsumtx ]\n"
47 " [ [no]udp6zerocsumrx ]\n"
48 " [ [no]remcsumtx ] [ [no]remcsumrx ]\n"
49 " [ [no]external ] [ gbp ] [ gpe ]\n"
50 "\n"
51 "Where: VNI := 0-16777215\n"
52 " ADDR := { IP_ADDRESS | any }\n"
53 " TOS := { NUMBER | inherit }\n"
54 " TTL := { 1..255 | inherit }\n"
55 " LABEL := 0-1048575\n"
56 );
57 }
58
59 static void explain(void)
60 {
61 print_explain(stderr);
62 }
63
64 static void check_duparg(__u64 *attrs, int type, const char *key,
65 const char *argv)
66 {
67 if (!VXLAN_ATTRSET(*attrs, type)) {
68 *attrs |= (1L << type);
69 return;
70 }
71 duparg2(key, argv);
72 }
73
74 static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
75 struct nlmsghdr *n)
76 {
77 __u32 vni = 0;
78 __u32 gaddr = 0;
79 __u32 daddr = 0;
80 struct in6_addr gaddr6 = IN6ADDR_ANY_INIT;
81 struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
82 __u8 learning = 1;
83 __u16 dstport = 0;
84 __u8 metadata = 0;
85 __u64 attrs = 0;
86 bool set_op = (n->nlmsg_type == RTM_NEWLINK &&
87 !(n->nlmsg_flags & NLM_F_CREATE));
88
89 while (argc > 0) {
90 if (!matches(*argv, "id") ||
91 !matches(*argv, "vni")) {
92 /* We will add ID attribute outside of the loop since we
93 * need to consider metadata information as well.
94 */
95 NEXT_ARG();
96 check_duparg(&attrs, IFLA_VXLAN_ID, "id", *argv);
97 if (get_u32(&vni, *argv, 0) ||
98 vni >= 1u << 24)
99 invarg("invalid id", *argv);
100 } else if (!matches(*argv, "group")) {
101 if (daddr || !IN6_IS_ADDR_UNSPECIFIED(&daddr6)) {
102 fprintf(stderr, "vxlan: both group and remote");
103 fprintf(stderr, " cannot be specified\n");
104 return -1;
105 }
106 NEXT_ARG();
107 check_duparg(&attrs, IFLA_VXLAN_GROUP, "group", *argv);
108 if (!inet_get_addr(*argv, &gaddr, &gaddr6)) {
109 fprintf(stderr, "Invalid address \"%s\"\n", *argv);
110 return -1;
111 }
112 if (!IN6_IS_ADDR_MULTICAST(&gaddr6) && !IN_MULTICAST(ntohl(gaddr)))
113 invarg("invalid group address", *argv);
114 } else if (!matches(*argv, "remote")) {
115 if (gaddr || !IN6_IS_ADDR_UNSPECIFIED(&gaddr6)) {
116 fprintf(stderr, "vxlan: both group and remote");
117 fprintf(stderr, " cannot be specified\n");
118 return -1;
119 }
120 NEXT_ARG();
121 check_duparg(&attrs, IFLA_VXLAN_GROUP, "remote", *argv);
122 if (!inet_get_addr(*argv, &daddr, &daddr6)) {
123 fprintf(stderr, "Invalid address \"%s\"\n", *argv);
124 return -1;
125 }
126 if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
127 invarg("invalid remote address", *argv);
128 } else if (!matches(*argv, "local")) {
129 __u32 saddr = 0;
130 struct in6_addr saddr6 = IN6ADDR_ANY_INIT;
131
132 NEXT_ARG();
133 check_duparg(&attrs, IFLA_VXLAN_LOCAL, "local", *argv);
134 if (strcmp(*argv, "any")) {
135 if (!inet_get_addr(*argv, &saddr, &saddr6)) {
136 fprintf(stderr, "Invalid address \"%s\"\n", *argv);
137 return -1;
138 }
139 }
140
141 if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6))
142 invarg("invalid local address", *argv);
143
144 if (saddr)
145 addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4);
146 else if (!IN6_IS_ADDR_UNSPECIFIED(&saddr6))
147 addattr_l(n, 1024, IFLA_VXLAN_LOCAL6, &saddr6,
148 sizeof(struct in6_addr));
149 } else if (!matches(*argv, "dev")) {
150 unsigned int link;
151
152 NEXT_ARG();
153 check_duparg(&attrs, IFLA_VXLAN_LINK, "dev", *argv);
154 link = if_nametoindex(*argv);
155 if (link == 0) {
156 fprintf(stderr, "Cannot find device \"%s\"\n",
157 *argv);
158 exit(-1);
159 }
160 addattr32(n, 1024, IFLA_VXLAN_LINK, link);
161 } else if (!matches(*argv, "ttl") ||
162 !matches(*argv, "hoplimit")) {
163 unsigned int uval;
164 __u8 ttl = 0;
165
166 NEXT_ARG();
167 check_duparg(&attrs, IFLA_VXLAN_TTL, "ttl", *argv);
168 if (strcmp(*argv, "inherit") != 0) {
169 if (get_unsigned(&uval, *argv, 0))
170 invarg("invalid TTL", *argv);
171 if (uval > 255)
172 invarg("TTL must be <= 255", *argv);
173 ttl = uval;
174 }
175 addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
176 } else if (!matches(*argv, "tos") ||
177 !matches(*argv, "dsfield")) {
178 __u32 uval;
179 __u8 tos;
180
181 NEXT_ARG();
182 check_duparg(&attrs, IFLA_VXLAN_TOS, "tos", *argv);
183 if (strcmp(*argv, "inherit") != 0) {
184 if (rtnl_dsfield_a2n(&uval, *argv))
185 invarg("bad TOS value", *argv);
186 tos = uval;
187 } else
188 tos = 1;
189 addattr8(n, 1024, IFLA_VXLAN_TOS, tos);
190 } else if (!matches(*argv, "label") ||
191 !matches(*argv, "flowlabel")) {
192 __u32 uval;
193
194 NEXT_ARG();
195 check_duparg(&attrs, IFLA_VXLAN_LABEL, "flowlabel",
196 *argv);
197 if (get_u32(&uval, *argv, 0) ||
198 (uval & ~LABEL_MAX_MASK))
199 invarg("invalid flowlabel", *argv);
200 addattr32(n, 1024, IFLA_VXLAN_LABEL, htonl(uval));
201 } else if (!matches(*argv, "ageing")) {
202 __u32 age;
203
204 NEXT_ARG();
205 check_duparg(&attrs, IFLA_VXLAN_AGEING, "ageing",
206 *argv);
207 if (strcmp(*argv, "none") == 0)
208 age = 0;
209 else if (get_u32(&age, *argv, 0))
210 invarg("ageing timer", *argv);
211 addattr32(n, 1024, IFLA_VXLAN_AGEING, age);
212 } else if (!matches(*argv, "maxaddress")) {
213 __u32 maxaddr;
214
215 NEXT_ARG();
216 check_duparg(&attrs, IFLA_VXLAN_LIMIT,
217 "maxaddress", *argv);
218 if (strcmp(*argv, "unlimited") == 0)
219 maxaddr = 0;
220 else if (get_u32(&maxaddr, *argv, 0))
221 invarg("max addresses", *argv);
222 addattr32(n, 1024, IFLA_VXLAN_LIMIT, maxaddr);
223 } else if (!matches(*argv, "port") ||
224 !matches(*argv, "srcport")) {
225 struct ifla_vxlan_port_range range = { 0, 0 };
226
227 NEXT_ARG();
228 check_duparg(&attrs, IFLA_VXLAN_PORT_RANGE, "srcport",
229 *argv);
230 if (get_be16(&range.low, *argv, 0))
231 invarg("min port", *argv);
232 NEXT_ARG();
233 if (get_be16(&range.high, *argv, 0))
234 invarg("max port", *argv);
235 if (range.low || range.high) {
236 addattr_l(n, 1024, IFLA_VXLAN_PORT_RANGE,
237 &range, sizeof(range));
238 }
239 } else if (!matches(*argv, "dstport")) {
240 NEXT_ARG();
241 check_duparg(&attrs, IFLA_VXLAN_PORT, "dstport", *argv);
242 if (get_u16(&dstport, *argv, 0))
243 invarg("dst port", *argv);
244 } else if (!matches(*argv, "nolearning")) {
245 check_duparg(&attrs, IFLA_VXLAN_LEARNING, *argv, *argv);
246 learning = 0;
247 } else if (!matches(*argv, "learning")) {
248 check_duparg(&attrs, IFLA_VXLAN_LEARNING, *argv, *argv);
249 learning = 1;
250 } else if (!matches(*argv, "noproxy")) {
251 check_duparg(&attrs, IFLA_VXLAN_PROXY, *argv, *argv);
252 addattr8(n, 1024, IFLA_VXLAN_PROXY, 0);
253 } else if (!matches(*argv, "proxy")) {
254 check_duparg(&attrs, IFLA_VXLAN_PROXY, *argv, *argv);
255 addattr8(n, 1024, IFLA_VXLAN_PROXY, 1);
256 } else if (!matches(*argv, "norsc")) {
257 check_duparg(&attrs, IFLA_VXLAN_RSC, *argv, *argv);
258 addattr8(n, 1024, IFLA_VXLAN_RSC, 0);
259 } else if (!matches(*argv, "rsc")) {
260 check_duparg(&attrs, IFLA_VXLAN_RSC, *argv, *argv);
261 addattr8(n, 1024, IFLA_VXLAN_RSC, 1);
262 } else if (!matches(*argv, "nol2miss")) {
263 check_duparg(&attrs, IFLA_VXLAN_L2MISS, *argv, *argv);
264 addattr8(n, 1024, IFLA_VXLAN_L2MISS, 0);
265 } else if (!matches(*argv, "l2miss")) {
266 check_duparg(&attrs, IFLA_VXLAN_L2MISS, *argv, *argv);
267 addattr8(n, 1024, IFLA_VXLAN_L2MISS, 1);
268 } else if (!matches(*argv, "nol3miss")) {
269 check_duparg(&attrs, IFLA_VXLAN_L3MISS, *argv, *argv);
270 addattr8(n, 1024, IFLA_VXLAN_L3MISS, 0);
271 } else if (!matches(*argv, "l3miss")) {
272 check_duparg(&attrs, IFLA_VXLAN_L3MISS, *argv, *argv);
273 addattr8(n, 1024, IFLA_VXLAN_L3MISS, 1);
274 } else if (!matches(*argv, "udpcsum")) {
275 check_duparg(&attrs, IFLA_VXLAN_UDP_CSUM, *argv, *argv);
276 addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, 1);
277 } else if (!matches(*argv, "noudpcsum")) {
278 check_duparg(&attrs, IFLA_VXLAN_UDP_CSUM, *argv, *argv);
279 addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, 0);
280 } else if (!matches(*argv, "udp6zerocsumtx")) {
281 check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
282 *argv, *argv);
283 addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, 1);
284 } else if (!matches(*argv, "noudp6zerocsumtx")) {
285 check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
286 *argv, *argv);
287 addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, 0);
288 } else if (!matches(*argv, "udp6zerocsumrx")) {
289 check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
290 *argv, *argv);
291 addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 1);
292 } else if (!matches(*argv, "noudp6zerocsumrx")) {
293 check_duparg(&attrs, IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
294 *argv, *argv);
295 addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, 0);
296 } else if (!matches(*argv, "remcsumtx")) {
297 check_duparg(&attrs, IFLA_VXLAN_REMCSUM_TX,
298 *argv, *argv);
299 addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, 1);
300 } else if (!matches(*argv, "noremcsumtx")) {
301 check_duparg(&attrs, IFLA_VXLAN_REMCSUM_TX,
302 *argv, *argv);
303 addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, 0);
304 } else if (!matches(*argv, "remcsumrx")) {
305 check_duparg(&attrs, IFLA_VXLAN_REMCSUM_RX,
306 *argv, *argv);
307 addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, 1);
308 } else if (!matches(*argv, "noremcsumrx")) {
309 check_duparg(&attrs, IFLA_VXLAN_REMCSUM_RX,
310 *argv, *argv);
311 addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, 0);
312 } else if (!matches(*argv, "external")) {
313 check_duparg(&attrs, IFLA_VXLAN_COLLECT_METADATA,
314 *argv, *argv);
315 metadata = 1;
316 learning = 0;
317 /* we will add LEARNING attribute outside of the loop */
318 addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA,
319 metadata);
320 } else if (!matches(*argv, "noexternal")) {
321 check_duparg(&attrs, IFLA_VXLAN_COLLECT_METADATA,
322 *argv, *argv);
323 metadata = 0;
324 addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA,
325 metadata);
326 } else if (!matches(*argv, "gbp")) {
327 check_duparg(&attrs, IFLA_VXLAN_GBP, *argv, *argv);
328 addattr_l(n, 1024, IFLA_VXLAN_GBP, NULL, 0);
329 } else if (!matches(*argv, "gpe")) {
330 check_duparg(&attrs, IFLA_VXLAN_GPE, *argv, *argv);
331 addattr_l(n, 1024, IFLA_VXLAN_GPE, NULL, 0);
332 } else if (matches(*argv, "help") == 0) {
333 explain();
334 return -1;
335 } else {
336 fprintf(stderr, "vxlan: unknown command \"%s\"?\n", *argv);
337 explain();
338 return -1;
339 }
340 argc--, argv++;
341 }
342
343 if (metadata && VXLAN_ATTRSET(attrs, IFLA_VXLAN_ID)) {
344 fprintf(stderr, "vxlan: both 'external' and vni cannot be specified\n");
345 return -1;
346 }
347
348 if (!metadata && !VXLAN_ATTRSET(attrs, IFLA_VXLAN_ID) && !set_op) {
349 fprintf(stderr, "vxlan: missing virtual network identifier\n");
350 return -1;
351 }
352
353 if ((gaddr || !IN6_IS_ADDR_UNSPECIFIED(&gaddr6)) &&
354 !VXLAN_ATTRSET(attrs, IFLA_VXLAN_LINK)) {
355 fprintf(stderr, "vxlan: 'group' requires 'dev' to be specified\n");
356 return -1;
357 }
358
359 if (!VXLAN_ATTRSET(attrs, IFLA_VXLAN_PORT) &&
360 VXLAN_ATTRSET(attrs, IFLA_VXLAN_GPE)) {
361 dstport = 4790;
362 } else if (!VXLAN_ATTRSET(attrs, IFLA_VXLAN_PORT) && !set_op) {
363 fprintf(stderr, "vxlan: destination port not specified\n"
364 "Will use Linux kernel default (non-standard value)\n");
365 fprintf(stderr,
366 "Use 'dstport 4789' to get the IANA assigned value\n"
367 "Use 'dstport 0' to get default and quiet this message\n");
368 }
369
370 if (VXLAN_ATTRSET(attrs, IFLA_VXLAN_ID))
371 addattr32(n, 1024, IFLA_VXLAN_ID, vni);
372 if (gaddr)
373 addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
374 else if (daddr)
375 addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4);
376 else if (!IN6_IS_ADDR_UNSPECIFIED(&gaddr6))
377 addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &gaddr6, sizeof(struct in6_addr));
378 else if (!IN6_IS_ADDR_UNSPECIFIED(&daddr6))
379 addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr));
380 else if (preferred_family == AF_INET)
381 addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4);
382 else if (preferred_family == AF_INET6)
383 addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr));
384
385 if (!set_op || VXLAN_ATTRSET(attrs, IFLA_VXLAN_LEARNING))
386 addattr8(n, 1024, IFLA_VXLAN_LEARNING, learning);
387
388 if (dstport)
389 addattr16(n, 1024, IFLA_VXLAN_PORT, htons(dstport));
390
391 return 0;
392 }
393
394 static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
395 {
396 __u32 vni;
397 unsigned int link;
398 __u8 tos;
399 __u32 maxaddr;
400 char s2[64];
401
402 if (!tb)
403 return;
404
405 if (!tb[IFLA_VXLAN_ID] ||
406 RTA_PAYLOAD(tb[IFLA_VXLAN_ID]) < sizeof(__u32))
407 return;
408
409 vni = rta_getattr_u32(tb[IFLA_VXLAN_ID]);
410 print_uint(PRINT_ANY, "id", "id %u ", vni);
411
412 if (tb[IFLA_VXLAN_GROUP]) {
413 __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]);
414
415 if (addr) {
416 if (IN_MULTICAST(ntohl(addr)))
417 print_string(PRINT_ANY,
418 "group",
419 "group %s ",
420 format_host(AF_INET, 4, &addr));
421 else
422 print_string(PRINT_ANY,
423 "remote",
424 "remote %s ",
425 format_host(AF_INET, 4, &addr));
426 }
427 } else if (tb[IFLA_VXLAN_GROUP6]) {
428 struct in6_addr addr;
429
430 memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
431 if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) {
432 if (IN6_IS_ADDR_MULTICAST(&addr))
433 print_string(PRINT_ANY,
434 "group6",
435 "group %s ",
436 format_host(AF_INET6,
437 sizeof(struct in6_addr),
438 &addr));
439 else
440 print_string(PRINT_ANY,
441 "remote6",
442 "remote %s ",
443 format_host(AF_INET6,
444 sizeof(struct in6_addr),
445 &addr));
446 }
447 }
448
449 if (tb[IFLA_VXLAN_LOCAL]) {
450 __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
451
452 if (addr)
453 print_string(PRINT_ANY,
454 "local",
455 "local %s ",
456 format_host(AF_INET, 4, &addr));
457 } else if (tb[IFLA_VXLAN_LOCAL6]) {
458 struct in6_addr addr;
459
460 memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
461 if (!IN6_IS_ADDR_UNSPECIFIED(&addr))
462 print_string(PRINT_ANY,
463 "local6",
464 "local %s ",
465 format_host(AF_INET6,
466 sizeof(struct in6_addr),
467 &addr));
468 }
469
470 if (tb[IFLA_VXLAN_LINK] &&
471 (link = rta_getattr_u32(tb[IFLA_VXLAN_LINK]))) {
472 const char *n = if_indextoname(link, s2);
473
474 if (n)
475 print_string(PRINT_ANY, "link", "dev %s ", n);
476 else
477 print_uint(PRINT_ANY, "link_index", "dev %u ", link);
478 }
479
480 if (tb[IFLA_VXLAN_PORT_RANGE]) {
481 const struct ifla_vxlan_port_range *r
482 = RTA_DATA(tb[IFLA_VXLAN_PORT_RANGE]);
483 if (is_json_context()) {
484 open_json_object("port_range");
485 print_uint(PRINT_JSON, "low", NULL, ntohs(r->low));
486 print_uint(PRINT_JSON, "high", NULL, ntohs(r->high));
487 close_json_object();
488 } else {
489 fprintf(f, "srcport %u %u ",
490 ntohs(r->low), ntohs(r->high));
491 }
492 }
493
494 if (tb[IFLA_VXLAN_PORT])
495 print_uint(PRINT_ANY,
496 "port",
497 "dstport %u ",
498 rta_getattr_be16(tb[IFLA_VXLAN_PORT]));
499
500 if (tb[IFLA_VXLAN_LEARNING]) {
501 __u8 learning = rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]);
502
503 print_bool(PRINT_JSON, "learning", NULL, learning);
504 if (!learning)
505 print_bool(PRINT_FP, NULL, "nolearning ", true);
506 }
507
508 if (tb[IFLA_VXLAN_PROXY] && rta_getattr_u8(tb[IFLA_VXLAN_PROXY]))
509 print_bool(PRINT_ANY, "proxy", "proxy ", true);
510
511 if (tb[IFLA_VXLAN_RSC] && rta_getattr_u8(tb[IFLA_VXLAN_RSC]))
512 print_bool(PRINT_ANY, "rsc", "rsc ", true);
513
514 if (tb[IFLA_VXLAN_L2MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L2MISS]))
515 print_bool(PRINT_ANY, "l2miss", "l2miss ", true);
516
517 if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS]))
518 print_bool(PRINT_ANY, "l3miss", "l3miss ", true);
519
520 if (tb[IFLA_VXLAN_TOS] &&
521 (tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) {
522 if (is_json_context()) {
523 print_0xhex(PRINT_JSON, "tos", "%#x", tos);
524 } else {
525 if (tos == 1)
526 fprintf(f, "tos %s ", "inherit");
527 else
528 fprintf(f, "tos %#x ", tos);
529 }
530 }
531
532 if (tb[IFLA_VXLAN_TTL]) {
533 __u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
534
535 if (ttl)
536 print_int(PRINT_ANY, "ttl", "ttl %d ", ttl);
537 else
538 print_int(PRINT_JSON, "ttl", NULL, ttl);
539 }
540
541 if (tb[IFLA_VXLAN_LABEL]) {
542 __u32 label = rta_getattr_u32(tb[IFLA_VXLAN_LABEL]);
543
544 if (label)
545 print_0xhex(PRINT_ANY,
546 "label",
547 "flowlabel %#x ",
548 ntohl(label));
549 }
550
551 if (tb[IFLA_VXLAN_AGEING]) {
552 __u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]);
553
554 if (age == 0)
555 print_uint(PRINT_ANY, "ageing", "ageing none ", 0);
556 else
557 print_uint(PRINT_ANY, "ageing", "ageing %u ", age);
558 }
559
560 if (tb[IFLA_VXLAN_LIMIT] &&
561 ((maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT])) != 0))
562 print_uint(PRINT_ANY, "limit", "maxaddr %u ", maxaddr);
563
564 if (tb[IFLA_VXLAN_UDP_CSUM]) {
565 __u8 udp_csum = rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]);
566
567 if (is_json_context()) {
568 print_bool(PRINT_ANY, "udp_csum", NULL, udp_csum);
569 } else {
570 if (!udp_csum)
571 fputs("no", f);
572 fputs("udpcsum ", f);
573 }
574 }
575
576 if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]) {
577 __u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]);
578
579 if (is_json_context()) {
580 print_bool(PRINT_ANY,
581 "udp_zero_csum6_tx", NULL, csum6);
582 } else {
583 if (!csum6)
584 fputs("no", f);
585 fputs("udp6zerocsumtx ", f);
586 }
587 }
588
589 if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) {
590 __u8 csum6 = rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]);
591
592 if (is_json_context()) {
593 print_bool(PRINT_ANY,
594 "udp_zero_csum6_rx",
595 NULL,
596 csum6);
597 } else {
598 if (!csum6)
599 fputs("no", f);
600 fputs("udp6zerocsumrx ", f);
601 }
602 }
603
604 if (tb[IFLA_VXLAN_REMCSUM_TX] &&
605 rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX]))
606 print_bool(PRINT_ANY, "remcsum_tx", "remcsumtx ", true);
607
608 if (tb[IFLA_VXLAN_REMCSUM_RX] &&
609 rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX]))
610 print_bool(PRINT_ANY, "remcsum_rx", "remcsumrx ", true);
611
612 if (tb[IFLA_VXLAN_COLLECT_METADATA] &&
613 rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA]))
614 print_bool(PRINT_ANY, "collect_metadata", "external ", true);
615
616 if (tb[IFLA_VXLAN_GBP])
617 print_bool(PRINT_ANY, "gbp", "gbp ", true);
618 if (tb[IFLA_VXLAN_GPE])
619 print_bool(PRINT_ANY, "gpe", "gpe ", true);
620 }
621
622 static void vxlan_print_help(struct link_util *lu, int argc, char **argv,
623 FILE *f)
624 {
625 print_explain(f);
626 }
627
628 struct link_util vxlan_link_util = {
629 .id = "vxlan",
630 .maxattr = IFLA_VXLAN_MAX,
631 .parse_opt = vxlan_parse_opt,
632 .print_opt = vxlan_print_opt,
633 .print_help = vxlan_print_help,
634 };