📄 mbuf.h
字号:
* pointer while on the free list.
*/
union mcluster {
union mcluster *mcl_next;
char mcl_buf[MCLBYTES];
};
#define MCLALLOC(p, how) \
MBUFLOCK( \
OS_DbgPrint(OSK_MID_TRACE,("(MCLALLOC)\n")); \
if (mclfree == 0) \
(void)m_clalloc(1, (how)); \
(p) = (caddr_t)mclfree; \
if ((p)) { \
++mclrefcnt[mtocl(p)]; \
mbstat.m_clfree--; \
mclfree = ((union mcluster *)(p))->mcl_next; \
} \
)
#ifdef __REACTOS__
#define MCLGET(m, how) { \
OS_DbgPrint(OSK_MID_TRACE,("(MCLGET) m = %x\n", m)); \
(m)->m_ext.ext_buf = malloc(MCLBYTES,__FILE__,__LINE__); \
if ((m)->m_ext.ext_buf != NULL) { \
(m)->m_data = (m)->m_ext.ext_buf; \
(m)->m_flags |= M_EXT; \
(m)->m_ext.ext_size = MCLBYTES; \
} \
}
#define MCLFREE(p) { \
free( (p), 0 ); \
}
#else
#define MCLGET(m, how) \
{ MCLALLOC((m)->m_ext.ext_buf, (how)); \
OS_DbgPrint(OSK_MID_TRACE,("(MCLGET) m = %x\n", m)); \
if ((m)->m_ext.ext_buf != NULL) { \
(m)->m_data = (m)->m_ext.ext_buf; \
(m)->m_flags |= M_EXT; \
(m)->m_ext.ext_size = MCLBYTES; \
} \
}
#define MCLFREE(p) \
MBUFLOCK ( \
OS_DbgPrint(OSK_MID_TRACE,("(MCLFREE)\n")); \
if (--mclrefcnt[mtocl(p)] == 0) { \
((union mcluster *)(p))->mcl_next = mclfree; \
mclfree = (union mcluster *)(p); \
mbstat.m_clfree++; \
} \
)
#endif
#else
#define MCLGET(m, how) \
{ (m)->m_ext.ext_bufio = oskit_bufio_create(MCLBYTES); \
OS_DbgPrint(OSK_MID_TRACE,("(!OSKIT MCLGET)\n")); \
oskit_bufio_map((m)->m_ext.ext_bufio, \
(void **)&((m)->m_ext.ext_buf), 0, MCLBYTES); \
if ((m)->m_ext.ext_buf != NULL) { \
(m)->m_data = (m)->m_ext.ext_buf; \
(m)->m_flags |= M_EXT; \
(m)->m_ext.ext_size = MCLBYTES; \
} \
}
#endif /* !OSKIT */
/*
* MFREE(struct mbuf *m, struct mbuf *n)
* Free a single mbuf and associated external storage.
* Place the successor, if any, in n.
*/
#ifdef notyet
#define MFREE(m, n) \
{ 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, \
(m)->m_ext.ext_size); \
else \
MCLFREE((m)->m_ext.ext_buf); \
} \
(n) = (m)->m_next; \
FREE((m), mbtypes[(m)->m_type]); \
m = NULL; \
}
#else /* notyet */
#ifdef OSKIT
#define MFREE(m, nn) \
{ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
OS_DbgPrint(OSK_MID_TRACE,("(OSKIT MFREE) m = %x\n", m)); \
if ((m)->m_flags & M_EXT) { \
oskit_bufio_release((m)->m_ext.ext_bufio); \
} \
(nn) = (m)->m_next; \
FREE((m), mbtypes[(m)->m_type]); \
m = NULL; \
}
#else /* !OSKIT */
#define MFREE(m, nn) \
{ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
OS_DbgPrint(OSK_MID_TRACE,("(!OSKIT MFREE) m = %x\n", m)); \
if ((m)->m_flags & M_EXT) { \
MCLFREE((m)->m_ext.ext_buf); \
} \
(nn) = (m)->m_next; \
FREE((m), mbtypes[(m)->m_type]); \
m = NULL; \
}
#endif /* OSKIT */
#endif
/*
* Copy mbuf pkthdr from from to to.
* from must have M_PKTHDR set, and to must be empty.
*/
#define M_COPY_PKTHDR(to, from) { \
OS_DbgPrint(OSK_MID_TRACE,("(M_COPY_PKTHDR) to %x from %x\n", to, from)); \
(to)->m_pkthdr = (from)->m_pkthdr; \
(to)->m_flags = (from)->m_flags & M_COPYFLAGS; \
(to)->m_data = (to)->m_pktdat; \
}
/*
* Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
* an object of the specified size at the end of the mbuf, longword aligned.
*/
#define M_ALIGN(m, len) \
{ \
OS_DbgPrint(OSK_MID_TRACE,("(M_ALIGN) %d @ %x\n", m, len)); \
(m)->m_data += (MLEN - (len)) &~ (sizeof(long) - 1); \
}
/*
* As above, for mbufs allocated with m_gethdr/MGETHDR
* or initialized by M_COPY_PKTHDR.
*/
#define MH_ALIGN(m, len) \
{ \
OS_DbgPrint(OSK_MID_TRACE,("(MH_ALIGN) %d @ %x\n", m, len)); \
(m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 1); \
}
/*
* Compute the amount of space available
* before the current start of data in an mbuf.
*/
#ifdef OSKIT
/* Be bold and strong: why shouldn't that work??? */
#define M_LEADINGSPACE(m) \
((m)->m_flags & M_EXT ? (m)->m_data - (m)->m_ext.ext_buf : \
(m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
(m)->m_data - (m)->m_dat)
#else
#define M_LEADINGSPACE(m) \
((m)->m_flags & M_EXT ? /* (m)->m_data - (m)->m_ext.ext_buf */ 0 : \
(m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
(m)->m_data - (m)->m_dat)
#endif /* OSKIT */
/*
* Compute the amount of space available
* after the end of data in an mbuf.
*/
#define M_TRAILINGSPACE(m) \
OS_DbgPrint(OSK_MID_TRACE,("(M_TRAILINGSPACE) %x\n", m)); \
((m)->m_flags & M_EXT ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size - \
((m)->m_data + (m)->m_len) : \
&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
/*
* Arrange to prepend space of size plen to mbuf m.
* If a new mbuf must be allocated, how specifies whether to wait.
* If how is M_DONTWAIT and allocation fails, the original mbuf chain
* is freed and m is set to NULL.
*/
#define M_PREPEND(m, plen, how) { \
OS_DbgPrint(OSK_MID_TRACE,("(M_PREPEND) %d on %x\n", plen, m)); \
if (M_LEADINGSPACE(m) >= (plen)) { \
(m)->m_data -= (plen); \
(m)->m_len += (plen); \
} else \
(m) = m_prepend((m), (plen), (how)); \
if ((m) && (m)->m_flags & M_PKTHDR) \
(m)->m_pkthdr.len += (plen); \
}
/* change mbuf to new type */
#define MCHTYPE(m, t) { \
OS_DbgPrint(OSK_MID_TRACE,("(MCHTYPE) %x %x\n", m, t)); \
MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--; mbstat.m_mtypes[t]++;) \
(m)->m_type = t;\
}
/* length to m_copy to copy all */
#define M_COPYALL 1000000000
/* compatiblity with 4.3 */
#define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT)
/*
* Mbuf statistics.
*/
struct mbstat {
u_long m_mbufs; /* mbufs obtained from page pool */
u_long m_clusters; /* clusters obtained from page pool */
u_long m_spare; /* spare field */
u_long m_clfree; /* free clusters */
u_long m_drops; /* times failed to find space */
u_long m_wait; /* times waited for space */
u_long m_drain; /* times drained protocols for space */
u_short m_mtypes[256]; /* type specific mbuf allocations */
};
#ifdef KERNEL
#ifndef OSKIT
extern struct mbuf *mbutl; /* virtual address of mclusters */
extern char *mclrefcnt; /* cluster reference counts */
#endif /* !OSKIT */
struct mbstat mbstat;
#ifndef OSKIT
extern int nmbclusters;
union mcluster *mclfree;
#endif /* !OSKIT */
int max_linkhdr; /* largest link-level header */
int max_protohdr; /* largest protocol header */
int max_hdr; /* largest link+protocol header */
int max_datalen; /* MHLEN - max_hdr */
extern int mbtypes[]; /* XXX */
int m_clalloc __P((int, int));
void m_copyback __P((struct mbuf *, int, int, caddr_t));
struct mbuf *m_retry __P((int, int));
struct mbuf *m_retryhdr __P((int, int));
void m_reclaim __P((void));
struct mbuf *m_get __P((int, int));
struct mbuf *m_gethdr __P((int, int));
struct mbuf *m_getclr __P((int, int));
struct mbuf *m_free __P((struct mbuf *));
void m_freem __P((struct mbuf *));
struct mbuf *m_prepend __P((struct mbuf *,int,int));
struct mbuf *m_copym __P((struct mbuf *, int, int, int));
void m_copydata __P((struct mbuf *,int,int,caddr_t));
void m_cat __P((struct mbuf *,struct mbuf *));
void m_adj __P((struct mbuf *,int));
struct mbuf *m_pullup __P((struct mbuf *, int));
struct mbuf *m_split __P((struct mbuf *,int,int));
struct mbuf *m_devget __P((char *, int, int, struct ifnet *,
void (*copy)(struct mbuf *, caddr_t, u_int)));
#ifdef MBTYPES
int mbtypes[] = { /* XXX */
M_FREE, /* MT_FREE 0 should be on free list */
M_MBUF, /* MT_DATA 1 dynamic (data) allocation */
M_MBUF, /* MT_HEADER 2 packet header */
M_SOCKET, /* MT_SOCKET 3 socket structure */
M_PCB, /* MT_PCB 4 protocol control block */
M_RTABLE, /* MT_RTABLE 5 routing tables */
M_HTABLE, /* MT_HTABLE 6 IMP host tables */
0, /* MT_ATABLE 7 address resolution tables */
M_MBUF, /* MT_SONAME 8 socket name */
0, /* 9 */
M_SOOPTS, /* MT_SOOPTS 10 socket options */
M_FTABLE, /* MT_FTABLE 11 fragment reassembly header */
M_MBUF, /* MT_RIGHTS 12 access rights */
M_IFADDR, /* MT_IFADDR 13 interface address */
M_MBUF, /* MT_CONTROL 14 extra-data protocol message */
M_MBUF, /* MT_OOBDATA 15 expedited data */
#ifdef DATAKIT
25, 26, 27, 28, 29, 30, 31, 32 /* datakit ugliness */
#endif
};
#endif
#endif
#ifdef LOCAL_OSKIT_DEFINED
#undef LOCAL_OSKIT_DEFINED
#undef OSKIT
#endif
#endif /* !_SYS_MBUF_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -