From patchwork Mon Jan 14 22:52:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10763497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD98C6C2 for ; Mon, 14 Jan 2019 23:00:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEE192C4A9 for ; Mon, 14 Jan 2019 23:00:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A35002C492; Mon, 14 Jan 2019 23:00:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B7D12C4C0 for ; Mon, 14 Jan 2019 23:00:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:59957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjBE1-0002WB-TU for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 Jan 2019 18:00:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjB6l-0004CF-B6 for qemu-devel@nongnu.org; Mon, 14 Jan 2019 17:53:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjB6i-0001DW-9S for qemu-devel@nongnu.org; Mon, 14 Jan 2019 17:53:27 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:40288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjB6h-0001AA-Rr for qemu-devel@nongnu.org; Mon, 14 Jan 2019 17:53:24 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A14431BBC; Mon, 14 Jan 2019 23:53:19 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8qVZQHFIrqkT; Mon, 14 Jan 2019 23:53:18 +0100 (CET) Received: from function.home (lfbn-1-11161-124.w86-213.abo.wanadoo.fr [86.213.235.124]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 5F3251BC0; Mon, 14 Jan 2019 23:53:10 +0100 (CET) Received: from samy by function.home with local (Exim 4.92-RC4) (envelope-from ) id 1gjB6S-0005dt-NB; Mon, 14 Jan 2019 23:53:08 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 23:52:09 +0100 Message-Id: <20190114225306.21569-9-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114225306.21569-1-samuel.thibault@ens-lyon.org> References: <20190114225306.21569-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.233.100.1 Subject: [Qemu-devel] [PULL 08/65] slirp: remove Monitor dependency, return a string for info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Samuel Thibault , stefanha@redhat.com, jan.kiszka@siemens.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau 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 Signed-off-by: Samuel Thibault --- net/slirp.c | 7 ++++--- slirp/libslirp.h | 2 +- slirp/misc.c | 23 +++++++++++++---------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 58d880de8d..b7319ca6b2 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -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); } } diff --git a/slirp/libslirp.h b/slirp/libslirp.h index a4f390ee89..04b6db9f49 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -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); diff --git a/slirp/misc.c b/slirp/misc.c index 2784fc420f..ce323ef92e 100644 --- a/slirp/misc.c +++ b/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); }