1
1

Reorganize the opal interface code in opal/util/if.c per prior emails and telecon discussions. Move the interface discovery code into a framework so that configuration logic can separate it out (instead of the prior #if-#else confusion).

All interface APIs for accessing the info remain unchanged in opal/util/if.c.

This has been tested on Mac, Linux, and NetBSD. Nobody else seemed interested in testing it, so there may be some future problems revealed as people try it on other OSs.

This commit was SVN r23743.
Этот коммит содержится в:
Ralph Castain 2010-09-13 01:58:51 +00:00
родитель 08dd20c834
Коммит e96b5f486f
39 изменённых файлов: 1922 добавлений и 866 удалений

Просмотреть файл

@ -56,6 +56,7 @@
#endif
#include "opal/runtime/opal.h"
#include "opal/dss/dss.h"
#include "opal/mca/if/base/base.h"
#include "ompi/mca/allocator/base/base.h"
#include "ompi/mca/coll/base/base.h"
@ -345,7 +346,15 @@ void ompi_info_open_components(void)
map->components = &opal_compress_base_components_available;
opal_pointer_array_add(&component_map, map);
#endif
if (OPAL_SUCCESS != opal_if_base_open()) {
goto error;
}
map = OBJ_NEW(ompi_info_component_map_t);
map->type = strdup("if");
map->components = &opal_if_components;
opal_pointer_array_add(&component_map, map);
/* OPAL's installdirs base open has already been called as part of
* opal_init_util() back in main().
*/

Просмотреть файл

@ -203,6 +203,8 @@ int main(int argc, char *argv[])
opal_pointer_array_add(&mca_types, "crs");
opal_pointer_array_add(&mca_types, "compress");
#endif
opal_pointer_array_add(&mca_types, "if");
opal_pointer_array_add(&mca_types, "dpm");
opal_pointer_array_add(&mca_types, "pubsub");
opal_pointer_array_add(&mca_types, "allocator");

54
opal/config/opal_check_os_flavors.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,54 @@
dnl -*- shell-script -*-
dnl
dnl Copyright (c) 2010 Cisco Systems, In. All rights reserved.
dnl
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl
# OPAL_CHECK_OS_FLAVOR_SPECIFIC()
# ----------------------------------------------------
# Helper macro from OPAL-CHECK-OS-FLAVORS(), below.
# $1 = macro to look for
# $2 = suffix of env variable to set with results
AC_DEFUN([OPAL_CHECK_OS_FLAVOR_SPECIFIC],
[
AC_MSG_CHECKING([$1])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[#ifndef $1
error: this isnt $1
#endif
]])],
[opal_found_$2=yes],
[opal_found_$2=no])
AC_MSG_RESULT([$opal_found_$2])
])dnl
# OPAL_CHECK_OS_FLAVORS()
# ----------------------------------------------------
# Try to figure out the various OS flavors out there.
#
AC_DEFUN([OPAL_CHECK_OS_FLAVORS],
[
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__NetBSD__], [netbsd])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__FreeBSD__], [freebsd])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__OpenBSD__], [openbsd])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__DragonFly__], [dragonfly])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__386BSD__], [386bsd])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__bsdi__], [bsdi])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__APPLE__], [apple])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__linux__], [linux])
OPAL_CHECK_OS_FLAVOR_SPECIFIC([__sun__], [sun])
# check for sockaddr_in (a good sign we have TCP)
AC_CHECK_TYPES([struct sockaddr_in],
[opal_found_sockaddr=yes],
[opal_found_sockaddr=no],
[AC_INCLUDES_DEFAULT
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif])
])dnl

32
opal/mca/if/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,32 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# main library setup
noinst_LTLIBRARIES = libmca_if.la
libmca_if_la_SOURCES =
# header setup
nobase_opal_HEADERS =
# local files
headers = if.h
libmca_if_la_SOURCES += $(headers)
# Conditionally install the header files
if WANT_INSTALL_HEADERS
nobase_opal_HEADERS += $(headers)
opaldir = $(includedir)/openmpi/opal/mca/if
else
opaldir = $(includedir)
endif
include base/Makefile.am
distclean-local:
rm -f base/static-components.h

14
opal/mca/if/base/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,14 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
headers += \
base/base.h
libmca_if_la_SOURCES += \
base/if_base_components.c

33
opal/mca/if/base/base.h Обычный файл
Просмотреть файл

@ -0,0 +1,33 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#ifndef OPAL_IF_BASE_H
#define OPAL_IF_BASE_H
#include "opal_config.h"
#include "opal/mca/if/if.h"
/*
* Global functions for MCA overall if open and close
*/
BEGIN_C_DECLS
OPAL_DECLSPEC int opal_if_base_open(void);
OPAL_DECLSPEC int opal_if_base_close(void);
/*
* Globals
*/
OPAL_DECLSPEC extern opal_list_t opal_if_components;
END_C_DECLS
#endif /* OPAL_BASE_IF_H */

104
opal/mca/if/base/if_base_components.c Обычный файл
Просмотреть файл

