[openib-general] [PATCH] RDMA CM: allow listen without prior binding to listen on any address

Sean Hefty sean.hefty at intel.com
Mon Apr 24 13:49:45 PDT 2006


Will something like the following work for you for now?

---

Allow calling rdma_listen() without calling rdma_bind_addr() beforehand.

This will result in binding to any address / any port before listening.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>

---

Index: cma.c
===================================================================
--- cma.c	(revision 6588)
+++ cma.c	(working copy)
@@ -1002,12 +1002,27 @@ static void cma_listen_on_all(struct rdm
 	mutex_unlock(&lock);
 }
 
+static int cma_bind_any(struct rdma_cm_id *id, sa_family_t af)
+{
+	struct sockaddr_in addr_in;
+
+	memset(&addr_in, 0, sizeof addr_in);
+	addr_in.sin_family = af;
+	return rdma_bind_addr(id, (struct sockaddr *) &addr_in);
+}
+
 int rdma_listen(struct rdma_cm_id *id, int backlog)
 {
 	struct rdma_id_private *id_priv;
 	int ret;
 
 	id_priv = container_of(id, struct rdma_id_private, id);
+	if (id_priv->state == CMA_IDLE) {
+		ret = cma_bind_any(id, AF_INET);
+		if (ret)
+			return ret;
+	}
+
 	if (!cma_comp_exch(id_priv, CMA_ADDR_BOUND, CMA_LISTEN))
 		return -EINVAL;
 
@@ -1276,15 +1291,10 @@ err:
 static int cma_bind_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
 			 struct sockaddr *dst_addr)
 {
-	struct sockaddr_in addr_in;
-
 	if (src_addr && src_addr->sa_family)
 		return rdma_bind_addr(id, src_addr);
-	else {
-		memset(&addr_in, 0, sizeof addr_in);
-		addr_in.sin_family = dst_addr->sa_family;
-		return rdma_bind_addr(id, (struct sockaddr *) &addr_in);
-	}
+	else
+		return cma_bind_any(id, dst_addr->sa_family);
 }
 
 int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,




More information about the general mailing list