]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
librdmacm: Enable AF_IB support
authorSean Hefty <sean.hefty@intel.com>
Fri, 17 Aug 2012 21:02:45 +0000 (14:02 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 27 Aug 2012 23:39:52 +0000 (16:39 -0700)
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
include/rdma/rdma_cma.h
src/acm.c
src/cma.c
src/librdmacm.map

index 1487f8f0e9a446849a3d8524247fabfaa72424bb..f3c89211cb7d62ea7bbb9629a7b0d5909438e4a6 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2005 Voltaire Inc.  All rights reserved.
- * Copyright (c) 2005-2010 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2005-2012 Intel Corporation.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -581,19 +581,8 @@ int rdma_get_cm_event(struct rdma_event_channel *channel,
  */
 int rdma_ack_cm_event(struct rdma_cm_event *event);
 
-static inline uint16_t rdma_get_src_port(struct rdma_cm_id *id)
-{
-       return  id->route.addr.src_addr.sa_family == PF_INET6 ?
-               id->route.addr.src_sin6.sin6_port :
-               id->route.addr.src_sin.sin_port;
-}
-
-static inline uint16_t rdma_get_dst_port(struct rdma_cm_id *id)
-{
-       return  id->route.addr.dst_addr.sa_family == PF_INET6 ?
-               id->route.addr.dst_sin6.sin6_port :
-               id->route.addr.dst_sin.sin_port;
-}
+uint16_t rdma_get_src_port(struct rdma_cm_id *id);
+uint16_t rdma_get_dst_port(struct rdma_cm_id *id);
 
 static inline struct sockaddr *rdma_get_local_addr(struct rdma_cm_id *id)
 {
index d96dbcd9aed4c4aade4ab04bbbf672183863dd6d..92411fa99a836758aa3ee19be9f7225163f0fe05 100755 (executable)
--- a/src/acm.c
+++ b/src/acm.c
@@ -324,6 +324,17 @@ static void ucma_copy_rai_addr(struct acm_ep_addr_data *data, struct sockaddr *a
        }
 }
 
+static int ucma_inet_addr(struct sockaddr *addr, socklen_t len)
+{
+       return len && addr && (addr->sa_family == AF_INET ||
+                              addr->sa_family == AF_INET6);
+}
+
+static int ucma_ib_addr(struct sockaddr *addr, socklen_t len)
+{
+       return len && addr && (addr->sa_family == AF_IB);
+}
+
 void ucma_ib_resolve(struct rdma_addrinfo **rai, struct rdma_addrinfo *hints)
 {
        cma_acm_msg_t msg;
@@ -340,14 +351,14 @@ void ucma_ib_resolve(struct rdma_addrinfo **rai, struct rdma_addrinfo *hints)
        msg.hdr.length = ACM_MSG_HDR_LENGTH;
 
        data = &msg.resolve_data[0];
-       if ((*rai)->ai_src_len) {
+       if (ucma_inet_addr((*rai)->ai_src_addr, (*rai)->ai_src_len)) {
                data->flags = ACM_EP_FLAG_SOURCE;
                ucma_copy_rai_addr(data, (*rai)->ai_src_addr);
                data++;
                msg.hdr.length += ACM_MSG_EP_LENGTH;
        }
 
-       if ((*rai)->ai_dst_len) {
+       if (ucma_inet_addr((*rai)->ai_dst_addr, (*rai)->ai_dst_len)) {
                data->flags = ACM_EP_FLAG_DEST;
                if ((*rai)->ai_flags & (RAI_NUMERICHOST | RAI_NOROUTE))
                        data->flags |= ACM_FLAGS_NODELAY;
@@ -356,7 +367,9 @@ void ucma_ib_resolve(struct rdma_addrinfo **rai, struct rdma_addrinfo *hints)
                msg.hdr.length += ACM_MSG_EP_LENGTH;
        }
 
-       if (hints && hints->ai_route_len) {
+       if (hints && (hints->ai_route_len ||
+           ucma_ib_addr((*rai)->ai_src_addr, (*rai)->ai_src_len) ||
+           ucma_ib_addr((*rai)->ai_dst_addr, (*rai)->ai_dst_len))) {
                struct ibv_path_record *path;
 
                if (hints->ai_route_len == sizeof(struct ibv_path_record))
@@ -366,12 +379,20 @@ void ucma_ib_resolve(struct rdma_addrinfo **rai, struct rdma_addrinfo *hints)
                else
                        path = NULL;
 
-               if (path) {
-                       data->type = ACM_EP_INFO_PATH;
+               if (path)
                        memcpy(&data->info.path, path, sizeof(*path));
-                       data++;
-                       msg.hdr.length += ACM_MSG_EP_LENGTH;
+
+               if (ucma_ib_addr((*rai)->ai_src_addr, (*rai)->ai_src_len)) {
+                       memcpy(&data->info.path.sgid,
+                              &((struct sockaddr_ib *) (*rai)->ai_src_addr)->sib_addr, 16);
+               }
+               if (ucma_ib_addr((*rai)->ai_dst_addr, (*rai)->ai_dst_len)) {
+                       memcpy(&data->info.path.dgid,
+                              &((struct sockaddr_ib *) (*rai)->ai_dst_addr)->sib_addr, 16);
                }
+               data->type = ACM_EP_INFO_PATH;
+               data++;
+               msg.hdr.length += ACM_MSG_EP_LENGTH;
        }
 
        pthread_mutex_lock(&acm_lock);
@@ -389,7 +410,7 @@ void ucma_ib_resolve(struct rdma_addrinfo **rai, struct rdma_addrinfo *hints)
        ucma_ib_save_resp(*rai, &msg);
 
        if (af_ib_support && !((*rai)->ai_flags & RAI_ROUTEONLY) &&
-           (*rai)->ai_route_len)
+           (*rai)->ai_route_len && ((*rai)->ai_family != AF_IB))
                ucma_resolve_af_ib(rai);
 }
 
index 4f6a5abddd6c36285308c5feea9da095283e5eed..f4609672979eb58de62cb8f980121d3c04e15f71 100755 (executable)
--- a/src/cma.c
+++ b/src/cma.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005-2011 Intel Corporation.  All rights reserved.
+ * Copyright (c) 2005-2012 Intel Corporation.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -185,9 +185,6 @@ static void ucma_set_af_ib_support(void)
        struct sockaddr_ib sib;
        int ret;
 
-       /* Just return - do not enable AF_IB support for now */
-       return;
-
        ret = rdma_create_id(NULL, &id, NULL, RDMA_PS_IB);
        if (ret)
                return;
@@ -2242,3 +2239,28 @@ int ucma_max_qpsize(struct rdma_cm_id *id)
        id_priv = container_of(id, struct cma_id_private, id);
        return id_priv->cma_dev->max_qpsize;
 }
+
+static uint16_t ucma_get_port(struct sockaddr *addr)
+{
+       switch (addr->sa_family) {
+       case AF_INET:
+               return ((struct sockaddr_in *) addr)->sin_port;
+       case AF_INET6:
+               return ((struct sockaddr_in6 *) addr)->sin6_port;
+       case AF_IB:
+               return htons((uint16_t) ntohll(((struct sockaddr_ib *) addr)->sib_sid));
+       default:
+               return 0;
+       }
+}
+
+uint16_t rdma_get_src_port(struct rdma_cm_id *id)
+{
+       return ucma_get_port(&id->route.addr.src_addr);
+}
+
+uint16_t rdma_get_dst_port(struct rdma_cm_id *id)
+{
+       return ucma_get_port(&id->route.addr.dst_addr);
+}
+
index d994de4a729ddf9f9fcf200b2b469db40a236d85..5c317a3e78704716f59eb4fe6df495a8d95da006 100644 (file)
@@ -61,5 +61,7 @@ RDMACM_1.0 {
                rfcntl;
                rpoll;
                rselect;
+               rdma_get_src_port;
+               rdma_get_dst_port;
        local: *;
 };