mirror of https://gitee.com/openkylin/qemu.git
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>
This commit is contained in:
parent
8e207c327c
commit
07abf6d43a
21
net/slirp.c
21
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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ struct Slirp {
|
|||
NdpTable ndp_table;
|
||||
|
||||
GRand *grand;
|
||||
QEMUTimer *ra_timer;
|
||||
void *ra_timer;
|
||||
|
||||
const SlirpCb *cb;
|
||||
void *opaque;
|
||||
|
|
Loading…
Reference in New Issue