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