@ -0,0 +1,104 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/mca.h"
#include "opal/mca/if/if.h"
#include "opal/mca/if/base/base.h"
#include "opal/mca/if/base/static-components.h"
int opal_if_base_output;
opal_list_t opal_if_components;
static bool already_done = false;
/* instantiate the global list of interfaces */
opal_list_t opal_if_list;
bool opal_if_do_not_resolve;
bool opal_if_retain_loopback;
/* instance the opal_if_t object */
OBJ_CLASS_INSTANCE(opal_if_t, opal_list_item_t, NULL, NULL);
int opal_if_base_open(void)
{
int i, ret;
mca_base_component_list_item_t *cli;
if (already_done) {
return OPAL_SUCCESS;
}
already_done = true;
/* setup the global list */
OBJ_CONSTRUCT(&opal_if_list, opal_list_t);
mca_base_param_reg_int_name("opal", "if_do_not_resolve",
"If nonzero, do not attempt to resolve interfaces",
false, false, (int)false, &ret);
opal_if_do_not_resolve = OPAL_INT_TO_BOOL(ret);
mca_base_param_reg_int_name("opal", "if_retain_loopback",
"If nonzero, retain loopback interfaces",
false, false, (int)false, &ret);
opal_if_retain_loopback = OPAL_INT_TO_BOOL(ret);
OBJ_CONSTRUCT(&opal_if_components, opal_list_t);
for (i = 0 ; mca_if_base_static_components[i] != NULL ; ++i) {
opal_if_base_component_t *component =
(opal_if_base_component_t*)
mca_if_base_static_components[i];
/* Save it in a global list for ompi_info */
cli = OBJ_NEW(mca_base_component_list_item_t);
cli->cli_component = mca_if_base_static_components[i];
opal_list_append(&opal_if_components, &cli->super);
if (NULL != component->component.mca_open_component) {
ret = component->component.mca_open_component();
if (OPAL_SUCCESS != ret) continue;
}
if (NULL != mca_if_base_static_components[i]->mca_close_component) {
mca_if_base_static_components[i]->mca_close_component();
}
}
return OPAL_SUCCESS;
}
int opal_if_base_close(void)
{
opal_list_item_t *item;
if (!already_done) {
return OPAL_SUCCESS;
}
already_done = false;
for (item = opal_list_remove_first(&opal_if_list);
NULL != item;
item = opal_list_remove_first(&opal_if_list)) {
OBJ_RELEASE(item);
}
OBJ_DESTRUCT(&opal_if_list);
for (item = opal_list_remove_first(&opal_if_components);
NULL != item;
item = opal_list_remove_first(&opal_if_components)) {
OBJ_RELEASE(item);
}
OBJ_DESTRUCT(&opal_if_components);
return OPAL_SUCCESS;
}

12
opal/mca/if/bsdx_ipv4/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,12 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_if_bsdx_ipv4.la
libmca_if_bsdx_ipv4_la_SOURCES = if_bsdx.c

39
opal/mca/if/bsdx_ipv4/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,39 @@
# -*- shell-script -*-
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_if_bsdx_ipv4_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_if_config_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_if_bsdx_ipv4_CONFIG], [
AC_REQUIRE([OPAL_CHECK_OS_FLAVORS])
# If we found struct sockaddr and we're on any of the BSDs, we're
# happy. I.e., this:
#if defined(__NetBSD__) || defined(__FreeBSD__) || \
# defined(__OpenBSD__) || defined(__DragonFly__)
AC_MSG_CHECKING([struct sockaddr])
AS_IF([test "$opal_found_sockaddr" = "yes"],
[AC_MSG_RESULT([yes (cached)])
AC_MSG_CHECKING([NetBSD, FreeBSD, OpenBSD, or DragonFly])
AS_IF([test "$opal_found_netbsd" = "yes" -o "$opal_found_freebsd" = "yes" -o "$opal_found_openbsd" = "yes" -o "$opal_found_dragonfly" = "yes"],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])],
[AC_MSG_RESULT([no (cached)])
$2])
])

15
opal/mca/if/bsdx_ipv4/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,15 @@
# -*- shell-script -*-
#
# Copyright (c) 2006 Los Alamos National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_CONFIG_PRIORITY=10
PARAM_CONFIG_FILES="Makefile"

143
opal/mca/if/bsdx_ipv4/if_bsdx.c Обычный файл
Просмотреть файл

@ -0,0 +1,143 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include "opal/constants.h"
#include "opal/mca/if/if.h"
static int if_bsdx_open(void);
/* Supports specific flavors of BSD:
* NetBSD
* FreeBSD
* OpenBSD
* DragonFly
*/
opal_if_base_component_t mca_if_bsdx_ipv4_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
OPAL_IF_BASE_VERSION_2_0_0,
/* Component name and version */
"bsdx_ipv4",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
if_bsdx_open,
NULL
},
{
/* This component is checkpointable */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
/* convert a netmask (in network byte order) to CIDR notation */
static int prefix (uint32_t netmask)
{
uint32_t mask = ntohl(netmask);
int plen = 0;
if (0 == mask) {
plen = 32;
} else {
while ((mask % 2) == 0) {
plen += 1;
mask /= 2;
}
}
return (32 - plen);
}
/* configure using getifaddrs(3) */
static int if_bsdx_open(void)
{
struct ifaddrs **ifadd_list;
struct ifaddrs *cur_ifaddrs;
struct sockaddr_in* sin_addr;
/*
* the manpage claims that getifaddrs() allocates the memory,
* and freeifaddrs() is later used to release the allocated memory.
* however, without this malloc the call to getifaddrs() segfaults
*/
ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*));
/* create the linked list of ifaddrs structs */
if (getifaddrs(ifadd_list) < 0) {
opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n",
errno);
return OPAL_ERROR;
}
for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
cur_ifaddrs = cur_ifaddrs->ifa_next) {
opal_if_t *intf;
struct in_addr a4;
/* skip non- af_inet interface addresses */
if (AF_INET != cur_ifaddrs->ifa_addr->sa_family) {
continue;
}
/* skip interface if it is down (IFF_UP not set) */
if (0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
continue;
}
/* skip interface if it is a loopback device (IFF_LOOPBACK set) */
if (!opal_if_retain_loopback && 0 != (cur_ifaddrs->ifa_flags & IFF_LOOPBACK)) {
continue;
}
/* or if it is a point-to-point interface */
/* TODO: do we really skip p2p? */
if (0 != (cur_ifaddrs->ifa_flags & IFF_POINTOPOINT)) {
continue;
}
sin_addr = (struct sockaddr_in *) cur_ifaddrs->ifa_addr;
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output(0, "opal_ifinit: unable to allocate %d bytes\n",
(int) sizeof(opal_if_t));
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* fill values into the opal_if_t */
memcpy(&a4, &(sin_addr->sin_addr), sizeof(struct in_addr));
strncpy(intf->if_name, cur_ifaddrs->ifa_name, IF_NAMESIZE);
intf->if_index = opal_list_get_size(&opal_if_list) + 1;
((struct sockaddr_in*) &intf->if_addr)->sin_addr = a4;
((struct sockaddr_in*) &intf->if_addr)->sin_family = AF_INET;
((struct sockaddr_in*) &intf->if_addr)->sin_len = cur_ifaddrs->ifa_addr->sa_len;
intf->if_mask = prefix( sin_addr->sin_addr.s_addr);
intf->if_flags = cur_ifaddrs->ifa_flags;
intf->if_kernel_index =
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
opal_list_append(&opal_if_list, &(intf->super));
} /* of for loop over ifaddrs list */
return OPAL_SUCCESS;
}

