aboutsummaryrefslogtreecommitdiff
path: root/slirp
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-01-17 15:43:58 +0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-02-07 15:49:08 +0200
commit3e0fad3aa5f9f36566ac2815a54288d214e58689 (patch)
treef2714d8506fe29bcaaaa4edabe341ee8befddc34 /slirp
parentdeaeb3f71d1fdf199d5b949e8575303486e3dec8 (diff)
slirp: pass opaque to all callbacks
This is friendlier for FFI bindings. 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/dhcpv6.c2
-rw-r--r--slirp/if.c2
-rw-r--r--slirp/ip6_icmp.c15
-rw-r--r--slirp/ip_icmp.c2
-rw-r--r--slirp/libslirp.h16
-rw-r--r--slirp/misc.c2
-rw-r--r--slirp/slirp.c13
-rw-r--r--slirp/socket.c2
-rw-r--r--slirp/tcp_subr.c8
-rw-r--r--slirp/udp.c2
10 files changed, 33 insertions, 31 deletions
diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c
index 9ffba38e8f..e655c7d5b1 100644
--- a/slirp/dhcpv6.c
+++ b/slirp/dhcpv6.c
@@ -59,7 +59,7 @@ static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen,
int len = odata[2] << 8 | odata[3];
if (len + 4 > olen) {
- slirp->cb->guest_error("Guest sent bad DHCPv6 packet!");
+ slirp->cb->guest_error("Guest sent bad DHCPv6 packet!", slirp->opaque);
return -E2BIG;
}
diff --git a/slirp/if.c b/slirp/if.c
index 2ad03b8a79..1830cc396c 100644
--- a/slirp/if.c
+++ b/slirp/if.c
@@ -146,7 +146,7 @@ diddit:
*/
void if_start(Slirp *slirp)
{
- uint64_t now = slirp->cb->clock_get_ns();
+ uint64_t now = slirp->cb->clock_get_ns(slirp->opaque);
bool from_batchq = false;
struct mbuf *ifm, *ifm_next, *ifqt;
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index 2a432ebbd4..c1e3d30470 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -14,7 +14,8 @@ static void ra_timer_handler(void *opaque)
Slirp *slirp = opaque;
slirp->cb->timer_mod(slirp->ra_timer,
- slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval);
+ slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + NDP_Interval,
+ slirp->opaque);
ndp_send_ra(slirp);
}
@@ -24,9 +25,10 @@ void icmp6_init(Slirp *slirp)
return;
}
- slirp->ra_timer = slirp->cb->timer_new(ra_timer_handler, slirp);
+ slirp->ra_timer = slirp->cb->timer_new(ra_timer_handler, slirp, slirp->opaque);
slirp->cb->timer_mod(slirp->ra_timer,
- slirp->cb->clock_get_ns() / SCALE_MS + NDP_Interval);
+ slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + NDP_Interval,
+ slirp->opaque);
}
void icmp6_cleanup(Slirp *slirp)
@@ -35,7 +37,7 @@ void icmp6_cleanup(Slirp *slirp)
return;
}
- slirp->cb->timer_free(slirp->ra_timer);
+ slirp->cb->timer_free(slirp->ra_timer, slirp->opaque);
}
static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
@@ -334,7 +336,8 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
case ICMP6_NDP_RA:
DEBUG_CALL(" type = Router Advertisement");
- slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't");
+ slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't",
+ slirp->opaque);
break;
case ICMP6_NDP_NS:
@@ -368,7 +371,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
case ICMP6_NDP_REDIRECT:
DEBUG_CALL(" type = Redirect");
slirp->cb->guest_error(
- "Warning: guest sent NDP REDIRECT, but shouldn't");
+ "Warning: guest sent NDP REDIRECT, but shouldn't", slirp->opaque);
break;
}
}
diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 7c5cb75ae5..ce79c0b051 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -113,7 +113,7 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
void icmp_detach(struct socket *so)
{
- so->slirp->cb->unregister_poll_fd(so->s);
+ so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
slirp_closesocket(so->s);
sofree(so);
}
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index b5c1b2122b..9b13d8250c 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -40,21 +40,21 @@ typedef struct SlirpCb {
*/
SlirpWriteCb send_packet;
/* Print a message for an error due to guest misbehavior. */
- void (*guest_error)(const char *msg);
+ void (*guest_error)(const char *msg, void *opaque);
/* Return the virtual clock value in nanoseconds */
- int64_t (*clock_get_ns)(void);
+ int64_t (*clock_get_ns)(void *opaque);
/* Create a new timer with the given callback and opaque data */
- void *(*timer_new)(SlirpTimerCb cb, void *opaque);
+ void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque);
/* Remove and free a timer */
- void (*timer_free)(void *timer);
+ void (*timer_free)(void *timer, void *opaque);
/* Modify a timer to expire at @expire_time */
- void (*timer_mod)(void *timer, int64_t expire_time);
+ void (*timer_mod)(void *timer, int64_t expire_time, void *opaque);
/* Register a fd for future polling */
- void (*register_poll_fd)(int fd);
+ void (*register_poll_fd)(int fd, void *opaque);
/* Unregister a fd */
- void (*unregister_poll_fd)(int fd);
+ void (*unregister_poll_fd)(int fd, void *opaque);
/* Kick the io-thread, to signal that new events may be processed */
- void (*notify)(void);
+ void (*notify)(void *opaque);
} SlirpCb;
diff --git a/slirp/misc.c b/slirp/misc.c
index 3c02510101..3f4cd852f8 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -222,7 +222,7 @@ fork_exec(struct socket *so, const char *ex)
opt = 1;
slirp_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
slirp_set_nonblock(so->s);
- so->slirp->cb->register_poll_fd(so->s);
+ so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
return 1;
}
diff --git a/slirp/slirp.c b/slirp/slirp.c
index eedbce23dc..a746c6fd86 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -289,6 +289,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
slirp_init_once();
+ slirp->opaque = opaque;
slirp->cb = callbacks;
slirp->grand = g_rand_new();
slirp->restricted = restricted;
@@ -325,12 +326,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
translate_dnssearch(slirp, vdnssearch);
}
- slirp->opaque = opaque;
-
#ifdef WITH_QEMU
slirp_state_register(slirp);
#endif
-
return slirp;
}
@@ -537,7 +535,7 @@ void slirp_pollfds_poll(Slirp *slirp, int select_error,
struct socket *so, *so_next;
int ret;
- curtime = slirp->cb->clock_get_ns() / SCALE_MS;
+ curtime = slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS;
/*
* See if anything has timed out
@@ -860,7 +858,8 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
ifm->resolution_requested = true;
/* Expire request and drop outgoing packet after 1 second */
- ifm->expiration_date = slirp->cb->clock_get_ns() + 1000000000ULL;
+ ifm->expiration_date =
+ slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL;
}
return 0;
} else {
@@ -886,7 +885,7 @@ static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh,
if (!ifm->resolution_requested) {
ndp_send_ns(slirp, ip6h->ip_dst);
ifm->resolution_requested = true;
- ifm->expiration_date = slirp->cb->clock_get_ns() + 1000000000ULL;
+ ifm->expiration_date = slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL;
}
return 0;
} else {
@@ -961,7 +960,7 @@ int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 &&
addr.sin_addr.s_addr == host_addr.s_addr &&
addr.sin_port == port) {
- so->slirp->cb->unregister_poll_fd(so->s);
+ so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
slirp_closesocket(so->s);
sofree(so);
return 0;
diff --git a/slirp/socket.c b/slirp/socket.c
index c896fa6da3..ce1d6ffa1d 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -930,6 +930,6 @@ void sotranslate_accept(struct socket *so)
void sodrop(struct socket *s, int num)
{
if (sbdrop(&s->so_snd, num)) {
- s->slirp->cb->notify();
+ s->slirp->cb->notify(s->slirp->opaque);
}
}
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index e35628a892..cda94815f6 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -336,7 +336,7 @@ tcp_close(struct tcpcb *tp)
/* clobber input socket cache if we're closing the cached connection */
if (so == slirp->tcp_last_so)
slirp->tcp_last_so = &slirp->tcb;
- so->slirp->cb->unregister_poll_fd(so->s);
+ so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
slirp_closesocket(so->s);
sbfree(&so->so_rcv);
sbfree(&so->so_snd);
@@ -413,7 +413,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
struct sockaddr_storage addr;
slirp_set_nonblock(s);
- so->slirp->cb->register_poll_fd(so->s);
+ so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
slirp_socket_set_fast_reuse(s);
opt = 1;
slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
@@ -486,7 +486,7 @@ void tcp_connect(struct socket *inso)
return;
}
slirp_set_nonblock(s);
- so->slirp->cb->register_poll_fd(so->s);
+ so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque);
slirp_socket_set_fast_reuse(s);
opt = 1;
slirp_setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
@@ -498,7 +498,7 @@ void tcp_connect(struct socket *inso)
/* Close the accept() socket, set right state */
if (inso->so_state & SS_FACCEPTONCE) {
/* If we only accept once, close the accept() socket */
- so->slirp->cb->unregister_poll_fd(so->s);
+ so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
slirp_closesocket(so->s);
/* Don't select it yet, even though we have an FD */
diff --git a/slirp/udp.c b/slirp/udp.c
index 5baa604b33..29a31e9400 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -291,7 +291,7 @@ udp_attach(struct socket *so, unsigned short af)
void
udp_detach(struct socket *so)
{
- so->slirp->cb->unregister_poll_fd(so->s);
+ so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque);
slirp_closesocket(so->s);
sofree(so);
}