diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2017-12-22 13:20:40 +0000 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2018-03-13 18:06:06 +0000 |
commit | 9bb4060c998e56976b36ee628ce7e0ecbd8ffb49 (patch) | |
tree | fb802da3a2b4576db6cd5d11f28e91920181ae85 /chardev | |
parent | 1723d6b1cfe6572881f578bce3aa25185b81b148 (diff) |
char: refactor parsing of socket address information
To prepare for handling more address types, refactor the parsing of
socket address information to make it more robust and extensible.
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'chardev')
-rw-r--r-- | chardev/char-socket.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1a371b91ac..a916ef4012 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1012,21 +1012,25 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, SocketAddressLegacy *addr; ChardevSocket *sock; + if ((!!path + !!host) != 1) { + error_setg(errp, + "Exactly one of 'path' or 'host' required"); + return; + } + backend->type = CHARDEV_BACKEND_KIND_SOCKET; - if (!path) { - if (!host) { - error_setg(errp, "chardev: socket: no host given"); + if (path) { + if (tls_creds) { + error_setg(errp, "TLS can only be used over TCP socket"); return; } + } else if (host) { if (!port) { error_setg(errp, "chardev: socket: no port given"); return; } } else { - if (tls_creds) { - error_setg(errp, "TLS can only be used over TCP socket"); - return; - } + g_assert_not_reached(); } sock = backend->u.socket.data = g_new0(ChardevSocket, 1); @@ -1052,7 +1056,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); q_unix->path = g_strdup(path); - } else { + } else if (host) { addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; addr->u.inet.data = g_new(InetSocketAddress, 1); *addr->u.inet.data = (InetSocketAddress) { @@ -1065,6 +1069,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, .has_ipv6 = qemu_opt_get(opts, "ipv6"), .ipv6 = qemu_opt_get_bool(opts, "ipv6", 0), }; + } else { + g_assert_not_reached(); } sock->addr = addr; } |