12
opal/mca/if/bsdx_ipv6/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,12 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_if_bsdx_ipv6.la
libmca_if_bsdx_ipv6_la_SOURCES = if_bsdx_ipv6.c

38
opal/mca/if/bsdx_ipv6/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,38 @@
# -*- shell-script -*-
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_if_bsdx_ipv6_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_if_config_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_if_bsdx_ipv6_CONFIG], [
AC_REQUIRE([OPAL_CHECK_OS_FLAVORS])
# If we found struct sockaddr and we're on any of the BSDs, we're
# happy. I.e., this:
#if defined( __NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
# defined(__386BSD__) || defined(__bsdi__) || defined(__APPLE__)
AC_MSG_CHECKING([struct sockaddr])
AS_IF([test "$opal_found_sockaddr" = "yes"],
[AC_MSG_RESULT([yes (cached)])
AC_MSG_CHECKING([some flavor of BSD])
AS_IF([test "$opal_found_netbsd" = "yes" -o "$opal_found_freebsd" = "yes" -o "$opal_found_openbsd" = "yes" -o "$opal_found_386bsd" = "yes" -o "$opal_found_bsdi" = "yes" -o "$opal_found_apple" = "yes"],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])],
[AC_MSG_RESULT([no (cached)])
$2])
])dnl

15
opal/mca/if/bsdx_ipv6/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,15 @@
# -*- shell-script -*-
#
# Copyright (c) 2006 Los Alamos National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_CONFIG_PRIORITY=10
PARAM_CONFIG_FILES="Makefile"

219
opal/mca/if/bsdx_ipv6/if_bsdx_ipv6.c Обычный файл
Просмотреть файл

@ -0,0 +1,219 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NET_IF_H
#if defined(__APPLE__) && defined(_LP64)
/* Apple engineering suggested using options align=power as a
workaround for a bug in OS X 10.4 (Tiger) that prevented ioctl(...,
SIOCGIFCONF, ...) from working properly in 64 bit mode on Power PC.
It turns out that the underlying issue is the size of struct
ifconf, which the kernel expects to be 12 and natural 64 bit
alignment would make 16. The same bug appears in 64 bit mode on
Intel macs, but align=power is a no-op there, so instead, use the
pack pragma to instruct the compiler to pack on 4 byte words, which
has the same effect as align=power for our needs and works on both
Intel and Power PC Macs. */
#pragma pack(push,4)
#endif
#include <net/if.h>
#if defined(__APPLE__) && defined(_LP64)
#pragma pack(pop)
#endif
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#include "opal/mca/if/if.h"
static int if_bsdx_ipv6_open(void);
/* Discovers IPv6 interfaces for:
*
* NetBSD
* OpenBSD
* FreeBSD
* 386BSD
* bsdi
* Apple
*/
opal_if_base_component_t mca_if_bsdx_ipv6_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
OPAL_IF_BASE_VERSION_2_0_0,
/* Component name and version */
"bsdx_ipv6",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
if_bsdx_ipv6_open,
NULL
},
{
/* This component is checkpointable */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
/* configure using getifaddrs(3) */
static int if_bsdx_ipv6_open(void)
{
struct ifaddrs **ifadd_list;
struct ifaddrs *cur_ifaddrs;
struct sockaddr_in6* sin_addr;
/*
* the manpage claims that getifaddrs() allocates the memory,
* and freeifaddrs() is later used to release the allocated memory.
* however, without this malloc the call to getifaddrs() segfaults
*/
ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*));
/* create the linked list of ifaddrs structs */
if (getifaddrs(ifadd_list) < 0) {
opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n",
errno);
return OPAL_ERROR;
}
for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
cur_ifaddrs = cur_ifaddrs->ifa_next) {
opal_if_t *intf;
struct in6_addr a6;
/* skip non-ipv6 interface addresses */
if (AF_INET6 != cur_ifaddrs->ifa_addr->sa_family) {
#if 0
printf("skipping non-ipv6 interface %s.\n", cur_ifaddrs->ifa_name);
#endif
continue;
}
/* skip interface if it is down (IFF_UP not set) */
if (0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
#if 0
printf("skipping non-up interface %s.\n", cur_ifaddrs->ifa_name);
#endif
continue;
}
/* skip interface if it is a loopback device (IFF_LOOPBACK set) */
if (!opal_if_retain_loopback && 0 != (cur_ifaddrs->ifa_flags & IFF_LOOPBACK)) {
continue;
}
/* or if it is a point-to-point interface */
/* TODO: do we really skip p2p? */
if (0!= (cur_ifaddrs->ifa_flags & IFF_POINTOPOINT)) {
#if 0
printf("skipping loopback interface %s.\n", cur_ifaddrs->ifa_name);
#endif
continue;
}
sin_addr = (struct sockaddr_in6 *) cur_ifaddrs->ifa_addr;
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n",
sizeof(opal_if_t));
return OPAL_ERR_OUT_OF_RESOURCE;
}
/*
* skip IPv6 address starting with fe80:, as this is supposed to be
* link-local scope. sockaddr_in6->sin6_scope_id doesn't always work
* TODO: test whether scope id is set to a sensible value on
* linux and/or bsd (including osx)
*
* MacOSX: fe80::... has a scope of 0, but ifconfig -a shows
* a scope of 4 on that particular machine,
* so the scope returned by getifaddrs() isn't working properly
*/
if ((IN6_IS_ADDR_LINKLOCAL (&sin_addr->sin6_addr))) {
#if 0
printf("skipping link-local ipv6 address on interface \
%s with scope %d.\n",
cur_ifaddrs->ifa_name, sin_addr->sin6_scope_id);
#endif
continue;
}
#if 0
char *addr_name = (char *) malloc(48*sizeof(char));
inet_ntop(AF_INET6, &sin_addr->sin6_addr, addr_name, 48*sizeof(char));
opal_output(0, "ipv6 capable interface %s discovered, address %s.\n",
cur_ifaddrs->ifa_name, addr_name);
free(addr_name);
#endif
/* fill values into the opal_if_t */
memcpy(&a6, &(sin_addr->sin6_addr), sizeof(struct in6_addr));
strncpy(intf->if_name, cur_ifaddrs->ifa_name, IF_NAMESIZE);
intf->if_index = opal_list_get_size(&opal_if_list) + 1;
((struct sockaddr_in6*) &intf->if_addr)->sin6_addr = a6;
((struct sockaddr_in6*) &intf->if_addr)->sin6_family = AF_INET6;
/* since every scope != 0 is ignored, we just set the scope to 0 */
((struct sockaddr_in6*) &intf->if_addr)->sin6_scope_id = 0;
/*
* hardcoded netmask, adrian says that's ok
*/
intf->if_mask = 64;
intf->if_flags = cur_ifaddrs->ifa_flags;
/*
* FIXME: figure out how to gain access to the kernel index
* (or create our own), getifaddrs() does not contain such
* data
*/
intf->if_kernel_index =
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
opal_list_append(&opal_if_list, &(intf->super));
} /* of for loop over ifaddrs list */
return OPAL_SUCCESS;
}

