mbuf.h

来自「eCos操作系统源码」· C头文件 代码 · 共 642 行 · 第 1/2 页

H
642
字号
									\	if (mmbfree == NULL)						\		(void)m_mballoc(1, _mhow);				\	_mm = mmbfree;							\	if (_mm != NULL) {						\		mmbfree = _mm->m_next;					\		mbtypes[MT_FREE]--;					\		_mm->m_type = _mtype;					\		mbtypes[_mtype]++;					\		_mm->m_next = NULL;					\		_mm->m_nextpkt = NULL;					\		_mm->m_data = _mm->m_dat;				\		_mm->m_flags = 0;					\		(m) = _mm;						\		splx(_ms);						\	} else {							\		splx(_ms);						\		_mm = m_retry(_mhow, _mtype);				\		if (_mm == NULL && _mhow == M_WAIT)			\			(m) = m_mballoc_wait(MGET_C, _mtype);		\		else							\			(m) = _mm;					\	}								\} while (0)#define	MGETHDR(m, how, type) do {					\	struct mbuf *_mm;						\	int _mhow = (how);						\	int _mtype = (type);						\	int _ms = splimp();						\									\	if (mmbfree == NULL)						\		(void)m_mballoc(1, _mhow);				\	_mm = mmbfree;							\	if (_mm != NULL) {						\		mmbfree = _mm->m_next;					\		mbtypes[MT_FREE]--;					\		_mm->m_type = _mtype;					\		mbtypes[_mtype]++;					\		_mm->m_next = NULL;					\		_mm->m_nextpkt = NULL;					\		_mm->m_data = _mm->m_pktdat;				\		_mm->m_flags = M_PKTHDR;				\		bzero(&(_mm)->m_pkthdr, sizeof((_mm)->m_pkthdr));	\		(m) = _mm;						\		splx(_ms);						\	} else {							\		splx(_ms);						\		_mm = m_retryhdr(_mhow, _mtype);			\		if (_mm == NULL && _mhow == M_WAIT)			\			(m) = m_mballoc_wait(MGETHDR_C, _mtype);	\		else							\			(m) = _mm;					\	}								\} while (0)/* * Mbuf cluster macros. * MCLALLOC(caddr_t p, int how) allocates an mbuf cluster. * MCLGET adds such clusters to a normal mbuf; * the flag M_EXT is set upon success. * MCLFREE releases a reference to a cluster allocated by MCLALLOC, * freeing the cluster if the reference count has reached 0. */#define	MCLALLOC(p, how) do {						\	caddr_t _mp;							\	int _mhow = (how);						\	int _ms = splimp();						\									\	if (mclfree == NULL)						\		(void)m_clalloc(1, _mhow);				\	_mp = (caddr_t)mclfree;						\	if (_mp != NULL) {						\		mclrefcnt[mtocl(_mp)]++;				\		mbstat.m_clfree--;					\		mclfree = ((union mcluster *)_mp)->mcl_next;		\		(p) = _mp;						\		splx(_ms);						\	} else {							\		splx(_ms);						\		if (_mhow == M_WAIT)					\			(p) = m_clalloc_wait();				\		else							\			(p) = NULL;					\	}								\} while (0)	#define	MCLGET(m, how) do {						\	struct mbuf *_mm = (m);						\									\	MCLALLOC(_mm->m_ext.ext_buf, (how));				\	if (_mm->m_ext.ext_buf != NULL) {				\		_mm->m_data = _mm->m_ext.ext_buf;			\		_mm->m_flags |= M_EXT;					\		_mm->m_ext.ext_free = NULL;				\		_mm->m_ext.ext_ref = NULL;				\		_mm->m_ext.ext_size = MCLBYTES;				\	}								\} while (0)#define	MCLFREE1(p) do {						\	union mcluster *_mp = (union mcluster *)(p);			\									\	/* KASSERT(mclrefcnt[mtocl(_mp)] > 0, ("freeing free cluster")); */	\	if (--mclrefcnt[mtocl(_mp)] == 0) {				\		_mp->mcl_next = mclfree;				\		mclfree = _mp;						\		mbstat.m_clfree++;					\		MCLWAKEUP();						\	}								\} while (0)#define	MCLFREE(p) MBUFLOCK(						\	MCLFREE1(p);							\)#define	MEXTFREE1(m) do {						\		struct mbuf *_mm = (m);					\									\		if (_mm->m_ext.ext_free != NULL)			\			(*_mm->m_ext.ext_free)(_mm->m_ext.ext_buf,	\		    	    _mm->m_ext.ext_size);			\		else							\			MCLFREE1(_mm->m_ext.ext_buf);			\} while (0)#define	MEXTFREE(m) MBUFLOCK(						\	MEXTFREE1(m);							\)/* * MFREE(struct mbuf *m, struct mbuf *n) * Free a single mbuf and associated external storage. * Place the successor, if any, in n. * * we do need to check non-first mbuf for m_aux, since some of existing * code does not call M_PREPEND properly. * (example: call to bpf_mtap from drivers) */#define	MFREE(m, n) MBUFLOCK(						\	struct mbuf *_mm = (m);						\									\	/* KASSERT(_mm->m_type != MT_FREE, ("freeing free mbuf")); */		\	mbtypes[_mm->m_type]--;						\	if ((_mm->m_flags & M_PKTHDR) != 0 && _mm->m_pkthdr.aux) {	\		m_freem(_mm->m_pkthdr.aux);				\		_mm->m_pkthdr.aux = NULL;				\	}								\	if (_mm->m_flags & M_EXT)					\		MEXTFREE1(m);						\	(n) = _mm->m_next;						\	_mm->m_type = MT_FREE;						\	mbtypes[MT_FREE]++;						\	_mm->m_next = mmbfree;						\	mmbfree = _mm;							\	MMBWAKEUP();							\)/* * Copy mbuf pkthdr from "from" to "to". * from must have M_PKTHDR set, and to must be empty. * aux pointer will be moved to `to'. */#define	M_COPY_PKTHDR(to, from) do {					\	struct mbuf *_mfrom = (from);					\	struct mbuf *_mto = (to);					\									\	_mto->m_data = _mto->m_pktdat;					\	_mto->m_flags = _mfrom->m_flags & M_COPYFLAGS;			\	_mto->m_pkthdr = _mfrom->m_pkthdr;				\	_mfrom->m_pkthdr.aux = (struct mbuf *)NULL;			\} while (0)/* * 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) do {						\	(m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1);		\} while (0)/* * As above, for mbufs allocated with m_gethdr/MGETHDR * or initialized by M_COPY_PKTHDR. */#define	MH_ALIGN(m, len) do {						\	(m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1);		\} while (0)/* * Check if we can write to an mbuf. */#define M_WRITABLE(m) (!((m)->m_flags & M_EXT) || \    ((m)->m_ext.ext_free == NULL && mclrefcnt[mtocl((m)->m_ext.ext_buf)] == 1))/* * Compute the amount of space available * before the current start of data in an mbuf. */#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)/* * Compute the amount of space available * after the end of data in an mbuf. */#define	M_TRAILINGSPACE(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) do {					\	struct mbuf **_mmp = &(m);					\	struct mbuf *_mm = *_mmp;					\	int _mplen = (plen);						\	int __mhow = (how);						\									\	if (M_LEADINGSPACE(_mm) >= _mplen) {				\		_mm->m_data -= _mplen;					\		_mm->m_len += _mplen;					\	} else								\		_mm = m_prepend(_mm, _mplen, __mhow);			\	if (_mm != NULL && _mm->m_flags & M_PKTHDR)			\		_mm->m_pkthdr.len += _mplen;				\	*_mmp = _mm;							\} while (0)/* change mbuf to new type */#define	MCHTYPE(m, t) do {						\	struct mbuf *_mm = (m);						\	int _mt = (t);							\	int _ms = splimp();						\									\	mbtypes[_mm->m_type]--;						\	mbtypes[_mt]++;							\	splx(_ms);							\	_mm->m_type = (_mt);						\} while (0)/* length to m_copy to copy all */#define	M_COPYALL	1000000000/* compatibility with 4.3 */#define	m_copy(m, o, l)	m_copym((m), (o), (l), M_DONTWAIT)/* * pkthdr.aux type tags. */struct mauxtag {	int	af;	int	type;	void*	p;};#ifdef _KERNELextern	u_int		 m_clalloc_wid;	/* mbuf cluster wait count */extern	u_int		 m_mballoc_wid;	/* mbuf wait count */extern	int		 max_linkhdr;	/* largest link-level header */extern	int		 max_protohdr;	/* largest protocol header */extern	int		 max_hdr;	/* largest link+protocol header */extern	int		 max_datalen;	/* MHLEN - max_hdr */extern	struct mbstat	 mbstat;extern	u_long		 mbtypes[MT_NTYPES]; /* per-type mbuf allocations */extern	int		 mbuf_wait;	/* mbuf sleep time */extern	struct mbuf	*mbutl;		/* virtual address of mclusters */extern	char		*mclrefcnt;	/* cluster reference counts */extern	union mcluster	*mclfree;extern	struct mbuf	*mmbfree;extern	int		 nmbclusters;extern	int		 nmbufs;extern	int		 nsfbufs;void	m_adj __P((struct mbuf *, int));void	m_cat __P((struct mbuf *,struct mbuf *));int	m_clalloc __P((int, int));caddr_t	m_clalloc_wait __P((void));void	m_copyback __P((struct mbuf *, int, int, caddr_t));void	m_copydata __P((struct mbuf *,int,int,caddr_t));struct	mbuf *m_copym __P((struct mbuf *, int, int, int));struct	mbuf *m_copypacket __P((struct mbuf *, int));struct	mbuf *m_devget __P((char *, int, int, struct ifnet *,    void (*copy)(char *, caddr_t, u_int)));struct	mbuf *m_dup __P((struct mbuf *, int));struct	mbuf *m_free __P((struct mbuf *));void	m_freem __P((struct mbuf *));struct	mbuf *m_get __P((int, int));struct	mbuf *m_getclr __P((int, int));struct	mbuf *m_gethdr __P((int, int));struct	mbuf *m_getm __P((struct mbuf *, int, int, int));int	m_mballoc __P((int, int));struct	mbuf *m_mballoc_wait __P((int, int));struct	mbuf *m_prepend __P((struct mbuf *,int,int));struct	mbuf *m_pulldown __P((struct mbuf *, int, int, int *));void	m_print __P((const struct mbuf *m));struct	mbuf *m_pullup __P((struct mbuf *, int));struct	mbuf *m_retry __P((int, int));struct	mbuf *m_retryhdr __P((int, int));struct	mbuf *m_split __P((struct mbuf *,int,int));struct	mbuf *m_aux_add2 __P((struct mbuf *, int, int, void *));struct	mbuf *m_aux_find2 __P((struct mbuf *, int, int, void *));struct	mbuf *m_aux_add __P((struct mbuf *, int, int));struct	mbuf *m_aux_find __P((struct mbuf *, int, int));void	m_aux_delete __P((struct mbuf *, struct mbuf *));extern void *cyg_net_mbuf_alloc(void);extern void *cyg_net_cluster_alloc(void );#ifdef CYGDBG_NET_SHOW_MBUFS                extern void cyg_net_show_mbufs(void);#endif#endif /* _KERNEL */#endif /* !_SYS_MBUF_H_ */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?