From 2d85ef645f3048419d905cfc9da10a28885a6775 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Wed, 27 Jan 2010 06:57:16 +0000 Subject: transport/socket: guess an appropriate address family when it is not specified in configuration. Signed-off-by: Raghavendra G Signed-off-by: Anand V. Avati BUG: 561 (with address family set to 'inet-sdp', transport/socket doesn't work correctly) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=561 --- transport/socket/src/name.c | 36 ++++++++++++++++++++++++++++++------ transport/socket/src/name.h | 16 +++++----------- transport/socket/src/socket.c | 14 ++------------ 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/transport/socket/src/name.c b/transport/socket/src/name.c index 6a1a1b08afc..3e965f0bbe8 100644 --- a/transport/socket/src/name.c +++ b/transport/socket/src/name.c @@ -463,16 +463,25 @@ client_bind (transport_t *this, int32_t socket_client_get_remote_sockaddr (transport_t *this, struct sockaddr *sockaddr, - socklen_t *sockaddr_len) + socklen_t *sockaddr_len, + sa_family_t *sa_family) { int32_t ret = 0; + if ((sockaddr == NULL) || (sockaddr_len == NULL) + || (sa_family == NULL)) { + ret = -1; + goto err; + } + ret = client_fill_address_family (this, &sockaddr->sa_family); if (ret) { ret = -1; goto err; } + *sa_family = sockaddr->sa_family; + switch (sockaddr->sa_family) { case AF_INET_SDP: @@ -481,11 +490,13 @@ socket_client_get_remote_sockaddr (transport_t *this, case AF_INET: case AF_INET6: case AF_UNSPEC: - ret = af_inet_client_get_remote_sockaddr (this, sockaddr, sockaddr_len); + ret = af_inet_client_get_remote_sockaddr (this, sockaddr, + sockaddr_len); break; case AF_UNIX: - ret = af_unix_client_get_remote_sockaddr (this, sockaddr, sockaddr_len); + ret = af_unix_client_get_remote_sockaddr (this, sockaddr, + sockaddr_len); break; default: @@ -494,6 +505,10 @@ socket_client_get_remote_sockaddr (transport_t *this, ret = -1; } + if (*sa_family == AF_UNSPEC) { + *sa_family = sockaddr->sa_family; + } + err: return ret; } @@ -542,17 +557,22 @@ out: } int32_t -socket_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len) +socket_server_get_local_sockaddr (transport_t *this, struct sockaddr *addr, + socklen_t *addr_len, sa_family_t *sa_family) { int32_t ret = -1; + if ((addr == NULL) || (addr_len == NULL) || (sa_family == NULL)) { + goto err; + } + ret = server_fill_address_family (this, &addr->sa_family); if (ret == -1) { goto err; } + *sa_family = addr->sa_family; + switch (addr->sa_family) { case AF_INET_SDP: @@ -569,6 +589,10 @@ socket_server_get_local_sockaddr (transport_t *this, break; } + if (*sa_family == AF_UNSPEC) { + *sa_family = addr->sa_family; + } + err: return ret; } diff --git a/transport/socket/src/name.h b/transport/socket/src/name.h index 019f988dd91..886d728704b 100644 --- a/transport/socket/src/name.h +++ b/transport/socket/src/name.h @@ -27,21 +27,15 @@ client_bind (transport_t *this, struct sockaddr *sockaddr, socklen_t *sockaddr_len, int sock); -int32_t -client_fill_address_family (transport_t *this, sa_family_t *sa_family); - -int32_t -server_fill_address_family (transport_t *this, sa_family_t *sa_family); int32_t -socket_client_get_remote_sockaddr (transport_t *this, - struct sockaddr *sockaddr, - socklen_t *sockaddr_len); +socket_client_get_remote_sockaddr (transport_t *this, struct sockaddr *sockaddr, + socklen_t *sockaddr_len, + sa_family_t *sa_family); int32_t -socket_server_get_local_sockaddr (transport_t *this, - struct sockaddr *addr, - socklen_t *addr_len); +socket_server_get_local_sockaddr (transport_t *this, struct sockaddr *addr, + socklen_t *addr_len, sa_family_t *sa_family); int32_t get_transport_identifiers (transport_t *this); diff --git a/transport/socket/src/socket.c b/transport/socket/src/socket.c index 23d5661ec4f..b28212a5fde 100644 --- a/transport/socket/src/socket.c +++ b/transport/socket/src/socket.c @@ -971,13 +971,8 @@ socket_connect (transport_t *this) goto err; } - ret = client_fill_address_family (this, &sa_family); - if (ret == -1) { - goto err; - } - ret = socket_client_get_remote_sockaddr (this, SA (&sockaddr), - &sockaddr_len); + &sockaddr_len, &sa_family); if (ret == -1) { /* logged inside client_get_remote_sockaddr */ goto err; @@ -1119,13 +1114,8 @@ socket_listen (transport_t *this) return ret; } - ret = server_fill_address_family (this, &sa_family); - if (ret == -1) { - return ret; - } - ret = socket_server_get_local_sockaddr (this, SA (&sockaddr), - &sockaddr_len); + &sockaddr_len, &sa_family); if (ret == -1) { return ret; } -- cgit