2 * VXLAN: Virtual eXtensible Local Area Network
4 * Copyright (c) 2012-2013 Vyatta Inc.
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
8 * published by the Free Software Foundation.
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/errno.h>
16 #include <linux/slab.h>
17 #include <linux/udp.h>
18 #include <linux/igmp.h>
19 #include <linux/inetdevice.h>
20 #include <linux/if_ether.h>
21 #include <linux/ethtool.h>
23 #include <net/ndisc.h>
26 #include <net/rtnetlink.h>
27 #include <net/inet_ecn.h>
28 #include <net/net_namespace.h>
29 #include <net/netns/generic.h>
30 #include <net/tun_proto.h>
31 #include <net/vxlan.h>
33 #if IS_ENABLED(CONFIG_IPV6)
34 #include <net/ip6_tunnel.h>
35 #include <net/ip6_checksum.h>
38 #define VXLAN_VERSION "0.1"
40 #define PORT_HASH_BITS 8
41 #define PORT_HASH_SIZE (1<<PORT_HASH_BITS)
42 #define FDB_AGE_DEFAULT 300 /* 5 min */
43 #define FDB_AGE_INTERVAL (10 * HZ) /* rescan interval */
45 /* UDP port for VXLAN traffic.
46 * The IANA assigned port is 4789, but the Linux default is 8472
47 * for compatibility with early adopters.
49 static unsigned short vxlan_port __read_mostly
= 8472;
50 module_param_named(udp_port
, vxlan_port
, ushort
, 0444);
51 MODULE_PARM_DESC(udp_port
, "Destination UDP port");
53 static bool log_ecn_error
= true;
54 module_param(log_ecn_error
, bool, 0644);
55 MODULE_PARM_DESC(log_ecn_error
, "Log packets received with corrupted ECN");
57 static unsigned int vxlan_net_id
;
58 static struct rtnl_link_ops vxlan_link_ops
;
60 static const u8 all_zeros_mac
[ETH_ALEN
+ 2];
62 static int vxlan_sock_add(struct vxlan_dev
*vxlan
);
64 static void vxlan_vs_del_dev(struct vxlan_dev
*vxlan
);
66 /* per-network namespace private data for this module */
68 struct list_head vxlan_list
;
69 struct hlist_head sock_list
[PORT_HASH_SIZE
];
73 /* Forwarding table entry */
75 struct hlist_node hlist
; /* linked list of entries */
77 unsigned long updated
; /* jiffies */
79 struct list_head remotes
;
80 u8 eth_addr
[ETH_ALEN
];
81 u16 state
; /* see ndm_state */
83 u8 flags
; /* see ndm_flags */
86 /* salt for hash table */
87 static u32 vxlan_salt __read_mostly
;
89 static inline bool vxlan_collect_metadata(struct vxlan_sock
*vs
)
91 return vs
->flags
& VXLAN_F_COLLECT_METADATA
||
92 ip_tunnel_collect_metadata();
95 static struct ip_fan_map
*vxlan_fan_find_map(struct vxlan_dev
*vxlan
, __be32 daddr
)
97 struct ip_fan_map
*fan_map
;
100 list_for_each_entry_rcu(fan_map
, &vxlan
->fan
.fan_maps
, list
) {
101 if (fan_map
->overlay
==
102 (daddr
& inet_make_mask(fan_map
->overlay_prefix
))) {
112 static void vxlan_fan_flush_map(struct vxlan_dev
*vxlan
)
114 struct ip_fan_map
*fan_map
;
116 list_for_each_entry_rcu(fan_map
, &vxlan
->fan
.fan_maps
, list
) {
117 list_del_rcu(&fan_map
->list
);
118 kfree_rcu(fan_map
, rcu
);
122 static int vxlan_fan_del_map(struct vxlan_dev
*vxlan
, __be32 overlay
)
124 struct ip_fan_map
*fan_map
;
126 fan_map
= vxlan_fan_find_map(vxlan
, overlay
);
130 list_del_rcu(&fan_map
->list
);
131 kfree_rcu(fan_map
, rcu
);
136 static int vxlan_fan_add_map(struct vxlan_dev
*vxlan
, struct ifla_fan_map
*map
)
138 __be32 overlay_mask
, underlay_mask
;
139 struct ip_fan_map
*fan_map
;
141 overlay_mask
= inet_make_mask(map
->overlay_prefix
);
142 underlay_mask
= inet_make_mask(map
->underlay_prefix
);
144 netdev_dbg(vxlan
->dev
, "vfam: map: o %x/%d u %x/%d om %x um %x\n",
145 map
->overlay
, map
->overlay_prefix
,
146 map
->underlay
, map
->underlay_prefix
,
147 overlay_mask
, underlay_mask
);
149 if ((map
->overlay
& ~overlay_mask
) || (map
->underlay
& ~underlay_mask
))
152 if (!(map
->overlay
& overlay_mask
) && (map
->underlay
& underlay_mask
))
155 /* Special case: overlay 0 and underlay 0: flush all mappings */
156 if (!map
->overlay
&& !map
->underlay
) {
157 vxlan_fan_flush_map(vxlan
);
161 /* Special case: overlay set and underlay 0: clear map for overlay */
163 return vxlan_fan_del_map(vxlan
, map
->overlay
);
165 if (vxlan_fan_find_map(vxlan
, map
->overlay
))
168 fan_map
= kmalloc(sizeof(*fan_map
), GFP_KERNEL
);
169 fan_map
->underlay
= map
->underlay
;
170 fan_map
->overlay
= map
->overlay
;
171 fan_map
->underlay_prefix
= map
->underlay_prefix
;
172 fan_map
->overlay_mask
= ntohl(overlay_mask
);
173 fan_map
->overlay_prefix
= map
->overlay_prefix
;
175 list_add_tail_rcu(&fan_map
->list
, &vxlan
->fan
.fan_maps
);
180 static int vxlan_parse_fan_map(struct nlattr
*data
[], struct vxlan_dev
*vxlan
)
182 struct ifla_fan_map
*map
;
186 nla_for_each_nested(attr
, data
[IFLA_IPTUN_FAN_MAP
], rem
) {
187 map
= nla_data(attr
);
188 rv
= vxlan_fan_add_map(vxlan
, map
);
196 static int vxlan_fan_build_rdst(struct vxlan_dev
*vxlan
, struct sk_buff
*skb
,
197 struct vxlan_rdst
*fan_rdst
)
199 struct ip_fan_map
*f_map
;
200 union vxlan_addr
*va
;
208 switch (eth
->h_proto
) {
209 case htons(ETH_P_IP
):
215 case htons(ETH_P_ARP
):
220 netdev_dbg(vxlan
->dev
,
221 "vfbr: arp sha %pM sip %pI4 tha %pM tip %pI4\n",
222 arp_ptr
, arp_ptr
+ skb
->dev
->addr_len
,
223 arp_ptr
+ skb
->dev
->addr_len
+ 4,
224 arp_ptr
+ (skb
->dev
->addr_len
* 2) + 4);
225 arp_ptr
+= (skb
->dev
->addr_len
* 2) + 4;
226 memcpy(&daddr
, arp_ptr
, 4);
229 netdev_dbg(vxlan
->dev
, "vfbr: unknown eth p %x\n", eth
->h_proto
);
233 f_map
= vxlan_fan_find_map(vxlan
, daddr
);
237 daddr
= ntohl(daddr
);
238 underlay
= ntohl(f_map
->underlay
);
242 memset(fan_rdst
, 0, sizeof(*fan_rdst
));
243 va
= &fan_rdst
->remote_ip
;
244 va
->sa
.sa_family
= AF_INET
;
245 fan_rdst
->remote_vni
= vxlan
->default_dst
.remote_vni
;
246 va
->sin
.sin_addr
.s_addr
= htonl(underlay
|
247 ((daddr
& ~f_map
->overlay_mask
) >>
248 (32 - f_map
->overlay_prefix
-
249 (32 - f_map
->underlay_prefix
))));
250 netdev_dbg(vxlan
->dev
, "vfbr: daddr %x ul %x dst %x\n",
251 daddr
, underlay
, va
->sin
.sin_addr
.s_addr
);
256 #if IS_ENABLED(CONFIG_IPV6)
258 bool vxlan_addr_equal(const union vxlan_addr
*a
, const union vxlan_addr
*b
)
260 if (a
->sa
.sa_family
!= b
->sa
.sa_family
)
262 if (a
->sa
.sa_family
== AF_INET6
)
263 return ipv6_addr_equal(&a
->sin6
.sin6_addr
, &b
->sin6
.sin6_addr
);
265 return a
->sin
.sin_addr
.s_addr
== b
->sin
.sin_addr
.s_addr
;
268 static inline bool vxlan_addr_any(const union vxlan_addr
*ipa
)
270 if (ipa
->sa
.sa_family
== AF_INET6
)
271 return ipv6_addr_any(&ipa
->sin6
.sin6_addr
);
273 return ipa
->sin
.sin_addr
.s_addr
== htonl(INADDR_ANY
);
276 static inline bool vxlan_addr_multicast(const union vxlan_addr
*ipa
)
278 if (ipa
->sa
.sa_family
== AF_INET6
)
279 return ipv6_addr_is_multicast(&ipa
->sin6
.sin6_addr
);
281 return IN_MULTICAST(ntohl(ipa
->sin
.sin_addr
.s_addr
));
284 static int vxlan_nla_get_addr(union vxlan_addr
*ip
, struct nlattr
*nla
)
286 if (nla_len(nla
) >= sizeof(struct in6_addr
)) {
287 ip
->sin6
.sin6_addr
= nla_get_in6_addr(nla
);
288 ip
->sa
.sa_family
= AF_INET6
;
290 } else if (nla_len(nla
) >= sizeof(__be32
)) {
291 ip
->sin
.sin_addr
.s_addr
= nla_get_in_addr(nla
);
292 ip
->sa
.sa_family
= AF_INET
;
295 return -EAFNOSUPPORT
;
299 static int vxlan_nla_put_addr(struct sk_buff
*skb
, int attr
,
300 const union vxlan_addr
*ip
)
302 if (ip
->sa
.sa_family
== AF_INET6
)
303 return nla_put_in6_addr(skb
, attr
, &ip
->sin6
.sin6_addr
);
305 return nla_put_in_addr(skb
, attr
, ip
->sin
.sin_addr
.s_addr
);
308 #else /* !CONFIG_IPV6 */
311 bool vxlan_addr_equal(const union vxlan_addr
*a
, const union vxlan_addr
*b
)
313 return a
->sin
.sin_addr
.s_addr
== b
->sin
.sin_addr
.s_addr
;
316 static inline bool vxlan_addr_any(const union vxlan_addr
*ipa
)
318 return ipa
->sin
.sin_addr
.s_addr
== htonl(INADDR_ANY
);
321 static inline bool vxlan_addr_multicast(const union vxlan_addr
*ipa
)
323 return IN_MULTICAST(ntohl(ipa
->sin
.sin_addr
.s_addr
));
326 static int vxlan_nla_get_addr(union vxlan_addr
*ip
, struct nlattr
*nla
)
328 if (nla_len(nla
) >= sizeof(struct in6_addr
)) {
329 return -EAFNOSUPPORT
;
330 } else if (nla_len(nla
) >= sizeof(__be32
)) {
331 ip
->sin
.sin_addr
.s_addr
= nla_get_in_addr(nla
);
332 ip
->sa
.sa_family
= AF_INET
;
335 return -EAFNOSUPPORT
;
339 static int vxlan_nla_put_addr(struct sk_buff
*skb
, int attr
,
340 const union vxlan_addr
*ip
)
342 return nla_put_in_addr(skb
, attr
, ip
->sin
.sin_addr
.s_addr
);
346 /* Virtual Network hash table head */
347 static inline struct hlist_head
*vni_head(struct vxlan_sock
*vs
, __be32 vni
)
349 return &vs
->vni_list
[hash_32((__force u32
)vni
, VNI_HASH_BITS
)];
352 /* Socket hash table head */
353 static inline struct hlist_head
*vs_head(struct net
*net
, __be16 port
)
355 struct vxlan_net
*vn
= net_generic(net
, vxlan_net_id
);
357 return &vn
->sock_list
[hash_32(ntohs(port
), PORT_HASH_BITS
)];
360 /* First remote destination for a forwarding entry.
361 * Guaranteed to be non-NULL because remotes are never deleted.
363 static inline struct vxlan_rdst
*first_remote_rcu(struct vxlan_fdb
*fdb
)
365 return list_entry_rcu(fdb
->remotes
.next
, struct vxlan_rdst
, list
);
368 static inline struct vxlan_rdst
*first_remote_rtnl(struct vxlan_fdb
*fdb
)
370 return list_first_entry(&fdb
->remotes
, struct vxlan_rdst
, list
);
373 /* Find VXLAN socket based on network namespace, address family and UDP port
374 * and enabled unshareable flags.
376 static struct vxlan_sock
*vxlan_find_sock(struct net
*net
, sa_family_t family
,
377 __be16 port
, u32 flags
)
379 struct vxlan_sock
*vs
;
381 flags
&= VXLAN_F_RCV_FLAGS
;
383 hlist_for_each_entry_rcu(vs
, vs_head(net
, port
), hlist
) {
384 if (inet_sk(vs
->sock
->sk
)->inet_sport
== port
&&
385 vxlan_get_sk_family(vs
) == family
&&
392 static struct vxlan_dev
*vxlan_vs_find_vni(struct vxlan_sock
*vs
, int ifindex
,
395 struct vxlan_dev_node
*node
;
397 /* For flow based devices, map all packets to VNI 0 */
398 if (vs
->flags
& VXLAN_F_COLLECT_METADATA
)
401 hlist_for_each_entry_rcu(node
, vni_head(vs
, vni
), hlist
) {
402 if (node
->vxlan
->default_dst
.remote_vni
!= vni
)
405 if (IS_ENABLED(CONFIG_IPV6
)) {
406 const struct vxlan_config
*cfg
= &node
->vxlan
->cfg
;
408 if ((cfg
->flags
& VXLAN_F_IPV6_LINKLOCAL
) &&
409 cfg
->remote_ifindex
!= ifindex
)
419 /* Look up VNI in a per net namespace table */
420 static struct vxlan_dev
*vxlan_find_vni(struct net
*net
, int ifindex
,
421 __be32 vni
, sa_family_t family
,
422 __be16 port
, u32 flags
)
424 struct vxlan_sock
*vs
;
426 vs
= vxlan_find_sock(net
, family
, port
, flags
);
430 return vxlan_vs_find_vni(vs
, ifindex
, vni
);
433 /* Fill in neighbour message in skbuff. */
434 static int vxlan_fdb_info(struct sk_buff
*skb
, struct vxlan_dev
*vxlan
,
435 const struct vxlan_fdb
*fdb
,
436 u32 portid
, u32 seq
, int type
, unsigned int flags
,
437 const struct vxlan_rdst
*rdst
)
439 unsigned long now
= jiffies
;
440 struct nda_cacheinfo ci
;
441 struct nlmsghdr
*nlh
;
443 bool send_ip
, send_eth
;
445 nlh
= nlmsg_put(skb
, portid
, seq
, type
, sizeof(*ndm
), flags
);
449 ndm
= nlmsg_data(nlh
);
450 memset(ndm
, 0, sizeof(*ndm
));
452 send_eth
= send_ip
= true;
454 if (type
== RTM_GETNEIGH
) {
455 send_ip
= !vxlan_addr_any(&rdst
->remote_ip
);
456 send_eth
= !is_zero_ether_addr(fdb
->eth_addr
);
457 ndm
->ndm_family
= send_ip
? rdst
->remote_ip
.sa
.sa_family
: AF_INET
;
459 ndm
->ndm_family
= AF_BRIDGE
;
460 ndm
->ndm_state
= fdb
->state
;
461 ndm
->ndm_ifindex
= vxlan
->dev
->ifindex
;
462 ndm
->ndm_flags
= fdb
->flags
;
463 ndm
->ndm_type
= RTN_UNICAST
;
465 if (!net_eq(dev_net(vxlan
->dev
), vxlan
->net
) &&
466 nla_put_s32(skb
, NDA_LINK_NETNSID
,
467 peernet2id(dev_net(vxlan
->dev
), vxlan
->net
)))
468 goto nla_put_failure
;
470 if (send_eth
&& nla_put(skb
, NDA_LLADDR
, ETH_ALEN
, &fdb
->eth_addr
))
471 goto nla_put_failure
;
473 if (send_ip
&& vxlan_nla_put_addr(skb
, NDA_DST
, &rdst
->remote_ip
))
474 goto nla_put_failure
;
476 if (rdst
->remote_port
&& rdst
->remote_port
!= vxlan
->cfg
.dst_port
&&
477 nla_put_be16(skb
, NDA_PORT
, rdst
->remote_port
))
478 goto nla_put_failure
;
479 if (rdst
->remote_vni
!= vxlan
->default_dst
.remote_vni
&&
480 nla_put_u32(skb
, NDA_VNI
, be32_to_cpu(rdst
->remote_vni
)))
481 goto nla_put_failure
;
482 if ((vxlan
->cfg
.flags
& VXLAN_F_COLLECT_METADATA
) && fdb
->vni
&&
483 nla_put_u32(skb
, NDA_SRC_VNI
,
484 be32_to_cpu(fdb
->vni
)))
485 goto nla_put_failure
;
486 if (rdst
->remote_ifindex
&&
487 nla_put_u32(skb
, NDA_IFINDEX
, rdst
->remote_ifindex
))
488 goto nla_put_failure
;
490 ci
.ndm_used
= jiffies_to_clock_t(now
- fdb
->used
);
491 ci
.ndm_confirmed
= 0;
492 ci
.ndm_updated
= jiffies_to_clock_t(now
- fdb
->updated
);
495 if (nla_put(skb
, NDA_CACHEINFO
, sizeof(ci
), &ci
))
496 goto nla_put_failure
;
502 nlmsg_cancel(skb
, nlh
);
506 static inline size_t vxlan_nlmsg_size(void)
508 return NLMSG_ALIGN(sizeof(struct ndmsg
))
509 + nla_total_size(ETH_ALEN
) /* NDA_LLADDR */
510 + nla_total_size(sizeof(struct in6_addr
)) /* NDA_DST */
511 + nla_total_size(sizeof(__be16
)) /* NDA_PORT */
512 + nla_total_size(sizeof(__be32
)) /* NDA_VNI */
513 + nla_total_size(sizeof(__u32
)) /* NDA_IFINDEX */
514 + nla_total_size(sizeof(__s32
)) /* NDA_LINK_NETNSID */
515 + nla_total_size(sizeof(struct nda_cacheinfo
));
518 static void vxlan_fdb_notify(struct vxlan_dev
*vxlan
, struct vxlan_fdb
*fdb
,
519 struct vxlan_rdst
*rd
, int type
)
521 struct net
*net
= dev_net(vxlan
->dev
);
525 skb
= nlmsg_new(vxlan_nlmsg_size(), GFP_ATOMIC
);
529 err
= vxlan_fdb_info(skb
, vxlan
, fdb
, 0, 0, type
, 0, rd
);
531 /* -EMSGSIZE implies BUG in vxlan_nlmsg_size() */
532 WARN_ON(err
== -EMSGSIZE
);
537 rtnl_notify(skb
, net
, 0, RTNLGRP_NEIGH
, NULL
, GFP_ATOMIC
);
541 rtnl_set_sk_err(net
, RTNLGRP_NEIGH
, err
);
544 static void vxlan_ip_miss(struct net_device
*dev
, union vxlan_addr
*ipa
)
546 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
547 struct vxlan_fdb f
= {
550 struct vxlan_rdst remote
= {
551 .remote_ip
= *ipa
, /* goes to NDA_DST */
552 .remote_vni
= cpu_to_be32(VXLAN_N_VID
),
555 vxlan_fdb_notify(vxlan
, &f
, &remote
, RTM_GETNEIGH
);
558 static void vxlan_fdb_miss(struct vxlan_dev
*vxlan
, const u8 eth_addr
[ETH_ALEN
])
560 struct vxlan_fdb f
= {
563 struct vxlan_rdst remote
= { };
565 memcpy(f
.eth_addr
, eth_addr
, ETH_ALEN
);
567 vxlan_fdb_notify(vxlan
, &f
, &remote
, RTM_GETNEIGH
);
570 /* Hash Ethernet address */
571 static u32
eth_hash(const unsigned char *addr
)
573 u64 value
= get_unaligned((u64
*)addr
);
575 /* only want 6 bytes */
581 return hash_64(value
, FDB_HASH_BITS
);
584 static u32
eth_vni_hash(const unsigned char *addr
, __be32 vni
)
586 /* use 1 byte of OUI and 3 bytes of NIC */
587 u32 key
= get_unaligned((u32
*)(addr
+ 2));
589 return jhash_2words(key
, vni
, vxlan_salt
) & (FDB_HASH_SIZE
- 1);
592 /* Hash chain to use given mac address */
593 static inline struct hlist_head
*vxlan_fdb_head(struct vxlan_dev
*vxlan
,
594 const u8
*mac
, __be32 vni
)
596 if (vxlan
->cfg
.flags
& VXLAN_F_COLLECT_METADATA
)
597 return &vxlan
->fdb_head
[eth_vni_hash(mac
, vni
)];
599 return &vxlan
->fdb_head
[eth_hash(mac
)];
602 /* Look up Ethernet address in forwarding table */
603 static struct vxlan_fdb
*__vxlan_find_mac(struct vxlan_dev
*vxlan
,
604 const u8
*mac
, __be32 vni
)
606 struct hlist_head
*head
= vxlan_fdb_head(vxlan
, mac
, vni
);
609 hlist_for_each_entry_rcu(f
, head
, hlist
) {
610 if (ether_addr_equal(mac
, f
->eth_addr
)) {
611 if (vxlan
->cfg
.flags
& VXLAN_F_COLLECT_METADATA
) {
623 static struct vxlan_fdb
*vxlan_find_mac(struct vxlan_dev
*vxlan
,
624 const u8
*mac
, __be32 vni
)
628 f
= __vxlan_find_mac(vxlan
, mac
, vni
);
635 /* caller should hold vxlan->hash_lock */
636 static struct vxlan_rdst
*vxlan_fdb_find_rdst(struct vxlan_fdb
*f
,
637 union vxlan_addr
*ip
, __be16 port
,
638 __be32 vni
, __u32 ifindex
)
640 struct vxlan_rdst
*rd
;
642 list_for_each_entry(rd
, &f
->remotes
, list
) {
643 if (vxlan_addr_equal(&rd
->remote_ip
, ip
) &&
644 rd
->remote_port
== port
&&
645 rd
->remote_vni
== vni
&&
646 rd
->remote_ifindex
== ifindex
)
653 /* Replace destination of unicast mac */
654 static int vxlan_fdb_replace(struct vxlan_fdb
*f
,
655 union vxlan_addr
*ip
, __be16 port
, __be32 vni
,
658 struct vxlan_rdst
*rd
;
660 rd
= vxlan_fdb_find_rdst(f
, ip
, port
, vni
, ifindex
);
664 rd
= list_first_entry_or_null(&f
->remotes
, struct vxlan_rdst
, list
);
668 dst_cache_reset(&rd
->dst_cache
);
670 rd
->remote_port
= port
;
671 rd
->remote_vni
= vni
;
672 rd
->remote_ifindex
= ifindex
;
676 /* Add/update destinations for multicast */
677 static int vxlan_fdb_append(struct vxlan_fdb
*f
,
678 union vxlan_addr
*ip
, __be16 port
, __be32 vni
,
679 __u32 ifindex
, struct vxlan_rdst
**rdp
)
681 struct vxlan_rdst
*rd
;
683 rd
= vxlan_fdb_find_rdst(f
, ip
, port
, vni
, ifindex
);
687 rd
= kmalloc(sizeof(*rd
), GFP_ATOMIC
);
691 if (dst_cache_init(&rd
->dst_cache
, GFP_ATOMIC
)) {
697 rd
->remote_port
= port
;
698 rd
->remote_vni
= vni
;
699 rd
->remote_ifindex
= ifindex
;
701 list_add_tail_rcu(&rd
->list
, &f
->remotes
);
707 static struct vxlanhdr
*vxlan_gro_remcsum(struct sk_buff
*skb
,
709 struct vxlanhdr
*vh
, size_t hdrlen
,
711 struct gro_remcsum
*grc
,
714 size_t start
, offset
;
716 if (skb
->remcsum_offload
)
719 if (!NAPI_GRO_CB(skb
)->csum_valid
)
722 start
= vxlan_rco_start(vni_field
);
723 offset
= start
+ vxlan_rco_offset(vni_field
);
725 vh
= skb_gro_remcsum_process(skb
, (void *)vh
, off
, hdrlen
,
726 start
, offset
, grc
, nopartial
);
728 skb
->remcsum_offload
= 1;
733 static struct sk_buff
**vxlan_gro_receive(struct sock
*sk
,
734 struct sk_buff
**head
,
737 struct sk_buff
*p
, **pp
= NULL
;
738 struct vxlanhdr
*vh
, *vh2
;
739 unsigned int hlen
, off_vx
;
741 struct vxlan_sock
*vs
= rcu_dereference_sk_user_data(sk
);
743 struct gro_remcsum grc
;
745 skb_gro_remcsum_init(&grc
);
747 off_vx
= skb_gro_offset(skb
);
748 hlen
= off_vx
+ sizeof(*vh
);
749 vh
= skb_gro_header_fast(skb
, off_vx
);
750 if (skb_gro_header_hard(skb
, hlen
)) {
751 vh
= skb_gro_header_slow(skb
, hlen
, off_vx
);
756 skb_gro_postpull_rcsum(skb
, vh
, sizeof(struct vxlanhdr
));
758 flags
= vh
->vx_flags
;
760 if ((flags
& VXLAN_HF_RCO
) && (vs
->flags
& VXLAN_F_REMCSUM_RX
)) {
761 vh
= vxlan_gro_remcsum(skb
, off_vx
, vh
, sizeof(struct vxlanhdr
),
764 VXLAN_F_REMCSUM_NOPARTIAL
));
770 skb_gro_pull(skb
, sizeof(struct vxlanhdr
)); /* pull vxlan header */
772 for (p
= *head
; p
; p
= p
->next
) {
773 if (!NAPI_GRO_CB(p
)->same_flow
)
776 vh2
= (struct vxlanhdr
*)(p
->data
+ off_vx
);
777 if (vh
->vx_flags
!= vh2
->vx_flags
||
778 vh
->vx_vni
!= vh2
->vx_vni
) {
779 NAPI_GRO_CB(p
)->same_flow
= 0;
784 pp
= call_gro_receive(eth_gro_receive
, head
, skb
);
788 skb_gro_remcsum_cleanup(skb
, &grc
);
789 skb
->remcsum_offload
= 0;
790 NAPI_GRO_CB(skb
)->flush
|= flush
;
795 static int vxlan_gro_complete(struct sock
*sk
, struct sk_buff
*skb
, int nhoff
)
797 /* Sets 'skb->inner_mac_header' since we are always called with
798 * 'skb->encapsulation' set.
800 return eth_gro_complete(skb
, nhoff
+ sizeof(struct vxlanhdr
));
803 /* Add new entry to forwarding table -- assumes lock held */
804 static int vxlan_fdb_create(struct vxlan_dev
*vxlan
,
805 const u8
*mac
, union vxlan_addr
*ip
,
806 __u16 state
, __u16 flags
,
807 __be16 port
, __be32 src_vni
, __be32 vni
,
808 __u32 ifindex
, __u8 ndm_flags
)
810 struct vxlan_rdst
*rd
= NULL
;
815 f
= __vxlan_find_mac(vxlan
, mac
, src_vni
);
817 if (flags
& NLM_F_EXCL
) {
818 netdev_dbg(vxlan
->dev
,
819 "lost race to create %pM\n", mac
);
822 if (f
->state
!= state
) {
824 f
->updated
= jiffies
;
827 if (f
->flags
!= ndm_flags
) {
828 f
->flags
= ndm_flags
;
829 f
->updated
= jiffies
;
832 if ((flags
& NLM_F_REPLACE
)) {
833 /* Only change unicasts */
834 if (!(is_multicast_ether_addr(f
->eth_addr
) ||
835 is_zero_ether_addr(f
->eth_addr
))) {
836 notify
|= vxlan_fdb_replace(f
, ip
, port
, vni
,
841 if ((flags
& NLM_F_APPEND
) &&
842 (is_multicast_ether_addr(f
->eth_addr
) ||
843 is_zero_ether_addr(f
->eth_addr
))) {
844 rc
= vxlan_fdb_append(f
, ip
, port
, vni
, ifindex
, &rd
);
851 if (!(flags
& NLM_F_CREATE
))
854 if (vxlan
->cfg
.addrmax
&&
855 vxlan
->addrcnt
>= vxlan
->cfg
.addrmax
)
858 /* Disallow replace to add a multicast entry */
859 if ((flags
& NLM_F_REPLACE
) &&
860 (is_multicast_ether_addr(mac
) || is_zero_ether_addr(mac
)))
863 netdev_dbg(vxlan
->dev
, "add %pM -> %pIS\n", mac
, ip
);
864 f
= kmalloc(sizeof(*f
), GFP_ATOMIC
);
870 f
->flags
= ndm_flags
;
871 f
->updated
= f
->used
= jiffies
;
873 INIT_LIST_HEAD(&f
->remotes
);
874 memcpy(f
->eth_addr
, mac
, ETH_ALEN
);
876 rc
= vxlan_fdb_append(f
, ip
, port
, vni
, ifindex
, &rd
);
883 hlist_add_head_rcu(&f
->hlist
,
884 vxlan_fdb_head(vxlan
, mac
, src_vni
));
889 rd
= first_remote_rtnl(f
);
890 vxlan_fdb_notify(vxlan
, f
, rd
, RTM_NEWNEIGH
);
896 static void vxlan_fdb_free(struct rcu_head
*head
)
898 struct vxlan_fdb
*f
= container_of(head
, struct vxlan_fdb
, rcu
);
899 struct vxlan_rdst
*rd
, *nd
;
901 list_for_each_entry_safe(rd
, nd
, &f
->remotes
, list
) {
902 dst_cache_destroy(&rd
->dst_cache
);
908 static void vxlan_fdb_destroy(struct vxlan_dev
*vxlan
, struct vxlan_fdb
*f
)
910 netdev_dbg(vxlan
->dev
,
911 "delete %pM\n", f
->eth_addr
);
914 vxlan_fdb_notify(vxlan
, f
, first_remote_rtnl(f
), RTM_DELNEIGH
);
916 hlist_del_rcu(&f
->hlist
);
917 call_rcu(&f
->rcu
, vxlan_fdb_free
);
920 static void vxlan_dst_free(struct rcu_head
*head
)
922 struct vxlan_rdst
*rd
= container_of(head
, struct vxlan_rdst
, rcu
);
924 dst_cache_destroy(&rd
->dst_cache
);
928 static void vxlan_fdb_dst_destroy(struct vxlan_dev
*vxlan
, struct vxlan_fdb
*f
,
929 struct vxlan_rdst
*rd
)
931 list_del_rcu(&rd
->list
);
932 vxlan_fdb_notify(vxlan
, f
, rd
, RTM_DELNEIGH
);
933 call_rcu(&rd
->rcu
, vxlan_dst_free
);
936 static int vxlan_fdb_parse(struct nlattr
*tb
[], struct vxlan_dev
*vxlan
,
937 union vxlan_addr
*ip
, __be16
*port
, __be32
*src_vni
,
938 __be32
*vni
, u32
*ifindex
)
940 struct net
*net
= dev_net(vxlan
->dev
);
944 err
= vxlan_nla_get_addr(ip
, tb
[NDA_DST
]);
948 union vxlan_addr
*remote
= &vxlan
->default_dst
.remote_ip
;
949 if (remote
->sa
.sa_family
== AF_INET
) {
950 ip
->sin
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
951 ip
->sa
.sa_family
= AF_INET
;
952 #if IS_ENABLED(CONFIG_IPV6)
954 ip
->sin6
.sin6_addr
= in6addr_any
;
955 ip
->sa
.sa_family
= AF_INET6
;
961 if (nla_len(tb
[NDA_PORT
]) != sizeof(__be16
))
963 *port
= nla_get_be16(tb
[NDA_PORT
]);
965 *port
= vxlan
->cfg
.dst_port
;
969 if (nla_len(tb
[NDA_VNI
]) != sizeof(u32
))
971 *vni
= cpu_to_be32(nla_get_u32(tb
[NDA_VNI
]));
973 *vni
= vxlan
->default_dst
.remote_vni
;
976 if (tb
[NDA_SRC_VNI
]) {
977 if (nla_len(tb
[NDA_SRC_VNI
]) != sizeof(u32
))
979 *src_vni
= cpu_to_be32(nla_get_u32(tb
[NDA_SRC_VNI
]));
981 *src_vni
= vxlan
->default_dst
.remote_vni
;
984 if (tb
[NDA_IFINDEX
]) {
985 struct net_device
*tdev
;
987 if (nla_len(tb
[NDA_IFINDEX
]) != sizeof(u32
))
989 *ifindex
= nla_get_u32(tb
[NDA_IFINDEX
]);
990 tdev
= __dev_get_by_index(net
, *ifindex
);
992 return -EADDRNOTAVAIL
;
1000 /* Add static entry (via netlink) */
1001 static int vxlan_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
1002 struct net_device
*dev
,
1003 const unsigned char *addr
, u16 vid
, u16 flags
)
1005 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1006 /* struct net *net = dev_net(vxlan->dev); */
1007 union vxlan_addr ip
;
1009 __be32 src_vni
, vni
;
1013 if (!(ndm
->ndm_state
& (NUD_PERMANENT
|NUD_REACHABLE
))) {
1014 pr_info("RTM_NEWNEIGH with invalid state %#x\n",
1019 if (tb
[NDA_DST
] == NULL
)
1022 err
= vxlan_fdb_parse(tb
, vxlan
, &ip
, &port
, &src_vni
, &vni
, &ifindex
);
1026 if (vxlan
->default_dst
.remote_ip
.sa
.sa_family
!= ip
.sa
.sa_family
)
1027 return -EAFNOSUPPORT
;
1029 spin_lock_bh(&vxlan
->hash_lock
);
1030 err
= vxlan_fdb_create(vxlan
, addr
, &ip
, ndm
->ndm_state
, flags
,
1031 port
, src_vni
, vni
, ifindex
, ndm
->ndm_flags
);
1032 spin_unlock_bh(&vxlan
->hash_lock
);
1037 static int __vxlan_fdb_delete(struct vxlan_dev
*vxlan
,
1038 const unsigned char *addr
, union vxlan_addr ip
,
1039 __be16 port
, __be32 src_vni
, __be32 vni
,
1040 u32 ifindex
, u16 vid
)
1042 struct vxlan_fdb
*f
;
1043 struct vxlan_rdst
*rd
= NULL
;
1046 f
= vxlan_find_mac(vxlan
, addr
, src_vni
);
1050 if (!vxlan_addr_any(&ip
)) {
1051 rd
= vxlan_fdb_find_rdst(f
, &ip
, port
, vni
, ifindex
);
1056 /* remove a destination if it's not the only one on the list,
1057 * otherwise destroy the fdb entry
1059 if (rd
&& !list_is_singular(&f
->remotes
)) {
1060 vxlan_fdb_dst_destroy(vxlan
, f
, rd
);
1064 vxlan_fdb_destroy(vxlan
, f
);
1070 /* Delete entry (via netlink) */
1071 static int vxlan_fdb_delete(struct ndmsg
*ndm
, struct nlattr
*tb
[],
1072 struct net_device
*dev
,
1073 const unsigned char *addr
, u16 vid
)
1075 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1076 union vxlan_addr ip
;
1077 __be32 src_vni
, vni
;
1082 err
= vxlan_fdb_parse(tb
, vxlan
, &ip
, &port
, &src_vni
, &vni
, &ifindex
);
1086 spin_lock_bh(&vxlan
->hash_lock
);
1087 err
= __vxlan_fdb_delete(vxlan
, addr
, ip
, port
, src_vni
, vni
, ifindex
,
1089 spin_unlock_bh(&vxlan
->hash_lock
);
1094 /* Dump forwarding table */
1095 static int vxlan_fdb_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
,
1096 struct net_device
*dev
,
1097 struct net_device
*filter_dev
, int *idx
)
1099 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1103 for (h
= 0; h
< FDB_HASH_SIZE
; ++h
) {
1104 struct vxlan_fdb
*f
;
1106 hlist_for_each_entry_rcu(f
, &vxlan
->fdb_head
[h
], hlist
) {
1107 struct vxlan_rdst
*rd
;
1109 list_for_each_entry_rcu(rd
, &f
->remotes
, list
) {
1110 if (*idx
< cb
->args
[2])
1113 err
= vxlan_fdb_info(skb
, vxlan
, f
,
1114 NETLINK_CB(cb
->skb
).portid
,
1129 /* Watch incoming packets to learn mapping between Ethernet address
1130 * and Tunnel endpoint.
1131 * Return true if packet is bogus and should be dropped.
1133 static bool vxlan_snoop(struct net_device
*dev
,
1134 union vxlan_addr
*src_ip
, const u8
*src_mac
,
1135 u32 src_ifindex
, __be32 vni
)
1137 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1138 struct vxlan_fdb
*f
;
1141 #if IS_ENABLED(CONFIG_IPV6)
1142 if (src_ip
->sa
.sa_family
== AF_INET6
&&
1143 (ipv6_addr_type(&src_ip
->sin6
.sin6_addr
) & IPV6_ADDR_LINKLOCAL
))
1144 ifindex
= src_ifindex
;
1147 f
= vxlan_find_mac(vxlan
, src_mac
, vni
);
1149 struct vxlan_rdst
*rdst
= first_remote_rcu(f
);
1151 if (likely(vxlan_addr_equal(&rdst
->remote_ip
, src_ip
) &&
1152 rdst
->remote_ifindex
== ifindex
))
1155 /* Don't migrate static entries, drop packets */
1156 if (f
->state
& (NUD_PERMANENT
| NUD_NOARP
))
1159 if (net_ratelimit())
1161 "%pM migrated from %pIS to %pIS\n",
1162 src_mac
, &rdst
->remote_ip
.sa
, &src_ip
->sa
);
1164 rdst
->remote_ip
= *src_ip
;
1165 f
->updated
= jiffies
;
1166 vxlan_fdb_notify(vxlan
, f
, rdst
, RTM_NEWNEIGH
);
1168 /* learned new entry */
1169 spin_lock(&vxlan
->hash_lock
);
1171 /* close off race between vxlan_flush and incoming packets */
1172 if (netif_running(dev
))
1173 vxlan_fdb_create(vxlan
, src_mac
, src_ip
,
1175 NLM_F_EXCL
|NLM_F_CREATE
,
1176 vxlan
->cfg
.dst_port
,
1178 vxlan
->default_dst
.remote_vni
,
1180 spin_unlock(&vxlan
->hash_lock
);
1186 /* See if multicast group is already in use by other ID */
1187 static bool vxlan_group_used(struct vxlan_net
*vn
, struct vxlan_dev
*dev
)
1189 struct vxlan_dev
*vxlan
;
1190 struct vxlan_sock
*sock4
;
1191 #if IS_ENABLED(CONFIG_IPV6)
1192 struct vxlan_sock
*sock6
;
1194 unsigned short family
= dev
->default_dst
.remote_ip
.sa
.sa_family
;
1196 sock4
= rtnl_dereference(dev
->vn4_sock
);
1198 /* The vxlan_sock is only used by dev, leaving group has
1199 * no effect on other vxlan devices.
1201 if (family
== AF_INET
&& sock4
&& refcount_read(&sock4
->refcnt
) == 1)
1203 #if IS_ENABLED(CONFIG_IPV6)
1204 sock6
= rtnl_dereference(dev
->vn6_sock
);
1205 if (family
== AF_INET6
&& sock6
&& refcount_read(&sock6
->refcnt
) == 1)
1209 list_for_each_entry(vxlan
, &vn
->vxlan_list
, next
) {
1210 if (!netif_running(vxlan
->dev
) || vxlan
== dev
)
1213 if (family
== AF_INET
&&
1214 rtnl_dereference(vxlan
->vn4_sock
) != sock4
)
1216 #if IS_ENABLED(CONFIG_IPV6)
1217 if (family
== AF_INET6
&&
1218 rtnl_dereference(vxlan
->vn6_sock
) != sock6
)
1222 if (!vxlan_addr_equal(&vxlan
->default_dst
.remote_ip
,
1223 &dev
->default_dst
.remote_ip
))
1226 if (vxlan
->default_dst
.remote_ifindex
!=
1227 dev
->default_dst
.remote_ifindex
)
1236 static bool __vxlan_sock_release_prep(struct vxlan_sock
*vs
)
1238 struct vxlan_net
*vn
;
1242 if (!refcount_dec_and_test(&vs
->refcnt
))
1245 vn
= net_generic(sock_net(vs
->sock
->sk
), vxlan_net_id
);
1246 spin_lock(&vn
->sock_lock
);
1247 hlist_del_rcu(&vs
->hlist
);
1248 udp_tunnel_notify_del_rx_port(vs
->sock
,
1249 (vs
->flags
& VXLAN_F_GPE
) ?
1250 UDP_TUNNEL_TYPE_VXLAN_GPE
:
1251 UDP_TUNNEL_TYPE_VXLAN
);
1252 spin_unlock(&vn
->sock_lock
);
1257 static void vxlan_sock_release(struct vxlan_dev
*vxlan
)
1259 struct vxlan_sock
*sock4
= rtnl_dereference(vxlan
->vn4_sock
);
1260 #if IS_ENABLED(CONFIG_IPV6)
1261 struct vxlan_sock
*sock6
= rtnl_dereference(vxlan
->vn6_sock
);
1263 RCU_INIT_POINTER(vxlan
->vn6_sock
, NULL
);
1266 RCU_INIT_POINTER(vxlan
->vn4_sock
, NULL
);
1269 vxlan_vs_del_dev(vxlan
);
1271 if (__vxlan_sock_release_prep(sock4
)) {
1272 udp_tunnel_sock_release(sock4
->sock
);
1276 #if IS_ENABLED(CONFIG_IPV6)
1277 if (__vxlan_sock_release_prep(sock6
)) {
1278 udp_tunnel_sock_release(sock6
->sock
);
1284 /* Update multicast group membership when first VNI on
1285 * multicast address is brought up
1287 static int vxlan_igmp_join(struct vxlan_dev
*vxlan
)
1290 union vxlan_addr
*ip
= &vxlan
->default_dst
.remote_ip
;
1291 int ifindex
= vxlan
->default_dst
.remote_ifindex
;
1294 if (ip
->sa
.sa_family
== AF_INET
) {
1295 struct vxlan_sock
*sock4
= rtnl_dereference(vxlan
->vn4_sock
);
1296 struct ip_mreqn mreq
= {
1297 .imr_multiaddr
.s_addr
= ip
->sin
.sin_addr
.s_addr
,
1298 .imr_ifindex
= ifindex
,
1301 sk
= sock4
->sock
->sk
;
1303 ret
= ip_mc_join_group(sk
, &mreq
);
1305 #if IS_ENABLED(CONFIG_IPV6)
1307 struct vxlan_sock
*sock6
= rtnl_dereference(vxlan
->vn6_sock
);
1309 sk
= sock6
->sock
->sk
;
1311 ret
= ipv6_stub
->ipv6_sock_mc_join(sk
, ifindex
,
1312 &ip
->sin6
.sin6_addr
);
1320 /* Inverse of vxlan_igmp_join when last VNI is brought down */
1321 static int vxlan_igmp_leave(struct vxlan_dev
*vxlan
)
1324 union vxlan_addr
*ip
= &vxlan
->default_dst
.remote_ip
;
1325 int ifindex
= vxlan
->default_dst
.remote_ifindex
;
1328 if (ip
->sa
.sa_family
== AF_INET
) {
1329 struct vxlan_sock
*sock4
= rtnl_dereference(vxlan
->vn4_sock
);
1330 struct ip_mreqn mreq
= {
1331 .imr_multiaddr
.s_addr
= ip
->sin
.sin_addr
.s_addr
,
1332 .imr_ifindex
= ifindex
,
1335 sk
= sock4
->sock
->sk
;
1337 ret
= ip_mc_leave_group(sk
, &mreq
);
1339 #if IS_ENABLED(CONFIG_IPV6)
1341 struct vxlan_sock
*sock6
= rtnl_dereference(vxlan
->vn6_sock
);
1343 sk
= sock6
->sock
->sk
;
1345 ret
= ipv6_stub
->ipv6_sock_mc_drop(sk
, ifindex
,
1346 &ip
->sin6
.sin6_addr
);
1354 static bool vxlan_remcsum(struct vxlanhdr
*unparsed
,
1355 struct sk_buff
*skb
, u32 vxflags
)
1357 size_t start
, offset
;
1359 if (!(unparsed
->vx_flags
& VXLAN_HF_RCO
) || skb
->remcsum_offload
)
1362 start
= vxlan_rco_start(unparsed
->vx_vni
);
1363 offset
= start
+ vxlan_rco_offset(unparsed
->vx_vni
);
1365 if (!pskb_may_pull(skb
, offset
+ sizeof(u16
)))
1368 skb_remcsum_process(skb
, (void *)(vxlan_hdr(skb
) + 1), start
, offset
,
1369 !!(vxflags
& VXLAN_F_REMCSUM_NOPARTIAL
));
1371 unparsed
->vx_flags
&= ~VXLAN_HF_RCO
;
1372 unparsed
->vx_vni
&= VXLAN_VNI_MASK
;
1376 static void vxlan_parse_gbp_hdr(struct vxlanhdr
*unparsed
,
1377 struct sk_buff
*skb
, u32 vxflags
,
1378 struct vxlan_metadata
*md
)
1380 struct vxlanhdr_gbp
*gbp
= (struct vxlanhdr_gbp
*)unparsed
;
1381 struct metadata_dst
*tun_dst
;
1383 if (!(unparsed
->vx_flags
& VXLAN_HF_GBP
))
1386 md
->gbp
= ntohs(gbp
->policy_id
);
1388 tun_dst
= (struct metadata_dst
*)skb_dst(skb
);
1390 tun_dst
->u
.tun_info
.key
.tun_flags
|= TUNNEL_VXLAN_OPT
;
1391 tun_dst
->u
.tun_info
.options_len
= sizeof(*md
);
1393 if (gbp
->dont_learn
)
1394 md
->gbp
|= VXLAN_GBP_DONT_LEARN
;
1396 if (gbp
->policy_applied
)
1397 md
->gbp
|= VXLAN_GBP_POLICY_APPLIED
;
1399 /* In flow-based mode, GBP is carried in dst_metadata */
1400 if (!(vxflags
& VXLAN_F_COLLECT_METADATA
))
1401 skb
->mark
= md
->gbp
;
1403 unparsed
->vx_flags
&= ~VXLAN_GBP_USED_BITS
;
1406 static bool vxlan_parse_gpe_hdr(struct vxlanhdr
*unparsed
,
1408 struct sk_buff
*skb
, u32 vxflags
)
1410 struct vxlanhdr_gpe
*gpe
= (struct vxlanhdr_gpe
*)unparsed
;
1412 /* Need to have Next Protocol set for interfaces in GPE mode. */
1413 if (!gpe
->np_applied
)
1415 /* "The initial version is 0. If a receiver does not support the
1416 * version indicated it MUST drop the packet.
1418 if (gpe
->version
!= 0)
1420 /* "When the O bit is set to 1, the packet is an OAM packet and OAM
1421 * processing MUST occur." However, we don't implement OAM
1422 * processing, thus drop the packet.
1427 *protocol
= tun_p_to_eth_p(gpe
->next_protocol
);
1431 unparsed
->vx_flags
&= ~VXLAN_GPE_USED_BITS
;
1435 static bool vxlan_set_mac(struct vxlan_dev
*vxlan
,
1436 struct vxlan_sock
*vs
,
1437 struct sk_buff
*skb
, __be32 vni
)
1439 union vxlan_addr saddr
;
1440 u32 ifindex
= skb
->dev
->ifindex
;
1442 skb_reset_mac_header(skb
);
1443 skb
->protocol
= eth_type_trans(skb
, vxlan
->dev
);
1444 skb_postpull_rcsum(skb
, eth_hdr(skb
), ETH_HLEN
);
1446 /* Ignore packet loops (and multicast echo) */
1447 if (ether_addr_equal(eth_hdr(skb
)->h_source
, vxlan
->dev
->dev_addr
))
1450 /* Get address from the outer IP header */
1451 if (vxlan_get_sk_family(vs
) == AF_INET
) {
1452 saddr
.sin
.sin_addr
.s_addr
= ip_hdr(skb
)->saddr
;
1453 saddr
.sa
.sa_family
= AF_INET
;
1454 #if IS_ENABLED(CONFIG_IPV6)
1456 saddr
.sin6
.sin6_addr
= ipv6_hdr(skb
)->saddr
;
1457 saddr
.sa
.sa_family
= AF_INET6
;
1461 if ((vxlan
->cfg
.flags
& VXLAN_F_LEARN
) &&
1462 vxlan_snoop(skb
->dev
, &saddr
, eth_hdr(skb
)->h_source
, ifindex
, vni
))
1468 static bool vxlan_ecn_decapsulate(struct vxlan_sock
*vs
, void *oiph
,
1469 struct sk_buff
*skb
)
1473 if (vxlan_get_sk_family(vs
) == AF_INET
)
1474 err
= IP_ECN_decapsulate(oiph
, skb
);
1475 #if IS_ENABLED(CONFIG_IPV6)
1477 err
= IP6_ECN_decapsulate(oiph
, skb
);
1480 if (unlikely(err
) && log_ecn_error
) {
1481 if (vxlan_get_sk_family(vs
) == AF_INET
)
1482 net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
1483 &((struct iphdr
*)oiph
)->saddr
,
1484 ((struct iphdr
*)oiph
)->tos
);
1486 net_info_ratelimited("non-ECT from %pI6\n",
1487 &((struct ipv6hdr
*)oiph
)->saddr
);
1492 /* Callback from net/ipv4/udp.c to receive packets */
1493 static int vxlan_rcv(struct sock
*sk
, struct sk_buff
*skb
)
1495 struct pcpu_sw_netstats
*stats
;
1496 struct vxlan_dev
*vxlan
;
1497 struct vxlan_sock
*vs
;
1498 struct vxlanhdr unparsed
;
1499 struct vxlan_metadata _md
;
1500 struct vxlan_metadata
*md
= &_md
;
1501 __be16 protocol
= htons(ETH_P_TEB
);
1502 bool raw_proto
= false;
1506 /* Need UDP and VXLAN header to be present */
1507 if (!pskb_may_pull(skb
, VXLAN_HLEN
))
1510 unparsed
= *vxlan_hdr(skb
);
1511 /* VNI flag always required to be set */
1512 if (!(unparsed
.vx_flags
& VXLAN_HF_VNI
)) {
1513 netdev_dbg(skb
->dev
, "invalid vxlan flags=%#x vni=%#x\n",
1514 ntohl(vxlan_hdr(skb
)->vx_flags
),
1515 ntohl(vxlan_hdr(skb
)->vx_vni
));
1516 /* Return non vxlan pkt */
1519 unparsed
.vx_flags
&= ~VXLAN_HF_VNI
;
1520 unparsed
.vx_vni
&= ~VXLAN_VNI_MASK
;
1522 vs
= rcu_dereference_sk_user_data(sk
);
1526 vni
= vxlan_vni(vxlan_hdr(skb
)->vx_vni
);
1528 vxlan
= vxlan_vs_find_vni(vs
, skb
->dev
->ifindex
, vni
);
1532 /* For backwards compatibility, only allow reserved fields to be
1533 * used by VXLAN extensions if explicitly requested.
1535 if (vs
->flags
& VXLAN_F_GPE
) {
1536 if (!vxlan_parse_gpe_hdr(&unparsed
, &protocol
, skb
, vs
->flags
))
1541 if (__iptunnel_pull_header(skb
, VXLAN_HLEN
, protocol
, raw_proto
,
1542 !net_eq(vxlan
->net
, dev_net(vxlan
->dev
))))
1545 if (vxlan_collect_metadata(vs
)) {
1546 struct metadata_dst
*tun_dst
;
1548 tun_dst
= udp_tun_rx_dst(skb
, vxlan_get_sk_family(vs
), TUNNEL_KEY
,
1549 key32_to_tunnel_id(vni
), sizeof(*md
));
1554 md
= ip_tunnel_info_opts(&tun_dst
->u
.tun_info
);
1556 skb_dst_set(skb
, (struct dst_entry
*)tun_dst
);
1558 memset(md
, 0, sizeof(*md
));
1561 if (vs
->flags
& VXLAN_F_REMCSUM_RX
)
1562 if (!vxlan_remcsum(&unparsed
, skb
, vs
->flags
))
1564 if (vs
->flags
& VXLAN_F_GBP
)
1565 vxlan_parse_gbp_hdr(&unparsed
, skb
, vs
->flags
, md
);
1566 /* Note that GBP and GPE can never be active together. This is
1567 * ensured in vxlan_dev_configure.
1570 if (unparsed
.vx_flags
|| unparsed
.vx_vni
) {
1571 /* If there are any unprocessed flags remaining treat
1572 * this as a malformed packet. This behavior diverges from
1573 * VXLAN RFC (RFC7348) which stipulates that bits in reserved
1574 * in reserved fields are to be ignored. The approach here
1575 * maintains compatibility with previous stack code, and also
1576 * is more robust and provides a little more security in
1577 * adding extensions to VXLAN.
1583 if (!vxlan_set_mac(vxlan
, vs
, skb
, vni
))
1586 skb_reset_mac_header(skb
);
1587 skb
->dev
= vxlan
->dev
;
1588 skb
->pkt_type
= PACKET_HOST
;
1591 oiph
= skb_network_header(skb
);
1592 skb_reset_network_header(skb
);
1594 if (!vxlan_ecn_decapsulate(vs
, oiph
, skb
)) {
1595 ++vxlan
->dev
->stats
.rx_frame_errors
;
1596 ++vxlan
->dev
->stats
.rx_errors
;
1600 stats
= this_cpu_ptr(vxlan
->dev
->tstats
);
1601 u64_stats_update_begin(&stats
->syncp
);
1602 stats
->rx_packets
++;
1603 stats
->rx_bytes
+= skb
->len
;
1604 u64_stats_update_end(&stats
->syncp
);
1606 gro_cells_receive(&vxlan
->gro_cells
, skb
);
1610 /* Consume bad packet */
1615 static int arp_reduce(struct net_device
*dev
, struct sk_buff
*skb
, __be32 vni
)
1617 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1618 struct arphdr
*parp
;
1621 struct neighbour
*n
;
1623 if (dev
->flags
& IFF_NOARP
)
1626 if (!pskb_may_pull(skb
, arp_hdr_len(dev
))) {
1627 dev
->stats
.tx_dropped
++;
1630 parp
= arp_hdr(skb
);
1632 if ((parp
->ar_hrd
!= htons(ARPHRD_ETHER
) &&
1633 parp
->ar_hrd
!= htons(ARPHRD_IEEE802
)) ||
1634 parp
->ar_pro
!= htons(ETH_P_IP
) ||
1635 parp
->ar_op
!= htons(ARPOP_REQUEST
) ||
1636 parp
->ar_hln
!= dev
->addr_len
||
1639 arpptr
= (u8
*)parp
+ sizeof(struct arphdr
);
1641 arpptr
+= dev
->addr_len
; /* sha */
1642 memcpy(&sip
, arpptr
, sizeof(sip
));
1643 arpptr
+= sizeof(sip
);
1644 arpptr
+= dev
->addr_len
; /* tha */
1645 memcpy(&tip
, arpptr
, sizeof(tip
));
1647 if (ipv4_is_loopback(tip
) ||
1648 ipv4_is_multicast(tip
))
1651 n
= neigh_lookup(&arp_tbl
, &tip
, dev
);
1654 struct vxlan_fdb
*f
;
1655 struct sk_buff
*reply
;
1657 if (!(n
->nud_state
& NUD_CONNECTED
)) {
1662 f
= vxlan_find_mac(vxlan
, n
->ha
, vni
);
1663 if (f
&& vxlan_addr_any(&(first_remote_rcu(f
)->remote_ip
))) {
1664 /* bridge-local neighbor */
1669 reply
= arp_create(ARPOP_REPLY
, ETH_P_ARP
, sip
, dev
, tip
, sha
,
1677 skb_reset_mac_header(reply
);
1678 __skb_pull(reply
, skb_network_offset(reply
));
1679 reply
->ip_summed
= CHECKSUM_UNNECESSARY
;
1680 reply
->pkt_type
= PACKET_HOST
;
1682 if (netif_rx_ni(reply
) == NET_RX_DROP
)
1683 dev
->stats
.rx_dropped
++;
1684 } else if (vxlan
->cfg
.flags
& VXLAN_F_L3MISS
) {
1685 union vxlan_addr ipa
= {
1686 .sin
.sin_addr
.s_addr
= tip
,
1687 .sin
.sin_family
= AF_INET
,
1690 vxlan_ip_miss(dev
, &ipa
);
1694 return NETDEV_TX_OK
;
1697 #if IS_ENABLED(CONFIG_IPV6)
1698 static struct sk_buff
*vxlan_na_create(struct sk_buff
*request
,
1699 struct neighbour
*n
, bool isrouter
)
1701 struct net_device
*dev
= request
->dev
;
1702 struct sk_buff
*reply
;
1703 struct nd_msg
*ns
, *na
;
1704 struct ipv6hdr
*pip6
;
1706 int na_olen
= 8; /* opt hdr + ETH_ALEN for target */
1710 if (dev
== NULL
|| !pskb_may_pull(request
, request
->len
))
1713 len
= LL_RESERVED_SPACE(dev
) + sizeof(struct ipv6hdr
) +
1714 sizeof(*na
) + na_olen
+ dev
->needed_tailroom
;
1715 reply
= alloc_skb(len
, GFP_ATOMIC
);
1719 reply
->protocol
= htons(ETH_P_IPV6
);
1721 skb_reserve(reply
, LL_RESERVED_SPACE(request
->dev
));
1722 skb_push(reply
, sizeof(struct ethhdr
));
1723 skb_reset_mac_header(reply
);
1725 ns
= (struct nd_msg
*)(ipv6_hdr(request
) + 1);
1727 daddr
= eth_hdr(request
)->h_source
;
1728 ns_olen
= request
->len
- skb_network_offset(request
) -
1729 sizeof(struct ipv6hdr
) - sizeof(*ns
);
1730 for (i
= 0; i
< ns_olen
-1; i
+= (ns
->opt
[i
+1]<<3)) {
1731 if (ns
->opt
[i
] == ND_OPT_SOURCE_LL_ADDR
) {
1732 daddr
= ns
->opt
+ i
+ sizeof(struct nd_opt_hdr
);
1737 /* Ethernet header */
1738 ether_addr_copy(eth_hdr(reply
)->h_dest
, daddr
);
1739 ether_addr_copy(eth_hdr(reply
)->h_source
, n
->ha
);
1740 eth_hdr(reply
)->h_proto
= htons(ETH_P_IPV6
);
1741 reply
->protocol
= htons(ETH_P_IPV6
);
1743 skb_pull(reply
, sizeof(struct ethhdr
));
1744 skb_reset_network_header(reply
);
1745 skb_put(reply
, sizeof(struct ipv6hdr
));
1749 pip6
= ipv6_hdr(reply
);
1750 memset(pip6
, 0, sizeof(struct ipv6hdr
));
1752 pip6
->priority
= ipv6_hdr(request
)->priority
;
1753 pip6
->nexthdr
= IPPROTO_ICMPV6
;
1754 pip6
->hop_limit
= 255;
1755 pip6
->daddr
= ipv6_hdr(request
)->saddr
;
1756 pip6
->saddr
= *(struct in6_addr
*)n
->primary_key
;
1758 skb_pull(reply
, sizeof(struct ipv6hdr
));
1759 skb_reset_transport_header(reply
);
1761 /* Neighbor Advertisement */
1762 na
= skb_put_zero(reply
, sizeof(*na
) + na_olen
);
1763 na
->icmph
.icmp6_type
= NDISC_NEIGHBOUR_ADVERTISEMENT
;
1764 na
->icmph
.icmp6_router
= isrouter
;
1765 na
->icmph
.icmp6_override
= 1;
1766 na
->icmph
.icmp6_solicited
= 1;
1767 na
->target
= ns
->target
;
1768 ether_addr_copy(&na
->opt
[2], n
->ha
);
1769 na
->opt
[0] = ND_OPT_TARGET_LL_ADDR
;
1770 na
->opt
[1] = na_olen
>> 3;
1772 na
->icmph
.icmp6_cksum
= csum_ipv6_magic(&pip6
->saddr
,
1773 &pip6
->daddr
, sizeof(*na
)+na_olen
, IPPROTO_ICMPV6
,
1774 csum_partial(na
, sizeof(*na
)+na_olen
, 0));
1776 pip6
->payload_len
= htons(sizeof(*na
)+na_olen
);
1778 skb_push(reply
, sizeof(struct ipv6hdr
));
1780 reply
->ip_summed
= CHECKSUM_UNNECESSARY
;
1785 static int neigh_reduce(struct net_device
*dev
, struct sk_buff
*skb
, __be32 vni
)
1787 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1788 const struct in6_addr
*daddr
;
1789 const struct ipv6hdr
*iphdr
;
1790 struct inet6_dev
*in6_dev
;
1791 struct neighbour
*n
;
1794 in6_dev
= __in6_dev_get(dev
);
1798 iphdr
= ipv6_hdr(skb
);
1799 daddr
= &iphdr
->daddr
;
1800 msg
= (struct nd_msg
*)(iphdr
+ 1);
1802 if (ipv6_addr_loopback(daddr
) ||
1803 ipv6_addr_is_multicast(&msg
->target
))
1806 n
= neigh_lookup(ipv6_stub
->nd_tbl
, &msg
->target
, dev
);
1809 struct vxlan_fdb
*f
;
1810 struct sk_buff
*reply
;
1812 if (!(n
->nud_state
& NUD_CONNECTED
)) {
1817 f
= vxlan_find_mac(vxlan
, n
->ha
, vni
);
1818 if (f
&& vxlan_addr_any(&(first_remote_rcu(f
)->remote_ip
))) {
1819 /* bridge-local neighbor */
1824 reply
= vxlan_na_create(skb
, n
,
1825 !!(f
? f
->flags
& NTF_ROUTER
: 0));
1832 if (netif_rx_ni(reply
) == NET_RX_DROP
)
1833 dev
->stats
.rx_dropped
++;
1835 } else if (vxlan
->cfg
.flags
& VXLAN_F_L3MISS
) {
1836 union vxlan_addr ipa
= {
1837 .sin6
.sin6_addr
= msg
->target
,
1838 .sin6
.sin6_family
= AF_INET6
,
1841 vxlan_ip_miss(dev
, &ipa
);
1846 return NETDEV_TX_OK
;
1850 static bool route_shortcircuit(struct net_device
*dev
, struct sk_buff
*skb
)
1852 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
1853 struct neighbour
*n
;
1855 if (is_multicast_ether_addr(eth_hdr(skb
)->h_dest
))
1859 switch (ntohs(eth_hdr(skb
)->h_proto
)) {
1864 if (!pskb_may_pull(skb
, sizeof(struct iphdr
)))
1867 n
= neigh_lookup(&arp_tbl
, &pip
->daddr
, dev
);
1868 if (!n
&& (vxlan
->cfg
.flags
& VXLAN_F_L3MISS
)) {
1869 union vxlan_addr ipa
= {
1870 .sin
.sin_addr
.s_addr
= pip
->daddr
,
1871 .sin
.sin_family
= AF_INET
,
1874 vxlan_ip_miss(dev
, &ipa
);
1880 #if IS_ENABLED(CONFIG_IPV6)
1883 struct ipv6hdr
*pip6
;
1885 if (!pskb_may_pull(skb
, sizeof(struct ipv6hdr
)))
1887 pip6
= ipv6_hdr(skb
);
1888 n
= neigh_lookup(ipv6_stub
->nd_tbl
, &pip6
->daddr
, dev
);
1889 if (!n
&& (vxlan
->cfg
.flags
& VXLAN_F_L3MISS
)) {
1890 union vxlan_addr ipa
= {
1891 .sin6
.sin6_addr
= pip6
->daddr
,
1892 .sin6
.sin6_family
= AF_INET6
,
1895 vxlan_ip_miss(dev
, &ipa
);
1909 diff
= !ether_addr_equal(eth_hdr(skb
)->h_dest
, n
->ha
);
1911 memcpy(eth_hdr(skb
)->h_source
, eth_hdr(skb
)->h_dest
,
1913 memcpy(eth_hdr(skb
)->h_dest
, n
->ha
, dev
->addr_len
);
1922 static void vxlan_build_gbp_hdr(struct vxlanhdr
*vxh
, u32 vxflags
,
1923 struct vxlan_metadata
*md
)
1925 struct vxlanhdr_gbp
*gbp
;
1930 gbp
= (struct vxlanhdr_gbp
*)vxh
;
1931 vxh
->vx_flags
|= VXLAN_HF_GBP
;
1933 if (md
->gbp
& VXLAN_GBP_DONT_LEARN
)
1934 gbp
->dont_learn
= 1;
1936 if (md
->gbp
& VXLAN_GBP_POLICY_APPLIED
)
1937 gbp
->policy_applied
= 1;
1939 gbp
->policy_id
= htons(md
->gbp
& VXLAN_GBP_ID_MASK
);
1942 static int vxlan_build_gpe_hdr(struct vxlanhdr
*vxh
, u32 vxflags
,
1945 struct vxlanhdr_gpe
*gpe
= (struct vxlanhdr_gpe
*)vxh
;
1947 gpe
->np_applied
= 1;
1948 gpe
->next_protocol
= tun_p_from_eth_p(protocol
);
1949 if (!gpe
->next_protocol
)
1950 return -EPFNOSUPPORT
;
1954 static int vxlan_build_skb(struct sk_buff
*skb
, struct dst_entry
*dst
,
1955 int iphdr_len
, __be32 vni
,
1956 struct vxlan_metadata
*md
, u32 vxflags
,
1959 struct vxlanhdr
*vxh
;
1962 int type
= udp_sum
? SKB_GSO_UDP_TUNNEL_CSUM
: SKB_GSO_UDP_TUNNEL
;
1963 __be16 inner_protocol
= htons(ETH_P_TEB
);
1965 if ((vxflags
& VXLAN_F_REMCSUM_TX
) &&
1966 skb
->ip_summed
== CHECKSUM_PARTIAL
) {
1967 int csum_start
= skb_checksum_start_offset(skb
);
1969 if (csum_start
<= VXLAN_MAX_REMCSUM_START
&&
1970 !(csum_start
& VXLAN_RCO_SHIFT_MASK
) &&
1971 (skb
->csum_offset
== offsetof(struct udphdr
, check
) ||
1972 skb
->csum_offset
== offsetof(struct tcphdr
, check
)))
1973 type
|= SKB_GSO_TUNNEL_REMCSUM
;
1976 min_headroom
= LL_RESERVED_SPACE(dst
->dev
) + dst
->header_len
1977 + VXLAN_HLEN
+ iphdr_len
;
1979 /* Need space for new headers (invalidates iph ptr) */
1980 err
= skb_cow_head(skb
, min_headroom
);
1984 err
= iptunnel_handle_offloads(skb
, type
);
1988 vxh
= __skb_push(skb
, sizeof(*vxh
));
1989 vxh
->vx_flags
= VXLAN_HF_VNI
;
1990 vxh
->vx_vni
= vxlan_vni_field(vni
);
1992 if (type
& SKB_GSO_TUNNEL_REMCSUM
) {
1995 start
= skb_checksum_start_offset(skb
) - sizeof(struct vxlanhdr
);
1996 vxh
->vx_vni
|= vxlan_compute_rco(start
, skb
->csum_offset
);
1997 vxh
->vx_flags
|= VXLAN_HF_RCO
;
1999 if (!skb_is_gso(skb
)) {
2000 skb
->ip_summed
= CHECKSUM_NONE
;
2001 skb
->encapsulation
= 0;
2005 if (vxflags
& VXLAN_F_GBP
)
2006 vxlan_build_gbp_hdr(vxh
, vxflags
, md
);
2007 if (vxflags
& VXLAN_F_GPE
) {
2008 err
= vxlan_build_gpe_hdr(vxh
, vxflags
, skb
->protocol
);
2011 inner_protocol
= skb
->protocol
;
2014 skb_set_inner_protocol(skb
, inner_protocol
);
2018 static struct rtable
*vxlan_get_route(struct vxlan_dev
*vxlan
, struct net_device
*dev
,
2019 struct vxlan_sock
*sock4
,
2020 struct sk_buff
*skb
, int oif
, u8 tos
,
2021 __be32 daddr
, __be32
*saddr
, __be16 dport
, __be16 sport
,
2022 struct dst_cache
*dst_cache
,
2023 const struct ip_tunnel_info
*info
)
2025 bool use_cache
= ip_tunnel_dst_cache_usable(skb
, info
);
2026 struct rtable
*rt
= NULL
;
2030 return ERR_PTR(-EIO
);
2035 rt
= dst_cache_get_ip4(dst_cache
, saddr
);
2040 memset(&fl4
, 0, sizeof(fl4
));
2041 fl4
.flowi4_oif
= oif
;
2042 fl4
.flowi4_tos
= RT_TOS(tos
);
2043 fl4
.flowi4_mark
= skb
->mark
;
2044 fl4
.flowi4_proto
= IPPROTO_UDP
;
2047 fl4
.fl4_dport
= dport
;
2048 fl4
.fl4_sport
= sport
;
2050 rt
= ip_route_output_key(vxlan
->net
, &fl4
);
2051 if (likely(!IS_ERR(rt
))) {
2052 if (rt
->dst
.dev
== dev
) {
2053 netdev_dbg(dev
, "circular route to %pI4\n", &daddr
);
2055 return ERR_PTR(-ELOOP
);
2060 dst_cache_set_ip4(dst_cache
, &rt
->dst
, fl4
.saddr
);
2062 netdev_dbg(dev
, "no route to %pI4\n", &daddr
);
2063 return ERR_PTR(-ENETUNREACH
);
2068 #if IS_ENABLED(CONFIG_IPV6)
2069 static struct dst_entry
*vxlan6_get_route(struct vxlan_dev
*vxlan
,
2070 struct net_device
*dev
,
2071 struct vxlan_sock
*sock6
,
2072 struct sk_buff
*skb
, int oif
, u8 tos
,
2074 const struct in6_addr
*daddr
,
2075 struct in6_addr
*saddr
,
2076 __be16 dport
, __be16 sport
,
2077 struct dst_cache
*dst_cache
,
2078 const struct ip_tunnel_info
*info
)
2080 bool use_cache
= ip_tunnel_dst_cache_usable(skb
, info
);
2081 struct dst_entry
*ndst
;
2086 return ERR_PTR(-EIO
);
2091 ndst
= dst_cache_get_ip6(dst_cache
, saddr
);
2096 memset(&fl6
, 0, sizeof(fl6
));
2097 fl6
.flowi6_oif
= oif
;
2100 fl6
.flowlabel
= ip6_make_flowinfo(RT_TOS(tos
), label
);
2101 fl6
.flowi6_mark
= skb
->mark
;
2102 fl6
.flowi6_proto
= IPPROTO_UDP
;
2103 fl6
.fl6_dport
= dport
;
2104 fl6
.fl6_sport
= sport
;
2106 err
= ipv6_stub
->ipv6_dst_lookup(vxlan
->net
,
2109 if (unlikely(err
< 0)) {
2110 netdev_dbg(dev
, "no route to %pI6\n", daddr
);
2111 return ERR_PTR(-ENETUNREACH
);
2114 if (unlikely(ndst
->dev
== dev
)) {
2115 netdev_dbg(dev
, "circular route to %pI6\n", daddr
);
2117 return ERR_PTR(-ELOOP
);
2122 dst_cache_set_ip6(dst_cache
, ndst
, saddr
);
2127 /* Bypass encapsulation if the destination is local */
2128 static void vxlan_encap_bypass(struct sk_buff
*skb
, struct vxlan_dev
*src_vxlan
,
2129 struct vxlan_dev
*dst_vxlan
, __be32 vni
)
2131 struct pcpu_sw_netstats
*tx_stats
, *rx_stats
;
2132 union vxlan_addr loopback
;
2133 union vxlan_addr
*remote_ip
= &dst_vxlan
->default_dst
.remote_ip
;
2134 struct net_device
*dev
= skb
->dev
;
2137 tx_stats
= this_cpu_ptr(src_vxlan
->dev
->tstats
);
2138 rx_stats
= this_cpu_ptr(dst_vxlan
->dev
->tstats
);
2139 skb
->pkt_type
= PACKET_HOST
;
2140 skb
->encapsulation
= 0;
2141 skb
->dev
= dst_vxlan
->dev
;
2142 __skb_pull(skb
, skb_network_offset(skb
));
2144 if (remote_ip
->sa
.sa_family
== AF_INET
) {
2145 loopback
.sin
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
2146 loopback
.sa
.sa_family
= AF_INET
;
2147 #if IS_ENABLED(CONFIG_IPV6)
2149 loopback
.sin6
.sin6_addr
= in6addr_loopback
;
2150 loopback
.sa
.sa_family
= AF_INET6
;
2154 if (dst_vxlan
->cfg
.flags
& VXLAN_F_LEARN
)
2155 vxlan_snoop(skb
->dev
, &loopback
, eth_hdr(skb
)->h_source
, 0,
2158 u64_stats_update_begin(&tx_stats
->syncp
);
2159 tx_stats
->tx_packets
++;
2160 tx_stats
->tx_bytes
+= len
;
2161 u64_stats_update_end(&tx_stats
->syncp
);
2163 if (netif_rx(skb
) == NET_RX_SUCCESS
) {
2164 u64_stats_update_begin(&rx_stats
->syncp
);
2165 rx_stats
->rx_packets
++;
2166 rx_stats
->rx_bytes
+= len
;
2167 u64_stats_update_end(&rx_stats
->syncp
);
2169 dev
->stats
.rx_dropped
++;
2173 static int encap_bypass_if_local(struct sk_buff
*skb
, struct net_device
*dev
,
2174 struct vxlan_dev
*vxlan
,
2175 union vxlan_addr
*daddr
,
2176 __be16 dst_port
, int dst_ifindex
, __be32 vni
,
2177 struct dst_entry
*dst
,
2180 #if IS_ENABLED(CONFIG_IPV6)
2181 /* IPv6 rt-flags are checked against RTF_LOCAL, but the value of
2182 * RTF_LOCAL is equal to RTCF_LOCAL. So to keep code simple
2183 * we can use RTCF_LOCAL which works for ipv4 and ipv6 route entry.
2185 BUILD_BUG_ON(RTCF_LOCAL
!= RTF_LOCAL
);
2187 /* Bypass encapsulation if the destination is local */
2188 if (rt_flags
& RTCF_LOCAL
&&
2189 !(rt_flags
& (RTCF_BROADCAST
| RTCF_MULTICAST
))) {
2190 struct vxlan_dev
*dst_vxlan
;
2193 dst_vxlan
= vxlan_find_vni(vxlan
->net
, dst_ifindex
, vni
,
2194 daddr
->sa
.sa_family
, dst_port
,
2197 dev
->stats
.tx_errors
++;
2202 vxlan_encap_bypass(skb
, vxlan
, dst_vxlan
, vni
);
2209 static void vxlan_xmit_one(struct sk_buff
*skb
, struct net_device
*dev
,
2210 __be32 default_vni
, struct vxlan_rdst
*rdst
,
2213 struct dst_cache
*dst_cache
;
2214 struct ip_tunnel_info
*info
;
2215 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2216 const struct iphdr
*old_iph
= ip_hdr(skb
);
2217 union vxlan_addr
*dst
;
2218 union vxlan_addr remote_ip
, local_ip
;
2219 struct vxlan_metadata _md
;
2220 struct vxlan_metadata
*md
= &_md
;
2221 __be16 src_port
= 0, dst_port
;
2222 struct dst_entry
*ndst
= NULL
;
2227 u32 flags
= vxlan
->cfg
.flags
;
2228 bool udp_sum
= false;
2229 bool xnet
= !net_eq(vxlan
->net
, dev_net(vxlan
->dev
));
2231 info
= skb_tunnel_info(skb
);
2234 dst
= &rdst
->remote_ip
;
2235 if (vxlan_addr_any(dst
)) {
2237 /* short-circuited back to local bridge */
2238 vxlan_encap_bypass(skb
, vxlan
, vxlan
, default_vni
);
2244 dst_port
= rdst
->remote_port
? rdst
->remote_port
: vxlan
->cfg
.dst_port
;
2245 vni
= (rdst
->remote_vni
) ? : default_vni
;
2246 ifindex
= rdst
->remote_ifindex
;
2247 local_ip
= vxlan
->cfg
.saddr
;
2248 dst_cache
= &rdst
->dst_cache
;
2249 md
->gbp
= skb
->mark
;
2250 ttl
= vxlan
->cfg
.ttl
;
2251 if (!ttl
&& vxlan_addr_multicast(dst
))
2254 tos
= vxlan
->cfg
.tos
;
2256 tos
= ip_tunnel_get_dsfield(old_iph
, skb
);
2258 if (dst
->sa
.sa_family
== AF_INET
)
2259 udp_sum
= !(flags
& VXLAN_F_UDP_ZERO_CSUM_TX
);
2261 udp_sum
= !(flags
& VXLAN_F_UDP_ZERO_CSUM6_TX
);
2262 label
= vxlan
->cfg
.label
;
2265 WARN_ONCE(1, "%s: Missing encapsulation instructions\n",
2269 remote_ip
.sa
.sa_family
= ip_tunnel_info_af(info
);
2270 if (remote_ip
.sa
.sa_family
== AF_INET
) {
2271 remote_ip
.sin
.sin_addr
.s_addr
= info
->key
.u
.ipv4
.dst
;
2272 local_ip
.sin
.sin_addr
.s_addr
= info
->key
.u
.ipv4
.src
;
2274 remote_ip
.sin6
.sin6_addr
= info
->key
.u
.ipv6
.dst
;
2275 local_ip
.sin6
.sin6_addr
= info
->key
.u
.ipv6
.src
;
2278 dst_port
= info
->key
.tp_dst
? : vxlan
->cfg
.dst_port
;
2279 vni
= tunnel_id_to_key32(info
->key
.tun_id
);
2281 dst_cache
= &info
->dst_cache
;
2282 if (info
->options_len
)
2283 md
= ip_tunnel_info_opts(info
);
2284 ttl
= info
->key
.ttl
;
2285 tos
= info
->key
.tos
;
2286 label
= info
->key
.label
;
2287 udp_sum
= !!(info
->key
.tun_flags
& TUNNEL_CSUM
);
2289 src_port
= udp_flow_src_port(dev_net(dev
), skb
, vxlan
->cfg
.port_min
,
2290 vxlan
->cfg
.port_max
, true);
2293 if (dst
->sa
.sa_family
== AF_INET
) {
2294 struct vxlan_sock
*sock4
= rcu_dereference(vxlan
->vn4_sock
);
2298 rt
= vxlan_get_route(vxlan
, dev
, sock4
, skb
, ifindex
, tos
,
2299 dst
->sin
.sin_addr
.s_addr
,
2300 &local_ip
.sin
.sin_addr
.s_addr
,
2308 if (fan_has_map(&vxlan
->fan
) && rt
->rt_flags
& RTCF_LOCAL
) {
2309 netdev_dbg(dev
, "discard fan to localhost %pI4\n",
2310 &dst
->sin
.sin_addr
.s_addr
);
2315 /* Bypass encapsulation if the destination is local */
2317 err
= encap_bypass_if_local(skb
, dev
, vxlan
, dst
,
2318 dst_port
, ifindex
, vni
,
2319 &rt
->dst
, rt
->rt_flags
);
2322 } else if (info
->key
.tun_flags
& TUNNEL_DONT_FRAGMENT
) {
2328 int mtu
= dst_mtu(ndst
) - VXLAN_HEADROOM
;
2330 skb_dst_update_pmtu(skb
, mtu
);
2333 tos
= ip_tunnel_ecn_encap(tos
, old_iph
, skb
);
2334 ttl
= ttl
? : ip4_dst_hoplimit(&rt
->dst
);
2335 err
= vxlan_build_skb(skb
, ndst
, sizeof(struct iphdr
),
2336 vni
, md
, flags
, udp_sum
);
2340 udp_tunnel_xmit_skb(rt
, sock4
->sock
->sk
, skb
, local_ip
.sin
.sin_addr
.s_addr
,
2341 dst
->sin
.sin_addr
.s_addr
, tos
, ttl
, df
,
2342 src_port
, dst_port
, xnet
, !udp_sum
);
2343 #if IS_ENABLED(CONFIG_IPV6)
2345 struct vxlan_sock
*sock6
= rcu_dereference(vxlan
->vn6_sock
);
2347 ndst
= vxlan6_get_route(vxlan
, dev
, sock6
, skb
, ifindex
, tos
,
2348 label
, &dst
->sin6
.sin6_addr
,
2349 &local_ip
.sin6
.sin6_addr
,
2353 err
= PTR_ERR(ndst
);
2359 u32 rt6i_flags
= ((struct rt6_info
*)ndst
)->rt6i_flags
;
2361 err
= encap_bypass_if_local(skb
, dev
, vxlan
, dst
,
2362 dst_port
, ifindex
, vni
,
2369 int mtu
= dst_mtu(ndst
) - VXLAN6_HEADROOM
;
2371 skb_dst_update_pmtu(skb
, mtu
);
2374 tos
= ip_tunnel_ecn_encap(tos
, old_iph
, skb
);
2375 ttl
= ttl
? : ip6_dst_hoplimit(ndst
);
2376 skb_scrub_packet(skb
, xnet
);
2377 err
= vxlan_build_skb(skb
, ndst
, sizeof(struct ipv6hdr
),
2378 vni
, md
, flags
, udp_sum
);
2382 udp_tunnel6_xmit_skb(ndst
, sock6
->sock
->sk
, skb
, dev
,
2383 &local_ip
.sin6
.sin6_addr
,
2384 &dst
->sin6
.sin6_addr
, tos
, ttl
,
2385 label
, src_port
, dst_port
, !udp_sum
);
2393 dev
->stats
.tx_dropped
++;
2400 dev
->stats
.collisions
++;
2401 else if (err
== -ENETUNREACH
)
2402 dev
->stats
.tx_carrier_errors
++;
2404 dev
->stats
.tx_errors
++;
2409 /* Transmit local packets over Vxlan
2411 * Outer IP header inherits ECN and DF from inner header.
2412 * Outer UDP destination is the VXLAN assigned port.
2413 * source port is based on hash of flow
2415 static netdev_tx_t
vxlan_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
2417 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2418 struct vxlan_rdst
*rdst
, *fdst
= NULL
;
2419 const struct ip_tunnel_info
*info
;
2420 bool did_rsc
= false;
2421 struct vxlan_fdb
*f
;
2425 info
= skb_tunnel_info(skb
);
2427 skb_reset_mac_header(skb
);
2429 if (vxlan
->cfg
.flags
& VXLAN_F_COLLECT_METADATA
) {
2430 if (info
&& info
->mode
& IP_TUNNEL_INFO_BRIDGE
&&
2431 info
->mode
& IP_TUNNEL_INFO_TX
) {
2432 vni
= tunnel_id_to_key32(info
->key
.tun_id
);
2434 if (info
&& info
->mode
& IP_TUNNEL_INFO_TX
)
2435 vxlan_xmit_one(skb
, dev
, vni
, NULL
, false);
2438 return NETDEV_TX_OK
;
2442 if (vxlan
->cfg
.flags
& VXLAN_F_PROXY
) {
2444 if (ntohs(eth
->h_proto
) == ETH_P_ARP
)
2445 return arp_reduce(dev
, skb
, vni
);
2446 #if IS_ENABLED(CONFIG_IPV6)
2447 else if (ntohs(eth
->h_proto
) == ETH_P_IPV6
&&
2448 pskb_may_pull(skb
, sizeof(struct ipv6hdr
) +
2449 sizeof(struct nd_msg
)) &&
2450 ipv6_hdr(skb
)->nexthdr
== IPPROTO_ICMPV6
) {
2451 struct nd_msg
*m
= (struct nd_msg
*)(ipv6_hdr(skb
) + 1);
2453 if (m
->icmph
.icmp6_code
== 0 &&
2454 m
->icmph
.icmp6_type
== NDISC_NEIGHBOUR_SOLICITATION
)
2455 return neigh_reduce(dev
, skb
, vni
);
2460 if (fan_has_map(&vxlan
->fan
)) {
2461 struct vxlan_rdst fan_rdst
;
2463 netdev_dbg(vxlan
->dev
, "vxlan_xmit p %x d %pM\n",
2464 eth
->h_proto
, eth
->h_dest
);
2465 if (vxlan_fan_build_rdst(vxlan
, skb
, &fan_rdst
)) {
2466 dev
->stats
.tx_dropped
++;
2468 return NETDEV_TX_OK
;
2470 vxlan_xmit_one(skb
, dev
, vni
, &fan_rdst
, 0);
2471 return NETDEV_TX_OK
;
2475 f
= vxlan_find_mac(vxlan
, eth
->h_dest
, vni
);
2478 if (f
&& (f
->flags
& NTF_ROUTER
) && (vxlan
->cfg
.flags
& VXLAN_F_RSC
) &&
2479 (ntohs(eth
->h_proto
) == ETH_P_IP
||
2480 ntohs(eth
->h_proto
) == ETH_P_IPV6
)) {
2481 did_rsc
= route_shortcircuit(dev
, skb
);
2483 f
= vxlan_find_mac(vxlan
, eth
->h_dest
, vni
);
2487 f
= vxlan_find_mac(vxlan
, all_zeros_mac
, vni
);
2489 if ((vxlan
->cfg
.flags
& VXLAN_F_L2MISS
) &&
2490 !is_multicast_ether_addr(eth
->h_dest
))
2491 vxlan_fdb_miss(vxlan
, eth
->h_dest
);
2493 dev
->stats
.tx_dropped
++;
2495 return NETDEV_TX_OK
;
2499 list_for_each_entry_rcu(rdst
, &f
->remotes
, list
) {
2500 struct sk_buff
*skb1
;
2506 skb1
= skb_clone(skb
, GFP_ATOMIC
);
2508 vxlan_xmit_one(skb1
, dev
, vni
, rdst
, did_rsc
);
2512 vxlan_xmit_one(skb
, dev
, vni
, fdst
, did_rsc
);
2515 return NETDEV_TX_OK
;
2518 /* Walk the forwarding table and purge stale entries */
2519 static void vxlan_cleanup(struct timer_list
*t
)
2521 struct vxlan_dev
*vxlan
= from_timer(vxlan
, t
, age_timer
);
2522 unsigned long next_timer
= jiffies
+ FDB_AGE_INTERVAL
;
2525 if (!netif_running(vxlan
->dev
))
2528 for (h
= 0; h
< FDB_HASH_SIZE
; ++h
) {
2529 struct hlist_node
*p
, *n
;
2531 spin_lock_bh(&vxlan
->hash_lock
);
2532 hlist_for_each_safe(p
, n
, &vxlan
->fdb_head
[h
]) {
2534 = container_of(p
, struct vxlan_fdb
, hlist
);
2535 unsigned long timeout
;
2537 if (f
->state
& (NUD_PERMANENT
| NUD_NOARP
))
2540 if (f
->flags
& NTF_EXT_LEARNED
)
2543 timeout
= f
->used
+ vxlan
->cfg
.age_interval
* HZ
;
2544 if (time_before_eq(timeout
, jiffies
)) {
2545 netdev_dbg(vxlan
->dev
,
2546 "garbage collect %pM\n",
2548 f
->state
= NUD_STALE
;
2549 vxlan_fdb_destroy(vxlan
, f
);
2550 } else if (time_before(timeout
, next_timer
))
2551 next_timer
= timeout
;
2553 spin_unlock_bh(&vxlan
->hash_lock
);
2556 mod_timer(&vxlan
->age_timer
, next_timer
);
2559 static void vxlan_vs_del_dev(struct vxlan_dev
*vxlan
)
2561 struct vxlan_net
*vn
= net_generic(vxlan
->net
, vxlan_net_id
);
2563 spin_lock(&vn
->sock_lock
);
2564 hlist_del_init_rcu(&vxlan
->hlist4
.hlist
);
2565 #if IS_ENABLED(CONFIG_IPV6)
2566 hlist_del_init_rcu(&vxlan
->hlist6
.hlist
);
2568 spin_unlock(&vn
->sock_lock
);
2571 static void vxlan_vs_add_dev(struct vxlan_sock
*vs
, struct vxlan_dev
*vxlan
,
2572 struct vxlan_dev_node
*node
)
2574 struct vxlan_net
*vn
= net_generic(vxlan
->net
, vxlan_net_id
);
2575 __be32 vni
= vxlan
->default_dst
.remote_vni
;
2577 node
->vxlan
= vxlan
;
2578 spin_lock(&vn
->sock_lock
);
2579 hlist_add_head_rcu(&node
->hlist
, vni_head(vs
, vni
));
2580 spin_unlock(&vn
->sock_lock
);
2583 /* Setup stats when device is created */
2584 static int vxlan_init(struct net_device
*dev
)
2586 dev
->tstats
= netdev_alloc_pcpu_stats(struct pcpu_sw_netstats
);
2593 static void vxlan_fdb_delete_default(struct vxlan_dev
*vxlan
, __be32 vni
)
2595 struct vxlan_fdb
*f
;
2597 spin_lock_bh(&vxlan
->hash_lock
);
2598 f
= __vxlan_find_mac(vxlan
, all_zeros_mac
, vni
);
2600 vxlan_fdb_destroy(vxlan
, f
);
2601 spin_unlock_bh(&vxlan
->hash_lock
);
2604 static void vxlan_uninit(struct net_device
*dev
)
2606 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2608 vxlan_fdb_delete_default(vxlan
, vxlan
->cfg
.vni
);
2610 free_percpu(dev
->tstats
);
2613 /* Start ageing timer and join group when device is brought up */
2614 static int vxlan_open(struct net_device
*dev
)
2616 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2619 ret
= vxlan_sock_add(vxlan
);
2623 if (vxlan_addr_multicast(&vxlan
->default_dst
.remote_ip
)) {
2624 ret
= vxlan_igmp_join(vxlan
);
2625 if (ret
== -EADDRINUSE
)
2628 vxlan_sock_release(vxlan
);
2633 if (vxlan
->cfg
.age_interval
)
2634 mod_timer(&vxlan
->age_timer
, jiffies
+ FDB_AGE_INTERVAL
);
2639 /* Purge the forwarding table */
2640 static void vxlan_flush(struct vxlan_dev
*vxlan
, bool do_all
)
2644 spin_lock_bh(&vxlan
->hash_lock
);
2645 for (h
= 0; h
< FDB_HASH_SIZE
; ++h
) {
2646 struct hlist_node
*p
, *n
;
2647 hlist_for_each_safe(p
, n
, &vxlan
->fdb_head
[h
]) {
2649 = container_of(p
, struct vxlan_fdb
, hlist
);
2650 if (!do_all
&& (f
->state
& (NUD_PERMANENT
| NUD_NOARP
)))
2652 /* the all_zeros_mac entry is deleted at vxlan_uninit */
2653 if (!is_zero_ether_addr(f
->eth_addr
))
2654 vxlan_fdb_destroy(vxlan
, f
);
2657 spin_unlock_bh(&vxlan
->hash_lock
);
2660 /* Cleanup timer and forwarding table on shutdown */
2661 static int vxlan_stop(struct net_device
*dev
)
2663 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2664 struct vxlan_net
*vn
= net_generic(vxlan
->net
, vxlan_net_id
);
2667 if (vxlan_addr_multicast(&vxlan
->default_dst
.remote_ip
) &&
2668 !vxlan_group_used(vn
, vxlan
))
2669 ret
= vxlan_igmp_leave(vxlan
);
2671 del_timer_sync(&vxlan
->age_timer
);
2673 vxlan_flush(vxlan
, false);
2674 vxlan_sock_release(vxlan
);
2679 /* Stub, nothing needs to be done. */
2680 static void vxlan_set_multicast_list(struct net_device
*dev
)
2684 static int vxlan_change_mtu(struct net_device
*dev
, int new_mtu
)
2686 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2687 struct vxlan_rdst
*dst
= &vxlan
->default_dst
;
2688 struct net_device
*lowerdev
= __dev_get_by_index(vxlan
->net
,
2689 dst
->remote_ifindex
);
2690 bool use_ipv6
= !!(vxlan
->cfg
.flags
& VXLAN_F_IPV6
);
2692 /* This check is different than dev->max_mtu, because it looks at
2693 * the lowerdev->mtu, rather than the static dev->max_mtu
2696 int max_mtu
= lowerdev
->mtu
-
2697 (use_ipv6
? VXLAN6_HEADROOM
: VXLAN_HEADROOM
);
2698 if (new_mtu
> max_mtu
)
2706 static int vxlan_fill_metadata_dst(struct net_device
*dev
, struct sk_buff
*skb
)
2708 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2709 struct ip_tunnel_info
*info
= skb_tunnel_info(skb
);
2710 __be16 sport
, dport
;
2712 sport
= udp_flow_src_port(dev_net(dev
), skb
, vxlan
->cfg
.port_min
,
2713 vxlan
->cfg
.port_max
, true);
2714 dport
= info
->key
.tp_dst
? : vxlan
->cfg
.dst_port
;
2716 if (ip_tunnel_info_af(info
) == AF_INET
) {
2717 struct vxlan_sock
*sock4
= rcu_dereference(vxlan
->vn4_sock
);
2720 rt
= vxlan_get_route(vxlan
, dev
, sock4
, skb
, 0, info
->key
.tos
,
2721 info
->key
.u
.ipv4
.dst
,
2722 &info
->key
.u
.ipv4
.src
, dport
, sport
,
2723 &info
->dst_cache
, info
);
2728 #if IS_ENABLED(CONFIG_IPV6)
2729 struct vxlan_sock
*sock6
= rcu_dereference(vxlan
->vn6_sock
);
2730 struct dst_entry
*ndst
;
2732 ndst
= vxlan6_get_route(vxlan
, dev
, sock6
, skb
, 0, info
->key
.tos
,
2733 info
->key
.label
, &info
->key
.u
.ipv6
.dst
,
2734 &info
->key
.u
.ipv6
.src
, dport
, sport
,
2735 &info
->dst_cache
, info
);
2737 return PTR_ERR(ndst
);
2739 #else /* !CONFIG_IPV6 */
2740 return -EPFNOSUPPORT
;
2743 info
->key
.tp_src
= sport
;
2744 info
->key
.tp_dst
= dport
;
2748 static const struct net_device_ops vxlan_netdev_ether_ops
= {
2749 .ndo_init
= vxlan_init
,
2750 .ndo_uninit
= vxlan_uninit
,
2751 .ndo_open
= vxlan_open
,
2752 .ndo_stop
= vxlan_stop
,
2753 .ndo_start_xmit
= vxlan_xmit
,
2754 .ndo_get_stats64
= ip_tunnel_get_stats64
,
2755 .ndo_set_rx_mode
= vxlan_set_multicast_list
,
2756 .ndo_change_mtu
= vxlan_change_mtu
,
2757 .ndo_validate_addr
= eth_validate_addr
,
2758 .ndo_set_mac_address
= eth_mac_addr
,
2759 .ndo_fdb_add
= vxlan_fdb_add
,
2760 .ndo_fdb_del
= vxlan_fdb_delete
,
2761 .ndo_fdb_dump
= vxlan_fdb_dump
,
2762 .ndo_fill_metadata_dst
= vxlan_fill_metadata_dst
,
2765 static const struct net_device_ops vxlan_netdev_raw_ops
= {
2766 .ndo_init
= vxlan_init
,
2767 .ndo_uninit
= vxlan_uninit
,
2768 .ndo_open
= vxlan_open
,
2769 .ndo_stop
= vxlan_stop
,
2770 .ndo_start_xmit
= vxlan_xmit
,
2771 .ndo_get_stats64
= ip_tunnel_get_stats64
,
2772 .ndo_change_mtu
= vxlan_change_mtu
,
2773 .ndo_fill_metadata_dst
= vxlan_fill_metadata_dst
,
2776 /* Info for udev, that this is a virtual tunnel endpoint */
2777 static struct device_type vxlan_type
= {
2781 /* Calls the ndo_udp_tunnel_add of the caller in order to
2782 * supply the listening VXLAN udp ports. Callers are expected
2783 * to implement the ndo_udp_tunnel_add.
2785 static void vxlan_offload_rx_ports(struct net_device
*dev
, bool push
)
2787 struct vxlan_sock
*vs
;
2788 struct net
*net
= dev_net(dev
);
2789 struct vxlan_net
*vn
= net_generic(net
, vxlan_net_id
);
2792 spin_lock(&vn
->sock_lock
);
2793 for (i
= 0; i
< PORT_HASH_SIZE
; ++i
) {
2794 hlist_for_each_entry_rcu(vs
, &vn
->sock_list
[i
], hlist
) {
2795 unsigned short type
;
2797 if (vs
->flags
& VXLAN_F_GPE
)
2798 type
= UDP_TUNNEL_TYPE_VXLAN_GPE
;
2800 type
= UDP_TUNNEL_TYPE_VXLAN
;
2803 udp_tunnel_push_rx_port(dev
, vs
->sock
, type
);
2805 udp_tunnel_drop_rx_port(dev
, vs
->sock
, type
);
2808 spin_unlock(&vn
->sock_lock
);
2811 /* Initialize the device structure. */
2812 static void vxlan_setup(struct net_device
*dev
)
2814 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
2817 eth_hw_addr_random(dev
);
2820 dev
->needs_free_netdev
= true;
2821 SET_NETDEV_DEVTYPE(dev
, &vxlan_type
);
2823 dev
->features
|= NETIF_F_LLTX
;
2824 dev
->features
|= NETIF_F_SG
| NETIF_F_HW_CSUM
;
2825 dev
->features
|= NETIF_F_RXCSUM
;
2826 dev
->features
|= NETIF_F_GSO_SOFTWARE
;
2828 dev
->vlan_features
= dev
->features
;
2829 dev
->hw_features
|= NETIF_F_SG
| NETIF_F_HW_CSUM
| NETIF_F_RXCSUM
;
2830 dev
->hw_features
|= NETIF_F_GSO_SOFTWARE
;
2831 netif_keep_dst(dev
);
2832 dev
->priv_flags
|= IFF_NO_QUEUE
;
2834 /* MTU range: 68 - 65535 */
2835 dev
->min_mtu
= ETH_MIN_MTU
;
2836 dev
->max_mtu
= ETH_MAX_MTU
;
2838 INIT_LIST_HEAD(&vxlan
->next
);
2839 spin_lock_init(&vxlan
->hash_lock
);
2841 timer_setup(&vxlan
->age_timer
, vxlan_cleanup
, TIMER_DEFERRABLE
);
2845 gro_cells_init(&vxlan
->gro_cells
, dev
);
2847 for (h
= 0; h
< FDB_HASH_SIZE
; ++h
)
2848 INIT_HLIST_HEAD(&vxlan
->fdb_head
[h
]);
2850 INIT_LIST_HEAD(&vxlan
->fan
.fan_maps
);
2853 static void vxlan_ether_setup(struct net_device
*dev
)
2855 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
2856 dev
->priv_flags
|= IFF_LIVE_ADDR_CHANGE
;
2857 dev
->netdev_ops
= &vxlan_netdev_ether_ops
;
2860 static void vxlan_raw_setup(struct net_device
*dev
)
2862 dev
->header_ops
= NULL
;
2863 dev
->type
= ARPHRD_NONE
;
2864 dev
->hard_header_len
= 0;
2866 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
| IFF_MULTICAST
;
2867 dev
->netdev_ops
= &vxlan_netdev_raw_ops
;
2870 static const struct nla_policy vxlan_policy
[IFLA_VXLAN_MAX
+ 1] = {
2871 [IFLA_VXLAN_ID
] = { .type
= NLA_U32
},
2872 [IFLA_VXLAN_GROUP
] = { .len
= FIELD_SIZEOF(struct iphdr
, daddr
) },
2873 [IFLA_VXLAN_GROUP6
] = { .len
= sizeof(struct in6_addr
) },
2874 [IFLA_VXLAN_LINK
] = { .type
= NLA_U32
},
2875 [IFLA_VXLAN_LOCAL
] = { .len
= FIELD_SIZEOF(struct iphdr
, saddr
) },
2876 [IFLA_VXLAN_LOCAL6
] = { .len
= sizeof(struct in6_addr
) },
2877 [IFLA_VXLAN_TOS
] = { .type
= NLA_U8
},
2878 [IFLA_VXLAN_TTL
] = { .type
= NLA_U8
},
2879 [IFLA_VXLAN_LABEL
] = { .type
= NLA_U32
},
2880 [IFLA_VXLAN_LEARNING
] = { .type
= NLA_U8
},
2881 [IFLA_VXLAN_AGEING
] = { .type
= NLA_U32
},
2882 [IFLA_VXLAN_LIMIT
] = { .type
= NLA_U32
},
2883 [IFLA_VXLAN_PORT_RANGE
] = { .len
= sizeof(struct ifla_vxlan_port_range
) },
2884 [IFLA_VXLAN_PROXY
] = { .type
= NLA_U8
},
2885 [IFLA_VXLAN_RSC
] = { .type
= NLA_U8
},
2886 [IFLA_VXLAN_L2MISS
] = { .type
= NLA_U8
},
2887 [IFLA_VXLAN_L3MISS
] = { .type
= NLA_U8
},
2888 [IFLA_VXLAN_COLLECT_METADATA
] = { .type
= NLA_U8
},
2889 [IFLA_VXLAN_PORT
] = { .type
= NLA_U16
},
2890 [IFLA_VXLAN_UDP_CSUM
] = { .type
= NLA_U8
},
2891 [IFLA_VXLAN_UDP_ZERO_CSUM6_TX
] = { .type
= NLA_U8
},
2892 [IFLA_VXLAN_UDP_ZERO_CSUM6_RX
] = { .type
= NLA_U8
},
2893 [IFLA_VXLAN_REMCSUM_TX
] = { .type
= NLA_U8
},
2894 [IFLA_VXLAN_REMCSUM_RX
] = { .type
= NLA_U8
},
2895 [IFLA_VXLAN_GBP
] = { .type
= NLA_FLAG
, },
2896 [IFLA_VXLAN_GPE
] = { .type
= NLA_FLAG
, },
2897 [IFLA_VXLAN_REMCSUM_NOPARTIAL
] = { .type
= NLA_FLAG
},
2900 static int vxlan_validate(struct nlattr
*tb
[], struct nlattr
*data
[],
2901 struct netlink_ext_ack
*extack
)
2903 if (tb
[IFLA_ADDRESS
]) {
2904 if (nla_len(tb
[IFLA_ADDRESS
]) != ETH_ALEN
) {
2905 NL_SET_ERR_MSG_ATTR(extack
, tb
[IFLA_ADDRESS
],
2906 "Provided link layer address is not Ethernet");
2910 if (!is_valid_ether_addr(nla_data(tb
[IFLA_ADDRESS
]))) {
2911 NL_SET_ERR_MSG_ATTR(extack
, tb
[IFLA_ADDRESS
],
2912 "Provided Ethernet address is not unicast");
2913 return -EADDRNOTAVAIL
;
2918 u32 mtu
= nla_get_u32(tb
[IFLA_MTU
]);
2920 if (mtu
< ETH_MIN_MTU
|| mtu
> ETH_MAX_MTU
) {
2921 NL_SET_ERR_MSG_ATTR(extack
, tb
[IFLA_MTU
],
2922 "MTU must be between 68 and 65535");
2928 NL_SET_ERR_MSG(extack
,
2929 "Required attributes not provided to perform the operation");
2933 if (data
[IFLA_VXLAN_ID
]) {
2934 u32 id
= nla_get_u32(data
[IFLA_VXLAN_ID
]);
2936 if (id
>= VXLAN_N_VID
) {
2937 NL_SET_ERR_MSG_ATTR(extack
, tb
[IFLA_VXLAN_ID
],
2938 "VXLAN ID must be lower than 16777216");
2943 if (data
[IFLA_VXLAN_PORT_RANGE
]) {
2944 const struct ifla_vxlan_port_range
*p
2945 = nla_data(data
[IFLA_VXLAN_PORT_RANGE
]);
2947 if (ntohs(p
->high
) < ntohs(p
->low
)) {
2948 NL_SET_ERR_MSG_ATTR(extack
, tb
[IFLA_VXLAN_PORT_RANGE
],
2949 "Invalid source port range");
2957 static void vxlan_get_drvinfo(struct net_device
*netdev
,
2958 struct ethtool_drvinfo
*drvinfo
)
2960 strlcpy(drvinfo
->version
, VXLAN_VERSION
, sizeof(drvinfo
->version
));
2961 strlcpy(drvinfo
->driver
, "vxlan", sizeof(drvinfo
->driver
));
2964 static const struct ethtool_ops vxlan_ethtool_ops
= {
2965 .get_drvinfo
= vxlan_get_drvinfo
,
2966 .get_link
= ethtool_op_get_link
,
2969 static struct socket
*vxlan_create_sock(struct net
*net
, bool ipv6
,
2970 __be16 port
, u32 flags
)
2972 struct socket
*sock
;
2973 struct udp_port_cfg udp_conf
;
2976 memset(&udp_conf
, 0, sizeof(udp_conf
));
2979 udp_conf
.family
= AF_INET6
;
2980 udp_conf
.use_udp6_rx_checksums
=
2981 !(flags
& VXLAN_F_UDP_ZERO_CSUM6_RX
);
2982 udp_conf
.ipv6_v6only
= 1;
2984 udp_conf
.family
= AF_INET
;
2987 udp_conf
.local_udp_port
= port
;
2989 /* Open UDP socket */
2990 err
= udp_sock_create(net
, &udp_conf
, &sock
);
2992 return ERR_PTR(err
);
2997 /* Create new listen socket if needed */
2998 static struct vxlan_sock
*vxlan_socket_create(struct net
*net
, bool ipv6
,
2999 __be16 port
, u32 flags
)
3001 struct vxlan_net
*vn
= net_generic(net
, vxlan_net_id
);
3002 struct vxlan_sock
*vs
;
3003 struct socket
*sock
;
3005 struct udp_tunnel_sock_cfg tunnel_cfg
;
3007 vs
= kzalloc(sizeof(*vs
), GFP_KERNEL
);
3009 return ERR_PTR(-ENOMEM
);
3011 for (h
= 0; h
< VNI_HASH_SIZE
; ++h
)
3012 INIT_HLIST_HEAD(&vs
->vni_list
[h
]);
3014 sock
= vxlan_create_sock(net
, ipv6
, port
, flags
);
3017 return ERR_CAST(sock
);
3021 refcount_set(&vs
->refcnt
, 1);
3022 vs
->flags
= (flags
& VXLAN_F_RCV_FLAGS
);
3024 spin_lock(&vn
->sock_lock
);
3025 hlist_add_head_rcu(&vs
->hlist
, vs_head(net
, port
));
3026 udp_tunnel_notify_add_rx_port(sock
,
3027 (vs
->flags
& VXLAN_F_GPE
) ?
3028 UDP_TUNNEL_TYPE_VXLAN_GPE
:
3029 UDP_TUNNEL_TYPE_VXLAN
);
3030 spin_unlock(&vn
->sock_lock
);
3032 /* Mark socket as an encapsulation socket. */
3033 memset(&tunnel_cfg
, 0, sizeof(tunnel_cfg
));
3034 tunnel_cfg
.sk_user_data
= vs
;
3035 tunnel_cfg
.encap_type
= 1;
3036 tunnel_cfg
.encap_rcv
= vxlan_rcv
;
3037 tunnel_cfg
.encap_destroy
= NULL
;
3038 tunnel_cfg
.gro_receive
= vxlan_gro_receive
;
3039 tunnel_cfg
.gro_complete
= vxlan_gro_complete
;
3041 setup_udp_tunnel_sock(net
, sock
, &tunnel_cfg
);
3046 static int __vxlan_sock_add(struct vxlan_dev
*vxlan
, bool ipv6
)
3048 struct vxlan_net
*vn
= net_generic(vxlan
->net
, vxlan_net_id
);
3049 struct vxlan_sock
*vs
= NULL
;
3050 struct vxlan_dev_node
*node
;
3052 if (!vxlan
->cfg
.no_share
) {
3053 spin_lock(&vn
->sock_lock
);
3054 vs
= vxlan_find_sock(vxlan
->net
, ipv6
? AF_INET6
: AF_INET
,
3055 vxlan
->cfg
.dst_port
, vxlan
->cfg
.flags
);
3056 if (vs
&& !refcount_inc_not_zero(&vs
->refcnt
)) {
3057 spin_unlock(&vn
->sock_lock
);
3060 spin_unlock(&vn
->sock_lock
);
3063 vs
= vxlan_socket_create(vxlan
->net
, ipv6
,
3064 vxlan
->cfg
.dst_port
, vxlan
->cfg
.flags
);
3067 #if IS_ENABLED(CONFIG_IPV6)
3069 rcu_assign_pointer(vxlan
->vn6_sock
, vs
);
3070 node
= &vxlan
->hlist6
;
3074 rcu_assign_pointer(vxlan
->vn4_sock
, vs
);
3075 node
= &vxlan
->hlist4
;
3077 vxlan_vs_add_dev(vs
, vxlan
, node
);
3081 static int vxlan_sock_add(struct vxlan_dev
*vxlan
)
3083 bool metadata
= vxlan
->cfg
.flags
& VXLAN_F_COLLECT_METADATA
;
3084 bool ipv6
= vxlan
->cfg
.flags
& VXLAN_F_IPV6
|| metadata
;
3085 bool ipv4
= !ipv6
|| metadata
;
3088 RCU_INIT_POINTER(vxlan
->vn4_sock
, NULL
);
3089 #if IS_ENABLED(CONFIG_IPV6)
3090 RCU_INIT_POINTER(vxlan
->vn6_sock
, NULL
);
3092 ret
= __vxlan_sock_add(vxlan
, true);
3093 if (ret
< 0 && ret
!= -EAFNOSUPPORT
)
3098 ret
= __vxlan_sock_add(vxlan
, false);
3100 vxlan_sock_release(vxlan
);
3104 static int vxlan_config_validate(struct net
*src_net
, struct vxlan_config
*conf
,
3105 struct net_device
**lower
,
3106 struct vxlan_dev
*old
,
3107 struct netlink_ext_ack
*extack
)
3109 struct vxlan_net
*vn
= net_generic(src_net
, vxlan_net_id
);
3110 struct vxlan_dev
*tmp
;
3111 bool use_ipv6
= false;
3113 if (conf
->flags
& VXLAN_F_GPE
) {
3114 /* For now, allow GPE only together with
3115 * COLLECT_METADATA. This can be relaxed later; in such
3116 * case, the other side of the PtP link will have to be
3119 if ((conf
->flags
& ~VXLAN_F_ALLOWED_GPE
) ||
3120 !(conf
->flags
& VXLAN_F_COLLECT_METADATA
)) {
3121 NL_SET_ERR_MSG(extack
,
3122 "VXLAN GPE does not support this combination of attributes");
3127 if (!conf
->remote_ip
.sa
.sa_family
&& !conf
->saddr
.sa
.sa_family
) {
3128 /* Unless IPv6 is explicitly requested, assume IPv4 */
3129 conf
->remote_ip
.sa
.sa_family
= AF_INET
;
3130 conf
->saddr
.sa
.sa_family
= AF_INET
;
3131 } else if (!conf
->remote_ip
.sa
.sa_family
) {
3132 conf
->remote_ip
.sa
.sa_family
= conf
->saddr
.sa
.sa_family
;
3133 } else if (!conf
->saddr
.sa
.sa_family
) {
3134 conf
->saddr
.sa
.sa_family
= conf
->remote_ip
.sa
.sa_family
;
3137 if (conf
->saddr
.sa
.sa_family
!= conf
->remote_ip
.sa
.sa_family
) {
3138 NL_SET_ERR_MSG(extack
,
3139 "Local and remote address must be from the same family");
3143 if (vxlan_addr_multicast(&conf
->saddr
)) {
3144 NL_SET_ERR_MSG(extack
, "Local address cannot be multicast");
3148 if (conf
->saddr
.sa
.sa_family
== AF_INET6
) {
3149 if (!IS_ENABLED(CONFIG_IPV6
)) {
3150 NL_SET_ERR_MSG(extack
,
3151 "IPv6 support not enabled in the kernel");
3152 return -EPFNOSUPPORT
;
3155 conf
->flags
|= VXLAN_F_IPV6
;
3157 if (!(conf
->flags
& VXLAN_F_COLLECT_METADATA
)) {
3159 ipv6_addr_type(&conf
->saddr
.sin6
.sin6_addr
);
3161 ipv6_addr_type(&conf
->remote_ip
.sin6
.sin6_addr
);
3163 if (local_type
& IPV6_ADDR_LINKLOCAL
) {
3164 if (!(remote_type
& IPV6_ADDR_LINKLOCAL
) &&
3165 (remote_type
!= IPV6_ADDR_ANY
)) {
3166 NL_SET_ERR_MSG(extack
,
3167 "Invalid combination of local and remote address scopes");
3171 conf
->flags
|= VXLAN_F_IPV6_LINKLOCAL
;
3174 (IPV6_ADDR_UNICAST
| IPV6_ADDR_LINKLOCAL
)) {
3175 NL_SET_ERR_MSG(extack
,
3176 "Invalid combination of local and remote address scopes");
3180 conf
->flags
&= ~VXLAN_F_IPV6_LINKLOCAL
;
3185 if (conf
->label
&& !use_ipv6
) {
3186 NL_SET_ERR_MSG(extack
,
3187 "Label attribute only applies to IPv6 VXLAN devices");
3191 if (conf
->remote_ifindex
) {
3192 struct net_device
*lowerdev
;
3194 lowerdev
= __dev_get_by_index(src_net
, conf
->remote_ifindex
);
3196 NL_SET_ERR_MSG(extack
,
3197 "Invalid local interface, device not found");
3201 #if IS_ENABLED(CONFIG_IPV6)
3203 struct inet6_dev
*idev
= __in6_dev_get(lowerdev
);
3204 if (idev
&& idev
->cnf
.disable_ipv6
) {
3205 NL_SET_ERR_MSG(extack
,
3206 "IPv6 support disabled by administrator");
3214 if (vxlan_addr_multicast(&conf
->remote_ip
)) {
3215 NL_SET_ERR_MSG(extack
,
3216 "Local interface required for multicast remote destination");
3221 #if IS_ENABLED(CONFIG_IPV6)
3222 if (conf
->flags
& VXLAN_F_IPV6_LINKLOCAL
) {
3223 NL_SET_ERR_MSG(extack
,
3224 "Local interface required for link-local local/remote addresses");
3232 if (!conf
->dst_port
) {
3233 if (conf
->flags
& VXLAN_F_GPE
)
3234 conf
->dst_port
= htons(4790); /* IANA VXLAN-GPE port */
3236 conf
->dst_port
= htons(vxlan_port
);
3239 if (!conf
->age_interval
)
3240 conf
->age_interval
= FDB_AGE_DEFAULT
;
3242 list_for_each_entry(tmp
, &vn
->vxlan_list
, next
) {
3246 if (tmp
->cfg
.vni
!= conf
->vni
)
3248 if (tmp
->cfg
.dst_port
!= conf
->dst_port
)
3250 if ((tmp
->cfg
.flags
& (VXLAN_F_RCV_FLAGS
| VXLAN_F_IPV6
)) !=
3251 (conf
->flags
& (VXLAN_F_RCV_FLAGS
| VXLAN_F_IPV6
)))
3254 if ((conf
->flags
& VXLAN_F_IPV6_LINKLOCAL
) &&
3255 tmp
->cfg
.remote_ifindex
!= conf
->remote_ifindex
)
3258 NL_SET_ERR_MSG(extack
,
3259 "A VXLAN device with the specified VNI already exists");
3266 static void vxlan_config_apply(struct net_device
*dev
,
3267 struct vxlan_config
*conf
,
3268 struct net_device
*lowerdev
,
3269 struct net
*src_net
,
3272 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3273 struct vxlan_rdst
*dst
= &vxlan
->default_dst
;
3274 unsigned short needed_headroom
= ETH_HLEN
;
3275 bool use_ipv6
= !!(conf
->flags
& VXLAN_F_IPV6
);
3276 int max_mtu
= ETH_MAX_MTU
;
3279 if (conf
->flags
& VXLAN_F_GPE
)
3280 vxlan_raw_setup(dev
);
3282 vxlan_ether_setup(dev
);
3285 dev
->mtu
= conf
->mtu
;
3287 vxlan
->net
= src_net
;
3290 dst
->remote_vni
= conf
->vni
;
3292 memcpy(&dst
->remote_ip
, &conf
->remote_ip
, sizeof(conf
->remote_ip
));
3295 dst
->remote_ifindex
= conf
->remote_ifindex
;
3297 dev
->gso_max_size
= lowerdev
->gso_max_size
;
3298 dev
->gso_max_segs
= lowerdev
->gso_max_segs
;
3300 needed_headroom
= lowerdev
->hard_header_len
;
3302 max_mtu
= lowerdev
->mtu
- (use_ipv6
? VXLAN6_HEADROOM
:
3304 if (max_mtu
< ETH_MIN_MTU
)
3305 max_mtu
= ETH_MIN_MTU
;
3307 if (!changelink
&& !conf
->mtu
)
3311 if (dev
->mtu
> max_mtu
)
3314 if (use_ipv6
|| conf
->flags
& VXLAN_F_COLLECT_METADATA
)
3315 needed_headroom
+= VXLAN6_HEADROOM
;
3317 needed_headroom
+= VXLAN_HEADROOM
;
3318 dev
->needed_headroom
= needed_headroom
;
3320 memcpy(&vxlan
->cfg
, conf
, sizeof(*conf
));
3323 static int vxlan_dev_configure(struct net
*src_net
, struct net_device
*dev
,
3324 struct vxlan_config
*conf
, bool changelink
,
3325 struct netlink_ext_ack
*extack
)
3327 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3328 struct net_device
*lowerdev
;
3331 ret
= vxlan_config_validate(src_net
, conf
, &lowerdev
, vxlan
, extack
);
3335 vxlan_config_apply(dev
, conf
, lowerdev
, src_net
, changelink
);
3340 static int __vxlan_dev_create(struct net
*net
, struct net_device
*dev
,
3341 struct vxlan_config
*conf
,
3342 struct netlink_ext_ack
*extack
)
3344 struct vxlan_net
*vn
= net_generic(net
, vxlan_net_id
);
3345 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3348 err
= vxlan_dev_configure(net
, dev
, conf
, false, extack
);
3352 dev
->ethtool_ops
= &vxlan_ethtool_ops
;
3354 /* create an fdb entry for a valid default destination */
3355 if (!vxlan_addr_any(&vxlan
->default_dst
.remote_ip
)) {
3356 err
= vxlan_fdb_create(vxlan
, all_zeros_mac
,
3357 &vxlan
->default_dst
.remote_ip
,
3358 NUD_REACHABLE
| NUD_PERMANENT
,
3359 NLM_F_EXCL
| NLM_F_CREATE
,
3360 vxlan
->cfg
.dst_port
,
3361 vxlan
->default_dst
.remote_vni
,
3362 vxlan
->default_dst
.remote_vni
,
3363 vxlan
->default_dst
.remote_ifindex
,
3369 err
= register_netdevice(dev
);
3371 vxlan_fdb_delete_default(vxlan
, vxlan
->default_dst
.remote_vni
);
3375 list_add(&vxlan
->next
, &vn
->vxlan_list
);
3379 static int vxlan_nl2conf(struct nlattr
*tb
[], struct nlattr
*data
[],
3380 struct net_device
*dev
, struct vxlan_config
*conf
,
3383 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3386 memset(conf
, 0, sizeof(*conf
));
3388 /* if changelink operation, start with old existing cfg */
3390 memcpy(conf
, &vxlan
->cfg
, sizeof(*conf
));
3392 if (data
[IFLA_VXLAN_ID
]) {
3393 __be32 vni
= cpu_to_be32(nla_get_u32(data
[IFLA_VXLAN_ID
]));
3395 if (changelink
&& (vni
!= conf
->vni
))
3397 conf
->vni
= cpu_to_be32(nla_get_u32(data
[IFLA_VXLAN_ID
]));
3400 if (data
[IFLA_VXLAN_GROUP
]) {
3401 if (changelink
&& (conf
->remote_ip
.sa
.sa_family
!= AF_INET
))
3404 conf
->remote_ip
.sin
.sin_addr
.s_addr
= nla_get_in_addr(data
[IFLA_VXLAN_GROUP
]);
3405 conf
->remote_ip
.sa
.sa_family
= AF_INET
;
3406 } else if (data
[IFLA_VXLAN_GROUP6
]) {
3407 if (!IS_ENABLED(CONFIG_IPV6
))
3408 return -EPFNOSUPPORT
;
3410 if (changelink
&& (conf
->remote_ip
.sa
.sa_family
!= AF_INET6
))
3413 conf
->remote_ip
.sin6
.sin6_addr
= nla_get_in6_addr(data
[IFLA_VXLAN_GROUP6
]);
3414 conf
->remote_ip
.sa
.sa_family
= AF_INET6
;
3417 if (data
[IFLA_VXLAN_FAN_MAP
]) {
3418 err
= vxlan_parse_fan_map(data
, vxlan
);
3423 if (data
[IFLA_VXLAN_LOCAL
]) {
3424 if (changelink
&& (conf
->saddr
.sa
.sa_family
!= AF_INET
))
3427 conf
->saddr
.sin
.sin_addr
.s_addr
= nla_get_in_addr(data
[IFLA_VXLAN_LOCAL
]);
3428 conf
->saddr
.sa
.sa_family
= AF_INET
;
3429 } else if (data
[IFLA_VXLAN_LOCAL6
]) {
3430 if (!IS_ENABLED(CONFIG_IPV6
))
3431 return -EPFNOSUPPORT
;
3433 if (changelink
&& (conf
->saddr
.sa
.sa_family
!= AF_INET6
))
3436 /* TODO: respect scope id */
3437 conf
->saddr
.sin6
.sin6_addr
= nla_get_in6_addr(data
[IFLA_VXLAN_LOCAL6
]);
3438 conf
->saddr
.sa
.sa_family
= AF_INET6
;
3441 if (data
[IFLA_VXLAN_LINK
])
3442 conf
->remote_ifindex
= nla_get_u32(data
[IFLA_VXLAN_LINK
]);
3444 if (data
[IFLA_VXLAN_TOS
])
3445 conf
->tos
= nla_get_u8(data
[IFLA_VXLAN_TOS
]);
3447 if (data
[IFLA_VXLAN_TTL
])
3448 conf
->ttl
= nla_get_u8(data
[IFLA_VXLAN_TTL
]);
3450 if (data
[IFLA_VXLAN_LABEL
])
3451 conf
->label
= nla_get_be32(data
[IFLA_VXLAN_LABEL
]) &
3452 IPV6_FLOWLABEL_MASK
;
3454 if (data
[IFLA_VXLAN_LEARNING
]) {
3455 if (nla_get_u8(data
[IFLA_VXLAN_LEARNING
]))
3456 conf
->flags
|= VXLAN_F_LEARN
;
3458 conf
->flags
&= ~VXLAN_F_LEARN
;
3459 } else if (!changelink
) {
3460 /* default to learn on a new device */
3461 conf
->flags
|= VXLAN_F_LEARN
;
3464 if (data
[IFLA_VXLAN_AGEING
]) {
3467 conf
->age_interval
= nla_get_u32(data
[IFLA_VXLAN_AGEING
]);
3470 if (data
[IFLA_VXLAN_PROXY
]) {
3473 if (nla_get_u8(data
[IFLA_VXLAN_PROXY
]))
3474 conf
->flags
|= VXLAN_F_PROXY
;
3477 if (data
[IFLA_VXLAN_RSC
]) {
3480 if (nla_get_u8(data
[IFLA_VXLAN_RSC
]))
3481 conf
->flags
|= VXLAN_F_RSC
;
3484 if (data
[IFLA_VXLAN_L2MISS
]) {
3487 if (nla_get_u8(data
[IFLA_VXLAN_L2MISS
]))
3488 conf
->flags
|= VXLAN_F_L2MISS
;
3491 if (data
[IFLA_VXLAN_L3MISS
]) {
3494 if (nla_get_u8(data
[IFLA_VXLAN_L3MISS
]))
3495 conf
->flags
|= VXLAN_F_L3MISS
;
3498 if (data
[IFLA_VXLAN_LIMIT
]) {
3501 conf
->addrmax
= nla_get_u32(data
[IFLA_VXLAN_LIMIT
]);
3504 if (data
[IFLA_VXLAN_COLLECT_METADATA
]) {
3507 if (nla_get_u8(data
[IFLA_VXLAN_COLLECT_METADATA
]))
3508 conf
->flags
|= VXLAN_F_COLLECT_METADATA
;
3511 if (data
[IFLA_VXLAN_PORT_RANGE
]) {
3513 const struct ifla_vxlan_port_range
*p
3514 = nla_data(data
[IFLA_VXLAN_PORT_RANGE
]);
3515 conf
->port_min
= ntohs(p
->low
);
3516 conf
->port_max
= ntohs(p
->high
);
3522 if (data
[IFLA_VXLAN_PORT
]) {
3525 conf
->dst_port
= nla_get_be16(data
[IFLA_VXLAN_PORT
]);
3528 if (data
[IFLA_VXLAN_UDP_CSUM
]) {
3531 if (!nla_get_u8(data
[IFLA_VXLAN_UDP_CSUM
]))
3532 conf
->flags
|= VXLAN_F_UDP_ZERO_CSUM_TX
;
3535 if (data
[IFLA_VXLAN_UDP_ZERO_CSUM6_TX
]) {
3538 if (nla_get_u8(data
[IFLA_VXLAN_UDP_ZERO_CSUM6_TX
]))
3539 conf
->flags
|= VXLAN_F_UDP_ZERO_CSUM6_TX
;
3542 if (data
[IFLA_VXLAN_UDP_ZERO_CSUM6_RX
]) {
3545 if (nla_get_u8(data
[IFLA_VXLAN_UDP_ZERO_CSUM6_RX
]))
3546 conf
->flags
|= VXLAN_F_UDP_ZERO_CSUM6_RX
;
3549 if (data
[IFLA_VXLAN_REMCSUM_TX
]) {
3552 if (nla_get_u8(data
[IFLA_VXLAN_REMCSUM_TX
]))
3553 conf
->flags
|= VXLAN_F_REMCSUM_TX
;
3556 if (data
[IFLA_VXLAN_REMCSUM_RX
]) {
3559 if (nla_get_u8(data
[IFLA_VXLAN_REMCSUM_RX
]))
3560 conf
->flags
|= VXLAN_F_REMCSUM_RX
;
3563 if (data
[IFLA_VXLAN_GBP
]) {
3566 conf
->flags
|= VXLAN_F_GBP
;
3569 if (data
[IFLA_VXLAN_GPE
]) {
3572 conf
->flags
|= VXLAN_F_GPE
;
3575 if (data
[IFLA_VXLAN_REMCSUM_NOPARTIAL
]) {
3578 conf
->flags
|= VXLAN_F_REMCSUM_NOPARTIAL
;
3584 conf
->mtu
= nla_get_u32(tb
[IFLA_MTU
]);
3590 static int vxlan_newlink(struct net
*src_net
, struct net_device
*dev
,
3591 struct nlattr
*tb
[], struct nlattr
*data
[],
3592 struct netlink_ext_ack
*extack
)
3594 struct vxlan_config conf
;
3597 err
= vxlan_nl2conf(tb
, data
, dev
, &conf
, false);
3601 return __vxlan_dev_create(src_net
, dev
, &conf
, extack
);
3604 static int vxlan_changelink(struct net_device
*dev
, struct nlattr
*tb
[],
3605 struct nlattr
*data
[],
3606 struct netlink_ext_ack
*extack
)
3608 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3609 struct vxlan_rdst
*dst
= &vxlan
->default_dst
;
3610 struct vxlan_rdst old_dst
;
3611 struct vxlan_config conf
;
3614 err
= vxlan_nl2conf(tb
, data
,
3619 memcpy(&old_dst
, dst
, sizeof(struct vxlan_rdst
));
3621 err
= vxlan_dev_configure(vxlan
->net
, dev
, &conf
, true, extack
);
3625 /* handle default dst entry */
3626 if (!vxlan_addr_equal(&dst
->remote_ip
, &old_dst
.remote_ip
)) {
3627 spin_lock_bh(&vxlan
->hash_lock
);
3628 if (!vxlan_addr_any(&old_dst
.remote_ip
))
3629 __vxlan_fdb_delete(vxlan
, all_zeros_mac
,
3631 vxlan
->cfg
.dst_port
,
3634 old_dst
.remote_ifindex
, 0);
3636 if (!vxlan_addr_any(&dst
->remote_ip
)) {
3637 err
= vxlan_fdb_create(vxlan
, all_zeros_mac
,
3639 NUD_REACHABLE
| NUD_PERMANENT
,
3640 NLM_F_CREATE
| NLM_F_APPEND
,
3641 vxlan
->cfg
.dst_port
,
3644 dst
->remote_ifindex
,
3647 spin_unlock_bh(&vxlan
->hash_lock
);
3651 spin_unlock_bh(&vxlan
->hash_lock
);
3657 static void vxlan_dellink(struct net_device
*dev
, struct list_head
*head
)
3659 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3661 vxlan_flush(vxlan
, true);
3663 gro_cells_destroy(&vxlan
->gro_cells
);
3664 list_del(&vxlan
->next
);
3665 unregister_netdevice_queue(dev
, head
);
3668 static size_t vxlan_get_size(const struct net_device
*dev
)
3671 return nla_total_size(sizeof(__u32
)) + /* IFLA_VXLAN_ID */
3672 nla_total_size(sizeof(struct in6_addr
)) + /* IFLA_VXLAN_GROUP{6} */
3673 nla_total_size(sizeof(__u32
)) + /* IFLA_VXLAN_LINK */
3674 nla_total_size(sizeof(struct in6_addr
)) + /* IFLA_VXLAN_LOCAL{6} */
3675 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_TTL */
3676 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_TOS */
3677 nla_total_size(sizeof(__be32
)) + /* IFLA_VXLAN_LABEL */
3678 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_LEARNING */
3679 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_PROXY */
3680 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_RSC */
3681 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_L2MISS */
3682 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_L3MISS */
3683 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_COLLECT_METADATA */
3684 nla_total_size(sizeof(__u32
)) + /* IFLA_VXLAN_AGEING */
3685 nla_total_size(sizeof(__u32
)) + /* IFLA_VXLAN_LIMIT */
3686 nla_total_size(sizeof(struct ifla_vxlan_port_range
)) +
3687 nla_total_size(sizeof(__be16
)) + /* IFLA_VXLAN_PORT */
3688 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_UDP_CSUM */
3689 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_UDP_ZERO_CSUM6_TX */
3690 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_UDP_ZERO_CSUM6_RX */
3691 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_REMCSUM_TX */
3692 nla_total_size(sizeof(__u8
)) + /* IFLA_VXLAN_REMCSUM_RX */
3693 nla_total_size(sizeof(struct ip_fan_map
) * 256) +
3697 static int vxlan_fill_info(struct sk_buff
*skb
, const struct net_device
*dev
)
3699 const struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3700 const struct vxlan_rdst
*dst
= &vxlan
->default_dst
;
3701 struct ifla_vxlan_port_range ports
= {
3702 .low
= htons(vxlan
->cfg
.port_min
),
3703 .high
= htons(vxlan
->cfg
.port_max
),
3706 if (nla_put_u32(skb
, IFLA_VXLAN_ID
, be32_to_cpu(dst
->remote_vni
)))
3707 goto nla_put_failure
;
3709 if (!vxlan_addr_any(&dst
->remote_ip
)) {
3710 if (dst
->remote_ip
.sa
.sa_family
== AF_INET
) {
3711 if (nla_put_in_addr(skb
, IFLA_VXLAN_GROUP
,
3712 dst
->remote_ip
.sin
.sin_addr
.s_addr
))
3713 goto nla_put_failure
;
3714 #if IS_ENABLED(CONFIG_IPV6)
3716 if (nla_put_in6_addr(skb
, IFLA_VXLAN_GROUP6
,
3717 &dst
->remote_ip
.sin6
.sin6_addr
))
3718 goto nla_put_failure
;
3723 if (dst
->remote_ifindex
&& nla_put_u32(skb
, IFLA_VXLAN_LINK
, dst
->remote_ifindex
))
3724 goto nla_put_failure
;
3726 if (!vxlan_addr_any(&vxlan
->cfg
.saddr
)) {
3727 if (vxlan
->cfg
.saddr
.sa
.sa_family
== AF_INET
) {
3728 if (nla_put_in_addr(skb
, IFLA_VXLAN_LOCAL
,
3729 vxlan
->cfg
.saddr
.sin
.sin_addr
.s_addr
))
3730 goto nla_put_failure
;
3731 #if IS_ENABLED(CONFIG_IPV6)
3733 if (nla_put_in6_addr(skb
, IFLA_VXLAN_LOCAL6
,
3734 &vxlan
->cfg
.saddr
.sin6
.sin6_addr
))
3735 goto nla_put_failure
;
3740 if (fan_has_map(&vxlan
->fan
)) {
3741 struct nlattr
*fan_nest
;
3742 struct ip_fan_map
*fan_map
;
3744 fan_nest
= nla_nest_start(skb
, IFLA_VXLAN_FAN_MAP
);
3746 goto nla_put_failure
;
3747 list_for_each_entry_rcu(fan_map
, &vxlan
->fan
.fan_maps
, list
) {
3748 struct ifla_fan_map map
;
3750 map
.underlay
= fan_map
->underlay
;
3751 map
.underlay_prefix
= fan_map
->underlay_prefix
;
3752 map
.overlay
= fan_map
->overlay
;
3753 map
.overlay_prefix
= fan_map
->overlay_prefix
;
3754 if (nla_put(skb
, IFLA_FAN_MAPPING
, sizeof(map
), &map
))
3755 goto nla_put_failure
;
3757 nla_nest_end(skb
, fan_nest
);
3760 if (nla_put_u8(skb
, IFLA_VXLAN_TTL
, vxlan
->cfg
.ttl
) ||
3761 nla_put_u8(skb
, IFLA_VXLAN_TOS
, vxlan
->cfg
.tos
) ||
3762 nla_put_be32(skb
, IFLA_VXLAN_LABEL
, vxlan
->cfg
.label
) ||
3763 nla_put_u8(skb
, IFLA_VXLAN_LEARNING
,
3764 !!(vxlan
->cfg
.flags
& VXLAN_F_LEARN
)) ||
3765 nla_put_u8(skb
, IFLA_VXLAN_PROXY
,
3766 !!(vxlan
->cfg
.flags
& VXLAN_F_PROXY
)) ||
3767 nla_put_u8(skb
, IFLA_VXLAN_RSC
,
3768 !!(vxlan
->cfg
.flags
& VXLAN_F_RSC
)) ||
3769 nla_put_u8(skb
, IFLA_VXLAN_L2MISS
,
3770 !!(vxlan
->cfg
.flags
& VXLAN_F_L2MISS
)) ||
3771 nla_put_u8(skb
, IFLA_VXLAN_L3MISS
,
3772 !!(vxlan
->cfg
.flags
& VXLAN_F_L3MISS
)) ||
3773 nla_put_u8(skb
, IFLA_VXLAN_COLLECT_METADATA
,
3774 !!(vxlan
->cfg
.flags
& VXLAN_F_COLLECT_METADATA
)) ||
3775 nla_put_u32(skb
, IFLA_VXLAN_AGEING
, vxlan
->cfg
.age_interval
) ||
3776 nla_put_u32(skb
, IFLA_VXLAN_LIMIT
, vxlan
->cfg
.addrmax
) ||
3777 nla_put_be16(skb
, IFLA_VXLAN_PORT
, vxlan
->cfg
.dst_port
) ||
3778 nla_put_u8(skb
, IFLA_VXLAN_UDP_CSUM
,
3779 !(vxlan
->cfg
.flags
& VXLAN_F_UDP_ZERO_CSUM_TX
)) ||
3780 nla_put_u8(skb
, IFLA_VXLAN_UDP_ZERO_CSUM6_TX
,
3781 !!(vxlan
->cfg
.flags
& VXLAN_F_UDP_ZERO_CSUM6_TX
)) ||
3782 nla_put_u8(skb
, IFLA_VXLAN_UDP_ZERO_CSUM6_RX
,
3783 !!(vxlan
->cfg
.flags
& VXLAN_F_UDP_ZERO_CSUM6_RX
)) ||
3784 nla_put_u8(skb
, IFLA_VXLAN_REMCSUM_TX
,
3785 !!(vxlan
->cfg
.flags
& VXLAN_F_REMCSUM_TX
)) ||
3786 nla_put_u8(skb
, IFLA_VXLAN_REMCSUM_RX
,
3787 !!(vxlan
->cfg
.flags
& VXLAN_F_REMCSUM_RX
)))
3788 goto nla_put_failure
;
3790 if (nla_put(skb
, IFLA_VXLAN_PORT_RANGE
, sizeof(ports
), &ports
))
3791 goto nla_put_failure
;
3793 if (vxlan
->cfg
.flags
& VXLAN_F_GBP
&&
3794 nla_put_flag(skb
, IFLA_VXLAN_GBP
))
3795 goto nla_put_failure
;
3797 if (vxlan
->cfg
.flags
& VXLAN_F_GPE
&&
3798 nla_put_flag(skb
, IFLA_VXLAN_GPE
))
3799 goto nla_put_failure
;
3801 if (vxlan
->cfg
.flags
& VXLAN_F_REMCSUM_NOPARTIAL
&&
3802 nla_put_flag(skb
, IFLA_VXLAN_REMCSUM_NOPARTIAL
))
3803 goto nla_put_failure
;
3811 static struct net
*vxlan_get_link_net(const struct net_device
*dev
)
3813 struct vxlan_dev
*vxlan
= netdev_priv(dev
);
3818 static struct rtnl_link_ops vxlan_link_ops __read_mostly
= {
3820 .maxtype
= IFLA_VXLAN_MAX
,
3821 .policy
= vxlan_policy
,
3822 .priv_size
= sizeof(struct vxlan_dev
),
3823 .setup
= vxlan_setup
,
3824 .validate
= vxlan_validate
,
3825 .newlink
= vxlan_newlink
,
3826 .changelink
= vxlan_changelink
,
3827 .dellink
= vxlan_dellink
,
3828 .get_size
= vxlan_get_size
,
3829 .fill_info
= vxlan_fill_info
,
3830 .get_link_net
= vxlan_get_link_net
,
3833 struct net_device
*vxlan_dev_create(struct net
*net
, const char *name
,
3834 u8 name_assign_type
,
3835 struct vxlan_config
*conf
)
3837 struct nlattr
*tb
[IFLA_MAX
+ 1];
3838 struct net_device
*dev
;
3841 memset(&tb
, 0, sizeof(tb
));
3843 dev
= rtnl_create_link(net
, name
, name_assign_type
,
3844 &vxlan_link_ops
, tb
);
3848 err
= __vxlan_dev_create(net
, dev
, conf
, NULL
);
3851 return ERR_PTR(err
);
3854 err
= rtnl_configure_link(dev
, NULL
);
3856 LIST_HEAD(list_kill
);
3858 vxlan_dellink(dev
, &list_kill
);
3859 unregister_netdevice_many(&list_kill
);
3860 return ERR_PTR(err
);
3865 EXPORT_SYMBOL_GPL(vxlan_dev_create
);
3867 static void vxlan_handle_lowerdev_unregister(struct vxlan_net
*vn
,
3868 struct net_device
*dev
)
3870 struct vxlan_dev
*vxlan
, *next
;
3871 LIST_HEAD(list_kill
);
3873 list_for_each_entry_safe(vxlan
, next
, &vn
->vxlan_list
, next
) {
3874 struct vxlan_rdst
*dst
= &vxlan
->default_dst
;
3876 /* In case we created vxlan device with carrier
3877 * and we loose the carrier due to module unload
3878 * we also need to remove vxlan device. In other
3879 * cases, it's not necessary and remote_ifindex
3880 * is 0 here, so no matches.
3882 if (dst
->remote_ifindex
== dev
->ifindex
)
3883 vxlan_dellink(vxlan
->dev
, &list_kill
);
3886 unregister_netdevice_many(&list_kill
);
3889 static int vxlan_netdevice_event(struct notifier_block
*unused
,
3890 unsigned long event
, void *ptr
)
3892 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
3893 struct vxlan_net
*vn
= net_generic(dev_net(dev
), vxlan_net_id
);
3895 if (event
== NETDEV_UNREGISTER
) {
3896 vxlan_offload_rx_ports(dev
, false);
3897 vxlan_handle_lowerdev_unregister(vn
, dev
);
3898 } else if (event
== NETDEV_REGISTER
) {
3899 vxlan_offload_rx_ports(dev
, true);
3900 } else if (event
== NETDEV_UDP_TUNNEL_PUSH_INFO
||
3901 event
== NETDEV_UDP_TUNNEL_DROP_INFO
) {
3902 vxlan_offload_rx_ports(dev
, event
== NETDEV_UDP_TUNNEL_PUSH_INFO
);
3908 static struct notifier_block vxlan_notifier_block __read_mostly
= {
3909 .notifier_call
= vxlan_netdevice_event
,
3912 static __net_init
int vxlan_init_net(struct net
*net
)
3914 struct vxlan_net
*vn
= net_generic(net
, vxlan_net_id
);
3917 INIT_LIST_HEAD(&vn
->vxlan_list
);
3918 spin_lock_init(&vn
->sock_lock
);
3920 for (h
= 0; h
< PORT_HASH_SIZE
; ++h
)
3921 INIT_HLIST_HEAD(&vn
->sock_list
[h
]);
3926 #ifdef CONFIG_SYSCTL
3927 static struct ctl_table_header
*vxlan_fan_header
;
3928 static unsigned int vxlan_fan_version
= 4;
3930 static struct ctl_table vxlan_fan_sysctls
[] = {
3932 .procname
= "vxlan",
3933 .data
= &vxlan_fan_version
,
3934 .maxlen
= sizeof(vxlan_fan_version
),
3936 .proc_handler
= proc_dointvec
,
3940 #endif /* CONFIG_SYSCTL */
3942 static void __net_exit
vxlan_exit_net(struct net
*net
)
3944 struct vxlan_net
*vn
= net_generic(net
, vxlan_net_id
);
3945 struct vxlan_dev
*vxlan
, *next
;
3946 struct net_device
*dev
, *aux
;
3951 for_each_netdev_safe(net
, dev
, aux
)
3952 if (dev
->rtnl_link_ops
== &vxlan_link_ops
)
3953 unregister_netdevice_queue(dev
, &list
);
3955 list_for_each_entry_safe(vxlan
, next
, &vn
->vxlan_list
, next
) {
3956 /* If vxlan->dev is in the same netns, it has already been added
3957 * to the list by the previous loop.
3959 if (!net_eq(dev_net(vxlan
->dev
), net
)) {
3960 gro_cells_destroy(&vxlan
->gro_cells
);
3961 unregister_netdevice_queue(vxlan
->dev
, &list
);
3965 unregister_netdevice_many(&list
);
3968 for (h
= 0; h
< PORT_HASH_SIZE
; ++h
)
3969 WARN_ON_ONCE(!hlist_empty(&vn
->sock_list
[h
]));
3972 static struct pernet_operations vxlan_net_ops
= {
3973 .init
= vxlan_init_net
,
3974 .exit
= vxlan_exit_net
,
3975 .id
= &vxlan_net_id
,
3976 .size
= sizeof(struct vxlan_net
),
3979 static int __init
vxlan_init_module(void)
3983 get_random_bytes(&vxlan_salt
, sizeof(vxlan_salt
));
3985 rc
= register_pernet_subsys(&vxlan_net_ops
);
3989 rc
= register_netdevice_notifier(&vxlan_notifier_block
);
3993 rc
= rtnl_link_register(&vxlan_link_ops
);
3997 #ifdef CONFIG_SYSCTL
3998 vxlan_fan_header
= register_net_sysctl(&init_net
, "net/fan",
4000 if (!vxlan_fan_header
) {
4004 #endif /* CONFIG_SYSCTL */
4007 #ifdef CONFIG_SYSCTL
4009 rtnl_link_unregister(&vxlan_link_ops
);
4010 #endif /* CONFIG_SYSCTL */
4012 unregister_netdevice_notifier(&vxlan_notifier_block
);
4014 unregister_pernet_subsys(&vxlan_net_ops
);
4018 late_initcall(vxlan_init_module
);
4020 static void __exit
vxlan_cleanup_module(void)
4022 #ifdef CONFIG_SYSCTL
4023 unregister_net_sysctl_table(vxlan_fan_header
);
4024 #endif /* CONFIG_SYSCTL */
4025 rtnl_link_unregister(&vxlan_link_ops
);
4026 unregister_netdevice_notifier(&vxlan_notifier_block
);
4027 unregister_pernet_subsys(&vxlan_net_ops
);
4028 /* rcu_barrier() is called by netns */
4030 module_exit(vxlan_cleanup_module
);
4032 MODULE_LICENSE("GPL");
4033 MODULE_VERSION(VXLAN_VERSION
);
4034 MODULE_AUTHOR("Stephen Hemminger <stephen@networkplumber.org>");
4035 MODULE_DESCRIPTION("Driver for VXLAN encapsulated traffic");
4036 MODULE_ALIAS_RTNL_LINK("vxlan");