[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 18/17] util/qemu-sockets: Display IPv6 addresses within s
From: |
Daniel P . Berrangé |
Subject: |
Re: [RFC PATCH 18/17] util/qemu-sockets: Display IPv6 addresses within square brackets |
Date: |
Thu, 20 Oct 2022 14:50:18 +0100 |
User-agent: |
Mutt/2.2.7 (2022-08-07) |
On Thu, Oct 20, 2022 at 03:40:51PM +0200, Philippe Mathieu-Daudé wrote:
> See RFC3986 "Uniform Resource Identifier (URI): Generic Syntax"
> section 3.2.2. 'Host' [1]:
>
> A host identified by an Internet Protocol literal address, version
> 6 [RFC3513] or later, is distinguished by enclosing the IP literal
> within square brackets ("[" and "]"). This is the only place where
> square bracket characters are allowed in the URI syntax.
>
> and RFC5952 "A Recommendation for IPv6 Address Text Representation"
> section 6. 'Notes on Combining IPv6 Addresses with Port Numbers' [2]:
>
> The [] style as expressed in [RFC3986] SHOULD be employed, and is
> the default unless otherwise specified. [...] For URIs containing
> IPv6 address literals, [RFC3986] MUST be followed [...].
>
> [1] https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2
> [2] https://www.rfc-editor.org/rfc/rfc5952#section-6
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> tests/qtest/netdev-socket.c | 4 ++--
> util/qemu-sockets.c | 4 +++-
> 2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c
> index 4ea66b4c69..65f0e01db1 100644
> --- a/tests/qtest/netdev-socket.c
> +++ b/tests/qtest/netdev-socket.c
> @@ -134,13 +134,13 @@ static void test_stream_inet_ipv6(void)
> "addr.ipv4=off,addr.ipv6=on,"
> "addr.host=localhost,addr.port=%d", port);
>
> - expect = g_strdup_printf("st0: index=0,type=stream,tcp:::1:%d\r\n",
> + expect = g_strdup_printf("st0: index=0,type=stream,tcp:[::1]:%d\r\n",
> port);
> EXPECT_STATE(qts1, expect, 0);
> g_free(expect);
>
> /* the port is unknown, check only the address */
> - EXPECT_STATE(qts0, "st0: index=0,type=stream,tcp:::1", ':');
> + EXPECT_STATE(qts0, "st0: index=0,type=stream,tcp:[::1]", ':');
>
> qtest_quit(qts1);
> qtest_quit(qts0);
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index a9926af714..19af96fa2c 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -1081,8 +1081,10 @@ char *socket_uri(SocketAddress *addr)
> {
> switch (addr->type) {
> case SOCKET_ADDRESS_TYPE_INET:
> - return g_strdup_printf("tcp:%s:%s",
> + return g_strdup_printf("tcp:%s%s%s:%s",
> + addr->u.inet.ipv6 ? "[" : "",
> addr->u.inet.host,
> + addr->u.inet.ipv6 ? "]" : "",
> addr->u.inet.port);
"host" is not required to be numeric and using [..] is only
valid for numeric IPv6 addresses, not hostnames. So you
need to actually check "host" is fully numeric.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [PATCH v12 13/17] qemu-sockets: move and rename SocketAddress_to_str(), (continued)