Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 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 | |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 24 | static void print_explain(FILE *f) |
| 25 | { |
Thomas Faivre | 5cd64c9 | 2016-01-14 18:10:19 +0100 | [diff] [blame] | 26 | fprintf(f, "Usage: ... vxlan id VNI [ { group | remote } IP_ADDRESS ] [ local ADDR ]\n"); |
Daniel Borkmann | f8eb79a | 2016-03-24 16:49:55 +0100 | [diff] [blame] | 27 | fprintf(f, " [ ttl TTL ] [ tos TOS ] [ flowlabel LABEL ] [ dev PHYS_DEV ]\n"); |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 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 Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 32 | fprintf(f, " [ [no]udpcsum ] [ [no]udp6zerocsumtx ] [ [no]udp6zerocsumrx ]\n"); |
Tom Herbert | 35f59d8 | 2015-11-27 10:23:43 -0800 | [diff] [blame] | 33 | fprintf(f, " [ [no]remcsumtx ] [ [no]remcsumrx ]\n"); |
Jiri Benc | 346410b | 2016-04-07 14:36:29 +0200 | [diff] [blame] | 34 | fprintf(f, " [ [no]external ] [ gbp ] [ gpe ]\n"); |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 35 | fprintf(f, "\n"); |
Daniel Borkmann | f8eb79a | 2016-03-24 16:49:55 +0100 | [diff] [blame] | 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 | fprintf(f, " LABEL := 0-1048575\n"); |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 41 | } |
| 42 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 43 | static void explain(void) |
| 44 | { |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 45 | print_explain(stderr); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, |
| 49 | struct nlmsghdr *n) |
| 50 | { |
| 51 | __u32 vni = 0; |
| 52 | int vni_set = 0; |
| 53 | __u32 saddr = 0; |
| 54 | __u32 gaddr = 0; |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 55 | __u32 daddr = 0; |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 56 | struct in6_addr saddr6 = IN6ADDR_ANY_INIT; |
| 57 | struct in6_addr gaddr6 = IN6ADDR_ANY_INIT; |
| 58 | struct in6_addr daddr6 = IN6ADDR_ANY_INIT; |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 59 | unsigned int link = 0; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 60 | __u8 tos = 0; |
| 61 | __u8 ttl = 0; |
Daniel Borkmann | f8eb79a | 2016-03-24 16:49:55 +0100 | [diff] [blame] | 62 | __u32 label = 0; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 63 | __u8 learning = 1; |
David L Stevens | 1556e29 | 2012-12-12 10:02:19 -0800 | [diff] [blame] | 64 | __u8 proxy = 0; |
| 65 | __u8 rsc = 0; |
| 66 | __u8 l2miss = 0; |
| 67 | __u8 l3miss = 0; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 68 | __u8 noage = 0; |
| 69 | __u32 age = 0; |
| 70 | __u32 maxaddr = 0; |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 71 | __u16 dstport = 0; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 72 | __u8 udpcsum = 0; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 73 | bool udpcsum_set = false; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 74 | __u8 udp6zerocsumtx = 0; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 75 | bool udp6zerocsumtx_set = false; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 76 | __u8 udp6zerocsumrx = 0; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 77 | bool udp6zerocsumrx_set = false; |
Tom Herbert | 35f59d8 | 2015-11-27 10:23:43 -0800 | [diff] [blame] | 78 | __u8 remcsumtx = 0; |
| 79 | __u8 remcsumrx = 0; |
Paolo Abeni | e79c327 | 2015-12-18 10:50:36 +0100 | [diff] [blame] | 80 | __u8 metadata = 0; |
Thomas Graf | 2eb90dc | 2015-01-15 14:54:25 +0100 | [diff] [blame] | 81 | __u8 gbp = 0; |
Jiri Benc | 346410b | 2016-04-07 14:36:29 +0200 | [diff] [blame] | 82 | __u8 gpe = 0; |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 83 | int dst_port_set = 0; |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 84 | struct ifla_vxlan_port_range range = { 0, 0 }; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 85 | |
| 86 | while (argc > 0) { |
| 87 | if (!matches(*argv, "id") || |
| 88 | !matches(*argv, "vni")) { |
| 89 | NEXT_ARG(); |
| 90 | if (get_u32(&vni, *argv, 0) || |
| 91 | vni >= 1u << 24) |
| 92 | invarg("invalid id", *argv); |
| 93 | vni_set = 1; |
| 94 | } else if (!matches(*argv, "group")) { |
| 95 | NEXT_ARG(); |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 96 | if (!inet_get_addr(*argv, &gaddr, &gaddr6)) { |
| 97 | fprintf(stderr, "Invalid address \"%s\"\n", *argv); |
| 98 | return -1; |
| 99 | } |
| 100 | if (!IN6_IS_ADDR_MULTICAST(&gaddr6) && !IN_MULTICAST(ntohl(gaddr))) |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 101 | invarg("invalid group address", *argv); |
| 102 | } else if (!matches(*argv, "remote")) { |
| 103 | NEXT_ARG(); |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 104 | if (!inet_get_addr(*argv, &daddr, &daddr6)) { |
| 105 | fprintf(stderr, "Invalid address \"%s\"\n", *argv); |
| 106 | return -1; |
| 107 | } |
| 108 | if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr))) |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 109 | invarg("invalid remote address", *argv); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 110 | } else if (!matches(*argv, "local")) { |
| 111 | NEXT_ARG(); |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 112 | if (strcmp(*argv, "any")) { |
| 113 | if (!inet_get_addr(*argv, &saddr, &saddr6)) { |
| 114 | fprintf(stderr, "Invalid address \"%s\"\n", *argv); |
| 115 | return -1; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if (IN_MULTICAST(ntohl(saddr)) || IN6_IS_ADDR_MULTICAST(&saddr6)) |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 120 | invarg("invalid local address", *argv); |
| 121 | } else if (!matches(*argv, "dev")) { |
| 122 | NEXT_ARG(); |
| 123 | link = if_nametoindex(*argv); |
Cong Wang | 0cb6bb5 | 2014-06-03 16:06:45 -0700 | [diff] [blame] | 124 | if (link == 0) { |
| 125 | fprintf(stderr, "Cannot find device \"%s\"\n", |
| 126 | *argv); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 127 | exit(-1); |
Cong Wang | 0cb6bb5 | 2014-06-03 16:06:45 -0700 | [diff] [blame] | 128 | } |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 129 | } else if (!matches(*argv, "ttl") || |
| 130 | !matches(*argv, "hoplimit")) { |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 131 | unsigned int uval; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 132 | |
| 133 | NEXT_ARG(); |
| 134 | if (strcmp(*argv, "inherit") != 0) { |
| 135 | if (get_unsigned(&uval, *argv, 0)) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 136 | invarg("invalid TTL", *argv); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 137 | if (uval > 255) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 138 | invarg("TTL must be <= 255", *argv); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 139 | ttl = uval; |
| 140 | } |
| 141 | } else if (!matches(*argv, "tos") || |
| 142 | !matches(*argv, "dsfield")) { |
| 143 | __u32 uval; |
| 144 | |
| 145 | NEXT_ARG(); |
| 146 | if (strcmp(*argv, "inherit") != 0) { |
| 147 | if (rtnl_dsfield_a2n(&uval, *argv)) |
| 148 | invarg("bad TOS value", *argv); |
| 149 | tos = uval; |
| 150 | } else |
| 151 | tos = 1; |
Daniel Borkmann | f8eb79a | 2016-03-24 16:49:55 +0100 | [diff] [blame] | 152 | } else if (!matches(*argv, "label") || |
| 153 | !matches(*argv, "flowlabel")) { |
| 154 | __u32 uval; |
| 155 | |
| 156 | NEXT_ARG(); |
| 157 | if (get_u32(&uval, *argv, 0) || |
| 158 | (uval & ~LABEL_MAX_MASK)) |
| 159 | invarg("invalid flowlabel", *argv); |
| 160 | label = htonl(uval); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 161 | } else if (!matches(*argv, "ageing")) { |
| 162 | NEXT_ARG(); |
| 163 | if (strcmp(*argv, "none") == 0) |
| 164 | noage = 1; |
| 165 | else if (get_u32(&age, *argv, 0)) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 166 | invarg("ageing timer", *argv); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 167 | } else if (!matches(*argv, "maxaddress")) { |
| 168 | NEXT_ARG(); |
| 169 | if (strcmp(*argv, "unlimited") == 0) |
| 170 | maxaddr = 0; |
| 171 | else if (get_u32(&maxaddr, *argv, 0)) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 172 | invarg("max addresses", *argv); |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 173 | } else if (!matches(*argv, "port") || |
| 174 | !matches(*argv, "srcport")) { |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 175 | NEXT_ARG(); |
Sabrina Dubroca | 9f7401f | 2016-06-03 16:45:46 +0200 | [diff] [blame] | 176 | if (get_be16(&range.low, *argv, 0)) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 177 | invarg("min port", *argv); |
| 178 | NEXT_ARG(); |
Sabrina Dubroca | 9f7401f | 2016-06-03 16:45:46 +0200 | [diff] [blame] | 179 | if (get_be16(&range.high, *argv, 0)) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 180 | invarg("max port", *argv); |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 181 | } else if (!matches(*argv, "dstport")) { |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 182 | NEXT_ARG(); |
| 183 | if (get_u16(&dstport, *argv, 0)) |
| 184 | invarg("dst port", *argv); |
| 185 | dst_port_set = 1; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 186 | } else if (!matches(*argv, "nolearning")) { |
| 187 | learning = 0; |
| 188 | } else if (!matches(*argv, "learning")) { |
| 189 | learning = 1; |
David L Stevens | 1556e29 | 2012-12-12 10:02:19 -0800 | [diff] [blame] | 190 | } else if (!matches(*argv, "noproxy")) { |
| 191 | proxy = 0; |
| 192 | } else if (!matches(*argv, "proxy")) { |
| 193 | proxy = 1; |
| 194 | } else if (!matches(*argv, "norsc")) { |
| 195 | rsc = 0; |
| 196 | } else if (!matches(*argv, "rsc")) { |
| 197 | rsc = 1; |
| 198 | } else if (!matches(*argv, "nol2miss")) { |
| 199 | l2miss = 0; |
| 200 | } else if (!matches(*argv, "l2miss")) { |
| 201 | l2miss = 1; |
| 202 | } else if (!matches(*argv, "nol3miss")) { |
| 203 | l3miss = 0; |
| 204 | } else if (!matches(*argv, "l3miss")) { |
| 205 | l3miss = 1; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 206 | } else if (!matches(*argv, "udpcsum")) { |
| 207 | udpcsum = 1; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 208 | udpcsum_set = true; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 209 | } else if (!matches(*argv, "noudpcsum")) { |
| 210 | udpcsum = 0; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 211 | udpcsum_set = true; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 212 | } else if (!matches(*argv, "udp6zerocsumtx")) { |
| 213 | udp6zerocsumtx = 1; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 214 | udp6zerocsumtx_set = true; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 215 | } else if (!matches(*argv, "noudp6zerocsumtx")) { |
| 216 | udp6zerocsumtx = 0; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 217 | udp6zerocsumtx_set = true; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 218 | } else if (!matches(*argv, "udp6zerocsumrx")) { |
| 219 | udp6zerocsumrx = 1; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 220 | udp6zerocsumrx_set = true; |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 221 | } else if (!matches(*argv, "noudp6zerocsumrx")) { |
| 222 | udp6zerocsumrx = 0; |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 223 | udp6zerocsumrx_set = true; |
Tom Herbert | 35f59d8 | 2015-11-27 10:23:43 -0800 | [diff] [blame] | 224 | } else if (!matches(*argv, "remcsumtx")) { |
| 225 | remcsumtx = 1; |
| 226 | } else if (!matches(*argv, "noremcsumtx")) { |
| 227 | remcsumtx = 0; |
| 228 | } else if (!matches(*argv, "remcsumrx")) { |
| 229 | remcsumrx = 1; |
| 230 | } else if (!matches(*argv, "noremcsumrx")) { |
| 231 | remcsumrx = 0; |
Paolo Abeni | e79c327 | 2015-12-18 10:50:36 +0100 | [diff] [blame] | 232 | } else if (!matches(*argv, "external")) { |
| 233 | metadata = 1; |
Jiri Benc | 44df459 | 2016-04-07 14:36:27 +0200 | [diff] [blame] | 234 | learning = 0; |
Paolo Abeni | e79c327 | 2015-12-18 10:50:36 +0100 | [diff] [blame] | 235 | } else if (!matches(*argv, "noexternal")) { |
| 236 | metadata = 0; |
Thomas Graf | 2eb90dc | 2015-01-15 14:54:25 +0100 | [diff] [blame] | 237 | } else if (!matches(*argv, "gbp")) { |
| 238 | gbp = 1; |
Jiri Benc | 346410b | 2016-04-07 14:36:29 +0200 | [diff] [blame] | 239 | } else if (!matches(*argv, "gpe")) { |
| 240 | gpe = 1; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 241 | } else if (matches(*argv, "help") == 0) { |
| 242 | explain(); |
| 243 | return -1; |
| 244 | } else { |
Kees van Reeuwijk | 14645ec | 2013-02-08 03:32:36 +0000 | [diff] [blame] | 245 | fprintf(stderr, "vxlan: unknown command \"%s\"?\n", *argv); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 246 | explain(); |
| 247 | return -1; |
| 248 | } |
| 249 | argc--, argv++; |
| 250 | } |
Stephen Hemminger | 2a126a8 | 2013-05-15 13:41:49 -0700 | [diff] [blame] | 251 | |
Paolo Abeni | e79c327 | 2015-12-18 10:50:36 +0100 | [diff] [blame] | 252 | if (metadata && vni_set) { |
| 253 | fprintf(stderr, "vxlan: both 'external' and vni cannot be specified\n"); |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | if (!metadata && !vni_set) { |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 258 | fprintf(stderr, "vxlan: missing virtual network identifier\n"); |
| 259 | return -1; |
| 260 | } |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 261 | |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 262 | if ((gaddr && daddr) || |
Jiri Benc | 1f4c51c | 2016-09-05 11:35:27 +0200 | [diff] [blame] | 263 | (!IN6_IS_ADDR_UNSPECIFIED(&gaddr6) && |
| 264 | !IN6_IS_ADDR_UNSPECIFIED(&daddr6))) { |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 265 | fprintf(stderr, "vxlan: both group and remote cannot be specified\n"); |
| 266 | return -1; |
| 267 | } |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 268 | |
Jiri Benc | e2cfe55 | 2016-09-05 11:35:28 +0200 | [diff] [blame] | 269 | if ((gaddr || !IN6_IS_ADDR_UNSPECIFIED(&gaddr6)) && !link) { |
| 270 | fprintf(stderr, "vxlan: 'group' requires 'dev' to be specified\n"); |
| 271 | return -1; |
| 272 | } |
| 273 | |
Jiri Benc | 346410b | 2016-04-07 14:36:29 +0200 | [diff] [blame] | 274 | if (!dst_port_set && gpe) { |
| 275 | dstport = 4790; |
| 276 | } else if (!dst_port_set) { |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 277 | fprintf(stderr, "vxlan: destination port not specified\n" |
| 278 | "Will use Linux kernel default (non-standard value)\n"); |
Stephen Hemminger | 0612519 | 2014-02-17 10:55:31 -0800 | [diff] [blame] | 279 | fprintf(stderr, |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 280 | "Use 'dstport 4789' to get the IANA assigned value\n" |
| 281 | "Use 'dstport 0' to get default and quiet this message\n"); |
| 282 | } |
| 283 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 284 | addattr32(n, 1024, IFLA_VXLAN_ID, vni); |
Stephen Hemminger | b64da5a | 2012-10-19 13:25:17 -0700 | [diff] [blame] | 285 | if (gaddr) |
| 286 | addattr_l(n, 1024, IFLA_VXLAN_GROUP, &gaddr, 4); |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 287 | else if (daddr) |
| 288 | addattr_l(n, 1024, IFLA_VXLAN_GROUP, &daddr, 4); |
Jiri Benc | 1f4c51c | 2016-09-05 11:35:27 +0200 | [diff] [blame] | 289 | if (!IN6_IS_ADDR_UNSPECIFIED(&gaddr6)) |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 290 | addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &gaddr6, sizeof(struct in6_addr)); |
Jiri Benc | 1f4c51c | 2016-09-05 11:35:27 +0200 | [diff] [blame] | 291 | else if (!IN6_IS_ADDR_UNSPECIFIED(&daddr6)) |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 292 | addattr_l(n, 1024, IFLA_VXLAN_GROUP6, &daddr6, sizeof(struct in6_addr)); |
| 293 | |
Stephen Hemminger | b64da5a | 2012-10-19 13:25:17 -0700 | [diff] [blame] | 294 | if (saddr) |
| 295 | addattr_l(n, 1024, IFLA_VXLAN_LOCAL, &saddr, 4); |
Jiri Benc | 1f4c51c | 2016-09-05 11:35:27 +0200 | [diff] [blame] | 296 | else if (!IN6_IS_ADDR_UNSPECIFIED(&saddr6)) |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 297 | addattr_l(n, 1024, IFLA_VXLAN_LOCAL6, &saddr6, sizeof(struct in6_addr)); |
| 298 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 299 | if (link) |
| 300 | addattr32(n, 1024, IFLA_VXLAN_LINK, link); |
Daniel Borkmann | f8eb79a | 2016-03-24 16:49:55 +0100 | [diff] [blame] | 301 | addattr32(n, 1024, IFLA_VXLAN_LABEL, label); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 302 | addattr8(n, 1024, IFLA_VXLAN_TTL, ttl); |
| 303 | addattr8(n, 1024, IFLA_VXLAN_TOS, tos); |
| 304 | addattr8(n, 1024, IFLA_VXLAN_LEARNING, learning); |
David L Stevens | 1556e29 | 2012-12-12 10:02:19 -0800 | [diff] [blame] | 305 | addattr8(n, 1024, IFLA_VXLAN_PROXY, proxy); |
| 306 | addattr8(n, 1024, IFLA_VXLAN_RSC, rsc); |
| 307 | addattr8(n, 1024, IFLA_VXLAN_L2MISS, l2miss); |
| 308 | addattr8(n, 1024, IFLA_VXLAN_L3MISS, l3miss); |
Tom Herbert | 35f59d8 | 2015-11-27 10:23:43 -0800 | [diff] [blame] | 309 | addattr8(n, 1024, IFLA_VXLAN_REMCSUM_TX, remcsumtx); |
| 310 | addattr8(n, 1024, IFLA_VXLAN_REMCSUM_RX, remcsumrx); |
Paolo Abeni | e79c327 | 2015-12-18 10:50:36 +0100 | [diff] [blame] | 311 | addattr8(n, 1024, IFLA_VXLAN_COLLECT_METADATA, metadata); |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 312 | |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 313 | if (udpcsum_set) |
| 314 | addattr8(n, 1024, IFLA_VXLAN_UDP_CSUM, udpcsum); |
| 315 | if (udp6zerocsumtx_set) |
| 316 | addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, udp6zerocsumtx); |
| 317 | if (udp6zerocsumrx_set) |
| 318 | addattr8(n, 1024, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, udp6zerocsumrx); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 319 | if (noage) |
| 320 | addattr32(n, 1024, IFLA_VXLAN_AGEING, 0); |
| 321 | else if (age) |
| 322 | addattr32(n, 1024, IFLA_VXLAN_AGEING, age); |
| 323 | if (maxaddr) |
| 324 | addattr32(n, 1024, IFLA_VXLAN_LIMIT, maxaddr); |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 325 | if (range.low || range.high) |
| 326 | addattr_l(n, 1024, IFLA_VXLAN_PORT_RANGE, |
| 327 | &range, sizeof(range)); |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 328 | if (dstport) |
| 329 | addattr16(n, 1024, IFLA_VXLAN_PORT, htons(dstport)); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 330 | |
Thomas Graf | 2eb90dc | 2015-01-15 14:54:25 +0100 | [diff] [blame] | 331 | if (gbp) |
| 332 | addattr_l(n, 1024, IFLA_VXLAN_GBP, NULL, 0); |
Jiri Benc | 346410b | 2016-04-07 14:36:29 +0200 | [diff] [blame] | 333 | if (gpe) |
| 334 | addattr_l(n, 1024, IFLA_VXLAN_GPE, NULL, 0); |
Thomas Graf | 2eb90dc | 2015-01-15 14:54:25 +0100 | [diff] [blame] | 335 | |
| 336 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) |
| 341 | { |
| 342 | __u32 vni; |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 343 | unsigned int link; |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 344 | __u8 tos; |
| 345 | __u32 maxaddr; |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 346 | char s2[64]; |
| 347 | |
| 348 | if (!tb) |
| 349 | return; |
| 350 | |
| 351 | if (!tb[IFLA_VXLAN_ID] || |
| 352 | RTA_PAYLOAD(tb[IFLA_VXLAN_ID]) < sizeof(__u32)) |
| 353 | return; |
| 354 | |
| 355 | vni = rta_getattr_u32(tb[IFLA_VXLAN_ID]); |
| 356 | fprintf(f, "id %u ", vni); |
| 357 | |
| 358 | if (tb[IFLA_VXLAN_GROUP]) { |
Stephen Hemminger | b64da5a | 2012-10-19 13:25:17 -0700 | [diff] [blame] | 359 | __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_GROUP]); |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 360 | |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 361 | if (addr) { |
| 362 | if (IN_MULTICAST(ntohl(addr))) |
| 363 | fprintf(f, "group %s ", |
Phil Sutter | a418e45 | 2016-03-22 19:35:15 +0100 | [diff] [blame] | 364 | format_host(AF_INET, 4, &addr)); |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 365 | else |
| 366 | fprintf(f, "remote %s ", |
Phil Sutter | a418e45 | 2016-03-22 19:35:15 +0100 | [diff] [blame] | 367 | format_host(AF_INET, 4, &addr)); |
Atzm Watanabe | 7cfa380 | 2013-07-24 14:01:01 +0900 | [diff] [blame] | 368 | } |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 369 | } else if (tb[IFLA_VXLAN_GROUP6]) { |
| 370 | struct in6_addr addr; |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 371 | |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 372 | memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_GROUP6]), sizeof(struct in6_addr)); |
Jiri Benc | 1f4c51c | 2016-09-05 11:35:27 +0200 | [diff] [blame] | 373 | if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) { |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 374 | if (IN6_IS_ADDR_MULTICAST(&addr)) |
| 375 | fprintf(f, "group %s ", |
Phil Sutter | a418e45 | 2016-03-22 19:35:15 +0100 | [diff] [blame] | 376 | format_host(AF_INET6, sizeof(struct in6_addr), &addr)); |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 377 | else |
| 378 | fprintf(f, "remote %s ", |
Phil Sutter | a418e45 | 2016-03-22 19:35:15 +0100 | [diff] [blame] | 379 | format_host(AF_INET6, sizeof(struct in6_addr), &addr)); |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 380 | } |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | if (tb[IFLA_VXLAN_LOCAL]) { |
Stephen Hemminger | b64da5a | 2012-10-19 13:25:17 -0700 | [diff] [blame] | 384 | __be32 addr = rta_getattr_u32(tb[IFLA_VXLAN_LOCAL]); |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 385 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 386 | if (addr) |
David L Stevens | 1556e29 | 2012-12-12 10:02:19 -0800 | [diff] [blame] | 387 | fprintf(f, "local %s ", |
Phil Sutter | a418e45 | 2016-03-22 19:35:15 +0100 | [diff] [blame] | 388 | format_host(AF_INET, 4, &addr)); |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 389 | } else if (tb[IFLA_VXLAN_LOCAL6]) { |
| 390 | struct in6_addr addr; |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 391 | |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 392 | memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr)); |
Jiri Benc | 1f4c51c | 2016-09-05 11:35:27 +0200 | [diff] [blame] | 393 | if (!IN6_IS_ADDR_UNSPECIFIED(&addr)) |
WANG Cong | aa574cd | 2013-10-16 22:03:48 -0700 | [diff] [blame] | 394 | fprintf(f, "local %s ", |
Phil Sutter | a418e45 | 2016-03-22 19:35:15 +0100 | [diff] [blame] | 395 | format_host(AF_INET6, sizeof(struct in6_addr), &addr)); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | if (tb[IFLA_VXLAN_LINK] && |
| 399 | (link = rta_getattr_u32(tb[IFLA_VXLAN_LINK]))) { |
| 400 | const char *n = if_indextoname(link, s2); |
| 401 | |
| 402 | if (n) |
| 403 | fprintf(f, "dev %s ", n); |
| 404 | else |
| 405 | fprintf(f, "dev %u ", link); |
| 406 | } |
| 407 | |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 408 | if (tb[IFLA_VXLAN_PORT_RANGE]) { |
| 409 | const struct ifla_vxlan_port_range *r |
| 410 | = RTA_DATA(tb[IFLA_VXLAN_PORT_RANGE]); |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 411 | fprintf(f, "srcport %u %u ", ntohs(r->low), ntohs(r->high)); |
David L Stevens | 1556e29 | 2012-12-12 10:02:19 -0800 | [diff] [blame] | 412 | } |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 413 | |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 414 | if (tb[IFLA_VXLAN_PORT]) |
| 415 | fprintf(f, "dstport %u ", |
Amir Vadai | aab0f61 | 2016-12-02 13:25:13 +0200 | [diff] [blame] | 416 | rta_getattr_be16(tb[IFLA_VXLAN_PORT])); |
Stephen Hemminger | 514cdfb | 2014-01-10 15:17:06 -0800 | [diff] [blame] | 417 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 418 | if (tb[IFLA_VXLAN_LEARNING] && |
| 419 | !rta_getattr_u8(tb[IFLA_VXLAN_LEARNING])) |
| 420 | fputs("nolearning ", f); |
David L Stevens | 1556e29 | 2012-12-12 10:02:19 -0800 | [diff] [blame] | 421 | |
| 422 | if (tb[IFLA_VXLAN_PROXY] && rta_getattr_u8(tb[IFLA_VXLAN_PROXY])) |
| 423 | fputs("proxy ", f); |
| 424 | |
| 425 | if (tb[IFLA_VXLAN_RSC] && rta_getattr_u8(tb[IFLA_VXLAN_RSC])) |
| 426 | fputs("rsc ", f); |
| 427 | |
| 428 | if (tb[IFLA_VXLAN_L2MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L2MISS])) |
| 429 | fputs("l2miss ", f); |
| 430 | |
| 431 | if (tb[IFLA_VXLAN_L3MISS] && rta_getattr_u8(tb[IFLA_VXLAN_L3MISS])) |
| 432 | fputs("l3miss ", f); |
| 433 | |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 434 | if (tb[IFLA_VXLAN_TOS] && |
| 435 | (tos = rta_getattr_u8(tb[IFLA_VXLAN_TOS]))) { |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 436 | if (tos == 1) |
| 437 | fprintf(f, "tos inherit "); |
| 438 | else |
| 439 | fprintf(f, "tos %#x ", tos); |
| 440 | } |
| 441 | |
| 442 | if (tb[IFLA_VXLAN_TTL]) { |
| 443 | __u8 ttl = rta_getattr_u8(tb[IFLA_VXLAN_TTL]); |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 444 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 445 | if (ttl) |
| 446 | fprintf(f, "ttl %d ", ttl); |
| 447 | } |
| 448 | |
Daniel Borkmann | f8eb79a | 2016-03-24 16:49:55 +0100 | [diff] [blame] | 449 | if (tb[IFLA_VXLAN_LABEL]) { |
| 450 | __u32 label = rta_getattr_u32(tb[IFLA_VXLAN_LABEL]); |
| 451 | |
| 452 | if (label) |
| 453 | fprintf(f, "flowlabel %#x ", ntohl(label)); |
| 454 | } |
| 455 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 456 | if (tb[IFLA_VXLAN_AGEING]) { |
| 457 | __u32 age = rta_getattr_u32(tb[IFLA_VXLAN_AGEING]); |
Stephen Hemminger | 56f5daa | 2016-03-21 11:52:19 -0700 | [diff] [blame] | 458 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 459 | if (age == 0) |
| 460 | fprintf(f, "ageing none "); |
| 461 | else |
| 462 | fprintf(f, "ageing %u ", age); |
| 463 | } |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 464 | |
| 465 | if (tb[IFLA_VXLAN_LIMIT] && |
Nicolas Dichtel | 6ad5399 | 2014-09-09 16:55:11 +0200 | [diff] [blame] | 466 | ((maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT])) != 0)) |
Stephen Hemminger | 2d59612 | 2012-10-09 23:39:17 -0700 | [diff] [blame] | 467 | fprintf(f, "maxaddr %u ", maxaddr); |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 468 | |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 469 | if (tb[IFLA_VXLAN_UDP_CSUM]) { |
| 470 | if (!rta_getattr_u8(tb[IFLA_VXLAN_UDP_CSUM])) |
| 471 | fputs("no", f); |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 472 | fputs("udpcsum ", f); |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 473 | } |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 474 | |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 475 | if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX]) { |
| 476 | if (!rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_TX])) |
| 477 | fputs("no", f); |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 478 | fputs("udp6zerocsumtx ", f); |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 479 | } |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 480 | |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 481 | if (tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]) { |
| 482 | if (!rta_getattr_u8(tb[IFLA_VXLAN_UDP_ZERO_CSUM6_RX])) |
| 483 | fputs("no", f); |
Tom Herbert | 666cdc5 | 2014-11-07 08:05:34 -0800 | [diff] [blame] | 484 | fputs("udp6zerocsumrx ", f); |
Jesse Gross | af32539 | 2016-03-18 17:51:08 -0700 | [diff] [blame] | 485 | } |
Thomas Graf | 2eb90dc | 2015-01-15 14:54:25 +0100 | [diff] [blame] | 486 | |
Tom Herbert | 35f59d8 | 2015-11-27 10:23:43 -0800 | [diff] [blame] | 487 | if (tb[IFLA_VXLAN_REMCSUM_TX] && |
| 488 | rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_TX])) |
| 489 | fputs("remcsumtx ", f); |
| 490 | |
| 491 | if (tb[IFLA_VXLAN_REMCSUM_RX] && |
| 492 | rta_getattr_u8(tb[IFLA_VXLAN_REMCSUM_RX])) |
| 493 | fputs("remcsumrx ", f); |
| 494 | |
Paolo Abeni | e79c327 | 2015-12-18 10:50:36 +0100 | [diff] [blame] | 495 | if (tb[IFLA_VXLAN_COLLECT_METADATA] && |
| 496 | rta_getattr_u8(tb[IFLA_VXLAN_COLLECT_METADATA])) |
| 497 | fputs("external ", f); |
| 498 | |
Thomas Graf | 2eb90dc | 2015-01-15 14:54:25 +0100 | [diff] [blame] | 499 | if (tb[IFLA_VXLAN_GBP]) |
| 500 | fputs("gbp ", f); |
Jiri Benc | 346410b | 2016-04-07 14:36:29 +0200 | [diff] [blame] | 501 | if (tb[IFLA_VXLAN_GPE]) |
| 502 | fputs("gpe ", f); |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 503 | } |
| 504 | |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 505 | static void vxlan_print_help(struct link_util *lu, int argc, char **argv, |
| 506 | FILE *f) |
| 507 | { |
| 508 | print_explain(f); |
| 509 | } |
| 510 | |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 511 | struct link_util vxlan_link_util = { |
| 512 | .id = "vxlan", |
| 513 | .maxattr = IFLA_VXLAN_MAX, |
| 514 | .parse_opt = vxlan_parse_opt, |
| 515 | .print_opt = vxlan_print_opt, |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 516 | .print_help = vxlan_print_help, |
Stephen Hemminger | a5494df | 2012-09-24 12:48:29 -0700 | [diff] [blame] | 517 | }; |