Builtin slirp: Last set of updates from libslirp 4.8.0.
This commit is contained in:
parent
da41022ee2
commit
fe390c3921
@ -9,16 +9,10 @@
|
||||
|
||||
static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead)
|
||||
{
|
||||
ifm->ifs_next = ifmhead->ifs_next;
|
||||
ifmhead->ifs_next = ifm;
|
||||
ifm->ifs_prev = ifmhead;
|
||||
ifm->ifs_next->ifs_prev = ifm;
|
||||
}
|
||||
|
||||
static void ifs_remque(struct mbuf *ifm)
|
||||
{
|
||||
ifm->ifs_prev->ifs_next = ifm->ifs_next;
|
||||
ifm->ifs_next->ifs_prev = ifm->ifs_prev;
|
||||
ifm->m_nextpkt = ifmhead->m_nextpkt;
|
||||
ifmhead->m_nextpkt = ifm;
|
||||
ifm->m_prevpkt = ifmhead;
|
||||
ifm->m_nextpkt->m_prevpkt = ifm;
|
||||
}
|
||||
|
||||
void if_init(Slirp *slirp)
|
||||
@ -73,11 +67,11 @@ void if_output(struct socket *so, struct mbuf *ifm)
|
||||
if (so) {
|
||||
for (ifq = (struct mbuf *)slirp->if_batchq.qh_rlink;
|
||||
(struct slirp_quehead *)ifq != &slirp->if_batchq;
|
||||
ifq = ifq->ifq_prev) {
|
||||
if (so == ifq->ifq_so) {
|
||||
ifq = ifq->m_prev) {
|
||||
if (so == ifq->m_so) {
|
||||
/* A match! */
|
||||
ifm->ifq_so = so;
|
||||
ifs_insque(ifm, ifq->ifs_prev);
|
||||
ifm->m_so = so;
|
||||
ifs_insque(ifm, ifq->m_prevpkt);
|
||||
goto diddit;
|
||||
}
|
||||
}
|
||||
@ -91,9 +85,9 @@ void if_output(struct socket *so, struct mbuf *ifm)
|
||||
* Check if this packet is a part of the last
|
||||
* packet's session
|
||||
*/
|
||||
if (ifq->ifq_so == so) {
|
||||
ifm->ifq_so = so;
|
||||
ifs_insque(ifm, ifq->ifs_prev);
|
||||
if (ifq->m_so == so) {
|
||||
ifm->m_so = so;
|
||||
ifs_insque(ifm, ifq->m_prevpkt);
|
||||
goto diddit;
|
||||
}
|
||||
} else {
|
||||
@ -101,7 +95,7 @@ void if_output(struct socket *so, struct mbuf *ifm)
|
||||
}
|
||||
|
||||
/* Create a new doubly linked list for this session */
|
||||
ifm->ifq_so = so;
|
||||
ifm->m_so = so;
|
||||
ifs_init(ifm);
|
||||
slirp_insque(ifm, ifq);
|
||||
|
||||
@ -120,10 +114,10 @@ diddit:
|
||||
if (on_fastq &&
|
||||
((so->so_nqueued >= 6) && (so->so_nqueued - so->so_queued) >= 3)) {
|
||||
/* Remove from current queue... */
|
||||
slirp_remque(ifm->ifs_next);
|
||||
slirp_remque(ifm->m_nextpkt);
|
||||
|
||||
/* ...And insert in the new. That'll teach ya! */
|
||||
slirp_insque(ifm->ifs_next, &slirp->if_batchq);
|
||||
slirp_insque(ifm->m_nextpkt, &slirp->if_batchq);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +158,7 @@ void if_start(Slirp *slirp)
|
||||
while (ifm_next) {
|
||||
ifm = ifm_next;
|
||||
|
||||
ifm_next = ifm->ifq_next;
|
||||
ifm_next = ifm->m_next;
|
||||
if ((struct slirp_quehead *)ifm_next == &slirp->if_fastq) {
|
||||
/* No more packets in fastq, switch to batchq */
|
||||
ifm_next = batch_head;
|
||||
@ -182,12 +176,12 @@ void if_start(Slirp *slirp)
|
||||
}
|
||||
|
||||
/* Remove it from the queue */
|
||||
ifqt = ifm->ifq_prev;
|
||||
ifqt = ifm->m_prev;
|
||||
slirp_remque(ifm);
|
||||
|
||||
/* If there are more packets for this session, re-queue them */
|
||||
if (ifm->ifs_next != ifm) {
|
||||
struct mbuf *next = ifm->ifs_next;
|
||||
if (ifm->m_nextpkt != ifm) {
|
||||
struct mbuf *next = ifm->m_nextpkt;
|
||||
|
||||
slirp_insque(next, ifqt);
|
||||
ifs_remque(ifm);
|
||||
@ -197,9 +191,9 @@ void if_start(Slirp *slirp)
|
||||
}
|
||||
|
||||
/* Update so_queued */
|
||||
if (ifm->ifq_so && --ifm->ifq_so->so_queued == 0) {
|
||||
if (ifm->m_so && --ifm->m_so->so_queued == 0) {
|
||||
/* If there's no more queued, reset nqueued */
|
||||
ifm->ifq_so->so_nqueued = 0;
|
||||
ifm->m_so->so_nqueued = 0;
|
||||
}
|
||||
|
||||
m_free(ifm);
|
||||
|
@ -31,17 +31,37 @@ void m_init(Slirp *slirp)
|
||||
slirp->m_usedlist.qh_link = slirp->m_usedlist.qh_rlink = &slirp->m_usedlist;
|
||||
}
|
||||
|
||||
static void m_cleanup_list(struct slirp_quehead *list_head)
|
||||
static void m_cleanup_list(struct slirp_quehead *list_head, bool pkts)
|
||||
{
|
||||
struct mbuf *m, *next;
|
||||
struct mbuf *m, *next, *next2;
|
||||
bool last;
|
||||
|
||||
m = (struct mbuf *)list_head->qh_link;
|
||||
while ((struct slirp_quehead *)m != list_head) {
|
||||
next = m->m_next;
|
||||
if (m->m_flags & M_EXT) {
|
||||
free(m->m_ext);
|
||||
}
|
||||
free(m);
|
||||
|
||||
last = false;
|
||||
while (1) {
|
||||
next2 = m->m_nextpkt;
|
||||
|
||||
if (pkts) {
|
||||
ifs_remque(m);
|
||||
last = next2 == m;
|
||||
} else {
|
||||
last = true;
|
||||
}
|
||||
|
||||
if (m->m_flags & M_EXT) {
|
||||
free(m->m_ext);
|
||||
}
|
||||
|
||||
free(m);
|
||||
|
||||
if (last)
|
||||
break;
|
||||
m = next2;
|
||||
};
|
||||
|
||||
m = next;
|
||||
}
|
||||
list_head->qh_link = list_head;
|
||||
@ -50,10 +70,10 @@ static void m_cleanup_list(struct slirp_quehead *list_head)
|
||||
|
||||
void m_cleanup(Slirp *slirp)
|
||||
{
|
||||
m_cleanup_list(&slirp->m_usedlist);
|
||||
m_cleanup_list(&slirp->m_freelist);
|
||||
m_cleanup_list(&slirp->if_batchq);
|
||||
m_cleanup_list(&slirp->if_fastq);
|
||||
m_cleanup_list(&slirp->m_usedlist, false);
|
||||
m_cleanup_list(&slirp->m_freelist, false);
|
||||
m_cleanup_list(&slirp->if_batchq, true);
|
||||
m_cleanup_list(&slirp->if_fastq, true);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -152,7 +172,7 @@ void m_inc(struct mbuf *m, int size)
|
||||
int gapsize;
|
||||
|
||||
/* some compilers throw up on gotos. This one we can fake. */
|
||||
if (M_ROOM(m) > size) {
|
||||
if (M_ROOM(m) >= size) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -242,8 +262,9 @@ struct mbuf *m_dup(Slirp *slirp, struct mbuf *m,
|
||||
if (copy_header) {
|
||||
m->m_len += header_size;
|
||||
m->m_data -= header_size;
|
||||
mcopy_result = m_copy(n, m, 0, m->m_len + header_size);
|
||||
mcopy_result = m_copy(n, m, 0, m->m_len);
|
||||
n->m_data += header_size;
|
||||
n->m_len -= header_size;
|
||||
m->m_len -= header_size;
|
||||
m->m_data += header_size;
|
||||
} else {
|
||||
|
@ -103,11 +103,11 @@ struct mbuf {
|
||||
char m_dat[];
|
||||
};
|
||||
|
||||
#define ifq_prev m_prev
|
||||
#define ifq_next m_next
|
||||
#define ifs_prev m_prevpkt
|
||||
#define ifs_next m_nextpkt
|
||||
#define ifq_so m_so
|
||||
static inline void ifs_remque(struct mbuf *ifm)
|
||||
{
|
||||
ifm->m_prevpkt->m_nextpkt = ifm->m_nextpkt;
|
||||
ifm->m_nextpkt->m_prevpkt = ifm->m_prevpkt;
|
||||
}
|
||||
|
||||
#define M_EXT 0x01 /* m_ext points to more (malloced) data */
|
||||
#define M_FREELIST 0x02 /* mbuf is on free list */
|
||||
@ -164,7 +164,7 @@ void *m_end(struct mbuf *);
|
||||
/* Initialize the ifs queue of the mbuf */
|
||||
static inline void ifs_init(struct mbuf *ifm)
|
||||
{
|
||||
ifm->ifs_next = ifm->ifs_prev = ifm;
|
||||
ifm->m_nextpkt = ifm->m_prevpkt = ifm;
|
||||
}
|
||||
|
||||
#ifdef SLIRP_DEBUG
|
||||
|
@ -70,12 +70,12 @@ static void soqfree(struct socket *so, struct slirp_quehead *qh)
|
||||
struct mbuf *ifq;
|
||||
|
||||
for (ifq = (struct mbuf *)qh->qh_link; (struct slirp_quehead *)ifq != qh;
|
||||
ifq = ifq->ifq_next) {
|
||||
if (ifq->ifq_so == so) {
|
||||
ifq = ifq->m_next) {
|
||||
if (ifq->m_so == so) {
|
||||
struct mbuf *ifm;
|
||||
ifq->ifq_so = NULL;
|
||||
for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) {
|
||||
ifm->ifq_so = NULL;
|
||||
ifq->m_so = NULL;
|
||||
for (ifm = ifq->m_nextpkt; ifm != ifq; ifm = ifm->m_nextpkt) {
|
||||
ifm->m_so = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user