The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netisdn/i4b_mbuf.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    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.
   12  *
   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
   23  * SUCH DAMAGE.
   24  *
   25  *---------------------------------------------------------------------------
   26  *
   27  *      i4b - mbuf handling support routines
   28  *      ------------------------------------
   29  *
   30  *      $Id: i4b_mbuf.c,v 1.5 2005/12/11 12:25:06 christos Exp $
   31  *
   32  * $FreeBSD$
   33  *
   34  *      last edit-date: [Fri Jan  5 11:33:47 2001]
   35  *
   36  *---------------------------------------------------------------------------*/
   37 
   38 #include <sys/cdefs.h>
   39 __KERNEL_RCSID(0, "$NetBSD: i4b_mbuf.c,v 1.5 2005/12/11 12:25:06 christos Exp $");
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/mbuf.h>
   44 #include <sys/tty.h>
   45 #include <sys/proc.h>
   46 #include <sys/uio.h>
   47 #include <sys/kernel.h>
   48 #include <sys/socket.h>
   49 #include <net/if.h>
   50 
   51 #include <netisdn/i4b_mbuf.h>
   52 #include <netisdn/i4b_global.h>
   53 
   54 #define I4B_MBUF_DEBUG
   55 #undef I4B_MBUF_TYPE_DEBUG
   56 
   57 #ifdef I4B_MBUF_TYPE_DEBUG
   58 
   59 #ifdef  __FreeBSD__
   60 
   61 #define MT_DCHAN        42
   62 #define MT_BCHAN        43
   63 
   64 #else /* NetBSD */
   65 
   66 #define MT_DCHAN        MT_DATA
   67 #define MT_BCHAN        MT_DATA
   68 
   69 #endif
   70 
   71 #define MT_I4B_D        MT_DCHAN
   72 #define MT_I4B_B        MT_BCHAN
   73 
   74 #else /* ! I4B_MBUF_TYPE_DEBUG */
   75 
   76 #define MT_I4B_D        MT_DATA
   77 #define MT_I4B_B        MT_DATA
   78 
   79 #endif /* I4B_MBUF_TYPE_DEBUG */
   80 
   81 /*---------------------------------------------------------------------------*
   82  *      allocate D-channel mbuf space
   83  *---------------------------------------------------------------------------*/
   84 struct mbuf*
   85 i4b_Dgetmbuf(int len)
   86 {
   87         struct mbuf *m;
   88 
   89         if(len > MCLBYTES)      /* if length > max extension size */
   90         {
   91 
   92 #ifdef I4B_MBUF_DEBUG
   93                 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
   94                                         len, MCLBYTES);
   95 #endif
   96 
   97                 return(NULL);
   98         }
   99 
  100         MGETHDR(m, M_DONTWAIT, MT_I4B_D);       /* get mbuf with pkthdr */
  101 
  102         /* did we actually get the mbuf ? */
  103 
  104         if(!m)
  105         {
  106 
  107 #ifdef I4B_MBUF_DEBUG
  108                 printf("i4b_getbuf: error - MGETHDR failed!\n");
  109 #endif
  110 
  111                 return(NULL);
  112         }
  113 
  114         if(len >= MHLEN)
  115         {
  116                 MCLGET(m, M_DONTWAIT);
  117 
  118                 if(!(m->m_flags & M_EXT))
  119                 {
  120                         m_freem(m);
  121 
  122 #ifdef I4B_MBUF_DEBUG
  123                         printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
  124 #endif
  125 
  126                         return (NULL);
  127                 }
  128         }
  129 
  130         m->m_len = len;
  131 
  132         return(m);
  133 }
  134 
  135 /*---------------------------------------------------------------------------*
  136  *      free a D-channel mbuf
  137  *---------------------------------------------------------------------------*/
  138 void
  139 i4b_Dfreembuf(struct mbuf *m)
  140 {
  141         if(m)
  142                 m_freem(m);
  143 }
  144 
  145 /*---------------------------------------------------------------------------*
  146  *      clear a D-channel ifqueue from data
  147  *---------------------------------------------------------------------------*/
  148 void
  149 i4b_Dcleanifq(struct ifqueue *ifq)
  150 {
  151         struct mbuf *m;
  152         int x = splnet();
  153 
  154         while(!IF_QEMPTY(ifq))
  155         {
  156                 IF_DEQUEUE(ifq, m);
  157                 i4b_Dfreembuf(m);
  158         }
  159 
  160         splx(x);
  161 }
  162 
  163 /*---------------------------------------------------------------------------*
  164  *      allocate B-channel mbuf space
  165  *---------------------------------------------------------------------------*/
  166 struct mbuf*
  167 i4b_Bgetmbuf(int len)
  168 {
  169         struct mbuf *m;
  170 
  171         if(len > MCLBYTES)      /* if length > max extension size */
  172         {
  173 
  174 #ifdef I4B_MBUF_DEBUG
  175                 printf("i4b_getmbuf: error - len(%d) > MCLBYTES(%d)\n",
  176                                         len, MCLBYTES);
  177 #endif
  178 
  179                 return(NULL);
  180         }
  181 
  182         MGETHDR(m, M_DONTWAIT, MT_I4B_B);       /* get mbuf with pkthdr */
  183 
  184         /* did we actually get the mbuf ? */
  185 
  186         if(!m)
  187         {
  188 
  189 #ifdef I4B_MBUF_DEBUG
  190                 printf("i4b_getbuf: error - MGETHDR failed!\n");
  191 #endif
  192 
  193                 return(NULL);
  194         }
  195 
  196         if(len >= MHLEN)
  197         {
  198                 MCLGET(m, M_DONTWAIT);
  199 
  200                 if(!(m->m_flags & M_EXT))
  201                 {
  202                         m_freem(m);
  203 
  204 #ifdef I4B_MBUF_DEBUG
  205                         printf("i4b_getbuf: error - MCLGET failed, len(%d)\n", len);
  206 #endif
  207 
  208                         return (NULL);
  209                 }
  210         }
  211 
  212         m->m_len = len;
  213 
  214         return(m);
  215 }
  216 
  217 /*---------------------------------------------------------------------------*
  218  *      free a B-channel mbuf
  219  *---------------------------------------------------------------------------*/
  220 void
  221 i4b_Bfreembuf(struct mbuf *m)
  222 {
  223         if(m)
  224                 m_freem(m);
  225 }
  226 
  227 /*---------------------------------------------------------------------------*
  228  *      clear a B-channel ifqueue from data
  229  *---------------------------------------------------------------------------*/
  230 void
  231 i4b_Bcleanifq(struct ifqueue *ifq)
  232 {
  233         struct mbuf *m;
  234         int x = splnet();
  235 
  236         while(!IF_QEMPTY(ifq))
  237         {
  238                 IF_DEQUEUE(ifq, m);
  239                 i4b_Bfreembuf(m);
  240         }
  241 
  242         splx(x);
  243 }
  244 
  245 /* EOF */

Cache object: 4c71aa508de46eaed6fd90ba8ea1afa1


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.