1
1

Commit a patch from Brian that fixes potential segfaults in systems where IPv6 include files are found, but the kernel doesn't actually support IPv6.

This commit was SVN r18106.
Этот коммит содержится в:
Ralph Castain 2008-04-09 12:53:24 +00:00
родитель 10434fb2f1
Коммит 11c6773c83

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

@ -94,7 +94,7 @@ OBJ_CLASS_INSTANCE(
* Local utility functions * Local utility functions
*/ */
static int mca_oob_tcp_create_listen(int *target_sd, uint16_t af_family); static int mca_oob_tcp_create_listen(int *target_sd, unsigned short *port, uint16_t af_family);
static int mca_oob_tcp_create_listen_thread(void); static int mca_oob_tcp_create_listen_thread(void);
static void mca_oob_tcp_recv_handler(int sd, short flags, void* user); static void mca_oob_tcp_recv_handler(int sd, short flags, void* user);
static void mca_oob_tcp_accept(int incoming_sd); static void mca_oob_tcp_accept(int incoming_sd);
@ -498,7 +498,7 @@ static void mca_oob_tcp_accept(int incoming_sd)
* Called by both the threaded and event based listen modes. * Called by both the threaded and event based listen modes.
*/ */
static int static int
mca_oob_tcp_create_listen(int *target_sd, uint16_t af_family) mca_oob_tcp_create_listen(int *target_sd, unsigned short *target_port, uint16_t af_family)
{ {
int flags, index, range, port=0; int flags, index, range, port=0;
struct sockaddr_storage inaddr; struct sockaddr_storage inaddr;
@ -633,15 +633,10 @@ mca_oob_tcp_create_listen(int *target_sd, uint16_t af_family)
} }
if (AF_INET == af_family) { if (AF_INET == af_family) {
mca_oob_tcp_component.tcp_listen_port = ((struct sockaddr_in*) &inaddr)->sin_port; *target_port = ((struct sockaddr_in*) &inaddr)->sin_port;
mca_oob_tcp_component.tcp_listen_sd = *target_sd; } else {
*target_port = ((struct sockaddr_in6*) &inaddr)->sin6_port;
} }
#if OPAL_WANT_IPV6
if (AF_INET6 == af_family) {
mca_oob_tcp_component.tcp6_listen_port = ((struct sockaddr_in6*) &inaddr)->sin6_port;
mca_oob_tcp_component.tcp6_listen_sd = *target_sd;
}
#endif /* OPAL_WANT_IPV6 */
/* setup listen backlog to maximum allowed by kernel */ /* setup listen backlog to maximum allowed by kernel */
if(listen(*target_sd, SOMAXCONN) < 0) { if(listen(*target_sd, SOMAXCONN) < 0) {
@ -1269,14 +1264,19 @@ int mca_oob_tcp_init(void)
/* Create an IPv4 listen socket and either register with the event /* Create an IPv4 listen socket and either register with the event
engine or give to the listen thread */ engine or give to the listen thread */
rc = mca_oob_tcp_create_listen(&mca_oob_tcp_component.tcp_listen_sd, rc = mca_oob_tcp_create_listen(&mca_oob_tcp_component.tcp_listen_sd,
&mca_oob_tcp_component.tcp_listen_port,
AF_INET); AF_INET);
if (ORTE_SUCCESS != rc && if (ORTE_SUCCESS != rc) {
(EAFNOSUPPORT != opal_socket_errno || /* Don't complain if just not supported unless want connect debugging */
mca_oob_tcp_component.tcp_debug >= OOB_TCP_DEBUG_CONNECT)) { if (EAFNOSUPPORT != opal_socket_errno ||
mca_oob_tcp_component.tcp_debug >= OOB_TCP_DEBUG_CONNECT) {
opal_output(0, opal_output(0,
"mca_oob_tcp_init: unable to create IPv4 listen socket: %s\n", "mca_oob_tcp_init: unable to create IPv4 listen socket: %s\n",
opal_strerror(rc)); opal_strerror(rc));
} }
mca_oob_tcp_component.tcp_listen_sd = -1;
mca_oob_tcp_component.tcp_listen_port = 0;
} else {
if (OOB_TCP_LISTEN_THREAD == mca_oob_tcp_component.tcp_listen_type) { if (OOB_TCP_LISTEN_THREAD == mca_oob_tcp_component.tcp_listen_type) {
int idx = mca_oob_tcp_component.tcp_listen_thread_num_sockets++; int idx = mca_oob_tcp_component.tcp_listen_thread_num_sockets++;
mca_oob_tcp_component.tcp_listen_thread_sds[idx] = mca_oob_tcp_component.tcp_listen_thread_sds[idx] =
@ -1289,20 +1289,26 @@ int mca_oob_tcp_init(void)
0); 0);
opal_event_add(&mca_oob_tcp_component.tcp_recv_event, 0); opal_event_add(&mca_oob_tcp_component.tcp_recv_event, 0);
} }
}
/* Create an IPv6 listen socket (if IPv6 is enabled, of course) /* Create an IPv6 listen socket (if IPv6 is enabled, of course)
and either register with the event engine or give to the listen and either register with the event engine or give to the listen
thread */ thread */
#if OPAL_WANT_IPV6 #if OPAL_WANT_IPV6
rc = mca_oob_tcp_create_listen(&mca_oob_tcp_component.tcp6_listen_sd, rc = mca_oob_tcp_create_listen(&mca_oob_tcp_component.tcp6_listen_sd,
&mca_oob_tcp_component.tcp6_listen_port,
AF_INET6); AF_INET6);
if (ORTE_SUCCESS != rc && if (ORTE_SUCCESS != rc) {
(EAFNOSUPPORT != opal_socket_errno || /* Don't complain if just not supported unless want connect debugging */
mca_oob_tcp_component.tcp_debug >= OOB_TCP_DEBUG_CONNECT)) { if (EAFNOSUPPORT != opal_socket_errno ||
mca_oob_tcp_component.tcp_debug >= OOB_TCP_DEBUG_CONNECT) {
opal_output(0, opal_output(0,
"mca_oob_tcp_init: unable to create IPv6 listen socket: %s\n", "mca_oob_tcp_init: unable to create IPv6 listen socket: %s\n",
opal_strerror(rc)); opal_strerror(rc));
} }
mca_oob_tcp_component.tcp6_listen_sd = -1;
mca_oob_tcp_component.tcp6_listen_port = 0;
} else {
if (OOB_TCP_LISTEN_THREAD == mca_oob_tcp_component.tcp_listen_type) { if (OOB_TCP_LISTEN_THREAD == mca_oob_tcp_component.tcp_listen_type) {
int idx = mca_oob_tcp_component.tcp_listen_thread_num_sockets++; int idx = mca_oob_tcp_component.tcp_listen_thread_num_sockets++;
mca_oob_tcp_component.tcp_listen_thread_sds[idx] = mca_oob_tcp_component.tcp_listen_thread_sds[idx] =
@ -1315,8 +1321,17 @@ int mca_oob_tcp_init(void)
0); 0);
opal_event_add(&mca_oob_tcp_component.tcp6_recv_event, 0); opal_event_add(&mca_oob_tcp_component.tcp6_recv_event, 0);
} }
}
#endif #endif
if (mca_oob_tcp_component.tcp_listen_sd < 0
#if OPAL_WANT_IPV6
&& mca_oob_tcp_component.tcp6_listen_sd < 0
#endif
) {
return ORTE_ERR_NOT_SUPPORTED;
}
/* Finish up by either printing a nice message (event library) or /* Finish up by either printing a nice message (event library) or
initializing the listen thread (listen thread) */ initializing the listen thread (listen thread) */
if (OOB_TCP_LISTEN_THREAD == mca_oob_tcp_component.tcp_listen_type) { if (OOB_TCP_LISTEN_THREAD == mca_oob_tcp_component.tcp_listen_type) {