BSD 4_2 development
[unix-history] / usr / src / sys / h / mbuf.h
CommitLineData
59703a43
C
1/* mbuf.h 6.1 83/07/29 */
2
3/*
4 * Constants related to memory allocator.
5 */
6#define MSIZE 128 /* size of an mbuf */
7#define MMINOFF 12 /* mbuf header length */
8#define MTAIL 4
9#define MMAXOFF (MSIZE-MTAIL) /* offset where data ends */
10#define MLEN (MSIZE-MMINOFF-MTAIL) /* mbuf data length */
11#define NMBCLUSTERS 256
12#define NMBPCL (CLBYTES/MSIZE) /* # mbufs per cluster */
13
14/*
15 * Macros for type conversion
16 */
17
18/* network cluster number to virtual address, and back */
19#define cltom(x) ((struct mbuf *)((int)mbutl + ((x) << CLSHIFT)))
20#define mtocl(x) (((int)x - (int)mbutl) >> CLSHIFT)
21
22/* address in mbuf to mbuf head */
23#define dtom(x) ((struct mbuf *)((int)x & ~(MSIZE-1)))
24
25/* mbuf head, to typed data */
26#define mtod(x,t) ((t)((int)(x) + (x)->m_off))
27
28struct mbuf {
29 struct mbuf *m_next; /* next buffer in chain */
30 u_long m_off; /* offset of data */
31 short m_len; /* amount of data in this mbuf */
32 short m_type; /* mbuf type (0 == free) */
33 u_char m_dat[MLEN]; /* data storage */
34 struct mbuf *m_act; /* link in higher-level mbuf list */
35};
36
37/* mbuf types */
38#define MT_FREE 0 /* should be on free list */
39#define MT_DATA 1 /* dynamic (data) allocation */
40#define MT_HEADER 2 /* packet header */
41#define MT_SOCKET 3 /* socket structure */
42#define MT_PCB 4 /* protocol control block */
43#define MT_RTABLE 5 /* routing tables */
44#define MT_HTABLE 6 /* IMP host tables */
45#define MT_ATABLE 7 /* address resolution tables */
46#define MT_SONAME 8 /* socket name */
47#define MT_ZOMBIE 9 /* zombie proc status */
48#define MT_SOOPTS 10 /* socket options */
49#define MT_FTABLE 11 /* fragment reassembly header */
50
51/* flags to m_get */
52#define M_DONTWAIT 0
53#define M_WAIT 1
54
55/* flags to m_pgalloc */
56#define MPG_MBUFS 0 /* put new mbufs on free list */
57#define MPG_CLUSTERS 1 /* put new clusters on free list */
58#define MPG_SPACE 2 /* don't free; caller wants space */
59
60/* length to m_copy to copy all */
61#define M_COPYALL 1000000000
62
63#define MGET(m, i, t) \
64 { int ms = splimp(); \
65 if ((m)=mfree) \
66 { if ((m)->m_type != MT_FREE) panic("mget"); (m)->m_type = t; \
67 mbstat.m_mbfree--; mbstat.m_mtypes[t]++; \
68 mfree = (m)->m_next; (m)->m_next = 0; \
69 (m)->m_off = MMINOFF; } \
70 else \
71 (m) = m_more(i, t); \
72 splx(ms); }
73#define MCLGET(m, i) \
74 { int ms = splimp(); \
75 if ((m)=mclfree) \
76 {++mclrefcnt[mtocl(m)];mbstat.m_clfree--;mclfree = (m)->m_next;} \
77 splx(ms); }
78#define MFREE(m, n) \
79 { int ms = splimp(); \
80 if ((m)->m_type == MT_FREE) panic("mfree"); \
81 mbstat.m_mtypes[(m)->m_type]--; (m)->m_type = MT_FREE; \
82 if ((m)->m_off > MSIZE) { \
83 (n) = (struct mbuf *)(mtod(m, int)&~CLOFSET); \
84 if (--mclrefcnt[mtocl(n)] == 0) \
85 { (n)->m_next = mclfree;mclfree = (n);mbstat.m_clfree++;} \
86 } \
87 (n) = (m)->m_next; (m)->m_next = mfree; \
88 (m)->m_off = 0; (m)->m_act = 0; mfree = (m); mbstat.m_mbfree++; \
89 splx(ms); }
90
91/*
92 * Mbuf statistics.
93 */
94struct mbstat {
95 short m_mbufs; /* mbufs obtained from page pool */
96 short m_mbfree; /* mbufs on our free list */
97 short m_clusters; /* clusters obtained from page pool */
98 short m_clfree; /* free clusters */
99 short m_drops; /* times failed to find space */
100 short m_mtypes[256]; /* type specific mbuf allocations */
101};
102
103#ifdef KERNEL
104extern struct mbuf mbutl[]; /* virtual address of net free mem */
105extern struct pte Mbmap[]; /* page tables to map Netutl */
106struct mbstat mbstat;
107int nmbclusters;
108struct mbuf *mfree, *mclfree;
109char mclrefcnt[NMBCLUSTERS];
110struct mbuf *m_get(),*m_getclr(),*m_free(),*m_more(),*m_copy(),*m_pullup();
111caddr_t m_clalloc();
112#endif