more spl's so the mbuf counters don't go wacky, also repair cltom()

This commit is contained in:
deraadt 1994-04-15 05:10:31 +00:00
parent e28a360811
commit a35608603b
1 changed files with 22 additions and 14 deletions

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)mbuf.h 7.14 (Berkeley) 12/5/90
* $Id: mbuf.h,v 1.5 1994/02/09 20:54:46 mycroft Exp $
* $Id: mbuf.h,v 1.6 1994/04/15 05:10:31 deraadt Exp $
*/
#ifndef _SYS_MBUF_H_
@ -65,7 +65,7 @@
#define mtod(m,t) ((t)((m)->m_data))
#define dtom(x) ((struct mbuf *)((int)(x) & ~(MSIZE-1)))
#define mtocl(x) (((u_int)(x) - (u_int)mbutl) >> MCLSHIFT)
#define cltom(x) ((caddr_t)((u_int)mbutl + ((u_int)(x) >> MCLSHIFT)))
#define cltom(x) ((caddr_t)((u_int)mbutl + ((u_int)(x) << MCLSHIFT)))
/* header at beginning of each mbuf: */
struct m_hdr {
@ -151,6 +151,10 @@ struct mbuf {
/*
* mbuf allocation/deallocation macros:
*
* MBUFLOCK(code)
* lock out network interrupt drivers for duration of this particular
* operation
*
* MGET(struct mbuf *m, int how, int type)
* allocates an mbuf and initializes it to contain internal data.
*
@ -158,11 +162,18 @@ struct mbuf {
* allocates an mbuf and initializes it to contain a packet header
* and internal data.
*/
#define MBUFLOCK(code) \
{ \
int ms = splimp(); \
{ code } \
splx(ms); \
}
#define MGET(m, how, type) { \
MALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \
if (m) { \
(m)->m_type = (type); \
mbstat.m_mtypes[type]++; \
MBUFLOCK(mbstat.m_mtypes[type]++;) \
(m)->m_next = (struct mbuf *)NULL; \
(m)->m_nextpkt = (struct mbuf *)NULL; \
(m)->m_data = (m)->m_dat; \
@ -175,7 +186,7 @@ struct mbuf {
MALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \
if (m) { \
(m)->m_type = (type); \
mbstat.m_mtypes[type]++; \
MBUFLOCK(mbstat.m_mtypes[type]++;) \
(m)->m_next = (struct mbuf *)NULL; \
(m)->m_nextpkt = (struct mbuf *)NULL; \
(m)->m_data = (m)->m_pktdat; \
@ -202,7 +213,7 @@ union mcluster {
};
#define MCLALLOC(p, how) \
{ int ms = splimp(); \
MBUFLOCK( \
if (mclfree == 0) \
(void)m_clalloc(1, (how)); \
if ((p) = (caddr_t)mclfree) { \
@ -210,8 +221,7 @@ union mcluster {
mbstat.m_clfree--; \
mclfree = ((union mcluster *)(p))->mcl_next; \
} \
splx(ms); \
}
)
#define MCLGET(m, how) \
{ MCLALLOC((m)->m_ext.ext_buf, (how)); \
@ -223,14 +233,13 @@ union mcluster {
}
#define MCLFREE(p) \
{ int ms = splimp(); \
MBUFLOCK( \
if (--mclrefcnt[mtocl(p)] == 0) { \
((union mcluster *)(p))->mcl_next = mclfree; \
mclfree = (union mcluster *)(p); \
mbstat.m_clfree++; \
} \
splx(ms); \
}
)
/*
* MFREE(struct mbuf *m, struct mbuf *n)
@ -239,7 +248,7 @@ union mcluster {
*/
#ifdef notyet
#define MFREE(m, n) \
{ mbstat.m_mtypes[(m)->m_type]--; \
{ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
if ((m)->m_flags & M_EXT) { \
if ((m)->m_ext.ext_free) \
(*((m)->m_ext.ext_free))((m)->m_ext.ext_buf, \
@ -252,7 +261,7 @@ union mcluster {
}
#else /* notyet */
#define MFREE(m, nn) \
{ mbstat.m_mtypes[(m)->m_type]--; \
{ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
if ((m)->m_flags & M_EXT) { \
MCLFREE((m)->m_ext.ext_buf); \
} \
@ -320,8 +329,7 @@ union mcluster {
/* change mbuf to new type */
#define MCHTYPE(m, t) { \
mbstat.m_mtypes[(m)->m_type]--; \
mbstat.m_mtypes[t]++; \
MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--; mbstat.m_mtypes[t]++;) \
(m)->m_type = t;\
}