[openib-general] [PATCH] CMA: local/loopback address handling

Michael S. Tsirkin mst at mellanox.co.il
Sun Mar 26 06:23:50 PST 2006


Sean,
Apparently, on bind, loopback addresses such as 127.0.0.1 in TCP have the same
meaning as zeronet ANY address.

Specifically,
getaddrinfo(NULL, port, &hints, &res);

seems to return 127.0.0.1 as interface.

The following patch makes it work for CMA as well.
I also changed cma_loopback_addr to match any address in LOOPBACK
subnet.

--

Interpret any ZERONET/LOOPBACK address as INADDR_ANY.
Make cma_loopback_addr match any address in LOOPBACK subnet.

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Interpret any ZERONET/LOOPBACK address as INADDR_ANY.
Make cma_loopback_addr match any address in LOOPBACK subnet.

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Index: linux-2.6.16/drivers/infiniband/core/cma.c
===================================================================
--- linux-2.6.16/drivers/infiniband/core/cma.c	(revision 6012)
+++ linux-2.6.16/drivers/infiniband/core/cma.c	(working copy)
@@ -446,10 +447,10 @@ static inline int cma_any_addr(struct so
 {
 	struct in6_addr *ip6;
 
-	if (addr->sa_family == AF_INET)
-		return ((struct sockaddr_in *) addr)->sin_addr.s_addr ==
-			INADDR_ANY;
-	else {
+	if (addr->sa_family == AF_INET) {
+		__u32 s_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+		return ZERONET(s_addr) || LOOPBACK(s_addr);
+	} else {
 		ip6 = &((struct sockaddr_in6 *) addr)->sin6_addr;
 		return (ip6->s6_addr32[0] | ip6->s6_addr32[1] |
 			ip6->s6_addr32[3] | ip6->s6_addr32[4]) == 0;
@@ -458,8 +459,7 @@ static inline int cma_any_addr(struct so
 
 static inline int cma_loopback_addr(struct sockaddr *addr)
 {
-	return ((struct sockaddr_in *) addr)->sin_addr.s_addr ==
-		ntohl(INADDR_LOOPBACK);
+	return LOOPBACK(((struct sockaddr_in *) addr)->sin_addr.s_addr);
 }
 
 static int cma_get_net_info(void *hdr, enum rdma_port_space ps,

-- 
Michael S. Tsirkin
Staff Engineer, Mellanox Technologies



More information about the general mailing list