⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbuf.h

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
	}

/*
 * mbuf allocation/deallocation macros:
 *
 *	MGET(struct mbuf *m, int how, int type)
 * allocates an mbuf and initializes it to contain internal data.
 *
 *	MGETHDR(struct mbuf *m, int how, int type)
 * allocates an mbuf and initializes it to contain a packet header
 * and internal data.
 */
#define	MGET(m, how, type) { \	MBUF_ALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \	if (m) { \		(m)->m_type = (type); \		MBUFLOCK(mbstat.m_mtypes[type]++;) \		(m)->m_next = (struct mbuf *)NULL; \		(m)->m_nextpkt = (struct mbuf *)NULL; \		(m)->m_data = (m)->m_dat; \		(m)->m_flags = 0; \	} else \		(m) = m_retry((how), (type)); \}

#define	MGETHDR(m, how, type) { \	MBUF_ALLOC((m), struct mbuf *, MSIZE, mbtypes[type], (how)); \	if (m) { \		(m)->m_type = (type); \		MBUFLOCK(mbstat.m_mtypes[type]++;) \		(m)->m_next = (struct mbuf *)NULL; \		(m)->m_nextpkt = (struct mbuf *)NULL; \		(m)->m_data = (m)->m_pktdat; \		(m)->m_flags = M_PKTHDR; \	} else \		(m) = m_retryhdr((how), (type)); \}

/*
 * 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.
 *
 * Normal mbuf clusters are normally treated as character arrays
 * after allocation, but use the first word of the buffer as a free list
 * pointer while on the free list.
 */
union mcluster {
	union	mcluster *mcl_next;
	char	mcl_buf[MCLBYTES];
};

#define	MCLALLOC(p, how) \	MBUFLOCK( \	  if (mclfree == 0) \		(void)m_clalloc(1, (how)); \	  if (((p) = (caddr_t)mclfree) != 0) { \		++mclrefcnt[mtocl(p)]; \		mbstat.m_clfree--; \		mclfree = ((union mcluster *)(p))->mcl_next; \	  } \	)

#define	MCLGET(m, how) \	{ MCLALLOC((m)->m_ext.ext_buf, (how)); \	  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;  \		(m)->m_ext.ext_free = NULL; \		(m)->m_ext.ext_ref = NULL; \		(m)->m_ext.ext_handle = NULL; \	  } \	}

#define	MCLFREE(p) \	MBUFLOCK ( \	  if (--mclrefcnt[mtocl(p)] == 0) { \		((union mcluster *)(p))->mcl_next = mclfree; \		mclfree = (union mcluster *)(p); \		mbstat.m_clfree++; \	  } \	)

/*
 * For cluster mbufs (regardless of header or not).
 */
#define MCL_ALIGN(m, len) \	{ (m)->m_data += (MCLBYTES - (len)) &~ (sizeof(long) -1); }

/*
 * MFREE(struct mbuf *m, struct mbuf *n)
 * Free a single mbuf and associated external storage.
 * Place the successor, if any, in n.
 */
#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); \		else \			MCLFREE((m)->m_ext.ext_buf); \	  } \	  (n) = (m)->m_next; \	  MBUF_FREE((m), mbtypes[(m)->m_type]); \	}

/*
 * Copy mbuf pkthdr from from to to.
 * from must have M_PKTHDR set, and to must be empty.
 */
#define	M_COPY_PKTHDR(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) \	{ (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) \	{ (m)->m_data += (MHLEN - (len)) &~ (sizeof(long) - 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) { \	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) { \	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
extern	struct mbuf *mbutl;		/* virtual address of mclusters */
extern	char *mclrefcnt;		/* cluster reference counts */
extern  struct	mbstat mbstat;
extern	int nmbclusters;
union	mcluster *mclfree;
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	int mbtypes[];			/* XXX */
extern	int needqueuedrain;		/* True if allocation failed at */
					/* interrupt level */

void	mbinit __P((void));
struct	mbuf *m_copym2 __P((struct mbuf *, int, int, int));
struct	mbuf *m_copym __P((struct mbuf *, int, int, int));
struct	mbuf *m_free __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_prepend __P((struct mbuf *, int, int));
struct	mbuf *m_pullup __P((struct mbuf *, int));
struct	mbuf *m_pullup2 __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_inject __P((struct mbuf *, int, int, int));
void	m_adj __P((struct mbuf *, int));
int	m_clalloc __P((int, int));
void	m_copyback __P((struct mbuf *, int, int, caddr_t));
void	m_freem __P((struct mbuf *));
void	m_reclaim __P((void));
void	m_copydata __P((struct mbuf *, int, int, caddr_t));
void	m_cat __P((struct mbuf *, struct mbuf *));
struct mbuf *m_devget __P((char *, int, int, struct ifnet *,
			   void (*) __P((const void *, void *, size_t))));
void	m_zero __P((struct mbuf *));
int	m_apply __P((struct mbuf *, int, int,
			int (*)(caddr_t, caddr_t, unsigned int), caddr_t));

#endif

#endif // _SYS_MBUF_H_

⌨️ 快捷键说明

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