blob: aa4d5198d78d16bdc35583f479e85801752a9d7f [file] [log] [blame]
Stephen Hemmingera5494df2012-09-24 12:48:29 -07001/*
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
vadimk561e6502014-09-30 08:17:31 +030024static void print_explain(FILE *f)
25{
26 fprintf(f, "Usage: ... vxlan id VNI [ { group | remote } ADDR ] [ local ADDR ]\n");
27 fprintf(f, " [ ttl TTL ] [ tos TOS ] [ dev PHYS_DEV ]\n");
28 fprintf(f, " [ dstport PORT ] [ srcport MIN MAX ]\n");
29 fprintf(f, " [ [no]learning ] [ [no]proxy ] [ [no]rsc ]\n");
30 fprintf(f, " [ [no]l2miss ] [ [no]l3miss ]\n");
31 fprintf(f, " [ ageing SECONDS ] [ maxaddress NUMBER ]\n");
Tom Herbert666cdc52014-11-07 08:05:34 -080032 fprintf(f, " [ [no]udpcsum ] [ [no]udp6zerocsumtx ] [ [no]udp6zerocsumrx ]\n");
Tom Herbert35f59d82015-11-27 10:23:43 -080033 fprintf(f, " [ [no]remcsumtx ] [ [no]remcsumrx ]\n");
Paolo Abenie79c3272015-12-18 10:50:36 +010034 fprintf(f, " [ [no]external ] [ gbp ]\n");
vadimk561e6502014-09-30 08:17:31 +030035 fprintf(f, "\n");
36 fprintf(f, "Where: VNI := 0-16777215\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}
41
Stephen Hemmingera5494df2012-09-24 12:48:29 -070042static void explain(void)
43{
vadimk561e6502014-09-30 08:17:31 +030044 print_explain(stderr);
Stephen Hemmingera5494df2012-09-24 12:48:29 -070045}
46
47static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv,
48 struct nlmsghdr *n)
49{
50 __u32 vni = 0;
51 int vni_set = 0;
52 __u32 saddr = 0;
53 __u32 gaddr = 0;
Atzm Watanabe7cfa3802013-07-24 14:01:01 +090054 __u32 daddr = 0;
WANG Congaa574cd2013-10-16 22:03:48 -070055 struct in6_addr saddr6 = IN6ADDR_ANY_INIT;
56 struct in6_addr gaddr6 = IN6ADDR_ANY_INIT;
57 struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
Stephen Hemmingera5494df2012-09-24 12:48:29 -070058 unsigned link = 0;
59 __u8 tos = 0;
60 __u8 ttl = 0;
61 __u8 learning = 1;
David L Stevens1556e292012-12-12 10:02:19 -080062 __u8 proxy = 0;
63 __u8 rsc = 0;
64 __u8 l2miss = 0;
65 __u8 l3miss = 0;
Stephen Hemmingera5494df2012-09-24 12:48:29 -070066 __u8 noage = 0;
67 __u32 age = 0;
68 __u32 maxaddr = 0;
Stephen Hemminger514cdfb2014-01-10 15:17:06 -080069 __u16 dstport = 0;
Tom Herbert666cdc52014-11-07 08:05:34 -080070 __u8 udpcsum = 0;
71 __u8 udp6zerocsumtx = 0;
72 __u8 udp6zerocsumrx = 0;
Tom Herbert35f59d82015-11-27 10:23:43 -080073 __u8 remcsumtx = 0;
74 __u8 remcsumrx = 0;
Paolo Abenie79c3272015-12-18 10:50:36 +010075 __u8 metadata = 0;
Thomas Graf2eb90dc2015-01-15 14:54:25 +010076 __u8 gbp = 0;
Stephen Hemminger514cdfb2014-01-10 15:17:06 -080077 int dst_port_set = 0;
Stephen Hemminger2d596122012-10-09 23:39:17 -070078 struct ifla_vxlan_port_range range = { 0, 0 };
Stephen Hemmingera5494df2012-09-24 12:48:29 -070079
80 while (argc > 0) {
81 if (!matches(*argv, "id") ||
82 !matches(*argv, "vni")) {
83 NEXT_ARG();
84 if (get_u32(&vni, *argv, 0) ||
85 vni >= 1u << 24)
86 invarg("invalid id", *argv);
87 vni_set = 1;
88 } else if (!matches(*argv, "group")) {
89 NEXT_ARG();
WANG Congaa574cd2013-10-16 22:03:48 -070090 if (!inet_get_addr(*argv, &gaddr, &gaddr6)) {
91 fprintf(stderr, "Invalid address \"%s\"\n", *argv);
92 return -1;
93 }
94 if (!IN6_IS_ADDR_MULTICAST(&gaddr6) && !IN_MULTICAST(ntohl(gaddr)))
Atzm Watanabe7cfa3802013-07-24 14:01:01 +090095 invarg("invalid group address", *argv);
96 } else if (!matches(*argv, "remote")) {
97 NEXT_ARG();
WANG Congaa574cd2013-10-16 22:03:48 -070098 if (!inet_get_addr(*argv, &daddr, &daddr6)) {
99 fprintf(stderr, "Invalid address \"%s\"\n", *argv);
100 return -1;
101 }
102 if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
Atzm Watanabe7cfa3802013-07-24 14:01:01 +0900103 invarg("invalid remote address", *argv);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700104 } else if (!matches(*argv, "local")) {
105 NEXT_ARG();
WANG Congaa574cd2013-10-16 22:03:48 -0700106 if (strcmp(*argv, "any")) {
107 if (!inet_get_addr(*argv, &saddr, &saddr6)) {
108 fprintf(stderr, "Invalid address \"%s\"\n", *argv);
109 return -1;
110 }
111 }
112
113 if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6))
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700114 invarg("invalid local address", *argv);
115 } else if (!matches(*argv, "dev")) {
116 NEXT_ARG();
117 link = if_nametoindex(*argv);
Cong Wang0cb6bb52014-06-03 16:06:45 -0700118 if (link == 0) {
119 fprintf(stderr, "Cannot find device \"%s\"\n",
120 *argv);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700121 exit(-1);
Cong Wang0cb6bb52014-06-03 16:06:45 -0700122 }
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700123 } else if (!matches(*argv, "ttl") ||
124 !matches(*argv, "hoplimit")) {
125 unsigned uval;
126
127 NEXT_ARG();
128 if (strcmp(*argv, "inherit") != 0) {
129 if (get_unsigned(&uval, *argv, 0))
Stephen Hemminger2d596122012-10-09 23:39:17 -0700130 invarg("invalid TTL", *argv);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700131 if (uval > 255)
Stephen Hemminger2d596122012-10-09 23:39:17 -0700132 invarg("TTL must be <= 255", *argv);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700133 ttl = uval;
134 }
135 } else if (!matches(*argv, "tos") ||
136 !matches(*argv, "dsfield")) {
137 __u32 uval;
138
139 NEXT_ARG();
140 if (strcmp(*argv, "inherit") != 0) {
141 if (rtnl_dsfield_a2n(&uval, *argv))
142 invarg("bad TOS value", *argv);
143 tos = uval;
144 } else
145 tos = 1;
146 } else if (!matches(*argv, "ageing")) {
147 NEXT_ARG();
148 if (strcmp(*argv, "none") == 0)
149 noage = 1;
150 else if (get_u32(&age, *argv, 0))
Stephen Hemminger2d596122012-10-09 23:39:17 -0700151 invarg("ageing timer", *argv);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700152 } else if (!matches(*argv, "maxaddress")) {
153 NEXT_ARG();
154 if (strcmp(*argv, "unlimited") == 0)
155 maxaddr = 0;
156 else if (get_u32(&maxaddr, *argv, 0))
Stephen Hemminger2d596122012-10-09 23:39:17 -0700157 invarg("max addresses", *argv);
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800158 } else if (!matches(*argv, "port") ||
159 !matches(*argv, "srcport")) {
Stephen Hemminger2d596122012-10-09 23:39:17 -0700160 __u16 minport, maxport;
161 NEXT_ARG();
162 if (get_u16(&minport, *argv, 0))
163 invarg("min port", *argv);
164 NEXT_ARG();
165 if (get_u16(&maxport, *argv, 0))
166 invarg("max port", *argv);
167 range.low = htons(minport);
168 range.high = htons(maxport);
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800169 } else if (!matches(*argv, "dstport")){
170 NEXT_ARG();
171 if (get_u16(&dstport, *argv, 0))
172 invarg("dst port", *argv);
173 dst_port_set = 1;
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700174 } else if (!matches(*argv, "nolearning")) {
175 learning = 0;
176 } else if (!matches(*argv, "learning")) {
177 learning = 1;
David L Stevens1556e292012-12-12 10:02:19 -0800178 } else if (!matches(*argv, "noproxy")) {
179 proxy = 0;
180 } else if (!matches(*argv, "proxy")) {
181 proxy = 1;
182 } else if (!matches(*argv, "norsc")) {
183 rsc = 0;
184 } else if (!matches(*argv, "rsc")) {
185 rsc = 1;
186 } else if (!matches(*argv, "nol2miss")) {
187 l2miss = 0;
188 } else if (!matches(*argv, "l2miss")) {
189 l2miss = 1;
190 } else if (!matches(*argv, "nol3miss")) {
191 l3miss = 0;
192 } else if (!matches(*argv, "l3miss")) {
193 l3miss = 1;
Tom Herbert666cdc52014-11-07 08:05:34 -0800194 } else if (!matches(*argv, "udpcsum")) {
195 udpcsum = 1;
196 } else if (!matches(*argv, "noudpcsum")) {
197 udpcsum = 0;
198 } else if (!matches(*argv, "udp6zerocsumtx")) {
199 udp6zerocsumtx = 1;
200 } else if (!matches(*argv, "noudp6zerocsumtx")) {
201 udp6zerocsumtx = 0;
202 } else if (!matches(*argv, "udp6zerocsumrx")) {
203 udp6zerocsumrx = 1;
204 } else if (!matches(*argv, "noudp6zerocsumrx")) {
205 udp6zerocsumrx = 0;
Tom Herbert35f59d82015-11-27 10:23:43 -0800206 } else if (!matches(*argv, "remcsumtx")) {
207 remcsumtx = 1;
208 } else if (!matches(*argv, "noremcsumtx")) {
209 remcsumtx = 0;
210 } else if (!matches(*argv, "remcsumrx")) {
211 remcsumrx = 1;
212 } else if (!matches(*argv, "noremcsumrx")) {
213 remcsumrx = 0;
Paolo Abenie79c3272015-12-18 10:50:36 +0100214 } else if (!matches(*argv, "external")) {
215 metadata = 1;
216 } else if (!matches(*argv, "noexternal")) {
217 metadata = 0;
Thomas Graf2eb90dc2015-01-15 14:54:25 +0100218 } else if (!matches(*argv, "gbp")) {
219 gbp = 1;
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700220 } else if (matches(*argv, "help") == 0) {
221 explain();
222 return -1;
223 } else {
Kees van Reeuwijk14645ec2013-02-08 03:32:36 +0000224 fprintf(stderr, "vxlan: unknown command \"%s\"?\n", *argv);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700225 explain();
226 return -1;
227 }
228 argc--, argv++;
229 }
Stephen Hemminger2a126a82013-05-15 13:41:49 -0700230
Paolo Abenie79c3272015-12-18 10:50:36 +0100231 if (metadata && vni_set) {
232 fprintf(stderr, "vxlan: both 'external' and vni cannot be specified\n");
233 return -1;
234 }
235
236 if (!metadata && !vni_set) {
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700237 fprintf(stderr, "vxlan: missing virtual network identifier\n");
238 return -1;
239 }
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800240
WANG Congaa574cd2013-10-16 22:03:48 -0700241 if ((gaddr && daddr) ||
242 (memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) &&
243 memcmp(&daddr6, &in6addr_any, sizeof(daddr6)))) {
Atzm Watanabe7cfa3802013-07-24 14:01:01 +0900244 fprintf(stderr, "vxlan: both group and remote cannot be specified\n");
245 return -1;
246 }
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800247
248 if (!dst_port_set) {
249 fprintf(stderr, "vxlan: destination port not specified\n"
250 "Will use Linux kernel default (non-standard value)\n");
Stephen Hemminger06125192014-02-17 10:55:31 -0800251 fprintf(stderr,
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800252 "Use 'dstport 4789' to get the IANA assigned value\n"
253 "Use 'dstport 0' to get default and quiet this message\n");
254 }
255
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700256 addattr32(n, 1024, IFLA_VXLAN_ID, vni);
Stephen Hemmingerb64da5a2012-10-19 13:25:17 -0700257 if (gaddr)
258 addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4);
Atzm Watanabe7cfa3802013-07-24 14:01:01 +0900259 else if (daddr)
260 addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4);
WANG Congaa574cd2013-10-16 22:03:48 -0700261 if (memcmp(&gaddr6, &in6addr_any, sizeof(gaddr6)) != 0)
262 addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &gaddr6, sizeof(struct in6_addr));
263 else if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0)
264 addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr));
265
Stephen Hemmingerb64da5a2012-10-19 13:25:17 -0700266 if (saddr)
267 addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4);
WANG Congaa574cd2013-10-16 22:03:48 -0700268 else if (memcmp(&saddr6, &in6addr_any, sizeof(saddr6)) != 0)
269 addattr_l(n, 1024, IFLA_VXLAN_LOCAL6, &saddr6, sizeof(struct in6_addr));
270
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700271 if (link)
272 addattr32(n, 1024, IFLA_VXLAN_LINK, link);
273 addattr8(n, 1024, IFLA_VXLAN_TTL, ttl);
274 addattr8(n, 1024, IFLA_VXLAN_TOS, tos);
275 addattr8(n, 1024, IFLA_VXLAN_LEARNING, learning);
David L Stevens1556e292012-12-12 10:02:19 -0800276 addattr8(n, 1024, IFLA_VXLAN_PROXY, proxy);
277 addattr8(n, 1024, IFLA_VXLAN_RSC, rsc);
278 addattr8(n, 1024, IFLA_VXLAN_L2MISS, l2miss);
279 addattr8(n, 1024, IFLA_VXLAN_L3MISS, l3miss);
Tom Herbert666cdc52014-11-07 08:05:34 -0800280 addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, udpcsum);
281 addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, udp6zerocsumtx);
282 addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, udp6zerocsumrx);
Tom Herbert35f59d82015-11-27 10:23:43 -0800283 addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, remcsumtx);
284 addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, remcsumrx);
Paolo Abenie79c3272015-12-18 10:50:36 +0100285 addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA, metadata);
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800286
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700287 if (noage)
288 addattr32(n, 1024, IFLA_VXLAN_AGEING, 0);
289 else if (age)
290 addattr32(n, 1024, IFLA_VXLAN_AGEING, age);
291 if (maxaddr)
292 addattr32(n, 1024, IFLA_VXLAN_LIMIT, maxaddr);
Stephen Hemminger2d596122012-10-09 23:39:17 -0700293 if (range.low || range.high)
294 addattr_l(n, 1024, IFLA_VXLAN_PORT_RANGE,
295 &range, sizeof(range));
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800296 if (dstport)
297 addattr16(n, 1024, IFLA_VXLAN_PORT, htons(dstport));
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700298
Thomas Graf2eb90dc2015-01-15 14:54:25 +0100299 if (gbp)
300 addattr_l(n, 1024, IFLA_VXLAN_GBP, NULL, 0);
301
302
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700303 return 0;
304}
305
306static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
307{
308 __u32 vni;
309 unsigned link;
Stephen Hemminger2d596122012-10-09 23:39:17 -0700310 __u8 tos;
311 __u32 maxaddr;
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700312 char s1[1024];
313 char s2[64];
314
315 if (!tb)
316 return;
317
318 if (!tb[IFLA_VXLAN_ID] ||
319 RTA_PAYLOAD(tb[IFLA_VXLAN_ID]) < sizeof(__u32))
320 return;
321
322 vni = rta_getattr_u32(tb[IFLA_VXLAN_ID]);
323 fprintf(f, "id %u ", vni);
324
325 if (tb[IFLA_VXLAN_GROUP]) {
Stephen Hemmingerb64da5a2012-10-19 13:25:17 -0700326 __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]);
Atzm Watanabe7cfa3802013-07-24 14:01:01 +0900327 if (addr) {
328 if (IN_MULTICAST(ntohl(addr)))
329 fprintf(f, "group %s ",
330 format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
331 else
332 fprintf(f, "remote %s ",
333 format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
334 }
WANG Congaa574cd2013-10-16 22:03:48 -0700335 } else if (tb[IFLA_VXLAN_GROUP6]) {
336 struct in6_addr addr;
337 memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr));
338 if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
339 if (IN6_IS_ADDR_MULTICAST(&addr))
340 fprintf(f, "group %s ",
341 format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
342 else
343 fprintf(f, "remote %s ",
344 format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
345 }
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700346 }
347
348 if (tb[IFLA_VXLAN_LOCAL]) {
Stephen Hemmingerb64da5a2012-10-19 13:25:17 -0700349 __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700350 if (addr)
David L Stevens1556e292012-12-12 10:02:19 -0800351 fprintf(f, "local %s ",
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700352 format_host(AF_INET, 4, &addr, s1, sizeof(s1)));
WANG Congaa574cd2013-10-16 22:03:48 -0700353 } else if (tb[IFLA_VXLAN_LOCAL6]) {
354 struct in6_addr addr;
355 memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
356 if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
357 fprintf(f, "local %s ",
358 format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1)));
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700359 }
360
361 if (tb[IFLA_VXLAN_LINK] &&
362 (link = rta_getattr_u32(tb[IFLA_VXLAN_LINK]))) {
363 const char *n = if_indextoname(link, s2);
364
365 if (n)
366 fprintf(f, "dev %s ", n);
367 else
368 fprintf(f, "dev %u ", link);
369 }
370
Stephen Hemminger2d596122012-10-09 23:39:17 -0700371 if (tb[IFLA_VXLAN_PORT_RANGE]) {
372 const struct ifla_vxlan_port_range *r
373 = RTA_DATA(tb[IFLA_VXLAN_PORT_RANGE]);
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800374 fprintf(f, "srcport %u %u ", ntohs(r->low), ntohs(r->high));
David L Stevens1556e292012-12-12 10:02:19 -0800375 }
Stephen Hemminger2d596122012-10-09 23:39:17 -0700376
Stephen Hemminger514cdfb2014-01-10 15:17:06 -0800377 if (tb[IFLA_VXLAN_PORT])
378 fprintf(f, "dstport %u ",
379 ntohs(rta_getattr_u16(tb[IFLA_VXLAN_PORT])));
380
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700381 if (tb[IFLA_VXLAN_LEARNING] &&
382 !rta_getattr_u8(tb[IFLA_VXLAN_LEARNING]))
383 fputs("nolearning ", f);
David L Stevens1556e292012-12-12 10:02:19 -0800384
385 if (tb[IFLA_VXLAN_PROXY] && rta_getattr_u8(tb[IFLA_VXLAN_PROXY]))
386 fputs("proxy ", f);
387
388 if (tb[IFLA_VXLAN_RSC] && rta_getattr_u8(tb[IFLA_VXLAN_RSC]))
389 fputs("rsc ", f);
390
391 if (tb[IFLA_VXLAN_L2MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L2MISS]))
392 fputs("l2miss ", f);
393
394 if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS]))
395 fputs("l3miss ", f);
396
Stephen Hemminger2d596122012-10-09 23:39:17 -0700397 if (tb[IFLA_VXLAN_TOS] &&
398 (tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) {
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700399 if (tos == 1)
400 fprintf(f, "tos inherit ");
401 else
402 fprintf(f, "tos %#x ", tos);
403 }
404
405 if (tb[IFLA_VXLAN_TTL]) {
406 __u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]);
407 if (ttl)
408 fprintf(f, "ttl %d ", ttl);
409 }
410
411 if (tb[IFLA_VXLAN_AGEING]) {
412 __u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]);
413 if (age == 0)
414 fprintf(f, "ageing none ");
415 else
416 fprintf(f, "ageing %u ", age);
417 }
Stephen Hemminger2d596122012-10-09 23:39:17 -0700418
419 if (tb[IFLA_VXLAN_LIMIT] &&
Nicolas Dichtel6ad53992014-09-09 16:55:11 +0200420 ((maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT])) != 0))
Stephen Hemminger2d596122012-10-09 23:39:17 -0700421 fprintf(f, "maxaddr %u ", maxaddr);
Tom Herbert666cdc52014-11-07 08:05:34 -0800422
423 if (tb[IFLA_VXLAN_UDP_CSUM] && rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM]))
424 fputs("udpcsum ", f);
425
426 if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX] &&
427 rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]))
428 fputs("udp6zerocsumtx ", f);
429
430 if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX] &&
431 rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
432 fputs("udp6zerocsumrx ", f);
Thomas Graf2eb90dc2015-01-15 14:54:25 +0100433
Tom Herbert35f59d82015-11-27 10:23:43 -0800434 if (tb[IFLA_VXLAN_REMCSUM_TX] &&
435 rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX]))
436 fputs("remcsumtx ", f);
437
438 if (tb[IFLA_VXLAN_REMCSUM_RX] &&
439 rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX]))
440 fputs("remcsumrx ", f);
441
Paolo Abenie79c3272015-12-18 10:50:36 +0100442 if (tb[IFLA_VXLAN_COLLECT_METADATA] &&
443 rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA]))
444 fputs("external ", f);
445
Thomas Graf2eb90dc2015-01-15 14:54:25 +0100446 if (tb[IFLA_VXLAN_GBP])
447 fputs("gbp ", f);
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700448}
449
vadimk561e6502014-09-30 08:17:31 +0300450static void vxlan_print_help(struct link_util *lu, int argc, char **argv,
451 FILE *f)
452{
453 print_explain(f);
454}
455
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700456struct link_util vxlan_link_util = {
457 .id = "vxlan",
458 .maxattr = IFLA_VXLAN_MAX,
459 .parse_opt = vxlan_parse_opt,
460 .print_opt = vxlan_print_opt,
vadimk561e6502014-09-30 08:17:31 +0300461 .print_help = vxlan_print_help,
Stephen Hemmingera5494df2012-09-24 12:48:29 -0700462};