diff mbox

[librdmacm] rstream.c: Add missing binding to source address in client_connect

Message ID 54F9C0A5.5010909@dev.mellanox.co.il (mailing list archive)
State Rejected
Headers show

Commit Message

Hal Rosenstock March 6, 2015, 2:58 p.m. UTC
This is needed for IPv6 connections.

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
---
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Hefty, Sean March 25, 2015, 10:47 p.m. UTC | #1
Thanks - applied
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/examples/rstream.c b/examples/rstream.c
index 05598a8..d93e9aa 100644
--- a/examples/rstream.c
+++ b/examples/rstream.c
@@ -1,5 +1,6 @@ 
 /*
  * Copyright (c) 2011-2012 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2014-2015 Mellanox Technologies LTD. All rights reserved.
  *
  * This software is available to you under the OpenIB.org BSD license
  * below:
@@ -401,8 +402,8 @@  static int server_connect(void)
 
 static int client_connect(void)
 {
-	struct rdma_addrinfo *rai = NULL;
-	struct addrinfo *ai;
+	struct rdma_addrinfo *rai = NULL, *rai_src = NULL;
+	struct addrinfo *ai, *ai_src;
 	struct pollfd fds;
 	int ret, err;
 	socklen_t len;
@@ -415,6 +416,20 @@  static int client_connect(void)
 		return ret;
 	}
 
+	if (src_addr) {
+		if (use_rgai) {
+			rai_hints.ai_flags |= RAI_PASSIVE;
+			ret = rdma_getaddrinfo(src_addr, port, &rai_hints, &rai_src);
+		} else {
+			ai_hints.ai_flags |= RAI_PASSIVE;
+			ret = getaddrinfo(src_addr, port, &ai_hints, &ai_src);
+		}
+		if (ret) {
+			perror("getaddrinfo src_addr");
+			return ret;
+		}
+	}
+
 	rs = rai ? rs_socket(rai->ai_family, SOCK_STREAM, 0) :
 		   rs_socket(ai->ai_family, SOCK_STREAM, 0);
 	if (rs < 0) {
@@ -424,7 +439,15 @@  static int client_connect(void)
 	}
 
 	set_options(rs);
-	/* TODO: bind client to src_addr */
+
+	if (src_addr) {
+		ret = rai ? rs_bind(rs, rai_src->ai_src_addr, rai_src->ai_src_len) :
+			    rs_bind(rs, ai_src->ai_addr, ai_src->ai_addrlen);
+		if (ret) {
+			perror("rbind");
+			goto close;
+		}
+	}
 
 	if (rai && rai->ai_route) {
 		ret = rs_setsockopt(rs, SOL_RDMA, RDMA_ROUTE, rai->ai_route,