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 $
31 * $DragonFly: src/sys/net/i4b/layer2/i4b_mbuf.c,v 1.3 2003/08/07 21:17:29 dillon Exp $
33 * last edit-date: [Sat Jan 13 13:15:45 2001]
35 *---------------------------------------------------------------------------*/
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/socket.h>
43 #include "../include/i4b_mbuf.h"
45 #define I4B_MBUF_DEBUG
46 #undef I4B_MBUF_TYPE_DEBUG
48 #ifdef I4B_MBUF_TYPE_DEBUG
57 #define MT_DCHAN MT_DATA
58 #define MT_BCHAN MT_DATA
62 #define MT_I4B_D MT_DCHAN
63 #define MT_I4B_B MT_BCHAN
65 #else /* ! I4B_MBUF_TYPE_DEBUG */
67 #define MT_I4B_D MT_DATA
68 #define MT_I4B_B MT_DATA
70 #endif /* I4B_MBUF_TYPE_DEBUG */
72 /*---------------------------------------------------------------------------*
73 * allocate D-channel mbuf space
74 *---------------------------------------------------------------------------*/
80 if(len > MCLBYTES) /* if length > max extension size */
84 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
91 MGETHDR(m, M_DONTWAIT, MT_I4B_D); /* get mbuf with pkthdr */
93 /* did we actually get the mbuf ? */
99 printf("i4b_getbuf: error - MGETHDR failed!\n");
107 MCLGET(m, M_DONTWAIT);
109 if(!(m->m_flags & M_EXT))
113 #ifdef I4B_MBUF_DEBUG
114 printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
126 /*---------------------------------------------------------------------------*
127 * free a D-channel mbuf
128 *---------------------------------------------------------------------------*/
130 i4b_Dfreembuf(struct mbuf *m)
136 /*---------------------------------------------------------------------------*
137 * clear a D-channel ifqueue from data
138 *---------------------------------------------------------------------------*/
140 i4b_Dcleanifq(struct ifqueue *ifq)
144 #if defined (__FreeBSD__) && __FreeBSD__ > 4
148 while(!IF_QEMPTY(ifq))
157 /*---------------------------------------------------------------------------*
158 * allocate B-channel mbuf space
159 *---------------------------------------------------------------------------*/
161 i4b_Bgetmbuf(int len)
165 if(len > MCLBYTES) /* if length > max extension size */
168 #ifdef I4B_MBUF_DEBUG
169 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
176 MGETHDR(m, M_DONTWAIT, MT_I4B_B); /* get mbuf with pkthdr */
178 /* did we actually get the mbuf ? */
183 #ifdef I4B_MBUF_DEBUG
184 printf("i4b_getbuf: error - MGETHDR failed!\n");
192 MCLGET(m, M_DONTWAIT);
194 if(!(m->m_flags & M_EXT))
198 #ifdef I4B_MBUF_DEBUG
199 printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
211 /*---------------------------------------------------------------------------*
212 * free a B-channel mbuf
213 *---------------------------------------------------------------------------*/
215 i4b_Bfreembuf(struct mbuf *m)
221 /*---------------------------------------------------------------------------*
222 * clear a B-channel ifqueue from data
223 *---------------------------------------------------------------------------*/
225 i4b_Bcleanifq(struct ifqueue *ifq)
229 #if defined (__FreeBSD__) && __FreeBSD__ > 4
233 while(!IF_QEMPTY(ifq))