From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Eric Blake" <eblake@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
qemu-block@nongnu.org, "Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH 8/8] sockets: fix parsing of ipv4/ipv6 opts in parse_socket_addr
Date: Thu, 10 Aug 2017 17:04:51 +0100 [thread overview]
Message-ID: <20170810160451.32723-9-berrange@redhat.com> (raw)
In-Reply-To: <20170810160451.32723-1-berrange@redhat.com>
The inet_parse() function looks for 'ipv4' and 'ipv6'
flags, but only treats them as bare bool flags. The normal
QemuOpts parsing would allow on/off values to be set too.
This updated inet_parse() so that its handling of the
'ipv4' and 'ipv6' flags matches that done by QemuOpts.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
tests/test-sockets-proto.c | 13 -------------
util/qemu-sockets.c | 36 ++++++++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/tests/test-sockets-proto.c b/tests/test-sockets-proto.c
index a92389bef6..5805d2be5f 100644
--- a/tests/test-sockets-proto.c
+++ b/tests/test-sockets-proto.c
@@ -69,7 +69,6 @@ typedef struct {
*/
static QSocketsData test_data[] = {
/* Migrate with "" address */
- /* XXX all settings with =off are disabled due to inet_parse() bug */
{ .ipv4 = 1, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/wildcard/all",
.args = "-incoming tcp::9000" },
@@ -85,7 +84,6 @@ static QSocketsData test_data[] = {
{ .ipv4 = 0, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/wildcard/ipv6on",
.args = "-incoming tcp::9000,ipv6=on" },
- /*
{ .ipv4 = 0, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/wildcard/ipv4off",
.args = "-incoming tcp::9000,ipv4=off" },
@@ -98,15 +96,12 @@ static QSocketsData test_data[] = {
{ .ipv4 = 0, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/wildcard/ipv4offipv6on",
.args = "-incoming tcp::9000,ipv4=off,ipv6=on" },
- */
{ .ipv4 = 1, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/wildcard/ipv4onipv6on",
.args = "-incoming tcp::9000,ipv4=on,ipv6=on" },
- /*
{ .ipv4 = 0, .ipv6 = 0, .error = true,
.name = "/sockets/migrate/wildcard/ipv4offipv6off",
.args = "-incoming tcp::9000,ipv4=off,ipv6=off" },
- */
/* Migrate with 0.0.0.0 address */
{ .ipv4 = 1, .ipv6 = 0, .error = false,
@@ -124,7 +119,6 @@ static QSocketsData test_data[] = {
{ .ipv4 = 0, .ipv6 = 0, .error = true,
.name = "/sockets/migrate/0.0.0.0/ipv6on",
.args = "-incoming tcp:0.0.0.0:9000,ipv6=on" },
- /*
{ .ipv4 = 0, .ipv6 = 0, .error = true,
.name = "/sockets/migrate/0.0.0.0/ipv4off",
.args = "-incoming tcp:0.0.0.0:9000,ipv4=off" },
@@ -137,15 +131,12 @@ static QSocketsData test_data[] = {
{ .ipv4 = 0, .ipv6 = 0, .error = true,
.name = "/sockets/migrate/0.0.0.0/ipv4offipv6on",
.args = "-incoming tcp:0.0.0.0:9000,ipv4=off,ipv6=on" },
- */
{ .ipv4 = 1, .ipv6 = 0, .error = false,
.name = "/sockets/migrate/0.0.0.0/ipv4onipv6on",
.args = "-incoming tcp:0.0.0.0:9000,ipv4=on,ipv6=on" },
- /*
{ .ipv4 = 0, .ipv6 = 0, .error = true,
.name = "/sockets/migrate/0.0.0.0/ipv4offipv6off",
.args = "-incoming tcp:0.0.0.0:9000,ipv4=off,ipv6=off" },
- */
/* Migrate with :: address */
{ .ipv4 = 1, .ipv6 = 1, .error = false,
@@ -163,7 +154,6 @@ static QSocketsData test_data[] = {
{ .ipv4 = 0, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/::/ipv6on",
.args = "-incoming tcp:[::]:9000,ipv6=on" },
- /*
{ .ipv4 = 0, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/::/ipv4off",
.args = "-incoming tcp:[::]:9000,ipv4=off" },
@@ -176,15 +166,12 @@ static QSocketsData test_data[] = {
{ .ipv4 = 0, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/::/ipv4offipv6on",
.args = "-incoming tcp:[::]:9000,ipv4=off,ipv6=on" },
- */
{ .ipv4 = 1, .ipv6 = 1, .error = false,
.name = "/sockets/migrate/::/ipv4onipv6on",
.args = "-incoming tcp:[::]:9000,ipv4=on,ipv6=on" },
- /*
{ .ipv4 = 0, .ipv6 = 0, .error = true,
.name = "/sockets/migrate/::/ipv4offipv6off",
.args = "-incoming tcp:[::]:9000,ipv4=off,ipv6=off" },
- */
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 1358c81bcc..76202949f5 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -616,6 +616,25 @@ err:
}
/* compatibility wrapper */
+static int inet_parse_flag(const char *flagname, const char *optstr, bool *val,
+ Error **errp)
+{
+ char *end;
+ size_t len;
+
+ end = strstr(optstr, ",");
+ len = end ? end - optstr : strlen(optstr);
+ if (len == 0 || (len == 3 && strncmp(optstr, "=on", len) == 0)) {
+ *val = true;
+ } else if ((len == 4) && strncmp(optstr, "=off", len) == 0) {
+ *val = false;
+ } else {
+ error_setg(errp, "error parsing '%s' flag '%s'", flagname, optstr);
+ return -1;
+ }
+ return 0;
+}
+
int inet_parse(InetSocketAddress *addr, const char *str, Error **errp)
{
const char *optstr, *h;
@@ -623,6 +642,7 @@ int inet_parse(InetSocketAddress *addr, const char *str, Error **errp)
char port[33];
int to;
int pos;
+ char *begin;
memset(addr, 0, sizeof(*addr));
@@ -664,11 +684,19 @@ int inet_parse(InetSocketAddress *addr, const char *str, Error **errp)
addr->has_to = true;
addr->to = to;
}
- if (strstr(optstr, ",ipv4")) {
- addr->ipv4 = addr->has_ipv4 = true;
+ begin = strstr(optstr, ",ipv4");
+ if (begin) {
+ if (inet_parse_flag("ipv4", begin + 5, &addr->ipv4, errp) < 0) {
+ return -1;
+ }
+ addr->has_ipv4 = true;
}
- if (strstr(optstr, ",ipv6")) {
- addr->ipv6 = addr->has_ipv6 = true;
+ begin = strstr(optstr, ",ipv6");
+ if (begin) {
+ if (inet_parse_flag("ipv6", begin + 5, &addr->ipv6, errp) < 0) {
+ return -1;
+ }
+ addr->has_ipv6 = true;
}
return 0;
}
--
2.13.3
next prev parent reply other threads:[~2017-08-10 16:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-10 16:04 [Qemu-devel] [PATCH 0/8] Enable full IPv4/IPv6 dual stack support Daniel P. Berrange
2017-08-10 16:04 ` [Qemu-devel] [PATCH 1/8] tests: add functional test validating ipv4/ipv6 address flag handling Daniel P. Berrange
2017-08-10 16:04 ` [Qemu-devel] [PATCH 2/8] io: introduce a network socket listener API Daniel P. Berrange
2017-08-10 18:12 ` Eric Blake
2017-08-11 9:15 ` Daniel P. Berrange
2017-08-11 10:18 ` Daniel P. Berrange
2017-08-11 12:26 ` Dr. David Alan Gilbert
2017-08-11 12:29 ` Daniel P. Berrange
2017-08-11 12:39 ` Dr. David Alan Gilbert
2017-08-11 12:48 ` Daniel P. Berrange
2017-08-10 16:04 ` [Qemu-devel] [PATCH 3/8] blockdev: convert internal NBD server to QIONetListener Daniel P. Berrange
2017-08-10 18:15 ` Eric Blake
2017-08-10 16:04 ` [Qemu-devel] [PATCH 4/8] blockdev: convert qemu-nbd " Daniel P. Berrange
2017-08-10 18:27 ` Eric Blake
2017-08-10 16:04 ` [Qemu-devel] [PATCH 5/8] migration: convert socket " Daniel P. Berrange
2017-08-10 16:04 ` [Qemu-devel] [PATCH 6/8] chardev: convert the " Daniel P. Berrange
2017-08-10 16:04 ` [Qemu-devel] [PATCH 7/8] ui: convert VNC " Daniel P. Berrange
2017-08-10 16:04 ` Daniel P. Berrange [this message]
2017-08-10 18:35 ` [Qemu-devel] [PATCH 8/8] sockets: fix parsing of ipv4/ipv6 opts in parse_socket_addr Eric Blake
2017-08-11 9:22 ` Daniel P. Berrange
2017-08-10 16:33 ` [Qemu-devel] [PATCH 0/8] Enable full IPv4/IPv6 dual stack support no-reply
2017-08-10 16:33 ` no-reply
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=20170810160451.32723-9-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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).