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/netccitt/pk_debug.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 /*      $NetBSD: pk_debug.c,v 1.12 2003/08/07 16:33:03 agc Exp $        */
    2 
    3 /*
    4  * Copyright (c) 1990, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * This code is derived from software contributed to Berkeley by
    8  * the Laboratory for Computation Vision and the Computer Science Department
    9  * of the University of British Columbia.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. Neither the name of the University nor the names of its contributors
   20  *    may be used to endorse or promote products derived from this software
   21  *    without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   33  * SUCH DAMAGE.
   34  *
   35  *      @(#)pk_debug.c  8.1 (Berkeley) 6/10/93
   36  */
   37 
   38 /*
   39  * Copyright (c) 1984 University of British Columbia.
   40  *
   41  * This code is derived from software contributed to Berkeley by
   42  * the Laboratory for Computation Vision and the Computer Science Department
   43  * of the University of British Columbia.
   44  *
   45  * Redistribution and use in source and binary forms, with or without
   46  * modification, are permitted provided that the following conditions
   47  * are met:
   48  * 1. Redistributions of source code must retain the above copyright
   49  *    notice, this list of conditions and the following disclaimer.
   50  * 2. Redistributions in binary form must reproduce the above copyright
   51  *    notice, this list of conditions and the following disclaimer in the
   52  *    documentation and/or other materials provided with the distribution.
   53  * 3. All advertising materials mentioning features or use of this software
   54  *    must display the following acknowledgement:
   55  *      This product includes software developed by the University of
   56  *      California, Berkeley and its contributors.
   57  * 4. Neither the name of the University nor the names of its contributors
   58  *    may be used to endorse or promote products derived from this software
   59  *    without specific prior written permission.
   60  *
   61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   71  * SUCH DAMAGE.
   72  *
   73  *      @(#)pk_debug.c  8.1 (Berkeley) 6/10/93
   74  */
   75 
   76 #include <sys/cdefs.h>
   77 __KERNEL_RCSID(0, "$NetBSD: pk_debug.c,v 1.12 2003/08/07 16:33:03 agc Exp $");
   78 
   79 #include <sys/param.h>
   80 #include <sys/systm.h>
   81 #include <sys/mbuf.h>
   82 #include <sys/socket.h>
   83 #include <sys/protosw.h>
   84 #include <sys/socketvar.h>
   85 #include <sys/errno.h>
   86 
   87 #include <net/if.h>
   88 
   89 #include <netccitt/x25.h>
   90 #include <netccitt/pk.h>
   91 #include <netccitt/pk_var.h>
   92 #include <netccitt/pk_extern.h>
   93 
   94 char    *pk_state[] = {
   95         "Listen",       "Ready",        "Received-Call",
   96         "Sent-Call",    "Data-Transfer","Received-Clear",
   97         "Sent-Clear",
   98 };
   99 
  100 char   *pk_name[] = {
  101         "Call",         "Call-Conf",    "Clear",
  102         "Clear-Conf",   "Data",         "Intr",         "Intr-Conf",
  103         "Rr",           "Rnr",          "Reset",        "Reset-Conf",
  104         "Restart",      "Restart-Conf", "Reject",       "Diagnostic",
  105         "Invalid"
  106 };
  107 
  108 void
  109 pk_trace (xcp, m, dir)
  110         struct x25config *xcp;
  111         struct mbuf *m;
  112         char *dir;
  113 {
  114         char *s;
  115         struct x25_packet *xp = mtod(m, struct x25_packet *);
  116         int i, len = 0, cnt = 0;
  117 
  118         if (xcp -> xc_ptrace == 0)
  119                 return;
  120 
  121         i = pk_decode (xp) / MAXSTATES;
  122         for (; m; m = m -> m_next) {
  123                 len = len + m -> m_len;
  124                 ++cnt;
  125         }
  126         printf ("LCN=%d %s:     %s      #=%d, len=%d ",
  127                 LCN(xp), dir, pk_name[i], cnt, len);
  128         for (s = (char *) xp, i = 0; i < 5; ++i, ++s)
  129                 printf ("%x ", (int) * s & 0xff);
  130         printf ("\n");
  131 }
  132 
  133 void
  134 mbuf_cache(c, m)
  135         struct mbuf_cache *c;
  136         struct mbuf *m;
  137 {
  138         struct mbuf **mp;
  139 
  140         if (c->mbc_size != c->mbc_oldsize) {
  141                 unsigned zero_size, copy_size;
  142                 unsigned new_size = c->mbc_size * sizeof(m);
  143                 caddr_t cache = (caddr_t)c->mbc_cache;
  144 
  145                 if (new_size) {
  146                         c->mbc_cache = (struct mbuf **)
  147                                 malloc(new_size, M_MBUF, M_NOWAIT);
  148                         if (c->mbc_cache == 0) {
  149                                 c->mbc_cache = (struct mbuf **)cache;
  150                                 return;
  151                         }
  152                         c->mbc_num %= c->mbc_size;
  153                 } else
  154                         c->mbc_cache = 0;
  155                 if (c->mbc_size < c->mbc_oldsize) {
  156                         struct mbuf **mplim;
  157                         mp = c->mbc_size + (struct mbuf **)cache;
  158                         mplim = c->mbc_oldsize + (struct mbuf **)cache;
  159                         while (mp < mplim)
  160                                 m_freem(*mp++);
  161                         zero_size = 0;
  162                 } else
  163                         zero_size = (c->mbc_size - c->mbc_oldsize) * sizeof(m);
  164                 copy_size = new_size - zero_size;
  165                 c->mbc_oldsize = c->mbc_size;
  166                 if (copy_size)
  167                         bcopy(cache, (caddr_t)c->mbc_cache, copy_size);
  168                 if (cache)
  169                         free(cache, M_MBUF);
  170                 if (zero_size)
  171                         bzero(copy_size + (caddr_t)c->mbc_cache, zero_size);
  172         }
  173         if (c->mbc_size == 0)
  174                 return;
  175         mp = c->mbc_cache + c->mbc_num;
  176         c->mbc_num = (1 + c->mbc_num) % c->mbc_size;
  177         if (*mp)
  178                 m_freem(*mp);
  179         if ((*mp = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) != NULL)
  180                 (*mp)->m_flags |= m->m_flags & 0x08;
  181 }

Cache object: d53b8394679e01ddd7591850ff02de72


[ 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.