All of lore.kernel.org
 help / color / mirror / Atom feed
From: Haggai Eran <haggaie@mellanox.com>
To: Doug Ledford <dledford@redhat.com>, Roland Dreier <roland@kernel.org>
Cc: Sean Hefty <sean.hefty@intel.com>,
	linux-rdma@vger.kernel.org, netdev@vger.kernel.org,
	Liran Liss <liranl@mellanox.com>,
	Guy Shapiro <guysh@mellanox.com>,
	Shachar Raindel <raindel@mellanox.com>,
	Yotam Kenneth <yotamke@mellanox.com>,
	Haggai Eran <haggaie@mellanox.com>
Subject: [PATCH v2 05/11] IB/ipoib: Return IPoIB devices as possible matches to get_net_device_by_port_pkey_ip
Date: Mon, 20 Apr 2015 12:03:36 +0300	[thread overview]
Message-ID: <1429520622-10303-6-git-send-email-haggaie@mellanox.com> (raw)
In-Reply-To: <1429520622-10303-1-git-send-email-haggaie@mellanox.com>

From: Guy Shapiro <guysh@mellanox.com>

Implement callback that returns network device to ib_core according to
connection parameters. Check the ipoib device and iterate over all child
devices to look for a match.

For each ipoib device we iterate through all upper devices when searching for
a matching IP, in order to support bonding.

Signed-off-by: Guy Shapiro <guysh@mellanox.com>
Signed-off-by: Haggai Eran <haggaie@mellanox.com>
Signed-off-by: Yotam Kenneth <yotamke@mellanox.com>
Signed-off-by: Shachar Raindel <raindel@mellanox.com>
---
 drivers/infiniband/ulp/ipoib/ipoib_main.c | 122 +++++++++++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 7cad4dd87469..89a59a0e17e6 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -48,6 +48,9 @@
 
 #include <linux/jhash.h>
 #include <net/arp.h>
+#include <net/addrconf.h>
+#include <linux/inetdevice.h>
+#include <rdma/ib_cache.h>
 
 #define DRV_VERSION "1.0.0"
 
@@ -91,11 +94,15 @@ struct ib_sa_client ipoib_sa_client;
 static void ipoib_add_one(struct ib_device *device);
 static void ipoib_remove_one(struct ib_device *device);
 static void ipoib_neigh_reclaim(struct rcu_head *rp);
+static struct net_device *ipoib_get_net_device_by_port_pkey_ip(
+		struct ib_device *dev, u8 port, u16 pkey,
+		struct sockaddr *addr);
 
 static struct ib_client ipoib_client = {
 	.name   = "ipoib",
 	.add    = ipoib_add_one,
-	.remove = ipoib_remove_one
+	.remove = ipoib_remove_one,
+	.get_net_device_by_port_pkey_ip = ipoib_get_net_device_by_port_pkey_ip,
 };
 
 int ipoib_open(struct net_device *dev)
@@ -222,6 +229,119 @@ static int ipoib_change_mtu(struct net_device *dev, int new_mtu)
 	return 0;
 }
 
