qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Samuel Thibault" <samuel.thibault@ens-lyon.org>,
	"Marc-André Lureau" <malureau@redhat.com>
Subject: [PULL 19/27] net: slirp: add support for CFI-friendly timer API
Date: Thu, 12 May 2022 19:24:57 +0200	[thread overview]
Message-ID: <20220512172505.1065394-20-pbonzini@redhat.com> (raw)
In-Reply-To: <20220512172505.1065394-1-pbonzini@redhat.com>

libslirp 4.7 introduces a CFI-friendly version of the .timer_new callback.
The new callback replaces the function pointer with an enum; invoking the
callback is done with a new function slirp_handle_timer.

Support the new API so that CFI can be made compatible with using a system
libslirp.

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Marc-André Lureau <malureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 net/slirp.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/net/slirp.c b/net/slirp.c
index b7464be86b..8679be6444 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -184,10 +184,43 @@ static int64_t net_slirp_clock_get_ns(void *opaque)
     return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 }
 
+typedef struct SlirpTimer SlirpTimer;
 struct SlirpTimer {
     QEMUTimer timer;
+#if SLIRP_CHECK_VERSION(4,7,0)
+    Slirp *slirp;
+    SlirpTimerId id;
+    void *cb_opaque;
+#endif
+};
+
+#if SLIRP_CHECK_VERSION(4,7,0)
+static void net_slirp_init_completed(Slirp *slirp, void *opaque)
+{
+    SlirpState *s = opaque;
+    s->slirp = slirp;
 }
 
+static void net_slirp_timer_cb(void *opaque)
+{
+    SlirpTimer *t = opaque;
+    slirp_handle_timer(t->slirp, t->id, t->cb_opaque);
+}
+
+static void *net_slirp_timer_new_opaque(SlirpTimerId id,
+                                        void *cb_opaque, void *opaque)
+{
+    SlirpState *s = opaque;
+    SlirpTimer *t = g_new(SlirpTimer, 1);
+    t->slirp = s->slirp;
+    t->id = id;
+    t->cb_opaque = cb_opaque;
+    timer_init_full(&t->timer, NULL, QEMU_CLOCK_VIRTUAL,
+                    SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
+                    net_slirp_timer_cb, t);
+    return t;
+}
+#else
 static void *net_slirp_timer_new(SlirpTimerCb cb,
                                  void *cb_opaque, void *opaque)
 {
@@ -197,6 +230,7 @@ static void *net_slirp_timer_new(SlirpTimerCb cb,
                     cb, cb_opaque);
     return t;
 }
