From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v3 4/5] sockets: remove use of QemuOpts from socket_dgram
Date: Mon, 11 Jan 2016 13:17:04 +0000 [thread overview]
Message-ID: <1452518225-11751-5-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1452518225-11751-1-git-send-email-berrange@redhat.com>
The socket_dgram method accepts a QAPI SocketAddress object
which it then turns into QemuOpts before calling the
inet_dgram_opts helper method. By converting the latter to
use QAPI SocketAddress directly, the QemuOpts conversion
step can be eliminated.
This removes the very last use of QemuOpts from the
sockets code, so the socket_optslist[] array is also
removed.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
include/qemu/sockets.h | 1 -
util/qemu-sockets.c | 99 ++++++++++++--------------------------------------
2 files changed, 24 insertions(+), 76 deletions(-)
diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 84221cb..573328e 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -26,7 +26,6 @@ int inet_aton(const char *cp, struct in_addr *ia);
#endif /* !_WIN32 */
-#include "qemu/option.h"
#include "qapi/error.h"
#include "qapi-types.h"
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 2befe6a..f455a17 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -36,39 +36,6 @@
# define AI_V4MAPPED 0
#endif
-/* used temporarily until all users are converted to QemuOpts */
-static QemuOptsList socket_optslist = {
- .name = "socket",
- .head = QTAILQ_HEAD_INITIALIZER(socket_optslist.head),
- .desc = {
- {
- .name = "path",
- .type = QEMU_OPT_STRING,
- },{
- .name = "host",
- .type = QEMU_OPT_STRING,
- },{
- .name = "port",
- .type = QEMU_OPT_STRING,
- },{
- .name = "localaddr",
- .type = QEMU_OPT_STRING,
- },{
- .name = "localport",
- .type = QEMU_OPT_STRING,
- },{
- .name = "to",
- .type = QEMU_OPT_NUMBER,
- },{
- .name = "ipv4",
- .type = QEMU_OPT_BOOL,
- },{
- .name = "ipv6",
- .type = QEMU_OPT_BOOL,
- },
- { /* end if list */ }
- },
-};
static int inet_getport(struct addrinfo *e)
{
@@ -479,21 +446,29 @@ static int inet_connect_saddr(InetSocketAddress *saddr, Error **errp,
return sock;
}
-static int inet_dgram_opts(QemuOpts *opts, Error **errp)
+static int inet_dgram_saddr(InetSocketAddress *sraddr,
+ InetSocketAddress *sladdr,
+ Error **errp)
{
struct addrinfo ai, *peer = NULL, *local = NULL;
const char *addr;
const char *port;
int sock = -1, rc;
+ Error *err = NULL;
/* lookup peer addr */
memset(&ai,0, sizeof(ai));
ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG;
- ai.ai_family = PF_UNSPEC;
+ ai.ai_family = inet_ai_family_from_address(sraddr, &err);
ai.ai_socktype = SOCK_DGRAM;
- addr = qemu_opt_get(opts, "host");
- port = qemu_opt_get(opts, "port");
+ if (err) {
+ error_propagate(errp, err);
+ return -1;
+ }
+
+ addr = sraddr->host;
+ port = sraddr->port;
if (addr == NULL || strlen(addr) == 0) {
addr = "localhost";
}
@@ -502,11 +477,6 @@ static int inet_dgram_opts(QemuOpts *opts, Error **errp)
return -1;
}
- if (qemu_opt_get_bool(opts, "ipv4", 0))
- ai.ai_family = PF_INET;
- if (qemu_opt_get_bool(opts, "ipv6", 0))
- ai.ai_family = PF_INET6;
-
if (0 != (rc = getaddrinfo(addr, port, &ai, &peer))) {
error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
gai_strerror(rc));
@@ -519,13 +489,19 @@ static int inet_dgram_opts(QemuOpts *opts, Error **errp)
ai.ai_family = peer->ai_family;
ai.ai_socktype = SOCK_DGRAM;
- addr = qemu_opt_get(opts, "localaddr");
- port = qemu_opt_get(opts, "localport");
- if (addr == NULL || strlen(addr) == 0) {
+ if (sladdr) {
+ addr = sladdr->host;
+ port = sladdr->port;
+ if (addr == NULL || strlen(addr) == 0) {
+ addr = NULL;
+ }
+ if (!port || strlen(port) == 0) {
+ port = "0";
+ }
+ } else {
addr = NULL;
- }
- if (!port || strlen(port) == 0)
port = "0";
+ }
if (0 != (rc = getaddrinfo(addr, port, &ai, &local))) {
error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
@@ -634,25 +610,6 @@ fail:
return NULL;
}
-static void inet_addr_to_opts(QemuOpts *opts, const InetSocketAddress *addr)
-{
- bool ipv4 = addr->has_ipv4 && addr->ipv4;
- bool ipv6 = addr->has_ipv6 && addr->ipv6;
-
- if (ipv4 || ipv6) {
- qemu_opt_set_bool(opts, "ipv4", ipv4, &error_abort);
- qemu_opt_set_bool(opts, "ipv6", ipv6, &error_abort);
- } else if (addr->has_ipv4 || addr->has_ipv6) {
- qemu_opt_set_bool(opts, "ipv4", !addr->has_ipv4, &error_abort);
- qemu_opt_set_bool(opts, "ipv6", !addr->has_ipv6, &error_abort);
- }
- if (addr->has_to) {
- qemu_opt_set_number(opts, "to", addr->to, &error_abort);
- }
- qemu_opt_set(opts, "host", addr->host, &error_abort);
- qemu_opt_set(opts, "port", addr->port, &error_abort);
-}
-
int inet_listen(const char *str, char *ostr, int olen,
int socktype, int port_offset, Error **errp)
{
@@ -1028,25 +985,17 @@ int socket_listen(SocketAddress *addr, Error **errp)
int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp)
{
- QemuOpts *opts;
int fd;
- opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
switch (remote->type) {
case SOCKET_ADDRESS_KIND_INET:
- inet_addr_to_opts(opts, remote->u.inet);
- if (local) {
- qemu_opt_set(opts, "localaddr", local->u.inet->host, &error_abort);
- qemu_opt_set(opts, "localport", local->u.inet->port, &error_abort);
- }
- fd = inet_dgram_opts(opts, errp);
+ fd = inet_dgram_saddr(remote->u.inet, local ? local->u.inet : NULL, errp);
break;
default:
error_setg(errp, "socket type unsupported for datagram");
fd = -1;
}
- qemu_opts_del(opts);
return fd;
}
--
2.5.0
next prev parent reply other threads:[~2016-01-11 13:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-11 13:17 [Qemu-devel] [PATCH v3 0/5] Convert qemu-socket to use QAPI exclusively Daniel P. Berrange
2016-01-11 13:17 ` [Qemu-devel] [PATCH v3 1/5] sockets: remove use of QemuOpts from header file Daniel P. Berrange
2016-01-11 13:17 ` [Qemu-devel] [PATCH v3 2/5] sockets: remove use of QemuOpts from socket_listen Daniel P. Berrange
2016-01-15 16:50 ` Eric Blake
2016-01-11 13:17 ` [Qemu-devel] [PATCH v3 3/5] sockets: remove use of QemuOpts from socket_connect Daniel P. Berrange
2016-01-15 17:41 ` Eric Blake
2016-01-11 13:17 ` Daniel P. Berrange [this message]
2016-01-15 23:12 ` [Qemu-devel] [PATCH v3 4/5] sockets: remove use of QemuOpts from socket_dgram Eric Blake
2016-01-11 13:17 ` [Qemu-devel] [PATCH v3 5/5] vnc: distiguish between ipv4/ipv6 omitted vs set to off Daniel P. Berrange
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=1452518225-11751-5-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=pbonzini@redhat.com \
--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).