All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 26/37] librdmacm: set src_addr in rdma_getaddrinfo
@ 2010-04-07 17:12 Sean Hefty
       [not found] ` <B7B5C575DF7D4C51AB84AFFAC7A5D5C5-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Hefty @ 2010-04-07 17:12 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA

RDMA requires the user to allocate hardware resources before
establishing a connection.  To support this, the user must know
the source address that the connection will use to reach the
remote endpoint.  Modify rdma_getaddrinfo to determine an
appropriate source address based on the specified destination,
when a source address is not given.

Signed-off-by: Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---

 src/addrinfo.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/src/addrinfo.c b/src/addrinfo.c
index 15ae071..dfaf9d5 100644
--- a/src/addrinfo.c
+++ b/src/addrinfo.c
@@ -39,6 +39,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
+#include <unistd.h>
 
 #include "cma.h"
 #include <rdma/rdma_cma.h>
@@ -129,6 +130,48 @@ static int ucma_convert_to_rai(struct rdma_addrinfo *rai, struct addrinfo *ai)
 	return 0;
 }
 
+static int ucma_resolve_src(struct rdma_addrinfo *rai)
+{
+	struct sockaddr *addr;
+	socklen_t len;
+	int ret, s;
+
+	s = socket(rai->ai_family, SOCK_DGRAM, IPPROTO_UDP);
+	if (s < 0)
+		return s;
+
+	ret = connect(s, rai->ai_dst_addr, rai->ai_dst_len);
+	if (ret)
+		goto err1;
+
+	addr = zalloc(rai->ai_dst_len);
+	if (!addr) {
+		ret = ERR(ENOMEM);
+		goto err1;
+	}
+
+	len = rai->ai_dst_len;
+	ret = getsockname(s, addr, &len);
+	if (ret)
+		goto err2;
+
+	if (addr->sa_family == AF_INET)
+		((struct sockaddr_in *) addr)->sin_port = 0;
+	else
+		((struct sockaddr_in6 *) addr)->sin6_port = 0;
+	rai->ai_src_addr = addr;
+	rai->ai_src_len = len;
+
+	close(s);
+	return 0;
+
+err2:
+	free(addr);
+err1:
+	close(s);
+	return ret;
+}
+
 int rdma_getaddrinfo(char *node, char *service,
 		     struct rdma_addrinfo *hints,
 		     struct rdma_addrinfo **res)
@@ -159,6 +202,23 @@ int rdma_getaddrinfo(char *node, char *service,
 	if (ret)
 		goto err2;
 
+	if (!rai->ai_src_len) {
+		if (hints && hints->ai_src_len) {
+			rai->ai_src_addr = zalloc(hints->ai_src_len);
+			if (!rai->ai_src_addr) {
+				ret = ERR(ENOMEM);
+				goto err2;
+			}
+			memcpy(rai->ai_src_addr, hints->ai_src_addr,
+			       hints->ai_src_len);
+			rai->ai_src_len = hints->ai_src_len;
+		} else {
+			ret = ucma_resolve_src(rai);
+			if (ret)
+				goto err2;
+		}
+	}
+
 	freeaddrinfo(ai);
 	*res = rai;
 	return 0;



--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-04-09 18:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-07 17:12 [PATCH 26/37] librdmacm: set src_addr in rdma_getaddrinfo Sean Hefty
     [not found] ` <B7B5C575DF7D4C51AB84AFFAC7A5D5C5-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2010-04-07 19:28   ` Jason Gunthorpe
     [not found]     ` <20100407192810.GG15629-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2010-04-07 19:54       ` Sean Hefty
     [not found]         ` <4BAFD82633A744729F9685D44B250100-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2010-04-07 20:14           ` Jason Gunthorpe
     [not found]             ` <20100407201417.GJ15629-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2010-04-07 22:10               ` Sean Hefty
     [not found]                 ` <569EDABAE9F84A029ED7AC84AA5767D6-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org>
2010-04-07 22:22                   ` Jason Gunthorpe
2010-04-09 18:54   ` [PATCH 26/37 v2] " Sean Hefty

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.