[SCM] Samba Shared Repository - branch master updated
Stefan Metzmacher
metze at samba.org
Wed Feb 17 06:47:58 MST 2010
The branch, master has been updated
via d07cd37... tsocket/bsd: fix bug #7115 FreeBSD includes the UDP header in FIONREAD
via 1ffcb99... tsocket/bsd: set IPV6_V6ONLY on AF_INET6 sockets
via 8a0949d... tsocket/bsd: fix bug #7140 autodetect ipv4 and ipv6 based on the remote address if the local address is any
via 6637b2f... tsocket/bsd: fix bug #7140 use calculated sa_socklen for bind() in tstream_bsd_connect_send()
via 135543b... tsocket/bsd: fix do_bind logic for AF_INET
via 0b3e950... socket_wrapper: also ignore AF_INET6 in swrap_setsockopt()
from a8cc2fa... cifs.upcall: allocate a talloc context for smb_krb5_unparse_name
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit d07cd37b993d3c9beded20323174633b806196b5
Author: Stefan Metzmacher <metze at samba.org>
Date: Wed Feb 17 13:53:02 2010 +0100
tsocket/bsd: fix bug #7115 FreeBSD includes the UDP header in FIONREAD
metze
commit 1ffcb991a900b78c9175f6b093839fe96b1bd7d9
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
commit 8a0949dfc8d2ecf577dfc5ef38496421101b734e
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
commit 6637b2f4b06fcee1e8e1b1782dd96e3273f8caac
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
commit 135543b4c300e2fc31ee4165ce630644e1aef455
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
commit 0b3e950731fe72a258a631e39ca1304d54663536
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
-----------------------------------------------------------------------
Summary of changes:
lib/socket_wrapper/socket_wrapper.c | 4 +
lib/tsocket/tsocket_bsd.c | 107 ++++++++++++++++++++++++++++++++---
2 files changed, 102 insertions(+), 9 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 7c02557..9027bc9 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -883,10 +883,12 @@ static void tdgram_bsd_recvfrom_handler(void *private_data)
return;
}
- if (ret != state->len) {
- tevent_req_error(req, EIO);
- return;
- }
+ /*
+ * some systems too much bytes in tsocket_bsd_pending()
+ * the return value includes some IP/UDP header bytes
+ */
+ state->len = ret;
+ talloc_realloc(state, state->buf, uint8_t, ret);
tevent_req_done(req);
}
@@ -1142,6 +1144,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) {
@@ -1170,9 +1175,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:
@@ -1185,6 +1192,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:
@@ -1192,7 +1202,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;
}
@@ -1217,6 +1243,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;
@@ -1254,6 +1295,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;
@@ -1944,6 +1991,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,
@@ -1979,9 +2029,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:
@@ -1994,6 +2046,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:
@@ -2001,7 +2056,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;
@@ -2013,6 +2084,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;
@@ -2025,13 +2109,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