From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ido Schimmel Subject: [PATCH net-next 13/18] vxlan: Add vxlan_fdb_find_uc() for FDB querying Date: Sat, 13 Oct 2018 17:18:42 +0000 Message-ID: <20181013171725.3261-14-idosch@mellanox.com> References: <20181013171725.3261-1-idosch@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: "davem@davemloft.net" , Jiri Pirko , Petr Machata , "ivecera@redhat.com" , "roopa@cumulusnetworks.com" , "nikolay@cumulusnetworks.com" , "andrew@lunn.ch" , "vivien.didelot@savoirfairelinux.com" , "f.fainelli@gmail.com" , "stephen@networkplumber.org" , "bridge@lists.linux-foundation.org" , mlxsw , Ido Schimmel To: "netdev@vger.kernel.org" Return-path: Received: from mail-he1eur01on0083.outbound.protection.outlook.com ([104.47.0.83]:32183 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726711AbeJNA5G (ORCPT ); Sat, 13 Oct 2018 20:57:06 -0400 In-Reply-To: <20181013171725.3261-1-idosch@mellanox.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: From: Petr Machata A switchdev-capable driver that is aware of VXLAN may need to query VXLAN FDB. In the particular case of mlxsw, this functionality is limited to querying UC FDBs. Those being easier to deal with than the general case of RDST chain traversal, introduce an interface to query specifically UC FDBs: vxlan_fdb_find_uc(). Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- drivers/net/vxlan.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/net/vxlan.h | 12 ++++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c index f8b579648d42..97c2218569d9 100644 --- a/drivers/net/vxlan.c +++ b/drivers/net/vxlan.c @@ -504,6 +504,46 @@ static struct vxlan_rdst *vxlan_fdb_find_rdst(struct v= xlan_fdb *f, return NULL; } =20 +int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, + struct switchdev_notifier_vxlan_fdb_info *fdb_info) +{ + struct vxlan_dev *vxlan =3D netdev_priv(dev); + u8 eth_addr[ETH_ALEN + 2] =3D { 0 }; + struct vxlan_rdst *rdst; + struct vxlan_fdb *f; + int rc =3D 0; + + if (is_multicast_ether_addr(mac) || + is_zero_ether_addr(mac)) + return -EINVAL; + + ether_addr_copy(eth_addr, mac); + + rcu_read_lock(); + + f =3D __vxlan_find_mac(vxlan, eth_addr, vni); + if (!f) { + rc =3D -ENOENT; + goto out; + } + + rdst =3D first_remote_rcu(f); + + memset(fdb_info, 0, sizeof(*fdb_info)); + fdb_info->info.dev =3D dev; + fdb_info->remote_ip =3D rdst->remote_ip; + fdb_info->remote_port =3D rdst->remote_port; + fdb_info->remote_vni =3D rdst->remote_vni; + fdb_info->remote_ifindex =3D rdst->remote_ifindex; + fdb_info->vni =3D vni; + ether_addr_copy(fdb_info->eth_addr, mac); + +out: + rcu_read_unlock(); + return rc; +} +EXPORT_SYMBOL_GPL(vxlan_fdb_find_uc); + /* Replace destination of unicast mac */ static int vxlan_fdb_replace(struct vxlan_fdb *f, union vxlan_addr *ip, __be16 port, __be32 vni, diff --git a/include/net/vxlan.h b/include/net/vxlan.h index a82b735decbc..798ba5019f4e 100644 --- a/include/net/vxlan.h +++ b/include/net/vxlan.h @@ -413,4 +413,16 @@ struct switchdev_notifier_vxlan_fdb_info { __be32 vni; }; =20 +#if IS_ENABLED(CONFIG_VXLAN) +int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, + struct switchdev_notifier_vxlan_fdb_info *fdb_info); +#else +static inline int +vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, + struct switchdev_notifier_vxlan_fdb_info *fdb_info) +{ + return -ENOENT; +} +#endif + #endif --=20 2.17.2