136
opal/mca/if/if.h Обычный файл
Просмотреть файл

@ -0,0 +1,136 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_IF_IF_H
#define OPAL_MCA_IF_IF_H
#include "opal_config.h"
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NET_IF_H
#if defined(__APPLE__) && defined(_LP64)
/* Apple engineering suggested using options align=power as a
workaround for a bug in OS X 10.4 (Tiger) that prevented ioctl(...,
SIOCGIFCONF, ...) from working properly in 64 bit mode on Power PC.
It turns out that the underlying issue is the size of struct
ifconf, which the kernel expects to be 12 and natural 64 bit
alignment would make 16. The same bug appears in 64 bit mode on
Intel macs, but align=power is a no-op there, so instead, use the
pack pragma to instruct the compiler to pack on 4 byte words, which
has the same effect as align=power for our needs and works on both
Intel and Power PC Macs. */
#pragma pack(push,4)
#endif
#include <net/if.h>
#if defined(__APPLE__) && defined(_LP64)
#pragma pack(pop)
#endif
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
BEGIN_C_DECLS
/*
* Define INADDR_NONE if we don't have it. Solaris is the only system
* where I have found that it does not exist, and the man page for
* inet_addr() says that it returns -1 upon failure. On Linux and
* other systems with INADDR_NONE, it's just a #define to -1 anyway.
* So just #define it to -1 here if it doesn't already exist.
*/
#if !defined(INADDR_NONE)
#define INADDR_NONE -1
#endif
#define DEFAULT_NUMBER_INTERFACES 10
#define MAX_IFCONF_SIZE 10 * 1024 * 1024
typedef struct opal_if_t {
opal_list_item_t super;
char if_name[IF_NAMESIZE];
int if_index;
uint16_t if_kernel_index;
#ifndef __WINDOWS__
int if_flags;
#else
u_long if_flags;
#endif
int if_speed;
struct sockaddr_storage if_addr;
uint32_t if_mask;
#ifdef __WINDOWS__
struct sockaddr_in if_bcast;
#endif
uint32_t if_bandwidth;
} opal_if_t;
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_if_t);
/* "global" list of available interfaces */
OPAL_DECLSPEC extern opal_list_t opal_if_list;
/* global flags */
OPAL_DECLSPEC extern bool opal_if_do_not_resolve;
OPAL_DECLSPEC extern bool opal_if_retain_loopback;
/**
* Structure for if components.
*/
struct opal_if_base_component_2_0_0_t {
/** MCA base component */
mca_base_component_t component;
/** MCA base data */
mca_base_component_data_t component_data;
};
/**
* Convenience typedef
*/
typedef struct opal_if_base_component_2_0_0_t opal_if_base_component_t;
/*
* Macro for use in components that are of type if
*/
#define OPAL_IF_BASE_VERSION_2_0_0 \
MCA_BASE_VERSION_2_0_0, \
"if", 2, 0, 0
END_C_DECLS
#endif /* OPAL_MCA_IF_IF_H */

12
opal/mca/if/linux_ipv6/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,12 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_if_linux_ipv6.la
libmca_if_linux_ipv6_la_SOURCES = if_linux_ipv6.c

31
opal/mca/if/linux_ipv6/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,31 @@
# -*- shell-script -*-
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_if_linux_ipv6_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_if_config_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_if_linux_ipv6_CONFIG], [
AC_REQUIRE([OPAL_CHECK_OS_FLAVORS])
AC_MSG_CHECKING([if we are on Linux with TCP])
# If we have struct sockaddr and we're on Linux, then we're
# happy.
AS_IF([test "$opal_found_sockaddr" = "yes" -a "$opal_found_linux" = "yes"],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])
])dnl

15
opal/mca/if/linux_ipv6/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,15 @@
# -*- shell-script -*-
#
# Copyright (c) 2006 Los Alamos National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_CONFIG_PRIORITY=10
PARAM_CONFIG_FILES="Makefile"

153
opal/mca/if/linux_ipv6/if_linux_ipv6.c Обычный файл
Просмотреть файл

