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/netnatm/natm_pcb.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: natm_pcb.c,v 1.7 2001/11/13 01:37:45 lukem Exp $       */
    2 
    3 /*
    4  *
    5  * Copyright (c) 1996 Charles D. Cranor and Washington University.
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by Charles D. Cranor and
   19  *      Washington University.
   20  * 4. The name of the author may not be used to endorse or promote products
   21  *    derived from this software without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   33  */
   34 
   35 /*
   36  * atm_pcb.c: manage atm protocol control blocks and keep IP and NATM
   37  * from trying to use each other's VCs.
   38  */
   39 
   40 #include <sys/cdefs.h>
   41 __KERNEL_RCSID(0, "$NetBSD: natm_pcb.c,v 1.7 2001/11/13 01:37:45 lukem Exp $");
   42 
   43 #include "opt_ddb.h"
   44 
   45 #include <sys/param.h>
   46 #include <sys/systm.h>
   47 #include <sys/queue.h>
   48 #include <sys/socket.h>
   49 #include <sys/protosw.h>
   50 #include <sys/domain.h>
   51 #include <sys/mbuf.h>
   52 #include <sys/malloc.h>
   53 
   54 #include <net/if.h>
   55 #include <net/radix.h>
   56 #include <net/route.h>
   57 
   58 #include <netinet/in.h>
   59 
   60 #include <netnatm/natm.h>
   61 
   62 /*
   63  * npcb_alloc: allocate a npcb [in the free state]
   64  */
   65 
   66 struct natmpcb *npcb_alloc(wait)
   67 
   68 int wait;
   69 
   70 {
   71   struct natmpcb *npcb;
   72 
   73   MALLOC(npcb, struct natmpcb *, sizeof(*npcb), M_PCB, wait);
   74 
   75 #ifdef DIAGNOSTIC
   76   if (wait == M_WAITOK && npcb == NULL) panic("npcb_alloc: malloc didn't wait");
   77 #endif
   78 
   79   if (npcb) {
   80     bzero(npcb, sizeof(*npcb));
   81     npcb->npcb_flags = NPCB_FREE;
   82   }
   83   return(npcb);
   84 }
   85 
   86 
   87 /*
   88  * npcb_free: free a npcb
   89  */
   90 
   91 void npcb_free(npcb, op)
   92 
   93 struct natmpcb *npcb;
   94 int op;
   95 
   96 {
   97   int s = splnet();
   98 
   99   if ((npcb->npcb_flags & NPCB_FREE) == 0) {
  100     LIST_REMOVE(npcb, pcblist);
  101     npcb->npcb_flags = NPCB_FREE;
  102   }
  103   if (op == NPCB_DESTROY) {
  104     if (npcb->npcb_inq) {
  105       npcb->npcb_flags = NPCB_DRAIN;    /* flag for distruction */
  106     } else {
  107       FREE(npcb, M_PCB);                /* kill it! */
  108     }
  109   }
  110 
  111   splx(s);
  112 }
  113 
  114 
  115 /*
  116  * npcb_add: add or remove npcb from main list
  117  *   returns npcb if ok
  118  */
  119 
  120 struct natmpcb *npcb_add(npcb, ifp, vci, vpi)
  121 
  122 struct natmpcb *npcb;
  123 struct ifnet *ifp;
  124 u_int16_t vci;
  125 u_int8_t vpi;
  126 
  127 {
  128   struct natmpcb *cpcb = NULL;          /* current pcb */
  129   int s = splnet();
  130 
  131 
  132   /*
  133    * lookup required
  134    */
  135 
  136   for (cpcb = natm_pcbs.lh_first ; cpcb != NULL ; 
  137                                         cpcb = cpcb->pcblist.le_next) {
  138     if (ifp == cpcb->npcb_ifp && vci == cpcb->npcb_vci && vpi == cpcb->npcb_vpi)
  139       break;
  140   }
  141 
  142   /*
  143    * add & something already there?
  144    */
  145 
  146   if (cpcb) {
  147     cpcb = NULL;
  148     goto done;                                  /* fail */
  149   }
  150     
  151   /*
  152    * need to allocate a pcb?
  153    */
  154 
  155   if (npcb == NULL) {
  156     cpcb = npcb_alloc(M_NOWAIT);        /* could be called from lower half */
  157     if (cpcb == NULL) 
  158       goto done;                        /* fail */
  159   } else {
  160     cpcb = npcb;
  161   }
  162 
  163   cpcb->npcb_ifp = ifp;
  164   cpcb->ipaddr.s_addr = 0;
  165   cpcb->npcb_vci = vci;
  166   cpcb->npcb_vpi = vpi;
  167   cpcb->npcb_flags = NPCB_CONNECTED;
  168 
  169   LIST_INSERT_HEAD(&natm_pcbs, cpcb, pcblist);
  170 
  171 done:
  172   splx(s);
  173   return(cpcb);
  174 }
  175 
  176 
  177 
  178 #ifdef DDB
  179 
  180 int npcb_dump __P((void));
  181 
  182 int npcb_dump()
  183 
  184 {
  185   struct natmpcb *cpcb;
  186 
  187   printf("npcb dump:\n");
  188   for (cpcb = natm_pcbs.lh_first ; cpcb != NULL ; 
  189                                         cpcb = cpcb->pcblist.le_next) {
  190     printf("if=%s, vci=%d, vpi=%d, IP=0x%x, sock=%p, flags=0x%x, inq=%d\n",
  191         cpcb->npcb_ifp->if_xname, cpcb->npcb_vci, cpcb->npcb_vpi,
  192         cpcb->ipaddr.s_addr, cpcb->npcb_socket, 
  193         cpcb->npcb_flags, cpcb->npcb_inq);
  194   }
  195   printf("done\n");
  196   return(0);
  197 }
  198 
  199 #endif

Cache object: 8de7c214bf047517ddc1ac2b46c4955c


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