[openib-general] [RFC][PATCH] rdma_cm: allow joins to return a unique address

Sean Hefty sean.hefty at intel.com
Mon Jan 29 12:06:43 PST 2007


Modify rdma_join_multicast to allow the user to specify that
they want the underlying transport to assign them a unique
multicast address.  This is done by specifying an IP address
of 0, which will translate into an IB MGID of 0.

To allow others to join this group, we need a way to determine
if additional join requests are for a specific MGID, or require
IP to MGID mapping.  This is done by comparing the requested
join address against SA assigned MGIDs.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 827df2a..395cf2f 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -2490,13 +2490,36 @@ out:
 	return 0;
 }
 
+static void cma_set_mgid(struct rdma_id_private *id_priv,
+			 struct sockaddr *addr, union ib_gid *mgid)
+{
+	unsigned char mc_map[MAX_ADDR_LEN];
+	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
+	struct sockaddr_in *sin = (struct sockaddr_in *) addr;
+	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr;
+
+	if (cma_any_addr(addr)) {
+		memset(mgid, 0, sizeof *mgid);
+	} else if ((addr->sa_family == AF_INET6) &&
+		   ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFF10A01B) ==
+								 0xFF10A01B)) {
+		/* IPv6 address is an SA assigned MGID. */
+		memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
+	} else {
+		ip_ib_mc_map(sin->sin_addr.s_addr, mc_map);
+		if (id_priv->id.ps == RDMA_PS_UDP)
+			mc_map[7] = 0x01;	/* Use RDMA CM signature */
+		mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
+		mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
+		*mgid = *(union ib_gid *) (mc_map + 4);
+	}
+}
+
 static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
 				 struct cma_multicast *mc)
 {
 	struct ib_sa_mcmember_rec rec;
-	unsigned char mc_map[MAX_ADDR_LEN];
 	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
-	struct sockaddr_in *sin = (struct sockaddr_in *) &mc->addr;
 	ib_sa_comp_mask comp_mask;
 	int ret;
 
@@ -2506,15 +2529,9 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
 	if (ret)
 		return ret;
 
-	ip_ib_mc_map(sin->sin_addr.s_addr, mc_map);
-	if (id_priv->id.ps == RDMA_PS_UDP) {
-		mc_map[7] = 0x01;		/* Use RDMA CM signature */
+	cma_set_mgid(id_priv, &mc->addr, &rec.mgid);
+	if (id_priv->id.ps == RDMA_PS_UDP)
 		rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
-	}
-	mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
-	mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
-
-	rec.mgid = *(union ib_gid *) (mc_map + 4);
 	ib_addr_get_sgid(dev_addr, &rec.port_gid);
 	rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
 	rec.join_state = 1;





More information about the general mailing list