+#endif
 
 static void net_slirp_timer_free(void *timer, void *opaque)
 {
@@ -231,7 +265,12 @@ static const SlirpCb slirp_cb = {
     .send_packet = net_slirp_send_packet,
     .guest_error = net_slirp_guest_error,
     .clock_get_ns = net_slirp_clock_get_ns,
+#if SLIRP_CHECK_VERSION(4,7,0)
+    .init_completed = net_slirp_init_completed,
+    .timer_new_opaque = net_slirp_timer_new_opaque,
+#else
     .timer_new = net_slirp_timer_new,
+#endif
     .timer_free = net_slirp_timer_free,
     .timer_mod = net_slirp_timer_mod,
     .register_poll_fd = net_slirp_register_poll_fd,
@@ -578,7 +617,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
 
     s = DO_UPCAST(SlirpState, nc, nc);
 
-    cfg.version = 1;
+    cfg.version = SLIRP_CHECK_VERSION(4,7,0) ? 4 : 1;
     cfg.restricted = restricted;
     cfg.in_enabled = ipv4;
     cfg.vnetwork = net;
-- 
2.36.0



  parent reply	other threads:[~2022-05-12 18:07 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12 17:24 [PULL 00/27] Misc patches for 2022-05-12 Paolo Bonzini
2022-05-12 17:24 ` [PULL 01/27] pc-bios/optionrom: detect -fno-pie Paolo Bonzini
2022-05-12 17:24 ` [PULL 02/27] pc-bios/optionrom: compile with -Wno-array-bounds Paolo Bonzini
2022-05-12 17:24 ` [PULL 03/27] target/i386: do not consult nonexistent host leaves Paolo Bonzini
2022-05-12 17:24 ` [PULL 04/27] checkpatch: fix g_malloc check Paolo Bonzini
2022-05-12 17:24 ` [PULL 05/27] meson: Make mremap() detecting works correctly Paolo Bonzini
2022-05-12 17:24 ` [PULL 06/27] hw/xen/xen_pt: Confine igd-passthrough-isa-bridge to XEN Paolo Bonzini
2022-05-12 17:24 ` [PULL 07/27] hw/xen/xen_pt: Resolve igd_passthrough_isa_bridge_create() indirection Paolo Bonzini
2022-05-12 17:24 ` [PULL 08/27] tests/qtest/libqos/pci: Introduce pio_limit Paolo Bonzini
2022-05-12 17:24 ` [PULL 09/27] tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable Paolo Bonzini
2022-05-12 17:24 ` [PULL 10/27] tests/qtest/libqos: Add generic pci host bridge in arm-virt machine Paolo Bonzini
2022-05-12 17:24 ` [PULL 11/27] machine: use QAPI struct for boot configuration Paolo Bonzini
2022-05-12 17:24 ` [PULL 12/27] machine: add boot compound property Paolo Bonzini
2022-05-12 17:24 ` [PULL 13/27] machine: add mem " Paolo Bonzini
2022-06-13 13:42   ` Markus Armbruster
2022-08-05  9:30     ` Regression in -readconfig [memory] size (was: [PULL 13/27] machine: add mem compound property) Markus Armbruster
2022-08-05  9:42       ` Paolo Bonzini
2022-08-05  9:51       ` Daniel P. Berrangé
2022-05-12 17:24 ` [PULL 14/27] machine: make memory-backend a link property Paolo Bonzini
2022-05-12 17:24 ` [PULL 15/27] machine: move more memory validation to Machine object Paolo Bonzini
2022-05-12 17:24 ` [PULL 16/27] slirp: bump submodule past 4.7 release Paolo Bonzini
2022-05-12 17:24 ` [PULL 17/27] net: slirp: introduce a wrapper struct for QemuTimer Paolo Bonzini
2022-05-12 17:24 ` [PULL 18/27] net: slirp: switch to slirp_new Paolo Bonzini
2022-05-12 17:24 ` Paolo Bonzini [this message]
2022-05-12 17:24 ` [PULL 20/27] net: slirp: allow CFI with libslirp >= 4.7 Paolo Bonzini
2022-05-12 17:24 ` [PULL 21/27] coroutine-lock: qemu_co_queue_next is a coroutine-only qemu_co_enter_next Paolo Bonzini
2022-05-12 17:25 ` [PULL 22/27] coroutine-lock: introduce qemu_co_queue_enter_all Paolo Bonzini
2022-05-12 17:25 ` [PULL 23/27] coroutine-lock: qemu_co_queue_restart_all is a coroutine-only qemu_co_enter_all Paolo Bonzini
2022-05-12 17:25 ` [PULL 24/27] vhost-backend: do not depend on CONFIG_VHOST_VSOCK Paolo Bonzini
2022-05-12 17:25 ` [PULL 25/27] meson: link libpng independent of vnc Paolo Bonzini
2022-05-12 17:25 ` [PULL 26/27] vl: make machine type deprecation a warning Paolo Bonzini
2022-05-12 17:25 ` [PULL 27/27] vmxcap: add tertiary execution controls Paolo Bonzini
2022-05-12 21:14 ` [PULL 00/27] Misc patches for 2022-05-12 Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512172505.1065394-20-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=malureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=samuel.thibault@ens-lyon.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).