This source file includes following definitions.
- npcb_alloc
- npcb_free
- npcb_add
- npcb_dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/queue.h>
43 #include <sys/socket.h>
44 #include <sys/protosw.h>
45 #include <sys/domain.h>
46 #include <sys/mbuf.h>
47 #include <sys/malloc.h>
48
49 #include <net/if.h>
50 #include <net/radix.h>
51 #include <net/route.h>
52
53 #include <netinet/in.h>
54
55 #include <netnatm/natm.h>
56
57
58
59
60
61 struct natmpcb *npcb_alloc(wait)
62
63 int wait;
64
65 {
66 struct natmpcb *npcb;
67
68 MALLOC(npcb, struct natmpcb *, sizeof(*npcb), M_PCB, wait);
69
70 if (npcb) {
71 bzero(npcb, sizeof(*npcb));
72 npcb->npcb_flags = NPCB_FREE;
73 }
74 return(npcb);
75 }
76
77
78
79
80
81
82 void npcb_free(npcb, op)
83
84 struct natmpcb *npcb;
85 int op;
86
87 {
88 int s = splnet();
89
90 if ((npcb->npcb_flags & NPCB_FREE) == 0) {
91 LIST_REMOVE(npcb, pcblist);
92 npcb->npcb_flags = NPCB_FREE;
93 }
94 if (op == NPCB_DESTROY) {
95 if (npcb->npcb_inq) {
96 npcb->npcb_flags = NPCB_DRAIN;
97 } else {
98 FREE(npcb, M_PCB);
99 }
100 }
101
102 splx(s);
103 }
104
105
106
107
108
109
110
111 struct natmpcb *npcb_add(npcb, ifp, vci, vpi)
112
113 struct natmpcb *npcb;
114 struct ifnet *ifp;
115 u_int16_t vci;
116 u_int8_t vpi;
117
118 {
119 struct natmpcb *cpcb = NULL;
120 int s = splnet();
121
122
123
124
125
126
127 LIST_FOREACH(cpcb, &natm_pcbs, pcblist) {
128 if (ifp == cpcb->npcb_ifp && vci == cpcb->npcb_vci && vpi == cpcb->npcb_vpi)
129 break;
130 }
131
132
133
134
135
136 if (cpcb) {
137 cpcb = NULL;
138 goto done;
139 }
140
141
142
143
144
145 if (npcb == NULL) {
146 cpcb = npcb_alloc(M_NOWAIT);
147 if (cpcb == NULL)
148 goto done;
149 } else {
150 cpcb = npcb;
151 }
152
153 cpcb->npcb_ifp = ifp;
154 cpcb->ipaddr.s_addr = 0;
155 cpcb->npcb_vci = vci;
156 cpcb->npcb_vpi = vpi;
157 cpcb->npcb_flags = NPCB_CONNECTED;
158
159 LIST_INSERT_HEAD(&natm_pcbs, cpcb, pcblist);
160
161 done:
162 splx(s);
163 return(cpcb);
164 }
165
166
167
168 #ifdef DDB
169
170 int npcb_dump(void);
171
172 int npcb_dump()
173
174 {
175 struct natmpcb *cpcb;
176
177 printf("npcb dump:\n");
178 LIST_FOREACH(cpcb, &natm_pcbs, pcblist) {
179 printf("if=%s, vci=%d, vpi=%d, IP=0x%x, sock=%p, flags=0x%x, inq=%d\n",
180 cpcb->npcb_ifp->if_xname, cpcb->npcb_vci, cpcb->npcb_vpi,
181 cpcb->ipaddr.s_addr, cpcb->npcb_socket,
182 cpcb->npcb_flags, cpcb->npcb_inq);
183 }
184 printf("done\n");
185 return(0);
186 }
187
188 #endif