From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv3fD-0005oX-5p for qemu-devel@nongnu.org; Fri, 14 Oct 2016 10:40:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bv3f9-00008f-0O for qemu-devel@nongnu.org; Fri, 14 Oct 2016 10:40:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45660) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bv3f8-00008b-M7 for qemu-devel@nongnu.org; Fri, 14 Oct 2016 10:40:42 -0400 References: <1476435656-3100-1-git-send-email-stefanha@redhat.com> <1476435656-3100-4-git-send-email-stefanha@redhat.com> From: Eric Blake Message-ID: Date: Fri, 14 Oct 2016 09:40:40 -0500 MIME-Version: 1.0 In-Reply-To: <1476435656-3100-4-git-send-email-stefanha@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="JlihXNPMN6urRA09NIU1aeiRCKVDEL7Pn" Subject: Re: [Qemu-devel] [PATCH v2 3/4] sockets: add AF_VSOCK support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --JlihXNPMN6urRA09NIU1aeiRCKVDEL7Pn From: Eric Blake To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Michael Roth Message-ID: Subject: Re: [Qemu-devel] [PATCH v2 3/4] sockets: add AF_VSOCK support References: <1476435656-3100-1-git-send-email-stefanha@redhat.com> <1476435656-3100-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1476435656-3100-4-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/14/2016 04:00 AM, Stefan Hajnoczi wrote: > Add the AF_VSOCK address family so that qemu-ga will be able to use > virtio-vsock. >=20 > The AF_VSOCK address family uses address tuples. The cid i= s > the unique identifier comparable to an IP address. AF_VSOCK does not > use name resolution so it's easy to convert between struct sockaddr_vm > and strings. >=20 > This patch defines a VsockSocketAddress instead of trying to piggy-back= > on InetSocketAddress. This is cleaner in the long run since it avoids > lots of IPv4 vs IPv6 vs vsock special casing. >=20 > Signed-off-by: Stefan Hajnoczi > --- > ## > +# @VsockSocketAddress > +# > +# Captures a socket address in the vsock namespace. > +# > +# @cid: unique host identifier > +# @port: port > +# > +# Note that string types are used to allow for possible future hostnam= e or > +# service resolution support. > +# > +# Since 2.8 > +## > +{ 'struct': 'VsockSocketAddress', > + 'data': { > + 'cid': 'str', > + 'port': 'str' } } It would also be possible to do this now: { 'struct': 'VsockSocketAddress', 'data': { 'cid': 'int', 'port': 'int' } } then down the road expand to: { 'alternate': 'StrOrInt', 'data': { 's': 'str', 'i': 'int' } } { 'struct': 'VsockSocketAddress', 'data': { 'cid': 'StrOrInt', 'port': 'StrOrInt' } } although the C code to do type-safe access vsock->cid.u.i or vsock->cid.u.s based on vsock->cid.type is a bit more verbose than just accessing vsock->cid as a string and converting every time around. Where it gets really interesting is that using the alternate would allow all of these QMP forms: { "socket": { "cid": 1, "port": 2 } } { "socket": { "cid": "1", "port": "2" } } { "socket": { "cid": "host", "port": "service" } } It MIGHT be worth going the type-safe route, especially if we WANT to convert the existing SocketAddress uses to use the alternate rather than always managing things as a string. But it doesn't have to be in this patch. > +static VsockSocketAddress *vsock_parse(const char *str, Error **errp) > +{ > + VsockSocketAddress *addr =3D NULL; > + char cid[33]; > + char port[33]; > + int n; > + > + if (sscanf(str, "%32[^:]:%32[^,]%n", cid, port, &n) !=3D 2) { This says stop at the first comma after the colon... > + error_setg(errp, "error parsing address '%s'", str); > + return NULL; > + } > + if (str[n] !=3D '\0') { > + error_setg(errp, "trailing characters in address '%s'", str); =2E..but this rejects a trailing comma. Is a trailing comma possible bas= e on how QemuOpts work? If so, do you need to handle it here? Otherwise looking okay to me. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --JlihXNPMN6urRA09NIU1aeiRCKVDEL7Pn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYAO5oAAoJEKeha0olJ0NqW18H/j7qgGu/qZxAfPOOPJrlF5k2 APPNXNStneEsbo4RvIxufyhpyHunTOSKCe+LJ5UYuHvXxwQeJ1+MexQKRH+YZLQJ lmQU0ZI8RbUhmLpQBOXiQkWcsgbNz3EXyRL7k168VtKdR90rSzMFhDQlO5lxnrKt xiDdgK9rh5z7b0uU9q06tP/W4hyXi5L+DOSWUAyWUxn+L2PQ/QldvRMCtkL4XzVf uFys9P2gCLxjl1QTjR7mbGpdfbIDO/nxneof8b9XysljrrwIcJoBG26xmGjhOKP5 /VdXlq0FDnuFqTP5jKNgXLQUCIMVPVqiW/voUL1JC7Ji3lwjxH/lsp0aieBCSWI= =XTRD -----END PGP SIGNATURE----- --JlihXNPMN6urRA09NIU1aeiRCKVDEL7Pn--