11556Srgrimes/*-
21556Srgrimes * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
31556Srgrimes *          based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
41556Srgrimes *                           Internet Initiative Japan, Inc (IIJ)
51556Srgrimes * All rights reserved.
61556Srgrimes *
71556Srgrimes * Redistribution and use in source and binary forms, with or without
81556Srgrimes * modification, are permitted provided that the following conditions
91556Srgrimes * are met:
101556Srgrimes * 1. Redistributions of source code must retain the above copyright
111556Srgrimes *    notice, this list of conditions and the following disclaimer.
121556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
131556Srgrimes *    notice, this list of conditions and the following disclaimer in the
141556Srgrimes *    documentation and/or other materials provided with the distribution.
151556Srgrimes *
161556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
171556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
181556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
191556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
201556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
211556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
221556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
231556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
241556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
251556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261556Srgrimes * SUCH DAMAGE.
271556Srgrimes *
281556Srgrimes * $FreeBSD$
291556Srgrimes */
301556Srgrimes
311556Srgrimesstruct mbuf {
3217987Speter  size_t m_size;		/* size allocated (excluding header) */
3350471Speter  u_short m_offset;		/* offset from header end to start position */
341556Srgrimes  size_t m_len;			/* available byte count in buffer */
351556Srgrimes  short m_type;			/* MB_* below */
361556Srgrimes  struct mbuf *m_next;		/* link to next mbuf */
3720425Ssteve  struct mbuf *m_nextpkt;	/* link to next packet */
3820425Ssteve  unsigned long priv;		/* private data - holds HDLC escape count */
3920425Ssteve  /* buffer space is malloc()d directly after the header */
401556Srgrimes};
4120425Ssteve
4220425Sstevestruct mqueue {
431556Srgrimes  struct mbuf *top;
441556Srgrimes  struct mbuf *last;
451556Srgrimes  size_t len;
461556Srgrimes};
471556Srgrimes
481556Srgrimes#define MBUF_CTOP(bp) \
491556Srgrimes	((bp) ? (u_char *)((bp)+1) + (bp)->m_offset : (u_char *)bp)
501556Srgrimes
511556Srgrimes#define CONST_MBUF_CTOP(bp) \
521556Srgrimes	((bp) ? (const u_char *)((bp)+1) + (bp)->m_offset : (const u_char *)bp)
531556Srgrimes
541556Srgrimes#define MB_IPIN		0
551556Srgrimes#define MB_IPOUT	1
561556Srgrimes#define MB_IPV6IN	2
571556Srgrimes#define MB_IPV6OUT	3
581556Srgrimes#define MB_NATIN	4
591556Srgrimes#define MB_NATOUT	5
601556Srgrimes#define MB_MPIN		6
611556Srgrimes#define MB_MPOUT	7
6219240Ssteve#define MB_VJIN		8
6345221Scracauer#define MB_VJOUT	9
64100664Stjr#define MB_ICOMPDIN	10
65223281Sjilles#define MB_ICOMPDOUT	11
661556Srgrimes#define MB_COMPDIN	12
67223281Sjilles#define MB_COMPDOUT	13
681556Srgrimes#define MB_LQRIN	14
691556Srgrimes#define MB_LQROUT	15
701556Srgrimes#define MB_ECHOIN	16
711556Srgrimes#define MB_ECHOOUT	17
721556Srgrimes#define MB_PROTOIN	18
731556Srgrimes#define MB_PROTOOUT	19
741556Srgrimes#define MB_ACFIN	20
751556Srgrimes#define MB_ACFOUT	21
761556Srgrimes#define MB_SYNCIN	22
7717987Speter#define MB_SYNCOUT	23
7817987Speter#define MB_HDLCIN	24
7917987Speter#define MB_HDLCOUT	25
8017987Speter#define MB_ASYNCIN	26
8117987Speter#define MB_ASYNCOUT	27
8217987Speter#define MB_CBCPIN	28
8317987Speter#define MB_CBCPOUT	29
8417987Speter#define MB_CHAPIN	30
8517987Speter#define MB_CHAPOUT	31
8617987Speter#define MB_PAPIN	32
8717987Speter#define MB_PAPOUT	33
8817987Speter#define MB_CCPIN	34
8917987Speter#define MB_CCPOUT	35
9017987Speter#define MB_IPCPIN	36
9117987Speter#define MB_IPCPOUT	37
9219240Ssteve#define MB_IPV6CPIN	38
9345221Scracauer#define MB_IPV6CPOUT	39
94100664Stjr#define MB_LCPIN	40
95223281Sjilles#define MB_LCPOUT	41
961556Srgrimes#define MB_UNKNOWN	42
971556Srgrimes#define MB_MAX		MB_UNKNOWN
981556Srgrimes
991556Srgrimes#define M_MAXLEN	(4352 - sizeof(struct mbuf))	/* > HDLCSIZE */
1001556Srgrimes
1011556Srgrimesstruct cmdargs;
1021556Srgrimes
1031556Srgrimesextern size_t m_length(struct mbuf *);
1041556Srgrimesextern struct mbuf *m_get(size_t, int);
1051556Srgrimesextern struct mbuf *m_free(struct mbuf *);
10659436Scracauerextern void m_freem(struct mbuf *);
107201053Sjillesextern void mbuf_Write(struct mbuf *, const void *, size_t);
1081556Srgrimesextern struct mbuf *mbuf_Read(struct mbuf *, void *, size_t);
10990111Simpextern size_t mbuf_View(struct mbuf *, void *, size_t);
11090111Simpextern struct mbuf *m_prepend(struct mbuf *, const void *, size_t, u_short);
11190111Simpextern struct mbuf *m_adj(struct mbuf *, ssize_t);
11290111Simpextern struct mbuf *m_pullup(struct mbuf *);
113200956Sjillesextern void m_settype(struct mbuf *, int);
11490111Simpextern struct mbuf *m_append(struct mbuf *, const void *, size_t);
115
116extern int mbuf_Show(struct cmdargs const *);
117
118extern void m_enqueue(struct mqueue *, struct mbuf *);
119extern struct mbuf *m_dequeue(struct mqueue *);
120