@ -0,0 +1,153 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NET_IF_H
#if defined(__APPLE__) && defined(_LP64)
/* Apple engineering suggested using options align=power as a
workaround for a bug in OS X 10.4 (Tiger) that prevented ioctl(...,
SIOCGIFCONF, ...) from working properly in 64 bit mode on Power PC.
It turns out that the underlying issue is the size of struct
ifconf, which the kernel expects to be 12 and natural 64 bit
alignment would make 16. The same bug appears in 64 bit mode on
Intel macs, but align=power is a no-op there, so instead, use the
pack pragma to instruct the compiler to pack on 4 byte words, which
has the same effect as align=power for our needs and works on both
Intel and Power PC Macs. */
#pragma pack(push,4)
#endif
#include <net/if.h>
#if defined(__APPLE__) && defined(_LP64)
#pragma pack(pop)
#endif
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#include "opal/constants.h"
#include "opal/util/if.h"
#include "opal/mca/if/if.h"
static int if_linux_ipv6_open(void);
/* Discovers Linux IPv6 interfaces */
opal_if_base_component_t mca_if_linux_ipv6_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
OPAL_IF_BASE_VERSION_2_0_0,
/* Component name and version */
"linux_ipv6",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
if_linux_ipv6_open,
NULL
},
{
/* This component is checkpointable */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
/* configure using getifaddrs(3) */
static int if_linux_ipv6_open(void)
{
FILE *f;
if ((f = fopen("/proc/net/if_inet6", "r"))) {
char ifname[IF_NAMESIZE];
unsigned int idx, pfxlen, scope, dadstat;
struct in6_addr a6;
int iter;
uint32_t flag;
unsigned int addrbyte[16];
while (fscanf(f, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x %x %x %x %x %20s\n",
&addrbyte[0], &addrbyte[1], &addrbyte[2], &addrbyte[3],
&addrbyte[4], &addrbyte[5], &addrbyte[6], &addrbyte[7],
&addrbyte[8], &addrbyte[9], &addrbyte[10], &addrbyte[11],
&addrbyte[12], &addrbyte[13], &addrbyte[14], &addrbyte[15],
&idx, &pfxlen, &scope, &dadstat, ifname) != EOF) {
opal_if_t *intf;
/* we don't want any other scope than global */
if (scope != 0) {
continue;
}
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n",
(unsigned long)sizeof(opal_if_t));
fclose(f);
return OPAL_ERR_OUT_OF_RESOURCE;
}
for (iter = 0; iter < 16; iter++) {
a6.s6_addr[iter] = addrbyte[iter];
}
/* now construct the opal_if_t */
strncpy(intf->if_name, ifname, IF_NAMESIZE);
intf->if_index = opal_list_get_size(&opal_if_list)+1;
intf->if_kernel_index = (uint16_t) idx;
((struct sockaddr_in6*) &intf->if_addr)->sin6_addr = a6;
((struct sockaddr_in6*) &intf->if_addr)->sin6_family = AF_INET6;
((struct sockaddr_in6*) &intf->if_addr)->sin6_scope_id = scope;
intf->if_mask = pfxlen;
if (OPAL_SUCCESS == opal_ifindextoflags(opal_ifnametoindex (ifname), &flag)) {
intf->if_flags = flag;
} else {
intf->if_flags = IFF_UP;
}
/* copy new interface information to heap and append
to list */
opal_list_append(&opal_if_list, &(intf->super));
} /* of while */
fclose(f);
}
return OPAL_SUCCESS;
}

12
opal/mca/if/posix_ipv4/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,12 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_if_posix_ipv4.la
libmca_if_posix_ipv4_la_SOURCES = if_posix.c

38
opal/mca/if/posix_ipv4/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,38 @@
# -*- shell-script -*-
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_if_posix_ipv4_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_if_config_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_if_posix_ipv4_CONFIG], [
AC_REQUIRE([OPAL_CHECK_OS_FLAVORS])
# If we found struct sockaddr and we're NOT on most of the BSDs,
# we're happy. I.e., if posix but not:
#if defined(__NetBSD__) || defined(__FreeBSD__) || \
# defined(__OpenBSD__) || defined(__DragonFly__)
AC_MSG_CHECKING([struct sockaddr])
AS_IF([test "$opal_found_sockaddr" = "yes"],
[AC_MSG_RESULT([yes (cached)])
AC_MSG_CHECKING([not NetBSD, FreeBSD, OpenBSD, or DragonFly])
AS_IF([test "$opal_found_netbsd" = "no" -a "$opal_found_freebsd" = "no" -a "$opal_found_openbsd" = "no" -a "$opal_found_dragonfly" = "no"],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])],
[AC_MSG_RESULT([no (cached)])
$2])
])dnl

15
opal/mca/if/posix_ipv4/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,15 @@
# -*- shell-script -*-
#
# Copyright (c) 2006 Los Alamos National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_CONFIG_PRIORITY=10
PARAM_CONFIG_FILES="Makefile"

264
opal/mca/if/posix_ipv4/if_posix.c Обычный файл
Просмотреть файл

