📄 mbuf.h
字号:
//==========================================================================
//
// include/sys/mbuf.h
//
//==========================================================================
//####BSDCOPYRIGHTBEGIN####
//
// -------------------------------------------
//
// Portions of this software may have been derived from OpenBSD,
// FreeBSD or other sources, and are covered by the appropriate
// copyright disclaimers included herein.
//
// Portions created by Red Hat are
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
//
// -------------------------------------------
//
//####BSDCOPYRIGHTEND####
//==========================================================================
/*
* Copyright (c) 1982, 1986, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mbuf.h 8.5 (Berkeley) 2/19/95
* $FreeBSD: src/sys/sys/mbuf.h,v 1.44.2.10 2001/07/03 11:02:01 ume Exp $
*/
#ifndef _SYS_MBUF_H_
#define _SYS_MBUF_H_
/*
* Mbufs are of a single size, MSIZE (machine/param.h), which
* includes overhead. An mbuf may add a single "mbuf cluster" of size
* MCLBYTES (also in machine/param.h), which has no additional overhead
* and is used instead of the internal data area; this is done when
* at least MINCLSIZE of data must be stored.
*/
#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
#define MINCLSIZE (MHLEN + 1) /* smallest amount to put in cluster */
#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
/*
* Macros for type conversion
* mtod(m, t) - convert mbuf pointer to data pointer of correct type
* dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX)
* mtocl(x) - convert pointer within cluster to cluster index #
* cltom(x) - convert cluster # to ptr to beginning of cluster
*/
#define mtod(m, t) ((t)((m)->m_data))
#define dtom(x) ((struct mbuf *)((CYG_ADDRESS)(x) & ~(MSIZE-1)))
extern int cyg_mtocl(u_long);
extern struct mbuf *cyg_cltom(u_long);
#define mtocl(x) cyg_mtocl((u_long)x)
#define cltom(x) cyg_cltom((u_long)x)
/* header at beginning of each mbuf: */
struct m_hdr {
struct mbuf *mh_next; /* next buffer in chain */
struct mbuf *mh_nextpkt; /* next chain in queue/record */
caddr_t mh_data; /* location of data */
int mh_len; /* amount of data in this mbuf */
short mh_type; /* type of data in this mbuf */
short mh_flags; /* flags; see below */
};
/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
struct pkthdr {
struct ifnet *rcvif; /* rcv interface */
int len; /* total packet length */
/* variables for ip and tcp reassembly */
void *header; /* pointer to packet header */
/* variables for hardware checksum */
int csum_flags; /* flags regarding checksum */
int csum_data; /* data field used by csum routines */
struct mbuf *aux; /* extra data buffer; ipsec/others */
};
/* description of external storage mapped into mbuf, valid if M_EXT set */
struct m_ext {
caddr_t ext_buf; /* start of buffer */
void (*ext_free) /* free routine if not the usual */
__P((caddr_t, u_int));
u_int ext_size; /* size of buffer, for ext_free */
void (*ext_ref) /* add a reference to the ext object */
__P((caddr_t, u_int));
};
struct mbuf {
struct m_hdr m_hdr;
union {
struct {
struct pkthdr MH_pkthdr; /* M_PKTHDR set */
union {
struct m_ext MH_ext; /* M_EXT set */
char MH_databuf[MHLEN];
} MH_dat;
} MH;
char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
} M_dat;
};
#define m_next m_hdr.mh_next
#define m_len m_hdr.mh_len
#define m_data m_hdr.mh_data
#define m_type m_hdr.mh_type
#define m_flags m_hdr.mh_flags
#define m_nextpkt m_hdr.mh_nextpkt
#define m_act m_nextpkt
#define m_pkthdr M_dat.MH.MH_pkthdr
#define m_ext M_dat.MH.MH_dat.MH_ext
#define m_pktdat M_dat.MH.MH_dat.MH_databuf
#define m_dat M_dat.M_databuf
/* mbuf flags */
#define M_EXT 0x0001 /* has associated external storage */
#define M_PKTHDR 0x0002 /* start of record */
#define M_EOR 0x0004 /* end of record */
#define M_PROTO1 0x0008 /* protocol-specific */
#define M_PROTO2 0x0010 /* protocol-specific */
#define M_PROTO3 0x0020 /* protocol-specific */
#define M_PROTO4 0x0040 /* protocol-specific */
#define M_PROTO5 0x0080 /* protocol-specific */
#define M_PROTO6 0x2000 /* protocol-specific */
/* mbuf pkthdr flags, also in m_flags */
#define M_BCAST 0x0100 /* send/received as link-level broadcast */
#define M_MCAST 0x0200 /* send/received as link-level multicast */
#define M_FRAG 0x0400 /* packet is a fragment of a larger packet */
#define M_FIRSTFRAG 0x0800 /* packet is first fragment */
#define M_LASTFRAG 0x1000 /* packet is last fragment */
#define M_AUX 0x4000 /* mbufs pointed to by m->m_pkthdr.aux */
/* flags copied when copying m_pkthdr */
#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO1|M_PROTO2|M_PROTO3| \ M_PROTO4|M_PROTO5|M_PROTO6|M_BCAST|M_MCAST|M_FRAG| \ M_AUX)
/* flags indicating hw checksum support and sw checksum requirements */
#define CSUM_IP 0x0001 /* will csum IP */
#define CSUM_TCP 0x0002 /* will csum TCP */
#define CSUM_UDP 0x0004 /* will csum UDP */
#define CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
#define CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
#define CSUM_IP_CHECKED 0x0100 /* did csum IP */
#define CSUM_IP_VALID 0x0200 /* ... the csum is valid */
#define CSUM_DATA_VALID 0x0400 /* csum_data field is valid */
#define CSUM_PSEUDO_HDR 0x0800 /* csum_data has pseudo hdr */
#define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP)
#define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */
/* mbuf types */
#define MT_FREE 0 /* should be on free list */
#define MT_DATA 1 /* dynamic (data) allocation */
#define MT_HEADER 2 /* packet header */
#if 0
#define MT_SOCKET 3 /* socket structure */
#define MT_PCB 4 /* protocol control block */
#define MT_RTABLE 5 /* routing tables */
#define MT_HTABLE 6 /* IMP host tables */
#define MT_ATABLE 7 /* address resolution tables */
#endif
#define MT_SONAME 8 /* socket name */
#if 0
#define MT_SOOPTS 10 /* socket options */
#endif
#define MT_FTABLE 11 /* fragment reassembly header */
#if 0
#define MT_RIGHTS 12 /* access rights */
#define MT_IFADDR 13 /* interface address */
#endif
#define MT_CONTROL 14 /* extra-data protocol message */
#define MT_OOBDATA 15 /* expedited data */
#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */
/*
* 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_long m_mcfail; /* times m_copym failed */
u_long m_mpfail; /* times m_pullup failed */
u_long m_msize; /* length of an mbuf */
u_long m_mclbytes; /* length of an mbuf cluster */
u_long m_minclsize; /* min length of data to allocate a cluster */
u_long m_mlen; /* length of data in an mbuf */
u_long m_mhlen; /* length of data in a header mbuf */
u_quad_t m_exthdrget; /* # of calls to IP6_EXTHDR_GET */
u_quad_t m_exthdrget0; /* # of calls to IP6_EXTHDR_GET0 */
u_quad_t m_pulldowns; /* # of calls to m_pulldown */
u_quad_t m_pulldown_copy; /* # of mbuf copies in m_pulldown */
u_quad_t m_pulldown_alloc; /* # of mbuf allocs in m_pulldown */
u_quad_t m_pullups; /* # of calls to m_pullup */
u_quad_t m_pullup_copy; /* # of possible m_pullup copies */
u_quad_t m_pullup_alloc; /* # of possible m_pullup mallocs */
u_quad_t m_pullup_fail; /* # of possible m_pullup failures */
u_quad_t m_pullup2; /* # of calls to m_pullup2 */
u_quad_t m_pullup2_copy; /* # of possible m_pullup2 copies */
u_quad_t m_pullup2_alloc; /* # of possible m_pullup2 mallocs */
u_quad_t m_pullup2_fail; /* # of possible m_pullup2 failures */
};
/* flags to m_get/MGET */
#define M_DONTWAIT 1
#define M_WAIT 0
/* Freelists:
*
* 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];
};
/*
* These are identifying numbers passed to the m_mballoc_wait function,
* allowing us to determine whether the call came from an MGETHDR or
* an MGET.
*/
#define MGETHDR_C 1
#define MGET_C 2
/*
* Wake up the next instance (if any) of m_mballoc_wait() which is
* waiting for an mbuf to be freed. This should be called at splimp().
*
* XXX: If there is another free mbuf, this routine will be called [again]
* from the m_mballoc_wait routine in order to wake another sleep instance.
*/
#define MMBWAKEUP() do { \ if (m_mballoc_wid) { \ m_mballoc_wid--; \ wakeup_one(&m_mballoc_wid); \ } \} while (0)
/*
* Same as above, but for mbuf cluster(s).
*/
#define MCLWAKEUP() do { \ if (m_clalloc_wid) { \ m_clalloc_wid--; \ wakeup_one(&m_clalloc_wid); \ } \} while (0)
/*
* mbuf utility macros:
*
* MBUFLOCK(code)
* prevents a section of code from from being interrupted by network
* drivers.
*/
#define MBUFLOCK(code) do { \ int _ms = splimp(); \ \ { code } \ splx(_ms); \} while (0)
/*
* 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) do { \ struct mbuf *_mm; \ int _mhow = (how); \ int _mtype = (type); \ int _ms = splimp(); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -