Home | History | Annotate | Line # | Download | only in altq
altq_conf.c revision 1.14
      1  1.14  christos /*	$NetBSD: altq_conf.c,v 1.14 2006/05/15 00:05:39 christos Exp $	*/
      2   1.6    itojun /*	$KAME: altq_conf.c,v 1.13 2002/01/29 10:16:01 kjc 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.5     lukem 
     30   1.5     lukem #include <sys/cdefs.h>
     31  1.14  christos __KERNEL_RCSID(0, "$NetBSD: altq_conf.c,v 1.14 2006/05/15 00:05:39 christos Exp $");
     32   1.1   thorpej 
     33   1.1   thorpej #if defined(__FreeBSD__) || defined(__NetBSD__)
     34   1.1   thorpej #include "opt_altq.h"
     35   1.1   thorpej #if (__FreeBSD__ != 2)
     36   1.1   thorpej #include "opt_inet.h"
     37   1.1   thorpej #ifdef __FreeBSD__
     38   1.1   thorpej #include "opt_inet6.h"
     39   1.1   thorpej #endif
     40   1.1   thorpej #endif
     41   1.1   thorpej #endif /* __FreeBSD__ || __NetBSD__ */
     42   1.1   thorpej 
     43   1.1   thorpej /*
     44   1.1   thorpej  * altq device interface.
     45   1.1   thorpej  */
     46   1.1   thorpej #include <sys/param.h>
     47   1.1   thorpej #include <sys/systm.h>
     48   1.1   thorpej #include <sys/socket.h>
     49   1.1   thorpej #include <sys/kernel.h>
     50   1.1   thorpej #include <sys/proc.h>
     51   1.1   thorpej #include <sys/errno.h>
     52  1.14  christos #include <sys/kauth.h>
     53   1.1   thorpej #if defined(__FreeBSD__) && (__FreeBSD_version < 400000) && defined(DEVFS)
     54   1.1   thorpej #include <sys/devfsext.h>
     55   1.1   thorpej #endif /*DEVFS*/
     56   1.1   thorpej #include <net/if.h>
     57   1.1   thorpej 
     58   1.1   thorpej #include <altq/altq.h>
     59   1.9  jdolecek #include <altq/altqconf.h>
     60   1.1   thorpej #include <altq/altq_conf.h>
     61   1.1   thorpej 
     62   1.1   thorpej #ifdef ALTQ_CBQ
     63   1.1   thorpej altqdev_decl(cbq);
     64   1.1   thorpej #endif
     65   1.1   thorpej #ifdef ALTQ_WFQ
     66   1.1   thorpej altqdev_decl(wfq);
     67   1.1   thorpej #endif
     68   1.1   thorpej #ifdef ALTQ_AFMAP
     69   1.1   thorpej altqdev_decl(afm);
     70   1.1   thorpej #endif
     71   1.1   thorpej #ifdef ALTQ_FIFOQ
     72   1.1   thorpej altqdev_decl(fifoq);
     73   1.1   thorpej #endif
     74   1.1   thorpej #ifdef ALTQ_RED
     75   1.1   thorpej altqdev_decl(red);
     76   1.1   thorpej #endif
     77   1.1   thorpej #ifdef ALTQ_RIO
     78   1.1   thorpej altqdev_decl(rio);
     79   1.1   thorpej #endif
     80   1.1   thorpej #ifdef ALTQ_LOCALQ
     81   1.1   thorpej altqdev_decl(localq);
     82   1.1   thorpej #endif
     83   1.1   thorpej #ifdef ALTQ_HFSC
     84   1.1   thorpej altqdev_decl(hfsc);
     85   1.1   thorpej #endif
     86   1.1   thorpej #ifdef ALTQ_CDNR
     87   1.1   thorpej altqdev_decl(cdnr);
     88   1.1   thorpej #endif
     89   1.1   thorpej #ifdef ALTQ_BLUE
     90   1.1   thorpej altqdev_decl(blue);
     91   1.1   thorpej #endif
     92   1.1   thorpej #ifdef ALTQ_PRIQ
     93   1.1   thorpej altqdev_decl(priq);
     94   1.1   thorpej #endif
     95   1.1   thorpej 
     96   1.1   thorpej /*
     97   1.1   thorpej  * altq minor device (discipline) table
     98   1.1   thorpej  */
     99   1.1   thorpej static struct altqsw altqsw[] = {				/* minor */
    100   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},  /* 0 (reserved) */
    101   1.1   thorpej #ifdef ALTQ_CBQ
    102   1.1   thorpej 	{"cbq",	cbqopen,	cbqclose,	cbqioctl},	/* 1 */
    103   1.1   thorpej #else
    104   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 1 */
    105   1.1   thorpej #endif
    106   1.1   thorpej #ifdef ALTQ_WFQ
    107   1.1   thorpej 	{"wfq",	wfqopen,	wfqclose,	wfqioctl},	/* 2 */
    108   1.1   thorpej #else
    109   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 2 */
    110   1.1   thorpej #endif
    111   1.1   thorpej #ifdef ALTQ_AFMAP
    112   1.1   thorpej 	{"afm",	afmopen,	afmclose,	afmioctl},	/* 3 */
    113   1.1   thorpej #else
    114   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 3 */
    115   1.1   thorpej #endif
    116   1.1   thorpej #ifdef ALTQ_FIFOQ
    117   1.1   thorpej 	{"fifoq", fifoqopen,	fifoqclose,	fifoqioctl},	/* 4 */
    118   1.1   thorpej #else
    119   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 4 */
    120   1.1   thorpej #endif
    121   1.1   thorpej #ifdef ALTQ_RED
    122   1.1   thorpej 	{"red", redopen,	redclose,	redioctl},	/* 5 */
    123   1.1   thorpej #else
    124   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 5 */
    125   1.1   thorpej #endif
    126   1.1   thorpej #ifdef ALTQ_RIO
    127   1.1   thorpej 	{"rio", rioopen,	rioclose,	rioioctl},	/* 6 */
    128   1.1   thorpej #else
    129   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 6 */
    130   1.1   thorpej #endif
    131   1.1   thorpej #ifdef ALTQ_LOCALQ
    132   1.1   thorpej 	{"localq",localqopen,	localqclose,	localqioctl}, /* 7 (local use) */
    133   1.1   thorpej #else
    134   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},  /* 7 (local use) */
    135   1.1   thorpej #endif
    136   1.1   thorpej #ifdef ALTQ_HFSC
    137   1.1   thorpej 	{"hfsc",hfscopen,	hfscclose,	hfscioctl},	/* 8 */
    138   1.1   thorpej #else
    139   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 8 */
    140   1.1   thorpej #endif
    141   1.1   thorpej #ifdef ALTQ_CDNR
    142   1.1   thorpej 	{"cdnr",cdnropen,	cdnrclose,	cdnrioctl},	/* 9 */
    143   1.1   thorpej #else
    144   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 9 */
    145   1.1   thorpej #endif
    146   1.1   thorpej #ifdef ALTQ_BLUE
    147   1.1   thorpej 	{"blue",blueopen,	blueclose,	blueioctl},	/* 10 */
    148   1.1   thorpej #else
    149   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 10 */
    150   1.1   thorpej #endif
    151   1.1   thorpej #ifdef ALTQ_PRIQ
    152   1.1   thorpej 	{"priq",priqopen,	priqclose,	priqioctl},	/* 11 */
    153   1.1   thorpej #else
    154   1.1   thorpej 	{"noq",	noopen,		noclose,	noioctl},	/* 11 */
    155   1.1   thorpej #endif
    156   1.1   thorpej };
    157   1.1   thorpej 
    158   1.1   thorpej /*
    159   1.1   thorpej  * altq major device support
    160   1.1   thorpej  */
    161   1.1   thorpej int	naltqsw = sizeof (altqsw) / sizeof (altqsw[0]);
    162   1.1   thorpej 
    163   1.8   gehenna #if defined(__NetBSD__)
    164   1.8   gehenna dev_type_open(altqopen);
    165   1.8   gehenna dev_type_close(altqclose);
    166   1.8   gehenna dev_type_ioctl(altqioctl);
    167   1.8   gehenna #endif
    168   1.8   gehenna #if defined(__OpenBSD__)
    169   1.1   thorpej static	d_open_t	altqopen;
    170   1.1   thorpej static	d_close_t	altqclose;
    171   1.1   thorpej static	d_ioctl_t	altqioctl;
    172   1.1   thorpej #endif
    173   1.1   thorpej #ifdef __FreeBSD__
    174   1.1   thorpej static void altq_drvinit __P((void *));
    175   1.1   thorpej #else
    176   1.1   thorpej void	altqattach __P((int));
    177   1.1   thorpej #endif
    178   1.1   thorpej 
    179   1.1   thorpej #if defined(__FreeBSD__)
    180   1.1   thorpej #define	CDEV_MAJOR 96		/* FreeBSD official number */
    181   1.1   thorpej #elif defined(__OpenBSD__)
    182   1.1   thorpej #if defined(__i386__)
    183   1.6    itojun #define	CDEV_MAJOR 74		/* OpenBSD i386 (official) */
    184   1.1   thorpej #elif defined(__alpha__)
    185   1.6    itojun #define	CDEV_MAJOR 53		/* OpenBSD alpha (official) */
    186   1.1   thorpej #else
    187   1.1   thorpej #error arch not supported
    188   1.1   thorpej #endif
    189   1.1   thorpej #endif
    190   1.1   thorpej 
    191   1.1   thorpej #if defined(__FreeBSD__)
    192   1.1   thorpej #if (__FreeBSD_version < 400000)
    193  1.11     perry static struct cdevsw altq_cdevsw =
    194   1.1   thorpej         { altqopen,	altqclose,	noread,	        nowrite,
    195   1.1   thorpej 	  altqioctl,	nostop,		nullreset,	nodevtotty,
    196   1.1   thorpej  	  seltrue,	nommap,		NULL,	"altq",	NULL,	  -1 };
    197   1.1   thorpej #else
    198  1.11     perry static struct cdevsw altq_cdevsw =
    199   1.1   thorpej         { altqopen,	altqclose,	noread,	        nowrite,
    200  1.11     perry 	  altqioctl,	seltrue,	nommap,		nostrategy,
    201   1.1   thorpej 	  "altq",	CDEV_MAJOR,	nodump,		nopsize,  0,  -1 };
    202   1.1   thorpej #endif
    203   1.7   gehenna #endif
    204   1.7   gehenna 
    205   1.7   gehenna #if defined(__NetBSD__)
    206   1.7   gehenna const struct cdevsw altq_cdevsw = {
    207   1.7   gehenna 	altqopen, altqclose, noread, nowrite, altqioctl,
    208  1.10  jdolecek 	nostop, notty, nopoll, nommap, nokqfilter
    209   1.7   gehenna };
    210   1.1   thorpej #endif
    211   1.1   thorpej 
    212   1.4   thorpej #if !defined(__NetBSD__) && !defined(__OpenBSD__)
    213   1.1   thorpej static
    214   1.1   thorpej #endif
    215   1.1   thorpej int
    216  1.12  christos altqopen(dev, flag, fmt, l)
    217   1.1   thorpej 	dev_t dev;
    218   1.1   thorpej 	int flag, fmt;
    219  1.12  christos 	struct lwp *l;
    220   1.1   thorpej {
    221   1.1   thorpej 	int unit = minor(dev);
    222   1.1   thorpej 
    223   1.1   thorpej 	if (unit == 0)
    224   1.1   thorpej 		return (0);
    225   1.1   thorpej 	if (unit < naltqsw)
    226  1.12  christos 		return (*altqsw[unit].d_open)(dev, flag, fmt, l);
    227   1.1   thorpej 
    228   1.1   thorpej 	return ENXIO;
    229   1.1   thorpej }
    230   1.1   thorpej 
    231   1.4   thorpej #if !defined(__NetBSD__) && !defined(__OpenBSD__)
    232   1.1   thorpej static
    233   1.1   thorpej #endif
    234   1.1   thorpej int
    235  1.12  christos altqclose(dev, flag, fmt, l)
    236   1.1   thorpej 	dev_t dev;
    237   1.1   thorpej 	int flag, fmt;
    238  1.12  christos 	struct lwp *l;
    239   1.1   thorpej {
    240   1.1   thorpej 	int unit = minor(dev);
    241   1.1   thorpej 
    242   1.1   thorpej 	if (unit == 0)
    243   1.1   thorpej 		return (0);
    244   1.1   thorpej 	if (unit < naltqsw)
    245  1.12  christos 		return (*altqsw[unit].d_close)(dev, flag, fmt, l);
    246   1.1   thorpej 
    247   1.1   thorpej 	return ENXIO;
    248   1.1   thorpej }
    249   1.1   thorpej 
    250   1.4   thorpej #if !defined(__NetBSD__) && !defined(__OpenBSD__)
    251   1.1   thorpej static
    252   1.1   thorpej #endif
    253   1.1   thorpej int
    254  1.12  christos altqioctl(dev, cmd, addr, flag, l)
    255   1.1   thorpej 	dev_t dev;
    256   1.1   thorpej 	ioctlcmd_t cmd;
    257   1.1   thorpej 	caddr_t addr;
    258   1.1   thorpej 	int flag;
    259  1.12  christos 	struct lwp *l;
    260   1.1   thorpej {
    261  1.12  christos 	struct proc *p = l->l_proc;
    262   1.1   thorpej 	int unit = minor(dev);
    263   1.1   thorpej 
    264   1.1   thorpej 	if (unit == 0) {
    265   1.1   thorpej 		struct ifnet *ifp;
    266   1.1   thorpej 		struct altqreq *typereq;
    267   1.1   thorpej 		struct tbrreq *tbrreq;
    268   1.1   thorpej 		int error;
    269   1.1   thorpej 
    270   1.1   thorpej 		switch (cmd) {
    271   1.1   thorpej 		case ALTQGTYPE:
    272   1.1   thorpej 		case ALTQTBRGET:
    273   1.1   thorpej 			break;
    274   1.1   thorpej 		default:
    275   1.1   thorpej #if (__FreeBSD_version > 400000)
    276   1.1   thorpej 			if ((error = suser(p)) != 0)
    277   1.1   thorpej 				return (error);
    278   1.1   thorpej #else
    279  1.13      elad 			if ((error = kauth_authorize_generic(p->p_cred,
    280  1.13      elad 						       KAUTH_GENERIC_ISSUSER,
    281  1.13      elad 						       &p->p_acflag)) != 0)
    282   1.1   thorpej 				return (error);
    283   1.1   thorpej #endif
    284   1.1   thorpej 			break;
    285   1.1   thorpej 		}
    286   1.1   thorpej 
    287   1.1   thorpej 		switch (cmd) {
    288   1.1   thorpej 		case ALTQGTYPE:
    289   1.1   thorpej 			typereq = (struct altqreq *)addr;
    290   1.1   thorpej 			if ((ifp = ifunit(typereq->ifname)) == NULL)
    291   1.1   thorpej 				return (EINVAL);
    292   1.1   thorpej 			typereq->arg = (u_long)ifp->if_snd.altq_type;
    293   1.1   thorpej 			return (0);
    294   1.1   thorpej 		case ALTQTBRSET:
    295   1.1   thorpej 			tbrreq = (struct tbrreq *)addr;
    296   1.1   thorpej 			if ((ifp = ifunit(tbrreq->ifname)) == NULL)
    297   1.1   thorpej 				return (EINVAL);
    298   1.1   thorpej 			return tbr_set(&ifp->if_snd, &tbrreq->tb_prof);
    299   1.1   thorpej 		case ALTQTBRGET:
    300   1.1   thorpej 			tbrreq = (struct tbrreq *)addr;
    301   1.1   thorpej 			if ((ifp = ifunit(tbrreq->ifname)) == NULL)
    302   1.1   thorpej 				return (EINVAL);
    303   1.1   thorpej 			return tbr_get(&ifp->if_snd, &tbrreq->tb_prof);
    304   1.1   thorpej 		default:
    305   1.1   thorpej 			return (EINVAL);
    306   1.1   thorpej 		}
    307   1.1   thorpej 	}
    308   1.1   thorpej 	if (unit < naltqsw)
    309  1.12  christos 		return (*altqsw[unit].d_ioctl)(dev, cmd, addr, flag, l);
    310   1.1   thorpej 
    311   1.1   thorpej 	return ENXIO;
    312   1.1   thorpej }
    313   1.1   thorpej 
    314   1.4   thorpej #if !defined(__NetBSD__)
    315   1.1   thorpej static int altq_devsw_installed = 0;
    316   1.4   thorpej #endif
    317   1.1   thorpej 
    318   1.1   thorpej #ifdef __FreeBSD__
    319   1.1   thorpej #if (__FreeBSD_version < 400000)
    320   1.1   thorpej #ifdef DEVFS
    321   1.1   thorpej static	void *altq_devfs_token[sizeof (altqsw) / sizeof (altqsw[0])];
    322   1.1   thorpej #endif
    323   1.1   thorpej 
    324   1.1   thorpej static void
    325   1.1   thorpej altq_drvinit(unused)
    326   1.1   thorpej 	void *unused;
    327   1.1   thorpej {
    328   1.1   thorpej 	dev_t dev;
    329   1.1   thorpej #ifdef DEVFS
    330   1.1   thorpej 	int i;
    331   1.1   thorpej #endif
    332   1.1   thorpej 
    333   1.1   thorpej 	if (!altq_devsw_installed) {
    334   1.1   thorpej 		dev = makedev(CDEV_MAJOR,0);
    335   1.1   thorpej 		cdevsw_add(&dev,&altq_cdevsw,NULL);
    336   1.1   thorpej 		altq_devsw_installed = 1;
    337   1.1   thorpej #ifdef DEVFS
    338   1.1   thorpej 		for (i=0; i<naltqsw; i++)
    339   1.1   thorpej 			altq_devfs_token[i] =
    340   1.1   thorpej 				devfs_add_devswf(&altq_cdevsw, i, DV_CHR,
    341   1.1   thorpej 						 0, 0, 0644, altqsw[i].d_name);
    342   1.1   thorpej #endif
    343   1.1   thorpej 		printf("altq: major number is %d\n", CDEV_MAJOR);
    344   1.1   thorpej 	}
    345   1.1   thorpej }
    346   1.1   thorpej 
    347   1.1   thorpej #else /* FreeBSD 4.x */
    348   1.1   thorpej 
    349   1.1   thorpej static void
    350   1.1   thorpej altq_drvinit(unused)
    351   1.1   thorpej 	void *unused;
    352   1.1   thorpej {
    353   1.1   thorpej 	int unit;
    354   1.1   thorpej 
    355   1.1   thorpej 	cdevsw_add(&altq_cdevsw);
    356   1.1   thorpej 	altq_devsw_installed = 1;
    357   1.1   thorpej 	printf("altq: major number is %d\n", CDEV_MAJOR);
    358   1.1   thorpej 
    359   1.1   thorpej 	/* create minor devices */
    360   1.1   thorpej 	for (unit = 0; unit < naltqsw; unit++)
    361   1.1   thorpej 		make_dev(&altq_cdevsw, unit, 0, 0, 0644,
    362   1.1   thorpej 			 altqsw[unit].d_name);
    363   1.1   thorpej }
    364   1.1   thorpej 
    365   1.1   thorpej #endif /* FreeBSD 4.x */
    366   1.1   thorpej 
    367   1.1   thorpej SYSINIT(altqdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,altq_drvinit,NULL)
    368   1.1   thorpej 
    369   1.1   thorpej #endif
    370   1.1   thorpej 
    371   1.1   thorpej #ifdef ALTQ_KLD
    372   1.1   thorpej /*
    373   1.1   thorpej  * KLD support
    374   1.1   thorpej  */
    375   1.1   thorpej static int altq_module_register __P((struct altq_module_data *));
    376   1.1   thorpej static int altq_module_deregister __P((struct altq_module_data *));
    377   1.1   thorpej 
    378   1.1   thorpej static struct altq_module_data *altq_modules[ALTQT_MAX];
    379   1.1   thorpej static struct altqsw noqdisc = {"noq", noopen, noclose, noioctl};
    380   1.1   thorpej 
    381   1.1   thorpej void altq_module_incref(type)
    382   1.1   thorpej 	int type;
    383   1.1   thorpej {
    384   1.1   thorpej 	if (type < 0 || type >= ALTQT_MAX || altq_modules[type] == NULL)
    385   1.1   thorpej 		return;
    386   1.1   thorpej 
    387   1.1   thorpej 	altq_modules[type]->ref++;
    388   1.1   thorpej }
    389   1.1   thorpej 
    390   1.1   thorpej void altq_module_declref(type)
    391   1.1   thorpej 	int type;
    392   1.1   thorpej {
    393   1.1   thorpej 	if (type < 0 || type >= ALTQT_MAX || altq_modules[type] == NULL)
    394   1.1   thorpej 		return;
    395   1.1   thorpej 
    396   1.1   thorpej 	altq_modules[type]->ref--;
    397   1.1   thorpej }
    398   1.1   thorpej 
    399  1.11     perry static int
    400   1.1   thorpej altq_module_register(mdata)
    401   1.1   thorpej 	struct altq_module_data *mdata;
    402   1.1   thorpej {
    403   1.1   thorpej 	int type = mdata->type;
    404   1.1   thorpej 
    405   1.1   thorpej 	if (type < 0 || type >= ALTQT_MAX)
    406   1.1   thorpej 		return (EINVAL);
    407   1.1   thorpej 	if (altqsw[type].d_open != noopen)
    408   1.1   thorpej 		return (EBUSY);
    409   1.1   thorpej 	altqsw[type] = *mdata->altqsw;	/* set discipline functions */
    410   1.1   thorpej 	altq_modules[type] = mdata;	/* save module data pointer */
    411   1.1   thorpej 	return (0);
    412   1.1   thorpej }
    413   1.1   thorpej 
    414  1.11     perry static int
    415   1.1   thorpej altq_module_deregister(mdata)
    416   1.1   thorpej 	struct altq_module_data *mdata;
    417   1.1   thorpej {
    418   1.1   thorpej 	int type = mdata->type;
    419   1.1   thorpej 
    420   1.1   thorpej 	if (type < 0 || type >= ALTQT_MAX)
    421   1.1   thorpej 		return (EINVAL);
    422   1.1   thorpej 	if (mdata != altq_modules[type])
    423   1.1   thorpej 		return (EINVAL);
    424   1.1   thorpej 	if (altq_modules[type]->ref > 0)
    425   1.1   thorpej 		return (EBUSY);
    426   1.1   thorpej 	altqsw[type] = noqdisc;
    427   1.1   thorpej 	altq_modules[type] = NULL;
    428   1.1   thorpej 	return (0);
    429   1.1   thorpej }
    430   1.1   thorpej 
    431   1.1   thorpej int
    432   1.1   thorpej altq_module_handler(mod, cmd, arg)
    433   1.1   thorpej     module_t	mod;
    434   1.1   thorpej     int cmd;
    435   1.1   thorpej     void * arg;
    436   1.1   thorpej {
    437   1.1   thorpej 	struct altq_module_data *data = (struct altq_module_data *)arg;
    438   1.1   thorpej 	int	error = 0;
    439   1.1   thorpej 
    440   1.1   thorpej 	switch (cmd) {
    441   1.1   thorpej 	case MOD_LOAD:
    442   1.1   thorpej 		error = altq_module_register(data);
    443   1.1   thorpej 		break;
    444   1.1   thorpej 
    445   1.1   thorpej 	case MOD_UNLOAD:
    446   1.1   thorpej 		error = altq_module_deregister(data);
    447   1.1   thorpej 		break;
    448   1.1   thorpej 
    449   1.1   thorpej 	default:
    450   1.1   thorpej 		error = EINVAL;
    451   1.1   thorpej 		break;
    452   1.1   thorpej 	}
    453   1.1   thorpej 
    454   1.1   thorpej 	return(error);
    455   1.1   thorpej }
    456   1.6    itojun 
    457   1.1   thorpej #endif  /* ALTQ_KLD */
    458