From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL v1 2/3] io: fix setting of QIO_CHANNEL_FEATURE_FD_PASS on server connections
Date: Wed, 23 Dec 2015 10:57:56 +0000 [thread overview]
Message-ID: <1450868277-25630-3-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1450868277-25630-1-git-send-email-berrange@redhat.com>
The QIO_CHANNEL_FEATURE_FD_PASS feature flag is set in the
qio_channel_socket_set_fd() method, however, this only deals
with client side connections.
To ensure server side connections also have the feature flag
set, we must set it in qio_channel_socket_accept() too. This
also highlighted a typo fix where the code updated the
sockaddr struct in the wrong object instance.
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
io/channel-socket.c | 10 ++++++++--
tests/test-io-channel-socket.c | 29 +++++++++++++++++++++++++----
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/io/channel-socket.c b/io/channel-socket.c
index 90b3c73..eed2ff5 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -352,13 +352,19 @@ qio_channel_socket_accept(QIOChannelSocket *ioc,
goto error;
}
- if (getsockname(cioc->fd, (struct sockaddr *)&ioc->localAddr,
- &ioc->localAddrLen) < 0) {
+ if (getsockname(cioc->fd, (struct sockaddr *)&cioc->localAddr,
+ &cioc->localAddrLen) < 0) {
error_setg_errno(errp, socket_error(),
"Unable to query local socket address");
goto error;
}
+#ifndef WIN32
+ if (cioc->localAddr.ss_family == AF_UNIX) {
+ QIO_CHANNEL(cioc)->features |= (1 << QIO_CHANNEL_FEATURE_FD_PASS);
+ }
+#endif /* WIN32 */
+
trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd);
return cioc;
diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c
index e76d54c..b0eb538 100644
--- a/tests/test-io-channel-socket.c
+++ b/tests/test-io-channel-socket.c
@@ -210,13 +210,19 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr,
static void test_io_channel(bool async,
SocketAddress *listen_addr,
- SocketAddress *connect_addr)
+ SocketAddress *connect_addr,
+ bool passFD)
{
QIOChannel *src, *dst;
QIOChannelTest *test;
if (async) {
test_io_channel_setup_async(listen_addr, connect_addr, &src, &dst);
+ g_assert(!passFD ||
+ qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
+ g_assert(!passFD ||
+ qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
+
test = qio_channel_test_new();
qio_channel_test_run_threads(test, true, src, dst);
qio_channel_test_validate(test);
@@ -226,6 +232,11 @@ static void test_io_channel(bool async,
test_io_channel_setup_async(listen_addr, connect_addr, &src, &dst);
+ g_assert(!passFD ||
+ qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
+ g_assert(!passFD ||
+ qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
+
test = qio_channel_test_new();
qio_channel_test_run_threads(test, false, src, dst);
qio_channel_test_validate(test);
@@ -235,6 +246,11 @@ static void test_io_channel(bool async,
} else {
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
+ g_assert(!passFD ||
+ qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
+ g_assert(!passFD ||
+ qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
+
test = qio_channel_test_new();
qio_channel_test_run_threads(test, true, src, dst);
qio_channel_test_validate(test);
@@ -244,6 +260,11 @@ static void test_io_channel(bool async,
test_io_channel_setup_sync(listen_addr, connect_addr, &src, &dst);
+ g_assert(!passFD ||
+ qio_channel_has_feature(src, QIO_CHANNEL_FEATURE_FD_PASS));
+ g_assert(!passFD ||
+ qio_channel_has_feature(dst, QIO_CHANNEL_FEATURE_FD_PASS));
+
test = qio_channel_test_new();
qio_channel_test_run_threads(test, false, src, dst);
qio_channel_test_validate(test);
@@ -269,7 +290,7 @@ static void test_io_channel_ipv4(bool async)
connect_addr->u.inet->host = g_strdup("127.0.0.1");
connect_addr->u.inet->port = NULL; /* Filled in later */
- test_io_channel(async, listen_addr, connect_addr);
+ test_io_channel(async, listen_addr, connect_addr, false);
qapi_free_SocketAddress(listen_addr);
qapi_free_SocketAddress(connect_addr);
@@ -303,7 +324,7 @@ static void test_io_channel_ipv6(bool async)
connect_addr->u.inet->host = g_strdup("::1");
connect_addr->u.inet->port = NULL; /* Filled in later */
- test_io_channel(async, listen_addr, connect_addr);
+ test_io_channel(async, listen_addr, connect_addr, false);
qapi_free_SocketAddress(listen_addr);
qapi_free_SocketAddress(connect_addr);
@@ -337,7 +358,7 @@ static void test_io_channel_unix(bool async)
connect_addr->u.q_unix = g_new0(UnixSocketAddress, 1);
connect_addr->u.q_unix->path = g_strdup(TEST_SOCKET);
- test_io_channel(async, listen_addr, connect_addr);
+ test_io_channel(async, listen_addr, connect_addr, true);
qapi_free_SocketAddress(listen_addr);
qapi_free_SocketAddress(connect_addr);
--
2.5.0
next prev parent reply other threads:[~2015-12-23 10:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-23 10:57 [Qemu-devel] [PULL v1 0/3] Misc I/O channel fixes Daniel P. Berrange
2015-12-23 10:57 ` [Qemu-devel] [PULL v1 1/3] io: bind to loopback IP addrs in test suite Daniel P. Berrange
2015-12-23 10:57 ` Daniel P. Berrange [this message]
2015-12-23 10:57 ` [Qemu-devel] [PULL v1 3/3] io: fix stack allocation when sending of file descriptors Daniel P. Berrange
2015-12-23 13:29 ` [Qemu-devel] [PULL v1 0/3] Misc I/O channel fixes Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1450868277-25630-3-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).