From 460fec67ee3807bb2eb189587ffe803a48f317e5 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 24 Jun 2009 14:42:31 +0200 Subject: slirp: Factor out internal state structure The essence of this patch is to stuff (almost) all global variables of the slirp stack into the structure Slirp. In this step, we still keep the structure as global variable, directly accessible by the whole stack. Changes to the external interface of slirp will be applied in the following patches. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori --- slirp/mbuf.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'slirp/mbuf.c') diff --git a/slirp/mbuf.c b/slirp/mbuf.c index 888de86e45..7652fea196 100644 --- a/slirp/mbuf.c +++ b/slirp/mbuf.c @@ -17,8 +17,6 @@ #include -static int mbuf_alloced; -struct mbuf m_freelist, m_usedlist; #define MBUF_THRESH 30 /* @@ -28,10 +26,10 @@ struct mbuf m_freelist, m_usedlist; #define SLIRP_MSIZE (IF_MTU + IF_MAXLINKHDR + sizeof(struct m_hdr ) + 6) void -m_init(void) +m_init(Slirp *slirp) { - m_freelist.m_next = m_freelist.m_prev = &m_freelist; - m_usedlist.m_next = m_usedlist.m_prev = &m_usedlist; + slirp->m_freelist.m_next = slirp->m_freelist.m_prev = &slirp->m_freelist; + slirp->m_usedlist.m_next = slirp->m_usedlist.m_prev = &slirp->m_usedlist; } /* @@ -43,26 +41,27 @@ m_init(void) * which tells m_free to actually free() it */ struct mbuf * -m_get(void) +m_get(Slirp *slirp) { register struct mbuf *m; int flags = 0; DEBUG_CALL("m_get"); - if (m_freelist.m_next == &m_freelist) { + if (slirp->m_freelist.m_next == &slirp->m_freelist) { m = (struct mbuf *)malloc(SLIRP_MSIZE); if (m == NULL) goto end_error; - mbuf_alloced++; - if (mbuf_alloced > MBUF_THRESH) + slirp->mbuf_alloced++; + if (slirp->mbuf_alloced > MBUF_THRESH) flags = M_DOFREE; + m->slirp = slirp; } else { - m = m_freelist.m_next; + m = slirp->m_freelist.m_next; remque(m); } /* Insert it in the used list */ - insque(m,&m_usedlist); + insque(m,&slirp->m_usedlist); m->m_flags = (flags | M_USEDLIST); /* Initialise it */ @@ -97,9 +96,9 @@ m_free(struct mbuf *m) */ if (m->m_flags & M_DOFREE) { free(m); - mbuf_alloced--; + m->slirp->mbuf_alloced--; } else if ((m->m_flags & M_FREELIST) == 0) { - insque(m,&m_freelist); + insque(m,&m->slirp->m_freelist); m->m_flags = M_FREELIST; /* Clobber other flags */ } } /* if(m) */ @@ -194,7 +193,7 @@ m_copy(struct mbuf *n, struct mbuf *m, int off, int len) * Fortunately, it's not used often */ struct mbuf * -dtom(void *dat) +dtom(Slirp *slirp, void *dat) { struct mbuf *m; @@ -202,7 +201,8 @@ dtom(void *dat) DEBUG_ARG("dat = %lx", (long )dat); /* bug corrected for M_EXT buffers */ - for (m = m_usedlist.m_next; m != &m_usedlist; m = m->m_next) { + for (m = slirp->m_usedlist.m_next; m != &slirp->m_usedlist; + m = m->m_next) { if (m->m_flags & M_EXT) { if( (char *)dat>=m->m_ext && (char *)dat<(m->m_ext + m->m_size) ) return m; -- cgit v1.2.1