1 /* $FreeBSD: src/sys/netnatm/natm_pcb.c,v 1.6.6.1 2000/08/03 18:56:28 peter Exp $ */
2 /* $NetBSD: natm_pcb.c,v 1.4 1996/11/09 03:26:27 chuck Exp $ */
6 * Copyright (c) 1996 Charles D. Cranor and Washington University.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Charles D. Cranor and
20 * Washington University.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * atm_pcb.c: manage atm protocol control blocks and keep IP and NATM
38 * from trying to use each other's VCs.
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/malloc.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
49 #include <netinet/in.h>
51 #include <netnatm/natm.h>
53 struct npcblist natm_pcbs;
56 * npcb_alloc: allocate a npcb [in the free state]
59 struct natmpcb *npcb_alloc(wait)
66 MALLOC(npcb, struct natmpcb *, sizeof(*npcb), M_PCB, wait);
69 if (wait == M_WAITOK && npcb == NULL) panic("npcb_alloc: malloc didn't wait");
73 bzero(npcb, sizeof(*npcb));
74 npcb->npcb_flags = NPCB_FREE;
81 * npcb_free: free a npcb
84 void npcb_free(npcb, op)
92 if ((npcb->npcb_flags & NPCB_FREE) == 0) {
93 LIST_REMOVE(npcb, pcblist);
94 npcb->npcb_flags = NPCB_FREE;
96 if (op == NPCB_DESTROY) {
98 npcb->npcb_flags = NPCB_DRAIN; /* flag for distruction */
100 FREE(npcb, M_PCB); /* kill it! */
109 * npcb_add: add or remove npcb from main list
113 struct natmpcb *npcb_add(npcb, ifp, vci, vpi)
115 struct natmpcb *npcb;
121 struct natmpcb *cpcb = NULL; /* current pcb */
129 for (cpcb = natm_pcbs.lh_first ; cpcb != NULL ;
130 cpcb = cpcb->pcblist.le_next) {
131 if (ifp == cpcb->npcb_ifp && vci == cpcb->npcb_vci && vpi == cpcb->npcb_vpi)
136 * add & something already there?
141 goto done; /* fail */
145 * need to allocate a pcb?
149 cpcb = npcb_alloc(M_NOWAIT); /* could be called from lower half */
151 goto done; /* fail */
156 cpcb->npcb_ifp = ifp;
157 cpcb->ipaddr.s_addr = 0;
158 cpcb->npcb_vci = vci;
159 cpcb->npcb_vpi = vpi;
160 cpcb->npcb_flags = NPCB_CONNECTED;
162 LIST_INSERT_HEAD(&natm_pcbs, cpcb, pcblist);
173 int npcb_dump __P((void));
178 struct natmpcb *cpcb;
180 printf("npcb dump:\n");
181 for (cpcb = natm_pcbs.lh_first ; cpcb != NULL ;
182 cpcb = cpcb->pcblist.le_next) {
183 printf("if=%s, vci=%d, vpi=%d, IP=0x%x, sock=%p, flags=0x%x, inq=%d\n",
184 cpcb->npcb_ifp->if_xname, cpcb->npcb_vci, cpcb->npcb_vpi,
185 cpcb->ipaddr.s_addr, cpcb->npcb_socket,
186 cpcb->npcb_flags, cpcb->npcb_inq);