aboutsummaryrefslogtreecommitdiff
path: root/migration/socket.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-04-26 09:36:41 +0200
committerMarkus Armbruster <armbru@redhat.com>2017-05-09 09:14:40 +0200
commitbd269ebc82fbaa5fe7ce5bc7c1770ac8acecd884 (patch)
tree82ef0cd9da0812afc7021d5690c14f72e8e13177 /migration/socket.c
parent62cf396b5d397948c5ac4d04d09596ca14f6c173 (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 'migration/socket.c')
-rw-r--r--migration/socket.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/migration/socket.c b/migration/socket.c
index 32032764a0..1cfbe81e69 100644
--- a/migration/socket.c
+++ b/migration/socket.c
@@ -25,32 +25,29 @@
#include "trace.h"
-static SocketAddressLegacy *tcp_build_address(const char *host_port, Error **errp)
+static SocketAddress *tcp_build_address(const char *host_port, Error **errp)
{
- InetSocketAddress *iaddr = g_new(InetSocketAddress, 1);
- SocketAddressLegacy *saddr;
+ SocketAddress *saddr;
- if (inet_parse(iaddr, host_port, errp)) {
- qapi_free_InetSocketAddress(iaddr);
+ saddr = g_new0(SocketAddress, 1);
+ saddr->type = SOCKET_ADDRESS_TYPE_INET;
+
+ if (inet_parse(&saddr->u.inet, host_port, errp)) {
+ qapi_free_SocketAddress(saddr);
return NULL;
}
- saddr = g_new0(SocketAddressLegacy, 1);
- saddr->type = SOCKET_ADDRESS_LEGACY_KIND_INET;
- saddr->u.inet.data = iaddr;
-
return saddr;
}
-static SocketAddressLegacy *unix_build_address(const char *path)
+static SocketAddress *unix_build_address(const char *path)
{
- SocketAddressLegacy *saddr;
+ SocketAddress *saddr;
- saddr = g_new0(SocketAddressLegacy, 1);
- saddr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX;
- saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1);
- saddr->u.q_unix.data->path = g_strdup(path);
+ saddr = g_new0(SocketAddress, 1);
+ saddr->type = SOCKET_ADDRESS_TYPE_UNIX;
+ saddr->u.q_unix.path = g_strdup(path);
return saddr;
}
@@ -90,15 +87,15 @@ static void socket_outgoing_migration(QIOTask *task,
}
static void socket_start_outgoing_migration(MigrationState *s,
- SocketAddressLegacy *saddr,
+ SocketAddress *saddr,
Error **errp)
{
QIOChannelSocket *sioc = qio_channel_socket_new();
struct SocketConnectData *data = g_new0(struct SocketConnectData, 1);
data->s = s;
- if (saddr->type == SOCKET_ADDRESS_LEGACY_KIND_INET) {
- data->hostname = g_strdup(saddr->u.inet.data->host);
+ if (saddr->type == SOCKET_ADDRESS_TYPE_INET) {
+ data->hostname = g_strdup(saddr->u.inet.host);
}
qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-outgoing");
@@ -107,7 +104,7 @@ static void socket_start_outgoing_migration(MigrationState *s,
socket_outgoing_migration,
data,
socket_connect_data_free);
- qapi_free_SocketAddressLegacy(saddr);
+ qapi_free_SocketAddress(saddr);
}
void tcp_start_outgoing_migration(MigrationState *s,
@@ -115,7 +112,7 @@ void tcp_start_outgoing_migration(MigrationState *s,
Error **errp)
{
Error *err = NULL;
- SocketAddressLegacy *saddr = tcp_build_address(host_port, &err);
+ SocketAddress *saddr = tcp_build_address(host_port, &err);
if (!err) {
socket_start_outgoing_migration(s, saddr, &err);
}
@@ -126,7 +123,7 @@ void unix_start_outgoing_migration(MigrationState *s,
const char *path,
Error **errp)
{
- SocketAddressLegacy *saddr = unix_build_address(path);
+ SocketAddress *saddr = unix_build_address(path);
socket_start_outgoing_migration(s, saddr, errp);
}
@@ -160,7 +157,7 @@ out:
}
-static void socket_start_incoming_migration(SocketAddressLegacy *saddr,
+static void socket_start_incoming_migration(SocketAddress *saddr,
Error **errp)
{
QIOChannelSocket *listen_ioc = qio_channel_socket_new();
@@ -170,7 +167,7 @@ static void socket_start_incoming_migration(SocketAddressLegacy *saddr,
if (qio_channel_socket_listen_sync(listen_ioc, saddr, errp) < 0) {
object_unref(OBJECT(listen_ioc));
- qapi_free_SocketAddressLegacy(saddr);
+ qapi_free_SocketAddress(saddr);
return;
}
@@ -179,13 +176,13 @@ static void socket_start_incoming_migration(SocketAddressLegacy *saddr,
socket_accept_incoming_migration,
listen_ioc,
(GDestroyNotify)object_unref);
- qapi_free_SocketAddressLegacy(saddr);
+ qapi_free_SocketAddress(saddr);
}
void tcp_start_incoming_migration(const char *host_port, Error **errp)
{
Error *err = NULL;
- SocketAddressLegacy *saddr = tcp_build_address(host_port, &err);
+ SocketAddress *saddr = tcp_build_address(host_port, &err);
if (!err) {
socket_start_incoming_migration(saddr, &err);
}
@@ -194,6 +191,6 @@ void tcp_start_incoming_migration(const char *host_port, Error **errp)
void unix_start_incoming_migration(const char *path, Error **errp)
{
- SocketAddressLegacy *saddr = unix_build_address(path);
+ SocketAddress *saddr = unix_build_address(path);
socket_start_incoming_migration(saddr, errp);
}