[ofa-general] IPv6 RDMA CM PATCHv2 8/8

Aleksey Senin alekseys at voltaire.com
Sun Aug 10 23:20:20 PDT 2008


>From 088d2fe2b2b3913ccca124de74a9cfe2cd362edd Mon Sep 17 00:00:00 2001
From: Aleksey Senin <alekseys at voltaire.com>
Date: Sun, 10 Aug 2008 13:50:58 +0300
Subject: [IPv6 RDMA CM PATCHv2 8/8]
Implemented IPv6 for RDMA CM in resolving remote nodes addr_send_arp
function modified to obtain generic sockaddr structure to support both
IPv4 and IPv6 protocols
addr6_resolve_remote added in order to deal with IPv6
addr_resolve_remote renamed to addr4_resolve_remote
Function addr_resolve_remote modified to obtain sockaddr strucure and call
corresponding IPv4/IPv6 function


Signed-off-by: Aleksey Senin <alekseys at voltaire.com>
---
 drivers/infiniband/core/addr.c |   96 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 83 insertions(+), 13 deletions(-)

diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 00dcb22..7756d80 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -43,6 +43,7 @@
 #include <net/netevent.h>
 #include <net/addrconf.h>
 #include <rdma/ib_addr.h>
+#include <net/ip6_route.h>
 
 MODULE_AUTHOR("Sean Hefty");
 MODULE_DESCRIPTION("IB Address Translation");
@@ -182,27 +183,42 @@ static void queue_req(struct addr_req *req)
 	mutex_unlock(&lock);
 }
 
-static void addr_send_arp(struct sockaddr_in *dst_in)
+static void addr_send_arp(struct sockaddr *dst_in)
 {
 	struct rtable *rt;
 	struct flowi fl;
-	__be32 dst_ip = dst_in->sin_addr.s_addr;
 
 	memset(&fl, 0, sizeof fl);
-	fl.nl_u.ip4_u.daddr = dst_ip;
-	if (ip_route_output_key(&init_net, &rt, &fl))
-		return;
 
-	neigh_event_send(rt->u.dst.neighbour, NULL);
-	ip_rt_put(rt);
+	if (dst_in->sa_family == AF_INET)  {
+		fl.nl_u.ip4_u.daddr =
+			((struct sockaddr_in *)dst_in)->sin_addr.s_addr;
+
+		if (ip_route_output_key(&init_net, &rt, &fl))
+			return;
+
+		neigh_event_send(rt->u.dst.neighbour, NULL);
+		ip_rt_put(rt);
+
+	} else {
+		struct dst_entry *dst;
+		fl.nl_u.ip6_u.daddr =
+			((struct sockaddr_in6 *)dst_in)->sin6_addr;
+		dst = ip6_route_output(&init_net, NULL, &fl);
+		if (!dst)
+			return;
+
+		neigh_event_send(dst->neighbour, NULL);
+		dst_release(dst);
+	}
 }
 
-static int addr_resolve_remote(struct sockaddr *src_in,
-			       struct sockaddr *dst_in,
+static int addr4_resolve_remote(struct sockaddr_in *src_in,
+			       struct sockaddr_in *dst_in,
 			       struct rdma_dev_addr *addr)
 {
-	__be32 src_ip = ((struct sockaddr_in *)src_in)->sin_addr.s_addr;
-	__be32 dst_ip = ((struct sockaddr_in *)dst_in)->sin_addr.s_addr;
+	__be32 src_ip = src_in->sin_addr.s_addr;
+	__be32 dst_ip = dst_in->sin_addr.s_addr;
 	struct flowi fl;
 	struct rtable *rt;
 	struct neighbour *neigh;
@@ -233,7 +249,7 @@ static int addr_resolve_remote(struct sockaddr *src_in,
 	}
 
 	if (!src_ip) {
-		src_in->sa_family = dst_in->sa_family;
+		src_in->sin_family = dst_in->sin_family;
 		((struct sockaddr_in *)src_in)->sin_addr.s_addr = rt->rt_src;
 	}
 
@@ -246,6 +262,60 @@ out:
 	return ret;
 }
 
+static int addr6_resolve_remote(struct sockaddr_in6 *src_in,
+			       struct sockaddr_in6 *dst_in,
+			       struct rdma_dev_addr *addr)
+{
+	struct flowi fl;
+	struct dst_entry *dst;
+	struct neighbour *neigh;
+	int ret = -ENODATA;
+
+	memset(&fl, 0, sizeof fl);
+	fl.nl_u.ip6_u.daddr = dst_in->sin6_addr;
+	fl.nl_u.ip6_u.saddr = src_in->sin6_addr;
+
+	dst = ip6_route_output(&init_net, NULL, &fl);
+
+	if (!dst)
+		goto out;
+
+	/* If the device does ARP internally, return 'done' */
+	if (dst->dev->flags & IFF_NOARP) {
+		ret = rdma_copy_addr(addr, dst->dev, NULL);
+		goto release;
+	}
+
+	neigh = dst->neighbour;
+	if (!neigh) {
+		ret = -ENODATA;
+		goto release;
+	}
+
+	if (!(neigh->nud_state & NUD_VALID)) {
+		ret = -ENODATA;
+		goto release;
+	}
+	ret = rdma_copy_addr(addr, neigh->dev, neigh->ha);
+
+release:
+	dst_release(dst);
+out:
+	return ret;
+}
+
+static int addr_resolve_remote(struct sockaddr *src_in,
+				struct sockaddr *dst_in,
+				struct rdma_dev_addr *addr)
+{
+	if (src_in->sa_family == AF_INET) {
+		return addr4_resolve_remote((struct sockaddr_in *)src_in,
+			(struct sockaddr_in *)dst_in, addr);
+	} else
+		return addr6_resolve_remote((struct sockaddr_in6 *)src_in,
+			(struct sockaddr_in6 *)dst_in, addr);
+}
+
 static void process_req(struct work_struct *work)
 {
 	struct addr_req *req, *temp_req;
@@ -384,7 +454,7 @@ int rdma_resolve_ip(struct rdma_addr_client *client,
 	case -ENODATA:
 		req->timeout = msecs_to_jiffies(timeout_ms) + jiffies;
 		queue_req(req);
-		addr_send_arp((struct sockaddr_in *)dst_in);
+		addr_send_arp(dst_in);
 		break;
 	default:
 		ret = req->status;
-- 
1.5.6.dirty





More information about the general mailing list