Commit aa1a5faa authored by Grigorii Demidov's avatar Grigorii Demidov

swrap: ipv6 socket names bug, auto-bind bug were fixed

parent 67169bd4
......@@ -1083,15 +1083,14 @@ static int convert_un_in(const struct sockaddr_un *un, struct sockaddr *in, sock
break;
}
#ifdef HAVE_IPV6
case SOCKET_TYPE_CHAR_TCP_V6:
case SOCKET_TYPE_CHAR_UDP_V6: {
case SOCKET_TYPE_CHAR_TCP_V6_LONG:
case SOCKET_TYPE_CHAR_UDP_V6_LONG: {
unsigned int in6_a0, in6_a1, in6_a2, in6_a3;
struct sockaddr_in6 *in2 = (struct sockaddr_in6 *)(void *)in;
if (sscanf(p, SOCKET_FORMAT_V6_LONG, &type,
&in6_a0, &in6_a1, &in6_a2, &in6_a3, &prt) != 6) {
errno = EINVAL;
SWRAP_LOG(SWRAP_LOG_DEBUG, "size 2 failed");
return -1;
}
......@@ -1177,10 +1176,10 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i
switch (si->type) {
case SOCK_STREAM:
type = SOCKET_TYPE_CHAR_TCP_V6;
type = SOCKET_TYPE_CHAR_TCP_V6_LONG;
break;
case SOCK_DGRAM:
type = SOCKET_TYPE_CHAR_UDP_V6;
type = SOCKET_TYPE_CHAR_UDP_V6_LONG;
break;
default:
SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n");
......@@ -1319,10 +1318,10 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in
switch (si->type) {
case SOCK_STREAM:
type = SOCKET_TYPE_CHAR_TCP_V6;
type = SOCKET_TYPE_CHAR_TCP_V6_LONG;
break;
case SOCK_DGRAM:
type = SOCKET_TYPE_CHAR_UDP_V6;
type = SOCKET_TYPE_CHAR_UDP_V6_LONG;
break;
default:
SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n");
......@@ -2796,6 +2795,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
char type;
int ret;
int port;
unsigned int in4_addr, in6_a0, in6_a1, in6_a2, in6_a3;
struct stat st;
if (autobind_start_init != 1) {
......@@ -2825,7 +2825,8 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
memset(&in, 0, sizeof(in));
in.sin_family = AF_INET;
in.sin_addr.s_addr = htonl(socket_wrapper_default_addr());
in4_addr = socket_wrapper_default_addr();
in.sin_addr.s_addr = htonl(in4_addr);
si->myname = (struct swrap_address) {
.sa_socklen = sizeof(in),
......@@ -2844,10 +2845,10 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
switch (si->type) {
case SOCK_STREAM:
type = SOCKET_TYPE_CHAR_TCP_V6;
type = SOCKET_TYPE_CHAR_TCP_V6_LONG;
break;
case SOCK_DGRAM:
type = SOCKET_TYPE_CHAR_UDP_V6;
type = SOCKET_TYPE_CHAR_UDP_V6_LONG;
break;
default:
errno = ESOCKTNOSUPPORT;
......@@ -2863,6 +2864,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
.sa_socklen = sizeof(in6),
};
memcpy(&si->myname.sa.in6, &in6, si->myname.sa_socklen);
swrap_make_ipv6_ints(in6.sin6_addr.s6_addr,&in6_a0,&in6_a1,&in6_a2,&in6_a3);
break;
}
#endif
......@@ -2877,9 +2879,16 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
for (i = 0; i < SOCKET_MAX_SOCKETS; i++) {
port = autobind_start + i;
snprintf(un_addr.sa.un.sun_path, sizeof(un_addr.sa.un.sun_path),
"%s/"SOCKET_FORMAT_LONG, socket_wrapper_dir(),
type, socket_wrapper_default_addr(), port);
if (family == AF_INET)
snprintf(un_addr.sa.un.sun_path, sizeof(un_addr.sa.un.sun_path),
"%s/"SOCKET_FORMAT_LONG, socket_wrapper_dir(),
type, in4_addr, port);
else
snprintf(un_addr.sa.un.sun_path, sizeof(un_addr.sa.un.sun_path),
"%s/"SOCKET_FORMAT_V6_LONG, socket_wrapper_dir(),
type, in6_a0,in6_a1, in6_a2, in6_a3, port);
if (stat(un_addr.sa.un.sun_path, &st) == 0) continue;
ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen);
......@@ -2889,6 +2898,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
si->bound = 1;
autobind_start = port + 1;
SWRAP_LOG(SWRAP_LOG_TRACE, "bound to: %s", un_addr.sa.un.sun_path);
break;
}
if (i == SOCKET_MAX_SOCKETS) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment