[SCM] Samba Shared Repository - branch v3-5-test updated

Karolin Seeger kseeger at samba.org
Thu Feb 18 04:57:49 MST 2010


The branch, v3-5-test has been updated
       via  d1dfa2e... tsocket/bsd: set IPV6_V6ONLY on AF_INET6 sockets
       via  b4a5c33... tsocket/bsd: fix bug #7140 autodetect ipv4 and ipv6 based on the remote address if the local address is any
       via  c84c467... tsocket/bsd: fix bug #7140 use calculated sa_socklen for bind() in tstream_bsd_connect_send()
       via  fc63303... tsocket/bsd: fix do_bind logic for AF_INET
       via  6aa0941... socket_wrapper: also ignore AF_INET6 in swrap_setsockopt()
      from  61ea3d3... s3-modules: fix get_acl_blob in the acl_tdb VFS module.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-5-test


- Log -----------------------------------------------------------------
commit d1dfa2e92fea3dc54771c4b1a6e3c06ee478b54f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 17 09:33:18 2010 +0100

    tsocket/bsd: set IPV6_V6ONLY on AF_INET6 sockets
    
    Some system already have this as default. It's easier
    to behave the same way on all systems and handle ipv6
    and ipv4 sockets separate.
    
    metze
    (cherry picked from commit 1ffcb991a900b78c9175f6b093839fe96b1bd7d9)

commit b4a5c3325a272c97658aaede1f1c659260524789
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 17 08:49:28 2010 +0100

    tsocket/bsd: fix bug #7140 autodetect ipv4 and ipv6 based on the remote address if the local address is any
    
    metze
    (cherry picked from commit 8a0949dfc8d2ecf577dfc5ef38496421101b734e)

commit c84c467be347384ab1ceb7d74147fef364678235
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 17 08:45:58 2010 +0100

    tsocket/bsd: fix bug #7140 use calculated sa_socklen for bind() in tstream_bsd_connect_send()
    
    This is needed because, we can't use sizeof(sockaddr_storage) for AF_UNIX
    sockets. Also some platforms require exact values for AF_INET and AF_INET6.
    
    metze
    (cherry picked from commit 6637b2f4b06fcee1e8e1b1782dd96e3273f8caac)

commit fc63303b07b09f6d6855284f4e0080972fe424f7
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 17 08:42:22 2010 +0100

    tsocket/bsd: fix do_bind logic for AF_INET
    
    We want the explicit bind() when we don't use the any address.
    
    metze
    (cherry picked from commit 135543b4c300e2fc31ee4165ce630644e1aef455)

commit 6aa09416ad5f27e3db679765657b67e54dde5fd9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 17 09:43:00 2010 +0100

    socket_wrapper: also ignore AF_INET6 in swrap_setsockopt()
    
    metze
    (cherry picked from commit 0b3e950731fe72a258a631e39ca1304d54663536)

-----------------------------------------------------------------------

Summary of changes:
 lib/socket_wrapper/socket_wrapper.c |    4 ++
 lib/tsocket/tsocket_bsd.c           |   97 +++++++++++++++++++++++++++++++++--
 2 files changed, 96 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index a188cc6..9d732ee 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -1839,6 +1839,10 @@ _PUBLIC_ int swrap_setsockopt(int s, int  level,  int  optname,  const  void  *o
 	switch (si->family) {
 	case AF_INET:
 		return 0;
+#ifdef HAVE_IPV6
+	case AF_INET6:
+		return 0;
+#endif
 	default:
 		errno = ENOPROTOOPT;
 		return -1;
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index 1c1e580..634deb8 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -1136,6 +1136,9 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
 	int ret;
 	bool do_bind = false;
 	bool do_reuseaddr = false;
+	bool do_ipv6only = false;
+	bool is_inet = false;
+	int sa_fam = lbsda->u.sa.sa_family;
 	socklen_t sa_socklen = sizeof(lbsda->u.ss);
 
 	if (remote) {
@@ -1164,9 +1167,11 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
 			do_reuseaddr = true;
 			do_bind = true;
 		}
-		if (lbsda->u.in.sin_addr.s_addr == INADDR_ANY) {
+		if (lbsda->u.in.sin_addr.s_addr != INADDR_ANY) {
 			do_bind = true;
 		}
+		is_inet = true;
+		sa_socklen = sizeof(rbsda->u.in);
 		break;
 #ifdef HAVE_IPV6
 	case AF_INET6:
@@ -1179,6 +1184,9 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
 			   sizeof(in6addr_any)) != 0) {
 			do_bind = true;
 		}
+		is_inet = true;
+		sa_socklen = sizeof(rbsda->u.in6);
+		do_ipv6only = true;
 		break;
 #endif
 	default:
@@ -1186,7 +1194,23 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
 		return -1;
 	}
 