@ -0,0 +1,264 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include "opal/constants.h"
#include "opal/mca/if/if.h"
static int if_posix_open(void);
/* Supports all flavors of posix except those
* BSD-flavors supported elsewhere
*/
opal_if_base_component_t mca_if_posix_ipv4_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
OPAL_IF_BASE_VERSION_2_0_0,
/* Component name and version */
"posix_ipv4",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
if_posix_open,
NULL
},
{
/* This component is checkpointable */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
/* convert a netmask (in network byte order) to CIDR notation */
static int prefix (uint32_t netmask)
{
uint32_t mask = ntohl(netmask);
int plen = 0;
if (0 == mask) {
plen = 32;
} else {
while ((mask % 2) == 0) {
plen += 1;
mask /= 2;
}
}
return (32 - plen);
}
/* configure using getifaddrs(3) */
static int if_posix_open(void)
{
int sd;
int lastlen, num, rem;
char *ptr;
struct ifconf ifconf;
int ifc_len;
bool successful_locate = false;
/* Create the internet socket to test with. Must use AF_INET;
using AF_UNSPEC or AF_INET6 will cause everything to
fail. */
if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
opal_output(0, "opal_ifinit: socket() failed with errno=%d\n",
errno);
return OPAL_ERROR;
}
/*
* Get Network Interface configuration
*
* Some notes on the behavior of ioctl(..., SIOCGIFCONF,...)
* when not enough space is allocated for all the entries.
*
* - Solaris returns -1, errno EINVAL if there is not enough
* space
* - OS X returns 0, sets .ifc_len to the space used by the
* by the entries that did fit.
* - Linux returns 0, sets .ifc_len to the space required to
* hold all the entries (although it only writes what will
* fit in the buffer of .ifc_len passed to the function).
* - FreeBSD returns 0, sets .ifc_len to 0.
*
* Everyone else seems to do one of the four.
*/
lastlen = 0;
ifc_len = sizeof(struct ifreq) * DEFAULT_NUMBER_INTERFACES;
do {
ifconf.ifc_len = ifc_len;
ifconf.ifc_req = malloc(ifc_len);
if (NULL == ifconf.ifc_req) {
close(sd);
return OPAL_ERROR;
}
/* initialize the memory so valgrind and purify won't
* complain. Since this isn't performance critical, just
* always memset.
*/
memset(ifconf.ifc_req, 0, ifconf.ifc_len);
if (ioctl(sd, SIOCGIFCONF, &ifconf) < 0) {
/* if we got an einval, we probably don't have enough
space. so we'll fall down and try to expand our
space */
if (errno != EINVAL && lastlen != 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFCONF) \
failed with errno=%d",
errno);
free(ifconf.ifc_req);
close(sd);
return OPAL_ERROR;
}
} else {
/* if ifc_len is 0 or different than what we set it to
at call to ioctl, try again with a bigger buffer.
else stop */
if (ifconf.ifc_len == lastlen && ifconf.ifc_len > 0) {
/* we didn't expand. we're done */
successful_locate = true;
break;
}
lastlen = ifconf.ifc_len;
}
/* Yes, we overflowed (or had an EINVAL on the ioctl).
Loop back around and try again with a bigger buffer */
free(ifconf.ifc_req);
ifc_len = (ifc_len == 0) ? 1 : ifc_len * 2;
} while (ifc_len < MAX_IFCONF_SIZE);
if (!successful_locate) {
opal_output(0, "opal_ifinit: unable to find network interfaces.");
return OPAL_ERR_FATAL;
}
/*
* Setup indexes
*/
ptr = (char*) ifconf.ifc_req;
rem = ifconf.ifc_len;
num = 0;
/* loop through all interfaces */
while (rem > 0) {
struct ifreq* ifr = (struct ifreq*) ptr;
opal_if_t *intf;
int length;
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output(0, "opal_ifinit: unable to allocated %lu bytes\n", (unsigned long)sizeof(opal_if_t));
free(ifconf.ifc_req);
close(sd);
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* compute offset for entries */
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
length = sizeof(struct sockaddr);
if (ifr->ifr_addr.sa_len > length) {
length = ifr->ifr_addr.sa_len;
}
length += sizeof(ifr->ifr_name);
#else
length = sizeof(struct ifreq);
#endif
rem -= length;
ptr += length;
/* see if we like this entry */
if (AF_INET != ifr->ifr_addr.sa_family) {
continue;
}
if (ioctl(sd, SIOCGIFFLAGS, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFFLAGS) failed with errno=%d", errno);
continue;
}
if ((ifr->ifr_flags & IFF_UP) == 0) {
continue;
}
#ifdef IFF_SLAVE
/* Is this a slave to a load balancer or bonded channel?
If so, don't use it -- pick up the master instead */
if ((ifr->ifr_flags & IFF_SLAVE) != 0) {
continue;
}
#endif
#if 0
if (!retain_loopback && (ifr->ifr_flags & IFF_LOOPBACK) != 0) {
continue;
}
#endif
/* copy entry over into our data structure */
strcpy(intf->if_name, ifr->ifr_name);
intf->if_flags = ifr->ifr_flags;
/* every new address gets its own internal if_index */
intf->if_index = opal_list_get_size(&opal_if_list)+1;
/* assign the kernel index to distinguish different NICs */
#ifndef SIOCGIFINDEX
intf->if_kernel_index = intf->if_index;
#else
if (ioctl(sd, SIOCGIFINDEX, ifr) < 0) {
opal_output(0,"opal_ifinit: ioctl(SIOCGIFINDEX) failed with errno=%d", errno);
continue;
}
#if defined(ifr_ifindex)
intf->if_kernel_index = ifr->ifr_ifindex;
#elif defined(ifr_index)
intf->if_kernel_index = ifr->ifr_index;
#else
intf->if_kernel_index = -1;
#endif
#endif /* SIOCGIFINDEX */
/* This call returns IPv4 addresses only. Use SIOCGLIFADDR
instead */
if (ioctl(sd, SIOCGIFADDR, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFADDR) failed with errno=%d", errno);
break;
}
if (AF_INET != ifr->ifr_addr.sa_family) {
continue;
}
/* based on above, we know this is an IPv4 address... */
memcpy(&intf->if_addr, &ifr->ifr_addr, sizeof(struct sockaddr_in));
if (ioctl(sd, SIOCGIFNETMASK, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFNETMASK) failed with errno=%d", errno);
continue;
}
/* generate CIDR and assign to netmask */
intf->if_mask = prefix(((struct sockaddr_in*) &ifr->ifr_addr)->sin_addr.s_addr);
opal_list_append(&opal_if_list, &(intf->super));
}
free(ifconf.ifc_req);
close(sd);
return OPAL_SUCCESS;
}

12
opal/mca/if/solaris_ipv6/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,12 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_if_solaris_ipv6.la
libmca_if_solaris_ipv6_la_SOURCES = if_solaris_ipv6.c

30
opal/mca/if/solaris_ipv6/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,30 @@
# -*- shell-script -*-
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_if_solaris_ipv6_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_if_config_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_if_solaris_ipv6_CONFIG], [
AC_REQUIRE([OPAL_CHECK_OS_FLAVORS])
# check to see if we are on a solaris machine
AS_IF([test "$opal_found_sun" = "yes"], [$1], [$2])
])dnl
#
# ifdef __sun__
#

15
opal/mca/if/solaris_ipv6/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,15 @@
# -*- shell-script -*-
#
# Copyright (c) 2006 Los Alamos National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_CONFIG_PRIORITY=10
PARAM_CONFIG_FILES="Makefile"

160
opal/mca/if/solaris_ipv6/if_solaris_ipv6.c Обычный файл
Просмотреть файл

@ -0,0 +1,160 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include "opal/constants.h"
#include "opal/mca/if/if.h"
static int if_solaris_ipv6_open(void);
/* Discovers Solaris IPv6 interfaces */
opal_if_base_component_t mca_if_solaris_ipv6_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
OPAL_IF_BASE_VERSION_2_0_0,
/* Component name and version */
"solaris_ipv6",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
if_solaris_ipv6_open,
NULL
},
{
/* This component is checkpointable */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
/* configure using getifaddrs(3) */
static int if_solaris_ipv6_open(void)
{
int i;
int sd;
int error;
uint16_t kindex;
struct lifnum lifnum;
struct lifconf lifconf;
struct lifreq *lifreq, lifquery;
sd = socket (AF_INET6, SOCK_DGRAM, 0);
if (sd < 0) {
opal_output (0, "opal_ifinit: unable to open IPv6 socket\n");
return OPAL_ERROR;
}
/* we only ask for IPv6; IPv4 discovery has already been done */
lifnum.lifn_family = AF_INET6;
lifnum.lifn_flags = 0;
lifnum.lifn_count = 0;
/* get the number of interfaces in the system */
error = ioctl (sd, SIOCGLIFNUM, &lifnum);
if (error < 0) {
opal_output (0,
"opal_ifinit: ioctl SIOCGLIFNUM failed with errno=%d\n", errno);
return OPAL_ERROR;
}
memset (&lifconf, 0, sizeof (struct lifconf));
memset (&lifquery, 0, sizeof (struct lifreq));
lifconf.lifc_family = AF_INET6;
lifconf.lifc_flags = 0;
lifconf.lifc_len = lifnum.lifn_count * sizeof (struct lifreq) * 2;
lifconf.lifc_buf = malloc (lifconf.lifc_len);
if (NULL == lifconf.lifc_buf) {
opal_output (0, "opal_ifinit: IPv6 discovery: malloc() failed\n");
return OPAL_ERR_OUT_OF_RESOURCE;
}
memset (lifconf.lifc_buf, 0, lifconf.lifc_len);
error = ioctl (sd, SIOCGLIFCONF, &lifconf);
if (error < 0) {
opal_output (0,
"opal_ifinit: IPv6 SIOCGLIFCONF failed with errno=%d\n", errno);
}
for (i = 0; i + sizeof (struct lifreq) <= lifconf.lifc_len;
i += sizeof (*lifreq)) {
lifreq = (struct lifreq *)((caddr_t)lifconf.lifc_buf + i);
strncpy (lifquery.lifr_name, lifreq->lifr_name,
sizeof (lifquery.lifr_name));
/* lookup kernel index */
error = ioctl (sd, SIOCGLIFINDEX, &lifquery);
if (error < 0) {
opal_output (0,
"opal_ifinit: SIOCGLIFINDEX failed with errno=%d\n", errno);
return OPAL_ERROR;
}
kindex = lifquery.lifr_index;
/* lookup interface flags */
error = ioctl (sd, SIOCGLIFFLAGS, &lifquery);
if (error < 0) {
opal_output (0,
"opal_ifinit: SIOCGLIFFLAGS failed with errno=%d\n", errno);
return OPAL_ERROR;
}
if (AF_INET6 == lifreq->lifr_addr.ss_family) {
struct sockaddr_in6* my_addr = (struct sockaddr_in6*) &lifreq->lifr_addr;
/* we surely want to check for sin6_scope_id, but Solaris
does not set it correctly, so we have to look for
global scope. For now, global is anything which is
neither loopback nor link local.
Bug, FIXME: site-local, multicast, ... missing
Check for 2000::/3?
*/
if ( (!retain_loopback && !IN6_IS_ADDR_LOOPBACK (&my_addr->sin6_addr)) &&
(! IN6_IS_ADDR_LINKLOCAL (&my_addr->sin6_addr))) {
/* create interface for newly found address */
opal_if_t *intf;
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output (0,
"opal_ifinit: unable to allocate %d bytes\n",
sizeof (opal_if_t));
return OPAL_ERR_OUT_OF_RESOURCE;
}
strncpy (intf->if_name, lifreq->lifr_name, IF_NAMESIZE);
intf->if_index = opal_list_get_size(&opal_if_list)+1;
memcpy(&intf->if_addr, my_addr, sizeof (*my_addr));
intf->if_mask = 64;
/* lifrq flags are uint64_t */
intf->if_flags =
(uint32_t)(0x00000000ffffffff) & lifquery.lifr_flags;
/* append to list */
opal_list_append (&opal_if_list, &(intf->super));
}
}
} /* for */
if (NULL != lifconf.lifc_buf) {
free (lifconf.lifc_buf);
}
return OPAL_SUCCESS;
}

0
opal/mca/if/windows/.windows Обычный файл
Просмотреть файл

19
opal/mca/if/windows/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,19 @@
#
# Copyright (c) 2004-2007 The Trustees of the University of Tennessee.
# All rights reserved.
# Copyright (c) 2009 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
EXTRA_DIST = .windows
noinst_LTLIBRARIES = libmca_if_windows.la
libmca_if_windows_la_SOURCES = \
opal_if_windows.c

45
opal/mca/if/windows/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,45 @@
# -*- shell-script -*-
#
# Copyright (c) 2004-2007 The Trustees of the University of Tennessee.
# All rights reserved.
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([MCA_if_windows_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# MCA_if_windows_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_if_windows_CONFIG],[
# check for RegOpenKeyEx allowing access to the Windows
# registry. We should first check that the function is defined,
# and then check for it's presence in the kernel32 library.
AC_MSG_CHECKING([for working RegOpenKeyEx])
AC_TRY_RUN( [#include <windows.h>
int main( int argc, char** argv ) {
RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Open MPI", 0, KEY_READ, NULL);
return 0; }],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2],
[AC_COMPILE_IFELSE([#include <windows.h>
int main( int argc, char** argv ) {
RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Open MPI", 0, KEY_READ, NULL);
return 0; }],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])])
])dnl

16
opal/mca/if/windows/configure.params Обычный файл
Просмотреть файл

@ -0,0 +1,16 @@
# -*- shell-script -*-
#
# Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
# All rights reserved.
# Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# Specific to this module
PARAM_WINDOWS_PRIORITY=100
PARAM_CONFIG_FILES="Makefile"

130
opal/mca/if/windows/opal_if_windows.c Обычный файл
Просмотреть файл

