From nobody Tue Feb 10 16:58:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502382036734812.6663063866642; Thu, 10 Aug 2017 09:20:36 -0700 (PDT) Received: from localhost ([::1]:53990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqCJ-0002UE-5x for importer@patchew.org; Thu, 10 Aug 2017 12:20:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpzR-0006Z5-3S for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpzP-0003xH-KW for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:07:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpzK-0003tl-Ml; Thu, 10 Aug 2017 12:07:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3244B2CE; Thu, 10 Aug 2017 16:07:09 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54BE56BF7C; Thu, 10 Aug 2017 16:07:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3244B2CE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:51 +0100 Message-Id: <20170810160451.32723-9-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 10 Aug 2017 16:07:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 8/8] sockets: fix parsing of ipv4/ipv6 opts in parse_socket_addr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake --- 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[] =3D { /* Migrate with "" address */ - /* XXX all settings with =3Doff are disabled due to inet_parse() bug */ { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/wildcard/all", .args =3D "-incoming tcp::9000" }, @@ -85,7 +84,6 @@ static QSocketsData test_data[] =3D { { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/wildcard/ipv6on", .args =3D "-incoming tcp::9000,ipv6=3Don" }, - /* { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/wildcard/ipv4off", .args =3D "-incoming tcp::9000,ipv4=3Doff" }, @@ -98,15 +96,12 @@ static QSocketsData test_data[] =3D { { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/wildcard/ipv4offipv6on", .args =3D "-incoming tcp::9000,ipv4=3Doff,ipv6=3Don" }, - */ { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/wildcard/ipv4onipv6on", .args =3D "-incoming tcp::9000,ipv4=3Don,ipv6=3Don" }, - /* { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, .name =3D "/sockets/migrate/wildcard/ipv4offipv6off", .args =3D "-incoming tcp::9000,ipv4=3Doff,ipv6=3Doff" }, - */ =20 /* Migrate with 0.0.0.0 address */ { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, @@ -124,7 +119,6 @@ static QSocketsData test_data[] =3D { { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, .name =3D "/sockets/migrate/0.0.0.0/ipv6on", .args =3D "-incoming tcp:0.0.0.0:9000,ipv6=3Don" }, - /* { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, .name =3D "/sockets/migrate/0.0.0.0/ipv4off", .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Doff" }, @@ -137,15 +131,12 @@ static QSocketsData test_data[] =3D { { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, .name =3D "/sockets/migrate/0.0.0.0/ipv4offipv6on", .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Doff,ipv6=3Don" }, - */ { .ipv4 =3D 1, .ipv6 =3D 0, .error =3D false, .name =3D "/sockets/migrate/0.0.0.0/ipv4onipv6on", .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Don,ipv6=3Don" }, - /* { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, .name =3D "/sockets/migrate/0.0.0.0/ipv4offipv6off", .args =3D "-incoming tcp:0.0.0.0:9000,ipv4=3Doff,ipv6=3Doff" }, - */ =20 /* Migrate with :: address */ { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, @@ -163,7 +154,6 @@ static QSocketsData test_data[] =3D { { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/::/ipv6on", .args =3D "-incoming tcp:[::]:9000,ipv6=3Don" }, - /* { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/::/ipv4off", .args =3D "-incoming tcp:[::]:9000,ipv4=3Doff" }, @@ -176,15 +166,12 @@ static QSocketsData test_data[] =3D { { .ipv4 =3D 0, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/::/ipv4offipv6on", .args =3D "-incoming tcp:[::]:9000,ipv4=3Doff,ipv6=3Don" }, - */ { .ipv4 =3D 1, .ipv6 =3D 1, .error =3D false, .name =3D "/sockets/migrate/::/ipv4onipv6on", .args =3D "-incoming tcp:[::]:9000,ipv4=3Don,ipv6=3Don" }, - /* { .ipv4 =3D 0, .ipv6 =3D 0, .error =3D true, .name =3D "/sockets/migrate/::/ipv4offipv6off", .args =3D "-incoming tcp:[::]:9000,ipv4=3Doff,ipv6=3Doff" }, - */ =20 =20 =20 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: } =20 /* compatibility wrapper */ +static int inet_parse_flag(const char *flagname, const char *optstr, bool = *val, + Error **errp) +{ + char *end; + size_t len; + + end =3D strstr(optstr, ","); + len =3D end ? end - optstr : strlen(optstr); + if (len =3D=3D 0 || (len =3D=3D 3 && strncmp(optstr, "=3Don", len) =3D= =3D 0)) { + *val =3D true; + } else if ((len =3D=3D 4) && strncmp(optstr, "=3Doff", len) =3D=3D 0) { + *val =3D 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; =20 memset(addr, 0, sizeof(*addr)); =20 @@ -664,11 +684,19 @@ int inet_parse(InetSocketAddress *addr, const char *s= tr, Error **errp) addr->has_to =3D true; addr->to =3D to; } - if (strstr(optstr, ",ipv4")) { - addr->ipv4 =3D addr->has_ipv4 =3D true; + begin =3D strstr(optstr, ",ipv4"); + if (begin) { + if (inet_parse_flag("ipv4", begin + 5, &addr->ipv4, errp) < 0) { + return -1; + } + addr->has_ipv4 =3D true; } - if (strstr(optstr, ",ipv6")) { - addr->ipv6 =3D addr->has_ipv6 =3D true; + begin =3D strstr(optstr, ",ipv6"); + if (begin) { + if (inet_parse_flag("ipv6", begin + 5, &addr->ipv6, errp) < 0) { + return -1; + } + addr->has_ipv6 =3D true; } return 0; } --=20 2.13.3