-	fd = socket(lbsda->u.sa.sa_family, SOCK_DGRAM, 0);
+	if (!do_bind && is_inet && rbsda) {
+		sa_fam = rbsda->u.sa.sa_family;
+		switch (sa_fam) {
+		case AF_INET:
+			sa_socklen = sizeof(rbsda->u.in);
+			do_ipv6only = false;
+			break;
+#ifdef HAVE_IPV6
+		case AF_INET6:
+			sa_socklen = sizeof(rbsda->u.in6);
+			do_ipv6only = true;
+			break;
+#endif
+		}
+	}
+
+	fd = socket(sa_fam, SOCK_DGRAM, 0);
 	if (fd < 0) {
 		return fd;
 	}
@@ -1211,6 +1235,21 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
 	bsds->fd = fd;
 	talloc_set_destructor(bsds, tdgram_bsd_destructor);
 
+#ifdef HAVE_IPV6
+	if (do_ipv6only) {
+		int val = 1;
+
+		ret = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
+				 (const void *)&val, sizeof(val));
+		if (ret == -1) {
+			int saved_errno = errno;
+			talloc_free(dgram);
+			errno = saved_errno;
+			return ret;
+		}
+	}
+#endif
+
 	if (broadcast) {
 		int val = 1;
 
@@ -1248,6 +1287,12 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
 	}
 
 	if (rbsda) {
+		if (rbsda->u.sa.sa_family != sa_fam) {
+			talloc_free(dgram);
+			errno = EINVAL;
+			return -1;
+		}
+
 		ret = connect(fd, &rbsda->u.sa, sa_socklen);
 		if (ret == -1) {
 			int saved_errno = errno;
@@ -1938,6 +1983,9 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
 	bool retry;
 	bool do_bind = false;
 	bool do_reuseaddr = false;
+	bool do_ipv6only = false;
+	bool is_inet = false;
+	int sa_fam = lbsda->u.sa.sa_family;
 	socklen_t sa_socklen = sizeof(rbsda->u.ss);
 
 	req = tevent_req_create(mem_ctx, &state,
@@ -1973,9 +2021,11 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
 			do_reuseaddr = true;
 			do_bind = true;
 		}
-		if (lbsda->u.in.sin_addr.s_addr == INADDR_ANY) {
+		if (lbsda->u.in.sin_addr.s_addr != INADDR_ANY) {
 			do_bind = true;
 		}
+		is_inet = true;
+		sa_socklen = sizeof(rbsda->u.in);
 		break;
 #ifdef HAVE_IPV6
 	case AF_INET6:
@@ -1988,6 +2038,9 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
 			   sizeof(in6addr_any)) != 0) {
 			do_bind = true;
 		}
+		is_inet = true;
+		sa_socklen = sizeof(rbsda->u.in6);
+		do_ipv6only = true;
 		break;
 #endif
 	default:
@@ -1995,7 +2048,23 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
 		goto post;
 	}
 
-	state->fd = socket(lbsda->u.sa.sa_family, SOCK_STREAM, 0);
+	if (!do_bind && is_inet) {
+		sa_fam = rbsda->u.sa.sa_family;
+		switch (sa_fam) {
+		case AF_INET:
+			sa_socklen = sizeof(rbsda->u.in);
+			do_ipv6only = false;
+			break;
+#ifdef HAVE_IPV6
+		case AF_INET6:
+			sa_socklen = sizeof(rbsda->u.in6);
+			do_ipv6only = true;
+			break;
+#endif
+		}
+	}
+
+	state->fd = socket(sa_fam, SOCK_STREAM, 0);
 	if (state->fd == -1) {
 		tevent_req_error(req, errno);
 		goto post;
@@ -2007,6 +2076,19 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
 		goto post;
 	}
 
+#ifdef HAVE_IPV6
+	if (do_ipv6only) {
+		int val = 1;
+
+		ret = setsockopt(state->fd, IPPROTO_IPV6, IPV6_V6ONLY,
+				 (const void *)&val, sizeof(val));
+		if (ret == -1) {
+			tevent_req_error(req, errno);
+			goto post;
+		}
+	}
+#endif
+
 	if (do_reuseaddr) {
 		int val = 1;
 
@@ -2019,13 +2101,18 @@ static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
 	}
 
 	if (do_bind) {
-		ret = bind(state->fd, &lbsda->u.sa, sizeof(lbsda->u.ss));
+		ret = bind(state->fd, &lbsda->u.sa, sa_socklen);
 		if (ret == -1) {
 			tevent_req_error(req, errno);
 			goto post;
 		}
 	}
 
+	if (rbsda->u.sa.sa_family != sa_fam) {
+		tevent_req_error(req, EINVAL);
+		goto post;
+	}
+
 	ret = connect(state->fd, &rbsda->u.sa, sa_socklen);
 	err = tsocket_bsd_error_from_errno(ret, errno, &retry);
 	if (retry) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list