From patchwork Sun Jan 27 12:05:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 10782817 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 4F5381390 for ; Sun, 27 Jan 2019 12:10:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F84529DE5 for ; Sun, 27 Jan 2019 12:10:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 340AC2B3E4; Sun, 27 Jan 2019 12:10:25 +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 BD41029DE5 for ; Sun, 27 Jan 2019 12:10:24 +0000 (UTC) Received: from localhost ([127.0.0.1]:44662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gnjGa-0005DW-2k for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Jan 2019 07:10:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gnjCD-0001PW-Nr for qemu-devel@nongnu.org; Sun, 27 Jan 2019 07:05:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gnjCB-0007R6-Cs for qemu-devel@nongnu.org; Sun, 27 Jan 2019 07:05:53 -0500 Received: from hera.aquilenet.fr ([2a0c:e300::1]:43396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gnjCB-0007Oa-0D for qemu-devel@nongnu.org; Sun, 27 Jan 2019 07:05:51 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id F10EC7CCF; Sun, 27 Jan 2019 13:05: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 f9PiUJK5L6UM; Sun, 27 Jan 2019 13:05:33 +0100 (CET) Received: from function (lfbn-1-11161-124.w86-213.abo.wanadoo.fr [86.213.235.124]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 733FC7CD5; Sun, 27 Jan 2019 13:05:28 +0100 (CET) Received: from samy by function with local (Exim 4.92-RC4) (envelope-from ) id 1gnjBm-00042l-UK; Sun, 27 Jan 2019 13:05:26 +0100 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sun, 27 Jan 2019 13:05:03 +0100 Message-Id: <20190127120526.15457-9-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190127120526.15457-1-samuel.thibault@ens-lyon.org> References: <20190127120526.15457-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULL 08/31] slirp: add callbacks for timer 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 | 21 +++++++++++++++++++++ slirp/ip6_icmp.c | 16 +++++++--------- slirp/libslirp.h | 14 +++++++++++--- slirp/slirp.h | 2 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 0b15f427f5..c24a779425 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -168,10 +168,31 @@ static int64_t net_slirp_clock_get_ns(void) return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); } +static void *net_slirp_timer_new(SlirpTimerCb cb, void *opaque) +{ + return timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, + SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, + cb, opaque); +} + +static void net_slirp_timer_free(void *timer) +{ + timer_del(timer); + timer_free(timer); +} + +static void net_slirp_timer_mod(void *timer, int64_t expire_timer) +{ + timer_mod(timer, expire_timer); +} + static const SlirpCb slirp_cb = { .output = net_slirp_output, .guest_error = net_slirp_guest_error, .clock_get_ns = net_slirp_clock_get_ns, + .timer_new = net_slirp_timer_new, + .timer_free = net_slirp_timer_free, + .timer_mod = net_slirp_timer_mod, }; static int net_slirp_init(NetClientState *peer, const char *model, diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c index 5261baae27..e72c57a81d 100644 --- a/slirp/ip6_icmp.c +++ b/slirp/ip6_icmp.c @@ -16,8 +16,9 @@ static void ra_timer_handler(void *opaque) { Slirp *slirp = opaque; - timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); + + slirp->cb->timer_mod(slirp->ra_timer, + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); ndp_send_ra(slirp); } @@ -27,11 +28,9 @@ void icmp6_init(Slirp *slirp) return; } - slirp->ra_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL, - SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, - ra_timer_handler, slirp); - timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); + slirp->ra_timer = slirp->cb->timer_new(ra_timer_handler, slirp); + slirp->cb->timer_mod(slirp->ra_timer, + slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval); } void icmp6_cleanup(Slirp *slirp) @@ -40,8 +39,7 @@ void icmp6_cleanup(Slirp *slirp) return; } - timer_del(slirp->ra_timer); - timer_free(slirp->ra_timer); + slirp->cb->timer_free(slirp->ra_timer); } static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip, diff --git a/slirp/libslirp.h b/slirp/libslirp.h index ea019828e8..3e75dadfa3 100644 --- a/slirp/libslirp.h +++ b/slirp/libslirp.h @@ -6,19 +6,27 @@ typedef struct Slirp Slirp; typedef int (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); +typedef void (*SlirpTimerCb)(void *opaque); /* * Callbacks from slirp - * - * The opaque parameter comes from the opaque parameter given to slirp_init(). */ typedef struct SlirpCb { - /* Send an ethernet frame to the guest network. */ + /* + * Send an ethernet frame to the guest network. The opaque parameter + * is the one given to slirp_init(). + */ 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); /* Return the virtual clock value in nanoseconds */ int64_t (*clock_get_ns)(void); + /* Create a new timer with the given callback and opaque data */ + void *(*timer_new)(SlirpTimerCb cb, void *opaque); + /* Remove and free a timer */ + void (*timer_free)(void *timer); + /* Modify a timer to expire at @expire_time */ + void (*timer_mod)(void *timer, int64_t expire_time); } SlirpCb; diff --git a/slirp/slirp.h b/slirp/slirp.h index 9aa245715d..17056f4b83 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -193,7 +193,7 @@ struct Slirp { NdpTable ndp_table; GRand *grand; - QEMUTimer *ra_timer; + void *ra_timer; const SlirpCb *cb; void *opaque;