| @@ -6,9 +6,6 @@ · 5 unmodified lines |
| 6 | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | 8 | * published by the Free Software Foundation. |
| 9 | | − * |
| 10 | | − * TODO |
| 11 | | − * - IPv6 (not in RFC) |
| 12 | 9 | */ |
| 13 | 10 | |
| 14 | 11 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| @@ -43,6 +40,11 @@ · 28 unmodified lines |
| 43 | 40 | #include <net/net_namespace.h> |
| 44 | 41 | #include <net/netns/generic.h> |
| 45 | 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 | 49 | #define VXLAN_VERSION "0.1" |
| 48 | 50 | |
| @@ -59,6 +61,8 @@ · 10 unmodified lines |
| 59 | 61 | #define VXLAN_VID_MASK (VXLAN_N_VID - 1) |
| 60 | 62 | /* IP header + UDP + VXLAN + Ethernet header */ |
| 61 | 63 | #define VXLAN_HEADROOM (20 + 8 + 8 + 14) |
| 64 | +/* IPv6 header + UDP + VXLAN + Ethernet header */ |
| 65 | +#define VXLAN6_HEADROOM (40 + 8 + 8 + 14) |
| 62 | 66 | #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr)) |
| 63 | 67 | |
| 64 | 68 | #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ |
| @@ -92,8 +96,14 @@ struct vxlan_net { · 27 unmodified lines |
| 92 | 96 | spinlock_t sock_lock; |
| 93 | 97 | }; |
| 94 | 98 | |
| 99 | +union vxlan_addr { |
| 100 | + struct sockaddr_in sin; |
| 101 | + struct sockaddr_in6 sin6; |
| 102 | + struct sockaddr sa; |
| 103 | +}; |
| 104 | + |
| 95 | 105 | struct vxlan_rdst { |
| 96 | | − __be32 remote_ip; |
| 106 | + union vxlan_addr remote_ip; |
| 97 | 107 | __be16 remote_port; |
| 98 | 108 | u32 remote_vni; |
| 99 | 109 | u32 remote_ifindex; |
| @@ -120,7 +130,7 @@ struct vxlan_dev { · 20 unmodified lines |
| 120 | 130 | struct vxlan_sock *vn_sock; /* listening socket */ |
| 121 | 131 | struct net_device *dev; |
| 122 | 132 | struct vxlan_rdst default_dst; /* default destination */ |
| 123 | | − __be32 saddr; /* source address */ |
| 133 | + union vxlan_addr saddr; /* source address */ |
| 124 | 134 | __be16 dst_port; |
| 125 | 135 | __u16 port_min; /* source port range */ |
| 126 | 136 | __u16 port_max; |
| @@ -146,6 +156,7 @@ struct vxlan_dev { · 19 unmodified lines |
| 146 | 156 | #define VXLAN_F_RSC 0x04 |
| 147 | 157 | #define VXLAN_F_L2MISS 0x08 |
| 148 | 158 | #define VXLAN_F_L3MISS 0x10 |
| 159 | +#define VXLAN_F_IPV6 0x20 /* internal flag */ |
| 149 | 160 | |
| 150 | 161 | /* salt for hash table */ |
| 151 | 162 | static u32 vxlan_salt __read_mostly; |
| @@ -153,6 +164,96 @@ static struct workqueue_struct *vxlan_wq; · 1 unmodified line |
| 153 | 164 | |
| 154 | 165 | static void vxlan_sock_work(struct work_struct *work); |
| 155 | 166 | |
| 167 | +#if IS_ENABLED(CONFIG_IPV6) |
| 168 | +static inline |
| 169 | +bool 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 | + |
| 179 | +static 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 | + |
| 187 | +static 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 | + |
| 195 | +static 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 | + |
| 210 | +static 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 | + |
| 221 | +static inline |
| 222 | +bool 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 | + |
| 227 | +static inline bool vxlan_addr_any(const union vxlan_addr *ipa) |
| 228 | +{ |
| 229 | + return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY); |
| 230 | +} |
| 231 | + |
| 232 | +static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa) |
| 233 | +{ |
| 234 | + return IN_MULTICAST(ntohl(ipa->sin.sin_addr.s_addr)); |
| 235 | +} |
| 236 | + |
| 237 | +static 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 | + |
| 250 | +static 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 | 257 | /* Virtual Network hash table head */ |
| 157 | 258 | static 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, · 80 unmodified lines |
| 239 | 340 | |
| 240 | 341 | if (type == RTM_GETNEIGH) { |
| 241 | 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 | 344 | send_eth = !is_zero_ether_addr(fdb->eth_addr); |
| 244 | 345 | } else |
| 245 | 346 | ndm->ndm_family = AF_BRIDGE; |
| @@ -251,7 +352,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan, · 5 unmodified lines |
| 251 | 352 | if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr)) |
| 252 | 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 | 356 | goto nla_put_failure; |
| 256 | 357 | |
| 257 | 358 | if (rdst->remote_port && rdst->remote_port != vxlan->dst_port && |
| @@ -283,7 +384,7 @@ static inline size_t vxlan_nlmsg_size(void) · 25 unmodified lines |
| 283 | 384 | { |
| 284 | 385 | return NLMSG_ALIGN(sizeof(struct ndmsg)) |
| 285 | 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 | 388 | + nla_total_size(sizeof(__be16)) /* NDA_PORT */ |
| 288 | 389 | + nla_total_size(sizeof(__be32)) /* NDA_VNI */ |
| 289 | 390 | + nla_total_size(sizeof(__u32)) /* NDA_IFINDEX */ |
| @@ -317,14 +418,14 @@ errout: · 27 unmodified lines |
| 317 | 418 | rtnl_set_sk_err(net, RTNLGRP_NEIGH, err); |
| 318 | 419 | } |
| 319 | 420 | |
| 320 | | −static void vxlan_ip_miss(struct net_device *dev, __be32 ipa) |
| 421 | +static void vxlan_ip_miss(struct net_device *dev, union vxlan_addr *ipa) |
| 321 | 422 | { |
| 322 | 423 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 323 | 424 | struct vxlan_fdb f = { |
| 324 | 425 | .state = NUD_STALE, |
| 325 | 426 | }; |
| 326 | 427 | struct vxlan_rdst remote = { |
| 327 | | − .remote_ip = ipa, /* goes to NDA_DST */ |
| 428 | + .remote_ip = *ipa, /* goes to NDA_DST */ |
| 328 | 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, · 66 unmodified lines |
| 397 | 498 | |
| 398 | 499 | /* caller should hold vxlan->hash_lock */ |
| 399 | 500 | static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f, |
| 400 | | − __be32 ip, __be16 port, |
| 501 | + union vxlan_addr *ip, __be16 port, |
| 401 | 502 | __u32 vni, __u32 ifindex) |
| 402 | 503 | { |
| 403 | 504 | struct vxlan_rdst *rd; |
| 404 | 505 | |
| 405 | 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 | 508 | rd->remote_port == port && |
| 408 | 509 | rd->remote_vni == vni && |
| 409 | 510 | rd->remote_ifindex == ifindex) |
| @@ -415,7 +516,7 @@ static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f, · 5 unmodified lines |
| 415 | 516 | |
| 416 | 517 | /* Replace destination of unicast mac */ |
| 417 | 518 | static 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 | 521 | struct vxlan_rdst *rd; |
| 421 | 522 | |
| @@ -426,7 +527,7 @@ static int vxlan_fdb_replace(struct vxlan_fdb *f, · 4 unmodified lines |
| 426 | 527 | rd = list_first_entry_or_null(&f->remotes, struct vxlan_rdst, list); |
| 427 | 528 | if (!rd) |
| 428 | 529 | return 0; |
| 429 | | − rd->remote_ip = ip; |
| 530 | + rd->remote_ip = *ip; |
| 430 | 531 | rd->remote_port = port; |
| 431 | 532 | rd->remote_vni = vni; |
| 432 | 533 | rd->remote_ifindex = ifindex; |
| @@ -435,7 +536,7 @@ static int vxlan_fdb_replace(struct vxlan_fdb *f, · 2 unmodified lines |
| 435 | 536 | |
| 436 | 537 | /* Add/update destinations for multicast */ |
| 437 | 538 | static 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 | 541 | struct vxlan_rdst *rd; |
| 441 | 542 | |
| @@ -446,7 +547,7 @@ static int vxlan_fdb_append(struct vxlan_fdb *f, · 4 unmodified lines |
| 446 | 547 | rd = kmalloc(sizeof(*rd), GFP_ATOMIC); |
| 447 | 548 | if (rd == NULL) |
| 448 | 549 | return -ENOBUFS; |
| 449 | | − rd->remote_ip = ip; |
| 550 | + rd->remote_ip = *ip; |
| 450 | 551 | rd->remote_port = port; |
| 451 | 552 | rd->remote_vni = vni; |
| 452 | 553 | rd->remote_ifindex = ifindex; |
| @@ -458,7 +559,7 @@ static int vxlan_fdb_append(struct vxlan_fdb *f, · 5 unmodified lines |
| 458 | 559 | |
| 459 | 560 | /* Add new entry to forwarding table -- assumes lock held */ |
| 460 | 561 | static int vxlan_fdb_create(struct vxlan_dev *vxlan, |
| 461 | | − const u8 *mac, __be32 ip, |
| 562 | + const u8 *mac, union vxlan_addr *ip, |
| 462 | 563 | __u16 state, __u16 flags, |
| 463 | 564 | __be16 port, __u32 vni, __u32 ifindex, |
| 464 | 565 | __u8 ndm_flags) |
| @@ -517,7 +618,7 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan, · 52 unmodified lines |
| 517 | 618 | (is_multicast_ether_addr(mac) || is_zero_ether_addr(mac))) |
| 518 | 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 | 622 | f = kmalloc(sizeof(*f), GFP_ATOMIC); |
| 522 | 623 | if (!f) |
| 523 | 624 | return -ENOMEM; |
| @@ -565,17 +666,26 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f) · 41 unmodified lines |
| 565 | 666 | } |
| 566 | 667 | |
| 567 | 668 | static 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 | 671 | struct net *net = dev_net(vxlan->dev); |
| 672 | + int err; |
| 571 | 673 | |
| 572 | 674 | if (tb[NDA_DST]) { |
| 573 | | − if (nla_len(tb[NDA_DST]) != sizeof(__be32)) |
| 574 | | − return -EAFNOSUPPORT; |
| 575 | | − |
| 576 | | − *ip = nla_get_be32(tb[NDA_DST]); |
| 675 | + err = vxlan_nla_get_addr(ip, tb[NDA_DST]); |
| 676 | + if (err) |
| 677 | + return err; |
| 577 | 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 | 691 | if (tb[NDA_PORT]) { |
| @@ -618,7 +728,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], · 36 unmodified lines |
| 618 | 728 | { |
| 619 | 729 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 620 | 730 | /* struct net *net = dev_net(vxlan->dev); */ |
| 621 | | − __be32 ip; |
| 731 | + union vxlan_addr ip; |
| 622 | 732 | __be16 port; |
| 623 | 733 | u32 vni, ifindex; |
| 624 | 734 | int err; |
| @@ -637,7 +747,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], · 12 unmodified lines |
| 637 | 747 | return err; |
| 638 | 748 | |
| 639 | 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 | 751 | port, vni, ifindex, ndm->ndm_flags); |
| 642 | 752 | spin_unlock_bh(&vxlan->hash_lock); |
| 643 | 753 | |
| @@ -652,7 +762,7 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], · 8 unmodified lines |
| 652 | 762 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 653 | 763 | struct vxlan_fdb *f; |
| 654 | 764 | struct vxlan_rdst *rd = NULL; |
| 655 | | − __be32 ip; |
| 765 | + union vxlan_addr ip; |
| 656 | 766 | __be16 port; |
| 657 | 767 | u32 vni, ifindex; |
| 658 | 768 | int err; |
| @@ -668,8 +778,8 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], · 9 unmodified lines |
| 668 | 778 | if (!f) |
| 669 | 779 | goto out; |
| 670 | 780 | |
| 671 | | − if (ip != htonl(INADDR_ANY)) { |
| 672 | | − rd = vxlan_fdb_find_rdst(f, ip, port, vni, ifindex); |
| 781 | + if (!vxlan_addr_any(&ip)) { |
| 782 | + rd = vxlan_fdb_find_rdst(f, &ip, port, vni, ifindex); |
| 673 | 783 | if (!rd) |
| 674 | 784 | goto out; |
| 675 | 785 | } |
| @@ -732,7 +842,7 @@ out: · 56 unmodified lines |
| 732 | 842 | * Return true if packet is bogus and should be droppped. |
| 733 | 843 | */ |
| 734 | 844 | static 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 | 847 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 738 | 848 | struct vxlan_fdb *f; |
| @@ -741,7 +851,7 @@ static bool vxlan_snoop(struct net_device *dev, · 2 unmodified lines |
| 741 | 851 | if (likely(f)) { |
| 742 | 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 | 855 | return false; |
| 746 | 856 | |
| 747 | 857 | /* Don't migrate static entries, drop packets */ |
| @@ -750,10 +860,10 @@ static bool vxlan_snoop(struct net_device *dev, · 2 unmodified lines |
| 750 | 860 | |
| 751 | 861 | if (net_ratelimit()) |
| 752 | 862 | netdev_info(dev, |
| 753 | | − "%pM migrated from %pI4 to %pI4\n", |
| 863 | + "%pM migrated from %pIS to %pIS\n", |
| 754 | 864 | src_mac, &rdst->remote_ip, &src_ip); |
| 755 | 865 | |
| 756 | | − rdst->remote_ip = src_ip; |
| 866 | + rdst->remote_ip = *src_ip; |
| 757 | 867 | f->updated = jiffies; |
| 758 | 868 | vxlan_fdb_notify(vxlan, f, RTM_NEWNEIGH); |
| 759 | 869 | } else { |
| @@ -775,7 +885,7 @@ static bool vxlan_snoop(struct net_device *dev, · 15 unmodified lines |
| 775 | 885 | } |
| 776 | 886 | |
| 777 | 887 | /* See if multicast group is already in use by other ID */ |
| 778 | | −static bool vxlan_group_used(struct vxlan_net *vn, __be32 remote_ip) |
| 888 | +static bool vxlan_group_used(struct vxlan_net *vn, union vxlan_addr *remote_ip) |
| 779 | 889 | { |
| 780 | 890 | struct vxlan_dev *vxlan; |
| 781 | 891 | |
| @@ -783,7 +893,8 @@ static bool vxlan_group_used(struct vxlan_net *vn, __be32 remote_ip) · 1 unmodified line |
| 783 | 893 | if (!netif_running(vxlan->dev)) |
| 784 | 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 | 898 | return true; |
| 788 | 899 | } |
| 789 | 900 | |
| @@ -819,13 +930,23 @@ static void vxlan_igmp_join(struct work_struct *work) · 29 unmodified lines |
| 819 | 930 | struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_join); |
| 820 | 931 | struct vxlan_sock *vs = vxlan->vn_sock; |
| 821 | 932 | struct sock *sk = vs->sock->sk; |
| 822 | | − struct ip_mreqn mreq = { |
| 823 | | − .imr_multiaddr.s_addr = vxlan->default_dst.remote_ip, |
| 824 | | − .imr_ifindex = vxlan->default_dst.remote_ifindex, |
| 825 | | − }; |
| 933 | + union vxlan_addr *ip = &vxlan->default_dst.remote_ip; |
| 934 | + int ifindex = vxlan->default_dst.remote_ifindex; |
| 826 | 935 | |
| 827 | 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 | 950 | release_sock(sk); |
| 830 | 951 | |
| 831 | 952 | vxlan_sock_release(vs); |
| @@ -838,13 +959,24 @@ static void vxlan_igmp_leave(struct work_struct *work) · 6 unmodified lines |
| 838 | 959 | struct vxlan_dev *vxlan = container_of(work, struct vxlan_dev, igmp_leave); |
| 839 | 960 | struct vxlan_sock *vs = vxlan->vn_sock; |
| 840 | 961 | struct sock *sk = vs->sock->sk; |
| 841 | | − struct ip_mreqn mreq = { |
| 842 | | − .imr_multiaddr.s_addr = vxlan->default_dst.remote_ip, |
| 843 | | − .imr_ifindex = vxlan->default_dst.remote_ifindex, |
| 844 | | − }; |
| 962 | + union vxlan_addr *ip = &vxlan->default_dst.remote_ip; |
| 963 | + int ifindex = vxlan->default_dst.remote_ifindex; |
| 845 | 964 | |
| 846 | 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 | 980 | release_sock(sk); |
| 849 | 981 | |
| 850 | 982 | vxlan_sock_release(vs); |
| @@ -896,11 +1028,14 @@ error: · 45 unmodified lines |
| 896 | 1028 | static void vxlan_rcv(struct vxlan_sock *vs, |
| 897 | 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 | 1033 | struct vxlan_dev *vxlan; |
| 901 | 1034 | struct pcpu_tstats *stats; |
| 1035 | + union vxlan_addr saddr; |
| 902 | 1036 | __u32 vni; |
| 903 | | − int err; |
| 1037 | + int err = 0; |
| 1038 | + union vxlan_addr *remote_ip; |
| 904 | 1039 | |
| 905 | 1040 | vni = ntohl(vx_vni) >> 8; |
| 906 | 1041 | /* Is this VNI defined? */ |
| @@ -908,6 +1043,7 @@ static void vxlan_rcv(struct vxlan_sock *vs, · 1 unmodified line |
| 908 | 1043 | if (!vxlan) |
| 909 | 1044 | goto drop; |
| 910 | 1045 | |
| 1046 | + remote_ip = &vxlan->default_dst.remote_ip; |
| 911 | 1047 | skb_reset_mac_header(skb); |
| 912 | 1048 | skb->protocol = eth_type_trans(skb, vxlan->dev); |
| 913 | 1049 | |
| @@ -917,9 +1053,20 @@ static void vxlan_rcv(struct vxlan_sock *vs, · 3 unmodified lines |
| 917 | 1053 | goto drop; |
| 918 | 1054 | |
| 919 | 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 | 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 | 1070 | goto drop; |
| 924 | 1071 | |
| 925 | 1072 | skb_reset_network_header(skb); |
| @@ -935,11 +1082,20 @@ static void vxlan_rcv(struct vxlan_sock *vs, · 9 unmodified lines |
| 935 | 1082 | |
| 936 | 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 | 1090 | if (unlikely(err)) { |
| 940 | | − if (log_ecn_error) |
| 941 | | − net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", |
| 942 | | − &oip->saddr, oip->tos); |
| 1091 | + if (log_ecn_error) { |
| 1092 | + if (oip6) |
| 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 | 1099 | if (err > 1) { |
| 944 | 1100 | ++vxlan->dev->stats.rx_frame_errors; |
| 945 | 1101 | ++vxlan->dev->stats.rx_errors; |
| @@ -1009,7 +1165,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb) · 63 unmodified lines |
| 1009 | 1165 | } |
| 1010 | 1166 | |
| 1011 | 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 | 1169 | /* bridge-local neighbor */ |
| 1014 | 1170 | neigh_release(n); |
| 1015 | 1171 | goto out; |
| @@ -1027,8 +1183,14 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb) · 11 unmodified lines |
| 1027 | 1183 | |
| 1028 | 1184 | if (netif_rx_ni(reply) == NET_RX_DROP) |
| 1029 | 1185 | dev->stats.rx_dropped++; |
| 1030 | | − } else if (vxlan->flags & VXLAN_F_L3MISS) |
| 1031 | | − vxlan_ip_miss(dev, tip); |
| 1186 | + } else if (vxlan->flags & VXLAN_F_L3MISS) { |
| 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 | + } |
| 1032 | 1194 | out: |
| 1033 | 1195 | consume_skb(skb); |
| 1034 | 1196 | return NETDEV_TX_OK; |
| @@ -1050,6 +1212,16 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · 15 unmodified lines |
| 1050 | 1212 | return false; |
| 1051 | 1213 | pip = ip_hdr(skb); |
| 1052 | 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 | 1225 | break; |
| 1054 | 1226 | default: |
| 1055 | 1227 | return false; |
| @@ -1066,8 +1238,8 @@ static bool route_shortcircuit(struct net_device *dev, struct sk_buff *skb) · 10 unmodified lines |
| 1066 | 1238 | } |
| 1067 | 1239 | neigh_release(n); |
| 1068 | 1240 | return diff; |
| 1069 | | − } else if (vxlan->flags & VXLAN_F_L3MISS) |
| 1070 | | − vxlan_ip_miss(dev, pip->daddr); |
| 1241 | + } |
| 1242 | + |
| 1071 | 1243 | return false; |
| 1072 | 1244 | } |
| 1073 | 1245 | |
| @@ -1118,6 +1290,102 @@ static int handle_offloads(struct sk_buff *skb) · 44 unmodified lines |
| 1118 | 1290 | return 0; |
| 1119 | 1291 | } |
| 1120 | 1292 | |
| 1293 | +#if IS_ENABLED(CONFIG_IPV6) |
| 1294 | +static 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 | + |
| 1121 | 1389 | int vxlan_xmit_skb(struct net *net, struct vxlan_sock *vs, |
| 1122 | 1390 | struct rtable *rt, struct sk_buff *skb, |
| 1123 | 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, · 58 unmodified lines |
| 1182 | 1450 | { |
| 1183 | 1451 | struct pcpu_tstats *tx_stats = this_cpu_ptr(src_vxlan->dev->tstats); |
| 1184 | 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 | 1456 | skb->pkt_type = PACKET_HOST; |
| 1187 | 1457 | skb->encapsulation = 0; |
| 1188 | 1458 | skb->dev = dst_vxlan->dev; |
| 1189 | 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 | 1471 | if (dst_vxlan->flags & VXLAN_F_LEARN) |
| 1192 | | − vxlan_snoop(skb->dev, htonl(INADDR_LOOPBACK), |
| 1193 | | − eth_hdr(skb)->h_source); |
| 1472 | + vxlan_snoop(skb->dev, &loopback, eth_hdr(skb)->h_source); |
| 1194 | 1473 | |
| 1195 | 1474 | u64_stats_update_begin(&tx_stats->syncp); |
| 1196 | 1475 | tx_stats->tx_packets++; |
| @@ -1211,11 +1490,11 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 14 unmodified lines |
| 1211 | 1490 | struct vxlan_rdst *rdst, bool did_rsc) |
| 1212 | 1491 | { |
| 1213 | 1492 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1214 | | − struct rtable *rt; |
| 1493 | + struct rtable *rt = NULL; |
| 1215 | 1494 | const struct iphdr *old_iph; |
| 1216 | 1495 | struct flowi4 fl4; |
| 1217 | | − __be32 dst; |
| 1218 | | − __be16 src_port, dst_port; |
| 1496 | + union vxlan_addr *dst; |
| 1497 | + __be16 src_port = 0, dst_port; |
| 1219 | 1498 | u32 vni; |
| 1220 | 1499 | __be16 df = 0; |
| 1221 | 1500 | __u8 tos, ttl; |
| @@ -1223,9 +1502,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 1 unmodified line |
| 1223 | 1502 | |
| 1224 | 1503 | dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port; |
| 1225 | 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 | 1508 | if (did_rsc) { |
| 1230 | 1509 | /* short-circuited back to local bridge */ |
| 1231 | 1510 | vxlan_encap_bypass(skb, vxlan, vxlan); |
| @@ -1237,7 +1516,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 5 unmodified lines |
| 1237 | 1516 | old_iph = ip_hdr(skb); |
| 1238 | 1517 | |
| 1239 | 1518 | ttl = vxlan->ttl; |
| 1240 | | − if (!ttl && IN_MULTICAST(ntohl(dst))) |
| 1519 | + if (!ttl && vxlan_addr_multicast(dst)) |
| 1241 | 1520 | ttl = 1; |
| 1242 | 1521 | |
| 1243 | 1522 | tos = vxlan->tos; |
| @@ -1246,48 +1525,101 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 2 unmodified lines |
| 1246 | 1525 | |
| 1247 | 1526 | src_port = vxlan_src_port(vxlan->port_min, vxlan->port_max, skb); |
| 1248 | 1527 | |
| 1249 | | − memset(&fl4, 0, sizeof(fl4)); |
| 1250 | | − fl4.flowi4_oif = rdst->remote_ifindex; |
| 1251 | | − fl4.flowi4_tos = RT_TOS(tos); |
| 1252 | | − fl4.daddr = dst; |
| 1253 | | − fl4.saddr = vxlan->saddr; |
| 1254 | | − |
| 1255 | | − rt = ip_route_output_key(dev_net(dev), &fl4); |
| 1256 | | − if (IS_ERR(rt)) { |
| 1257 | | − netdev_dbg(dev, "no route to %pI4\n", &dst); |
| 1258 | | − dev->stats.tx_carrier_errors++; |
| 1259 | | − goto tx_error; |
| 1260 | | − } |
| 1528 | + if (dst->sa.sa_family == AF_INET) { |
| 1529 | + memset(&fl4, 0, sizeof(fl4)); |
| 1530 | + fl4.flowi4_oif = rdst->remote_ifindex; |
| 1531 | + fl4.flowi4_tos = RT_TOS(tos); |
| 1532 | + fl4.daddr = dst->sin.sin_addr.s_addr; |
| 1533 | + fl4.saddr = vxlan->saddr.sin.sin_addr.s_addr; |
| 1534 | + |
| 1535 | + rt = ip_route_output_key(dev_net(dev), &fl4); |
| 1536 | + if (IS_ERR(rt)) { |
| 1537 | + netdev_dbg(dev, "no route to %pI4\n", |
| 1538 | + &dst->sin.sin_addr.s_addr); |
| 1539 | + dev->stats.tx_carrier_errors++; |
| 1540 | + goto tx_error; |
| 1541 | + } |
| 1261 | 1542 | |
| 1262 | | − if (rt->dst.dev == dev) { |
| 1263 | | − netdev_dbg(dev, "circular route to %pI4\n", &dst); |
| 1264 | | − dev->stats.collisions++; |
| 1265 | | − goto rt_tx_error; |
| 1266 | | − } |
| 1543 | + if (rt->dst.dev == dev) { |
| 1544 | + netdev_dbg(dev, "circular route to %pI4\n", |
| 1545 | + &dst->sin.sin_addr.s_addr); |
| 1546 | + dev->stats.collisions++; |
| 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 */ |
| 1269 | | − if (rt->rt_flags & RTCF_LOCAL && |
| 1270 | | − !(rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))) { |
| 1271 | | − struct vxlan_dev *dst_vxlan; |
| 1563 | + tos = ip_tunnel_ecn_encap(tos, old_iph, skb); |
| 1564 | + ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); |
| 1272 | 1565 | |
| 1273 | | − ip_rt_put(rt); |
| 1274 | | − dst_vxlan = vxlan_find_vni(dev_net(dev), vni, dst_port); |
| 1275 | | − if (!dst_vxlan) |
| 1566 | + err = vxlan_xmit_skb(dev_net(dev), vxlan->vn_sock, rt, skb, |
| 1567 | + fl4.saddr, dst->sin.sin_addr.s_addr, |
| 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 | 1591 | goto tx_error; |
| 1277 | | − vxlan_encap_bypass(skb, vxlan, dst_vxlan); |
| 1278 | | − return; |
| 1279 | | − } |
| 1592 | + } |
| 1280 | 1593 | |
| 1281 | | − tos = ip_tunnel_ecn_encap(tos, old_iph, skb); |
| 1282 | | − ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); |
| 1594 | + if (ndst->dev == dev) { |
| 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, |
| 1285 | | − fl4.saddr, dst, tos, ttl, df, |
| 1286 | | − src_port, dst_port, htonl(vni << 8)); |
| 1602 | + /* Bypass encapsulation if the destination is local */ |
| 1603 | + flags = ((struct rt6_info *)ndst)->rt6i_flags; |
| 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) |
| 1289 | | − goto rt_tx_error; |
| 1290 | | − iptunnel_xmit_stats(err, &dev->stats, dev->tstats); |
| 1616 | + ttl = ttl ? : ip6_dst_hoplimit(ndst); |
| 1617 | + |
| 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 | 1624 | return; |
| 1293 | 1625 | |
| @@ -1464,8 +1796,8 @@ static int vxlan_open(struct net_device *dev) · 170 unmodified lines |
| 1464 | 1796 | if (!vs) |
| 1465 | 1797 | return -ENOTCONN; |
| 1466 | 1798 | |
| 1467 | | − if (IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip)) && |
| 1468 | | − vxlan_group_used(vn, vxlan->default_dst.remote_ip)) { |
| 1799 | + if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip) && |
| 1800 | + vxlan_group_used(vn, &vxlan->default_dst.remote_ip)) { |
| 1469 | 1801 | vxlan_sock_hold(vs); |
| 1470 | 1802 | dev_hold(dev); |
| 1471 | 1803 | queue_work(vxlan_wq, &vxlan->igmp_join); |
| @@ -1503,8 +1835,8 @@ static int vxlan_stop(struct net_device *dev) · 31 unmodified lines |
| 1503 | 1835 | struct vxlan_dev *vxlan = netdev_priv(dev); |
| 1504 | 1836 | struct vxlan_sock *vs = vxlan->vn_sock; |
| 1505 | 1837 | |
| 1506 | | − if (vs && IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip)) && |
| 1507 | | − ! vxlan_group_used(vn, vxlan->default_dst.remote_ip)) { |
| 1838 | + if (vs && vxlan_addr_multicast(&vxlan->default_dst.remote_ip) && |
| 1839 | + ! vxlan_group_used(vn, &vxlan->default_dst.remote_ip)) { |
| 1508 | 1840 | vxlan_sock_hold(vs); |
| 1509 | 1841 | dev_hold(dev); |
| 1510 | 1842 | queue_work(vxlan_wq, &vxlan->igmp_leave); |
| @@ -1552,7 +1884,10 @@ static void vxlan_setup(struct net_device *dev) · 41 unmodified lines |
| 1552 | 1884 | |
| 1553 | 1885 | eth_hw_addr_random(dev); |
| 1554 | 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 | 1892 | dev->netdev_ops = &vxlan_netdev_ops; |
| 1558 | 1893 | dev->destructor = free_netdev; |
| @@ -1597,8 +1932,10 @@ static void vxlan_setup(struct net_device *dev) · 38 unmodified lines |
| 1597 | 1932 | static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = { |
| 1598 | 1933 | [IFLA_VXLAN_ID] = { .type = NLA_U32 }, |
| 1599 | 1934 | [IFLA_VXLAN_GROUP] = { .len = FIELD_SIZEOF(struct iphdr, daddr) }, |
| 1935 | + [IFLA_VXLAN_GROUP6] = { .len = sizeof(struct in6_addr) }, |
| 1600 | 1936 | [IFLA_VXLAN_LINK] = { .type = NLA_U32 }, |
| 1601 | 1937 | [IFLA_VXLAN_LOCAL] = { .len = FIELD_SIZEOF(struct iphdr, saddr) }, |
| 1938 | + [IFLA_VXLAN_LOCAL6] = { .len = sizeof(struct in6_addr) }, |
| 1602 | 1939 | [IFLA_VXLAN_TOS] = { .type = NLA_U8 }, |
| 1603 | 1940 | [IFLA_VXLAN_TTL] = { .type = NLA_U8 }, |
| 1604 | 1941 | [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 }, |
| @@ -1669,58 +2006,132 @@ static void vxlan_del_work(struct work_struct *work) · 64 unmodified lines |
| 1669 | 2006 | kfree_rcu(vs, rcu); |
| 1670 | 2007 | } |
| 1671 | 2008 | |
| 1672 | | −static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port, |
| 1673 | | − vxlan_rcv_t *rcv, void *data) |
| 2009 | +#if IS_ENABLED(CONFIG_IPV6) |
| 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 | + */ |
| 2014 | +static 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 | + |
| 2057 | +static int create_v6_sock(struct net *net, __be16 port, struct socket **psock) |
| 2058 | +{ |
| 2059 | + return -EPFNOSUPPORT; |
| 2060 | +} |
| 2061 | +#endif |
| 2062 | + |
| 2063 | +static 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 | 2065 | struct sock *sk; |
| 2066 | + struct socket *sock; |
| 1678 | 2067 | struct sockaddr_in vxlan_addr = { |
| 1679 | 2068 | .sin_family = AF_INET, |
| 1680 | 2069 | .sin_addr.s_addr = htonl(INADDR_ANY), |
| 1681 | 2070 | .sin_port = port, |
| 1682 | 2071 | }; |
| 1683 | 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 | 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 | 2076 | if (rc < 0) { |
| 1700 | 2077 | pr_debug("UDP socket create failed\n"); |
| 1701 | | − kfree(vs); |
| 1702 | | − return ERR_PTR(rc); |
| 2078 | + return rc; |
| 1703 | 2079 | } |
| 1704 | 2080 | |
| 1705 | 2081 | /* Put in proper namespace */ |
| 1706 | | − sk = vs->sock->sk; |
| 2082 | + sk = sock->sk; |
| 1707 | 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 | 2086 | sizeof(vxlan_addr)); |
| 1711 | 2087 | if (rc < 0) { |
| 1712 | 2088 | pr_debug("bind for UDP socket %pI4:%u (%d)\n", |
| 1713 | 2089 | &vxlan_addr.sin_addr, ntohs(vxlan_addr.sin_port), rc); |
| 1714 | 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 */ |
| 2101 | +static 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 | 2125 | kfree(vs); |
| 1716 | 2126 | return ERR_PTR(rc); |
| 1717 | 2127 | } |
| 2128 | + |
| 2129 | + vs->sock = sock; |
| 2130 | + sk = sock->sk; |
| 1718 | 2131 | atomic_set(&vs->refcnt, 1); |
| 1719 | 2132 | vs->rcv = rcv; |
| 1720 | 2133 | vs->data = data; |
| 1721 | 2134 | |
| 1722 | | − /* Disable multicast loopback */ |
| 1723 | | − inet_sk(sk)->mc_loop = 0; |
| 1724 | 2135 | spin_lock(&vn->sock_lock); |
| 1725 | 2136 | hlist_add_head_rcu(&vs->hlist, vs_head(net, port)); |
| 1726 | 2137 | spin_unlock(&vn->sock_lock); |
| @@ -1728,18 +2139,24 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port, · 1 unmodified line |
| 1728 | 2139 | /* Mark socket as an encapsulation socket. */ |
| 1729 | 2140 | udp_sk(sk)->encap_type = 1; |
| 1730 | 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 | 2149 | return vs; |
| 1733 | 2150 | } |
| 1734 | 2151 | |
| 1735 | 2152 | struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, |
| 1736 | 2153 | vxlan_rcv_t *rcv, void *data, |
| 1737 | | − bool no_share) |
| 2154 | + bool no_share, bool ipv6) |
| 1738 | 2155 | { |
| 1739 | 2156 | struct vxlan_net *vn = net_generic(net, vxlan_net_id); |
| 1740 | 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 | 2160 | if (!IS_ERR(vs)) |
| 1744 | 2161 | return vs; |
| 1745 | 2162 | |
| @@ -1772,7 +2189,7 @@ static void vxlan_sock_work(struct work_struct *work) · 26 unmodified lines |
| 1772 | 2189 | __be16 port = vxlan->dst_port; |
| 1773 | 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 | 2193 | spin_lock(&vn->sock_lock); |
| 1777 | 2194 | if (!IS_ERR(nvs)) |
| 1778 | 2195 | vxlan_vs_add_dev(nvs, vxlan); |
| @@ -1789,6 +2206,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev, · 10 unmodified lines |
| 1789 | 2206 | struct vxlan_rdst *dst = &vxlan->default_dst; |
| 1790 | 2207 | __u32 vni; |
| 1791 | 2208 | int err; |
| 2209 | + bool use_ipv6 = false; |
| 1792 | 2210 | |
| 1793 | 2211 | if (!data[IFLA_VXLAN_ID]) |
| 1794 | 2212 | return -EINVAL; |
| @@ -1796,11 +2214,32 @@ static int vxlan_newlink(struct net *net, struct net_device *dev, · 1 unmodified line |
| 1796 | 2214 | vni = nla_get_u32(data[IFLA_VXLAN_ID]); |
| 1797 | 2215 | dst->remote_vni = vni; |
| 1798 | 2216 | |
| 1799 | | − if (data[IFLA_VXLAN_GROUP]) |
| 1800 | | − dst->remote_ip = nla_get_be32(data[IFLA_VXLAN_GROUP]); |
| 2217 | + if (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]) |
| 1803 | | − vxlan->saddr = nla_get_be32(data[IFLA_VXLAN_LOCAL]); |
| 2230 | + if (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 | 2244 | if (data[IFLA_VXLAN_LINK] && |
| 1806 | 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, · 5 unmodified lines |
| 1812 | 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 | 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 | 2268 | /* update header length based on lower device */ |
| 1819 | 2269 | dev->hard_header_len = lowerdev->hard_header_len + |
| 1820 | | − VXLAN_HEADROOM; |
| 2270 | + (use_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM); |
| 1821 | 2271 | } |
| 1822 | 2272 | |
| 1823 | 2273 | if (data[IFLA_VXLAN_TOS]) |
| @@ -1868,7 +2318,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev, · 44 unmodified lines |
| 1868 | 2318 | |
| 1869 | 2319 | /* create an fdb entry for default destination */ |
| 1870 | 2320 | err = vxlan_fdb_create(vxlan, all_zeros_mac, |
| 1871 | | − vxlan->default_dst.remote_ip, |
| 2321 | + &vxlan->default_dst.remote_ip, |
| 1872 | 2322 | NUD_REACHABLE|NUD_PERMANENT, |
| 1873 | 2323 | NLM_F_EXCL|NLM_F_CREATE, |
| 1874 | 2324 | vxlan->dst_port, vxlan->default_dst.remote_vni, |
| @@ -1905,9 +2355,9 @@ static size_t vxlan_get_size(const struct net_device *dev) · 30 unmodified lines |
| 1905 | 2355 | { |
| 1906 | 2356 | |
| 1907 | 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 | 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 | 2361 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TTL */ |
| 1912 | 2362 | nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TOS */ |
| 1913 | 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) · 20 unmodified lines |
| 1934 | 2384 | if (nla_put_u32(skb, IFLA_VXLAN_ID, dst->remote_vni)) |
| 1935 | 2385 | goto nla_put_failure; |
| 1936 | 2386 | |
| 1937 | | − if (dst->remote_ip && nla_put_be32(skb, IFLA_VXLAN_GROUP, dst->remote_ip)) |
| 1938 | | − goto nla_put_failure; |
| 2387 | + if (!vxlan_addr_any(&dst->remote_ip)) { |
| 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 | 2401 | if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) |
| 1941 | 2402 | goto nla_put_failure; |
| 1942 | 2403 | |
| 1943 | | − if (vxlan->saddr && nla_put_be32(skb, IFLA_VXLAN_LOCAL, vxlan->saddr)) |
| 1944 | | − goto nla_put_failure; |
| 2404 | + if (!vxlan_addr_any(&vxlan->saddr)) { |
| 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 | 2418 | if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->ttl) || |
| 1947 | 2419 | nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->tos) || |