xref: /freebsd/usr.sbin/ppp/mbuf.h (revision 4cf49a43559ed9fdad601bdcccd2c55963008675)
1 /*
2  *	    Written by Toshiharu OHNO (tony-o@iij.ad.jp)
3  *
4  *   Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that the above copyright notice and this paragraph are
8  * duplicated in all such forms and that any documentation,
9  * advertising materials, and other materials related to such
10  * distribution and use acknowledge that the software was developed
11  * by the Internet Initiative Japan.  The name of the
12  * IIJ may not be used to endorse or promote products derived
13  * from this software without specific prior written permission.
14  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  * $FreeBSD$
19  *
20  *	TODO:
21  */
22 
23 struct mbuf {
24   short size;			/* size allocated (excluding header) */
25   short offset;			/* offset from header end to start position */
26   short cnt;			/* available byte count in buffer */
27   short type;			/* MB_* below */
28   struct mbuf *next;		/* link to next mbuf */
29   struct mbuf *pnext;		/* link to next packet */
30   /* buffer space is malloc()d directly after the header */
31 };
32 
33 struct mqueue {
34   struct mbuf *top;
35   struct mbuf *last;
36   int qlen;
37 };
38 
39 #define MBUF_CTOP(bp) \
40 	((bp) ? (u_char *)((bp)+1) + (bp)->offset : NULL)
41 
42 #define CONST_MBUF_CTOP(bp) \
43 	((bp) ? (const u_char *)((bp)+1) + (bp)->offset : NULL)
44 
45 #define MB_IPIN		0
46 #define MB_IPOUT	1
47 #define MB_NATIN	2
48 #define MB_NATOUT	3
49 #define MB_MPIN		4
50 #define MB_MPOUT	5
51 #define MB_VJIN		6
52 #define MB_VJOUT	7
53 #define MB_ICOMPDIN	8
54 #define MB_ICOMPDOUT	9
55 #define MB_COMPDIN	10
56 #define MB_COMPDOUT	11
57 #define MB_LQRIN	12
58 #define MB_LQROUT	13
59 #define MB_ECHOIN	14
60 #define MB_ECHOOUT	15
61 #define MB_PROTOIN	16
62 #define MB_PROTOOUT	17
63 #define MB_ACFIN	18
64 #define MB_ACFOUT	19
65 #define MB_SYNCIN	20
66 #define MB_SYNCOUT	21
67 #define MB_HDLCIN	22
68 #define MB_HDLCOUT	23
69 #define MB_ASYNCIN	24
70 #define MB_ASYNCOUT	25
71 #define MB_CBCPIN	26
72 #define MB_CBCPOUT	27
73 #define MB_CHAPIN	28
74 #define MB_CHAPOUT	29
75 #define MB_PAPIN	30
76 #define MB_PAPOUT	31
77 #define MB_CCPIN	32
78 #define MB_CCPOUT	33
79 #define MB_IPCPIN	34
80 #define MB_IPCPOUT	35
81 #define MB_LCPIN	36
82 #define MB_LCPOUT	37
83 #define MB_UNKNOWN	38
84 #define MB_MAX		MB_UNKNOWN
85 
86 struct cmdargs;
87 
88 extern int mbuf_Length(struct mbuf *);
89 extern struct mbuf *mbuf_Alloc(int, int);
90 extern struct mbuf *mbuf_FreeSeg(struct mbuf *);
91 extern void mbuf_Free(struct mbuf *);
92 extern void mbuf_Write(struct mbuf *, const void *, size_t);
93 extern struct mbuf *mbuf_Read(struct mbuf *, void *, size_t);
94 extern size_t mbuf_View(struct mbuf *, void *, size_t);
95 extern struct mbuf *mbuf_Prepend(struct mbuf *, const void *, size_t, size_t);
96 extern struct mbuf *mbuf_Truncate(struct mbuf *, size_t);
97 extern int mbuf_Show(struct cmdargs const *);
98 extern void mbuf_Enqueue(struct mqueue *, struct mbuf *);
99 extern struct mbuf *mbuf_Dequeue(struct mqueue *);
100 extern struct mbuf *mbuf_Contiguous(struct mbuf *);
101 extern void mbuf_SetType(struct mbuf *, int);
102