summaryrefslogtreecommitdiffstats
path: root/transport
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2010-01-22 03:02:32 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-01-22 05:34:35 -0800
commita116e5b3ef2d4fbb57a5690a01368ec7aa0942aa (patch)
tree57fa71374cc7f2ff7660bbcd970f6ae312276eaf /transport
parentab8cabcd30bbb5dde4cb8a35d4fd88136994f526 (diff)
transport/socket: use appropriate address family macro when address family is inet-sdp.
- sa_family should be set to AF_INET_SDP only during call to socket system call. For all other calls, sa_family should be AF_INET. Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> 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
Diffstat (limited to 'transport')
-rw-r--r--transport/socket/src/name.c100
-rw-r--r--transport/socket/src/name.h6
-rw-r--r--transport/socket/src/socket.c20
3 files changed, 79 insertions, 47 deletions
diff --git a/transport/socket/src/name.c b/transport/socket/src/name.c
index 712f5a3ffe3..b8d9664adb0 100644
--- a/transport/socket/src/name.c
+++ b/transport/socket/src/name.c
@@ -119,10 +119,15 @@ err:
return ret;
}
-static int32_t
-client_fill_address_family (transport_t *this, struct sockaddr *sockaddr)
+int32_t
+client_fill_address_family (transport_t *this, sa_family_t *sa_family)
{
- data_t *address_family_data = NULL;
+ data_t *address_family_data = NULL;
+ int32_t ret = -1;
+
+ if (sa_family == NULL) {
+ goto out;
+ }
address_family_data = dict_get (this->xl->options,
"transport.address-family");
@@ -141,43 +146,46 @@ client_fill_address_family (transport_t *this, struct sockaddr *sockaddr)
"transport.unix.connect-path:%s)",
data_to_str (remote_host_data),
data_to_str (connect_path_data));
- return -1;
+ goto out;
}
if (remote_host_data) {
gf_log (this->xl->name, GF_LOG_DEBUG,
"address-family not specified, guessing it "
"to be inet/inet6");
- sockaddr->sa_family = AF_UNSPEC;
+ *sa_family = AF_UNSPEC;
} else {
gf_log (this->xl->name, GF_LOG_DEBUG,
"address-family not specified, guessing it "
"to be unix");
- sockaddr->sa_family = AF_UNIX;
+ *sa_family = AF_UNIX;
}
} else {
char *address_family = data_to_str (address_family_data);
if (!strcasecmp (address_family, "unix")) {
- sockaddr->sa_family = AF_UNIX;
+ *sa_family = AF_UNIX;
} else if (!strcasecmp (address_family, "inet")) {
- sockaddr->sa_family = AF_INET;
+ *sa_family = AF_INET;
} else if (!strcasecmp (address_family, "inet6")) {
- sockaddr->sa_family = AF_INET6;
+ *sa_family = AF_INET6;
} else if (!strcasecmp (address_family, "inet-sdp")) {
- sockaddr->sa_family = AF_INET_SDP;
+ *sa_family = AF_INET_SDP;
} else if (!strcasecmp (address_family, "inet/inet6")
|| !strcasecmp (address_family, "inet6/inet")) {
- sockaddr->sa_family = AF_UNSPEC;
+ *sa_family = AF_UNSPEC;
} else {
gf_log (this->xl->name, GF_LOG_ERROR,
"unknown address-family (%s) specified",
address_family);
- return -1;
+ goto out;
}
}
- return 0;
+ ret = 0;
+
+out:
+ return ret;
}
static int32_t
@@ -459,9 +467,8 @@ socket_client_get_remote_sockaddr (transport_t *this,
socklen_t *sockaddr_len)
{
int32_t ret = 0;
- char is_inet_sdp = 0;
- ret = client_fill_address_family (this, sockaddr);
+ ret = client_fill_address_family (this, &sockaddr->sa_family);
if (ret) {
ret = -1;
goto err;
@@ -471,21 +478,17 @@ socket_client_get_remote_sockaddr (transport_t *this,
{
case AF_INET_SDP:
sockaddr->sa_family = AF_INET;
- is_inet_sdp = 1;
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
- ret = af_inet_client_get_remote_sockaddr (this, sockaddr, sockaddr_len);
-
- if (is_inet_sdp) {
- sockaddr->sa_family = AF_INET_SDP;
- }
-
+ 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:
@@ -498,14 +501,16 @@ err:
return ret;
}
+
int32_t
-socket_server_get_local_sockaddr (transport_t *this,
- struct sockaddr *addr,
- socklen_t *addr_len)
+server_fill_address_family (transport_t *this, sa_family_t *sa_family)
{
- data_t *address_family_data = NULL;
- int32_t ret = 0;
- char is_inet_sdp = 0;
+ data_t *address_family_data = NULL;
+ int32_t ret = -1;
+
+ if (sa_family == NULL) {
+ goto out;
+ }
address_family_data = dict_get (this->xl->options,
"transport.address-family");
@@ -514,41 +519,54 @@ socket_server_get_local_sockaddr (transport_t *this,
address_family = data_to_str (address_family_data);
if (!strcasecmp (address_family, "inet")) {
- addr->sa_family = AF_INET;
+ *sa_family = AF_INET;
} else if (!strcasecmp (address_family, "inet6")) {
- addr->sa_family = AF_INET6;
+ *sa_family = AF_INET6;
} else if (!strcasecmp (address_family, "inet-sdp")) {
- addr->sa_family = AF_INET_SDP;
+ *sa_family = AF_INET_SDP;
} else if (!strcasecmp (address_family, "unix")) {
- addr->sa_family = AF_UNIX;
+ *sa_family = AF_UNIX;
} else if (!strcasecmp (address_family, "inet/inet6")
|| !strcasecmp (address_family, "inet6/inet")) {
- addr->sa_family = AF_UNSPEC;
+ *sa_family = AF_UNSPEC;
} else {
gf_log (this->xl->name, GF_LOG_ERROR,
"unknown address family (%s) specified", address_family);
- ret = -1;
- goto err;
+ goto out;
}
} else {
gf_log (this->xl->name, GF_LOG_DEBUG,
"option address-family not specified, defaulting to inet/inet6");
- addr->sa_family = AF_UNSPEC;
+ *sa_family = AF_UNSPEC;
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+
+
+int32_t
+socket_server_get_local_sockaddr (transport_t *this,
+ struct sockaddr *addr,
+ socklen_t *addr_len)
+{
+ int32_t ret = -1;
+
+ ret = server_fill_address_family (this, &addr->sa_family);
+ if (ret == -1) {
+ goto err;
}
switch (addr->sa_family)
{
case AF_INET_SDP:
- is_inet_sdp = 1;
addr->sa_family = AF_INET;
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
ret = af_inet_server_get_local_sockaddr (this, addr, addr_len);
- if (is_inet_sdp && !ret) {
- addr->sa_family = AF_INET_SDP;
- }
break;
case AF_UNIX:
diff --git a/transport/socket/src/name.h b/transport/socket/src/name.h
index 9266be242a6..ace94ebccf7 100644
--- a/transport/socket/src/name.h
+++ b/transport/socket/src/name.h
@@ -29,6 +29,12 @@ client_bind (transport_t *this,
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);
diff --git a/transport/socket/src/socket.c b/transport/socket/src/socket.c
index 28baa67a5b4..151ce3c9350 100644
--- a/transport/socket/src/socket.c
+++ b/transport/socket/src/socket.c
@@ -971,6 +971,7 @@ socket_connect (transport_t *this)
struct sockaddr_storage sockaddr = {0, };
socklen_t sockaddr_len = 0;
glusterfs_ctx_t *ctx = NULL;
+ sa_family_t sa_family = {0, };
priv = this->private;
ctx = this->xl->ctx;
@@ -994,6 +995,11 @@ 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);
if (ret == -1) {
@@ -1012,9 +1018,7 @@ socket_connect (transport_t *this)
memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len);
this->peerinfo.sockaddr_len = sockaddr_len;
- priv->sock = socket (SA (&sockaddr)->sa_family,
- SOCK_STREAM, 0);
-
+ priv->sock = socket (sa_family, SOCK_STREAM, 0);
if (priv->sock == -1) {
gf_log (this->xl->name, GF_LOG_ERROR,
"socket creation failed (%s)",
@@ -1118,6 +1122,7 @@ socket_listen (transport_t *this)
socklen_t sockaddr_len;
peer_info_t *myinfo = NULL;
glusterfs_ctx_t *ctx = NULL;
+ sa_family_t sa_family = {0, };
priv = this->private;
myinfo = &this->myinfo;
@@ -1135,9 +1140,13 @@ 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);
-
if (ret == -1) {
return ret;
}
@@ -1153,8 +1162,7 @@ socket_listen (transport_t *this)
memcpy (&myinfo->sockaddr, &sockaddr, sockaddr_len);
myinfo->sockaddr_len = sockaddr_len;
- priv->sock = socket (SA (&sockaddr)->sa_family,
- SOCK_STREAM, 0);
+ priv->sock = socket (sa_family, SOCK_STREAM, 0);
if (priv->sock == -1) {
gf_log (this->xl->name, GF_LOG_ERROR,