summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-transport/socket/src/name.c
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/rpc-transport/socket/src/name.c')
-rw-r--r--rpc/rpc-transport/socket/src/name.c114
1 files changed, 65 insertions, 49 deletions
diff --git a/rpc/rpc-transport/socket/src/name.c b/rpc/rpc-transport/socket/src/name.c
index 3194a7cf369..9286bbb236d 100644
--- a/rpc/rpc-transport/socket/src/name.c
+++ b/rpc/rpc-transport/socket/src/name.c
@@ -21,7 +21,7 @@
#include "rpc-transport.h"
#include "socket.h"
-#include "common-utils.h"
+#include <glusterfs/common-utils.h>
static void
_assign_port(struct sockaddr *sockaddr, uint16_t port)
@@ -105,10 +105,10 @@ af_unix_client_bind(rpc_transport_t *this, struct sockaddr *sockaddr,
struct sockaddr_un *addr = NULL;
int32_t ret = 0;
- path_data = dict_get(this->options, "transport.socket.bind-path");
+ path_data = dict_get_sizen(this->options, "transport.socket.bind-path");
if (path_data) {
char *path = data_to_str(path_data);
- if (!path || strlen(path) > UNIX_PATH_MAX) {
+ if (!path || path_data->len > 108) { /* 108 = addr->sun_path length */
gf_log(this->name, GF_LOG_TRACE,
"bind-path not specified for unix socket, "
"letting connect to assign default value");
@@ -134,7 +134,7 @@ err:
return ret;
}
-int32_t
+static int32_t
client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family)
{
data_t *address_family_data = NULL;
@@ -145,12 +145,13 @@ client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family)
goto out;
}
- address_family_data = dict_get(this->options, "transport.address-family");
+ address_family_data = dict_get_sizen(this->options,
+ "transport.address-family");
if (!address_family_data) {
data_t *remote_host_data = NULL, *connect_path_data = NULL;
- remote_host_data = dict_get(this->options, "remote-host");
- connect_path_data = dict_get(this->options,
- "transport.socket.connect-path");
+ remote_host_data = dict_get_sizen(this->options, "remote-host");
+ connect_path_data = dict_get_sizen(this->options,
+ "transport.socket.connect-path");
if (!(remote_host_data || connect_path_data) ||
(remote_host_data && connect_path_data)) {
@@ -179,7 +180,7 @@ client_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family)
}
} else {
- char *address_family = data_to_str(address_family_data);
+ const char *address_family = data_to_str(address_family_data);
if (!strcasecmp(address_family, "unix")) {
*sa_family = AF_UNIX;
} else if (!strcasecmp(address_family, "inet")) {
@@ -211,11 +212,12 @@ af_inet_client_get_remote_sockaddr(rpc_transport_t *this,
data_t *remote_host_data = NULL;
data_t *remote_port_data = NULL;
char *remote_host = NULL;
- uint16_t remote_port = 0;
+ uint16_t remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
struct addrinfo *addr_info = NULL;
int32_t ret = 0;
+ struct in6_addr serveraddr;
- remote_host_data = dict_get(options, "remote-host");
+ remote_host_data = dict_get_sizen(options, "remote-host");
if (remote_host_data == NULL) {
gf_log(this->name, GF_LOG_ERROR,
"option remote-host missing in volume %s", this->name);
@@ -231,22 +233,27 @@ af_inet_client_get_remote_sockaddr(rpc_transport_t *this,
goto err;
}
- remote_port_data = dict_get(options, "remote-port");
+ remote_port_data = dict_get_sizen(options, "remote-port");
if (remote_port_data == NULL) {
gf_log(this->name, GF_LOG_TRACE,
"option remote-port missing in volume %s. Defaulting to %d",
this->name, GF_DEFAULT_SOCKET_LISTEN_PORT);
-
- remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
} else {
remote_port = data_to_uint16(remote_port_data);
+ if (remote_port == (uint16_t)-1) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "option remote-port has invalid port in volume %s",
+ this->name);
+ ret = -1;
+ goto err;
+ }
}
- if (remote_port == (uint16_t)-1) {
- gf_log(this->name, GF_LOG_ERROR,
- "option remote-port has invalid port in volume %s", this->name);
- ret = -1;
- goto err;
+ /* Need to update transport-address family if address-family is not provided
+ to command-line arguments
+ */
+ if (inet_pton(AF_INET6, remote_host, &serveraddr)) {
+ sockaddr->sa_family = AF_INET6;
}
/* TODO: gf_resolve is a blocking call. kick in some
@@ -274,31 +281,29 @@ af_unix_client_get_remote_sockaddr(rpc_transport_t *this,
struct sockaddr_un *sockaddr_un = NULL;
char *connect_path = NULL;
data_t *connect_path_data = NULL;
- int32_t ret = 0;
+ int32_t ret = -1;
- connect_path_data = dict_get(this->options,
- "transport.socket.connect-path");
+ connect_path_data = dict_get_sizen(this->options,
+ "transport.socket.connect-path");
if (!connect_path_data) {
gf_log(this->name, GF_LOG_ERROR,
"option transport.unix.connect-path not specified for "
"address-family unix");
- ret = -1;
goto err;
}
- connect_path = data_to_str(connect_path_data);
- if (!connect_path) {
+ /* 108 = sockaddr_un->sun_path length */
+ if ((connect_path_data->len + 1) > 108) {
gf_log(this->name, GF_LOG_ERROR,
- "transport.unix.connect-path is null-string");
- ret = -1;
+ "connect-path value length %d > %d octets",
+ connect_path_data->len + 1, UNIX_PATH_MAX);
goto err;
}
- if ((strlen(connect_path) + 1) > UNIX_PATH_MAX) {
+ connect_path = data_to_str(connect_path_data);
+ if (!connect_path) {
gf_log(this->name, GF_LOG_ERROR,
- "connect-path value length %" GF_PRI_SIZET " > %d octets",
- strlen(connect_path), UNIX_PATH_MAX);
- ret = -1;
+ "transport.unix.connect-path is null-string");
goto err;
}
@@ -307,6 +312,7 @@ af_unix_client_get_remote_sockaddr(rpc_transport_t *this,
strcpy(sockaddr_un->sun_path, connect_path);
*sockaddr_len = sizeof(struct sockaddr_un);
+ ret = 0;
err:
return ret;
}
@@ -320,7 +326,8 @@ af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
int32_t ret = 0;
struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr;
- listen_path_data = dict_get(this->options, "transport.socket.listen-path");
+ listen_path_data = dict_get_sizen(this->options,
+ "transport.socket.listen-path");
if (!listen_path_data) {
gf_log(this->name, GF_LOG_ERROR,
"missing option transport.socket.listen-path");
@@ -334,7 +341,7 @@ af_unix_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
#define UNIX_PATH_MAX 108
#endif
- if ((strlen(listen_path) + 1) > UNIX_PATH_MAX) {
+ if ((listen_path_data->len + 1) > UNIX_PATH_MAX) {
gf_log(this->name, GF_LOG_ERROR,
"option transport.unix.listen-path has value length "
"%" GF_PRI_SIZET " > %d",
@@ -357,23 +364,24 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
{
struct addrinfo hints, *res = 0, *rp = NULL;
data_t *listen_port_data = NULL, *listen_host_data = NULL;
- uint16_t listen_port = -1;
+ uint16_t listen_port = 0;
char service[NI_MAXSERV], *listen_host = NULL;
dict_t *options = NULL;
int32_t ret = 0;
- options = this->options;
+ /* initializes addr_len */
+ *addr_len = 0;
- listen_port_data = dict_get(options, "transport.socket.listen-port");
- listen_host_data = dict_get(options, "transport.socket.bind-address");
+ options = this->options;
+ listen_port_data = dict_get_sizen(options, "transport.socket.listen-port");
if (listen_port_data) {
listen_port = data_to_uint16(listen_port_data);
- }
-
- if (listen_port == (uint16_t)-1)
+ } else {
listen_port = GF_DEFAULT_SOCKET_LISTEN_PORT;
+ }
+ listen_host_data = dict_get_sizen(options, "transport.socket.bind-address");
if (listen_host_data) {
listen_host = data_to_str(listen_host_data);
} else {
@@ -418,8 +426,12 @@ af_inet_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
}
if (!(*addr_len)) {
- memcpy(addr, res->ai_addr, res->ai_addrlen);
- *addr_len = res->ai_addrlen;
+ if (res && res->ai_addr) {
+ memcpy(addr, res->ai_addr, res->ai_addrlen);
+ *addr_len = res->ai_addrlen;
+ } else {
+ ret = -1;
+ }
}
freeaddrinfo(res);
@@ -522,7 +534,10 @@ socket_client_get_remote_sockaddr(rpc_transport_t *this,
ret = -1;
}
- if (*sa_family == AF_UNSPEC) {
+ /* Address-family is updated based on remote_host in
+ af_inet_client_get_remote_sockaddr
+ */
+ if (*sa_family != sockaddr->sa_family) {
*sa_family = sockaddr->sa_family;
}
@@ -530,23 +545,24 @@ err:
return ret;
}
-int32_t
+static int32_t
server_fill_address_family(rpc_transport_t *this, sa_family_t *sa_family)
{
data_t *address_family_data = NULL;
int32_t ret = -1;
#ifdef IPV6_DEFAULT
- char *addr_family = "inet6";
+ const char *addr_family = "inet6";
sa_family_t default_family = AF_INET6;
#else
- char *addr_family = "inet";
+ const char *addr_family = "inet";
sa_family_t default_family = AF_INET;
#endif
GF_VALIDATE_OR_GOTO("socket", sa_family, out);
- address_family_data = dict_get(this->options, "transport.address-family");
+ address_family_data = dict_get_sizen(this->options,
+ "transport.address-family");
if (address_family_data) {
char *address_family = NULL;
address_family = data_to_str(address_family_data);
@@ -598,7 +614,7 @@ socket_server_get_local_sockaddr(rpc_transport_t *this, struct sockaddr *addr,
switch (addr->sa_family) {
case AF_INET_SDP:
addr->sa_family = AF_INET;
- /* Fall through */
+ /* Fall through */
case AF_INET:
case AF_INET6:
case AF_UNSPEC:
@@ -618,7 +634,7 @@ err:
return ret;
}
-int32_t
+static int32_t
fill_inet6_inet_identifiers(rpc_transport_t *this,
struct sockaddr_storage *addr, int32_t addr_len,
char *identifier)