[openib-general] [PATCH][uDAPL] openib_cma provider update
Arlin Davis
arlin.r.davis at intel.com
Fri Dec 9 12:39:15 PST 2005
James,
I modified the IP address lookup during the open to take either a network name, network address, or
device name. This will make the dat.conf setup a little easier and more flexible. I updated the
README, and /doc/dat.conf with details.
Thanks,
-arlin
Signed-off by: Arlin Davis <ardavis at ichips.intel.com>
Index: dapl/openib_cma/dapl_ib_util.c
===================================================================
--- dapl/openib_cma/dapl_ib_util.c (revision 4361)
+++ dapl/openib_cma/dapl_ib_util.c (working copy)
@@ -58,6 +58,13 @@ static const char rcsid[] = "$Id: $";
#include <sys/poll.h>
#include <fcntl.h>
+#include <sys/ioctl.h> /* for IOCTL's */
+#include <sys/types.h> /* for socket(2) and related bits and pieces */
+#include <sys/socket.h> /* for socket(2) */
+#include <net/if.h> /* for struct ifreq */
+#include <net/if_arp.h> /* for ARPHRD_INFINIBAND */
+
+
int g_dapl_loopback_connection = 0;
int g_ib_pipe[2];
ib_thread_state_t g_ib_thread_state = 0;
@@ -65,39 +72,77 @@ DAPL_OS_THREAD g_ib_thread;
DAPL_OS_LOCK g_hca_lock;
struct dapl_llist_entry *g_hca_list;
-/* Get IP address */
+/* Get IP address using network device name */
+static int getipaddr_netdev(char *name, char *addr, int addr_len)
+{
+ struct ifreq ifr;
+ int skfd, ret, len;
+
+ /* Fill in the structure */
+ snprintf(ifr.ifr_name, IFNAMSIZ, "%s", name);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_INFINIBAND;
+
+ /* Create a socket fd */
+ skfd = socket(PF_INET, SOCK_STREAM, 0);
+ ret = ioctl(skfd, SIOCGIFADDR, &ifr);
+ if (ret)
+ goto bail;
+
+ switch (ifr.ifr_addr.sa_family)
+ {
+#ifdef AF_INET6
+ case AF_INET6:
+ len = sizeof(struct sockaddr_in6);
+ break;
+#endif
+ case AF_INET:
+ default:
+ len = sizeof(struct sockaddr);
+ break;
+ }
+
+ if (len <= addr_len)
+ memcpy(addr, &ifr.ifr_addr, len);
+ else
+ ret = EINVAL;
+
+bail:
+ close(skfd);
+ return ret;
+}
+
+/* Get IP address using network name, address, or device name */
static int getipaddr(char *name, char *addr, int len)
{
struct addrinfo *res;
int ret;
-
- ret = getaddrinfo(name, NULL, NULL, &res);
- if (ret) {
- dapl_dbg_log(DAPL_DBG_TYPE_WARN,
- " getipaddr: invalid name or address (%s)\n",
- name);
+
+ /* Assume network name and address type for first attempt */
+ if (getaddrinfo(name, NULL, NULL, &res)) {
+ /* retry using network device name */
+ ret = getipaddr_netdev(name,addr,len);
+ if (ret)
+ dapl_dbg_log(DAPL_DBG_TYPE_WARN,
+ " getipaddr: invalid name, addr, or netdev(%s)\n",
+ name);
return ret;
+ } else {
+ if (len >= res->ai_addrlen)
+ memcpy(addr, res->ai_addr, res->ai_addrlen);
+ else
+ return EINVAL;
+
+ freeaddrinfo(res);
}
dapl_dbg_log(DAPL_DBG_TYPE_UTIL,
" getipaddr: family %d port %d addr %d.%d.%d.%d\n",
- ((struct sockaddr_in *)res->ai_addr)->sin_family,
- ((struct sockaddr_in *)res->ai_addr)->sin_port,
- ((struct sockaddr_in *)
- res->ai_addr)->sin_addr.s_addr >> 0 & 0xff,
- ((struct sockaddr_in *)
- res->ai_addr)->sin_addr.s_addr >> 8 & 0xff,
- ((struct sockaddr_in *)
- res->ai_addr)->sin_addr.s_addr >> 16 & 0xff,
- ((struct sockaddr_in *)
- res->ai_addr)->sin_addr.s_addr >> 24 & 0xff );
-
- if (len >= res->ai_addrlen)
- memcpy(addr, res->ai_addr, res->ai_addrlen);
- else
- return EINVAL;
-
- freeaddrinfo(res);
+ ((struct sockaddr_in *)addr)->sin_family,
+ ((struct sockaddr_in *)addr)->sin_port,
+ ((struct sockaddr_in *)addr)->sin_addr.s_addr >> 0 & 0xff,
+ ((struct sockaddr_in *)addr)->sin_addr.s_addr >> 8 & 0xff,
+ ((struct sockaddr_in *)addr)->sin_addr.s_addr >> 16 & 0xff,
+ ((struct sockaddr_in *)addr)->sin_addr.s_addr >> 24 & 0xff);
return 0;
}
Index: doc/dat.conf
===================================================================
--- doc/dat.conf (revision 4361)
+++ doc/dat.conf (working copy)
@@ -9,9 +9,12 @@
# Example for openib_cma and openib_scm
#
# For scm version you specify <ia_params> as actual device name and port
-# For cma version you specify <ia_params> as the ib device network address or network hostname and
0 for port
+# For cma version you specify <ia_params> as:
+# network address, network hostname, or netdev name and 0 for port
#
OpenIB-scm1 u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so mv_dapl.1.2
"mthca0 1" ""
OpenIB-scm2 u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so mv_dapl.1.2
"mthca0 2" ""
OpenIB-cma-ip u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so mv_dapl.1.2
"192.168.0.22 0" ""
OpenIB-cma-name u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so
mv_dapl.1.2 "svr1-ib0 0" ""
+OpenIB-cma-netdev u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so
mv_dapl.1.2 "ib0 0" ""
+
Index: README
===================================================================
--- README (revision 4361)
+++ README (working copy)
@@ -63,12 +63,14 @@ sample /etc/dat.conf
# Example for openib_cma and openib_scm
#
# For scm version you specify <ia_params> as actual device name and port
-# For cma version you specify <ia_params> as the ib device network address or network hostname and
0 for port
+# For cma version you specify <ia_params> as:
+# network address, network hostname, or netdev name and 0 for port
#
OpenIB-scm1 u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so mv_dapl.1.2
"mthca0 1" ""
OpenIB-scm2 u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so mv_dapl.1.2
"mthca0 2" ""
OpenIB-cma-ip u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so mv_dapl.1.2
"192.168.0.22 0" ""
OpenIB-cma-name u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so
mv_dapl.1.2 "svr1-ib0 0" ""
+OpenIB-cma-netdev u1.2 nonthreadsafe default /usr/local/openib_dapl/udapl/Target/libdapl.so
mv_dapl.1.2 "ib0 0" ""
=============================
3.0 SAMPLE uDAPL APPLICATION:
More information about the general
mailing list