[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 01/65] slirp: associate slirp_output callback with th
From: |
Samuel Thibault |
Subject: |
[Qemu-devel] [PULL 01/65] slirp: associate slirp_output callback with the Slirp context |
Date: |
Mon, 14 Jan 2019 01:02:22 +0100 |
From: Marc-André Lureau <address@hidden>
Let's make the slirp interface a bit more library-like.
Associate the slirp_output() with a Slirp context.
Signed-off-by: Marc-André Lureau <address@hidden>
Signed-off-by: Samuel Thibault <address@hidden>
---
net/slirp.c | 5 +++--
slirp/libslirp.h | 9 +++++----
slirp/ncsi.c | 2 +-
slirp/slirp.c | 11 +++++++----
slirp/slirp.h | 1 +
5 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/net/slirp.c b/net/slirp.c
index 38ae65e4a9..dd06b0189e 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -99,7 +99,7 @@ static void slirp_smb_cleanup(SlirpState *s);
static inline void slirp_smb_cleanup(SlirpState *s) { }
#endif
-void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len)
+static void net_slirp_output(void *opaque, const uint8_t *pkt, int pkt_len)
{
SlirpState *s = opaque;
@@ -378,7 +378,8 @@ static int net_slirp_init(NetClientState *peer, const char
*model,
ipv6, ip6_prefix, vprefix6_len, ip6_host,
vhostname, tftp_server_name,
tftp_export, bootfile, dhcp,
- dns, ip6_dns, dnssearch, vdomainname, s);
+ dns, ip6_dns, dnssearch, vdomainname,
+ net_slirp_output, s);
QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
for (config = slirp_configs; config; config = config->next) {
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 42e42e9a2a..52dbb9feb5 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -5,6 +5,8 @@
typedef struct Slirp Slirp;
+typedef void (*slirp_output)(void *opaque, const uint8_t *pkt, int pkt_len);
+
int get_dns_addr(struct in_addr *pdns_addr);
int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id);
@@ -17,7 +19,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct
in_addr vnetwork,
const char *tftp_path, const char *bootfile,
struct in_addr vdhcp_start, struct in_addr vnameserver,
struct in6_addr vnameserver6, const char **vdnssearch,
- const char *vdomainname, void *opaque);
+ const char *vdomainname,
+ slirp_output output,
+ void *opaque);
void slirp_cleanup(Slirp *slirp);
void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
@@ -26,9 +30,6 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error);
void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
-/* you must provide the following functions: */
-void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len);
-
int slirp_add_hostfwd(Slirp *slirp, int is_udp,
struct in_addr host_addr, int host_port,
struct in_addr guest_addr, int guest_port);
diff --git a/slirp/ncsi.c b/slirp/ncsi.c
index 7116034afc..d7701f7785 100644
--- a/slirp/ncsi.c
+++ b/slirp/ncsi.c
@@ -163,5 +163,5 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int
pkt_len)
*pchecksum = htonl(checksum);
ncsi_rsp_len += 4;
- slirp_output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len);
+ slirp->output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len);
}
diff --git a/slirp/slirp.c b/slirp/slirp.c
index ab2fc4eb8b..4d4c2c13b5 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -287,12 +287,15 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct
in_addr vnetwork,
const char *tftp_path, const char *bootfile,
struct in_addr vdhcp_start, struct in_addr vnameserver,
struct in6_addr vnameserver6, const char **vdnssearch,
- const char *vdomainname, void *opaque)
+ const char *vdomainname,
+ slirp_output output,
+ void *opaque)
{
Slirp *slirp = g_malloc0(sizeof(Slirp));
slirp_init_once();
+ slirp->output = output;
slirp->grand = g_rand_new();
slirp->restricted = restricted;
@@ -832,7 +835,7 @@ static void arp_input(Slirp *slirp, const uint8_t *pkt, int
pkt_len)
rah->ar_sip = ah->ar_tip;
memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN);
rah->ar_tip = ah->ar_sip;
- slirp_output(slirp->opaque, arp_reply, sizeof(arp_reply));
+ slirp->output(slirp->opaque, arp_reply, sizeof(arp_reply));
}
break;
case ARPOP_REPLY:
@@ -932,7 +935,7 @@ static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct
ethhdr *eh,
/* target IP */
rah->ar_tip = iph->ip_dst.s_addr;
slirp->client_ipaddr = iph->ip_dst;
- slirp_output(slirp->opaque, arp_req, sizeof(arp_req));
+ slirp->output(slirp->opaque, arp_req, sizeof(arp_req));
ifm->resolution_requested = true;
/* Expire request and drop outgoing packet after 1 second */
@@ -1018,7 +1021,7 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
- slirp_output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
+ slirp->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
return 1;
}
diff --git a/slirp/slirp.h b/slirp/slirp.h
index b80725a0d6..e3d65d68ec 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -220,6 +220,7 @@ struct Slirp {
GRand *grand;
QEMUTimer *ra_timer;
+ slirp_output output;
void *opaque;
};
--
2.20.1
- [Qemu-devel] [PULLv2 00/65] slirp updates, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 03/65] slirp: replace ex_pty with ex_chardev, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 06/65] slirp: rename /extra/chardev, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 10/65] slirp: replace the poor-man string split with g_strsplit(), Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 17/65] slirp: remove FULL_BOLT, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 21/65] slirp: remove NO_UNIX_SOCKETS, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 18/65] slirp: remove the disabled readv()/writev() code path, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 01/65] slirp: associate slirp_output callback with the Slirp context,
Samuel Thibault <=
- [Qemu-devel] [PULL 02/65] slirp: remove do_pty from fork_exec(), Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 07/65] slirp: move internal function declarations, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 09/65] slirp: fix slirp_add_exec() leaks, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 05/65] slirp: remove unused EMU_RSH, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 11/65] slirp: remove dead declarations, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 14/65] slirp: remove unused M_TRAILINGSPACE, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 12/65] slirp: add tftp tracing, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 15/65] slirp: use a callback structure to interface with qemu, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 24/65] slirp: remove unused HAVE_SYS_WAIT_H, Samuel Thibault, 2019/01/13
- [Qemu-devel] [PULL 22/65] slirp: remove unused HAVE_SYS_STROPTS_H, Samuel Thibault, 2019/01/13