2 * Copyright (c) 1997, 1999 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 * $Id: i4b_mbuf.c,v 1.13 1999/12/13 21:25:27 hm Exp $
34 * last edit-date: [Mon Dec 13 22:04:10 1999]
36 *---------------------------------------------------------------------------*/
38 #include <sys/param.h>
39 #include <sys/systm.h>
42 #if defined(__FreeBSD__)
43 #include <sys/ioccom.h>
45 #include <sys/ioctl.h>
51 #include <sys/kernel.h>
52 #include <sys/socket.h>
55 #include <i4b/include/i4b_mbuf.h>
56 #include <i4b/include/i4b_global.h>
58 #define I4B_MBUF_DEBUG
59 #undef I4B_MBUF_TYPE_DEBUG
61 #ifdef I4B_MBUF_TYPE_DEBUG
70 #define MT_DCHAN MT_DATA
71 #define MT_BCHAN MT_DATA
75 #define MT_I4B_D MT_DCHAN
76 #define MT_I4B_B MT_BCHAN
78 #else /* ! I4B_MBUF_TYPE_DEBUG */
80 #define MT_I4B_D MT_DATA
81 #define MT_I4B_B MT_DATA
83 #endif /* I4B_MBUF_TYPE_DEBUG */
85 /*---------------------------------------------------------------------------*
86 * allocate D-channel mbuf space
87 *---------------------------------------------------------------------------*/
93 if(len > MCLBYTES) /* if length > max extension size */
97 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
104 MGETHDR(m, M_DONTWAIT, MT_I4B_D); /* get mbuf with pkthdr */
106 /* did we actually get the mbuf ? */
111 #ifdef I4B_MBUF_DEBUG
112 printf("i4b_getbuf: error - MGETHDR failed!\n");
120 MCLGET(m, M_DONTWAIT);
122 if(!(m->m_flags & M_EXT))
126 #ifdef I4B_MBUF_DEBUG
127 printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
139 /*---------------------------------------------------------------------------*
140 * free a D-channel mbuf
141 *---------------------------------------------------------------------------*/
143 i4b_Dfreembuf(struct mbuf *m)
149 /*---------------------------------------------------------------------------*
150 * clear a D-channel ifqueue from data
151 *---------------------------------------------------------------------------*/
153 i4b_Dcleanifq(struct ifqueue *ifq)
158 while(!IF_QEMPTY(ifq))
167 /*---------------------------------------------------------------------------*
168 * allocate B-channel mbuf space
169 *---------------------------------------------------------------------------*/
171 i4b_Bgetmbuf(int len)
175 if(len > MCLBYTES) /* if length > max extension size */
178 #ifdef I4B_MBUF_DEBUG
179 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
186 MGETHDR(m, M_DONTWAIT, MT_I4B_B); /* get mbuf with pkthdr */
188 /* did we actually get the mbuf ? */
193 #ifdef I4B_MBUF_DEBUG
194 printf("i4b_getbuf: error - MGETHDR failed!\n");
202 MCLGET(m, M_DONTWAIT);
204 if(!(m->m_flags & M_EXT))
208 #ifdef I4B_MBUF_DEBUG
209 printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
221 /*---------------------------------------------------------------------------*
222 * free a B-channel mbuf
223 *---------------------------------------------------------------------------*/
225 i4b_Bfreembuf(struct mbuf *m)
231 /*---------------------------------------------------------------------------*
232 * clear a B-channel ifqueue from data
233 *---------------------------------------------------------------------------*/
235 i4b_Bcleanifq(struct ifqueue *ifq)
240 while(!IF_QEMPTY(ifq))