summaryrefslogtreecommitdiff
path: root/net/socket.c
diff options
context:
space:
mode:
authorAlexey Kirillov <lekiravi@yandex-team.ru>2021-03-03 12:59:08 +0300
committerJason Wang <jasowang@redhat.com>2021-03-15 16:41:22 +0800
commit59b5437eb732d6b103a9bc279c3482c834d1eff9 (patch)
tree9f0667074f09bf4fe8f7ac904a030e72189d9774 /net/socket.c
parent3c3b656885473ef0d699290ba966177f17839aa5 (diff)
net: Move NetClientState.info_str to dynamic allocations
The info_str field of the NetClientState structure is static and has a size of 256 bytes. This amount is often unclaimed, and the field itself is used exclusively for HMP "info network". The patch translates info_str to dynamic memory allocation. This action is also allows us to painlessly discard usage of this field for backend devices. Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/net/socket.c b/net/socket.c
index 1614523b82..98172347d7 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -180,7 +180,8 @@ static void net_socket_send(void *opaque)
s->fd = -1;
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
s->nc.link_down = true;
- memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_new0(char, 1);
return;
}
@@ -400,16 +401,16 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
stored->mcast = g_strdup(mcast);
s->dgram_dst = saddr;
- snprintf(nc->info_str, sizeof(nc->info_str),
- "socket: fd=%d (cloned mcast=%s:%d)",
- fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)",
+ fd, inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
} else {
if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) {
s->dgram_dst.sin_family = AF_UNIX;
}
- snprintf(nc->info_str, sizeof(nc->info_str),
- "socket: fd=%d %s", fd, SocketAddressType_str(sa_type));
+ nc->info_str = g_strdup_printf("socket: fd=%d %s",
+ fd, SocketAddressType_str(sa_type));
}
return s;
@@ -444,7 +445,7 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
- snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
+ nc->info_str = g_strdup_printf("socket: fd=%d", fd);
s = DO_UPCAST(NetSocketState, nc, nc);
@@ -528,9 +529,10 @@ static void net_socket_accept(void *opaque)
stored->has_fd = true;
stored->fd = g_strdup_printf("%d", fd);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: connection from %s:%d",
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: connection from %s:%d",
+ inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
}
static int net_socket_listen_init(NetClientState *peer,
@@ -645,9 +647,10 @@ static int net_socket_connect_init(NetClientState *peer,
stored->has_connect = true;
stored->connect = g_strdup(host_str);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: connect to %s:%d",
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: connect to %s:%d",
+ inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
return 0;
}
@@ -704,9 +707,10 @@ static int net_socket_mcast_init(NetClientState *peer,
stored->localaddr = g_strdup(localaddr_str);
}
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: mcast=%s:%d",
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d",
+ inet_ntoa(saddr.sin_addr),
+ ntohs(saddr.sin_port));
return 0;
}
@@ -769,9 +773,10 @@ static int net_socket_udp_init(NetClientState *peer,
stored->has_udp = true;
stored->udp = g_strdup(rhost);
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
- "socket: udp=%s:%d",
- inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
+ g_free(s->nc.info_str);
+ s->nc.info_str = g_strdup_printf("socket: udp=%s:%d",
+ inet_ntoa(raddr.sin_addr),
+ ntohs(raddr.sin_port));
return 0;
}