aboutsummaryrefslogtreecommitdiff
path: root/slirp
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-01-17 15:43:37 +0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-02-07 15:49:08 +0200
commit07abf6d43ad8845868674c76bdd498b1a868df64 (patch)
tree46bda10914033744e0b0e44ccc2d3a670c8bc887 /slirp
parent8e207c327cf89aca02ea4c7e3109d285df048d55 (diff)
downloadqemu-07abf6d43ad8845868674c76bdd498b1a868df64.zip
qemu-07abf6d43ad8845868674c76bdd498b1a868df64.tar.gz
qemu-07abf6d43ad8845868674c76bdd498b1a868df64.tar.bz2
slirp: add callbacks for timer
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'slirp')
-rw-r--r--slirp/ip6_icmp.c16
-rw-r--r--slirp/libslirp.h14
-rw-r--r--slirp/slirp.h2
3 files changed, 19 insertions, 13 deletions
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index 5261baa..e72c57a 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 ea01982..3e75dad 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 9aa2457..17056f4 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;