altq_conf.c revision 1.4.2.2 1 1.4.2.2 bouyer /* $NetBSD: altq_conf.c,v 1.4.2.2 2001/01/05 17:39:36 bouyer Exp $ */
2 1.4.2.2 bouyer /* $KAME: altq_conf.c,v 1.10 2000/12/14 08:12:45 thorpej Exp $ */
3 1.4.2.2 bouyer
4 1.4.2.2 bouyer /*
5 1.4.2.2 bouyer * Copyright (C) 1997-2000
6 1.4.2.2 bouyer * Sony Computer Science Laboratories Inc. All rights reserved.
7 1.4.2.2 bouyer *
8 1.4.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.4.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.4.2.2 bouyer * are met:
11 1.4.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.4.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.4.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.4.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.4.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.4.2.2 bouyer *
17 1.4.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
18 1.4.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.4.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.4.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
21 1.4.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.4.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.4.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.4.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.4.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.4.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.4.2.2 bouyer * SUCH DAMAGE.
28 1.4.2.2 bouyer */
29 1.4.2.2 bouyer
30 1.4.2.2 bouyer #if defined(__FreeBSD__) || defined(__NetBSD__)
31 1.4.2.2 bouyer #include "opt_altq.h"
32 1.4.2.2 bouyer #if (__FreeBSD__ != 2)
33 1.4.2.2 bouyer #include "opt_inet.h"
34 1.4.2.2 bouyer #ifdef __FreeBSD__
35 1.4.2.2 bouyer #include "opt_inet6.h"
36 1.4.2.2 bouyer #endif
37 1.4.2.2 bouyer #endif
38 1.4.2.2 bouyer #endif /* __FreeBSD__ || __NetBSD__ */
39 1.4.2.2 bouyer
40 1.4.2.2 bouyer /*
41 1.4.2.2 bouyer * altq device interface.
42 1.4.2.2 bouyer */
43 1.4.2.2 bouyer #include <sys/param.h>
44 1.4.2.2 bouyer #include <sys/systm.h>
45 1.4.2.2 bouyer #include <sys/socket.h>
46 1.4.2.2 bouyer #include <sys/kernel.h>
47 1.4.2.2 bouyer #include <sys/proc.h>
48 1.4.2.2 bouyer #include <sys/errno.h>
49 1.4.2.2 bouyer #if defined(__FreeBSD__) && (__FreeBSD_version < 400000) && defined(DEVFS)
50 1.4.2.2 bouyer #include <sys/devfsext.h>
51 1.4.2.2 bouyer #endif /*DEVFS*/
52 1.4.2.2 bouyer #include <net/if.h>
53 1.4.2.2 bouyer
54 1.4.2.2 bouyer #include <altq/altq.h>
55 1.4.2.2 bouyer #include <altq/altq_conf.h>
56 1.4.2.2 bouyer
57 1.4.2.2 bouyer #ifdef ALTQ_CBQ
58 1.4.2.2 bouyer altqdev_decl(cbq);
59 1.4.2.2 bouyer #endif
60 1.4.2.2 bouyer #ifdef ALTQ_WFQ
61 1.4.2.2 bouyer altqdev_decl(wfq);
62 1.4.2.2 bouyer #endif
63 1.4.2.2 bouyer #ifdef ALTQ_AFMAP
64 1.4.2.2 bouyer altqdev_decl(afm);
65 1.4.2.2 bouyer #endif
66 1.4.2.2 bouyer #ifdef ALTQ_FIFOQ
67 1.4.2.2 bouyer altqdev_decl(fifoq);
68 1.4.2.2 bouyer #endif
69 1.4.2.2 bouyer #ifdef ALTQ_RED
70 1.4.2.2 bouyer altqdev_decl(red);
71 1.4.2.2 bouyer #endif
72 1.4.2.2 bouyer #ifdef ALTQ_RIO
73 1.4.2.2 bouyer altqdev_decl(rio);
74 1.4.2.2 bouyer #endif
75 1.4.2.2 bouyer #ifdef ALTQ_LOCALQ
76 1.4.2.2 bouyer altqdev_decl(localq);
77 1.4.2.2 bouyer #endif
78 1.4.2.2 bouyer #ifdef ALTQ_HFSC
79 1.4.2.2 bouyer altqdev_decl(hfsc);
80 1.4.2.2 bouyer #endif
81 1.4.2.2 bouyer #ifdef ALTQ_CDNR
82 1.4.2.2 bouyer altqdev_decl(cdnr);
83 1.4.2.2 bouyer #endif
84 1.4.2.2 bouyer #ifdef ALTQ_BLUE
85 1.4.2.2 bouyer altqdev_decl(blue);
86 1.4.2.2 bouyer #endif
87 1.4.2.2 bouyer #ifdef ALTQ_PRIQ
88 1.4.2.2 bouyer altqdev_decl(priq);
89 1.4.2.2 bouyer #endif
90 1.4.2.2 bouyer
91 1.4.2.2 bouyer /*
92 1.4.2.2 bouyer * altq minor device (discipline) table
93 1.4.2.2 bouyer */
94 1.4.2.2 bouyer static struct altqsw altqsw[] = { /* minor */
95 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 0 (reserved) */
96 1.4.2.2 bouyer #ifdef ALTQ_CBQ
97 1.4.2.2 bouyer {"cbq", cbqopen, cbqclose, cbqioctl}, /* 1 */
98 1.4.2.2 bouyer #else
99 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 1 */
100 1.4.2.2 bouyer #endif
101 1.4.2.2 bouyer #ifdef ALTQ_WFQ
102 1.4.2.2 bouyer {"wfq", wfqopen, wfqclose, wfqioctl}, /* 2 */
103 1.4.2.2 bouyer #else
104 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 2 */
105 1.4.2.2 bouyer #endif
106 1.4.2.2 bouyer #ifdef ALTQ_AFMAP
107 1.4.2.2 bouyer {"afm", afmopen, afmclose, afmioctl}, /* 3 */
108 1.4.2.2 bouyer #else
109 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 3 */
110 1.4.2.2 bouyer #endif
111 1.4.2.2 bouyer #ifdef ALTQ_FIFOQ
112 1.4.2.2 bouyer {"fifoq", fifoqopen, fifoqclose, fifoqioctl}, /* 4 */
113 1.4.2.2 bouyer #else
114 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 4 */
115 1.4.2.2 bouyer #endif
116 1.4.2.2 bouyer #ifdef ALTQ_RED
117 1.4.2.2 bouyer {"red", redopen, redclose, redioctl}, /* 5 */
118 1.4.2.2 bouyer #else
119 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 5 */
120 1.4.2.2 bouyer #endif
121 1.4.2.2 bouyer #ifdef ALTQ_RIO
122 1.4.2.2 bouyer {"rio", rioopen, rioclose, rioioctl}, /* 6 */
123 1.4.2.2 bouyer #else
124 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 6 */
125 1.4.2.2 bouyer #endif
126 1.4.2.2 bouyer #ifdef ALTQ_LOCALQ
127 1.4.2.2 bouyer {"localq",localqopen, localqclose, localqioctl}, /* 7 (local use) */
128 1.4.2.2 bouyer #else
129 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 7 (local use) */
130 1.4.2.2 bouyer #endif
131 1.4.2.2 bouyer #ifdef ALTQ_HFSC
132 1.4.2.2 bouyer {"hfsc",hfscopen, hfscclose, hfscioctl}, /* 8 */
133 1.4.2.2 bouyer #else
134 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 8 */
135 1.4.2.2 bouyer #endif
136 1.4.2.2 bouyer #ifdef ALTQ_CDNR
137 1.4.2.2 bouyer {"cdnr",cdnropen, cdnrclose, cdnrioctl}, /* 9 */
138 1.4.2.2 bouyer #else
139 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 9 */
140 1.4.2.2 bouyer #endif
141 1.4.2.2 bouyer #ifdef ALTQ_BLUE
142 1.4.2.2 bouyer {"blue",blueopen, blueclose, blueioctl}, /* 10 */
143 1.4.2.2 bouyer #else
144 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 10 */
145 1.4.2.2 bouyer #endif
146 1.4.2.2 bouyer #ifdef ALTQ_PRIQ
147 1.4.2.2 bouyer {"priq",priqopen, priqclose, priqioctl}, /* 11 */
148 1.4.2.2 bouyer #else
149 1.4.2.2 bouyer {"noq", noopen, noclose, noioctl}, /* 11 */
150 1.4.2.2 bouyer #endif
151 1.4.2.2 bouyer };
152 1.4.2.2 bouyer
153 1.4.2.2 bouyer /*
154 1.4.2.2 bouyer * altq major device support
155 1.4.2.2 bouyer */
156 1.4.2.2 bouyer int naltqsw = sizeof (altqsw) / sizeof (altqsw[0]);
157 1.4.2.2 bouyer
158 1.4.2.2 bouyer #if !defined(__NetBSD__) && defined(__OpenBSD__)
159 1.4.2.2 bouyer static d_open_t altqopen;
160 1.4.2.2 bouyer static d_close_t altqclose;
161 1.4.2.2 bouyer static d_ioctl_t altqioctl;
162 1.4.2.2 bouyer #endif
163 1.4.2.2 bouyer #ifdef __FreeBSD__
164 1.4.2.2 bouyer static void altq_drvinit __P((void *));
165 1.4.2.2 bouyer #else
166 1.4.2.2 bouyer void altqattach __P((int));
167 1.4.2.2 bouyer #endif
168 1.4.2.2 bouyer
169 1.4.2.2 bouyer #if defined(__FreeBSD__)
170 1.4.2.2 bouyer #define CDEV_MAJOR 96 /* FreeBSD official number */
171 1.4.2.2 bouyer #elif defined(__OpenBSD__)
172 1.4.2.2 bouyer #if defined(__i386__)
173 1.4.2.2 bouyer #define CDEV_MAJOR 67 /* OpenBSD i386 (not official) */
174 1.4.2.2 bouyer #elif defined(__alpha__)
175 1.4.2.2 bouyer #define CDEV_MAJOR 52 /* OpenBSD alpha (not official) */
176 1.4.2.2 bouyer #else
177 1.4.2.2 bouyer #error arch not supported
178 1.4.2.2 bouyer #endif
179 1.4.2.2 bouyer #endif
180 1.4.2.2 bouyer
181 1.4.2.2 bouyer #if defined(__FreeBSD__)
182 1.4.2.2 bouyer #if (__FreeBSD_version < 400000)
183 1.4.2.2 bouyer static struct cdevsw altq_cdevsw =
184 1.4.2.2 bouyer { altqopen, altqclose, noread, nowrite,
185 1.4.2.2 bouyer altqioctl, nostop, nullreset, nodevtotty,
186 1.4.2.2 bouyer seltrue, nommap, NULL, "altq", NULL, -1 };
187 1.4.2.2 bouyer #else
188 1.4.2.2 bouyer static struct cdevsw altq_cdevsw =
189 1.4.2.2 bouyer { altqopen, altqclose, noread, nowrite,
190 1.4.2.2 bouyer altqioctl, seltrue, nommap, nostrategy,
191 1.4.2.2 bouyer "altq", CDEV_MAJOR, nodump, nopsize, 0, -1 };
192 1.4.2.2 bouyer #endif
193 1.4.2.2 bouyer #elif defined(__OpenBSD__)
194 1.4.2.2 bouyer static struct cdevsw altq_cdevsw = {
195 1.4.2.2 bouyer altqopen, altqclose, 0, 0, altqioctl, 0,
196 1.4.2.2 bouyer 0, 0, 0, 0 };
197 1.4.2.2 bouyer #endif
198 1.4.2.2 bouyer
199 1.4.2.2 bouyer #if !defined(__NetBSD__) && !defined(__OpenBSD__)
200 1.4.2.2 bouyer static
201 1.4.2.2 bouyer #endif
202 1.4.2.2 bouyer int
203 1.4.2.2 bouyer altqopen(dev, flag, fmt, p)
204 1.4.2.2 bouyer dev_t dev;
205 1.4.2.2 bouyer int flag, fmt;
206 1.4.2.2 bouyer struct proc *p;
207 1.4.2.2 bouyer {
208 1.4.2.2 bouyer int unit = minor(dev);
209 1.4.2.2 bouyer
210 1.4.2.2 bouyer if (unit == 0)
211 1.4.2.2 bouyer return (0);
212 1.4.2.2 bouyer if (unit < naltqsw)
213 1.4.2.2 bouyer return (*altqsw[unit].d_open)(dev, flag, fmt, p);
214 1.4.2.2 bouyer
215 1.4.2.2 bouyer return ENXIO;
216 1.4.2.2 bouyer }
217 1.4.2.2 bouyer
218 1.4.2.2 bouyer #if !defined(__NetBSD__) && !defined(__OpenBSD__)
219 1.4.2.2 bouyer static
220 1.4.2.2 bouyer #endif
221 1.4.2.2 bouyer int
222 1.4.2.2 bouyer altqclose(dev, flag, fmt, p)
223 1.4.2.2 bouyer dev_t dev;
224 1.4.2.2 bouyer int flag, fmt;
225 1.4.2.2 bouyer struct proc *p;
226 1.4.2.2 bouyer {
227 1.4.2.2 bouyer int unit = minor(dev);
228 1.4.2.2 bouyer
229 1.4.2.2 bouyer if (unit == 0)
230 1.4.2.2 bouyer return (0);
231 1.4.2.2 bouyer if (unit < naltqsw)
232 1.4.2.2 bouyer return (*altqsw[unit].d_close)(dev, flag, fmt, p);
233 1.4.2.2 bouyer
234 1.4.2.2 bouyer return ENXIO;
235 1.4.2.2 bouyer }
236 1.4.2.2 bouyer
237 1.4.2.2 bouyer #if !defined(__NetBSD__) && !defined(__OpenBSD__)
238 1.4.2.2 bouyer static
239 1.4.2.2 bouyer #endif
240 1.4.2.2 bouyer int
241 1.4.2.2 bouyer altqioctl(dev, cmd, addr, flag, p)
242 1.4.2.2 bouyer dev_t dev;
243 1.4.2.2 bouyer ioctlcmd_t cmd;
244 1.4.2.2 bouyer caddr_t addr;
245 1.4.2.2 bouyer int flag;
246 1.4.2.2 bouyer struct proc *p;
247 1.4.2.2 bouyer {
248 1.4.2.2 bouyer int unit = minor(dev);
249 1.4.2.2 bouyer
250 1.4.2.2 bouyer if (unit == 0) {
251 1.4.2.2 bouyer struct ifnet *ifp;
252 1.4.2.2 bouyer struct altqreq *typereq;
253 1.4.2.2 bouyer struct tbrreq *tbrreq;
254 1.4.2.2 bouyer int error;
255 1.4.2.2 bouyer
256 1.4.2.2 bouyer switch (cmd) {
257 1.4.2.2 bouyer case ALTQGTYPE:
258 1.4.2.2 bouyer case ALTQTBRGET:
259 1.4.2.2 bouyer break;
260 1.4.2.2 bouyer default:
261 1.4.2.2 bouyer #if (__FreeBSD_version > 400000)
262 1.4.2.2 bouyer if ((error = suser(p)) != 0)
263 1.4.2.2 bouyer return (error);
264 1.4.2.2 bouyer #else
265 1.4.2.2 bouyer if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
266 1.4.2.2 bouyer return (error);
267 1.4.2.2 bouyer #endif
268 1.4.2.2 bouyer break;
269 1.4.2.2 bouyer }
270 1.4.2.2 bouyer
271 1.4.2.2 bouyer switch (cmd) {
272 1.4.2.2 bouyer case ALTQGTYPE:
273 1.4.2.2 bouyer typereq = (struct altqreq *)addr;
274 1.4.2.2 bouyer if ((ifp = ifunit(typereq->ifname)) == NULL)
275 1.4.2.2 bouyer return (EINVAL);
276 1.4.2.2 bouyer typereq->arg = (u_long)ifp->if_snd.altq_type;
277 1.4.2.2 bouyer return (0);
278 1.4.2.2 bouyer case ALTQTBRSET:
279 1.4.2.2 bouyer tbrreq = (struct tbrreq *)addr;
280 1.4.2.2 bouyer if ((ifp = ifunit(tbrreq->ifname)) == NULL)
281 1.4.2.2 bouyer return (EINVAL);
282 1.4.2.2 bouyer return tbr_set(&ifp->if_snd, &tbrreq->tb_prof);
283 1.4.2.2 bouyer case ALTQTBRGET:
284 1.4.2.2 bouyer tbrreq = (struct tbrreq *)addr;
285 1.4.2.2 bouyer if ((ifp = ifunit(tbrreq->ifname)) == NULL)
286 1.4.2.2 bouyer return (EINVAL);
287 1.4.2.2 bouyer return tbr_get(&ifp->if_snd, &tbrreq->tb_prof);
288 1.4.2.2 bouyer default:
289 1.4.2.2 bouyer return (EINVAL);
290 1.4.2.2 bouyer }
291 1.4.2.2 bouyer }
292 1.4.2.2 bouyer if (unit < naltqsw)
293 1.4.2.2 bouyer return (*altqsw[unit].d_ioctl)(dev, cmd, addr, flag, p);
294 1.4.2.2 bouyer
295 1.4.2.2 bouyer return ENXIO;
296 1.4.2.2 bouyer }
297 1.4.2.2 bouyer
298 1.4.2.2 bouyer
299 1.4.2.2 bouyer #if !defined(__NetBSD__)
300 1.4.2.2 bouyer static int altq_devsw_installed = 0;
301 1.4.2.2 bouyer #endif
302 1.4.2.2 bouyer
303 1.4.2.2 bouyer #ifdef __FreeBSD__
304 1.4.2.2 bouyer #if (__FreeBSD_version < 400000)
305 1.4.2.2 bouyer #ifdef DEVFS
306 1.4.2.2 bouyer static void *altq_devfs_token[sizeof (altqsw) / sizeof (altqsw[0])];
307 1.4.2.2 bouyer #endif
308 1.4.2.2 bouyer
309 1.4.2.2 bouyer static void
310 1.4.2.2 bouyer altq_drvinit(unused)
311 1.4.2.2 bouyer void *unused;
312 1.4.2.2 bouyer {
313 1.4.2.2 bouyer dev_t dev;
314 1.4.2.2 bouyer #ifdef DEVFS
315 1.4.2.2 bouyer int i;
316 1.4.2.2 bouyer #endif
317 1.4.2.2 bouyer
318 1.4.2.2 bouyer if (!altq_devsw_installed) {
319 1.4.2.2 bouyer dev = makedev(CDEV_MAJOR,0);
320 1.4.2.2 bouyer cdevsw_add(&dev,&altq_cdevsw,NULL);
321 1.4.2.2 bouyer altq_devsw_installed = 1;
322 1.4.2.2 bouyer #ifdef DEVFS
323 1.4.2.2 bouyer for (i=0; i<naltqsw; i++)
324 1.4.2.2 bouyer altq_devfs_token[i] =
325 1.4.2.2 bouyer devfs_add_devswf(&altq_cdevsw, i, DV_CHR,
326 1.4.2.2 bouyer 0, 0, 0644, altqsw[i].d_name);
327 1.4.2.2 bouyer #endif
328 1.4.2.2 bouyer printf("altq: major number is %d\n", CDEV_MAJOR);
329 1.4.2.2 bouyer }
330 1.4.2.2 bouyer }
331 1.4.2.2 bouyer
332 1.4.2.2 bouyer #else /* FreeBSD 4.x */
333 1.4.2.2 bouyer
334 1.4.2.2 bouyer static void
335 1.4.2.2 bouyer altq_drvinit(unused)
336 1.4.2.2 bouyer void *unused;
337 1.4.2.2 bouyer {
338 1.4.2.2 bouyer int unit;
339 1.4.2.2 bouyer
340 1.4.2.2 bouyer cdevsw_add(&altq_cdevsw);
341 1.4.2.2 bouyer altq_devsw_installed = 1;
342 1.4.2.2 bouyer printf("altq: major number is %d\n", CDEV_MAJOR);
343 1.4.2.2 bouyer
344 1.4.2.2 bouyer /* create minor devices */
345 1.4.2.2 bouyer for (unit = 0; unit < naltqsw; unit++)
346 1.4.2.2 bouyer make_dev(&altq_cdevsw, unit, 0, 0, 0644,
347 1.4.2.2 bouyer altqsw[unit].d_name);
348 1.4.2.2 bouyer }
349 1.4.2.2 bouyer
350 1.4.2.2 bouyer #endif /* FreeBSD 4.x */
351 1.4.2.2 bouyer
352 1.4.2.2 bouyer SYSINIT(altqdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,altq_drvinit,NULL)
353 1.4.2.2 bouyer
354 1.4.2.2 bouyer #elif defined(__OpenBSD__)
355 1.4.2.2 bouyer
356 1.4.2.2 bouyer void
357 1.4.2.2 bouyer altqattach(int unused)
358 1.4.2.2 bouyer {
359 1.4.2.2 bouyer if (!altq_devsw_installed) {
360 1.4.2.2 bouyer bcopy(&altq_cdevsw,
361 1.4.2.2 bouyer &cdevsw[CDEV_MAJOR],
362 1.4.2.2 bouyer sizeof(struct cdevsw));
363 1.4.2.2 bouyer altq_devsw_installed = 1;
364 1.4.2.2 bouyer printf("altq: major number is %d\n", CDEV_MAJOR);
365 1.4.2.2 bouyer }
366 1.4.2.2 bouyer }
367 1.4.2.2 bouyer #elif defined(__NetBSD__)
368 1.4.2.2 bouyer /* NetBSD requires no altqattach() */
369 1.4.2.2 bouyer #else
370 1.4.2.2 bouyer #error altqattach()??
371 1.4.2.2 bouyer #endif
372 1.4.2.2 bouyer
373 1.4.2.2 bouyer #ifdef ALTQ_KLD
374 1.4.2.2 bouyer /*
375 1.4.2.2 bouyer * KLD support
376 1.4.2.2 bouyer */
377 1.4.2.2 bouyer static int altq_module_register __P((struct altq_module_data *));
378 1.4.2.2 bouyer static int altq_module_deregister __P((struct altq_module_data *));
379 1.4.2.2 bouyer
380 1.4.2.2 bouyer static struct altq_module_data *altq_modules[ALTQT_MAX];
381 1.4.2.2 bouyer static struct altqsw noqdisc = {"noq", noopen, noclose, noioctl};
382 1.4.2.2 bouyer
383 1.4.2.2 bouyer void altq_module_incref(type)
384 1.4.2.2 bouyer int type;
385 1.4.2.2 bouyer {
386 1.4.2.2 bouyer if (type < 0 || type >= ALTQT_MAX || altq_modules[type] == NULL)
387 1.4.2.2 bouyer return;
388 1.4.2.2 bouyer
389 1.4.2.2 bouyer altq_modules[type]->ref++;
390 1.4.2.2 bouyer }
391 1.4.2.2 bouyer
392 1.4.2.2 bouyer void altq_module_declref(type)
393 1.4.2.2 bouyer int type;
394 1.4.2.2 bouyer {
395 1.4.2.2 bouyer if (type < 0 || type >= ALTQT_MAX || altq_modules[type] == NULL)
396 1.4.2.2 bouyer return;
397 1.4.2.2 bouyer
398 1.4.2.2 bouyer altq_modules[type]->ref--;
399 1.4.2.2 bouyer }
400 1.4.2.2 bouyer
401 1.4.2.2 bouyer static int
402 1.4.2.2 bouyer altq_module_register(mdata)
403 1.4.2.2 bouyer struct altq_module_data *mdata;
404 1.4.2.2 bouyer {
405 1.4.2.2 bouyer int type = mdata->type;
406 1.4.2.2 bouyer
407 1.4.2.2 bouyer if (type < 0 || type >= ALTQT_MAX)
408 1.4.2.2 bouyer return (EINVAL);
409 1.4.2.2 bouyer if (altqsw[type].d_open != noopen)
410 1.4.2.2 bouyer return (EBUSY);
411 1.4.2.2 bouyer altqsw[type] = *mdata->altqsw; /* set discipline functions */
412 1.4.2.2 bouyer altq_modules[type] = mdata; /* save module data pointer */
413 1.4.2.2 bouyer return (0);
414 1.4.2.2 bouyer }
415 1.4.2.2 bouyer
416 1.4.2.2 bouyer static int
417 1.4.2.2 bouyer altq_module_deregister(mdata)
418 1.4.2.2 bouyer struct altq_module_data *mdata;
419 1.4.2.2 bouyer {
420 1.4.2.2 bouyer int type = mdata->type;
421 1.4.2.2 bouyer
422 1.4.2.2 bouyer if (type < 0 || type >= ALTQT_MAX)
423 1.4.2.2 bouyer return (EINVAL);
424 1.4.2.2 bouyer if (mdata != altq_modules[type])
425 1.4.2.2 bouyer return (EINVAL);
426 1.4.2.2 bouyer if (altq_modules[type]->ref > 0)
427 1.4.2.2 bouyer return (EBUSY);
428 1.4.2.2 bouyer altqsw[type] = noqdisc;
429 1.4.2.2 bouyer altq_modules[type] = NULL;
430 1.4.2.2 bouyer return (0);
431 1.4.2.2 bouyer }
432 1.4.2.2 bouyer
433 1.4.2.2 bouyer int
434 1.4.2.2 bouyer altq_module_handler(mod, cmd, arg)
435 1.4.2.2 bouyer module_t mod;
436 1.4.2.2 bouyer int cmd;
437 1.4.2.2 bouyer void * arg;
438 1.4.2.2 bouyer {
439 1.4.2.2 bouyer struct altq_module_data *data = (struct altq_module_data *)arg;
440 1.4.2.2 bouyer int error = 0;
441 1.4.2.2 bouyer
442 1.4.2.2 bouyer switch (cmd) {
443 1.4.2.2 bouyer case MOD_LOAD:
444 1.4.2.2 bouyer error = altq_module_register(data);
445 1.4.2.2 bouyer break;
446 1.4.2.2 bouyer
447 1.4.2.2 bouyer case MOD_UNLOAD:
448 1.4.2.2 bouyer error = altq_module_deregister(data);
449 1.4.2.2 bouyer break;
450 1.4.2.2 bouyer
451 1.4.2.2 bouyer default:
452 1.4.2.2 bouyer error = EINVAL;
453 1.4.2.2 bouyer break;
454 1.4.2.2 bouyer }
455 1.4.2.2 bouyer
456 1.4.2.2 bouyer return(error);
457 1.4.2.2 bouyer }
458 1.4.2.2 bouyer
459 1.4.2.2 bouyer #endif /* ALTQ_KLD */
460