Commit bd269ebc authored by Markus Armbruster's avatar Markus Armbruster

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 fce5d538..9445673e and 85a82e85..c5f1ae3a.
Signed-off-by: 's avatarMarkus Armbruster <armbru@redhat.com>
Message-Id: <1493192202-3184-7-git-send-email-armbru@redhat.com>
Reviewed-by: 's avatarEric Blake <eblake@redhat.com>
[Minor editing accident fixed, commit message and a comment tweaked]
Signed-off-by: 's avatarMarkus Armbruster <armbru@redhat.com>
parent 62cf396b
......@@ -306,10 +306,9 @@ NBDClientSession *nbd_get_client_session(BlockDriverState *bs)
return &s->client;
}
static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr_flat,
static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr,
Error **errp)
{
SocketAddressLegacy *saddr = socket_address_crumple(saddr_flat);
QIOChannelSocket *sioc;
Error *local_err = NULL;
......@@ -319,7 +318,6 @@ static QIOChannelSocket *nbd_establish_connection(SocketAddress *saddr_flat,
qio_channel_socket_connect_sync(sioc,
saddr,
&local_err);
qapi_free_SocketAddressLegacy(saddr);
if (local_err) {
object_unref(OBJECT(sioc));
error_propagate(errp, local_err);
......
......@@ -378,7 +378,7 @@ struct BDRVSheepdogState {
uint32_t cache_flags;
bool discard_supported;
SocketAddressLegacy *addr;
SocketAddress *addr;
int fd;
CoMutex lock;
......@@ -530,32 +530,29 @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings);
}
static SocketAddressLegacy *sd_socket_address(const char *path,
static SocketAddress *sd_socket_address(const char *path,
const char *host, const char *port)
{
SocketAddressLegacy *addr = g_new0(SocketAddressLegacy, 1);
SocketAddress *addr = g_new0(SocketAddress, 1);
if (path) {
addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
addr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
addr->u.q_unix.data->path = g_strdup(path);
addr->type = SOCKET_ADDRESS_TYPE_UNIX;
addr->u.q_unix.path = g_strdup(path);
} else {
addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
addr->u.inet.data = g_new0(InetSocketAddress, 1);
addr->u.inet.data->host = g_strdup(host ?: SD_DEFAULT_ADDR);
addr->u.inet.data->port = g_strdup(port ?: stringify(SD_DEFAULT_PORT));
addr->type = SOCKET_ADDRESS_TYPE_INET;
addr->u.inet.host = g_strdup(host ?: SD_DEFAULT_ADDR);
addr->u.inet.port = g_strdup(port ?: stringify(SD_DEFAULT_PORT));
}
return addr;
}
static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp)
static SocketAddress *sd_server_config(QDict *options, Error **errp)
{
QDict *server = NULL;
QObject *crumpled_server = NULL;
Visitor *iv = NULL;
SocketAddress *saddr_flat = NULL;
SocketAddressLegacy *saddr = NULL;
SocketAddress *saddr = NULL;
Error *local_err = NULL;
qdict_extract_subqdict(options, &server, "server.");
......@@ -574,16 +571,13 @@ static SocketAddressLegacy *sd_server_config(QDict *options, Error **errp)
* visitor expects the former.
*/
iv = qobject_input_visitor_new(crumpled_server);
visit_type_SocketAddress(iv, NULL, &saddr_flat, &local_err);
visit_type_SocketAddress(iv, NULL, &saddr, &local_err);
if (local_err) {
error_propagate(errp, local_err);
goto done;
}
saddr = socket_address_crumple(saddr_flat);
done:
qapi_free_SocketAddress(saddr_flat);
visit_free(iv);
qobject_decref(crumpled_server);
QDECREF(server);
......@@ -597,7 +591,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
fd = socket_connect(s->addr, NULL, NULL, errp);
if (s->addr->type == SOCKET_ADDRESS_LEGACY_KIND_INET && fd >= 0) {
if (s->addr->type == SOCKET_ADDRESS_TYPE_INET && fd >= 0) {
int ret = socket_set_nodelay(fd);
if (ret < 0) {
error_report("%s", strerror(errno));
......@@ -2149,7 +2143,7 @@ static void sd_close(BlockDriverState *bs)
aio_set_fd_handler(bdrv_get_aio_context(bs), s->fd,
false, NULL, NULL, NULL, NULL);
closesocket(s->fd);
qapi_free_SocketAddressLegacy(s->addr);
qapi_free_SocketAddress(s->addr);
}
static int64_t sd_getlength(BlockDriverState *bs)
......
......@@ -99,9 +99,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp)
}
void qmp_nbd_server_start(SocketAddressLegacy *addr,
bool has_tls_creds, const char *tls_creds,
Error **errp)
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
Error **errp)
{
if (nbd_server) {
error_setg(errp, "NBD server already running");
......@@ -118,14 +117,14 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
goto error;
}
if (has_tls_creds) {
if (tls_creds) {
nbd_server->tlscreds = nbd_get_tls_creds(tls_creds, errp);
if (!nbd_server->tlscreds) {
goto error;
}
/* TODO SOCKET_ADDRESS_LEGACY_KIND_FD where fd has AF_INET or AF_INET6 */
if (addr->type != SOCKET_ADDRESS_LEGACY_KIND_INET) {
/* TODO SOCKET_ADDRESS_TYPE_FD where fd has AF_INET or AF_INET6 */
if (addr->type != SOCKET_ADDRESS_TYPE_INET) {
error_setg(errp, "TLS is only supported with IPv4/IPv6");
goto error;
}
......@@ -145,6 +144,16 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr,
nbd_server = NULL;
}
void qmp_nbd_server_start(SocketAddressLegacy *addr,
bool has_tls_creds, const char *tls_creds,
Error **errp)
{
SocketAddress *addr_flat = socket_address_flatten(addr);
nbd_server_start(addr_flat, tls_creds, errp);
qapi_free_SocketAddress(addr_flat);
}
void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
Error **errp)
{
......
......@@ -52,7 +52,7 @@ typedef struct {
int *write_msgfds;
size_t write_msgfds_num;
SocketAddressLegacy *addr;
SocketAddress *addr;
bool is_listen;
bool is_telnet;
bool is_tn3270;
......@@ -356,30 +356,30 @@ static void tcp_chr_free_connection(Chardev *chr)
s->connected = 0;
}
static char *SocketAddress_to_str(const char *prefix, SocketAddressLegacy *addr,
static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr,
bool is_listen, bool is_telnet)
{
switch (addr->type) {
case SOCKET_ADDRESS_LEGACY_KIND_INET:
case SOCKET_ADDRESS_TYPE_INET:
return g_strdup_printf("%s%s:%s:%s%s", prefix,
is_telnet ? "telnet" : "tcp",
addr->u.inet.data->host,
addr->u.inet.data->port,
addr->u.inet.host,
addr->u.inet.port,
is_listen ? ",server" : "");
break;
case SOCKET_ADDRESS_LEGACY_KIND_UNIX:
case SOCKET_ADDRESS_TYPE_UNIX:
return g_strdup_printf("%sunix:%s%s", prefix,
addr->u.q_unix.data->path,
addr->u.q_unix.path,
is_listen ? ",server" : "");
break;
case SOCKET_ADDRESS_LEGACY_KIND_FD:
return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.data->str,
case SOCKET_ADDRESS_TYPE_FD:
return g_strdup_printf("%sfd:%s%s", prefix, addr->u.fd.str,
is_listen ? ",server" : "");
break;
case SOCKET_ADDRESS_LEGACY_KIND_VSOCK:
case SOCKET_ADDRESS_TYPE_VSOCK:
return g_strdup_printf("%svsock:%s:%s", prefix,
addr->u.vsock.data->cid,
addr->u.vsock.data->port);
addr->u.vsock.cid,
addr->u.vsock.port);
default:
abort();
}
......@@ -648,7 +648,7 @@ static void tcp_chr_tls_init(Chardev *chr)
} else {
tioc = qio_channel_tls_new_client(
s->ioc, s->tls_creds,
s->addr->u.inet.data->host,
s->addr->u.inet.host,
&err);
}
if (tioc == NULL) {
......@@ -796,7 +796,7 @@ static void char_socket_finalize(Object *obj)
g_source_remove(s->reconnect_timer);
s->reconnect_timer = 0;
}
qapi_free_SocketAddressLegacy(s->addr);
qapi_free_SocketAddress(s->addr);
if (s->listen_tag) {
g_source_remove(s->listen_tag);
s->listen_tag = 0;
......@@ -859,7 +859,6 @@ static void qmp_chardev_open_socket(Chardev *chr,
{
SocketChardev *s = SOCKET_CHARDEV(chr);
ChardevSocket *sock = backend->u.socket.data;
SocketAddressLegacy *addr = sock->addr;
bool do_nodelay = sock->has_nodelay ? sock->nodelay : false;
bool is_listen = sock->has_server ? sock->server : true;
bool is_telnet = sock->has_telnet ? sock->telnet : false;
......@@ -867,6 +866,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
bool is_waitconnect = sock->has_wait ? sock->wait : false;
int64_t reconnect = sock->has_reconnect ? sock->reconnect : 0;
QIOChannelSocket *sioc = NULL;
SocketAddress *addr;
s->is_listen = is_listen;
s->is_telnet = is_telnet;
......@@ -905,11 +905,11 @@ static void qmp_chardev_open_socket(Chardev *chr,
}
}
s->addr = QAPI_CLONE(SocketAddressLegacy, sock->addr);
s->addr = addr = socket_address_flatten(sock->addr);
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE);
/* TODO SOCKET_ADDRESS_FD where fd has AF_UNIX */
if (addr->type == SOCKET_ADDRESS_LEGACY_KIND_UNIX) {
if (addr->type == SOCKET_ADDRESS_TYPE_UNIX) {
qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS);
}
......@@ -945,7 +945,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
goto error;
}
qapi_free_SocketAddressLegacy(s->addr);
qapi_free_SocketAddress(s->addr);
s->addr = socket_local_address(sioc->fd, errp);
update_disconnected_filename(s);
......@@ -1051,7 +1051,7 @@ char_socket_get_addr(Object *obj, Visitor *v, const char *name,
{
SocketChardev *s = SOCKET_CHARDEV(obj);
visit_type_SocketAddressLegacy(v, name, &s->addr, errp);
visit_type_SocketAddress(v, name, &s->addr, errp);
}
static bool
......@@ -1078,7 +1078,7 @@ static void char_socket_class_init(ObjectClass *oc, void *data)
cc->chr_add_watch = tcp_chr_add_watch;
cc->chr_update_read_handler = tcp_chr_update_read_handler;
object_class_property_add(oc, "addr", "SocketAddressLegacy",
object_class_property_add(oc, "addr", "SocketAddress",
char_socket_get_addr, NULL,
NULL, NULL, &error_abort);
......
......@@ -191,13 +191,17 @@ static void qmp_chardev_open_udp(Chardev *chr,
Error **errp)
{
ChardevUdp *udp = backend->u.udp.data;
SocketAddress *local_addr = socket_address_flatten(udp->local);
SocketAddress *remote_addr = socket_address_flatten(udp->remote);
QIOChannelSocket *sioc = qio_channel_socket_new();
char *name;
UdpChardev *s = UDP_CHARDEV(chr);
int ret;
if (qio_channel_socket_dgram_sync(sioc,
udp->local, udp->remote,
errp) < 0) {
ret = qio_channel_socket_dgram_sync(sioc, local_addr, remote_addr, errp);
qapi_free_SocketAddress(local_addr);
qapi_free_SocketAddress(remote_addr);
if (ret < 0) {
object_unref(OBJECT(sioc));
return;
}
......
......@@ -34,6 +34,7 @@
#include "qapi-visit.h"
#include "qom/object_interfaces.h"
#include "ui/console.h"
#include "block/nbd.h"
#include "block/qapi.h"
#include "qemu-io.h"
#include "qemu/cutils.h"
......@@ -2108,7 +2109,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
bool all = qdict_get_try_bool(qdict, "all", false);
Error *local_err = NULL;
BlockInfoList *block_list, *info;
SocketAddressLegacy *addr;
SocketAddress *addr;
if (writable && !all) {
error_setg(&local_err, "-w only valid together with -a");
......@@ -2121,8 +2122,8 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
goto exit;
}
qmp_nbd_server_start(addr, false, NULL, &local_err);
qapi_free_SocketAddressLegacy(addr);
nbd_server_start(addr, NULL, &local_err);
qapi_free_SocketAddress(addr);
if (local_err != NULL) {
goto exit;
}
......
......@@ -164,4 +164,7 @@ void nbd_client_new(NBDExport *exp,
void nbd_client_get(NBDClient *client);
void nbd_client_put(NBDClient *client);
void nbd_server_start(SocketAddress *addr, const char *tls_creds,
Error **errp);
#endif
......@@ -91,7 +91,7 @@ qio_channel_socket_new_fd(int fd,
* an error occurs.
*/
int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
Error **errp);
/**
......@@ -110,7 +110,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
* as this function returns without waiting for completion.
*/
void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
QIOTaskFunc callback,
gpointer opaque,
GDestroyNotify destroy);
......@@ -128,7 +128,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
* an error occurs.
*/
int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
Error **errp);
/**
......@@ -147,7 +147,7 @@ int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
* as this function returns without waiting for completion.
*/
void qio_channel_socket_listen_async(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
QIOTaskFunc callback,
gpointer opaque,
GDestroyNotify destroy);
......@@ -167,8 +167,8 @@ void qio_channel_socket_listen_async(QIOChannelSocket *ioc,
* is established or an error occurs.
*/
int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc,
SocketAddressLegacy *localAddr,
SocketAddressLegacy *remoteAddr,
SocketAddress *localAddr,
SocketAddress *remoteAddr,
Error **errp);
/**
......@@ -190,8 +190,8 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc,
* waiting for completion.
*/
void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
SocketAddressLegacy *localAddr,
SocketAddressLegacy *remoteAddr,
SocketAddress *localAddr,
SocketAddress *remoteAddr,
QIOTaskFunc callback,
gpointer opaque,
GDestroyNotify destroy);
......@@ -205,12 +205,12 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
* Get the string representation of the local socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
* release with a call qapi_free_SocketAddressLegacy() when no
* release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: 0 on success, -1 on error
*/
SocketAddressLegacy *
SocketAddress *
qio_channel_socket_get_local_address(QIOChannelSocket *ioc,
Error **errp);
......@@ -222,12 +222,12 @@ qio_channel_socket_get_local_address(QIOChannelSocket *ioc,
* Get the string representation of the local socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
* release with a call qapi_free_SocketAddressLegacy() when no
* release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
*/
SocketAddressLegacy *
SocketAddress *
qio_channel_socket_get_remote_address(QIOChannelSocket *ioc,
Error **errp);
......
......@@ -40,15 +40,15 @@ typedef struct QIODNSResolverClass QIODNSResolverClass;
* QIODNSResolver:
*
* The QIODNSResolver class provides a framework for doing
* DNS resolution on SocketAddressLegacy objects, independently
* DNS resolution on SocketAddress objects, independently
* of socket creation.
*
* <example>
* <title>Resolving addresses synchronously</title>
* <programlisting>
* int mylisten(SocketAddressLegacy *addr, Error **errp) {
* int mylisten(SocketAddress *addr, Error **errp) {
* QIODNSResolver *resolver = qio_dns_resolver_get_instance();
* SocketAddressLegacy **rawaddrs = NULL;
* SocketAddress **rawaddrs = NULL;
* size_t nrawaddrs = 0;
* Error *err = NULL;
* QIOChannel **socks = NULL;
......@@ -69,7 +69,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass;
* socks = g_renew(QIOChannelSocket *, socks, nsocks + 1);
* socks[nsocks++] = sock;
* }
* qapi_free_SocketAddressLegacy(rawaddrs[i]);
* qapi_free_SocketAddress(rawaddrs[i]);
* }
* g_free(rawaddrs);
*
......@@ -95,7 +95,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass;
* MyListenData *data = opaque;
* QIODNSResolver *resolver =
* QIO_DNS_RESOLVER(qio_task_get_source(task);
* SocketAddressLegacy **rawaddrs = NULL;
* SocketAddress **rawaddrs = NULL;
* size_t nrawaddrs = 0;
* Error *err = NULL;
*
......@@ -116,7 +116,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass;
* socks = g_renew(QIOChannelSocket *, socks, nsocks + 1);
* socks[nsocks++] = sock;
* }
* qapi_free_SocketAddressLegacy(rawaddrs[i]);
* qapi_free_SocketAddress(rawaddrs[i]);
* }
* g_free(rawaddrs);
*
......@@ -127,7 +127,7 @@ typedef struct QIODNSResolverClass QIODNSResolverClass;
* }
* }
*
* void mylisten(SocketAddressLegacy *addr, MyListenData *data) {
* void mylisten(SocketAddress *addr, MyListenData *data) {
* QIODNSResolver *resolver = qio_dns_resolver_get_instance();
* qio_dns_resolver_lookup_async(dns, addr,
* mylistenresult, data, NULL);
......@@ -177,9 +177,9 @@ QIODNSResolver *qio_dns_resolver_get_instance(void);
* Returns: 0 if resolution was successful, -1 on error
*/
int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver,
SocketAddressLegacy *addr,
SocketAddress *addr,
size_t *naddrs,
SocketAddressLegacy ***addrs,
SocketAddress ***addrs,
Error **errp);
/**
......@@ -201,7 +201,7 @@ int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver,
* of the caller will not be blocked.
*/
void qio_dns_resolver_lookup_async(QIODNSResolver *resolver,
SocketAddressLegacy *addr,
SocketAddress *addr,
QIOTaskFunc func,
gpointer opaque,
GDestroyNotify notify);
......@@ -223,6 +223,6 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver,
void qio_dns_resolver_lookup_result(QIODNSResolver *resolver,
QIOTask *task,
size_t *naddrs,
SocketAddressLegacy ***addrs);
SocketAddress ***addrs);
#endif /* QIO_DNS_RESOLVER_H */
......@@ -166,7 +166,7 @@ typedef void (*QIOTaskWorker)(QIOTask *task,
* gpointer opaque)
* {
* QMyObject obj = QMY_OBJECT(qio_task_get_source(task));
* SocketAddressLegacy *addr = opaque;
* SocketAddress *addr = opaque;
* Error *err = NULL;
*
* obj->fd = socket_listen(addr, &err);
......@@ -175,20 +175,20 @@ typedef void (*QIOTaskWorker)(QIOTask *task,
* }
*
* void myobject_listen_async(QMyObject *obj,
* SocketAddressLegacy *addr,
* SocketAddress *addr,
* QIOTaskFunc *func,
* gpointer opaque,
* GDestroyNotify notify)
* {
* QIOTask *task;
* SocketAddressLegacy *addrCopy;
* SocketAddress *addrCopy;
*
* addrCopy = QAPI_CLONE(SocketAddressLegacy, addr);
* addrCopy = QAPI_CLONE(SocketAddress, addr);
* task = qio_task_new(OBJECT(obj), func, opaque, notify);
*
* qio_task_run_in_thread(task, myobject_listen_worker,
* addrCopy,
* qapi_free_SocketAddressLegacy);
* qapi_free_SocketAddress);
* }
* </example>
*
......
......@@ -45,12 +45,12 @@ NetworkAddressFamily inet_netfamily(int family);
int unix_listen(const char *path, char *ostr, int olen, Error **errp);
int unix_connect(const char *path, Error **errp);
SocketAddressLegacy *socket_parse(const char *str, Error **errp);
int socket_connect(SocketAddressLegacy *addr, NonBlockingConnectHandler *callback,
SocketAddress *socket_parse(const char *str, Error **errp);
int socket_connect(SocketAddress *addr, NonBlockingConnectHandler *callback,
void *opaque, Error **errp);
int socket_listen(SocketAddressLegacy *addr, Error **errp);
int socket_listen(SocketAddress *addr, Error **errp);
void socket_listen_cleanup(int fd, Error **errp);
int socket_dgram(SocketAddressLegacy *remote, SocketAddressLegacy *local, Error **errp);
int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
/* Old, ipv4 only bits. Don't use for new code. */
int parse_host_port(struct sockaddr_in *saddr, const char *str);
......@@ -65,12 +65,12 @@ int socket_init(void);
* Get the string representation of the socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
* release with a call qapi_free_SocketAddressLegacy() when no
* release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
*/
SocketAddressLegacy *
SocketAddress *
socket_sockaddr_to_address(struct sockaddr_storage *sa,
socklen_t salen,
Error **errp);
......@@ -83,12 +83,12 @@ socket_sockaddr_to_address(struct sockaddr_storage *sa,
* Get the string representation of the local socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
* release with a call qapi_free_SocketAddressLegacy() when no
* release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
*/
SocketAddressLegacy *socket_local_address(int fd, Error **errp);
SocketAddress *socket_local_address(int fd, Error **errp);
/**
* socket_remote_address:
......@@ -98,12 +98,12 @@ SocketAddressLegacy *socket_local_address(int fd, Error **errp);
* Get the string representation of the remote socket
* address. A pointer to the allocated address information
* struct will be returned, which the caller is required to
* release with a call qapi_free_SocketAddressLegacy() when no
* release with a call qapi_free_SocketAddress() when no
* longer required.
*
* Returns: the socket address struct, or NULL on error
*/
SocketAddressLegacy *socket_remote_address(int fd, Error **errp);
SocketAddress *socket_remote_address(int fd, Error **errp);
/**
* socket_address_to_string:
......@@ -118,7 +118,7 @@ SocketAddressLegacy *socket_remote_address(int fd, Error **errp);
*
* Returns: the socket address in string format, or NULL on error
*/
char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp);
char *socket_address_to_string(struct SocketAddress *addr, Error **errp);
/**
* socket_address_crumple:
......@@ -131,4 +131,15 @@ char *socket_address_to_string(struct SocketAddressLegacy *addr, Error **errp);
*/
SocketAddressLegacy *socket_address_crumple(SocketAddress *addr);
/**
* socket_address_flatten:
* @addr: the socket address to flatten
*
* Convert SocketAddressLegacy to SocketAddress. Caller is responsible
* for freeing with qapi_free_SocketAddress().
*
* Returns: the argument converted to SocketAddress.
*/
SocketAddress *socket_address_flatten(SocketAddressLegacy *addr);
#endif /* QEMU_SOCKETS_H */
......@@ -27,7 +27,7 @@
#define SOCKET_MAX_FDS 16
SocketAddressLegacy *
SocketAddress *
qio_channel_socket_get_local_address(QIOChannelSocket *ioc,
Error **errp)
{
......@@ -36,7 +36,7 @@ qio_channel_socket_get_local_address(QIOChannelSocket *ioc,
errp);
}
SocketAddressLegacy *
SocketAddress *
qio_channel_socket_get_remote_address(QIOChannelSocket *ioc,
Error **errp)
{
......@@ -134,7 +134,7 @@ qio_channel_socket_new_fd(int fd,
int qio_channel_socket_connect_sync(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
Error **errp)
{
int fd;
......@@ -160,7 +160,7 @@ static void qio_channel_socket_connect_worker(QIOTask *task,
gpointer opaque)
{
QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
SocketAddressLegacy *addr = opaque;
SocketAddress *addr = opaque;
Error *err = NULL;
qio_channel_socket_connect_sync(ioc, addr, &err);
......@@ -170,16 +170,16 @@ static void qio_channel_socket_connect_worker(QIOTask *task,
void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
QIOTaskFunc callback,
gpointer opaque,
GDestroyNotify destroy)
{
QIOTask *task = qio_task_new(
OBJECT(ioc), callback, opaque, destroy);
SocketAddressLegacy *addrCopy;
SocketAddress *addrCopy;
addrCopy = QAPI_CLONE(SocketAddressLegacy, addr);
addrCopy = QAPI_CLONE(SocketAddress, addr);
/* socket_connect() does a non-blocking connect(), but it
* still blocks in DNS lookups, so we must use a thread */
......@@ -187,12 +187,12 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
qio_task_run_in_thread(task,
qio_channel_socket_connect_worker,
addrCopy,
(GDestroyNotify)qapi_free_SocketAddressLegacy);
(GDestroyNotify)qapi_free_SocketAddress);
}
int qio_channel_socket_listen_sync(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
Error **errp)
{
int fd;
......@@ -219,7 +219,7 @@ static void qio_channel_socket_listen_worker(QIOTask *task,
gpointer opaque)
{
QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
SocketAddressLegacy *addr = opaque;
SocketAddress *addr = opaque;
Error *err = NULL;
qio_channel_socket_listen_sync(ioc, addr, &err);
......@@ -229,29 +229,29 @@ static void qio_channel_socket_listen_worker(QIOTask *task,
void qio_channel_socket_listen_async(QIOChannelSocket *ioc,
SocketAddressLegacy *addr,
SocketAddress *addr,
QIOTaskFunc callback,
gpointer opaque,
GDestroyNotify destroy)
{
QIOTask *task = qio_task_new(
OBJECT(ioc), callback, opaque, destroy);
SocketAddressLegacy *addrCopy;
SocketAddress *addrCopy;
addrCopy = QAPI_CLONE(SocketAddressLegacy, addr);
addrCopy = QAPI_CLONE(SocketAddress, addr);
/* socket_listen() blocks in DNS lookups, so we must use a thread */
trace_qio_channel_socket_listen_async(ioc, addr);
qio_task_run_in_thread(task,
qio_channel_socket_listen_worker,
addrCopy,
(GDestroyNotify)qapi_free_SocketAddressLegacy);
(GDestroyNotify)qapi_free_SocketAddress);
}
int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc,
SocketAddressLegacy *localAddr,
SocketAddressLegacy *remoteAddr,
SocketAddress *localAddr,
SocketAddress *remoteAddr,
Error **errp)
{
int fd;
......@@ -274,16 +274,16 @@ int qio_channel_socket_dgram_sync(QIOChannelSocket *ioc,
struct QIOChannelSocketDGramWorkerData {
SocketAddressLegacy *localAddr;
SocketAddressLegacy *remoteAddr;
SocketAddress *localAddr;
SocketAddress *remoteAddr;
};
static void qio_channel_socket_dgram_worker_free(gpointer opaque)
{
struct QIOChannelSocketDGramWorkerData *data = opaque;
qapi_free_SocketAddressLegacy(data->localAddr);