mirror of https://gitee.com/openkylin/qemu.git
Merge remote-tracking branch 'kiszka/queues/slirp' into staging
* kiszka/queues/slirp: slirp: Fix compiler warning for w64 slirp: Cleanup resources on instance removal slirp: Remove unneeded if_queued slirp: Fix queue walking in if_start slirp: Prevent recursion of if_start slirp: Keep next_m always valid
This commit is contained in:
commit
3e7ecd976b
|
@ -75,7 +75,7 @@ int cksum(struct mbuf *m, int len)
|
|||
/*
|
||||
* Force to even boundary.
|
||||
*/
|
||||
if ((1 & (long) w) && (mlen > 0)) {
|
||||
if ((1 & (uintptr_t)w) && (mlen > 0)) {
|
||||
REDUCE;
|
||||
sum <<= 8;
|
||||
s_util.c[0] = *(uint8_t *)w;
|
||||
|
|
86
slirp/if.c
86
slirp/if.c
|
@ -96,8 +96,13 @@ if_output(struct socket *so, struct mbuf *ifm)
|
|||
ifs_insque(ifm, ifq->ifs_prev);
|
||||
goto diddit;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
ifq = slirp->if_batchq.ifq_prev;
|
||||
/* Set next_m if the queue was empty so far */
|
||||
if (slirp->next_m == &slirp->if_batchq) {
|
||||
slirp->next_m = ifm;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a new doubly linked list for this session */
|
||||
ifm->ifq_so = so;
|
||||
|
@ -105,8 +110,6 @@ if_output(struct socket *so, struct mbuf *ifm)
|
|||
insque(ifm, ifq);
|
||||
|
||||
diddit:
|
||||
slirp->if_queued++;
|
||||
|
||||
if (so) {
|
||||
/* Update *_queued */
|
||||
so->so_queued++;
|
||||
|
@ -152,44 +155,54 @@ diddit:
|
|||
void if_start(Slirp *slirp)
|
||||
{
|
||||
uint64_t now = qemu_get_clock_ns(rt_clock);
|
||||
int requeued = 0;
|
||||
bool from_batchq = false;
|
||||
struct mbuf *ifm, *ifqt;
|
||||
bool from_batchq, next_from_batchq;
|
||||
struct mbuf *ifm, *ifm_next, *ifqt;
|
||||
|
||||
DEBUG_CALL("if_start");
|
||||
|
||||
while (slirp->if_queued) {
|
||||
if (slirp->if_start_busy) {
|
||||
return;
|
||||
}
|
||||
slirp->if_start_busy = true;
|
||||
|
||||
if (slirp->if_fastq.ifq_next != &slirp->if_fastq) {
|
||||
ifm_next = slirp->if_fastq.ifq_next;
|
||||
next_from_batchq = false;
|
||||
} else if (slirp->next_m != &slirp->if_batchq) {
|
||||
/* Nothing on fastq, pick up from batchq via next_m */
|
||||
ifm_next = slirp->next_m;
|
||||
next_from_batchq = true;
|
||||
} else {
|
||||
ifm_next = NULL;
|
||||
}
|
||||
|
||||
while (ifm_next) {
|
||||
/* check if we can really output */
|
||||
if (!slirp_can_output(slirp->opaque))
|
||||
return;
|
||||
|
||||
/*
|
||||
* See which queue to get next packet from
|
||||
* If there's something in the fastq, select it immediately
|
||||
*/
|
||||
if (slirp->if_fastq.ifq_next != &slirp->if_fastq) {
|
||||
ifm = slirp->if_fastq.ifq_next;
|
||||
} else {
|
||||
/* Nothing on fastq, see if next_m is valid */
|
||||
if (slirp->next_m != &slirp->if_batchq) {
|
||||
ifm = slirp->next_m;
|
||||
} else {
|
||||
ifm = slirp->if_batchq.ifq_next;
|
||||
}
|
||||
|
||||
from_batchq = true;
|
||||
if (!slirp_can_output(slirp->opaque)) {
|
||||
break;
|
||||
}
|
||||
|
||||
slirp->if_queued--;
|
||||
ifm = ifm_next;
|
||||
from_batchq = next_from_batchq;
|
||||
|
||||
ifm_next = ifm->ifq_next;
|
||||
if (ifm_next == &slirp->if_fastq) {
|
||||
/* No more packets in fastq, switch to batchq */
|
||||
ifm_next = slirp->next_m;
|
||||
next_from_batchq = true;
|
||||
}
|
||||
if (ifm_next == &slirp->if_batchq) {
|
||||
/* end of batchq */
|
||||
ifm_next = NULL;
|
||||
}
|
||||
|
||||
/* Try to send packet unless it already expired */
|
||||
if (ifm->expiration_date >= now && !if_encap(slirp, ifm)) {
|
||||
/* Packet is delayed due to pending ARP resolution */
|
||||
requeued++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (from_batchq) {
|
||||
if (ifm == slirp->next_m) {
|
||||
/* Set which packet to send on next iteration */
|
||||
slirp->next_m = ifm->ifq_next;
|
||||
}
|
||||
|
@ -200,8 +213,20 @@ void if_start(Slirp *slirp)
|
|||
|
||||
/* If there are more packets for this session, re-queue them */
|
||||
if (ifm->ifs_next != ifm) {
|
||||
insque(ifm->ifs_next, ifqt);
|
||||
struct mbuf *next = ifm->ifs_next;
|
||||
|
||||
insque(next, ifqt);
|
||||
ifs_remque(ifm);
|
||||
|
||||
if (!from_batchq) {
|
||||
/* Next packet in fastq is from the same session */
|
||||
ifm_next = next;
|
||||
next_from_batchq = false;
|
||||
} else if (slirp->next_m == &slirp->if_batchq) {
|
||||
/* Set next_m and ifm_next if the session packet is now the
|
||||
* only one on batchq */
|
||||
slirp->next_m = ifm_next = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update so_queued */
|
||||
|
@ -211,8 +236,7 @@ void if_start(Slirp *slirp)
|
|||
}
|
||||
|
||||
m_free(ifm);
|
||||
|
||||
}
|
||||
|
||||
slirp->if_queued = requeued;
|
||||
slirp->if_start_busy = false;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,13 @@ void icmp_init(Slirp *slirp)
|
|||
slirp->icmp_last_so = &slirp->icmp;
|
||||
}
|
||||
|
||||
void icmp_cleanup(Slirp *slirp)
|
||||
{
|
||||
while (slirp->icmp.so_next != &slirp->icmp) {
|
||||
icmp_detach(slirp->icmp.so_next);
|
||||
}
|
||||
}
|
||||
|
||||
static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
|
||||
{
|
||||
struct ip *ip = mtod(m, struct ip *);
|
||||
|
|
|
@ -154,6 +154,7 @@ struct icmp {
|
|||
(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
|
||||
|
||||
void icmp_init(Slirp *slirp);
|
||||
void icmp_cleanup(Slirp *slirp);
|
||||
void icmp_input(struct mbuf *, int);
|
||||
void icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
|
||||
const char *message);
|
||||
|
|
|
@ -61,6 +61,13 @@ ip_init(Slirp *slirp)
|
|||
icmp_init(slirp);
|
||||
}
|
||||
|
||||
void ip_cleanup(Slirp *slirp)
|
||||
{
|
||||
udp_cleanup(slirp);
|
||||
tcp_cleanup(slirp);
|
||||
icmp_cleanup(slirp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ip input routine. Checksum and byte swap header. If fragmented
|
||||
* try to reassemble. Process options. Pass to next level.
|
||||
|
|
21
slirp/mbuf.c
21
slirp/mbuf.c
|
@ -32,6 +32,27 @@ m_init(Slirp *slirp)
|
|||
slirp->m_usedlist.m_next = slirp->m_usedlist.m_prev = &slirp->m_usedlist;
|
||||
}
|
||||
|
||||
void m_cleanup(Slirp *slirp)
|
||||
{
|
||||
struct mbuf *m, *next;
|
||||
|
||||
m = slirp->m_usedlist.m_next;
|
||||
while (m != &slirp->m_usedlist) {
|
||||
next = m->m_next;
|
||||
if (m->m_flags & M_EXT) {
|
||||
free(m->m_ext);
|
||||
}
|
||||
free(m);
|
||||
m = next;
|
||||
}
|
||||
m = slirp->m_freelist.m_next;
|
||||
while (m != &slirp->m_freelist) {
|
||||
next = m->m_next;
|
||||
free(m);
|
||||
m = next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get an mbuf from the free list, if there are none
|
||||
* malloc one
|
||||
|
|
|
@ -116,6 +116,7 @@ struct mbuf {
|
|||
* it rather than putting it on the free list */
|
||||
|
||||
void m_init(Slirp *);
|
||||
void m_cleanup(Slirp *slirp);
|
||||
struct mbuf * m_get(Slirp *);
|
||||
void m_free(struct mbuf *);
|
||||
void m_cat(register struct mbuf *, register struct mbuf *);
|
||||
|
|
|
@ -246,6 +246,9 @@ void slirp_cleanup(Slirp *slirp)
|
|||
|
||||
unregister_savevm(NULL, "slirp", slirp);
|
||||
|
||||
ip_cleanup(slirp);
|
||||
m_cleanup(slirp);
|
||||
|
||||
g_free(slirp->tftp_prefix);
|
||||
g_free(slirp->bootp_filename);
|
||||
g_free(slirp);
|
||||
|
@ -581,12 +584,7 @@ void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds,
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* See if we can start outputting
|
||||
*/
|
||||
if (slirp->if_queued) {
|
||||
if_start(slirp);
|
||||
}
|
||||
if_start(slirp);
|
||||
}
|
||||
|
||||
/* clear global file descriptor sets.
|
||||
|
|
|
@ -235,10 +235,10 @@ struct Slirp {
|
|||
int mbuf_alloced;
|
||||
|
||||
/* if states */
|
||||
int if_queued; /* number of packets queued so far */
|
||||
struct mbuf if_fastq; /* fast queue (for interactive data) */
|
||||
struct mbuf if_batchq; /* queue for non-interactive data */
|
||||
struct mbuf *next_m; /* pointer to next mbuf to output */
|
||||
bool if_start_busy; /* avoid if_start recursion */
|
||||
|
||||
/* ip states */
|
||||
struct ipq ipq; /* ip reass. queue */
|
||||
|
@ -315,6 +315,7 @@ void if_output(struct socket *, struct mbuf *);
|
|||
|
||||
/* ip_input.c */
|
||||
void ip_init(Slirp *);
|
||||
void ip_cleanup(Slirp *);
|
||||
void ip_input(struct mbuf *);
|
||||
void ip_slowtimo(Slirp *);
|
||||
void ip_stripoptions(register struct mbuf *, struct mbuf *);
|
||||
|
@ -332,6 +333,7 @@ void tcp_setpersist(register struct tcpcb *);
|
|||
|
||||
/* tcp_subr.c */
|
||||
void tcp_init(Slirp *);
|
||||
void tcp_cleanup(Slirp *);
|
||||
void tcp_template(struct tcpcb *);
|
||||
void tcp_respond(struct tcpcb *, register struct tcpiphdr *, register struct mbuf *, tcp_seq, tcp_seq, int);
|
||||
struct tcpcb * tcp_newtcpcb(struct socket *);
|
||||
|
|
|
@ -55,6 +55,13 @@ tcp_init(Slirp *slirp)
|
|||
slirp->tcp_last_so = &slirp->tcb;
|
||||
}
|
||||
|
||||
void tcp_cleanup(Slirp *slirp)
|
||||
{
|
||||
while (slirp->tcb.so_next != &slirp->tcb) {
|
||||
tcp_close(sototcpcb(slirp->tcb.so_next));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create template to be used to send tcp packets on a connection.
|
||||
* Call after host entry created, fills
|
||||
|
|
|
@ -49,6 +49,14 @@ udp_init(Slirp *slirp)
|
|||
slirp->udb.so_next = slirp->udb.so_prev = &slirp->udb;
|
||||
slirp->udp_last_so = &slirp->udb;
|
||||
}
|
||||
|
||||
void udp_cleanup(Slirp *slirp)
|
||||
{
|
||||
while (slirp->udb.so_next != &slirp->udb) {
|
||||
udp_detach(slirp->udb.so_next);
|
||||
}
|
||||
}
|
||||
|
||||
/* m->m_data points at ip packet header
|
||||
* m->m_len length ip packet
|
||||
* ip->ip_len length data (IPDU)
|
||||
|
|
|
@ -74,6 +74,7 @@ struct udpiphdr {
|
|||
struct mbuf;
|
||||
|
||||
void udp_init(Slirp *);
|
||||
void udp_cleanup(Slirp *);
|
||||
void udp_input(register struct mbuf *, int);
|
||||
int udp_output(struct socket *, struct mbuf *, struct sockaddr_in *);
|
||||
int udp_attach(struct socket *);
|
||||
|
|
Loading…
Reference in New Issue