1 /* $NetBSD: natm_pcb.c,v 1.12 2009/03/18 10:22:44 cegger Exp $ */
5 * Copyright (c) 1996 Charles D. Cranor and Washington University.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
36 * atm_pcb.c: manage atm protocol control blocks and keep IP and NATM
37 * from trying to use each other's VCs.
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: natm_pcb.c,v 1.12 2009/03/18 10:22:44 cegger Exp $");
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>
52 #include <sys/malloc.h>
55 #include <net/radix.h>
56 #include <net/route.h>
58 #include <netinet/in.h>
60 #include <netnatm/natm.h>
63 * npcb_alloc: allocate a npcb [in the free state]
66 struct natmpcb
*npcb_alloc(wait
)
73 npcb
= malloc(sizeof(*npcb
), M_PCB
, wait
);
76 if (wait
== M_WAITOK
&& npcb
== NULL
) panic("npcb_alloc: malloc didn't wait");
80 memset(npcb
, 0, sizeof(*npcb
));
81 npcb
->npcb_flags
= NPCB_FREE
;
88 * npcb_free: free a npcb
91 void npcb_free(npcb
, op
)
99 if ((npcb
->npcb_flags
& NPCB_FREE
) == 0) {
100 LIST_REMOVE(npcb
, pcblist
);
101 npcb
->npcb_flags
= NPCB_FREE
;
103 if (op
== NPCB_DESTROY
) {
104 if (npcb
->npcb_inq
) {
105 npcb
->npcb_flags
= NPCB_DRAIN
; /* flag for distruction */
107 free(npcb
, M_PCB
); /* kill it! */
116 * npcb_add: add or remove npcb from main list
120 struct natmpcb
*npcb_add(npcb
, ifp
, vci
, vpi
)
122 struct natmpcb
*npcb
;
128 struct natmpcb
*cpcb
= NULL
; /* current pcb */
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
)
143 * add & something already there?
148 goto done
; /* fail */
152 * need to allocate a pcb?
156 cpcb
= npcb_alloc(M_NOWAIT
); /* could be called from lower half */
158 goto done
; /* fail */
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
;
169 LIST_INSERT_HEAD(&natm_pcbs
, cpcb
, pcblist
);
185 struct natmpcb
*cpcb
;
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
);