mirror of
https://github.com/qemu/qemu.git
synced 2024-11-24 03:13:44 +08:00
slirp: remove Monitor dependency, return a string for info
There is nothing performance-sensitive in returning an allocated string for info, and handling the monitor_printf() on the caller side. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
parent
634d03487b
commit
b7f43bf2f6
@ -828,10 +828,11 @@ void hmp_info_usernet(Monitor *mon, const QDict *qdict)
|
||||
QTAILQ_FOREACH(s, &slirp_stacks, entry) {
|
||||
int id;
|
||||
bool got_hub_id = net_hub_id_for_client(&s->nc, &id) == 0;
|
||||
monitor_printf(mon, "Hub %d (%s):\n",
|
||||
char *info = slirp_connection_info(s->slirp);
|
||||
monitor_printf(mon, "Hub %d (%s):\n%s",
|
||||
got_hub_id ? id : -1,
|
||||
s->nc.name);
|
||||
slirp_connection_info(s->slirp, mon);
|
||||
s->nc.name, info);
|
||||
g_free(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
|
||||
int slirp_add_exec(Slirp *slirp, void *chardev, const char *cmdline,
|
||||
struct in_addr *guest_addr, int guest_port);
|
||||
|
||||
void slirp_connection_info(Slirp *slirp, Monitor *mon);
|
||||
char *slirp_connection_info(Slirp *slirp);
|
||||
|
||||
void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
|
||||
int guest_port, const uint8_t *buf, int size);
|
||||
|
23
slirp/misc.c
23
slirp/misc.c
@ -8,7 +8,6 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "slirp.h"
|
||||
#include "libslirp.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
|
||||
@ -198,8 +197,9 @@ fork_exec(struct socket *so, const char *ex)
|
||||
}
|
||||
#endif
|
||||
|
||||
void slirp_connection_info(Slirp *slirp, Monitor *mon)
|
||||
char *slirp_connection_info(Slirp *slirp)
|
||||
{
|
||||
GString *str = g_string_new(NULL);
|
||||
const char * const tcpstates[] = {
|
||||
[TCPS_CLOSED] = "CLOSED",
|
||||
[TCPS_LISTEN] = "LISTEN",
|
||||
@ -221,8 +221,9 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon)
|
||||
const char *state;
|
||||
char buf[20];
|
||||
|
||||
monitor_printf(mon, " Protocol[State] FD Source Address Port "
|
||||
"Dest. Address Port RecvQ SendQ\n");
|
||||
g_string_append_printf(str,
|
||||
" Protocol[State] FD Source Address Port "
|
||||
"Dest. Address Port RecvQ SendQ\n");
|
||||
|
||||
for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) {
|
||||
if (so->so_state & SS_HOSTFWD) {
|
||||
@ -244,10 +245,10 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon)
|
||||
dst_port = so->so_fport;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), " TCP[%s]", state);
|
||||
monitor_printf(mon, "%-19s %3d %15s %5d ", buf, so->s,
|
||||
g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s,
|
||||
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
|
||||
ntohs(src.sin_port));
|
||||
monitor_printf(mon, "%15s %5d %5d %5d\n",
|
||||
g_string_append_printf(str, "%15s %5d %5d %5d\n",
|
||||
inet_ntoa(dst_addr), ntohs(dst_port),
|
||||
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
||||
}
|
||||
@ -267,10 +268,10 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon)
|
||||
dst_addr = so->so_faddr;
|
||||
dst_port = so->so_fport;
|
||||
}
|
||||
monitor_printf(mon, "%-19s %3d %15s %5d ", buf, so->s,
|
||||
g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s,
|
||||
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*",
|
||||
ntohs(src.sin_port));
|
||||
monitor_printf(mon, "%15s %5d %5d %5d\n",
|
||||
g_string_append_printf(str, "%15s %5d %5d %5d\n",
|
||||
inet_ntoa(dst_addr), ntohs(dst_port),
|
||||
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
||||
}
|
||||
@ -280,9 +281,11 @@ void slirp_connection_info(Slirp *slirp, Monitor *mon)
|
||||
(so->so_expire - curtime) / 1000);
|
||||
src.sin_addr = so->so_laddr;
|
||||
dst_addr = so->so_faddr;
|
||||
monitor_printf(mon, "%-19s %3d %15s - ", buf, so->s,
|
||||
g_string_append_printf(str, "%-19s %3d %15s - ", buf, so->s,
|
||||
src.sin_addr.s_addr ? inet_ntoa(src.sin_addr) : "*");
|
||||
monitor_printf(mon, "%15s - %5d %5d\n", inet_ntoa(dst_addr),
|
||||
g_string_append_printf(str, "%15s - %5d %5d\n", inet_ntoa(dst_addr),
|
||||
so->so_rcv.sb_cc, so->so_snd.sb_cc);
|
||||
}
|
||||
|
||||
return g_string_free(str, FALSE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user