aboutsummaryrefslogtreecommitdiff
path: root/src/libslirp.h
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-07-28 17:16:06 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2022-04-10 15:53:52 +0200
commit8e6b6d04b11d3a2a4fd8413555414c5f8e500915 (patch)
tree9ac78a94e70f4743665e322bac984b99b4b63133 /src/libslirp.h
parenta57ee6e6ef7472bce2c30f800e09daa89ea6fd47 (diff)
downloadslirp-8e6b6d04b11d3a2a4fd8413555414c5f8e500915.zip
slirp-8e6b6d04b11d3a2a4fd8413555414c5f8e500915.tar.gz
slirp-8e6b6d04b11d3a2a4fd8413555414c5f8e500915.tar.bz2
introduce timer_new_opaque callback
Add a new callback that supports CFI better by avoiding having function pointers in the external libslirp API. Instead, the new API passes an opaque integer and requests the application to call a new libslirp function when the timer expires. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'src/libslirp.h')
-rw-r--r--src/libslirp.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libslirp.h b/src/libslirp.h
index 546f2f9..8eb47a0 100644
--- a/src/libslirp.h
+++ b/src/libslirp.h
@@ -63,7 +63,8 @@ typedef struct SlirpCb {
void (*guest_error)(const char *msg, void *opaque);
/* Return the virtual clock value in nanoseconds */
int64_t (*clock_get_ns)(void *opaque);
- /* Create a new timer with the given callback and opaque data */
+ /* Create a new timer with the given callback and opaque data. Not
+ * needed if timer_new_opaque is provided. */
void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque);
/* Remove and free a timer */
void (*timer_free)(void *timer, void *opaque);
@@ -76,6 +77,14 @@ typedef struct SlirpCb {
/* Kick the io-thread, to signal that new events may be processed because some TCP buffer
* can now receive more data, i.e. slirp_socket_can_recv will return 1. */
void (*notify)(void *opaque);
+
+ /*
+ * Fields introduced in SlirpConfig version 4 begin
+ */
+
+ /* Create a new timer. When the timer fires, the application passes
+ * the SlirpTimerId and cb_opaque to slirp_handle_timer. */
+ void *(*timer_new_opaque)(SlirpTimerId id, void *cb_opaque, void *opaque);
} SlirpCb;
#define SLIRP_CONFIG_VERSION_MIN 1
@@ -171,6 +180,11 @@ void slirp_pollfds_poll(Slirp *slirp, int select_error,
* guest network, to be interpreted by slirp. */
void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
+/* This is called by the application when a timer expires, if it provides
+ * the timer_new_opaque callback. It is not needed if the application only
+ * uses timer_new. */
+void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque);
+
/* These set up / remove port forwarding between a host port in the real world
* and the guest network. */
int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,