@ -0,0 +1,130 @@
/*
* Copyright (c) 2004-2007 The Trustees of the University of Tennessee.
* All rights reserved.
* Copyright (c) 2009 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include "opal/mca/if/if.h"
#include "opal/constants.h"
static int if_windows_open(void);
opal_if_base_component_t mca_if_windows_component = {
/* First, the mca_component_t struct containing meta information
about the component itself */
{
OPAL_IF_BASE_VERSION_2_0_0,
/* Component name and version */
"windows",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
if_windows_open,
NULL
},
{
/* This component is checkpointable */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
/*
1. check if the interface info list is already populated. If so, return
2. get the interface information which is required using WSAIoctl
3. construct opal_if_list and populate it with the list of interfaces we have
CAVEAT: Does not support the following options which are supported in SIOCGIFCONF
- kernel table index
- interface name
*/
#define MAX_INTERFACES 10 /* Anju: for now assume there are no more than this */
static int if_windows_open(void)
{
SOCKET sd;
INTERFACE_INFO if_list[MAX_INTERFACES];
int num_interfaces;
unsigned long num_bytes_returned;
int i;
unsigned int interface_counter = 0;
opal_if_t *intf;
/* create a socket */
sd = WSASocket (AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 0, 0);
if (sd == SOCKET_ERROR) {
opal_output(0, "opal_ifinit: WSASocket failed with errno=%d\n",WSAGetLastError());
return OPAL_ERROR;
}
/* get the information about the interfaces */
if (SOCKET_ERROR == WSAIoctl (sd,
SIO_GET_INTERFACE_LIST,
NULL,
0,
&if_list,
sizeof (if_list),
&num_bytes_returned,
0,
0)) {
opal_output(0, "opal_ifinit: WSAIoctl failed with errno=%d\n",WSAGetLastError());
return OPAL_ERROR;
}
/* loop through all the interfaces and create the list */
num_interfaces = num_bytes_returned / sizeof (INTERFACE_INFO);
for (i = 0; i < num_interfaces; ++i) {
/* do all this only if the interface is up, and skip loopback interface */
if (0 != (if_list[i].iiFlags & IFF_UP)
&& (!retain_loopback && 0 == (if_list[i].iiFlags & IFF_LOOPBACK))) {
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output (0,"opal_ifinit: Unable to malloc %d bytes",sizeof(opal_list_t));
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* fill in the interface address */
memcpy(&intf->if_addr, &(if_list[i].iiAddress),
sizeof(intf->if_addr));
/* fill in the netmask information */
memcpy(&intf->if_mask, &(if_list[i].iiNetmask),
sizeof(intf->if_mask));
/* fill in the bcast address */
memcpy(&intf->if_bcast, &(if_list[i].iiBroadcastAddress),
sizeof(intf->if_bcast));
/* fill in the flags */
intf->if_flags = if_list[i].iiFlags;
/* fill in the index in the table */
intf->if_index = opal_list_get_size(&opal_if_list)+1;
/* fill in the kernel index */
intf->if_kernel_index = intf->if_index;
/* generate the interface name, e.g. eth0, eth1, ..... */
sprintf(intf->if_name, "eth%u", interface_counter++);
/* copy all this into a persistent form and store it in the list */
opal_list_append(&opal_if_list, &(intf->super));
}
}
return OPAL_SUCCESS;
}

Просмотреть файл

@ -50,7 +50,6 @@
#include "opal/util/opal_environ.h"
#include "opal/util/output.h"
#include "opal/util/malloc.h"
#include "opal/util/if.h"
#include "opal/util/keyval_parse.h"
#include "opal/util/opal_environ.h"
#include "opal/util/argv.h"
@ -61,6 +60,7 @@
#include "opal/runtime/opal.h"
#include "opal/constants.h"
#include "opal/mca/if/base/base.h"
#include "opal/mca/memcpy/base/base.h"
#include "opal/mca/memory/base/base.h"
#include "opal/mca/timer/base/base.h"
@ -773,7 +773,7 @@ int opal_cr_coord(int state)
/*
* Flush if() functionality, since it caches system specific info.
*/
opal_iffinalize();
opal_if_base_close();
/* Since opal_ifinit() is not exposed, the necessary
* functions will call it when needed. Just make sure we
* finalized this code so we don't get old socket addrs.

Просмотреть файл

@ -26,7 +26,6 @@
#include "opal/util/trace.h"
#include "opal/util/output.h"
#include "opal/util/malloc.h"
#include "opal/util/if.h"
#include "opal/util/net.h"
#include "opal/util/keyval_parse.h"
#include "opal/util/show_help.h"
@ -34,6 +33,7 @@
#include "opal/mca/base/base.h"
#include "opal/runtime/opal.h"
#include "opal/constants.h"
#include "opal/mca/if/base/base.h"
#include "opal/mca/installdirs/base/base.h"
#include "opal/mca/memcpy/base/base.h"
#include "opal/mca/memory/base/base.h"
@ -66,9 +66,8 @@ opal_finalize_util(void)
/* Clear out all the registered MCA params */
mca_base_param_finalize();
/* close interfaces code. This is lazy opened, but protected from
close when not opened internally */
opal_iffinalize();
/* close interfaces code. */
opal_if_base_close();
opal_net_finalize();

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -170,15 +170,6 @@ OPAL_DECLSPEC int opal_ifindextoflags(int if_index, uint32_t*);
*/
OPAL_DECLSPEC bool opal_ifislocal(const char *hostname);
/**
* Finalize the functions to release malloc'd data
*
* @param none
* @return OPAL_SUCCESS if no problems encountered
* @return OPAL_ERROR if data could not be released
*/
OPAL_DECLSPEC int opal_iffinalize(void);
/**
* Convert a dot-delimited network tuple to an IP address
*

Просмотреть файл

@ -53,6 +53,7 @@
#endif
#include "opal/runtime/opal.h"
#include "opal/dss/dss.h"
#include "opal/mca/if/base/base.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/errmgr/base/base.h"
@ -298,6 +299,15 @@ void orte_info_open_components(void)
map->components = &opal_crs_base_components_available;
opal_pointer_array_add(&component_map, map);
#endif
if (OPAL_SUCCESS != opal_if_base_open()) {
goto error;
}
map = OBJ_NEW(orte_info_component_map_t);
map->type = strdup("if");
map->components = &opal_if_components;
opal_pointer_array_add(&component_map, map);
/* OPAL's installdirs base open has already been called as part of
* opal_init_util() back in main().

Просмотреть файл

@ -196,6 +196,7 @@ int main(int argc, char *argv[])
#if OPAL_ENABLE_FT_CR == 1
opal_pointer_array_add(&mca_types, "crs");
#endif
opal_pointer_array_add(&mca_types, "if");
#if !ORTE_DISABLE_FULL_SUPPORT
opal_pointer_array_add(&mca_types, "debugger");