aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCong Wang <amwang@redhat.com>2013-08-31 01:44:33 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-31 22:30:00 -0400
commite4c7ed415387cf718ffbec305396c30cee092987 (patch)
treea484f436d61c6d716eca3f041cbbe8afc04c1c19
parentcaf92bc4007036cfac8ee06c845fdfe6496e4fb3 (diff)
vxlan: add ipv6 support
This patch adds IPv6 support to vxlan device, as the new version RFC already mentions it: http://tools.ietf.org/html/draft-mahalingam-dutt-dcops-vxlan-03 Cc: David Stevens <dlstevens@us.ibm.com> Cc: Stephen Hemminger <stephen@networkplumber.org> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Cong Wang <amwang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/vxlan.c764
-rw-r--r--include/net/vxlan.h2
-rw-r--r--include/uapi/linux/if_link.h2
-rw-r--r--net/openvswitch/vport-vxlan.c2
4 files changed, 622 insertions, 148 deletions
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 3b21aca0c0c2..faf131e02a72 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -6,9 +6,6 @@
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 *
10 * TODO
11 * - IPv6 (not in RFC)
12 */ 9 */
13 10
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -43,6 +40,11 @@
43#include <net/net_namespace.h> 40#include <net/net_namespace.h>
44#include <net/netns/generic.h> 41#include <net/netns/generic.h>
45#include <net/vxlan.h> 42#include <net/vxlan.h>
43#if IS_ENABLED(CONFIG_IPV6)
44#include <net/ipv6.h>
45#include <net/addrconf.h>
46#include <net/ip6_tunnel.h>
47#endif
46 48
47#define VXLAN_VERSION "0.1" 49#define VXLAN_VERSION "0.1"
48 50
@@ -59,6 +61,8 @@
59#define VXLAN_VID_MASK (VXLAN_N_VID - 1) 61#define VXLAN_VID_MASK (VXLAN_N_VID - 1)
60/* IP header + UDP + VXLAN + Ethernet header */ 62/* IP header + UDP + VXLAN + Ethernet header */
61#define VXLAN_HEADROOM (20 + 8 + 8 + 14) 63#define VXLAN_HEADROOM (20 + 8 + 8 + 14)
64/* IPv6 header + UDP + VXLAN + Ethernet header */
65#define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
62#define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr)) 66#define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
63 67
64#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ 68#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
@@ -92,8 +96,14 @@ struct vxlan_net {
92 spinlock_t sock_lock; 96 spinlock_t sock_lock;
93}; 97};
94 98
99union vxlan_addr {
100 struct sockaddr_in sin;
101 struct sockaddr_in6 sin6;
102 struct sockaddr sa;
103};
104
95struct vxlan_rdst { 105struct vxlan_rdst {
96 __be32 remote_ip; 106 union vxlan_addr remote_ip;
97 __be16 remote_port; 107 __be16 remote_port;
98 u32 remote_vni; 108 u32 remote_vni;
99 u32 remote_ifindex; 109 u32 remote_ifindex;
@@ -120,7 +130,7 @@ struct vxlan_dev {
120 struct vxlan_sock *vn_sock; /* listening socket */ 130 struct vxlan_sock *vn_sock; /* listening socket */
121 struct net_device *dev; 131 struct net_device *dev;
122 struct vxlan_rdst default_dst; /* default destination */ 132 struct vxlan_rdst default_dst; /* default destination */
123 __be32 saddr; /* source address */ 133 union vxlan_addr saddr; /* source address */
124 __be16 dst_port; 134 __be16 dst_port;
125 __u16 port_min; /* source port range */ 135 __u16 port_min; /* source port range */
126 __u16 port_max; 136 __u16 port_max;
@@ -146,6 +156,7 @@ struct vxlan_dev {
146#define VXLAN_F_RSC 0x04 156#define VXLAN_F_RSC 0x04
147#define VXLAN_F_L2MISS 0x08 157#define VXLAN_F_L2MISS 0x08
148#define VXLAN_F_L3MISS 0x10 158#define VXLAN_F_L3MISS 0x10
159#define VXLAN_F_IPV6 0x20 /* internal flag */
149 160
150/* salt for hash table */ 161/* salt for hash table */
151static u32 vxlan_salt __read_mostly; 162static u32 vxlan_salt __read_mostly;
@@ -153,6 +164,96 @@ static struct workqueue_struct *vxlan_wq;
153 164
154static void vxlan_sock_work(struct work_struct *work); 165static void vxlan_sock_work(struct work_struct *work);
155 166
167#if IS_ENABLED(CONFIG_IPV6)
168static inline
169bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
170{
171 if (a->sa.sa_family != b->sa.sa_family)
172 return false;
173 if (a->sa.sa_family == AF_INET6)
174 return ipv6_addr_equal(&a->sin6.sin6_addr, &b->sin6.sin6_addr);
175 else
176 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
177}
178
179static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
180{
181 if (ipa->sa.sa_family == AF_INET6)
182 return ipv6_addr_any(&ipa->sin6.sin6_addr);
183 else
184 return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
185}
186
187static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
188{
189 if (ipa->sa.sa_family == AF_INET6)
190 return ipv6_addr_is_multicast(&ipa->sin6.sin6_addr);
191 else
192 return IN_MULTICAST(ntohl(ipa->sin.sin_addr.s_addr));
193}
194
195static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla)
196{
197 if (nla_len(nla) >= sizeof(struct in6_addr)) {
198 nla_memcpy(&ip->sin6.sin6_addr, nla, sizeof(struct in6_addr));
199 ip->sa.sa_family = AF_INET6;
200 return 0;
201 } else if (nla_len(nla) >= sizeof(__be32)) {
202 ip->sin.sin_addr.s_addr = nla_get_be32(nla);
203 ip->sa.sa_family = AF_INET;
204 return 0;
205 } else {
206 return -EAFNOSUPPORT;
207 }
208}
209
210static int vxlan_nla_put_addr(struct sk_buff *skb, int attr,
211 const union vxlan_addr *ip)
212{
213 if (ip->sa.sa_family == AF_INET6)
214 return nla_put(skb, attr, sizeof(struct in6_addr), &ip->sin6.sin6_addr);
215 else
216 return nla_put_be32(skb, attr, ip->sin.sin_addr.s_addr);
217}
218
219#else /* !CONFIG_IPV6 */
220
221static inline
222bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
223{
224 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
225}
226
227static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
228{
229 return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
230}
231
232static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
233{
234 return IN_MULTICAST(ntohl(ipa->sin.sin_addr.s_addr));
235}
236
237static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla)
238{
239 if (nla_len(nla) >= sizeof(struct in6_addr)) {
240 return -EAFNOSUPPORT;
241 } else if (nla_len(nla) >= sizeof(__be32)) {
242 ip->sin.sin_addr.s_addr = nla_get_be32(nla);
243 ip->sa.sa_family = AF_INET;
244 return 0;
245 } else {
246 return -EAFNOSUPPORT;
247 }
248}
249
250static int vxlan_nla_put_addr(struct sk_buff *skb, int attr,
251 const union vxlan_addr *ip)
252{
253 return nla_put_be32(skb, attr, ip->sin.sin_addr.s_addr);
254}
255#endif
256
156/* Virtual Network hash table head */ 257/* Virtual Network hash table head */
157static inline struct hlist_head *vni_head(struct vxlan_sock *vs, u32 id) 258static inline struct hlist_head *vni_head(struct vxlan_sock *vs, u32 id)
158{ 259{
@@ -239,7 +340,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
239 340
240 if (type == RTM_GETNEIGH) { 341 if (type == RTM_GETNEIGH) {
241 ndm->ndm_family = AF_INET; 342 ndm->ndm_family = AF_INET;
242 send_ip = rdst->remote_ip != htonl(INADDR_ANY); 343 send_ip = !vxlan_addr_any(&rdst->remote_ip);
243 send_eth = !is_zero_ether_addr(fdb->eth_addr); 344 send_eth = !is_zero_ether_addr(fdb->eth_addr);
244 } else 345 } else
245 ndm->ndm_family = AF_BRIDGE; 346 ndm->ndm_family = AF_BRIDGE;
@@ -251,7 +352,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
251 if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr)) 352 if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr))
252 goto nla_put_failure; 353 goto nla_put_failure;
253 354
254 if (send_ip && nla_put_be32(skb, NDA_DST, rdst->remote_ip)) 355 if (send_ip && vxlan_nla_put_addr(skb, NDA_DST, &rdst->remote_ip))
255 goto nla_put_failure; 356 goto nla_put_failure;
256 357
257 if (rdst->remote_port && rdst->remote_port != vxlan->dst_port && 358 if (rdst->remote_port && rdst->remote_port != vxlan->dst_port &&
@@ -283,7 +384,7 @@ static inline size_t vxlan_nlmsg_size(void)
283{ 384{
284 return NLMSG_ALIGN(sizeof(struct ndmsg)) 385 return NLMSG_ALIGN(sizeof(struct ndmsg))
285 + nla_total_size(ETH_ALEN) /* NDA_LLADDR */ 386 + nla_total_size(ETH_ALEN) /* NDA_LLADDR */
286 + nla_total_size(sizeof(__be32)) /* NDA_DST */ 387 + nla_total_size(sizeof(struct in6_addr)) /* NDA_DST */
287 + nla_total_size(sizeof(__be16)) /* NDA_PORT */ 388 + nla_total_size(sizeof(__be16)) /* NDA_PORT */
288 + nla_total_size(sizeof(__be32)) /* NDA_VNI */ 389 + nla_total_size(sizeof(__be32)) /* NDA_VNI */
289 + nla_total_size(sizeof(__u32)) /* NDA_IFINDEX */ 390 + nla_total_size(sizeof(__u32)) /* NDA_IFINDEX */
@@ -317,14 +418,14 @@ errout:
317 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err); 418 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
318} 419}
319 420
320static void vxlan_ip_miss(struct net_device *dev, __be32 ipa) 421static void vxlan_ip_miss(struct net_device *dev, union vxlan_addr *ipa)
321{ 422{
322 struct vxlan_dev *vxlan = netdev_priv(dev); 423 struct vxlan_dev *vxlan = netdev_priv(dev);
323 struct vxlan_fdb f = { 424 struct vxlan_fdb f = {
324 .state = NUD_STALE, 425 .state = NUD_STALE,
325 }; 426 };
326 struct vxlan_rdst remote = { 427 struct vxlan_rdst remote = {
327 .remote_ip = ipa, /* goes to NDA_DST */ 428 .remote_ip = *ipa, /* goes to NDA_DST */
328 .remote_vni = VXLAN_N_VID, 429 .remote_vni = VXLAN_N_VID,
329 }; 430 };
330 431
@@ -397,13 +498,13 @@ static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan,
397 498
398/* caller should hold vxlan->hash_lock */ 499/* caller should hold vxlan->hash_lock */
399static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f, 500static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f,
400 __be32 ip, __be16 port, 501 union vxlan_addr *ip, __be16 port,
401 __u32 vni, __u32 ifindex) 502 __u32 vni, __u32 ifindex)
402{ 503{
403 struct vxlan_rdst *rd; 504 struct vxlan_rdst *rd;
404 505
405 list_for_each_entry(rd, &f->remotes, list) { 506 list_for_each_entry(rd, &f->remotes, list) {
406 if (rd->remote_ip == ip && 507 if (vxlan_addr_equal(&rd->remote_ip, ip) &&
407 rd->remote_port == port && 508 rd->remote_port == port &&
408 rd->remote_vni == vni && 509 rd->remote_vni == vni &&
409 rd->remote_ifindex == ifindex) 510 rd->remote_ifindex == ifindex)
@@ -415,7 +516,7 @@ static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f,
415 516
416/* Replace destination of unicast mac */ 517/* Replace destination of unicast mac */
417static int vxlan_fdb_replace(struct vxlan_fdb *f, 518static int vxlan_fdb_replace(struct vxlan_fdb *f,
418 __be32 ip, __be16 port, __u32 vni, __u32 ifindex) 519 union vxlan_addr *ip, __be16 port, __u32 vni, __u32 ifindex)
419{ 520{
420 struct vxlan_rdst *rd; 521 struct vxlan_rdst *rd;
421 522
@@ -426,7 +527,7 @@ static int vxlan_fdb_replace(struct vxlan_fdb *f,
426 rd = list_first_entry_or_null(&f->remotes, struct vxlan_rdst, list); 527 rd = list_first_entry_or_null(&f->remotes, struct vxlan_rdst, list);
427 if (!rd) 528 if (!rd)
428 return 0; 529 return 0;
429 rd->remote_ip = ip; 530 rd->remote_ip = *ip;
430 rd->remote_port = port; 531 rd->remote_port = port;
431 rd->remote_vni = vni; 532 rd->remote_vni = vni;
432 rd->remote_ifindex = ifindex; 533 rd->remote_ifindex = ifindex;
@@ -435,7 +536,7 @@ static int vxlan_fdb_replace(struct vxlan_fdb *f,
435 536
436/* Add/update destinations for multicast */ 537/* Add/update destinations for multicast */
437static int vxlan_fdb_append(struct vxlan_fdb *f, 538static int vxlan_fdb_append(struct vxlan_fdb *f,
438 __be32 ip, __be16 port, __u32 vni, __u32 ifindex) 539 union vxlan_addr *ip, __be16 port, __u32 vni, __u32 ifindex)
439{ 540{
440 struct vxlan_rdst *rd; 541 struct vxlan_rdst *rd;
441 542
@@ -446,7 +547,7 @@ static int vxlan_fdb_append(struct vxlan_fdb *f,
446 rd = kmalloc(sizeof(*rd), GFP_ATOMIC); 547 rd = kmalloc(sizeof(*rd), GFP_ATOMIC);
447 if (rd == NULL) 548 if (rd == NULL)
448 return -ENOBUFS; 549 return -ENOBUFS;
449 rd->remote_ip = ip; 550 rd->remote_ip = *ip;
450 rd->remote_port = port; 551 rd->remote_port = port;
451 rd->remote_vni = vni; 552 rd->remote_vni = vni;
452 rd->remote_ifindex = ifindex; 553 rd->remote_ifindex = ifindex;
@@ -458,7 +559,7 @@ static int vxlan_fdb_append(struct vxlan_fdb *f,
458 559
459/* Add new entry to forwarding table -- assumes lock held */ 560/* Add new entry to forwarding table -- assumes lock held */
460static int vxlan_fdb_create(struct vxlan_dev *vxlan, 561static int vxlan_fdb_create(struct vxlan_dev *vxlan,
461 const u8 *mac, __be32 ip, 562 const u8 *mac, union vxlan_addr *ip,
462 __u16 state, __u16 flags, 563 __u16 state, __u16 flags,
463 __be16 port, __u32 vni, __u32 ifindex, 564 __be16 port, __u32 vni, __u32 ifindex,
464 __u8 ndm_flags) 565 __u8 ndm_flags)
@@ -517,7 +618,7 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
517 (is_multicast_ether_addr(mac) || is_zero_ether_addr(mac))) 618 (is_multicast_ether_addr(mac) || is_zero_ether_addr(mac)))
518 return -EOPNOTSUPP; 619 return -EOPNOTSUPP;
519 620
520 netdev_dbg(vxlan->dev, "add %pM -> %pI4\n", mac, &ip); 621 netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip);
521 f = kmalloc(sizeof(*f), GFP_ATOMIC); 622 f = kmalloc(sizeof(*f), GFP_ATOMIC);
522 if (!f) 623 if (!f)
523 return -ENOMEM; 624 return -ENOMEM;
@@ -565,17 +666,26 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f)
565} 666}
566 667
567static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, 668static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
568 __be32 *ip, __be16 *port, u32 *vni, u32 *ifindex) 669 union vxlan_addr *ip, __be16 *port, u32 *vni, u32 *ifindex)
569{ 670{
570 struct net *net = dev_net(vxlan->dev); 671 struct net *net = dev_net(vxlan->dev);
672 int err;
571 673
572 if (tb[NDA_DST]) { 674 if (tb[NDA_DST]) {
573 if (nla_len(tb[NDA_DST]) != sizeof(__be32)) 675 err = vxlan_nla_get_addr(ip, tb[NDA_DST]);
574 return -EAFNOSUPPORT; 676 if (err)
575 677 return err;
576 *ip = nla_get_be32(tb[NDA_DST]);
577 } else { 678 } else {
578 *ip = htonl(INADDR_ANY); 679 union vxlan_addr *remote = &vxlan->default_dst.remote_ip;
680 if (remote->sa.sa_family == AF_INET) {
681 ip->sin.sin_addr.s_addr = htonl(INADDR_ANY);
682 ip->sa.sa_family = AF_INET;
683#if IS_ENABLED(CONFIG_IPV6)
684 } else {
685 ip->sin6.sin6_addr = in6addr_any;
686 ip->sa.sa_family = AF_INET6;
687#endif
688 }
579 } 689 }
580 690
581 if (tb[NDA_PORT]) { 691 if (tb[NDA_PORT]) {
@@ -618,7 +728,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
618{ 728{
619 struct vxlan_dev *vxlan = netdev_priv(dev); 729 struct vxlan_dev *vxlan = netdev_priv(dev);
620 /* struct net *net = dev_net(vxlan->dev); */ 730 /* struct net *net = dev_net(vxlan->dev); */
621 __be32 ip; 731 union vxlan_addr ip;
622 __be16 port; 732 __be16 port;
623 u32 vni, ifindex; 733 u32 vni, ifindex;
624 int err; 734 int err;
@@ -637,7 +747,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
637 return err; 747 return err;
638 748
639 spin_lock_bh(&vxlan->hash_lock); 749 spin_lock_bh(&vxlan->hash_lock);
640 err = vxlan_fdb_create(vxlan, addr, ip, ndm->ndm_state, flags, 750 err = vxlan_fdb_create(vxlan, addr, &ip, ndm->ndm_state, flags,
641 port, vni, ifindex, ndm->ndm_flags); 751 port, vni, ifindex, ndm->ndm_flags);
642 spin_unlock_bh(&vxlan->hash_lock); 752 spin_unlock_bh(&vxlan->hash_lock);
643 753
@@ -652,7 +762,7 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
652 struct vxlan_dev *vxlan = netdev_priv(dev); 762 struct vxlan_dev *vxlan = netdev_priv(dev);
653 struct vxlan_fdb *f; 763 struct vxlan_fdb *f;
654 struct vxlan_rdst *rd = NULL; 764 struct vxlan_rdst *rd = NULL;
655 __be32 ip; 765 union vxlan_addr ip;
656 __be16 port; 766 __be16 port;
657 u32 vni, ifindex; 767 u32 vni, ifindex;
658 int err; 768 int err;
@@ -668,8 +778,8 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
668 if (!f) 778 if (!f)
669 goto out; 779 goto out;
670 780
671 if (ip != htonl(INADDR_ANY)) { 781 if (!vxlan_addr_any(&ip)) {
672 rd = vxlan_fdb_find_rdst(f, ip, port, vni, ifindex); 782 rd = vxlan_fdb_find_rdst(f, &ip, port, vni, ifindex);
673 if (!rd) 783 if (!rd)
674 goto out; 784 goto out;
675 } 785 }
@@ -732,7 +842,7 @@ out:
732 * Return true if packet is bogus and should be droppped. 842 * Return true if packet is bogus and should be droppped.
733 */ 843 */
734static bool vxlan_snoop(struct net_device *dev, 844static bool vxlan_snoop(struct net_device *dev,
735 __be32 src_ip, const u8 *src_mac) 845 union vxlan_addr *src_ip, const u8 *src_mac)
736{ 846{
737 struct vxlan_dev *vxlan = netdev_priv(dev); 847 struct vxlan_dev *vxlan = netdev_priv(dev);
738 struct vxlan_fdb *f; 848 struct vxlan_fdb *f;
@@ -741,7 +851,7 @@ static bool vxlan_snoop(struct net_device *dev,
741 if (likely(f)) { 851 if (likely(f)) {
742 struct vxlan_rdst *rdst = first_remote_rcu(f); 852 struct vxlan_rdst *rdst = first_remote_rcu(f);
743 853
744 if (likely(rdst->remote_ip == src_ip)) 854 if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip)))
745 return false; 855 return false;
746 856
747 /* Don't migrate static entries, drop packets */ 857 /* Don't migrate static entries, drop packets */
@@ -750,10 +860,10 @@ static bool vxlan_snoop(struct net_device *dev,
750 860
751 if (net_ratelimit()) 861 if (net_ratelimit())
752 netdev_info(dev, 862 netdev_info(dev,
753 "%pM migrated from %pI4 to %pI4\n", 863 "%pM migrated from %pIS to %pIS\n",
754 src_mac, &rdst->remote_ip, &src_ip); 864 src_mac, &rdst->remote_ip, &src_ip);
755 865
756 rdst->remote_ip = src_ip; 866 rdst->remote_ip = *src_ip;
757 f->updated = jiffies; 867 f->updated = jiffies;
758 vxlan_fdb_notify(vxlan, f, RTM_NEWNEIGH); 868 vxlan_fdb_notify(vxlan, f, RTM_NEWNEIGH);
759 } else { 869 } else {
@@ -775,7 +885,7 @@ static bool vxlan_snoop(struct net_device *dev,
775} 885}
776 886
777/* See if multicast group is already in use by other ID */ 887/* See if multicast group is already in use by other ID */
778static bool vxlan_group_used(struct vxlan_net *vn, __be32 remote_ip) 888static bool vxlan_group_used(struct vxlan_net *vn, union vxlan_addr *remote_ip)
779{ 889{
780 struct vxlan_dev *vxlan; 890 struct vxlan_dev *vxlan;
781 891
@@ -783,7 +893,8 @@ static bool vxlan_group_used(struct vxlan_net *vn, __be32 remote_ip)
783 if (!netif_running(vxlan->dev)) 893 if (!netif_running(vxlan->dev))
784 continue; 894 continue;
785 895
786 if (vxlan->default_dst.remote_ip == remote_ip) 896 if (vxlan_addr_equal(&vxlan->default_dst.remote_ip,
897 remote_ip))
787 return true; 898 return true;
788 } 899 }
789 900
@@ -819,13 +930,23 @@ static void vxlan_igmp_join(struct work_struct *work)
819 struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_join); 930 struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_join);
820 struct vxlan_sock *vs = vxlan->vn_sock; 931 struct vxlan_sock *vs = vxlan->vn_sock;
821 struct sock *sk = vs->sock->sk; 932 struct sock *sk = vs->sock->sk;
822 struct ip_mreqn mreq = { 933 union vxlan_addr *ip = &vxlan->default_dst.remote_ip;
823 .imr_multiaddr.s_addr = vxlan->default_dst.remote_ip, 934 int ifindex = vxlan->default_dst.remote_ifindex;
824 .imr_ifindex = vxlan->default_dst.remote_ifindex,
825 };
826 935
827 lock_sock(sk); 936 lock_sock(sk);
828 ip_mc_join_group(sk, &mreq); 937 if (ip->sa.sa_family == AF_INET) {
938 struct ip_mreqn mreq = {
939 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr,
940 .imr_ifindex = ifindex,
941 };
942
943 ip_mc_join_group(sk, &mreq);
944#if IS_ENABLED(CONFIG_IPV6)
945 } else {
946 ipv6_stub->ipv6_sock_mc_join(sk, ifindex,
947 &ip->sin6.sin6_addr);
948#endif
949 }
829 release_sock(sk); 950 release_sock(sk);
830 951
831 vxlan_sock_release(vs); 952 vxlan_sock_release(vs);
@@ -838,13 +959,24 @@ static void vxlan_igmp_leave(struct work_struct *work)
838 struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_leave); 959 struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_leave);
839 struct vxlan_sock *vs = vxlan->vn_sock; 960 struct vxlan_sock *vs = vxlan->vn_sock;
840 struct sock *sk = vs->sock->sk; 961 struct sock *sk = vs->sock->sk;
841 struct ip_mreqn mreq = { 962 union vxlan_addr *ip = &vxlan->default_dst.remote_ip;
842 .imr_multiaddr.s_addr = vxlan->default_dst.remote_ip, 963 int ifindex = vxlan->default_dst.remote_ifindex;
843 .imr_ifindex = vxlan->default_dst.remote_ifindex,
844 };
845 964
846 lock_sock(sk); 965 lock_sock(sk);
847 ip_mc_leave_group(sk, &mreq); 966 if (ip->sa.sa_family == AF_INET) {
967 struct ip_mreqn mreq = {
968 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr,
969 .imr_ifindex = ifindex,
970 };
971
972 ip_mc_leave_group(sk, &mreq);
973#if IS_ENABLED(CONFIG_IPV6)
974 } else {
975 ipv6_stub->ipv6_sock_mc_drop(sk, ifindex,
976 &ip->sin6.sin6_addr);
977#endif
978 }
979
848 release_sock(sk); 980 release_sock(sk);
849 981
850 vxlan_sock_release(vs); 982 vxlan_sock_release(vs);
@@ -896,11 +1028,14 @@ error:
896static void vxlan_rcv(struct vxlan_sock *vs, 1028static void vxlan_rcv(struct vxlan_sock *vs,
897 struct sk_buff *skb, __be32 vx_vni) 1029 struct sk_buff *skb, __be32 vx_vni)
898{ 1030{
899 struct iphdr *oip; 1031 struct iphdr *oip = NULL;
1032 struct ipv6hdr *oip6 = NULL;
900 struct vxlan_dev *vxlan; 1033 struct vxlan_dev *vxlan;
901 struct pcpu_tstats *stats; 1034 struct pcpu_tstats *stats;
1035 union vxlan_addr saddr;
902 __u32 vni; 1036 __u32 vni;
903 int err; 1037 int err = 0;
1038 union vxlan_addr *remote_ip;
904 1039
905 vni = ntohl(vx_vni) >> 8; 1040 vni = ntohl(vx_vni) >> 8;
906 /* Is this VNI defined? */ 1041 /* Is this VNI defined? */
@@ -908,6 +1043,7 @@ static void vxlan_rcv(struct vxlan_sock *vs,
908 if (!vxlan) 1043 if (!vxlan)
909 goto drop; 1044 goto drop;
910 1045
1046 remote_ip = &vxlan->default_dst.remote_ip;
911 skb_reset_mac_header(skb); 1047 skb_reset_mac_header(skb);
912 skb->protocol = eth_type_trans(skb, vxlan->dev); 1048 skb->protocol = eth_type_trans(skb, vxlan->dev);
913 1049
@@ -917,9 +1053,20 @@ static void vxlan_rcv(struct vxlan_sock *vs,
917 goto drop; 1053 goto drop;
918 1054
919 /* Re-examine inner Ethernet packet */ 1055 /* Re-examine inner Ethernet packet */
920 oip = ip_hdr(skb); 1056 if (remote_ip->sa.sa_family == AF_INET) {
1057 oip = ip_hdr(skb);
1058 saddr.sin.sin_addr.s_addr = oip->saddr;
1059 saddr.sa.sa_family = AF_INET;
1060#if IS_ENABLED(CONFIG_IPV6)
1061 } else {
1062 oip6 = ipv6_hdr(skb);
1063 saddr.sin6.sin6_addr = oip6->saddr;
1064 saddr.sa.sa_family = AF_INET6;
1065#endif
1066 }
1067
921 if ((vxlan->flags & VXLAN_F_LEARN) && 1068 if ((vxlan->flags & VXLAN_F_LEARN) &&
922 vxlan_snoop(skb->dev, oip->saddr, eth_hdr(skb)->h_source)) 1069 vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source))
923 goto drop; 1070 goto drop;
924 1071
925 skb_reset_network_header(skb); 1072 skb_reset_network_header(skb);
@@ -935,11 +1082,20 @@ static void vxlan_rcv(struct vxlan_sock *vs,
935 1082
936 skb->encapsulation = 0; 1083 skb->encapsulation = 0;
937 1084
938 err = IP_ECN_decapsulate(oip, skb); 1085 if (oip6)
1086 err = IP6_ECN_decapsulate(oip6, skb);
1087 if (oip)
1088 err = IP_ECN_decapsulate(oip, skb);
1089
939 if (unlikely(err)) { 1090 if (unlikely(err)) {
940 if (log_ecn_error) 1091 if (log_ecn_error) {
941 net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", 1092 if (oip6)
942 &oip->saddr, oip->tos); 1093 net_info_ratelimited("non-ECT from %pI6\n",
1094 &oip6->saddr);
1095 if (oip)
1096 net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
1097 &oip->saddr, oip->tos);
1098 }
943 if (err > 1) { 1099 if (err > 1) {
944 ++vxlan->dev->stats.rx_frame_errors; 1100 ++vxlan->dev->stats.rx_frame_errors;
945 ++vxlan->dev->stats.rx_errors; 1101 ++vxlan->dev->stats.rx_errors;
@@ -1009,7 +1165,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb)
1009 } 1165 }
1010 1166
1011 f = vxlan_find_mac(vxlan, n->ha); 1167 f = vxlan_find_mac(vxlan, n->ha);
1012 if (f && first_remote_rcu(f)->remote_ip == htonl(INADDR_ANY)) { 1168 if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) {
1013 /* bridge-local neighbor */ 1169 /* bridge-local neighbor */
1014 neigh_release(n); 1170 neigh_release(n);
1015 goto out; 1171 goto out;
@@ -1027,8 +1183,14 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb)
1027 1183
1028 if (netif_rx_ni(reply) == NET_RX_DROP) 1184 if (netif_rx_ni(reply) == NET_RX_DROP)
1029 dev->stats.rx_dropped++; 1185 dev->stats.rx_dropped++;
1030 } else if (vxlan->flags & VXLAN_F_L3MISS) 1186 } else if (vxlan->flags & VXLAN_F_L3MISS) {
1031 vxlan_ip_miss(dev, tip); 1187 union vxlan_addr ipa = {
1188 .sin.sin_addr.s_addr = tip,
1189 .sa.sa_family = AF_INET,
1190 };
1191
1192 vxlan_ip_miss(dev, &ipa);
1193 }
1032out: 1194out:
1033 consume_skb(skb); 1195 consume_skb(skb);
1034 return NETDEV_TX_OK; 1196 return NETDEV_TX_OK;
@@ -1050,6 +1212,16 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)
1050 return false; 1212 return false;
1051 pip = ip_hdr(skb); 1213 pip = ip_hdr(skb);
1052 n = neigh_lookup(&arp_tbl, &pip->daddr, dev); 1214 n = neigh_lookup(&arp_tbl, &pip->daddr, dev);
1215 if (!n && (vxlan->flags & VXLAN_F_L3MISS)) {
1216 union vxlan_addr ipa = {
1217 .sin.sin_addr.s_addr = pip->daddr,
1218 .sa.sa_family = AF_INET,
1219 };
1220
1221 vxlan_ip_miss(dev, &ipa);
1222 return false;
1223 }
1224
1053 break; 1225 break;
1054 default: 1226 default:
1055 return false; 1227 return false;
@@ -1066,8 +1238,8 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb)
1066 } 1238 }
1067 neigh_release(n); 1239 neigh_release(n);
1068 return diff; 1240 return diff;
1069 } else if (vxlan->flags & VXLAN_F_L3MISS) 1241 }
1070 vxlan_ip_miss(dev, pip->daddr); 1242
1071 return false; 1243 return false;
1072} 1244}
1073 1245
@@ -1118,6 +1290,102 @@ static int handle_offloads(struct sk_buff *skb)
1118 return 0; 1290 return 0;
1119} 1291}
1120 1292
1293#if IS_ENABLED(CONFIG_IPV6)
1294static int vxlan6_xmit_skb(struct net *net, struct vxlan_sock *vs,
1295 struct dst_entry *dst, struct sk_buff *skb,
1296 struct net_device *dev, struct in6_addr *saddr,
1297 struct in6_addr *daddr, __u8 prio, __u8 ttl,
1298 __be16 src_port, __be16 dst_port, __be32 vni)
1299{
1300 struct ipv6hdr *ip6h;
1301 struct vxlanhdr *vxh;
1302 struct udphdr *uh;
1303 int min_headroom;
1304 int err;
1305
1306 if (!skb->encapsulation) {
1307 skb_reset_inner_headers(skb);
1308 skb->encapsulation = 1;
1309 }
1310
1311 min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len
1312 + VXLAN_HLEN + sizeof(struct ipv6hdr)
1313 + (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
1314
1315 /* Need space for new headers (invalidates iph ptr) */
1316 err = skb_cow_head(skb, min_headroom);
1317 if (unlikely(err))
1318 return err;
1319
1320 if (vlan_tx_tag_present(skb)) {
1321 if (WARN_ON(!__vlan_put_tag(skb,
1322 skb->vlan_proto,
1323 vlan_tx_tag_get(skb))))
1324 return -ENOMEM;
1325
1326 skb->vlan_tci = 0;
1327 }
1328
1329 vxh = (struct vxlanhdr *) __skb_push(skb, sizeof(*vxh));
1330 vxh->vx_flags = htonl(VXLAN_FLAGS);
1331 vxh->vx_vni = vni;
1332
1333 __skb_push(skb, sizeof(*uh));
1334 skb_reset_transport_header(skb);
1335 uh = udp_hdr(skb);
1336
1337 uh->dest = dst_port;
1338 uh->source = src_port;
1339
1340 uh->len = htons(skb->len);
1341 uh->check = 0;
1342
1343 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1344 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
1345 IPSKB_REROUTED);
1346 skb_dst_drop(skb);
1347 skb_dst_set(skb, dst);
1348
1349 if (!skb_is_gso(skb) && !(dst->dev->features & NETIF_F_IPV6_CSUM)) {
1350 __wsum csum = skb_checksum(skb, 0, skb->len, 0);
1351 skb->ip_summed = CHECKSUM_UNNECESSARY;
1352 uh->check = csum_ipv6_magic(saddr, daddr, skb->len,
1353 IPPROTO_UDP, csum);
1354 if (uh->check == 0)
1355 uh->check = CSUM_MANGLED_0;
1356 } else {
1357 skb->ip_summed = CHECKSUM_PARTIAL;
1358 skb->csum_start = skb_transport_header(skb) - skb->head;
1359 skb->csum_offset = offsetof(struct udphdr, check);
1360 uh->check = ~csum_ipv6_magic(saddr, daddr,
1361 skb->len, IPPROTO_UDP, 0);
1362 }
1363
1364 __skb_push(skb, sizeof(*ip6h));
1365 skb_reset_network_header(skb);
1366 ip6h = ipv6_hdr(skb);
1367 ip6h->version = 6;
1368 ip6h->priority = prio;
1369 ip6h->flow_lbl[0] = 0;
1370 ip6h->flow_lbl[1] = 0;
1371 ip6h->flow_lbl[2] = 0;
1372 ip6h->payload_len = htons(skb->len);
1373 ip6h->nexthdr = IPPROTO_UDP;
1374 ip6h->hop_limit = ttl;
1375 ip6h->daddr = *daddr;
1376 ip6h->saddr = *saddr;
1377
1378 vxlan_set_owner(vs->sock->sk, skb);
1379
1380 err = handle_offloads(skb);
1381 if (err)
1382 return err;
1383
1384 ip6tunnel_xmit(skb, dev);
1385 return 0;
1386}
1387#endif
1388
1121int vxlan_xmit_skb(struct net *net, struct vxlan_sock *vs, 1389int vxlan_xmit_skb(struct net *net, struct vxlan_sock *vs,
1122 struct rtable *rt, struct sk_buff *skb, 1390 struct rtable *rt, struct sk_buff *skb,
1123 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df, 1391 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
@@ -1182,15 +1450,26 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
1182{ 1450{
1183 struct pcpu_tstats *tx_stats = this_cpu_ptr(src_vxlan->dev->tstats); 1451 struct pcpu_tstats *tx_stats = this_cpu_ptr(src_vxlan->dev->tstats);
1184 struct pcpu_tstats *rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats); 1452 struct pcpu_tstats *rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats);
1453 union vxlan_addr loopback;
1454 union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip;
1185 1455
1186 skb->pkt_type = PACKET_HOST; 1456 skb->pkt_type = PACKET_HOST;
1187 skb->encapsulation = 0; 1457 skb->encapsulation = 0;
1188 skb->dev = dst_vxlan->dev; 1458 skb->dev = dst_vxlan->dev;
1189 __skb_pull(skb, skb_network_offset(skb)); 1459 __skb_pull(skb, skb_network_offset(skb));
1190 1460
1461 if (remote_ip->sa.sa_family == AF_INET) {
1462 loopback.sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
1463 loopback.sa.sa_family = AF_INET;
1464#if IS_ENABLED(CONFIG_IPV6)
1465 } else {
1466 loopback.sin6.sin6_addr = in6addr_loopback;
1467 loopback.sa.sa_family = AF_INET6;
1468#endif
1469 }
1470
1191 if (dst_vxlan->flags & VXLAN_F_LEARN) 1471 if (dst_vxlan->flags & VXLAN_F_LEARN)
1192 vxlan_snoop(skb->dev, htonl(INADDR_LOOPBACK), 1472 vxlan_snoop(skb->dev, &loopback, eth_hdr(skb)->h_source);
1193 eth_hdr(skb)->h_source);
1194 1473
1195 u64_stats_update_begin(&tx_stats->syncp); 1474 u64_stats_update_begin(&tx_stats->syncp);
1196 tx_stats->tx_packets++; 1475 tx_stats->tx_packets++;
@@ -1211,11 +1490,11 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1211 struct vxlan_rdst *rdst, bool did_rsc) 1490 struct vxlan_rdst *rdst, bool did_rsc)
1212{ 1491{
1213 struct vxlan_dev *vxlan = netdev_priv(dev); 1492 struct vxlan_dev *vxlan = netdev_priv(dev);
1214 struct rtable *rt; 1493 struct rtable *rt = NULL;
1215 const struct iphdr *old_iph; 1494 const struct iphdr *old_iph;
1216 struct flowi4 fl4; 1495 struct flowi4 fl4;
1217 __be32 dst; 1496 union vxlan_addr *dst;
1218 __be16 src_port, dst_port; 1497 __be16 src_port = 0, dst_port;
1219 u32 vni; 1498 u32 vni;
1220 __be16 df = 0; 1499 __be16 df = 0;
1221 __u8 tos, ttl; 1500 __u8 tos, ttl;
@@ -1223,9 +1502,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1223 1502
1224 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port; 1503 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port;
1225 vni = rdst->remote_vni; 1504 vni = rdst->remote_vni;
1226 dst = rdst->remote_ip; 1505 dst = &rdst->remote_ip;
1227 1506
1228 if (!dst) { 1507 if (vxlan_addr_any(dst)) {
1229 if (did_rsc) { 1508 if (did_rsc) {
1230 /* short-circuited back to local bridge */ 1509 /* short-circuited back to local bridge */
1231 vxlan_encap_bypass(skb, vxlan, vxlan); 1510 vxlan_encap_bypass(skb, vxlan, vxlan);
@@ -1237,7 +1516,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1237 old_iph = ip_hdr(skb); 1516 old_iph = ip_hdr(skb);
1238 1517
1239 ttl = vxlan->ttl; 1518 ttl = vxlan->ttl;
1240 if (!ttl && IN_MULTICAST(ntohl(dst))) 1519 if (!ttl && vxlan_addr_multicast(dst))
1241 ttl = 1; 1520 ttl = 1;
1242 1521
1243 tos = vxlan->tos; 1522 tos = vxlan->tos;
@@ -1246,48 +1525,101 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1246 1525
1247 src_port = vxlan_src_port(vxlan->port_min, vxlan->port_max, skb); 1526 src_port = vxlan_src_port(vxlan->port_min, vxlan->port_max, skb);
1248 1527
1249 memset(&fl4, 0, sizeof(fl4)); 1528 if (dst->sa.sa_family == AF_INET) {
1250 fl4.flowi4_oif = rdst->remote_ifindex; 1529 memset(&fl4, 0, sizeof(fl4));
1251 fl4.flowi4_tos = RT_TOS(tos); 1530 fl4.flowi4_oif = rdst->remote_ifindex;
1252 fl4.daddr = dst; 1531 fl4.flowi4_tos = RT_TOS(tos);
1253 fl4.saddr = vxlan->saddr; 1532 fl4.daddr = dst->sin.sin_addr.s_addr;
1254 1533 fl4.saddr = vxlan->saddr.sin.sin_addr.s_addr;
1255 rt = ip_route_output_key(dev_net(dev), &fl4); 1534
1256 if (IS_ERR(rt)) { 1535 rt = ip_route_output_key(dev_net(dev), &fl4);
1257 netdev_dbg(dev, "no route to %pI4\n", &dst); 1536 if (IS_ERR(rt)) {
1258 dev->stats.tx_carrier_errors++; 1537 netdev_dbg(dev, "no route to %pI4\n",
1259 goto tx_error; 1538 &dst->sin.sin_addr.s_addr);
1260 } 1539 dev->stats.tx_carrier_errors++;
1540 goto tx_error;
1541 }
1261 1542
1262 if (rt->dst.dev == dev) { 1543 if (rt->dst.dev == dev) {
1263 netdev_dbg(dev, "circular route to %pI4\n", &dst); 1544 netdev_dbg(dev, "circular route to %pI4\n",
1264 dev->stats.collisions++; 1545 &dst->sin.sin_addr.s_addr);
1265 goto rt_tx_error; 1546 dev->stats.collisions++;
1266 } 1547 goto tx_error;
1548 }
1549
1550 /* Bypass encapsulation if the destination is local */
1551 if (rt->rt_flags & RTCF_LOCAL &&
1552 !(rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) {
1553 struct vxlan_dev *dst_vxlan;
1554
1555 ip_rt_put(rt);
1556 dst_vxlan = vxlan_find_vni(dev_net(dev), vni, dst_port);
1557 if (!dst_vxlan)
1558 goto tx_error;
1559 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
1560 return;
1561 }
1267 1562
1268 /* Bypass encapsulation if the destination is local */ 1563 tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
1269 if (rt->rt_flags & RTCF_LOCAL && 1564 ttl = ttl ? : ip4_dst_hoplimit(&rt->dst);
1270 !(rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) {
1271 struct vxlan_dev *dst_vxlan;
1272 1565
1273 ip_rt_put(rt); 1566 err = vxlan_xmit_skb(dev_net(dev), vxlan->vn_sock, rt, skb,
1274 dst_vxlan = vxlan_find_vni(dev_net(dev), vni, dst_port); 1567 fl4.saddr, dst->sin.sin_addr.s_addr,
1275 if (!dst_vxlan) 1568 tos, ttl, df, src_port, dst_port,
1569 htonl(vni << 8));
1570
1571 if (err < 0)
1572 goto rt_tx_error;
1573 iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
1574#if IS_ENABLED(CONFIG_IPV6)
1575 } else {
1576 struct sock *sk = vxlan->vn_sock->sock->sk;
1577 struct dst_entry *ndst;
1578 struct flowi6 fl6;
1579 u32 flags;
1580
1581 memset(&fl6, 0, sizeof(fl6));
1582 fl6.flowi6_oif = rdst->remote_ifindex;
1583 fl6.daddr = dst->sin6.sin6_addr;
1584 fl6.saddr = vxlan->saddr.sin6.sin6_addr;
1585 fl6.flowi6_proto = skb->protocol;
1586
1587 if (ipv6_stub->ipv6_dst_lookup(sk, &ndst, &fl6)) {
1588 netdev_dbg(dev, "no route to %pI6\n",
1589 &dst->sin6.sin6_addr);
1590 dev->stats.tx_carrier_errors++;
1276 goto tx_error; 1591 goto tx_error;
1277 vxlan_encap_bypass(skb, vxlan, dst_vxlan); 1592 }
1278 return;
1279 }
1280 1593
1281 tos = ip_tunnel_ecn_encap(tos, old_iph, skb); 1594 if (ndst->dev == dev) {
1282 ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); 1595 netdev_dbg(dev, "circular route to %pI6\n",
1596 &dst->sin6.sin6_addr);
1597 dst_release(ndst);
1598 dev->stats.collisions++;
1599 goto tx_error;
1600 }
1283 1601
1284 err = vxlan_xmit_skb(dev_net(dev), vxlan->vn_sock, rt, skb, 1602 /* Bypass encapsulation if the destination is local */
1285 fl4.saddr, dst, tos, ttl, df, 1603 flags = ((struct rt6_info *)ndst)->rt6i_flags;
1286 src_port, dst_port, htonl(vni << 8)); 1604 if (flags & RTF_LOCAL &&
1605 !(flags & (RTCF_BROADCAST | RTCF_MULTICAST))) {
1606 struct vxlan_dev *dst_vxlan;
1607
1608 dst_release(ndst);
1609 dst_vxlan = vxlan_find_vni(dev_net(dev), vni, dst_port);
1610 if (!dst_vxlan)
1611 goto tx_error;
1612 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
1613 return;
1614 }
1287 1615
1288 if (err < 0) 1616 ttl = ttl ? : ip6_dst_hoplimit(ndst);
1289 goto rt_tx_error; 1617
1290 iptunnel_xmit_stats(err, &dev->stats, dev->tstats); 1618 err = vxlan6_xmit_skb(dev_net(dev), vxlan->vn_sock, ndst, skb,
1619 dev, &fl6.saddr, &fl6.daddr, 0, ttl,
1620 src_port, dst_port, htonl(vni << 8));
1621#endif
1622 }
1291 1623
1292 return; 1624 return;
1293 1625
@@ -1464,8 +1796,8 @@ static int vxlan_open(struct net_device *dev)
1464 if (!vs) 1796 if (!vs)
1465 return -ENOTCONN; 1797 return -ENOTCONN;
1466 1798
1467 if (IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip)) && 1799 if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip) &&
1468 vxlan_group_used(vn, vxlan->default_dst.remote_ip)) { 1800 vxlan_group_used(vn, &vxlan->default_dst.remote_ip)) {
1469 vxlan_sock_hold(vs); 1801 vxlan_sock_hold(vs);
1470 dev_hold(dev); 1802 dev_hold(dev);
1471 queue_work(vxlan_wq, &vxlan->igmp_join); 1803 queue_work(vxlan_wq, &vxlan->igmp_join);
@@ -1503,8 +1835,8 @@ static int vxlan_stop(struct net_device *dev)
1503 struct vxlan_dev *vxlan = netdev_priv(dev); 1835 struct vxlan_dev *vxlan = netdev_priv(dev);
1504 struct vxlan_sock *vs = vxlan->vn_sock; 1836 struct vxlan_sock *vs = vxlan->vn_sock;
1505 1837
1506 if (vs && IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip)) && 1838 if (vs && vxlan_addr_multicast(&vxlan->default_dst.remote_ip) &&
1507 ! vxlan_group_used(vn, vxlan->default_dst.remote_ip)) { 1839 ! vxlan_group_used(vn, &vxlan->default_dst.remote_ip)) {
1508 vxlan_sock_hold(vs); 1840 vxlan_sock_hold(vs);
1509 dev_hold(dev); 1841 dev_hold(dev);
1510 queue_work(vxlan_wq, &vxlan->igmp_leave); 1842 queue_work(vxlan_wq, &vxlan->igmp_leave);
@@ -1552,7 +1884,10 @@ static void vxlan_setup(struct net_device *dev)
1552 1884
1553 eth_hw_addr_random(dev); 1885 eth_hw_addr_random(dev);
1554 ether_setup(dev); 1886 ether_setup(dev);
1555 dev->hard_header_len = ETH_HLEN + VXLAN_HEADROOM; 1887 if (vxlan->default_dst.remote_ip.sa.sa_family == AF_INET6)
1888 dev->hard_header_len = ETH_HLEN + VXLAN6_HEADROOM;
1889 else
1890 dev->hard_header_len = ETH_HLEN + VXLAN_HEADROOM;
1556 1891
1557 dev->netdev_ops = &vxlan_netdev_ops; 1892 dev->netdev_ops = &vxlan_netdev_ops;
1558 dev->destructor = free_netdev; 1893 dev->destructor = free_netdev;
@@ -1597,8 +1932,10 @@ static void vxlan_setup(struct net_device *dev)
1597static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = { 1932static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = {
1598 [IFLA_VXLAN_ID] = { .type = NLA_U32 }, 1933 [IFLA_VXLAN_ID] = { .type = NLA_U32 },
1599 [IFLA_VXLAN_GROUP] = { .len = FIELD_SIZEOF(struct iphdr, daddr) }, 1934 [IFLA_VXLAN_GROUP] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
1935 [IFLA_VXLAN_GROUP6] = { .len = sizeof(struct in6_addr) },
1600 [IFLA_VXLAN_LINK] = { .type = NLA_U32 }, 1936 [IFLA_VXLAN_LINK] = { .type = NLA_U32 },
1601 [IFLA_VXLAN_LOCAL] = { .len = FIELD_SIZEOF(struct iphdr, saddr) }, 1937 [IFLA_VXLAN_LOCAL] = { .len = FIELD_SIZEOF(struct iphdr, saddr) },
1938 [IFLA_VXLAN_LOCAL6] = { .len = sizeof(struct in6_addr) },
1602 [IFLA_VXLAN_TOS] = { .type = NLA_U8 }, 1939 [IFLA_VXLAN_TOS] = { .type = NLA_U8 },
1603 [IFLA_VXLAN_TTL] = { .type = NLA_U8 }, 1940 [IFLA_VXLAN_TTL] = { .type = NLA_U8 },
1604 [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 }, 1941 [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 },
@@ -1669,58 +2006,132 @@ static void vxlan_del_work(struct work_struct *work)
1669 kfree_rcu(vs, rcu); 2006 kfree_rcu(vs, rcu);
1670} 2007}
1671 2008
1672static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port, 2009#if IS_ENABLED(CONFIG_IPV6)
1673 vxlan_rcv_t *rcv, void *data) 2010/* Create UDP socket for encapsulation receive. AF_INET6 socket
2011 * could be used for both IPv4 and IPv6 communications, but
2012 * users may set bindv6only=1.
2013 */
2014static int create_v6_sock(struct net *net, __be16 port, struct socket **psock)
2015{
2016 struct sock *sk;
2017 struct socket *sock;
2018 struct sockaddr_in6 vxlan_addr = {
2019 .sin6_family = AF_INET6,
2020 .sin6_port = port,
2021 };
2022 int rc, val = 1;
2023
2024 rc = sock_create_kern(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, &sock);
2025 if (rc < 0) {
2026 pr_debug("UDPv6 socket create failed\n");
2027 return rc;
2028 }
2029
2030 /* Put in proper namespace */
2031 sk = sock->sk;
2032 sk_change_net(sk, net);
2033
2034 kernel_setsockopt(sock, SOL_IPV6, IPV6_V6ONLY,
2035 (char *)&val, sizeof(val));
2036 rc = kernel_bind(sock, (struct sockaddr *)&vxlan_addr,
2037 sizeof(struct sockaddr_in6));
2038 if (rc < 0) {
2039 pr_debug("bind for UDPv6 socket %pI6:%u (%d)\n",
2040 &vxlan_addr.sin6_addr, ntohs(vxlan_addr.sin6_port), rc);
2041 sk_release_kernel(sk);
2042 return rc;
2043 }
2044 /* At this point, IPv6 module should have been loaded in
2045 * sock_create_kern().
2046 */
2047 BUG_ON(!ipv6_stub);
2048
2049 *psock = sock;
2050 /* Disable multicast loopback */
2051 inet_sk(sk)->mc_loop = 0;
2052 return 0;
2053}
2054
2055#else
2056
2057static int create_v6_sock(struct net *net, __be16 port, struct socket **psock)
2058{
2059 return -EPFNOSUPPORT;
2060}
2061#endif
2062
2063static int create_v4_sock(struct net *net, __be16 port, struct socket **psock)
1674{ 2064{
1675 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
1676 struct vxlan_sock *vs;
1677 struct sock *sk; 2065 struct sock *sk;
2066 struct socket *sock;
1678 struct sockaddr_in vxlan_addr = { 2067 struct sockaddr_in vxlan_addr = {
1679 .sin_family = AF_INET, 2068 .sin_family = AF_INET,
1680 .sin_addr.s_addr = htonl(INADDR_ANY), 2069 .sin_addr.s_addr = htonl(INADDR_ANY),
1681 .sin_port = port, 2070 .sin_port = port,
1682 }; 2071 };
1683 int rc; 2072 int rc;
1684 unsigned int h;
1685
1686 vs = kmalloc(sizeof(*vs), GFP_KERNEL);
1687 if (!vs) {
1688 pr_debug("memory alocation failure\n");
1689 return ERR_PTR(-ENOMEM);
1690 }
1691
1692 for (h = 0; h < VNI_HASH_SIZE; ++h)
1693 INIT_HLIST_HEAD(&vs->vni_list[h]);
1694
1695 INIT_WORK(&vs->del_work, vxlan_del_work);
1696 2073
1697 /* Create UDP socket for encapsulation receive. */ 2074 /* Create UDP socket for encapsulation receive. */
1698 rc = sock_create_kern(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &vs->sock); 2075 rc = sock_create_kern(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock);
1699 if (rc < 0) { 2076 if (rc < 0) {
1700 pr_debug("UDP socket create failed\n"); 2077 pr_debug("UDP socket create failed\n");
1701 kfree(vs); 2078 return rc;
1702 return ERR_PTR(rc);
1703 } 2079 }
1704 2080
1705 /* Put in proper namespace */ 2081 /* Put in proper namespace */
1706 sk = vs->sock->sk; 2082 sk = sock->sk;
1707 sk_change_net(sk, net); 2083 sk_change_net(sk, net);
1708 2084
1709 rc = kernel_bind(vs->sock, (struct sockaddr *) &vxlan_addr, 2085 rc = kernel_bind(sock, (struct sockaddr *) &vxlan_addr,
1710 sizeof(vxlan_addr)); 2086 sizeof(vxlan_addr));
1711 if (rc < 0) { 2087 if (rc < 0) {
1712 pr_debug("bind for UDP socket %pI4:%u (%d)\n", 2088 pr_debug("bind for UDP socket %pI4:%u (%d)\n",
1713 &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc); 2089 &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc);
1714 sk_release_kernel(sk); 2090 sk_release_kernel(sk);
2091 return rc;
2092 }
2093
2094 *psock = sock;
2095 /* Disable multicast loopback */
2096 inet_sk(sk)->mc_loop = 0;
2097 return 0;
2098}
2099
2100/* Create new listen socket if needed */
2101static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port,
2102 vxlan_rcv_t *rcv, void *data, bool ipv6)
2103{
2104 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
2105 struct vxlan_sock *vs;
2106 struct socket *sock;
2107 struct sock *sk;
2108 int rc = 0;
2109 unsigned int h;
2110
2111 vs = kmalloc(sizeof(*vs), GFP_KERNEL);
2112 if (!vs)
2113 return ERR_PTR(-ENOMEM);
2114
2115 for (h = 0; h < VNI_HASH_SIZE; ++h)
2116 INIT_HLIST_HEAD(&vs->vni_list[h]);
2117
2118 INIT_WORK(&vs->del_work, vxlan_del_work);
2119
2120 if (ipv6)
2121 rc = create_v6_sock(net, port, &sock);
2122 else
2123 rc = create_v4_sock(net, port, &sock);
2124 if (rc < 0) {
1715 kfree(vs); 2125 kfree(vs);
1716 return ERR_PTR(rc); 2126 return ERR_PTR(rc);
1717 } 2127 }
2128
2129 vs->sock = sock;
2130 sk = sock->sk;
1718 atomic_set(&vs->refcnt, 1); 2131 atomic_set(&vs->refcnt, 1);
1719 vs->rcv = rcv; 2132 vs->rcv = rcv;
1720 vs->data = data; 2133 vs->data = data;
1721 2134
1722 /* Disable multicast loopback */
1723 inet_sk(sk)->mc_loop = 0;
1724 spin_lock(&vn->sock_lock); 2135 spin_lock(&vn->sock_lock);
1725 hlist_add_head_rcu(&vs->hlist, vs_head(net, port)); 2136 hlist_add_head_rcu(&vs->hlist, vs_head(net, port));
1726 spin_unlock(&vn->sock_lock); 2137 spin_unlock(&vn->sock_lock);
@@ -1728,18 +2139,24 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port,
1728 /* Mark socket as an encapsulation socket. */ 2139 /* Mark socket as an encapsulation socket. */
1729 udp_sk(sk)->encap_type = 1; 2140 udp_sk(sk)->encap_type = 1;
1730 udp_sk(sk)->encap_rcv = vxlan_udp_encap_recv; 2141 udp_sk(sk)->encap_rcv = vxlan_udp_encap_recv;
1731 udp_encap_enable(); 2142#if IS_ENABLED(CONFIG_IPV6)
2143 if (ipv6)
2144 ipv6_stub->udpv6_encap_enable();
2145 else
2146#endif
2147 udp_encap_enable();
2148
1732 return vs; 2149 return vs;
1733} 2150}
1734 2151
1735struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, 2152struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
1736 vxlan_rcv_t *rcv, void *data, 2153 vxlan_rcv_t *rcv, void *data,
1737 bool no_share) 2154 bool no_share, bool ipv6)
1738{ 2155{
1739 struct vxlan_net *vn = net_generic(net, vxlan_net_id); 2156 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
1740 struct vxlan_sock *vs; 2157 struct vxlan_sock *vs;
1741 2158
1742 vs = vxlan_socket_create(net, port, rcv, data); 2159 vs = vxlan_socket_create(net, port, rcv, data, ipv6);
1743 if (!IS_ERR(vs)) 2160 if (!IS_ERR(vs))
1744 return vs; 2161 return vs;
1745 2162
@@ -1772,7 +2189,7 @@ static void vxlan_sock_work(struct work_struct *work)
1772 __be16 port = vxlan->dst_port; 2189 __be16 port = vxlan->dst_port;
1773 struct vxlan_sock *nvs; 2190 struct vxlan_sock *nvs;
1774 2191
1775 nvs = vxlan_sock_add(net, port, vxlan_rcv, NULL, false); 2192 nvs = vxlan_sock_add(net, port, vxlan_rcv, NULL, false, vxlan->flags & VXLAN_F_IPV6);
1776 spin_lock(&vn->sock_lock); 2193 spin_lock(&vn->sock_lock);
1777 if (!IS_ERR(nvs)) 2194 if (!IS_ERR(nvs))
1778 vxlan_vs_add_dev(nvs, vxlan); 2195 vxlan_vs_add_dev(nvs, vxlan);
@@ -1789,6 +2206,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
1789 struct vxlan_rdst *dst = &vxlan->default_dst; 2206 struct vxlan_rdst *dst = &vxlan->default_dst;
1790 __u32 vni; 2207 __u32 vni;
1791 int err; 2208 int err;
2209 bool use_ipv6 = false;
1792 2210
1793 if (!data[IFLA_VXLAN_ID]) 2211 if (!data[IFLA_VXLAN_ID])
1794 return -EINVAL; 2212 return -EINVAL;
@@ -1796,11 +2214,32 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
1796 vni = nla_get_u32(data[IFLA_VXLAN_ID]); 2214 vni = nla_get_u32(data[IFLA_VXLAN_ID]);
1797 dst->remote_vni = vni; 2215 dst->remote_vni = vni;
1798 2216
1799 if (data[IFLA_VXLAN_GROUP]) 2217 if (data[IFLA_VXLAN_GROUP]) {
1800 dst->remote_ip = nla_get_be32(data[IFLA_VXLAN_GROUP]); 2218 dst->remote_ip.sin.sin_addr.s_addr = nla_get_be32(data[IFLA_VXLAN_GROUP]);
2219 dst->remote_ip.sa.sa_family = AF_INET;
2220 } else if (data[IFLA_VXLAN_GROUP6]) {
2221 if (!IS_ENABLED(CONFIG_IPV6))
2222 return -EPFNOSUPPORT;
2223
2224 nla_memcpy(&dst->remote_ip.sin6.sin6_addr, data[IFLA_VXLAN_GROUP6],
2225 sizeof(struct in6_addr));
2226 dst->remote_ip.sa.sa_family = AF_INET6;
2227 use_ipv6 = true;
2228 }
1801 2229
1802 if (data[IFLA_VXLAN_LOCAL]) 2230 if (data[IFLA_VXLAN_LOCAL]) {
1803 vxlan->saddr = nla_get_be32(data[IFLA_VXLAN_LOCAL]); 2231 vxlan->saddr.sin.sin_addr.s_addr = nla_get_be32(data[IFLA_VXLAN_LOCAL]);
2232 vxlan->saddr.sa.sa_family = AF_INET;
2233 } else if (data[IFLA_VXLAN_LOCAL6]) {
2234 if (!IS_ENABLED(CONFIG_IPV6))
2235 return -EPFNOSUPPORT;
2236
2237 /* TODO: respect scope id */
2238 nla_memcpy(&vxlan->saddr.sin6.sin6_addr, data[IFLA_VXLAN_LOCAL6],
2239 sizeof(struct in6_addr));
2240 vxlan->saddr.sa.sa_family = AF_INET6;
2241 use_ipv6 = true;
2242 }
1804 2243
1805 if (data[IFLA_VXLAN_LINK] && 2244 if (data[IFLA_VXLAN_LINK] &&
1806 (dst->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]))) { 2245 (dst->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]))) {
@@ -1812,12 +2251,23 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
1812 return -ENODEV; 2251 return -ENODEV;
1813 } 2252 }
1814 2253
2254#if IS_ENABLED(CONFIG_IPV6)
2255 if (use_ipv6) {
2256 struct inet6_dev *idev = __in6_dev_get(lowerdev);
2257 if (idev && idev->cnf.disable_ipv6) {
2258 pr_info("IPv6 is disabled via sysctl\n");
2259 return -EPERM;
2260 }
2261 vxlan->flags |= VXLAN_F_IPV6;
2262 }
2263#endif
2264
1815 if (!tb[IFLA_MTU]) 2265 if (!tb[IFLA_MTU])
1816 dev->mtu = lowerdev->mtu - VXLAN_HEADROOM; 2266 dev->mtu = lowerdev->mtu - (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
1817 2267
1818 /* update header length based on lower device */ 2268 /* update header length based on lower device */
1819 dev->hard_header_len = lowerdev->hard_header_len + 2269 dev->hard_header_len = lowerdev->hard_header_len +
1820 VXLAN_HEADROOM; 2270 (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM);
1821 } 2271 }
1822 2272
1823 if (data[IFLA_VXLAN_TOS]) 2273 if (data[IFLA_VXLAN_TOS])
@@ -1868,7 +2318,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
1868 2318
1869 /* create an fdb entry for default destination */ 2319 /* create an fdb entry for default destination */
1870 err = vxlan_fdb_create(vxlan, all_zeros_mac, 2320 err = vxlan_fdb_create(vxlan, all_zeros_mac,
1871 vxlan->default_dst.remote_ip, 2321 &vxlan->default_dst.remote_ip,
1872 NUD_REACHABLE|NUD_PERMANENT, 2322 NUD_REACHABLE|NUD_PERMANENT,
1873 NLM_F_EXCL|NLM_F_CREATE, 2323 NLM_F_EXCL|NLM_F_CREATE,
1874 vxlan->dst_port, vxlan->default_dst.remote_vni, 2324 vxlan->dst_port, vxlan->default_dst.remote_vni,
@@ -1905,9 +2355,9 @@ static size_t vxlan_get_size(const struct net_device *dev)
1905{ 2355{
1906 2356
1907 return nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_ID */ 2357 return nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_ID */
1908 nla_total_size(sizeof(__be32)) +/* IFLA_VXLAN_GROUP */ 2358 nla_total_size(sizeof(struct in6_addr)) + /* IFLA_VXLAN_GROUP{6} */
1909 nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LINK */ 2359 nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LINK */
1910 nla_total_size(sizeof(__be32))+ /* IFLA_VXLAN_LOCAL */ 2360 nla_total_size(sizeof(struct in6_addr)) + /* IFLA_VXLAN_LOCAL{6} */
1911 nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TTL */ 2361 nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TTL */
1912 nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TOS */ 2362 nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TOS */
1913 nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_LEARNING */ 2363 nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_LEARNING */
@@ -1934,14 +2384,36 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
1934 if (nla_put_u32(skb, IFLA_VXLAN_ID, dst->remote_vni)) 2384 if (nla_put_u32(skb, IFLA_VXLAN_ID, dst->remote_vni))
1935 goto nla_put_failure; 2385 goto nla_put_failure;
1936 2386
1937 if (dst->remote_ip && nla_put_be32(skb, IFLA_VXLAN_GROUP, dst->remote_ip)) 2387 if (!vxlan_addr_any(&dst->remote_ip)) {
1938 goto nla_put_failure; 2388 if (dst->remote_ip.sa.sa_family == AF_INET) {
2389 if (nla_put_be32(skb, IFLA_VXLAN_GROUP,
2390 dst->remote_ip.sin.sin_addr.s_addr))
2391 goto nla_put_failure;
2392#if IS_ENABLED(CONFIG_IPV6)
2393 } else {
2394 if (nla_put(skb, IFLA_VXLAN_GROUP6, sizeof(struct in6_addr),
2395 &dst->remote_ip.sin6.sin6_addr))
2396 goto nla_put_failure;
2397#endif
2398 }
2399 }
1939 2400
1940 if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) 2401 if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex))
1941 goto nla_put_failure; 2402 goto nla_put_failure;
1942 2403
1943 if (vxlan->saddr && nla_put_be32(skb, IFLA_VXLAN_LOCAL, vxlan->saddr)) 2404 if (!vxlan_addr_any(&vxlan->saddr)) {
1944 goto nla_put_failure; 2405 if (vxlan->saddr.sa.sa_family == AF_INET) {
2406 if (nla_put_be32(skb, IFLA_VXLAN_LOCAL,
2407 vxlan->saddr.sin.sin_addr.s_addr))
2408 goto nla_put_failure;
2409#if IS_ENABLED(CONFIG_IPV6)
2410 } else {
2411 if (nla_put(skb, IFLA_VXLAN_LOCAL6, sizeof(struct in6_addr),
2412 &vxlan->saddr.sin6.sin6_addr))
2413 goto nla_put_failure;
2414#endif
2415 }
2416 }
1945 2417
1946 if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->ttl) || 2418 if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->ttl) ||
1947 nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->tos) || 2419 nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->tos) ||
diff --git a/include/net/vxlan.h b/include/net/vxlan.h
index ad342e3688a0..d2b88cafa7a2 100644
--- a/include/net/vxlan.h
+++ b/include/net/vxlan.h
@@ -25,7 +25,7 @@ struct vxlan_sock {
25 25
26struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, 26struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
27 vxlan_rcv_t *rcv, void *data, 27 vxlan_rcv_t *rcv, void *data,
28 bool no_share); 28 bool no_share, bool ipv6);
29 29
30void vxlan_sock_release(struct vxlan_sock *vs); 30void vxlan_sock_release(struct vxlan_sock *vs);
31 31
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 04c0e7a5d484..80394e8dc3a3 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -314,6 +314,8 @@ enum {
314 IFLA_VXLAN_L2MISS, 314 IFLA_VXLAN_L2MISS,
315 IFLA_VXLAN_L3MISS, 315 IFLA_VXLAN_L3MISS,
316 IFLA_VXLAN_PORT, /* destination port */ 316 IFLA_VXLAN_PORT, /* destination port */
317 IFLA_VXLAN_GROUP6,
318 IFLA_VXLAN_LOCAL6,
317 __IFLA_VXLAN_MAX 319 __IFLA_VXLAN_MAX
318}; 320};
319#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1) 321#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
diff --git a/net/openvswitch/vport-vxlan.c b/net/openvswitch/vport-vxlan.c
index 36848bd54a77..a0060245b4e1 100644
--- a/net/openvswitch/vport-vxlan.c
+++ b/net/openvswitch/vport-vxlan.c
@@ -123,7 +123,7 @@ static struct vport *vxlan_tnl_create(const struct vport_parms *parms)
123 vxlan_port = vxlan_vport(vport); 123 vxlan_port = vxlan_vport(vport);
124 strncpy(vxlan_port->name, parms->name, IFNAMSIZ); 124 strncpy(vxlan_port->name, parms->name, IFNAMSIZ);
125 125
126 vs = vxlan_sock_add(net, htons(dst_port), vxlan_rcv, vport, true); 126 vs = vxlan_sock_add(net, htons(dst_port), vxlan_rcv, vport, true, false);
127 if (IS_ERR(vs)) { 127 if (IS_ERR(vs)) {
128 ovs_vport_free(vport); 128 ovs_vport_free(vport);
129 return (void *)vs; 129 return (void *)vs;