diff options
author | Markus Armbruster <armbru@redhat.com> | 2017-04-26 09:36:41 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-05-09 09:14:40 +0200 |
commit | bd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 (patch) | |
tree | 82ef0cd9da0812afc7021d5690c14f72e8e13177 /ui/vnc.c | |
parent | 62cf396b5d397948c5ac4d04d09596ca14f6c173 (diff) |
sockets: Limit SocketAddressLegacy to external interfaces
SocketAddressLegacy is a simple union, and simple unions are awkward:
they have their variant members wrapped in a "data" object on the
wire, and require additional indirections in C. SocketAddress is the
equivalent flat union. Convert all users of SocketAddressLegacy to
SocketAddress, except for existing external interfaces.
See also commit fce5d53..9445673 and 85a82e8..c5f1ae3.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1493192202-3184-7-git-send-email-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[Minor editing accident fixed, commit message and a comment tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'ui/vnc.c')
-rw-r--r-- | ui/vnc.c | 138 |
1 files changed, 68 insertions, 70 deletions
@@ -108,31 +108,31 @@ static void vnc_set_share_mode(VncState *vs, VncShareMode mode) } -static void vnc_init_basic_info(SocketAddressLegacy *addr, +static void vnc_init_basic_info(SocketAddress *addr, VncBasicInfo *info, Error **errp) { switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_KIND_INET: - info->host = g_strdup(addr->u.inet.data->host); - info->service = g_strdup(addr->u.inet.data->port); - if (addr->u.inet.data->ipv6) { + case SOCKET_ADDRESS_TYPE_INET: + info->host = g_strdup(addr->u.inet.host); + info->service = g_strdup(addr->u.inet.port); + if (addr->u.inet.ipv6) { info->family = NETWORK_ADDRESS_FAMILY_IPV6; } else { info->family = NETWORK_ADDRESS_FAMILY_IPV4; } break; - case SOCKET_ADDRESS_LEGACY_KIND_UNIX: + case SOCKET_ADDRESS_TYPE_UNIX: info->host = g_strdup(""); - info->service = g_strdup(addr->u.q_unix.data->path); + info->service = g_strdup(addr->u.q_unix.path); info->family = NETWORK_ADDRESS_FAMILY_UNIX; break; - case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: - case SOCKET_ADDRESS_LEGACY_KIND_FD: + case SOCKET_ADDRESS_TYPE_VSOCK: + case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressLegacyKind_lookup[addr->type]); + SocketAddressType_lookup[addr->type]); break; default: abort(); @@ -145,7 +145,7 @@ static void vnc_init_basic_info_from_server_addr(QIOChannelSocket *ioc, VncBasicInfo *info, Error **errp) { - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; if (!ioc) { error_setg(errp, "No listener socket available"); @@ -158,14 +158,14 @@ static void vnc_init_basic_info_from_server_addr(QIOChannelSocket *ioc, } vnc_init_basic_info(addr, info, errp); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } static void vnc_init_basic_info_from_remote_addr(QIOChannelSocket *ioc, VncBasicInfo *info, Error **errp) { - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; addr = qio_channel_socket_get_remote_address(ioc, errp); if (!addr) { @@ -173,7 +173,7 @@ static void vnc_init_basic_info_from_remote_addr(QIOChannelSocket *ioc, } vnc_init_basic_info(addr, info, errp); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } static const char *vnc_auth_name(VncDisplay *vd) { @@ -377,7 +377,7 @@ VncInfo *qmp_query_vnc(Error **errp) { VncInfo *info = g_malloc0(sizeof(*info)); VncDisplay *vd = vnc_display_find(NULL); - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; if (vd == NULL || !vd->nlsock) { info->enabled = false; @@ -398,26 +398,26 @@ VncInfo *qmp_query_vnc(Error **errp) } switch (addr->type) { - case SOCKET_ADDRESS_LEGACY_KIND_INET: - info->host = g_strdup(addr->u.inet.data->host); - info->service = g_strdup(addr->u.inet.data->port); - if (addr->u.inet.data->ipv6) { + case SOCKET_ADDRESS_TYPE_INET: + info->host = g_strdup(addr->u.inet.host); + info->service = g_strdup(addr->u.inet.port); + if (addr->u.inet.ipv6) { info->family = NETWORK_ADDRESS_FAMILY_IPV6; } else { info->family = NETWORK_ADDRESS_FAMILY_IPV4; } break; - case SOCKET_ADDRESS_LEGACY_KIND_UNIX: + case SOCKET_ADDRESS_TYPE_UNIX: info->host = g_strdup(""); - info->service = g_strdup(addr->u.q_unix.data->path); + info->service = g_strdup(addr->u.q_unix.path); info->family = NETWORK_ADDRESS_FAMILY_UNIX; break; - case SOCKET_ADDRESS_LEGACY_KIND_VSOCK: - case SOCKET_ADDRESS_LEGACY_KIND_FD: + case SOCKET_ADDRESS_TYPE_VSOCK: + case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressLegacyKind_lookup[addr->type]); + SocketAddressType_lookup[addr->type]); goto out_error; default: abort(); @@ -431,11 +431,11 @@ VncInfo *qmp_query_vnc(Error **errp) info->auth = g_strdup(vnc_auth_name(vd)); } - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); return info; out_error: - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); qapi_free_VncInfo(info); return NULL; } @@ -455,7 +455,7 @@ static VncServerInfo2List *qmp_query_server_entry(QIOChannelSocket *ioc, VncServerInfo2List *list; VncServerInfo2 *info; Error *err = NULL; - SocketAddressLegacy *addr; + SocketAddress *addr; addr = qio_channel_socket_get_local_address(ioc, &err); if (!addr) { @@ -465,7 +465,7 @@ static VncServerInfo2List *qmp_query_server_entry(QIOChannelSocket *ioc, info = g_new0(VncServerInfo2, 1); vnc_init_basic_info(addr, qapi_VncServerInfo2_base(info), &err); - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); if (err) { qapi_free_VncServerInfo2(info); error_free(err); @@ -3149,7 +3149,7 @@ int vnc_display_pw_expire(const char *id, time_t expires) static void vnc_display_print_local_addr(VncDisplay *vd) { - SocketAddressLegacy *addr; + SocketAddress *addr; Error *err = NULL; if (!vd->nlsock) { @@ -3161,14 +3161,14 @@ static void vnc_display_print_local_addr(VncDisplay *vd) return; } - if (addr->type != SOCKET_ADDRESS_LEGACY_KIND_INET) { - qapi_free_SocketAddressLegacy(addr); + if (addr->type != SOCKET_ADDRESS_TYPE_INET) { + qapi_free_SocketAddress(addr); return; } error_printf_unless_qmp("VNC server running on %s:%s\n", - addr->u.inet.data->host, - addr->u.inet.data->port); - qapi_free_SocketAddressLegacy(addr); + addr->u.inet.host, + addr->u.inet.port); + qapi_free_SocketAddress(addr); } static QemuOptsList qemu_vnc_opts = { @@ -3414,18 +3414,17 @@ static int vnc_display_get_address(const char *addrstr, bool has_ipv6, bool ipv4, bool ipv6, - SocketAddressLegacy **retaddr, + SocketAddress **retaddr, Error **errp) { int ret = -1; - SocketAddressLegacy *addr = NULL; + SocketAddress *addr = NULL; - addr = g_new0(SocketAddressLegacy, 1); + addr = g_new0(SocketAddress, 1); if (strncmp(addrstr, "unix:", 5) == 0) { - addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; - addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); - addr->u.q_unix.data->path = g_strdup(addrstr + 5); + addr->type = SOCKET_ADDRESS_TYPE_UNIX; + addr->u.q_unix.path = g_strdup(addrstr + 5); if (websocket) { error_setg(errp, "UNIX sockets not supported with websock"); @@ -3461,8 +3460,8 @@ static int vnc_display_get_address(const char *addrstr, } } - addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; - inet = addr->u.inet.data = g_new0(InetSocketAddress, 1); + addr->type = SOCKET_ADDRESS_TYPE_INET; + inet = &addr->u.inet; if (addrstr[0] == '[' && addrstr[hostlen - 1] == ']') { inet->host = g_strndup(addrstr + 1, hostlen - 2); } else { @@ -3518,21 +3517,21 @@ static int vnc_display_get_address(const char *addrstr, cleanup: if (ret < 0) { - qapi_free_SocketAddressLegacy(addr); + qapi_free_SocketAddress(addr); } return ret; } static int vnc_display_get_addresses(QemuOpts *opts, bool reverse, - SocketAddressLegacy ***retsaddr, + SocketAddress ***retsaddr, size_t *retnsaddr, - SocketAddressLegacy ***retwsaddr, + SocketAddress ***retwsaddr, size_t *retnwsaddr, Error **errp) { - SocketAddressLegacy *saddr = NULL; - SocketAddressLegacy *wsaddr = NULL; + SocketAddress *saddr = NULL; + SocketAddress *wsaddr = NULL; QemuOptsIter addriter; const char *addr; int to = qemu_opt_get_number(opts, "to", 0); @@ -3577,7 +3576,7 @@ static int vnc_display_get_addresses(QemuOpts *opts, if (displaynum == -1) { displaynum = rv; } - *retsaddr = g_renew(SocketAddressLegacy *, *retsaddr, *retnsaddr + 1); + *retsaddr = g_renew(SocketAddress *, *retsaddr, *retnsaddr + 1); (*retsaddr)[(*retnsaddr)++] = saddr; } @@ -3601,16 +3600,15 @@ static int vnc_display_get_addresses(QemuOpts *opts, * address for websocket too */ if (*retnsaddr == 1 && - (*retsaddr)[0]->type == SOCKET_ADDRESS_LEGACY_KIND_INET && - wsaddr->type == SOCKET_ADDRESS_LEGACY_KIND_INET && - g_str_equal(wsaddr->u.inet.data->host, "") && - !g_str_equal((*retsaddr)[0]->u.inet.data->host, "")) { - g_free(wsaddr->u.inet.data->host); - wsaddr->u.inet.data->host = - g_strdup((*retsaddr)[0]->u.inet.data->host); + (*retsaddr)[0]->type == SOCKET_ADDRESS_TYPE_INET && + wsaddr->type == SOCKET_ADDRESS_TYPE_INET && + g_str_equal(wsaddr->u.inet.host, "") && + !g_str_equal((*retsaddr)[0]->u.inet.host, "")) { + g_free(wsaddr->u.inet.host); + wsaddr->u.inet.host = g_strdup((*retsaddr)[0]->u.inet.host); } - *retwsaddr = g_renew(SocketAddressLegacy *, *retwsaddr, *retnwsaddr + 1); + *retwsaddr = g_renew(SocketAddress *, *retwsaddr, *retnwsaddr + 1); (*retwsaddr)[(*retnwsaddr)++] = wsaddr; } @@ -3618,11 +3616,11 @@ static int vnc_display_get_addresses(QemuOpts *opts, cleanup: if (ret < 0) { for (i = 0; i < *retnsaddr; i++) { - qapi_free_SocketAddressLegacy((*retsaddr)[i]); + qapi_free_SocketAddress((*retsaddr)[i]); } g_free(*retsaddr); for (i = 0; i < *retnwsaddr; i++) { - qapi_free_SocketAddressLegacy((*retwsaddr)[i]); + qapi_free_SocketAddress((*retwsaddr)[i]); } g_free(*retwsaddr); *retsaddr = *retwsaddr = NULL; @@ -3632,9 +3630,9 @@ static int vnc_display_get_addresses(QemuOpts *opts, } static int vnc_display_connect(VncDisplay *vd, - SocketAddressLegacy **saddr, + SocketAddress **saddr, size_t nsaddr, - SocketAddressLegacy **wsaddr, + SocketAddress **wsaddr, size_t nwsaddr, Error **errp) { @@ -3648,8 +3646,8 @@ static int vnc_display_connect(VncDisplay *vd, error_setg(errp, "Expected a single address in reverse mode"); return -1; } - /* TODO SOCKET_ADDRESS_LEGACY_KIND_FD when fd has AF_UNIX */ - vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_LEGACY_KIND_UNIX; + /* TODO SOCKET_ADDRESS_TYPE_FD when fd has AF_UNIX */ + vd->is_unix = saddr[0]->type == SOCKET_ADDRESS_TYPE_UNIX; sioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(sioc), "vnc-reverse"); if (qio_channel_socket_connect_sync(sioc, saddr[0], errp) < 0) { @@ -3662,7 +3660,7 @@ static int vnc_display_connect(VncDisplay *vd, static int vnc_display_listen_addr(VncDisplay *vd, - SocketAddressLegacy *addr, + SocketAddress *addr, const char *name, QIOChannelSocket ***lsock, guint **lsock_tag, @@ -3670,7 +3668,7 @@ static int vnc_display_listen_addr(VncDisplay *vd, Error **errp) { QIODNSResolver *resolver = qio_dns_resolver_get_instance(); - SocketAddressLegacy **rawaddrs = NULL; + SocketAddress **rawaddrs = NULL; size_t nrawaddrs = 0; Error *listenerr = NULL; bool listening = false; @@ -3700,7 +3698,7 @@ static int vnc_display_listen_addr(VncDisplay *vd, } for (i = 0; i < nrawaddrs; i++) { - qapi_free_SocketAddressLegacy(rawaddrs[i]); + qapi_free_SocketAddress(rawaddrs[i]); } g_free(rawaddrs); @@ -3724,9 +3722,9 @@ static int vnc_display_listen_addr(VncDisplay *vd, static int vnc_display_listen(VncDisplay *vd, - SocketAddressLegacy **saddr, + SocketAddress **saddr, size_t nsaddr, - SocketAddressLegacy **wsaddr, + SocketAddress **wsaddr, size_t nwsaddr, Error **errp) { @@ -3761,7 +3759,7 @@ void vnc_display_open(const char *id, Error **errp) { VncDisplay *vd = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id); - SocketAddressLegacy **saddr = NULL, **wsaddr = NULL; + SocketAddress **saddr = NULL, **wsaddr = NULL; size_t nsaddr, nwsaddr; const char *share, *device_id; QemuConsole *con; @@ -3997,10 +3995,10 @@ void vnc_display_open(const char *id, Error **errp) cleanup: for (i = 0; i < nsaddr; i++) { - qapi_free_SocketAddressLegacy(saddr[i]); + qapi_free_SocketAddress(saddr[i]); } for (i = 0; i < nwsaddr; i++) { - qapi_free_SocketAddressLegacy(wsaddr[i]); + qapi_free_SocketAddress(wsaddr[i]); } return; |