+static bool ipoib_is_dev_match_addr(struct sockaddr *addr,
+				    struct net_device *dev)
+{
+	struct net *net = dev_net(dev);
+
+	if (addr->sa_family == AF_INET) {
+		struct in_device *in_dev = in_dev_get(dev);
+		struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
+		__be32 ret_addr;
+
+		if (!in_dev)
+			return false;
+
+		ret_addr = inet_confirm_addr(net, in_dev, 0,
+					     addr_in->sin_addr.s_addr,
+					     RT_SCOPE_HOST);
+		in_dev_put(in_dev);
+		if (ret_addr)
+			return true;
+	}
+#if IS_ENABLED(CONFIG_IPV6)
+	else if (addr->sa_family == AF_INET6) {
+		struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
+
+		if (ipv6_chk_addr(net, &addr_in6->sin6_addr, dev, 1))
+			return true;
+	}
+#endif
+	return false;
+}
+
+/**
+ * Find a net_device matching the given address, which is an upper device of
+ * the given net_device.
+ * @addr: IP address to look for.
+ * @dev: base IPoIB net_device
+ *
+ * If found, returns the net_device with a reference held. Otherwise return
+ * NULL.
+ */
+static struct net_device *ipoib_get_net_dev_match_addr(struct sockaddr *addr,
+						       struct net_device *dev)
+{
+	struct net_device *upper,
+			  *result = NULL;
+	struct list_head *iter;
+
+	if (ipoib_is_dev_match_addr(addr, dev)) {
+		dev_hold(dev);
+		return dev;
+	}
+
+	rcu_read_lock();
+	netdev_for_each_all_upper_dev_rcu(dev, upper, iter) {
+		if (ipoib_is_dev_match_addr(addr, upper)) {
+			dev_hold(upper);
+			result = upper;
+			break;
+		}
+	}
+	rcu_read_unlock();
+	return result;
+}
+
+static struct net_device *ipoib_get_net_device_by_port_pkey_ip(
+		struct ib_device *dev, u8 port, u16 pkey, struct sockaddr *addr)
+{
+	struct ipoib_dev_priv *priv;
+	struct list_head *dev_list;
+	u16 pkey_index;
+
+	ib_find_cached_pkey(dev, port, pkey, &pkey_index);
+	if (pkey_index == (u16)-1)
+		return NULL;
+
+	if (rdma_node_get_transport(dev->node_type) != RDMA_TRANSPORT_IB)
+		return NULL;
+
+	dev_list = ib_get_client_data(dev, &ipoib_client);
+	if (!dev_list)
+		return NULL;
+
+	list_for_each_entry(priv, dev_list, list) {
+		struct net_device *net_dev = NULL;
+		struct ipoib_dev_priv *child_priv;
+
+		if (priv->port != port)
+			continue;
+
+		if (priv->pkey_index == pkey_index) {
+			net_dev = ipoib_get_net_dev_match_addr(addr, priv->dev);
+			if (net_dev)
+				return net_dev;
+		}
+
+		down_read(&priv->vlan_rwsem);
+		list_for_each_entry(child_priv,
+				    &priv->child_intfs, list) {
+			if (child_priv->pkey_index != pkey_index)
+				continue;
+
+			net_dev = ipoib_get_net_dev_match_addr(
+					addr, child_priv->dev);
+			if (net_dev)
+				break;
+		}
+		up_read(&priv->vlan_rwsem);
+		if (net_dev)
+			return net_dev;
+	}
+	return NULL;
+}
+
 int ipoib_set_mode(struct net_device *dev, const char *buf)
 {
 	struct ipoib_dev_priv *priv = netdev_priv(dev);
-- 
1.7.11.2

  parent reply	other threads:[~2015-04-20  9:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-20  9:03 [PATCH v2 00/11] Add network namespace support in the RDMA-CM Haggai Eran
     [not found] ` <1429520622-10303-1-git-send-email-haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-20  9:03   ` [PATCH v2 01/11] RDMA/CMA: Mark IPv4 addresses correctly when the listener is IPv6 Haggai Eran
     [not found]     ` <1429520622-10303-2-git-send-email-haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-20 16:41       ` Jason Gunthorpe
     [not found]         ` <20150420164140.GC7676-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-20 18:38           ` Or Gerlitz
2015-04-20 20:01             ` Jason Gunthorpe
     [not found]               ` <20150420200111.GA32449-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-21 10:15                 ` Haggai Eran
     [not found]                   ` <5536232F.3050707-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-22 11:26                     ` Haggai Eran
2015-04-22 17:29                     ` Jason Gunthorpe
     [not found]             ` <CAJ3xEMgKFdr68Qt0vNCaf1p4YjPK2KUSn2FdtQVP0SZQ+Y7atg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-21  5:18               ` Shachar Raindel
2015-04-20  9:03   ` [PATCH v2 02/11] IB/addr: Pass network namespace as a parameter Haggai Eran
     [not found]     ` <1429520622-10303-3-git-send-email-haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-20 17:09       ` Jason Gunthorpe
     [not found]         ` <20150420170925.GE7676-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-21 10:29           ` Haggai Eran
2015-04-21 10:29             ` Haggai Eran
2015-04-20 22:05       ` Doug Ledford
     [not found]         ` <1429567530.45956.31.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-04-21 10:34           ` Haggai Eran
2015-04-21 10:34             ` Haggai Eran
2015-04-20  9:03   ` [PATCH v2 04/11] IB/core: Find the network namespace matching connection parameters Haggai Eran
2015-04-20  9:03   ` [PATCH v2 06/11] IB/cm, cma: Move RDMA IP CM private-data parsing code from ib_cma to ib_cm Haggai Eran
     [not found]     ` <1429520622-10303-7-git-send-email-haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-20 23:29       ` ira.weiny
2015-04-20  9:03   ` [PATCH v2 08/11] IB/cma: Separate port allocation to network namespaces Haggai Eran
2015-04-20  9:03   ` [PATCH v2 09/11] IB/cma: Add support for " Haggai Eran
2015-04-20  9:03   ` [PATCH v2 11/11] IB/ucm: Add partial " Haggai Eran
2015-04-20 23:46     ` ira.weiny
2015-04-20 14:53   ` [PATCH v2 00/11] Add network namespace support in the RDMA-CM Steve Wise
2015-04-21  6:36     ` Haggai Eran
2015-04-21  6:36       ` Haggai Eran
     [not found]       ` <5535EFE9.3000106-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-21 14:11         ` Steve Wise
     [not found]           ` <55365AAD.6020100-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
2015-04-21 14:21             ` Haggai Eran
2015-04-21 14:21               ` Haggai Eran
2015-04-20  9:03 ` [PATCH v2 03/11] IB/core: Pass network namespace as a parameter to relevant functions Haggai Eran
2015-04-20  9:03 ` Haggai Eran [this message]
2015-04-20 23:09   ` [PATCH v2 05/11] IB/ipoib: Return IPoIB devices as possible matches to get_net_device_by_port_pkey_ip ira.weiny
2015-04-20  9:03 ` [PATCH v2 07/11] IB/cm: Add network namespace support Haggai Eran
     [not found]   ` <1429520622-10303-8-git-send-email-haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-20 17:06     ` Jason Gunthorpe
     [not found]       ` <20150420170659.GD7676-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-04-20 23:35         ` ira.weiny
     [not found]           ` <55363D93.10706@mellanox.com>
     [not found]             ` <55363D93.10706-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2015-04-21 15:54               ` Jason Gunthorpe
2015-04-21 11:59         ` Haggai Eran
2015-04-21 11:59           ` Haggai Eran
2015-04-20  9:03 ` [PATCH v2 10/11] IB/ucma: Take the network namespace from the process Haggai Eran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429520622-10303-6-git-send-email-haggaie@mellanox.com \
    --to=haggaie@mellanox.com \
    --cc=dledford@redhat.com \
    --cc=guysh@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=liranl@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=raindel@mellanox.com \
    --cc=roland@kernel.org \
    --cc=sean.hefty@intel.com \
    --cc=yotamke@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.