vxlan metadata device vnifiltering support
Subsystems (4)
v2 cover vxlan metadata device vnifiltering support
This series adds vnifiltering support to vxlan collect metadata device.
Motivation:
You can only use a single vxlan collect metadata device for a given vxlan udp port in the system today. The vxlan collect metadata device terminates all received vxlan packets. As shown in the below diagram, there are use-cases where you need to support multiple such vxlan devices in independent bridge domains. Each vxlan device must terminate the vni's it is configured for.
Example usecase: In a service provider network a service provider typically supports multiple bridge domains with overlapping vlans. One bridge domain per customer. Vlans in each bridge domain are mapped to globally unique vxlan ranges assigned to each customer.
This series adds vnifiltering support to collect metadata devices to terminate only configured vnis. This is similar to vlan filtering in bridge driver. The vni filtering capability is provided by a new flag on collect metadata device.
In the below pic:
- customer1 is mapped to br1 bridge domain
- customer2 is mapped to br2 bridge domain
- customer1 vlan 10-11 is mapped to vni 1001-1002
- customer2 vlan 10-11 is mapped to vni 2001-2002
- br1 and br2 are vlan filtering bridges
- vxlan1 and vxlan2 are collect metadata devices with vnifiltering enabled
┌──────────────────────────────────────────────────────────────────┐
│ switch │
│ │
│ ┌───────────┐ ┌───────────┐ │
│ │ │ │ │ │
│ │ br1 │ │ br2 │ │
│ └┬─────────┬┘ └──┬───────┬┘ │
│ vlans│ │ vlans │ │ │
│ 10,11│ │ 10,11│ │ │
│ │ vlanvnimap: │ vlanvnimap: │
│ │ 10-1001,11-1002 │ 10-2001,11-2002 │
│ │ │ │ │ │
│ ┌──────┴┐ ┌──┴─────────┐ ┌───┴────┐ │ │
│ │ swp1 │ │vxlan1 │ │ swp2 │ ┌┴─────────────┐ │
│ │ │ │ vnifilter:│ │ │ │vxlan2 │ │
│ └───┬───┘ │ 1001,1002│ └───┬────┘ │ vnifilter: │ │
│ │ └────────────┘ │ │ 2001,2002 │ │
│ │ │ └──────────────┘ │
│ │ │ │
└───────┼──────────────────────────────────┼───────────────────────┘
│ │
│ │
┌─────┴───────┐ │
│ customer1 │ ┌─────┴──────┐
│ host/VM │ │customer2 │
└─────────────┘ │ host/VM │
└────────────┘v2:
- remove stale xstats declarations pointed out by Nikolay Aleksandrov
- squash selinux patch with the tunnel api patch as pointed out by benjamin poirier
- Fix various build issues:
Nikolay Aleksandrov (2):
drivers: vxlan: vnifilter: per vni stats
drivers: vxlan: vnifilter: add support for stats dumping
Roopa Prabhu (10):
vxlan: move to its own directory
vxlan_core: wrap label in ipv6 enabled checks in vxlan_xmit_one
vxlan_core: move common declarations to private header file
vxlan_core: move some fdb helpers to non-static
vxlan_core: make multicast helper take rip and ifindex explicitly
vxlan_core: add helper vxlan_vni_in_use
rtnetlink: add new rtm tunnel api for tunnel id filtering
vxlan_multicast: Move multicast helpers to a separate file
vxlan: vni filtering support on collect metadata device
selftests: add new tests for vxlan vnifiltering
drivers/net/Makefile | 2 +-
drivers/net/vxlan/Makefile | 7 +
drivers/net/{vxlan.c => vxlan/vxlan_core.c} | 414 +++-----
drivers/net/vxlan/vxlan_multicast.c | 272 +++++
drivers/net/vxlan/vxlan_private.h | 178 ++++
drivers/net/vxlan/vxlan_vnifilter.c | 962 ++++++++++++++++++
include/net/vxlan.h | 54 +-
include/uapi/linux/if_link.h | 47 +
include/uapi/linux/rtnetlink.h | 9 +
security/selinux/nlmsgtab.c | 5 +-
.../selftests/net/test_vxlan_vnifiltering.sh | 581 +++++++++++
11 files changed, 2271 insertions(+), 260 deletions(-)
create mode 100644 drivers/net/vxlan/Makefile
rename drivers/net/{vxlan.c => vxlan/vxlan_core.c} (94%)
create mode 100644 drivers/net/vxlan/vxlan_multicast.c
create mode 100644 drivers/net/vxlan/vxlan_private.h
create mode 100644 drivers/net/vxlan/vxlan_vnifilter.c
create mode 100755 tools/testing/selftests/net/test_vxlan_vnifiltering.shSignature · 1 line
2.25.1
PATCH v2 1/12 vxlan: move to its own directory
vxlan.c has grown too long. This patch moves it to its own directory. subsequent patches add new functionality in new files.
---
drivers/net/Makefile | 2 +-
drivers/net/vxlan/Makefile | 7 +++++++
drivers/net/{vxlan.c => vxlan/vxlan_core.c} | 0
3 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/vxlan/Makefile
rename drivers/net/{vxlan.c => vxlan/vxlan_core.c} (100%)drivers/net/Makefile +1 -1
@@ -31,7 +31,7 @@ obj-$(CONFIG_TUN) += tun.o obj-$(CONFIG_TAP) += tap.o obj-$(CONFIG_VETH) += veth.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o -obj-$(CONFIG_VXLAN) += vxlan.o +obj-$(CONFIG_VXLAN) += vxlan/ obj-$(CONFIG_GENEVE) += geneve.o obj-$(CONFIG_BAREUDP) += bareudp.o obj-$(CONFIG_GTP) += gtp.o
drivers/net/vxlan/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for the vxlan driver +# + +obj-$(CONFIG_VXLAN) += vxlan.o + +vxlan-objs := vxlan_core.o
drivers/net/vxlan/vxlan_core.c renamed from drivers/net/vxlan.c +0 -0
Signature · 1 line
2.25.1
PATCH v2 2/12 vxlan_core: fix build warnings in vxlan_xmit_one
In reply to Roopa PrabhuFix the below build warnings reported by kernel test robot:
- initialize vni in vxlan_xmit_one
- wrap label in ipv6 enabled checks in vxlan_xmit_one
warnings:
static
drivers/net/vxlan/vxlan_core.c:2437:14: warning: variable 'label' set
but not used [-Wunused-but-set-variable]
__be32 vni, label;
^Quoted 1 line
Quoted 1 line
drivers/net/vxlan/vxlan_core.c:2483:7: warning: variable 'vni' is
used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
--- drivers/net/vxlan/vxlan_core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +8 -1
@@ -2603,13 +2603,16 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,struct vxlan_metadata *md = &_md;__be16 src_port =0 , dst_port;struct dst_entry *ndst =NULL ; -__be32 vni, label;__u8 tos, ttl;int ifindex;int err;u32 flags = vxlan->cfg.flags;bool udp_sum = false;bool xnet = !net_eq (vxlan->net,dev_net (vxlan->dev)); +__be32 vni =0 ; +#if IS_ENABLED (CONFIG_IPV6 ) +__be32 label; +#endif info =skb_tunnel_info (skb);
@@ -2647,7 +2650,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM_TX ); else udp_sum = !(flags &VXLAN_F_UDP_ZERO_CSUM6_TX ); +#if IS_ENABLED (CONFIG_IPV6 ) label = vxlan->cfg.label; +#endif }else {if (!info) { WARN_ONCE(1, "%s: Missing encapsulation instructions\n",
@@ -2674,7 +2679,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, } ttl = info->key.ttl; tos = info->key.tos; +#if IS_ENABLED (CONFIG_IPV6 ) label = info->key.label; +#endif udp_sum = !!(info->key.tun_flags &TUNNEL_CSUM ); } src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
Signature · 1 line
2.25.1
PATCH v2 3/12 vxlan_core: move common declarations to private header file
In reply to Roopa PrabhuThis patch moves common structures and global declarations to a shared private headerfile vxlan_private.h. Subsequent patches use this header file as a common header file for additional shared declarations.
--- drivers/net/vxlan/vxlan_core.c | 84 ++------------------------- drivers/net/vxlan/vxlan_private.h | 95 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 79 deletions(-) create mode 100644 drivers/net/vxlan/vxlan_private.h
drivers/net/vxlan/vxlan_core.c +5 -79
@@ -34,10 +34,10 @@#include <net/ip6_checksum.h> #endif +#include "vxlan_private.h" +#define VXLAN_VERSION "0.1" -#define PORT_HASH_BITS 8 -#define PORT_HASH_SIZE (1<<PORT_HASH_BITS)#define FDB_AGE_DEFAULT 300/* 5 min */ #define FDB_AGE_INTERVAL (10 * HZ)/* rescan interval */
@@ -53,41 +53,15 @@ static bool log_ecn_error = true;module_param (log_ecn_error, bool,0644 );MODULE_PARM_DESC (log_ecn_error,"Log packets received with corrupted ECN" ); -static unsigned int vxlan_net_id; -static struct rtnl_link_ops vxlan_link_ops; +unsigned int vxlan_net_id; -static const u8 all_zeros_mac[ETH_ALEN +2 ]; +const u8 all_zeros_mac[ETH_ALEN +2 ]; +static struct rtnl_link_ops vxlan_link_ops;static int vxlan_sock_add (struct vxlan_dev *vxlan);static void vxlan_vs_del_dev (struct vxlan_dev *vxlan); -/* per-network namespace private data for this module */ -struct vxlan_net { -struct list_head vxlan_list; -struct hlist_head sock_list[PORT_HASH_SIZE ]; -spinlock_t sock_lock; -struct notifier_block nexthop_notifier_block; -}; - -/* Forwarding table entry */ -struct vxlan_fdb { -struct hlist_node hlist;/* linked list of entries */ -struct rcu_head rcu; -unsigned long updated;/* jiffies */ -unsigned long used; -struct list_head remotes; -u8 eth_addr[ETH_ALEN ]; -u16 state;/* see ndm_state */ -__be32 vni; -u16 flags;/* see ndm_flags and below */ -struct list_head nh_list; -struct nexthop __rcu *nh; -struct vxlan_dev __rcu *vdev; -}; - -#define NTF_VXLAN_ADDED_BY_USER 0x100 -/* salt for hash table */ static u32 vxlan_salt__read_mostly ;
@@ -98,17 +72,6 @@ static inline bool vxlan_collect_metadata(struct vxlan_sock *vs) }#if IS_ENABLED (CONFIG_IPV6 ) -static inline -bool vxlan_addr_equal (const union vxlan_addr *a,const union vxlan_addr *b) -{ -if (a->sa.sa_family != b->sa.sa_family) -return false; -if (a->sa.sa_family ==AF_INET6 ) -return ipv6_addr_equal (&a->sin6.sin6_addr, &b->sin6.sin6_addr); -else -return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; -} -static int vxlan_nla_get_addr (union vxlan_addr *ip,struct nlattr *nla) {if (nla_len (nla) >=sizeof (struct in6_addr )) {
@@ -135,12 +98,6 @@ static int vxlan_nla_put_addr(struct sk_buff *skb, int attr,#else /* !CONFIG_IPV6 */ -static inline -bool vxlan_addr_equal (const union vxlan_addr *a,const union vxlan_addr *b) -{ -return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; -} -static int vxlan_nla_get_addr (union vxlan_addr *ip,struct nlattr *nla) {if (nla_len (nla) >=sizeof (struct in6_addr )) {
@@ -161,37 +118,6 @@ static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, }#endif -/* Virtual Network hash table head */ -static inline struct hlist_head *vni_head (struct vxlan_sock *vs,__be32 vni) -{ -return &vs->vni_list[hash_32 ((__force u32 )vni,VNI_HASH_BITS )]; -} - -/* Socket hash table head */ -static inline struct hlist_head *vs_head (struct net *net,__be16 port) -{ -struct vxlan_net *vn =net_generic (net, vxlan_net_id); - -return &vn->sock_list[hash_32 (ntohs (port),PORT_HASH_BITS )]; -} - -/* First remote destination for a forwarding entry. -* Guaranteed to be non-NULL because remotes are never deleted. -*/ -static inline struct vxlan_rdst *first_remote_rcu (struct vxlan_fdb *fdb) -{ -if (rcu_access_pointer (fdb->nh)) -return NULL ; - return list_entry_rcu(fdb->remotes.next, struct vxlan_rdst, list); -} - -static inline struct vxlan_rdst *first_remote_rtnl (struct vxlan_fdb *fdb) -{ -if (rcu_access_pointer (fdb->nh)) -return NULL ; - return list_first_entry(&fdb->remotes, struct vxlan_rdst, list); -} -/* Find VXLAN socket based on network namespace, address family, UDP port, * enabled unshareable flags and socket device binding (see l3mdev with * non-default VRF).
drivers/net/vxlan/vxlan_private.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 4/12 vxlan_core: move some fdb helpers to non-static
In reply to Roopa PrabhuThis patch moves some fdb helpers to non-static for use in later patches. Ideally, all fdb code could move into its own file vxlan_fdb.c. This can be done as a subsequent patch and is out of scope of this series.
--- drivers/net/vxlan/vxlan_core.c | 38 +++++++++++++++---------------- drivers/net/vxlan/vxlan_private.h | 20 ++++++++++++++++ 2 files changed, 39 insertions(+), 19 deletions(-)
drivers/net/vxlan/vxlan_core.c +19 -19
@@ -419,7 +419,7 @@ static u32 eth_hash(const unsigned char *addr)return hash_64 (value,FDB_HASH_BITS ); } -static u32 eth_vni_hash (const unsigned char *addr,__be32 vni) +u32 eth_vni_hash (const unsigned char *addr,__be32 vni) {/* use 1 byte of OUI and 3 bytes of NIC */ u32 key =get_unaligned ((u32 *)(addr +2 ));
@@ -427,7 +427,7 @@ static u32 eth_vni_hash(const unsigned char *addr, __be32 vni)return jhash_2words (key, vni, vxlan_salt) & (FDB_HASH_SIZE -1 ); } -static u32 fdb_head_index (struct vxlan_dev *vxlan,const u8 *mac,__be32 vni) +u32 fdb_head_index (struct vxlan_dev *vxlan,const u8 *mac,__be32 vni) {if (vxlan->cfg.flags &VXLAN_F_COLLECT_METADATA )return eth_vni_hash (mac, vni);
@@ -846,12 +846,12 @@ static int vxlan_fdb_nh_update(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,return err; } -static int vxlan_fdb_create (struct vxlan_dev *vxlan, -const u8 *mac,union vxlan_addr *ip, -__u16 state,__be16 port,__be32 src_vni, -__be32 vni,__u32 ifindex,__u16 ndm_flags, -u32 nhid,struct vxlan_fdb **fdb, -struct netlink_ext_ack *extack) +int vxlan_fdb_create (struct vxlan_dev *vxlan, +const u8 *mac,union vxlan_addr *ip, +__u16 state,__be16 port,__be32 src_vni, +__be32 vni,__u32 ifindex,__u16 ndm_flags, +u32 nhid,struct vxlan_fdb **fdb, +struct netlink_ext_ack *extack) {struct vxlan_rdst *rd =NULL ;struct vxlan_fdb *f;
@@ -1076,13 +1076,13 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan, }/* Add new entry to forwarding table -- assumes lock held */ -static int vxlan_fdb_update (struct vxlan_dev *vxlan, -const u8 *mac,union vxlan_addr *ip, -__u16 state,__u16 flags, -__be16 port,__be32 src_vni,__be32 vni, -__u32 ifindex,__u16 ndm_flags,u32 nhid, -bool swdev_notify, -struct netlink_ext_ack *extack) +int vxlan_fdb_update (struct vxlan_dev *vxlan, +const u8 *mac,union vxlan_addr *ip, +__u16 state,__u16 flags, +__be16 port,__be32 src_vni,__be32 vni, +__u32 ifindex,__u16 ndm_flags,u32 nhid, +bool swdev_notify, +struct netlink_ext_ack *extack) {struct vxlan_fdb *f;
@@ -1233,10 +1233,10 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],return err; } -static int __vxlan_fdb_delete (struct vxlan_dev *vxlan, -const unsigned char *addr,union vxlan_addr ip, -__be16 port,__be32 src_vni,__be32 vni, -u32 ifindex,bool swdev_notify) +int __vxlan_fdb_delete (struct vxlan_dev *vxlan, +const unsigned char *addr,union vxlan_addr ip, +__be16 port,__be32 src_vni,__be32 vni, +u32 ifindex,bool swdev_notify) {struct vxlan_rdst *rd =NULL ;struct vxlan_fdb *f;
drivers/net/vxlan/vxlan_private.h +20 -0
@@ -92,4 +92,24 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)#endif +/* vxlan_core.c */ +int vxlan_fdb_create (struct vxlan_dev *vxlan, +const u8 *mac,union vxlan_addr *ip, +__u16 state,__be16 port,__be32 src_vni, +__be32 vni,__u32 ifindex,__u16 ndm_flags, +u32 nhid,struct vxlan_fdb **fdb, +struct netlink_ext_ack *extack); +int __vxlan_fdb_delete (struct vxlan_dev *vxlan, +const unsigned char *addr,union vxlan_addr ip, +__be16 port,__be32 src_vni,__be32 vni, +u32 ifindex,bool swdev_notify); +u32 eth_vni_hash (const unsigned char *addr,__be32 vni); +u32 fdb_head_index (struct vxlan_dev *vxlan,const u8 *mac,__be32 vni); +int vxlan_fdb_update (struct vxlan_dev *vxlan, +const u8 *mac,union vxlan_addr *ip, +__u16 state,__u16 flags, +__be16 port,__be32 src_vni,__be32 vni, +__u32 ifindex,__u16 ndm_flags,u32 nhid, +bool swdev_notify,struct netlink_ext_ack *extack); +#endif
Signature · 1 line
2.25.1
PATCH v2 5/12 vxlan_core: make multicast helper take rip and ifindex explicitly
In reply to Roopa PrabhuThis patch changes multicast helpers to take rip and ifindex as input. This is needed in future patches where rip can come from a pervni structure while the ifindex can come from the vxlan device.
--- drivers/net/vxlan/vxlan_core.c | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-)
drivers/net/vxlan/vxlan_core.c +21 -16
@@ -1446,8 +1446,11 @@ static bool vxlan_snoop(struct net_device *dev, }/* See if multicast group is already in use by other ID */ -static bool vxlan_group_used (struct vxlan_net *vn,struct vxlan_dev *dev) +static bool vxlan_group_used (struct vxlan_net *vn,struct vxlan_dev *dev, +union vxlan_addr *rip,int rifindex) { +union vxlan_addr *ip = (rip ? : &dev->default_dst.remote_ip); +int ifindex = (rifindex ? : dev->default_dst.remote_ifindex);struct vxlan_dev *vxlan;struct vxlan_sock *sock4;#if IS_ENABLED (CONFIG_IPV6 )
@@ -1482,11 +1485,10 @@ static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev)#endif if (!vxlan_addr_equal (&vxlan->default_dst.remote_ip, - &dev->default_dst.remote_ip)) + ip))continue ; -if (vxlan->default_dst.remote_ifindex != - dev->default_dst.remote_ifindex) +if (vxlan->default_dst.remote_ifindex != ifindex)continue ;return true;
@@ -1546,12 +1548,13 @@ static void vxlan_sock_release(struct vxlan_dev *vxlan)/* Update multicast group membership when first VNI on * multicast address is brought up */ -static int vxlan_igmp_join (struct vxlan_dev *vxlan) +static int vxlan_igmp_join (struct vxlan_dev *vxlan,union vxlan_addr *rip, +int rifindex) { -struct sock *sk; -union vxlan_addr *ip = &vxlan->default_dst.remote_ip; -int ifindex = vxlan->default_dst.remote_ifindex; +union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); +int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex);int ret = -EINVAL ; +struct sock *sk;if (ip->sa.sa_family ==AF_INET ) {struct vxlan_sock *sock4 =rtnl_dereference (vxlan->vn4_sock);
@@ -1579,13 +1582,13 @@ static int vxlan_igmp_join(struct vxlan_dev *vxlan)return ret; } -/* Inverse of vxlan_igmp_join when last VNI is brought down */ -static int vxlan_igmp_leave (struct vxlan_dev *vxlan) +static int vxlan_igmp_leave (struct vxlan_dev *vxlan,union vxlan_addr *rip, +int rifindex) { -struct sock *sk; -union vxlan_addr *ip = &vxlan->default_dst.remote_ip; -int ifindex = vxlan->default_dst.remote_ifindex; +union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); +int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex);int ret = -EINVAL ; +struct sock *sk;if (ip->sa.sa_family ==AF_INET ) {struct vxlan_sock *sock4 =rtnl_dereference (vxlan->vn4_sock);
@@ -3024,7 +3027,8 @@ static int vxlan_open(struct net_device *dev)return ret;if (vxlan_addr_multicast (&vxlan->default_dst.remote_ip)) { - ret =vxlan_igmp_join (vxlan); + ret =vxlan_igmp_join (vxlan, &vxlan->default_dst.remote_ip, + vxlan->default_dst.remote_ifindex);if (ret == -EADDRINUSE ) ret =0 ;if (ret) {
@@ -3071,8 +3075,9 @@ static int vxlan_stop(struct net_device *dev)int ret =0 ;if (vxlan_addr_multicast (&vxlan->default_dst.remote_ip) && - !vxlan_group_used (vn, vxlan)) - ret =vxlan_igmp_leave (vxlan); + !vxlan_group_used (vn, vxlan,NULL ,0 )) + ret =vxlan_igmp_leave (vxlan, &vxlan->default_dst.remote_ip, + vxlan->default_dst.remote_ifindex);del_timer_sync (&vxlan->age_timer);
Signature · 1 line
2.25.1
PATCH v2 6/12 vxlan_core: add helper vxlan_vni_in_use
In reply to Roopa Prabhumore users in follow up patches
--- drivers/net/vxlan/vxlan_core.c | 46 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 18 deletions(-)
drivers/net/vxlan/vxlan_core.c +28 -18
@@ -3554,13 +3554,38 @@ static int vxlan_sock_add(struct vxlan_dev *vxlan)return ret; } +static int vxlan_vni_in_use (struct net *src_net,struct vxlan_dev *vxlan, +struct vxlan_config *conf,__be32 vni) +{ +struct vxlan_net *vn =net_generic (src_net, vxlan_net_id); +struct vxlan_dev *tmp; + +list_for_each_entry (tmp, &vn->vxlan_list, next) { +if (tmp == vxlan) +continue ; +if (tmp->cfg.vni != vni) +continue ; +if (tmp->cfg.dst_port != conf->dst_port) +continue ; +if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS |VXLAN_F_IPV6 )) != + (conf->flags & (VXLAN_F_RCV_FLAGS |VXLAN_F_IPV6 ))) +continue ; + +if ((conf->flags &VXLAN_F_IPV6_LINKLOCAL ) && + tmp->cfg.remote_ifindex != conf->remote_ifindex) +continue ; + +return -EEXIST ; + } + +return 0 ; +} +static int vxlan_config_validate (struct net *src_net,struct vxlan_config *conf,struct net_device **lower,struct vxlan_dev *old,struct netlink_ext_ack *extack) { -struct vxlan_net *vn =net_generic (src_net, vxlan_net_id); -struct vxlan_dev *tmp;bool use_ipv6 = false;if (conf->flags &VXLAN_F_GPE ) {
@@ -3693,22 +3718,7 @@ static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf,if (!conf->age_interval) conf->age_interval =FDB_AGE_DEFAULT ; -list_for_each_entry (tmp, &vn->vxlan_list, next) { -if (tmp == old) -continue ; - -if (tmp->cfg.vni != conf->vni) -continue ; -if (tmp->cfg.dst_port != conf->dst_port) -continue ; -if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS |VXLAN_F_IPV6 )) != - (conf->flags & (VXLAN_F_RCV_FLAGS |VXLAN_F_IPV6 ))) -continue ; - -if ((conf->flags &VXLAN_F_IPV6_LINKLOCAL ) && - tmp->cfg.remote_ifindex != conf->remote_ifindex) -continue ; - +if (vxlan_vni_in_use (src_net, old, conf, conf->vni)) {NL_SET_ERR_MSG (extack,"A VXLAN device with the specified VNI already exists" );return -EEXIST ;
Signature · 1 line
2.25.1
PATCH v2 7/12 rtnetlink: add new rtm tunnel api for tunnel id filtering
In reply to Roopa PrabhuThis patch adds new rtm tunnel msg and api for tunnel id filtering in dst_metadata devices. First dst_metadata device to use the api is vxlan driver with AF_BRIDGE family.
This and later changes add ability in vxlan driver to do tunnel id filtering (or vni filtering) on dst_metadata devices. This is similar to vlan api in the vlan filtering bridge.
this patch includes selinux nlmsg_route_perms support for RTM_*TUNNEL api from Benjamin Poirier.
--- include/uapi/linux/if_link.h | 26 ++++++++++++++++++++++++++ include/uapi/linux/rtnetlink.h | 9 +++++++++ security/selinux/nlmsgtab.c | 5 ++++- 3 files changed, 39 insertions(+), 1 deletion(-)
include/uapi/linux/if_link.h +26 -0
@@ -712,7 +712,32 @@ enum ipvlan_mode {#define IPVLAN_F_PRIVATE 0x01#define IPVLAN_F_VEPA 0x02 +/* Tunnel RTM header */ +struct tunnel_msg { +__u8 family; +__u8 reserved1; +__u16 reserved2; +__u32 ifindex; +}; +/* VXLAN section */ +enum { +VXLAN_VNIFILTER_ENTRY_UNSPEC , +VXLAN_VNIFILTER_ENTRY_START , +VXLAN_VNIFILTER_ENTRY_END , +VXLAN_VNIFILTER_ENTRY_GROUP , +VXLAN_VNIFILTER_ENTRY_GROUP6 , + __VXLAN_VNIFILTER_ENTRY_MAX +}; +#define VXLAN_VNIFILTER_ENTRY_MAX (__VXLAN_VNIFILTER_ENTRY_MAX - 1) + +enum { +VXLAN_VNIFILTER_UNSPEC , +VXLAN_VNIFILTER_ENTRY , + __VXLAN_VNIFILTER_MAX +}; +#define VXLAN_VNIFILTER_MAX (__VXLAN_VNIFILTER_MAX - 1) +enum {IFLA_VXLAN_UNSPEC ,IFLA_VXLAN_ID ,
@@ -744,6 +769,7 @@ enum {IFLA_VXLAN_GPE ,IFLA_VXLAN_TTL_INHERIT ,IFLA_VXLAN_DF , +IFLA_VXLAN_VNIFILTER ,/* only applicable with COLLECT_METADATA mode */ __IFLA_VXLAN_MAX };#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
include/uapi/linux/rtnetlink.h +9 -0
@@ -185,6 +185,13 @@ enum { RTM_GETNEXTHOPBUCKET,#define RTM_GETNEXTHOPBUCKET RTM_GETNEXTHOPBUCKET + RTM_NEWTUNNEL = 120, +#define RTM_NEWTUNNEL RTM_NEWTUNNEL + RTM_DELTUNNEL, +#define RTM_DELTUNNEL RTM_DELTUNNEL + RTM_GETTUNNEL, +#define RTM_GETTUNNEL RTM_GETTUNNEL + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
@@ -756,6 +763,8 @@ enum rtnetlink_groups {#define RTNLGRP_BRVLAN RTNLGRP_BRVLAN RTNLGRP_MCTP_IFADDR,#define RTNLGRP_MCTP_IFADDR RTNLGRP_MCTP_IFADDR + RTNLGRP_TUNNEL, +#define RTNLGRP_TUNNEL RTNLGRP_TUNNEL __RTNLGRP_MAX };#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
security/selinux/nlmsgtab.c +4 -1
@@ -91,6 +91,9 @@ static const struct nlmsg_perm nlmsg_route_perms[] = { RTM_NEWNEXTHOPBUCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_DELNEXTHOPBUCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_GETNEXTHOPBUCKET, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_NEWTUNNEL, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, + { RTM_DELTUNNEL, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, + { RTM_GETTUNNEL, NETLINK_ROUTE_SOCKET__NLMSG_READ }, }; static const struct nlmsg_perm nlmsg_tcpdiag_perms[] =
@@ -176,7 +179,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)* structures at the top of this file with the new mappings * before updating the BUILD_BUG_ON() macro! */ -BUILD_BUG_ON (RTM_MAX != (RTM_NEWNEXTHOPBUCKET +3 )); +BUILD_BUG_ON (RTM_MAX != (RTM_NEWTUNNEL +3 )); err =nlmsg_perm (nlmsg_type, perm, nlmsg_route_perms,sizeof (nlmsg_route_perms));break ;
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 07/12] rtnetlink: add new rtm tunnel api for tunnel id filtering
include/uapi/linux/rtnetlink.h enum { · line 193
Quoted 6 lines · On Tue, 22 Feb 2022 02:52:25 +0000 Roopa Prabhu wrote:
include/uapi/linux/rtnetlink.h +6
-0+ RTM_NEWTUNNEL = 120, +#define RTM_NEWTUNNEL RTM_NEWTUNNEL + RTM_DELTUNNEL, +#define RTM_DELTUNNEL RTM_DELTUNNEL + RTM_GETTUNNEL, +#define RTM_GETTUNNEL RTM_GETTUNNEL
Why create new RTM_ commands instead of using changelink?
I thought we had to add special commands for bridge because if the target of the command is not a bridge device but possibly a bridge port, which could be anything. That's not the case here.
Is it only about the convenience of add/del vs changelink where we'd potentially have to pass and parse the entire vni list each time?
Re: [PATCH net-next v2 07/12] rtnetlink: add new rtm tunnel api for tunnel id filtering
Quoted 9 lines · Jakub Kicinski
include/uapi/linux/rtnetlink.h enum { · line 193
Quoted 6 lines · On Tue, 22 Feb 2022 02:52:25 +0000 Roopa Prabhu wrote:
include/uapi/linux/rtnetlink.h +6
-0+ RTM_NEWTUNNEL = 120, +#define RTM_NEWTUNNEL RTM_NEWTUNNEL + RTM_DELTUNNEL, +#define RTM_DELTUNNEL RTM_DELTUNNEL + RTM_GETTUNNEL, +#define RTM_GETTUNNEL RTM_GETTUNNELWhy create new
RTM_commands instead of using changelink?
Quoted 6 lines
I thought we had to add special commands for bridge because if the target of the command is not a bridge device but possibly a bridge port, which could be anything. That's not the case here.
Is it only about the convenience of add/del vs changelink where we'd potentially have to pass and parse the entire vni list each time?
yes, exactly. that's the reason. My first internal version used changelink and soon realized it was too limiting.
especially notifications. Its too heavy to notify the full vni list every-time.
IIRC bridge also went through a similar transition. Now bridge also has RTM_*VLAN commands.
Couldn't think of another way than adding a new msg. Tried to keep the name generic for use by potentially other dst/collect metadata devices
Jakub Kicinski
maintainerRe: [PATCH net-next v2 07/12] rtnetlink: add new rtm tunnel api for tunnel id filtering
Quoted 10 lines · On Tue, 22 Feb 2022 18:49:03 -0800 Roopa Prabhu wrote:
Quoted 8 lines · Jakub Kicinski
Why create new
RTM_commands instead of using changelink?I thought we had to add special commands for bridge because if the target of the command is not a bridge device but possibly a bridge port, which could be anything. That's not the case here.
Is it only about the convenience of add/del vs changelink where we'd potentially have to pass and parse the entire vni list each time?
Quoted 8 lines
yes, exactly. that's the reason. My first internal version used changelink and soon realized it was too limiting.
especially notifications. Its too heavy to notify the full vni list every-time.
IIRC bridge also went through a similar transition. Now bridge also has RTM_*VLAN commands.
Makes sense. I wasn't quite sure if this isn't over-engineering
- do deployments really use VxLAN devs with many VNIs?
Quoted 2 lines
Couldn't think of another way than adding a new msg. Tried to keep the name generic for use by potentially other dst/collect metadata devices
Ack, I don't have any better ideas either :)
Re: [PATCH net-next v2 07/12] rtnetlink: add new rtm tunnel api for tunnel id filtering
Quoted 13 lines · Jakub Kicinski
Quoted 12 lines · On Tue, 22 Feb 2022 18:49:03 -0800 Roopa Prabhu wrote:
Quoted 8 lines · Jakub Kicinski
Why create new
RTM_commands instead of using changelink?I thought we had to add special commands for bridge because if the target of the command is not a bridge device but possibly a bridge port, which could be anything. That's not the case here.
Is it only about the convenience of add/del vs changelink where we'd potentially have to pass and parse the entire vni list each time?
yes, exactly. that's the reason. My first internal version used changelink and soon realized it was too limiting.
Quoted 7 lines
Quoted 5 lines
especially notifications. Its too heavy to notify the full vni list every-time.
IIRC bridge also went through a similar transition. Now bridge also has RTM_*VLAN commands.
Makes sense. I wasn't quite sure if this isn't over-engineering
- do deployments really use VxLAN devs with many VNIs?
yes, vnis are unfortunately used to stretch layer 2 domains exceeding the 4k vlan limit
In the example provided in this series, vnis can be deployed in the ranges of more than 15k if each customer is allocated a 4k vlan range (bridge domain),
and a single switch can host 3-4 customers.
the scale is also the reason to switch to dst metadata devices when deployed vni numbers get large. The traditional vxlan netdev per vni does not work well at this scale.
Quoted 4 lines
Quoted 3 lines
Couldn't think of another way than adding a new msg. Tried to keep the name generic for use by potentially other dst/collect metadata devices
Ack, I don't have any better ideas either :)
Jakub Kicinski
maintainerRe: [PATCH net-next v2 07/12] rtnetlink: add new rtm tunnel api for tunnel id filtering
Quoted 10 lines · On Tue, 22 Feb 2022 22:31:18 -0800 Roopa Prabhu wrote:
Quoted 2 lines
Makes sense. I wasn't quite sure if this isn't over-engineering
- do deployments really use VxLAN devs with many VNIs?yes, vnis are unfortunately used to stretch layer 2 domains exceeding the 4k vlan limit
In the example provided in this series, vnis can be deployed in the ranges of more than 15k if each customer is allocated a 4k vlan range (bridge domain),
Quoted 5 lines
and a single switch can host 3-4 customers.
the scale is also the reason to switch to dst metadata devices when deployed vni numbers get large. The traditional vxlan netdev per vni does not work well at this scale.
Ah, now it all clicked together, thanks!
PATCH v2 8/12 vxlan_multicast: Move multicast helpers to a separate file
In reply to Roopa Prabhusubsequent patches will add more helpers.
--- drivers/net/vxlan/Makefile | 2 +- drivers/net/vxlan/vxlan_core.c | 123 ------------------------- drivers/net/vxlan/vxlan_multicast.c | 134 ++++++++++++++++++++++++++++ drivers/net/vxlan/vxlan_private.h | 7 ++ 4 files changed, 142 insertions(+), 124 deletions(-) create mode 100644 drivers/net/vxlan/vxlan_multicast.c
drivers/net/vxlan/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_VXLAN) += vxlan.o -vxlan-objs := vxlan_core.o +vxlan-objs := vxlan_core.o vxlan_multicast.o
drivers/net/vxlan/vxlan_core.c +0 -123
135 lines not on this page · raw message
drivers/net/vxlan/vxlan_multicast.c new file +134 -0
134 lines not on this page · raw message
drivers/net/vxlan/vxlan_private.h +7 -0
@@ -112,4 +112,11 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, __u32 ifindex, __u16 ndm_flags, u32 nhid, bool swdev_notify, struct netlink_ext_ack *extack); +/* vxlan_multicast.c */ +int vxlan_igmp_join (struct vxlan_dev *vxlan,union vxlan_addr *rip, +int rifindex); +int vxlan_igmp_leave (struct vxlan_dev *vxlan,union vxlan_addr *rip, +int rifindex); +bool vxlan_group_used (struct vxlan_net *vn,struct vxlan_dev *dev, +union vxlan_addr *rip,int rifindex);#endif
Signature · 1 line
2.25.1
PATCH v2 9/12 vxlan: vni filtering support on collect metadata device
In reply to Roopa PrabhuThis patch adds vnifiltering support to collect metadata device.
Motivation:
You can only use a single vxlan collect metadata device for a given vxlan udp port in the system today. The vxlan collect metadata device terminates all received vxlan packets. As shown in the below diagram, there are use-cases where you need to support multiple such vxlan devices in independent bridge domains. Each vxlan device must terminate the vni's it is configured for.
Example usecase: In a service provider network a service provider typically supports multiple bridge domains with overlapping vlans. One bridge domain per customer. Vlans in each bridge domain are mapped to globally unique vxlan ranges assigned to each customer.
vnifiltering support in collect metadata devices terminates only configured vnis. This is similar to vlan filtering in bridge driver. The vni filtering capability is provided by a new flag on collect metadata device.
In the below pic:
- customer1 is mapped to br1 bridge domain
- customer2 is mapped to br2 bridge domain
- customer1 vlan 10-11 is mapped to vni 1001-1002
- customer2 vlan 10-11 is mapped to vni 2001-2002
- br1 and br2 are vlan filtering bridges
- vxlan1 and vxlan2 are collect metadata devices with vnifiltering enabled
┌──────────────────────────────────────────────────────────────────┐
│ switch │
│ │
│ ┌───────────┐ ┌───────────┐ │
│ │ │ │ │ │
│ │ br1 │ │ br2 │ │
│ └┬─────────┬┘ └──┬───────┬┘ │
│ vlans│ │ vlans │ │ │
│ 10,11│ │ 10,11│ │ │
│ │ vlanvnimap: │ vlanvnimap: │
│ │ 10-1001,11-1002 │ 10-2001,11-2002 │
│ │ │ │ │ │
│ ┌──────┴┐ ┌──┴─────────┐ ┌───┴────┐ │ │
│ │ swp1 │ │vxlan1 │ │ swp2 │ ┌┴─────────────┐ │
│ │ │ │ vnifilter:│ │ │ │vxlan2 │ │
│ └───┬───┘ │ 1001,1002│ └───┬────┘ │ vnifilter: │ │
│ │ └────────────┘ │ │ 2001,2002 │ │
│ │ │ └──────────────┘ │
│ │ │ │
└───────┼──────────────────────────────────┼───────────────────────┘
│ │
│ │
┌─────┴───────┐ │
│ customer1 │ ┌─────┴──────┐
│ host/VM │ │customer2 │
└─────────────┘ │ host/VM │
└────────────┘With this implementation, vxlan dst metadata device can be associated with range of vnis.
struct vxlan_vni_node is introduced to represent a configured vni. We start with vni and its associated remote_ip in this structure. This structure can be extended to bring in other per vni attributes if there are usecases for it. A vni inherits an attribute from the base vxlan device if there is no per vni attributes defined.
struct vxlan_dev gets a new rhashtable for vnis called vxlan_vni_group. vxlan_vnifilter.c implements the necessary netlink api, notifications and helper functions to process and manage lifecycle of vxlan_vni_node.
This patch also adds new helper functions in vxlan_multicast.c to handle per vni remote_ip multicast groups which are part of vxlan_vni_group.
Fix build problems:
--- drivers/net/vxlan/Makefile | 2 +- drivers/net/vxlan/vxlan_core.c | 96 +++- drivers/net/vxlan/vxlan_multicast.c | 150 ++++- drivers/net/vxlan/vxlan_private.h | 59 +- drivers/net/vxlan/vxlan_vnifilter.c | 835 ++++++++++++++++++++++++++++ include/net/vxlan.h | 28 +- 6 files changed, 1138 insertions(+), 32 deletions(-) create mode 100644 drivers/net/vxlan/vxlan_vnifilter.c
drivers/net/vxlan/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_VXLAN) += vxlan.o -vxlan-objs := vxlan_core.o vxlan_multicast.o +vxlan-objs := vxlan_core.o vxlan_multicast.o vxlan_vnifilter.o
drivers/net/vxlan/vxlan_core.c +75 -21
199 lines not on this page · raw message
drivers/net/vxlan/vxlan_multicast.c +144 -6
167 lines not on this page · raw message
drivers/net/vxlan/vxlan_private.h +57 -2
81 lines not on this page · raw message
drivers/net/vxlan/vxlan_vnifilter.c new file +835 -0
835 lines not on this page · raw message
include/net/vxlan.h +26 -2
@@ -232,6 +232,25 @@ struct vxlan_dev_node {struct vxlan_dev *vxlan; }; +struct vxlan_vni_node { +struct rhash_head vnode; +struct vxlan_dev_node hlist4;/* vni hash table for IPv4 socket */ +#if IS_ENABLED (CONFIG_IPV6 ) +struct vxlan_dev_node hlist6;/* vni hash table for IPv6 socket */ +#endif +struct list_head vlist; +__be32 vni; +union vxlan_addr remote_ip;/* default remote ip for this vni */ + +struct rcu_head rcu; +}; + +struct vxlan_vni_group { +struct rhashtable vni_hash; +struct list_head vni_list; +u32 num_vnis; +}; +/* Pseudo network device */ struct vxlan_dev {struct vxlan_dev_node hlist4;/* vni hash table for IPv4 socket */
@@ -254,6 +273,8 @@ struct vxlan_dev {struct vxlan_config cfg; +struct vxlan_vni_group __rcu *vnigrp; +struct hlist_head fdb_head[FDB_HASH_SIZE ]; };
@@ -274,6 +295,7 @@ struct vxlan_dev {#define VXLAN_F_GPE 0x4000#define VXLAN_F_IPV6_LINKLOCAL 0x8000#define VXLAN_F_TTL_INHERIT 0x10000 +#define VXLAN_F_VNIFILTER 0x20000/* Flags that are used in the receive path. These flags must match in * order for a socket to be shareable
@@ -283,7 +305,8 @@ struct vxlan_dev { VXLAN_F_UDP_ZERO_CSUM6_RX | \ VXLAN_F_REMCSUM_RX | \ VXLAN_F_REMCSUM_NOPARTIAL | \ - VXLAN_F_COLLECT_METADATA) + VXLAN_F_COLLECT_METADATA | \ + VXLAN_F_VNIFILTER)/* Flags that can be set together with VXLAN_F_GPE. */ #define VXLAN_F_ALLOWED_GPE (VXLAN_F_GPE | \
@@ -292,7 +315,8 @@ struct vxlan_dev { VXLAN_F_UDP_ZERO_CSUM_TX | \ VXLAN_F_UDP_ZERO_CSUM6_TX | \ VXLAN_F_UDP_ZERO_CSUM6_RX | \ - VXLAN_F_COLLECT_METADATA) + VXLAN_F_COLLECT_METADATA | \ + VXLAN_F_VNIFILTER)struct net_device *vxlan_dev_create (struct net *net,const char *name,u8 name_assign_type,struct vxlan_config *conf);
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 09/12] vxlan: vni filtering support on collect metadata device
Quoted 15 lines · On Tue, 22 Feb 2022 02:52:27 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_private.h +2
-0@@ -7,6 +7,8 @@#ifndef _VXLAN_PRIVATE_H#define _VXLAN_PRIVATE_H +#include <linux/rhashtable.h> +extern unsigned int vxlan_net_id;extern const u8 all_zeros_mac[ETH_ALEN +2 ];@@ -92,6 +94,38 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
drivers/net/vxlan/vxlan_private.h bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) · line 104
Quoted 10 lines
drivers/net/vxlan/vxlan_private.h +8
-0#endif +static inline int vxlan_vni_cmp (struct rhashtable_compare_arg *arg, +const void *ptr) +{ +const struct vxlan_vni_node *vnode = ptr; +__be32 vni = *(__be32 *)arg->key; + +return vnode->vni != vni; +}
This one is called thru a pointer so can as well move to a C source with the struct, see below.
drivers/net/vxlan/vxlan_private.h bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) · line 114
Quoted 9 lines
drivers/net/vxlan/vxlan_private.h +9
-0+static const struct rhashtable_params vxlan_vni_rht_params = { + .head_offset = offsetof(struct vxlan_vni_node , vnode), + .key_offset = offsetof(struct vxlan_vni_node , vni), + .key_len =sizeof (__be32), + .nelem_hint =3 , + .max_size =VXLAN_N_VID , + .obj_cmpfn = vxlan_vni_cmp, + .automatic_shrinking = true, +};
struct definition in the header? Shouldn't it be an extern and definition in a C file?
Quoted 12 lines
drivers/net/vxlan/vxlan_private.h +12
-0+static inline struct vxlan_vni_node * +vxlan_vnifilter_lookup (struct vxlan_dev *vxlan,__be32 vni) +{ +struct vxlan_vni_group *vg; + + vg =rcu_dereference_rtnl (vxlan->vnigrp); +if (!vg) +return NULL ; + +return rhashtable_lookup_fast (&vg->vni_hash, &vni, + vxlan_vni_rht_params); +}
Re: [PATCH net-next v2 09/12] vxlan: vni filtering support on collect metadata device
Quoted 29 lines · Jakub Kicinski
Quoted 15 lines · On Tue, 22 Feb 2022 02:52:27 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_private.h +2
-0@@ -7,6 +7,8 @@#ifndef _VXLAN_PRIVATE_H#define _VXLAN_PRIVATE_H +#include <linux/rhashtable.h> +extern unsigned int vxlan_net_id;extern const u8 all_zeros_mac[ETH_ALEN +2 ];@@ -92,6 +94,38 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)drivers/net/vxlan/vxlan_private.h bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) · line 104
Quoted 10 lines
drivers/net/vxlan/vxlan_private.h +8
-0#endif +static inline int vxlan_vni_cmp (struct rhashtable_compare_arg *arg, +const void *ptr) +{ +const struct vxlan_vni_node *vnode = ptr; +__be32 vni = *(__be32 *)arg->key; + +return vnode->vni != vni; +}This one is called thru a pointer so can as well move to a C source with the struct, see below.
Quoted 11 lines
drivers/net/vxlan/vxlan_private.h bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) · line 114
Quoted 9 lines
drivers/net/vxlan/vxlan_private.h +9
-0+static const struct rhashtable_params vxlan_vni_rht_params = { + .head_offset = offsetof(struct vxlan_vni_node , vnode), + .key_offset = offsetof(struct vxlan_vni_node , vni), + .key_len =sizeof (__be32), + .nelem_hint =3 , + .max_size =VXLAN_N_VID , + .obj_cmpfn = vxlan_vni_cmp, + .automatic_shrinking = true, +};struct definition in the header? Shouldn't it be an extern and definition in a C file?
dont remember why i accidentally moved it to the header file a few internal revisions back.
you are correct. Will fix. thanks.
Jakub Kicinski
maintainerRe: [PATCH net-next v2 09/12] vxlan: vni filtering support on collect metadata device
In reply to Roopa PrabhuQuoted 17 lines · On Tue, 22 Feb 2022 02:52:27 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_vnifilter.c new file +17
-0+static int vxlan_vni_add (struct vxlan_dev *vxlan, +struct vxlan_vni_group *vg, +u32 vni,union vxlan_addr *group, +struct netlink_ext_ack *extack) +{ +struct vxlan_vni_node *vninode; +__be32 v =cpu_to_be32 (vni); +bool changed = false; +int err =0 ; + +if (vxlan_vnifilter_lookup (vxlan, v)) +return vxlan_vni_update (vxlan, vg, v, group, &changed, extack); + + err =vxlan_vni_in_use (vxlan->net, vxlan, &vxlan->cfg, v); +if (err) { +NL_SET_ERR_MSG (extack,"VNI in use" ); +return err;
drivers/net/vxlan/vxlan_vnifilter.c line 577
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+ } + + vninode =vxlan_vni_alloc (vxlan, v); +if (!vninode) +return -ENOMEM ; + + err =rhashtable_lookup_insert_fast (&vg->vni_hash, + &vninode->vnode, + vxlan_vni_rht_params); +if (err)
leak ?
Quoted 13 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +13
-0+return err; + +__vxlan_vni_add_list (vg, vninode); + +if (vxlan->dev->flags &IFF_UP ) +vxlan_vs_add_del_vninode (vxlan, vninode, false); + + err =vxlan_vni_update_group (vxlan, vninode, group, true, &changed, + extack); + +if (changed) +vxlan_vnifilter_notify (vxlan, vninode,RTM_NEWTUNNEL ); +
drivers/net/vxlan/vxlan_vnifilter.c line 600
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+return err; +} + +static void vxlan_vni_node_rcu_free (struct rcu_head *rcu) +{ +struct vxlan_vni_node *v; + + v = container_of(rcu, struct vxlan_vni_node, rcu); +kfree (v); +}
kfree_rcu()?
Quoted 67 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +67
-0+static int vxlan_vni_del (struct vxlan_dev *vxlan, +struct vxlan_vni_group *vg, +u32 vni,struct netlink_ext_ack *extack) +{ +struct vxlan_vni_node *vninode; +__be32 v =cpu_to_be32 (vni); +int err =0 ; + + vg =rtnl_dereference (vxlan->vnigrp); + + vninode =rhashtable_lookup_fast (&vg->vni_hash, &v, + vxlan_vni_rht_params); +if (!vninode) { + err = -ENOENT ; + goto out; + } + +vxlan_vni_delete_group (vxlan, vninode); + + err =rhashtable_remove_fast (&vg->vni_hash, + &vninode->vnode, + vxlan_vni_rht_params); +if (err) + goto out; + +__vxlan_vni_del_list (vg, vninode); + +vxlan_vnifilter_notify (vxlan, vninode,RTM_DELTUNNEL ); + +if (vxlan->dev->flags &IFF_UP ) +vxlan_vs_add_del_vninode (vxlan, vninode, true); + +call_rcu (&vninode->rcu, vxlan_vni_node_rcu_free); + +return 0 ; +out: +return err; +} + +static int vxlan_vni_add_del (struct vxlan_dev *vxlan,__u32 start_vni, +__u32 end_vni,union vxlan_addr *group, +int cmd,struct netlink_ext_ack *extack) +{ +struct vxlan_vni_group *vg; +int v, err =0 ; + + vg =rtnl_dereference (vxlan->vnigrp); + +for (v = start_vni; v <= end_vni; v++) { +switch (cmd) { +case RTM_NEWTUNNEL : + err =vxlan_vni_add (vxlan, vg, v, group, extack); +break ; +case RTM_DELTUNNEL : + err =vxlan_vni_del (vxlan, vg, v, extack); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } +if (err) + goto out; + } + +return 0 ; +out: +return err;
drivers/net/vxlan/vxlan_vnifilter.c line 678
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+} + +static int vxlan_process_vni_filter (struct vxlan_dev *vxlan, +struct nlattr *nlvnifilter, +int cmd,struct netlink_ext_ack *extack) +{ +struct nlattr *vattrs[VXLAN_VNIFILTER_ENTRY_MAX +1 ]; +u32 vni_start =0 , vni_end =0 ; +union vxlan_addr group; +int err =0 ;
unnecessary init
Quoted 44 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +44
-0+ err =nla_parse_nested (vattrs, +VXLAN_VNIFILTER_ENTRY_MAX , + nlvnifilter, vni_filter_entry_policy, + extack); +if (err) +return err; + +if (vattrs[VXLAN_VNIFILTER_ENTRY_START ]) { + vni_start =nla_get_u32 (vattrs[VXLAN_VNIFILTER_ENTRY_START ]); + vni_end = vni_start; + } + +if (vattrs[VXLAN_VNIFILTER_ENTRY_END ]) + vni_end =nla_get_u32 (vattrs[VXLAN_VNIFILTER_ENTRY_END ]); + +if (!vni_start && !vni_end) { +NL_SET_ERR_MSG_ATTR (extack, nlvnifilter, +"vni start nor end found in vni entry" ); +return -EINVAL ; + } + +if (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP ]) { + group.sin.sin_addr.s_addr = +nla_get_in_addr (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP ]); + group.sa.sa_family =AF_INET ; + }else if (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP6 ]) { + group.sin6.sin6_addr = +nla_get_in6_addr (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP6 ]); + group.sa.sa_family =AF_INET6 ; + }else { +memset (&group,0 ,sizeof (group)); + } + + err =vxlan_vni_add_del (vxlan, vni_start, vni_end, &group, cmd, + extack); +if (err) +return err; + +return 0 ; +} + +void vxlan_vnigroup_uninit (struct vxlan_dev *vxlan) +{ +struct vxlan_vni_node *v, *tmp;
drivers/net/vxlan/vxlan_vnifilter.c line 733
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+struct vxlan_vni_group *vg; + + vg =rtnl_dereference (vxlan->vnigrp); +list_for_each_entry_safe (v, tmp, &vg->vni_list, vlist) { +rhashtable_remove_fast (&vg->vni_hash, &v->vnode, + vxlan_vni_rht_params); +hlist_del_init_rcu (&v->hlist4.hlist); +#if IS_ENABLED (CONFIG_IPV6 ) +hlist_del_init_rcu (&v->hlist6.hlist); +#endif
no need to generate the notifications here?
Quoted 5 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +5
-0+__vxlan_vni_del_list (vg, v); +call_rcu (&v->rcu, vxlan_vni_node_rcu_free); + } +rhashtable_destroy (&vg->vni_hash); +kfree (vg);
drivers/net/vxlan/vxlan_vnifilter.c line 748
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+} + +int vxlan_vnigroup_init (struct vxlan_dev *vxlan) +{ +struct vxlan_vni_group *vg; +int ret = -ENOMEM ; + + vg =kzalloc (sizeof (*vg),GFP_KERNEL ); +if (!vg) + goto out;
return -ENOMEM;
the jumping dance is really not worth it here
Quoted 21 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +21
-0+ ret =rhashtable_init (&vg->vni_hash, &vxlan_vni_rht_params); +if (ret) + goto err_rhtbl; +INIT_LIST_HEAD (&vg->vni_list); +rcu_assign_pointer (vxlan->vnigrp, vg); + +return 0 ; + +out: +return ret; + +err_rhtbl: +kfree (vg); + + goto out; +} + +static int vxlan_vnifilter_process (struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack) +{ +struct net *net =sock_net (skb->sk);
drivers/net/vxlan/vxlan_vnifilter.c line 779
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+struct tunnel_msg *tmsg; +struct vxlan_dev *vxlan; +struct net_device *dev; +struct nlattr *attr; +int err, vnis =0 ; +int rem; + +/* this should validate the header and check for remaining bytes */ + err =nlmsg_parse (nlh,sizeof (*tmsg),NULL ,VXLAN_VNIFILTER_MAX ,NULL , + extack);
Could be useful to provide a policy here, even if it only points to single type (entry which is nested). Otherwise we will not reject UNSPEC, and validate if ENTRY has NLA_F_NESTED set, no?
Quoted 39 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +39
-0+if (err <0 ) +return err; + + tmsg =nlmsg_data (nlh); + dev =__dev_get_by_index (net, tmsg->ifindex); +if (!dev) +return -ENODEV ; + +if (!netif_is_vxlan (dev)) { +NL_SET_ERR_MSG_MOD (extack,"The device is not a vxlan device" ); +return -EINVAL ; + } + + vxlan =netdev_priv (dev); + +if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +return -EOPNOTSUPP ; + +nlmsg_for_each_attr (attr, nlh,sizeof (*tmsg), rem) { +switch (nla_type (attr)) { +case VXLAN_VNIFILTER_ENTRY : + err =vxlan_process_vni_filter (vxlan, attr, + nlh->nlmsg_type, extack); +break ; +default : +continue ; + } + vnis++; +if (err) +break ; + } + +if (!vnis) { +NL_SET_ERR_MSG_MOD (extack,"No vnis found to process" ); + err = -EINVAL ; + } + +return err; +}
Re: [PATCH net-next v2 09/12] vxlan: vni filtering support on collect metadata device
Quoted 21 lines · Jakub Kicinski
Quoted 20 lines · On Tue, 22 Feb 2022 02:52:27 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_vnifilter.c new file +20
-0+static int vxlan_vni_add (struct vxlan_dev *vxlan, +struct vxlan_vni_group *vg, +u32 vni,union vxlan_addr *group, +struct netlink_ext_ack *extack) +{ +struct vxlan_vni_node *vninode; +__be32 v =cpu_to_be32 (vni); +bool changed = false; +int err =0 ; + +if (vxlan_vnifilter_lookup (vxlan, v)) +return vxlan_vni_update (vxlan, vg, v, group, &changed, extack); + + err =vxlan_vni_in_use (vxlan->net, vxlan, &vxlan->cfg, v); +if (err) { +NL_SET_ERR_MSG (extack,"VNI in use" ); +return err; + } + + vninode =vxlan_vni_alloc (vxlan, v);
Quoted 8 lines
drivers/net/vxlan/vxlan_vnifilter.c line 577
Quoted 7 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +7
-0+if (!vninode) +return -ENOMEM ; + + err =rhashtable_lookup_insert_fast (&vg->vni_hash, + &vninode->vnode, + vxlan_vni_rht_params); +if (err)leak ?
ouch, will fix.
Quoted 17 lines
Quoted 17 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +16
-0+return err; + +__vxlan_vni_add_list (vg, vninode); + +if (vxlan->dev->flags &IFF_UP ) +vxlan_vs_add_del_vninode (vxlan, vninode, false); + + err =vxlan_vni_update_group (vxlan, vninode, group, true, &changed, + extack); + +if (changed) +vxlan_vnifilter_notify (vxlan, vninode,RTM_NEWTUNNEL ); + +return err; +} +
Quoted 8 lines
drivers/net/vxlan/vxlan_vnifilter.c line 600
Quoted 7 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +7
-0+static void vxlan_vni_node_rcu_free (struct rcu_head *rcu) +{ +struct vxlan_vni_node *v; + + v = container_of(rcu, struct vxlan_vni_node, rcu); +kfree (v); +}
kfree_rcu()?
you are right it can move it to kfree_rcu in this patch. But, later in the stats patch, this also frees up stats.
so, wont be able to switch it to kfree_rcu. but will look again.
Quoted 127 lines
Quoted 68 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +67
-0+static int vxlan_vni_del (struct vxlan_dev *vxlan, +struct vxlan_vni_group *vg, +u32 vni,struct netlink_ext_ack *extack) +{ +struct vxlan_vni_node *vninode; +__be32 v =cpu_to_be32 (vni); +int err =0 ; + + vg =rtnl_dereference (vxlan->vnigrp); + + vninode =rhashtable_lookup_fast (&vg->vni_hash, &v, + vxlan_vni_rht_params); +if (!vninode) { + err = -ENOENT ; + goto out; + } + +vxlan_vni_delete_group (vxlan, vninode); + + err =rhashtable_remove_fast (&vg->vni_hash, + &vninode->vnode, + vxlan_vni_rht_params); +if (err) + goto out; + +__vxlan_vni_del_list (vg, vninode); + +vxlan_vnifilter_notify (vxlan, vninode,RTM_DELTUNNEL ); + +if (vxlan->dev->flags &IFF_UP ) +vxlan_vs_add_del_vninode (vxlan, vninode, true); + +call_rcu (&vninode->rcu, vxlan_vni_node_rcu_free); + +return 0 ; +out: +return err; +} + +static int vxlan_vni_add_del (struct vxlan_dev *vxlan,__u32 start_vni, +__u32 end_vni,union vxlan_addr *group, +int cmd,struct netlink_ext_ack *extack) +{ +struct vxlan_vni_group *vg; +int v, err =0 ; + + vg =rtnl_dereference (vxlan->vnigrp); + +for (v = start_vni; v <= end_vni; v++) { +switch (cmd) { +case RTM_NEWTUNNEL : + err =vxlan_vni_add (vxlan, vg, v, group, extack); +break ; +case RTM_DELTUNNEL : + err =vxlan_vni_del (vxlan, vg, v, extack); +break ; +default : + err = -EOPNOTSUPP ; +break ; + } +if (err) + goto out; + } + +return 0 ; +out: +return err;drivers/net/vxlan/vxlan_vnifilter.c line 678
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +10
-0+} + +static int vxlan_process_vni_filter (struct vxlan_dev *vxlan, +struct nlattr *nlvnifilter, +int cmd,struct netlink_ext_ack *extack) +{ +struct nlattr *vattrs[VXLAN_VNIFILTER_ENTRY_MAX +1 ]; +u32 vni_start =0 , vni_end =0 ; +union vxlan_addr group; +int err =0 ;unnecessary init
Quoted 47 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +47
-0+ err =nla_parse_nested (vattrs, +VXLAN_VNIFILTER_ENTRY_MAX , + nlvnifilter, vni_filter_entry_policy, + extack); +if (err) +return err; + +if (vattrs[VXLAN_VNIFILTER_ENTRY_START ]) { + vni_start =nla_get_u32 (vattrs[VXLAN_VNIFILTER_ENTRY_START ]); + vni_end = vni_start; + } + +if (vattrs[VXLAN_VNIFILTER_ENTRY_END ]) + vni_end =nla_get_u32 (vattrs[VXLAN_VNIFILTER_ENTRY_END ]); + +if (!vni_start && !vni_end) { +NL_SET_ERR_MSG_ATTR (extack, nlvnifilter, +"vni start nor end found in vni entry" ); +return -EINVAL ; + } + +if (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP ]) { + group.sin.sin_addr.s_addr = +nla_get_in_addr (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP ]); + group.sa.sa_family =AF_INET ; + }else if (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP6 ]) { + group.sin6.sin6_addr = +nla_get_in6_addr (vattrs[VXLAN_VNIFILTER_ENTRY_GROUP6 ]); + group.sa.sa_family =AF_INET6 ; + }else { +memset (&group,0 ,sizeof (group)); + } + + err =vxlan_vni_add_del (vxlan, vni_start, vni_end, &group, cmd, + extack); +if (err) +return err; + +return 0 ; +} + +void vxlan_vnigroup_uninit (struct vxlan_dev *vxlan) +{ +struct vxlan_vni_node *v, *tmp; +struct vxlan_vni_group *vg; + + vg =rtnl_dereference (vxlan->vnigrp);
Quoted 8 lines
drivers/net/vxlan/vxlan_vnifilter.c line 733
Quoted 7 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +7
-0+list_for_each_entry_safe (v, tmp, &vg->vni_list, vlist) { +rhashtable_remove_fast (&vg->vni_hash, &v->vnode, + vxlan_vni_rht_params); +hlist_del_init_rcu (&v->hlist4.hlist); +#if IS_ENABLED (CONFIG_IPV6 ) +hlist_del_init_rcu (&v->hlist6.hlist); +#endif no need to generate the notifications here?
great catch, will fix.
Quoted 10 lines
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +9
-0+__vxlan_vni_del_list (vg, v); +call_rcu (&v->rcu, vxlan_vni_node_rcu_free); + } +rhashtable_destroy (&vg->vni_hash); +kfree (vg); +} + +int vxlan_vnigroup_init (struct vxlan_dev *vxlan) +{
Quoted 8 lines
drivers/net/vxlan/vxlan_vnifilter.c line 748
Quoted 6 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +6
-0+struct vxlan_vni_group *vg; +int ret = -ENOMEM ; + + vg =kzalloc (sizeof (*vg),GFP_KERNEL ); +if (!vg) + goto out;return
-ENOMEM;
the jumping dance is really not worth it here
agreed :)
Quoted 26 lines
Quoted 26 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +26
-0+ ret =rhashtable_init (&vg->vni_hash, &vxlan_vni_rht_params); +if (ret) + goto err_rhtbl; +INIT_LIST_HEAD (&vg->vni_list); +rcu_assign_pointer (vxlan->vnigrp, vg); + +return 0 ; + +out: +return ret; + +err_rhtbl: +kfree (vg); + + goto out; +} + +static int vxlan_vnifilter_process (struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack) +{ +struct net *net =sock_net (skb->sk); +struct tunnel_msg *tmsg; +struct vxlan_dev *vxlan; +struct net_device *dev; +struct nlattr *attr; +int err, vnis =0 ;
Quoted 8 lines
drivers/net/vxlan/vxlan_vnifilter.c line 779
Quoted 5 lines
drivers/net/vxlan/vxlan_vnifilter.c new file +5
-0+int rem; + +/* this should validate the header and check for remaining bytes */ + err =nlmsg_parse (nlh,sizeof (*tmsg),NULL ,VXLAN_VNIFILTER_MAX ,NULL , + extack);Could be useful to provide a policy here, even if it only points to single type (entry which is nested). Otherwise we will not reject UNSPEC, and validate if ENTRY has
NLA_F_NESTEDset, no?
yeah, any policy is better than no policy, will fix.
thanks for the review!
PATCH v2 10/12 selftests: add new tests for vxlan vnifiltering
In reply to Roopa PrabhuThis patch adds a new test script test_vxlan_vnifiltering.sh with tests for vni filtering api, various datapath tests. Also has a test with a mix of traditional, metadata and vni filtering devices inuse at the same time.
--- .../selftests/net/test_vxlan_vnifiltering.sh | 581 ++++++++++++++++++ 1 file changed, 581 insertions(+) create mode 100755 tools/testing/selftests/net/test_vxlan_vnifiltering.sh
tools/testing/selftests/net/test_vxlan_vnifiltering.sh new file +581 -0
@@ -0,0 +1,581 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# This test is for checking the VXLAN vni filtering api and +# datapath. +# It simulates two hypervisors running two VMs each using four network +# six namespaces: two for the HVs, four for the VMs. Each VM is +# connected to a separate bridge. The VM's use overlapping vlans and +# hence the separate bridge domain. Each vxlan device is a collect +# metadata device with vni filtering and hence has the ability to +# terminate configured vni's only. + +# +--------------------------------+ +------------------------------------+ +# | vm-11 netns | | vm-21 netns | +# | | | | +# |+------------+ +-------------+ | |+-------------+ +----------------+ | +# ||veth-11.10 | |veth-11.20 | | ||veth-21.10 | | veth-21.20 | | +# ||10.0.10.11/24 |10.0.20.11/24| | ||10.0.10.21/24| | 10.0.20.21/24 | | +# |+------|-----+ +|------------+ | |+-----------|-+ +---|------------+ | +# | | | | | | | | +# | | | | | +------------+ | +# | +------------+ | | | veth-21 | | +# | | veth-11 | | | | | | +# | | | | | +-----|------+ | +# | +-----|------+ | | | | +# | | | | | | +# +------------|-------------------+ +---------------|--------------------+ +# +------------|-----------------------------------------|-------------------+ +# | +-----|------+ +-----|------+ | +# | |vethhv-11 | |vethhv-21 | | +# | +----|-------+ +-----|------+ | +# | +---|---+ +---|--+ | +# | | br1 | | br2 | | +# | +---|---+ +---|--+ | +# | +---|----+ +---|--+ | +# | | vxlan1| |vxlan2| | +# | +--|-----+ +--|---+ | +# | | | | +# | | +---------------------+ | | +# | | |veth0 | | | +# | +---------|172.16.0.1/24 -----------+ | +# | |2002:fee1::1/64 | | +# | hv-1 netns +--------|------------+ | +# +-----------------------------|--------------------------------------------+ +# | +# +-----------------------------|--------------------------------------------+ +# | hv-2 netns +--------|-------------+ | +# | | veth0 | | +# | +------| 172.16.0.2/24 |---+ | +# | | | 2002:fee1::2/64 | | | +# | | | | | | +# | | +----------------------+ | - | +# | | | | +# | +-|-------+ +--------|-+ | +# | | vxlan1 | | vxlan2 | | +# | +----|----+ +---|------+ | +# | +--|--+ +-|---+ | +# | | br1 | | br2 | | +# | +--|--+ +--|--+ | +# | +-----|-------+ +----|-------+ | +# | | vethhv-12 | |vethhv-22 | | +# | +------|------+ +-------|----+ | +# +-----------------|----------------------------|---------------------------+ +# | | +# +-----------------|-----------------+ +--------|---------------------------+ +# | +-------|---+ | | +--|---------+ | +# | | veth-12 | | | |veth-22 | | +# | +-|--------|+ | | +--|--------|+ | +# | | | | | | | | +# |+----------|--+ +---|-----------+ | |+-------|-----+ +|---------------+ | +# ||veth-12.10 | |veth-12.20 | | ||veth-22.10 | |veth-22.20 | | +# ||10.0.10.12/24| |10.0.20.12/24 | | ||10.0.10.22/24| |10.0.20.22/24 | | +# |+-------------+ +---------------+ | |+-------------+ +----------------+ | +# | | | | +# | | | | +# | vm-12 netns | |vm-22 netns | +# +-----------------------------------+ +------------------------------------+ +# +# +# This test tests the new vxlan vnifiltering api + +ret=0 +# Kselftest framework requirement - SKIP code is 4. +ksft_skip=4 + +# all tests in this script. Can be overridden with -t option +TESTS=" + vxlan_vnifilter_api + vxlan_vnifilter_datapath + vxlan_vnifilter_datapath_pervni + vxlan_vnifilter_datapath_mgroup + vxlan_vnifilter_datapath_mgroup_pervni + vxlan_vnifilter_metadata_and_traditional_mix +" +VERBOSE=0 +PAUSE_ON_FAIL=no +PAUSE=no +IP="ip -netns ns1" +NS_EXEC="ip netns exec ns1" + +which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) + +log_test() +{ + local rc=$1 + local expected=$2 + local msg="$3" + + if [ ${rc} -eq ${expected} ]; then + printf " TEST: %-60s [ OK ]\n" "${msg}" + nsuccess=$((nsuccess+1)) + else + ret=1 + nfail=$((nfail+1)) + printf " TEST: %-60s [FAIL]\n" "${msg}" + if [ "${PAUSE_ON_FAIL}" = "yes" ]; then + echo + echo "hit enter to continue, 'q' to quit" + read a + [ "$a" = "q" ] && exit 1 + fi + fi + + if [ "${PAUSE}" = "yes" ]; then + echo + echo "hit enter to continue, 'q' to quit" + read a + [ "$a" = "q" ] && exit 1 + fi +} + +run_cmd() +{ + local cmd="$1" + local out + local stderr="2>/dev/null" + + if [ "$VERBOSE" = "1" ]; then + printf "COMMAND: $cmd\n" + stderr= + fi + + out=$(eval $cmd $stderr) + rc=$? + if [ "$VERBOSE" = "1" -a -n "$out" ]; then + echo " $out" + fi + + return $rc +} + +check_hv_connectivity() { + ip netns exec hv-1 ping -c 1 -W 1 $1 &>/dev/null + sleep 1 + ip netns exec hv-1 ping -c 1 -W 1 $2 &>/dev/null + + return $? +} + +check_vm_connectivity() { + run_cmd "ip netns exec vm-11 ping -c 1 -W 1 10.0.10.12" + log_test $? 0 "VM connectivity over $1 (ipv4 default rdst)" + + run_cmd "ip netns exec vm-21 ping -c 1 -W 1 10.0.10.22" + log_test $? 0 "VM connectivity over $1 (ipv6 default rdst)" +} + +cleanup() { + ip link del veth-hv-1 2>/dev/null || true + ip link del vethhv-11 vethhv-12 vethhv-21 vethhv-22 2>/dev/null || true + + for ns in hv-1 hv-2 vm-11 vm-21 vm-12 vm-22 vm-31 vm-32; do + ip netns del $ns 2>/dev/null || true + done +} + +trap cleanup EXIT + +setup-hv-networking() { + hv=$1 + local1=$2 + mask1=$3 + local2=$4 + mask2=$5 + + ip netns add hv-$hv + ip link set veth-hv-$hv netns hv-$hv + ip -netns hv-$hv link set veth-hv-$hv name veth0 + ip -netns hv-$hv addr add $local1/$mask1 dev veth0 + ip -netns hv-$hv addr add $local2/$mask2 dev veth0 + ip -netns hv-$hv link set veth0 up +} + +# Setups a "VM" simulated by a netns an a veth pair +# example: setup-vm <hvid> <vmid> <brid> <VATTRS> <mcast_for_bum> +# VATTRS = comma separated "<vlan>-<v[46]>-<localip>-<remoteip>-<VTYPE>-<vxlandstport>" +# VTYPE = vxlan device type. "default = traditional device, metadata = metadata device +# vnifilter = vnifiltering device, +# vnifilterg = vnifiltering device with per vni group/remote" +# example: +# setup-vm 1 11 1 \ +# 10-v4-172.16.0.1-239.1.1.100-vnifilterg,20-v4-172.16.0.1-239.1.1.100-vnifilterg 1 +# +setup-vm() { + hvid=$1 + vmid=$2 + brid=$3 + vattrs=$4 + mcast=$5 + lastvxlandev="" + + # create bridge + ip -netns hv-$hvid link add br$brid type bridge vlan_filtering 1 vlan_default_pvid 0 \ + mcast_snooping 0 + ip -netns hv-$hvid link set br$brid up + + # create vm namespace and interfaces and connect to hypervisor + # namespace + ip netns add vm-$vmid + hvvethif="vethhv-$vmid" + vmvethif="veth-$vmid" + ip link add $hvvethif type veth peer name $vmvethif + ip link set $hvvethif netns hv-$hvid + ip link set $vmvethif netns vm-$vmid + ip -netns hv-$hvid link set $hvvethif up + ip -netns vm-$vmid link set $vmvethif up + ip -netns hv-$hvid link set $hvvethif master br$brid + + # configure VM vlan/vni filtering on hypervisor + for vmap in $(echo $vattrs | cut -d "," -f1- --output-delimiter=' ') + do + local vid=$(echo $vmap | awk -F'-' '{print ($1)}') + local family=$(echo $vmap | awk -F'-' '{print ($2)}') + local localip=$(echo $vmap | awk -F'-' '{print ($3)}') + local group=$(echo $vmap | awk -F'-' '{print ($4)}') + local vtype=$(echo $vmap | awk -F'-' '{print ($5)}') + local port=$(echo $vmap | awk -F'-' '{print ($6)}') + + ip -netns vm-$vmid link add name $vmvethif.$vid link $vmvethif type vlan id $vid + ip -netns vm-$vmid addr add 10.0.$vid.$vmid/24 dev $vmvethif.$vid + ip -netns vm-$vmid link set $vmvethif.$vid up + + tid=$vid + vxlandev="vxlan$brid" + vxlandevflags="" + + if [[ -n $vtype && $vtype == "metadata" ]]; then + vxlandevflags="$vxlandevflags external" + elif [[ -n $vtype && $vtype == "vnifilter" || $vtype == "vnifilterg" ]]; then + vxlandevflags="$vxlandevflags external vnifilter" + tid=$((vid+brid)) + else + vxlandevflags="$vxlandevflags id $tid" + vxlandev="vxlan$tid" + fi + + if [[ -n $vtype && $vtype != "vnifilterg" ]]; then + if [[ -n "$group" && "$group" != "null" ]]; then + if [ $mcast -eq 1 ]; then + vxlandevflags="$vxlandevflags group $group" + else + vxlandevflags="$vxlandevflags remote $group" + fi + fi + fi + + if [[ -n "$port" && "$port" != "default" ]]; then + vxlandevflags="$vxlandevflags dstport $port" + fi + + # create vxlan device + if [ "$vxlandev" != "$lastvxlandev" ]; then + ip -netns hv-$hvid link add $vxlandev type vxlan local $localip $vxlandevflags dev veth0 2>/dev/null + ip -netns hv-$hvid link set $vxlandev master br$brid + ip -netns hv-$hvid link set $vxlandev up + lastvxlandev=$vxlandev + fi + + # add vlan + bridge -netns hv-$hvid vlan add vid $vid dev $hvvethif + bridge -netns hv-$hvid vlan add vid $vid pvid dev $vxlandev + + # Add bridge vni filter for tx + if [[ -n $vtype && $vtype == "metadata" || $vtype == "vnifilter" || $vtype == "vnifilterg" ]]; then + bridge -netns hv-$hvid link set dev $vxlandev vlan_tunnel on + bridge -netns hv-$hvid vlan add dev $vxlandev vid $vid tunnel_info id $tid + fi + + if [[ -n $vtype && $vtype == "metadata" ]]; then + bridge -netns hv-$hvid fdb add 00:00:00:00:00:00 dev $vxlandev \ + src_vni $tid vni $tid dst $group self + elif [[ -n $vtype && $vtype == "vnifilter" ]]; then + # Add per vni rx filter with 'bridge vni' api + bridge -netns hv-$hvid vni add dev $vxlandev vni $tid + elif [[ -n $vtype && $vtype == "vnifilterg" ]]; then + # Add per vni group config with 'bridge vni' api + if [ -n "$group" ]; then + if [ "$family" == "v4" ]; then + if [ $mcast -eq 1 ]; then + bridge -netns hv-$hvid vni add dev $vxlandev vni $tid group $group + else + bridge -netns hv-$hvid vni add dev $vxlandev vni $tid remote $group + fi + else + if [ $mcast -eq 1 ]; then + bridge -netns hv-$hvid vni add dev $vxlandev vni $tid group6 $group + else + bridge -netns hv-$hvid vni add dev $vxlandev vni $tid remote6 $group + fi + fi + fi + fi + done +} + +setup_vnifilter_api() +{ + ip link add veth-host type veth peer name veth-testns + ip netns add testns + ip link set veth-testns netns testns +} + +cleanup_vnifilter_api() +{ + ip link del veth-host 2>/dev/null || true + ip netns del testns 2>/dev/null || true +} + +# tests vxlan filtering api +vxlan_vnifilter_api() +{ + hv1addr1="172.16.0.1" + hv2addr1="172.16.0.2" + hv1addr2="2002:fee1::1" + hv2addr2="2002:fee1::2" + localip="172.16.0.1" + group="239.1.1.101" + + cleanup_vnifilter_api &>/dev/null + setup_vnifilter_api + + # Duplicate vni test + # create non-vnifiltering traditional vni device + run_cmd "ip -netns testns link add vxlan100 type vxlan id 100 local $localip dev veth-testns dstport 4789" + log_test $? 0 "Create traditional vxlan device" + + # create vni filtering device + run_cmd "ip -netns testns link add vxlan-ext1 type vxlan vnifilter local $localip dev veth-testns dstport 4789" + log_test $? 1 "Cannot create vnifilter device without external flag" + + run_cmd "ip -netns testns link add vxlan-ext1 type vxlan external vnifilter local $localip dev veth-testns dstport 4789" + log_test $? 0 "Creating external vxlan device with vnifilter flag" + + run_cmd "bridge -netns testns vni add dev vxlan-ext1 vni 100" + log_test $? 0 "Cannot set in-use vni id on vnifiltering device" + + run_cmd "bridge -netns testns vni add dev vxlan-ext1 vni 200" + log_test $? 0 "Set new vni id on vnifiltering device" + + run_cmd "ip -netns testns link add vxlan-ext2 type vxlan external vnifilter local $localip dev veth-testns dstport 4789" + log_test $? 0 "Create second external vxlan device with vnifilter flag" + + run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 200" + log_test $? 255 "Cannot set in-use vni id on vnifiltering device" + + run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 300" + log_test $? 0 "Set new vni id on vnifiltering device" + + # check in bridge vni show + run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 300" + log_test $? 0 "Update vni id on vnifiltering device" + + run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 400" + log_test $? 0 "Add new vni id on vnifiltering device" + + # add multicast group per vni + run_cmd "bridge -netns testns vni add dev vxlan-ext1 vni 200 group $group" + log_test $? 0 "Set multicast group on existing vni" + + # add multicast group per vni + run_cmd "bridge -netns testns vni add dev vxlan-ext2 vni 300 group $group" + log_test $? 0 "Set multicast group on existing vni" + + # set vnifilter on an existing external vxlan device + run_cmd "ip -netns testns link set dev vxlan-ext1 type vxlan external vnifilter" + log_test $? 2 "Cannot set vnifilter flag on a device" + + # change vxlan vnifilter flag + run_cmd "ip -netns testns link set dev vxlan-ext1 type vxlan external novnifilter" + log_test $? 2 "Cannot unset vnifilter flag on a device" +} + +# Sanity test vnifilter datapath +# vnifilter vnis inherit BUM group from +# vxlan device +vxlan_vnifilter_datapath() +{ + hv1addr1="172.16.0.1" + hv2addr1="172.16.0.2" + hv1addr2="2002:fee1::1" + hv2addr2="2002:fee1::2" + + ip link add veth-hv-1 type veth peer name veth-hv-2 + setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64 $hv2addr1 $hv2addr2 + setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64 $hv1addr1 $hv1addr2 + + check_hv_connectivity hv2addr1 hv2addr2 + + setup-vm 1 11 1 10-v4-$hv1addr1-$hv2addr1-vnifilter,20-v4-$hv1addr1-$hv2addr1-vnifilter 0 + setup-vm 1 21 2 10-v6-$hv1addr2-$hv2addr2-vnifilter,20-v6-$hv1addr2-$hv2addr2-vnifilter 0 + + setup-vm 2 12 1 10-v4-$hv2addr1-$hv1addr1-vnifilter,20-v4-$hv2addr1-$hv1addr1-vnifilter 0 + setup-vm 2 22 2 10-v6-$hv2addr2-$hv1addr2-vnifilter,20-v6-$hv2addr2-$hv1addr2-vnifilter 0 + + check_vm_connectivity "vnifiltering vxlan" +} + +# Sanity test vnifilter datapath +# with vnifilter per vni configured BUM +# group/remote +vxlan_vnifilter_datapath_pervni() +{ + hv1addr1="172.16.0.1" + hv2addr1="172.16.0.2" + hv1addr2="2002:fee1::1" + hv2addr2="2002:fee1::2" + + ip link add veth-hv-1 type veth peer name veth-hv-2 + setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64 + setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64 + + check_hv_connectivity hv2addr1 hv2addr2 + + setup-vm 1 11 1 10-v4-$hv1addr1-$hv2addr1-vnifilterg,20-v4-$hv1addr1-$hv2addr1-vnifilterg 0 + setup-vm 1 21 2 10-v6-$hv1addr2-$hv2addr2-vnifilterg,20-v6-$hv1addr2-$hv2addr2-vnifilterg 0 + + setup-vm 2 12 1 10-v4-$hv2addr1-$hv1addr1-vnifilterg,20-v4-$hv2addr1-$hv1addr1-vnifilterg 0 + setup-vm 2 22 2 10-v6-$hv2addr2-$hv1addr2-vnifilterg,20-v6-$hv2addr2-$hv1addr2-vnifilterg 0 + + check_vm_connectivity "vnifiltering vxlan pervni remote" +} + + +vxlan_vnifilter_datapath_mgroup() +{ + hv1addr1="172.16.0.1" + hv2addr1="172.16.0.2" + hv1addr2="2002:fee1::1" + hv2addr2="2002:fee1::2" + group="239.1.1.100" + group6="ff07::1" + + ip link add veth-hv-1 type veth peer name veth-hv-2 + setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64 + setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64 + + check_hv_connectivity hv2addr1 hv2addr2 + + setup-vm 1 11 1 10-v4-$hv1addr1-$group-vnifilter,20-v4-$hv1addr1-$group-vnifilter 1 + setup-vm 1 21 2 "10-v6-$hv1addr2-$group6-vnifilter,20-v6-$hv1addr2-$group6-vnifilter" 1 + + setup-vm 2 12 1 10-v4-$hv2addr1-$group-vnifilter,20-v4-$hv2addr1-$group-vnifilter 1 + setup-vm 2 22 2 10-v6-$hv2addr2-$group6-vnifilter,20-v6-$hv2addr2-$group6-vnifilter 1 + + check_vm_connectivity "vnifiltering vxlan mgroup" +} + +vxlan_vnifilter_datapath_mgroup_pervni() +{ + hv1addr1="172.16.0.1" + hv2addr1="172.16.0.2" + hv1addr2="2002:fee1::1" + hv2addr2="2002:fee1::2" + group="239.1.1.100" + group6="ff07::1" + + ip link add veth-hv-1 type veth peer name veth-hv-2 + setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64 + setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64 + + check_hv_connectivity hv2addr1 hv2addr2 + + setup-vm 1 11 1 10-v4-$hv1addr1-$group-vnifilterg,20-v4-$hv1addr1-$group-vnifilterg 1 + setup-vm 1 21 2 10-v6-$hv1addr2-$group6-vnifilterg,20-v6-$hv1addr2-$group6-vnifilterg 1 + + setup-vm 2 12 1 10-v4-$hv2addr1-$group-vnifilterg,20-v4-$hv2addr1-$group-vnifilterg 1 + setup-vm 2 22 2 10-v6-$hv2addr2-$group6-vnifilterg,20-v6-$hv2addr2-$group6-vnifilterg 1 + + check_vm_connectivity "vnifiltering vxlan pervni mgroup" +} + +vxlan_vnifilter_metadata_and_traditional_mix() +{ + hv1addr1="172.16.0.1" + hv2addr1="172.16.0.2" + hv1addr2="2002:fee1::1" + hv2addr2="2002:fee1::2" + + ip link add veth-hv-1 type veth peer name veth-hv-2 + setup-hv-networking 1 $hv1addr1 24 $hv1addr2 64 + setup-hv-networking 2 $hv2addr1 24 $hv2addr2 64 + + check_hv_connectivity hv2addr1 hv2addr2 + + setup-vm 1 11 1 10-v4-$hv1addr1-$hv2addr1-vnifilter,20-v4-$hv1addr1-$hv2addr1-vnifilter 0 + setup-vm 1 21 2 10-v6-$hv1addr2-$hv2addr2-vnifilter,20-v6-$hv1addr2-$hv2addr2-vnifilter 0 + setup-vm 1 31 3 30-v4-$hv1addr1-$hv2addr1-default-4790,40-v6-$hv1addr2-$hv2addr2-default-4790,50-v4-$hv1addr1-$hv2addr1-metadata-4791 0 + + + setup-vm 2 12 1 10-v4-$hv2addr1-$hv1addr1-vnifilter,20-v4-$hv2addr1-$hv1addr1-vnifilter 0 + setup-vm 2 22 2 10-v6-$hv2addr2-$hv1addr2-vnifilter,20-v6-$hv2addr2-$hv1addr2-vnifilter 0 + setup-vm 2 32 3 30-v4-$hv2addr1-$hv1addr1-default-4790,40-v6-$hv2addr2-$hv1addr2-default-4790,50-v4-$hv2addr1-$hv1addr1-metadata-4791 0 + + check_vm_connectivity "vnifiltering vxlan pervni remote mix" + + # check VM connectivity over traditional/non-vxlan filtering vxlan devices + run_cmd "ip netns exec vm-31 ping -c 1 -W 1 10.0.30.32" + log_test $? 0 "VM connectivity over traditional vxlan (ipv4 default rdst)" + + run_cmd "ip netns exec vm-31 ping -c 1 -W 1 10.0.40.32" + log_test $? 0 "VM connectivity over traditional vxlan (ipv6 default rdst)" + + run_cmd "ip netns exec vm-31 ping -c 1 -W 1 10.0.50.32" + log_test $? 0 "VM connectivity over metadata nonfiltering vxlan (ipv4 default rdst)" +} + +while getopts :t:pP46hv o +do + case $o in + t) TESTS=$OPTARG;; + p) PAUSE_ON_FAIL=yes;; + P) PAUSE=yes;; + v) VERBOSE=$(($VERBOSE + 1));; + h) usage; exit 0;; + *) usage; exit 1;; + esac +done + +# make sure we don't pause twice +[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no + +if [ "$(id -u)" -ne 0 ];then + echo "SKIP: Need root privileges" + exit $ksft_skip; +fi + +if [ ! -x "$(command -v ip)" ]; then + echo "SKIP: Could not run test without ip tool" + exit $ksft_skip +fi + +ip link help vxlan 2>&1 | grep -q "vnifilter" +if [ $? -ne 0 ]; then + echo "SKIP: iproute2 too old, missing vxlan dev vnifilter setting" + sync + exit $ksft_skip +fi + +bridge vni help 2>&1 | grep -q "Usage: bridge vni" +if [ $? -ne 0 ]; then + echo "SKIP: iproute2 bridge lacks vxlan vnifiltering support" + exit $ksft_skip +fi + +# start clean +cleanup &> /dev/null + +for t in $TESTS +do + case $t in + none) setup; exit 0;; + *) $t; cleanup;; + esac +done + +if [ "$TESTS" != "none" ]; then + printf "\nTests passed: %3d\n" ${nsuccess} + printf "Tests failed: %3d\n" ${nfail} +fi + +exit $ret
Signature · 1 line
2.25.1
PATCH v2 11/12 drivers: vxlan: vnifilter: per vni stats
In reply to Roopa PrabhuFrom: Nikolay Aleksandrov <[email protected]>
Add per-vni statistics for vni filter mode. Counting Rx/Tx bytes/packets/drops/errors at the appropriate places.
--- drivers/net/vxlan/vxlan_core.c | 29 +++++++++-- drivers/net/vxlan/vxlan_private.h | 3 +- drivers/net/vxlan/vxlan_vnifilter.c | 80 +++++++++++++++++++++++++++++ include/net/vxlan.h | 26 ++++++++++ 4 files changed, 134 insertions(+), 4 deletions(-)
drivers/net/vxlan/vxlan_core.c +26 -3
@@ -1746,6 +1746,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)if (!vxlan_ecn_decapsulate (vs, oiph, skb)) { ++vxlan->dev->stats.rx_frame_errors; ++vxlan->dev->stats.rx_errors; +vxlan_vnifilter_count (vxlan, vni,VXLAN_VNI_STATS_RX_ERRORS ,0 ); goto drop; }
@@ -1754,10 +1755,12 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)if (unlikely (!(vxlan->dev->flags &IFF_UP ))) {rcu_read_unlock ();atomic_long_inc (&vxlan->dev->rx_dropped); +vxlan_vnifilter_count (vxlan, vni,VXLAN_VNI_STATS_RX_DROPS ,0 ); goto drop; }dev_sw_netstats_rx_add (vxlan->dev, skb->len); +vxlan_vnifilter_count (vxlan, vni,VXLAN_VNI_STATS_RX , skb->len);gro_cells_receive (&vxlan->gro_cells, skb);rcu_read_unlock ();
@@ -1865,8 +1868,12 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) reply->ip_summed =CHECKSUM_UNNECESSARY ; reply->pkt_type =PACKET_HOST ; -if (netif_rx_ni (reply) ==NET_RX_DROP ) +if (netif_rx_ni (reply) ==NET_RX_DROP ) { dev->stats.rx_dropped++; +vxlan_vnifilter_count (vxlan, vni, +VXLAN_VNI_STATS_RX_DROPS ,0 ); + } + }else if (vxlan->cfg.flags &VXLAN_F_L3MISS ) {union vxlan_addr ipa = { .sin.sin_addr.s_addr = tip,
@@ -2020,9 +2027,11 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (reply ==NULL ) goto out; -if (netif_rx_ni (reply) ==NET_RX_DROP ) +if (netif_rx_ni (reply) ==NET_RX_DROP ) { dev->stats.rx_dropped++; - +vxlan_vnifilter_count (vxlan, vni, +VXLAN_VNI_STATS_RX_DROPS ,0 ); + } }else if (vxlan->cfg.flags &VXLAN_F_L3MISS ) {union vxlan_addr ipa = { .sin6.sin6_addr = msg->target,
@@ -2356,15 +2365,19 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan, tx_stats->tx_packets++; tx_stats->tx_bytes += len;u64_stats_update_end (&tx_stats->syncp); +vxlan_vnifilter_count (src_vxlan, vni,VXLAN_VNI_STATS_TX , len);if (__netif_rx (skb) ==NET_RX_SUCCESS ) {u64_stats_update_begin (&rx_stats->syncp); rx_stats->rx_packets++; rx_stats->rx_bytes += len;u64_stats_update_end (&rx_stats->syncp); +vxlan_vnifilter_count (dst_vxlan, vni,VXLAN_VNI_STATS_RX , len); }else { drop: dev->stats.rx_dropped++; +vxlan_vnifilter_count (dst_vxlan, vni,VXLAN_VNI_STATS_RX_DROPS , +0 ); }rcu_read_unlock (); }
@@ -2394,6 +2407,8 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev, vxlan->cfg.flags);if (!dst_vxlan) { dev->stats.tx_errors++; +vxlan_vnifilter_count (vxlan, vni, +VXLAN_VNI_STATS_TX_ERRORS ,0 );kfree_skb (skb);return -ENOENT ;
@@ -2417,6 +2432,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,union vxlan_addr remote_ip, local_ip;struct vxlan_metadata _md;struct vxlan_metadata *md = &_md; +unsigned int pkt_len = skb->len;__be16 src_port =0 , dst_port;struct dst_entry *ndst =NULL ;__u8 tos, ttl;
@@ -2644,12 +2660,14 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, label, src_port, dst_port, !udp_sum);#endif } +vxlan_vnifilter_count (vxlan, vni,VXLAN_VNI_STATS_TX , pkt_len); out_unlock:rcu_read_unlock ();return ; drop: dev->stats.tx_dropped++; +vxlan_vnifilter_count (vxlan, vni,VXLAN_VNI_STATS_TX_DROPS ,0 );dev_kfree_skb (skb);return ;
@@ -2661,6 +2679,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, dev->stats.tx_carrier_errors++;dst_release (ndst); dev->stats.tx_errors++; +vxlan_vnifilter_count (vxlan, vni,VXLAN_VNI_STATS_TX_ERRORS ,0 );kfree_skb (skb); }
@@ -2693,6 +2712,8 @@ static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev, drop: dev->stats.tx_dropped++; +vxlan_vnifilter_count (netdev_priv (dev), vni, +VXLAN_VNI_STATS_TX_DROPS ,0 );dev_kfree_skb (skb); }
@@ -2767,6 +2788,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)vxlan_fdb_miss (vxlan, eth->h_dest); dev->stats.tx_dropped++; +vxlan_vnifilter_count (vxlan, vni, +VXLAN_VNI_STATS_TX_DROPS ,0 );kfree_skb (skb);return NETDEV_TX_OK ; }
drivers/net/vxlan/vxlan_private.h +2 -1
@@ -154,6 +154,8 @@ void vxlan_vnigroup_uninit(struct vxlan_dev *vxlan);void vxlan_vnifilter_init (void );void vxlan_vnifilter_uninit (void ); +void vxlan_vnifilter_count (struct vxlan_dev *vxlan,__be32 vni, +int type,unsigned int len); void vxlan_vs_add_vnigrp(struct vxlan_dev *vxlan, struct vxlan_sock *vs,
@@ -164,7 +166,6 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan,union vxlan_addr *new_remote_ip, struct netlink_ext_ack *extack); -/* vxlan_multicast.c */ int vxlan_multicast_join (struct vxlan_dev *vxlan);int vxlan_multicast_leave (struct vxlan_dev *vxlan);
drivers/net/vxlan/vxlan_vnifilter.c +80 -0
98 lines not on this page · raw message
include/net/vxlan.h +26 -0
@@ -227,6 +227,31 @@ struct vxlan_config {enum ifla_vxlan_df df; }; +enum { +VXLAN_VNI_STATS_RX , +VXLAN_VNI_STATS_RX_DROPS , +VXLAN_VNI_STATS_RX_ERRORS , +VXLAN_VNI_STATS_TX , +VXLAN_VNI_STATS_TX_DROPS , +VXLAN_VNI_STATS_TX_ERRORS , +}; + +struct vxlan_vni_stats { +u64 rx_packets; +u64 rx_bytes; +u64 rx_drops; +u64 rx_errors; +u64 tx_packets; +u64 tx_bytes; +u64 tx_drops; +u64 tx_errors; +}; + +struct vxlan_vni_stats_pcpu { +struct vxlan_vni_stats stats; +struct u64_stats_sync syncp; +}; +struct vxlan_dev_node {struct hlist_node hlist;struct vxlan_dev *vxlan;
@@ -241,6 +266,7 @@ struct vxlan_vni_node {struct list_head vlist;__be32 vni;union vxlan_addr remote_ip;/* default remote ip for this vni */ +struct vxlan_vni_stats_pcpu __percpu *stats;struct rcu_head rcu; };
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 11/12] drivers: vxlan: vnifilter: per vni stats
drivers/net/vxlan/vxlan_private.h int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, · line 167
Quoted 5 lines · On Tue, 22 Feb 2022 02:52:29 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_private.h +0
-1@@ -164,7 +166,6 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan,union vxlan_addr *new_remote_ip, struct netlink_ext_ack *extack); -
spurious
Quoted 5 lines
drivers/net/vxlan/vxlan_vnifilter.c +1
-0/* vxlan_multicast.c */ int vxlan_multicast_join (struct vxlan_dev *vxlan);int vxlan_multicast_leave (struct vxlan_dev *vxlan); +void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni,
drivers/net/vxlan/vxlan_vnifilter.c void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan) · line 169
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c +10
-0+ int type, unsigned int len) +{ +struct vxlan_vni_node *vninode; + +if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +return ; + + vninode =vxlan_vnifilter_lookup (vxlan, vni); +if (!vninode) +return ;
Don't we end up calling vxlan_vnifilter_lookup() multiple times for every packet? Can't we remember the vninode from vxlan_vs_find_vni()?
Quoted 2 lines
drivers/net/vxlan/vxlan_vnifilter.c +2
-0+vxlan_vnifilter_stats_add (vninode, type, len); +}
Re: [PATCH net-next v2 11/12] drivers: vxlan: vnifilter: per vni stats
Quoted 8 lines · Jakub Kicinski
drivers/net/vxlan/vxlan_private.h int vxlan_vnilist_update_group(struct vxlan_dev *vxlan, · line 167
Quoted 5 lines · On Tue, 22 Feb 2022 02:52:29 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_private.h +0
-1@@ -164,7 +166,6 @@ int vxlan_vnilist_update_group(struct vxlan_dev *vxlan,union vxlan_addr *new_remote_ip, struct netlink_ext_ack *extack); -spurious
Quoted 17 lines
Quoted 4 lines
drivers/net/vxlan/vxlan_vnifilter.c +1
-0/* vxlan_multicast.c */ int vxlan_multicast_join (struct vxlan_dev *vxlan);int vxlan_multicast_leave (struct vxlan_dev *vxlan); +void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni,drivers/net/vxlan/vxlan_vnifilter.c void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan) · line 169
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c +10
-0+ int type, unsigned int len) +{ +struct vxlan_vni_node *vninode; + +if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +return ; + + vninode =vxlan_vnifilter_lookup (vxlan, vni); +if (!vninode) +return ;Don't we end up calling
vxlan_vnifilter_lookup()multiple times for every packet? Can't we remember the vninode fromvxlan_vs_find_vni()?
you are right, its done this way to not propagate vninode into vxlan_rcv.
let me see what we can do here.thanks
Jakub Kicinski
maintainerRe: [PATCH net-next v2 11/12] drivers: vxlan: vnifilter: per vni stats
Quoted 19 lines · On Fri, 25 Feb 2022 09:49:20 -0800 Roopa Prabhu wrote:
Quoted 18 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 22 Feb 2022 02:52:29 +0000 Roopa Prabhu wrote:
/* vxlan_multicast.c */ int vxlan_multicast_join(struct vxlan_dev *vxlan); int vxlan_multicast_leave(struct vxlan_dev *vxlan);drivers/net/vxlan/vxlan_vnifilter.c +1
-0+void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni,drivers/net/vxlan/vxlan_vnifilter.c void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan) · line 169
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c +10
-0+ int type, unsigned int len) +{ +struct vxlan_vni_node *vninode; + +if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +return ; + + vninode =vxlan_vnifilter_lookup (vxlan, vni); +if (!vninode) +return ;Don't we end up calling
vxlan_vnifilter_lookup()multiple times for every packet? Can't we remember the vninode fromvxlan_vs_find_vni()?
Quoted 3 lines
you are right, its done this way to not propagate vninode into
vxlan_rcv.let me see what we can do here.thanks
Thanks for making the changes, BTW there was also a transient warning here about vxlan_vnifilter_stats_get() being defined but not used. Maybe move it to the next patch?
Re: [PATCH net-next v2 11/12] drivers: vxlan: vnifilter: per vni stats
Quoted 20 lines · Jakub Kicinski
Quoted 19 lines · On Fri, 25 Feb 2022 09:49:20 -0800 Roopa Prabhu wrote:
Quoted 18 lines · Jakub Kicinski
Quoted 4 lines · On Tue, 22 Feb 2022 02:52:29 +0000 Roopa Prabhu wrote:
/* vxlan_multicast.c */ int vxlan_multicast_join(struct vxlan_dev *vxlan); int vxlan_multicast_leave(struct vxlan_dev *vxlan);drivers/net/vxlan/vxlan_vnifilter.c +1
-0+void vxlan_vnifilter_count(struct vxlan_dev *vxlan, __be32 vni,drivers/net/vxlan/vxlan_vnifilter.c void vxlan_vs_del_vnigrp(struct vxlan_dev *vxlan) · line 169
Quoted 10 lines
drivers/net/vxlan/vxlan_vnifilter.c +10
-0+ int type, unsigned int len) +{ +struct vxlan_vni_node *vninode; + +if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER )) +return ; + + vninode =vxlan_vnifilter_lookup (vxlan, vni); +if (!vninode) +return ;Don't we end up calling
vxlan_vnifilter_lookup()multiple times for every packet? Can't we remember the vninode fromvxlan_vs_find_vni()?
Quoted 6 lines
Quoted 3 lines
you are right, its done this way to not propagate vninode into
vxlan_rcv.let me see what we can do here.thanks
Thanks for making the changes, BTW there was also a transient warning here about
vxlan_vnifilter_stats_get()being defined but not used. Maybe move it to the next patch?
yes, will do, thanks.
PATCH v2 12/12 drivers: vxlan: vnifilter: add support for stats dumping
In reply to Roopa PrabhuFrom: Nikolay Aleksandrov <[email protected]>
Add support for VXLAN vni filter entries' stats dumping
--- drivers/net/vxlan/vxlan_vnifilter.c | 59 ++++++++++++++++++++++++++--- include/uapi/linux/if_link.h | 23 ++++++++++- 2 files changed, 75 insertions(+), 7 deletions(-)
drivers/net/vxlan/vxlan_vnifilter.c +53 -6
@@ -186,9 +186,48 @@ static size_t vxlan_vnifilter_entry_nlmsg_size(void) +nla_total_size (sizeof (struct in6_addr ));/* VXLAN_VNIFILTER_ENTRY_GROUP{6} */ } +static int __vnifilter_entry_fill_stats (struct sk_buff *skb, +const struct vxlan_vni_node *vbegin) +{ +struct vxlan_vni_stats vstats; +struct nlattr *vstats_attr; + + vstats_attr =nla_nest_start (skb,VXLAN_VNIFILTER_ENTRY_STATS ); +if (!vstats_attr) + goto out_stats_err; + +vxlan_vnifilter_stats_get (vbegin, &vstats); +if (nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_RX_BYTES , + vstats.rx_bytes,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_RX_PKTS , + vstats.rx_packets,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_RX_DROPS , + vstats.rx_drops,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_RX_ERRORS , + vstats.rx_errors,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_TX_BYTES , + vstats.tx_bytes,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_TX_PKTS , + vstats.tx_packets,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_TX_DROPS , + vstats.tx_drops,VNIFILTER_ENTRY_STATS_PAD ) || +nla_put_u64_64bit (skb,VNIFILTER_ENTRY_STATS_TX_ERRORS , + vstats.tx_errors,VNIFILTER_ENTRY_STATS_PAD )) + goto out_stats_err; + +nla_nest_end (skb, vstats_attr); + +return 0 ; + +out_stats_err: +nla_nest_cancel (skb, vstats_attr); +return -EMSGSIZE ; +} +static bool vxlan_fill_vni_filter_entry (struct sk_buff *skb,struct vxlan_vni_node *vbegin, -struct vxlan_vni_node *vend) +struct vxlan_vni_node *vend, +bool fill_stats) {struct nlattr *ventry;u32 vs =be32_to_cpu (vbegin->vni);
@@ -221,6 +260,9 @@ static bool vxlan_fill_vni_filter_entry(struct sk_buff *skb, } } +if (fill_stats &&__vnifilter_entry_fill_stats (skb, vbegin)) + goto out_err; +nla_nest_end (skb, ventry);return true;
@@ -253,7 +295,7 @@ static void vxlan_vnifilter_notify(const struct vxlan_dev *vxlan, tmsg->family =AF_BRIDGE ; tmsg->ifindex = vxlan->dev->ifindex; -if (!vxlan_fill_vni_filter_entry (skb, vninode, vninode)) +if (!vxlan_fill_vni_filter_entry (skb, vninode, vninode, false)) goto out_err;nlmsg_end (skb, nlh);
@@ -273,10 +315,11 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, {struct vxlan_vni_node *tmp, *v, *vbegin =NULL , *vend =NULL ;struct vxlan_dev *vxlan =netdev_priv (dev); -struct tunnel_msg *new_tmsg; +struct tunnel_msg *new_tmsg, *tmsg;int idx =0 , s_idx = cb->args[1 ];struct vxlan_vni_group *vg;struct nlmsghdr *nlh; +bool dump_stats;int err =0 ;if (!(vxlan->cfg.flags &VXLAN_F_VNIFILTER ))
@@ -287,6 +330,9 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev,if (!vg || !vg->num_vnis)return 0 ; + tmsg =nlmsg_data (cb->nlh); + dump_stats = !!(tmsg->flags &TUNNEL_MSG_FLAG_STATS ); + nlh =nlmsg_put (skb,NETLINK_CB (cb->skb).portid, cb->nlh->nlmsg_seq,RTM_NEWTUNNEL ,sizeof (*new_tmsg),NLM_F_MULTI );if (!nlh)
@@ -306,11 +352,12 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, vend = v;continue ; } -if (vnirange (vend, v) ==1 && +if (!dump_stats &&vnirange (vend, v) ==1 &&vxlan_addr_equal (&v->remote_ip, &vend->remote_ip)) { goto update_end; }else { -if (!vxlan_fill_vni_filter_entry (skb, vbegin, vend)) { +if (!vxlan_fill_vni_filter_entry (skb, vbegin, vend, + dump_stats)) { err = -EMSGSIZE ;break ; }
@@ -322,7 +369,7 @@ static int vxlan_vnifilter_dump_dev(const struct net_device *dev, }if (!err && vbegin) { -if (!vxlan_fill_vni_filter_entry (skb, vbegin, vend)) +if (!vxlan_fill_vni_filter_entry (skb, vbegin, vend, dump_stats)) err = -EMSGSIZE ; }
include/uapi/linux/if_link.h +22 -1
@@ -715,18 +715,39 @@ enum ipvlan_mode {/* Tunnel RTM header */ struct tunnel_msg {__u8 family; -__u8 reserved1; +__u8 flags;__u16 reserved2;__u32 ifindex; };/* VXLAN section */ + +/* include statistics in the dump */ +#define TUNNEL_MSG_FLAG_STATS 0x01 + +/* Embedded inside VXLAN_VNIFILTER_ENTRY_STATS */ +enum { +VNIFILTER_ENTRY_STATS_UNSPEC , +VNIFILTER_ENTRY_STATS_RX_BYTES , +VNIFILTER_ENTRY_STATS_RX_PKTS , +VNIFILTER_ENTRY_STATS_RX_DROPS , +VNIFILTER_ENTRY_STATS_RX_ERRORS , +VNIFILTER_ENTRY_STATS_TX_BYTES , +VNIFILTER_ENTRY_STATS_TX_PKTS , +VNIFILTER_ENTRY_STATS_TX_DROPS , +VNIFILTER_ENTRY_STATS_TX_ERRORS , +VNIFILTER_ENTRY_STATS_PAD , + __VNIFILTER_ENTRY_STATS_MAX +}; +#define VNIFILTER_ENTRY_STATS_MAX (__VNIFILTER_ENTRY_STATS_MAX - 1) +enum {VXLAN_VNIFILTER_ENTRY_UNSPEC ,VXLAN_VNIFILTER_ENTRY_START ,VXLAN_VNIFILTER_ENTRY_END ,VXLAN_VNIFILTER_ENTRY_GROUP ,VXLAN_VNIFILTER_ENTRY_GROUP6 , +VXLAN_VNIFILTER_ENTRY_STATS , __VXLAN_VNIFILTER_ENTRY_MAX };#define VXLAN_VNIFILTER_ENTRY_MAX (__VXLAN_VNIFILTER_ENTRY_MAX - 1)
Signature · 1 line
2.25.1
Jakub Kicinski
maintainerRe: [PATCH net-next v2 12/12] drivers: vxlan: vnifilter: add support for stats dumping
drivers/net/vxlan/vxlan_vnifilter.c static int vxlan_vnifilter_dump_dev(const struct net_device *dev, · line 334
Quoted 1 line · On Tue, 22 Feb 2022 02:52:30 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_vnifilter.c +1
-0+ dump_stats = !!(tmsg->flags &TUNNEL_MSG_FLAG_STATS );
Are unknown flags rejected somewhere?
Re: [PATCH net-next v2 12/12] drivers: vxlan: vnifilter: add support for stats dumping
Quoted 3 lines · Jakub Kicinski
drivers/net/vxlan/vxlan_vnifilter.c static int vxlan_vnifilter_dump_dev(const struct net_device *dev, · line 334
Quoted 1 line · On Tue, 22 Feb 2022 02:52:30 +0000 Roopa Prabhu wrote:
drivers/net/vxlan/vxlan_vnifilter.c +1
-0+ dump_stats = !!(tmsg->flags &TUNNEL_MSG_FLAG_STATS );Are unknown flags rejected somewhere?
you are right, they are not. Will fix. thanks