2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b - mbuf handling support routines
28 * ------------------------------------
30 * $FreeBSD: src/sys/i4b/layer2/i4b_mbuf.c,v 1.6.2.1 2001/08/10 14:08:41 obrien Exp $
32 * last edit-date: [Sat Jan 13 13:15:45 2001]
34 *---------------------------------------------------------------------------*/
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/socket.h>
42 #include <i4b/include/i4b_mbuf.h>
44 #define I4B_MBUF_DEBUG
45 #undef I4B_MBUF_TYPE_DEBUG
47 #ifdef I4B_MBUF_TYPE_DEBUG
56 #define MT_DCHAN MT_DATA
57 #define MT_BCHAN MT_DATA
61 #define MT_I4B_D MT_DCHAN
62 #define MT_I4B_B MT_BCHAN
64 #else /* ! I4B_MBUF_TYPE_DEBUG */
66 #define MT_I4B_D MT_DATA
67 #define MT_I4B_B MT_DATA
69 #endif /* I4B_MBUF_TYPE_DEBUG */
71 /*---------------------------------------------------------------------------*
72 * allocate D-channel mbuf space
73 *---------------------------------------------------------------------------*/
79 if(len > MCLBYTES) /* if length > max extension size */
83 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
90 MGETHDR(m, M_DONTWAIT, MT_I4B_D); /* get mbuf with pkthdr */
92 /* did we actually get the mbuf ? */
98 printf("i4b_getbuf: error - MGETHDR failed!\n");
106 MCLGET(m, M_DONTWAIT);
108 if(!(m->m_flags & M_EXT))
112 #ifdef I4B_MBUF_DEBUG
113 printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
125 /*---------------------------------------------------------------------------*
126 * free a D-channel mbuf
127 *---------------------------------------------------------------------------*/
129 i4b_Dfreembuf(struct mbuf *m)
135 /*---------------------------------------------------------------------------*
136 * clear a D-channel ifqueue from data
137 *---------------------------------------------------------------------------*/
139 i4b_Dcleanifq(struct ifqueue *ifq)
143 #if defined (__FreeBSD__) && __FreeBSD__ > 4
147 while(!IF_QEMPTY(ifq))
156 /*---------------------------------------------------------------------------*
157 * allocate B-channel mbuf space
158 *---------------------------------------------------------------------------*/
160 i4b_Bgetmbuf(int len)
164 if(len > MCLBYTES) /* if length > max extension size */
167 #ifdef I4B_MBUF_DEBUG
168 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
175 MGETHDR(m, M_DONTWAIT, MT_I4B_B); /* get mbuf with pkthdr */
177 /* did we actually get the mbuf ? */
182 #ifdef I4B_MBUF_DEBUG
183 printf("i4b_getbuf: error - MGETHDR failed!\n");
191 MCLGET(m, M_DONTWAIT);
193 if(!(m->m_flags & M_EXT))
197 #ifdef I4B_MBUF_DEBUG
198 printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
210 /*---------------------------------------------------------------------------*
211 * free a B-channel mbuf
212 *---------------------------------------------------------------------------*/
214 i4b_Bfreembuf(struct mbuf *m)
220 /*---------------------------------------------------------------------------*
221 * clear a B-channel ifqueue from data
222 *---------------------------------------------------------------------------*/
224 i4b_Bcleanifq(struct ifqueue *ifq)
228 #if defined (__FreeBSD__) && __FreeBSD__ > 4
232 while(!IF_QEMPTY(ifq))