From patchwork Mon Jan 14 22:52:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10763529 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 6DEAA1390 for ; Mon, 14 Jan 2019 23:10:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FEEB2C32A for ; Mon, 14 Jan 2019 23:10:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 548162C4F2; Mon, 14 Jan 2019 23:10:48 +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 DDB992C4D6 for ; Mon, 14 Jan 2019 23:10:47 +0000 (UTC) Received: from localhost ([127.0.0.1]:34085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjBNX-000243-3z for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 Jan 2019 18:10:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjB7D-0004in-Ot for qemu-devel@nongnu.org; Mon, 14 Jan 2019 17:53:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjB7A-0001bX-3a for qemu-devel@nongnu.org; Mon, 14 Jan 2019 17:53:53 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:40474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gjB77-0001RF-Fn for qemu-devel@nongnu.org; Mon, 14 Jan 2019 17:53:50 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8A8F91BBB; Mon, 14 Jan 2019 23:53:34 +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 EqnE2jWmG47g; Mon, 14 Jan 2019 23:53:33 +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 345401BE5; Mon, 14 Jan 2019 23:53:12 +0100 (CET) Received: from samy by function.home with local (Exim 4.92-RC4) (envelope-from ) id 1gjB6U-0005fB-4s; Mon, 14 Jan 2019 23:53:10 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2019 23:52:37 +0100 Message-Id: <20190114225306.21569-37-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 36/65] slirp: add a callback to log guest errors 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 Signed-off-by: Marc-André Lureau Signed-off-by: Samuel Thibault --- net/slirp.c | 7 +++++++ slirp/dhcpv6.c | 6 +++--- slirp/ip6_icmp.c | 7 +++---- slirp/libslirp.h | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 031c324f02..ea8b04e007 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -23,6 +23,7 @@ */ #include "qemu/osdep.h" +#include "qemu/log.h" #include "net/slirp.h" @@ -140,8 +141,14 @@ static NetClientInfo net_slirp_info = { .cleanup = net_slirp_cleanup, }; +static void net_slirp_guest_error(const char *msg) +{ + qemu_log_mask(LOG_GUEST_ERROR, "%s", msg); +} + static const SlirpCb slirp_cb = { .output = net_slirp_output, + .guest_error = net_slirp_guest_error, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c index 943a13bca8..5d703e8ae6 100644 --- a/slirp/dhcpv6.c +++ b/slirp/dhcpv6.c @@ -50,7 +50,7 @@ struct requested_infos { * the odata region, thus the caller must keep odata valid as long as it * needs to access the requested_infos struct. */ -static int dhcpv6_parse_info_request(uint8_t *odata, int olen, +static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen, struct requested_infos *ri) { int i, req_opt; @@ -61,7 +61,7 @@ static int dhcpv6_parse_info_request(uint8_t *odata, int olen, int len = odata[2] << 8 | odata[3]; if (len + 4 > olen) { - qemu_log_mask(LOG_GUEST_ERROR, "Guest sent bad DHCPv6 packet!\n"); + slirp->cb->guest_error("Guest sent bad DHCPv6 packet!"); return -E2BIG; } @@ -121,7 +121,7 @@ static void dhcpv6_info_request(Slirp *slirp, struct sockaddr_in6 *srcsas, struct mbuf *m; uint8_t *resp; - if (dhcpv6_parse_info_request(odata, olen, &ri) < 0) { + if (dhcpv6_parse_info_request(slirp, odata, olen, &ri) < 0) { return; } diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 595647b1b1..3f74d172f4 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -342,8 +342,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip, case ICMP6_NDP_RA: DEBUG_CALL(" type = Router Advertisement"); - qemu_log_mask(LOG_GUEST_ERROR, - "Warning: guest sent NDP RA, but shouldn't"); + slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't"); break; case ICMP6_NDP_NS: @@ -376,8 +375,8 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip, case ICMP6_NDP_REDIRECT: DEBUG_CALL(" type = Redirect"); - qemu_log_mask(LOG_GUEST_ERROR, - "Warning: guest sent NDP REDIRECT, but shouldn't"); + slirp->cb->guest_error( + "Warning: guest sent NDP REDIRECT, but shouldn't"); break; } } diff --git a/slirp/libslirp.h b/slirp/libslirp.h index a5d1b27b5e..3e0aa19f4b 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -13,6 +13,8 @@ typedef struct Slirp Slirp; typedef struct SlirpCb { /* Send an ethernet frame to the guest network. */ void (*output)(void *opaque, const uint8_t *pkt, int pkt_len); + /* Print a message for an error due to guest misbehavior. */ + void (*guest_error)(const char *msg); } SlirpCb;