diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2019-01-17 15:43:37 +0400 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2019-02-07 15:49:08 +0200 |
commit | 07abf6d43ad8845868674c76bdd498b1a868df64 (patch) | |
tree | 46bda10914033744e0b0e44ccc2d3a670c8bc887 | |
parent | 8e207c327cf89aca02ea4c7e3109d285df048d55 (diff) | |
download | qemu-07abf6d43ad8845868674c76bdd498b1a868df64.zip |
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>
-rw-r--r-- | net/slirp.c | 21 | ||||
-rw-r--r-- | slirp/ip6_icmp.c | 16 | ||||
-rw-r--r-- | slirp/libslirp.h | 14 | ||||
-rw-r--r-- | 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; |