Home | History | Annotate | Line # | Download | only in libaltq
qop_priq.c revision 1.2
      1  1.1  thorpej /*	$KAME: qop_priq.c,v 1.1 2000/10/18 09:15:19 kjc Exp $	*/
      2  1.1  thorpej /*
      3  1.1  thorpej  * Copyright (C) 2000
      4  1.1  thorpej  *	Sony Computer Science Laboratories, Inc.  All rights reserved.
      5  1.1  thorpej  *
      6  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      7  1.1  thorpej  * modification, are permitted provided that the following conditions
      8  1.1  thorpej  * are met:
      9  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     10  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     11  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     14  1.1  thorpej  *
     15  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     19  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  thorpej  * SUCH DAMAGE.
     26  1.1  thorpej  */
     27  1.1  thorpej 
     28  1.1  thorpej #include <sys/param.h>
     29  1.1  thorpej #include <sys/socket.h>
     30  1.1  thorpej #include <sys/sockio.h>
     31  1.1  thorpej #include <sys/ioctl.h>
     32  1.1  thorpej #include <sys/fcntl.h>
     33  1.1  thorpej #include <net/if.h>
     34  1.1  thorpej #include <netinet/in.h>
     35  1.1  thorpej #include <arpa/inet.h>
     36  1.1  thorpej 
     37  1.1  thorpej #include <stdio.h>
     38  1.1  thorpej #include <stdlib.h>
     39  1.1  thorpej #include <unistd.h>
     40  1.1  thorpej #include <stddef.h>
     41  1.1  thorpej #include <string.h>
     42  1.1  thorpej #include <ctype.h>
     43  1.1  thorpej #include <errno.h>
     44  1.1  thorpej #include <syslog.h>
     45  1.1  thorpej #include <netdb.h>
     46  1.1  thorpej 
     47  1.1  thorpej #include <altq/altq.h>
     48  1.1  thorpej #include <altq/altq_priq.h>
     49  1.1  thorpej #include "altq_qop.h"
     50  1.1  thorpej #include "qop_priq.h"
     51  1.1  thorpej 
     52  1.2   itojun static int qop_priq_enable_hook(struct ifinfo *);
     53  1.1  thorpej 
     54  1.2   itojun static int priq_attach(struct ifinfo *);
     55  1.2   itojun static int priq_detach(struct ifinfo *);
     56  1.2   itojun static int priq_clear(struct ifinfo *);
     57  1.2   itojun static int priq_enable(struct ifinfo *);
     58  1.2   itojun static int priq_disable(struct ifinfo *);
     59  1.2   itojun static int priq_add_class(struct classinfo *);
     60  1.2   itojun static int priq_modify_class(struct classinfo *, void *);
     61  1.2   itojun static int priq_delete_class(struct classinfo *);
     62  1.2   itojun static int priq_add_filter(struct fltrinfo *);
     63  1.2   itojun static int priq_delete_filter(struct fltrinfo *);
     64  1.1  thorpej 
     65  1.1  thorpej #define PRIQ_DEVICE	"/dev/altq/priq"
     66  1.1  thorpej 
     67  1.1  thorpej static int priq_fd = -1;
     68  1.1  thorpej static int priq_refcount = 0;
     69  1.1  thorpej 
     70  1.1  thorpej static struct qdisc_ops priq_qdisc = {
     71  1.1  thorpej 	ALTQT_PRIQ,
     72  1.1  thorpej 	"priq",
     73  1.1  thorpej 	priq_attach,
     74  1.1  thorpej 	priq_detach,
     75  1.1  thorpej 	priq_clear,
     76  1.1  thorpej 	priq_enable,
     77  1.1  thorpej 	priq_disable,
     78  1.1  thorpej 	priq_add_class,
     79  1.1  thorpej 	priq_modify_class,
     80  1.1  thorpej 	priq_delete_class,
     81  1.1  thorpej 	priq_add_filter,
     82  1.1  thorpej 	priq_delete_filter,
     83  1.1  thorpej };
     84  1.1  thorpej 
     85  1.1  thorpej #define EQUAL(s1, s2)	(strcmp((s1), (s2)) == 0)
     86  1.1  thorpej 
     87  1.1  thorpej /*
     88  1.1  thorpej  * parser interface
     89  1.1  thorpej  */
     90  1.1  thorpej int
     91  1.1  thorpej priq_interface_parser(const char *ifname, int argc, char **argv)
     92  1.1  thorpej {
     93  1.1  thorpej 	u_int  	bandwidth = 100000000;	/* 100Mbps */
     94  1.1  thorpej 	u_int	tbrsize = 0;
     95  1.1  thorpej 	int	flags = 0;
     96  1.1  thorpej 
     97  1.1  thorpej 	/*
     98  1.1  thorpej 	 * process options
     99  1.1  thorpej 	 */
    100  1.1  thorpej 	while (argc > 0) {
    101  1.1  thorpej 		if (EQUAL(*argv, "bandwidth")) {
    102  1.1  thorpej 			argc--; argv++;
    103  1.1  thorpej 			if (argc > 0)
    104  1.1  thorpej 				bandwidth = atobps(*argv);
    105  1.1  thorpej 		} else if (EQUAL(*argv, "tbrsize")) {
    106  1.1  thorpej 			argc--; argv++;
    107  1.1  thorpej 			if (argc > 0)
    108  1.1  thorpej 				tbrsize = atobytes(*argv);
    109  1.1  thorpej 		} else if (EQUAL(*argv, "priq")) {
    110  1.1  thorpej 			/* just skip */
    111  1.1  thorpej 		} else {
    112  1.1  thorpej 			LOG(LOG_ERR, 0, "Unknown keyword '%s'\n", argv);
    113  1.1  thorpej 			return (0);
    114  1.1  thorpej 		}
    115  1.1  thorpej 		argc--; argv++;
    116  1.1  thorpej 	}
    117  1.1  thorpej 
    118  1.1  thorpej 	if (qcmd_tbr_register(ifname, bandwidth, tbrsize) != 0)
    119  1.1  thorpej 		return (0);
    120  1.1  thorpej 
    121  1.1  thorpej 	if (qcmd_priq_add_if(ifname, bandwidth, flags) != 0)
    122  1.1  thorpej 		return (0);
    123  1.1  thorpej 	return (1);
    124  1.1  thorpej }
    125  1.1  thorpej 
    126  1.1  thorpej int
    127  1.1  thorpej priq_class_parser(const char *ifname, const char *class_name,
    128  1.1  thorpej 		  const char *parent_name, int argc, char **argv)
    129  1.1  thorpej {
    130  1.1  thorpej 	int	pri = 0, qlimit = 50;
    131  1.1  thorpej 	int	flags = 0, error;
    132  1.1  thorpej 
    133  1.1  thorpej 	while (argc > 0) {
    134  1.1  thorpej 		if (EQUAL(*argv, "priority")) {
    135  1.1  thorpej 			argc--; argv++;
    136  1.1  thorpej 			if (argc > 0)
    137  1.1  thorpej 				pri = strtoul(*argv, NULL, 0);
    138  1.1  thorpej 		} else if (EQUAL(*argv, "qlimit")) {
    139  1.1  thorpej 			argc--; argv++;
    140  1.1  thorpej 			if (argc > 0)
    141  1.1  thorpej 				qlimit = strtoul(*argv, NULL, 0);
    142  1.1  thorpej 		} else if (EQUAL(*argv, "default")) {
    143  1.1  thorpej 			flags |= PRCF_DEFAULTCLASS;
    144  1.1  thorpej 		} else if (EQUAL(*argv, "red")) {
    145  1.1  thorpej 			flags |= PRCF_RED;
    146  1.1  thorpej 		} else if (EQUAL(*argv, "ecn")) {
    147  1.1  thorpej 			flags |= PRCF_ECN;
    148  1.1  thorpej 		} else if (EQUAL(*argv, "rio")) {
    149  1.1  thorpej 			flags |= PRCF_RIO;
    150  1.1  thorpej 		} else if (EQUAL(*argv, "cleardscp")) {
    151  1.1  thorpej 			flags |= PRCF_CLEARDSCP;
    152  1.1  thorpej 		} else {
    153  1.1  thorpej 			LOG(LOG_ERR, 0,
    154  1.1  thorpej 			    "Unknown keyword '%s' in %s, line %d\n",
    155  1.1  thorpej 			    *argv, altqconfigfile, line_no);
    156  1.1  thorpej 			return (0);
    157  1.1  thorpej 		}
    158  1.1  thorpej 
    159  1.1  thorpej 		argc--; argv++;
    160  1.1  thorpej 	}
    161  1.1  thorpej 
    162  1.1  thorpej 	if ((flags & PRCF_ECN) && (flags & (PRCF_RED|PRCF_RIO)) == 0)
    163  1.1  thorpej 		flags |= PRCF_RED;
    164  1.1  thorpej 
    165  1.1  thorpej 	error = qcmd_priq_add_class(ifname, class_name, pri, qlimit, flags);
    166  1.1  thorpej 
    167  1.1  thorpej 	if (error) {
    168  1.1  thorpej 		LOG(LOG_ERR, errno, "priq_class_parser: %s\n",
    169  1.1  thorpej 		    qoperror(error));
    170  1.1  thorpej 		return (0);
    171  1.1  thorpej 	}
    172  1.1  thorpej 	return (1);
    173  1.1  thorpej }
    174  1.1  thorpej 
    175  1.1  thorpej /*
    176  1.1  thorpej  * qcmd api
    177  1.1  thorpej  */
    178  1.1  thorpej int
    179  1.1  thorpej qcmd_priq_add_if(const char *ifname, u_int bandwidth, int flags)
    180  1.1  thorpej {
    181  1.1  thorpej 	int error;
    182  1.1  thorpej 
    183  1.1  thorpej 	error = qop_priq_add_if(NULL, ifname, bandwidth, flags);
    184  1.1  thorpej 	if (error != 0)
    185  1.1  thorpej 		LOG(LOG_ERR, errno, "%s: can't add priq on interface '%s'\n",
    186  1.1  thorpej 		    qoperror(error), ifname);
    187  1.1  thorpej 	return (error);
    188  1.1  thorpej }
    189  1.1  thorpej 
    190  1.1  thorpej int
    191  1.1  thorpej qcmd_priq_add_class(const char *ifname, const char *class_name,
    192  1.1  thorpej 		    int pri, int qlimit, int flags)
    193  1.1  thorpej {
    194  1.1  thorpej 	struct ifinfo *ifinfo;
    195  1.1  thorpej 	int error = 0;
    196  1.1  thorpej 
    197  1.1  thorpej 	if ((ifinfo = ifname2ifinfo(ifname)) == NULL)
    198  1.1  thorpej 		error = QOPERR_BADIF;
    199  1.1  thorpej 
    200  1.1  thorpej 	if (error == 0)
    201  1.1  thorpej 		error = qop_priq_add_class(NULL, class_name, ifinfo,
    202  1.1  thorpej 					   pri, qlimit, flags);
    203  1.1  thorpej 	if (error != 0)
    204  1.1  thorpej 		LOG(LOG_ERR, errno,
    205  1.1  thorpej 		    "priq: %s: can't add class '%s' on interface '%s'\n",
    206  1.1  thorpej 		    qoperror(error), class_name, ifname);
    207  1.1  thorpej 	return (error);
    208  1.1  thorpej }
    209  1.1  thorpej 
    210  1.1  thorpej int
    211  1.1  thorpej qcmd_priq_modify_class(const char *ifname, const char *class_name,
    212  1.1  thorpej 		       int pri, int qlimit, int flags)
    213  1.1  thorpej {
    214  1.1  thorpej 	struct ifinfo *ifinfo;
    215  1.1  thorpej 	struct classinfo *clinfo;
    216  1.1  thorpej 
    217  1.1  thorpej 	if ((ifinfo = ifname2ifinfo(ifname)) == NULL)
    218  1.1  thorpej 		return (QOPERR_BADIF);
    219  1.1  thorpej 
    220  1.1  thorpej 	if ((clinfo = clname2clinfo(ifinfo, class_name)) == NULL)
    221  1.1  thorpej 		return (QOPERR_BADCLASS);
    222  1.1  thorpej 
    223  1.1  thorpej 	return qop_priq_modify_class(clinfo, pri, qlimit, flags);
    224  1.1  thorpej }
    225  1.1  thorpej 
    226  1.1  thorpej /*
    227  1.1  thorpej  * qop api
    228  1.1  thorpej  */
    229  1.1  thorpej int
    230  1.1  thorpej qop_priq_add_if(struct ifinfo **rp, const char *ifname,
    231  1.1  thorpej 		u_int bandwidth, int flags)
    232  1.1  thorpej {
    233  1.1  thorpej 	struct ifinfo *ifinfo = NULL;
    234  1.1  thorpej 	struct priq_ifinfo *priq_ifinfo = NULL;
    235  1.1  thorpej 	int error;
    236  1.1  thorpej 
    237  1.1  thorpej 	if ((priq_ifinfo = calloc(1, sizeof(*priq_ifinfo))) == NULL)
    238  1.1  thorpej 		return (QOPERR_NOMEM);
    239  1.1  thorpej 
    240  1.1  thorpej 	error = qop_add_if(&ifinfo, ifname, bandwidth,
    241  1.1  thorpej 			   &priq_qdisc, priq_ifinfo);
    242  1.1  thorpej 	if (error != 0)
    243  1.1  thorpej 		goto err_ret;
    244  1.1  thorpej 
    245  1.1  thorpej 	/* set enable hook */
    246  1.1  thorpej 	ifinfo->enable_hook = qop_priq_enable_hook;
    247  1.1  thorpej 
    248  1.1  thorpej 	if (rp != NULL)
    249  1.1  thorpej 		*rp = ifinfo;
    250  1.1  thorpej 	return (0);
    251  1.1  thorpej 
    252  1.1  thorpej  err_ret:
    253  1.1  thorpej 	if (priq_ifinfo != NULL) {
    254  1.1  thorpej 		free(priq_ifinfo);
    255  1.1  thorpej 		if (ifinfo != NULL)
    256  1.1  thorpej 			ifinfo->private = NULL;
    257  1.1  thorpej 	}
    258  1.1  thorpej 	return (error);
    259  1.1  thorpej }
    260  1.1  thorpej 
    261  1.1  thorpej int
    262  1.1  thorpej qop_priq_add_class(struct classinfo **rp, const char *class_name,
    263  1.1  thorpej 		   struct ifinfo *ifinfo, int pri, int qlimit, int flags)
    264  1.1  thorpej {
    265  1.1  thorpej 	struct classinfo *clinfo;
    266  1.1  thorpej 	struct priq_ifinfo *priq_ifinfo;
    267  1.1  thorpej 	struct priq_classinfo *priq_clinfo = NULL;
    268  1.1  thorpej 	int error;
    269  1.1  thorpej 
    270  1.1  thorpej 	priq_ifinfo = ifinfo->private;
    271  1.1  thorpej 	if ((flags & PRCF_DEFAULTCLASS) && priq_ifinfo->default_class != NULL)
    272  1.1  thorpej 		return (QOPERR_CLASS_INVAL);
    273  1.1  thorpej 
    274  1.1  thorpej 	if ((priq_clinfo = calloc(1, sizeof(*priq_clinfo))) == NULL) {
    275  1.1  thorpej 		error = QOPERR_NOMEM;
    276  1.1  thorpej 		goto err_ret;
    277  1.1  thorpej 	}
    278  1.1  thorpej 
    279  1.1  thorpej 	priq_clinfo->pri = pri;
    280  1.1  thorpej 	priq_clinfo->qlimit = qlimit;
    281  1.1  thorpej 	priq_clinfo->flags = flags;
    282  1.1  thorpej 
    283  1.1  thorpej 	if ((error = qop_add_class(&clinfo, class_name, ifinfo, NULL,
    284  1.1  thorpej 				   priq_clinfo)) != 0)
    285  1.1  thorpej 		goto err_ret;
    286  1.1  thorpej 
    287  1.1  thorpej 	if (flags & PRCF_DEFAULTCLASS)
    288  1.1  thorpej 		priq_ifinfo->default_class = clinfo;
    289  1.1  thorpej 
    290  1.1  thorpej 	if (rp != NULL)
    291  1.1  thorpej 		*rp = clinfo;
    292  1.1  thorpej 	return (0);
    293  1.1  thorpej 
    294  1.1  thorpej  err_ret:
    295  1.1  thorpej 	if (priq_clinfo != NULL) {
    296  1.1  thorpej 		free(priq_clinfo);
    297  1.1  thorpej 		clinfo->private = NULL;
    298  1.1  thorpej 	}
    299  1.1  thorpej 
    300  1.1  thorpej 	return (error);
    301  1.1  thorpej }
    302  1.1  thorpej 
    303  1.1  thorpej int
    304  1.1  thorpej qop_priq_modify_class(struct classinfo *clinfo,
    305  1.1  thorpej 		      int pri, int qlimit, int flags)
    306  1.1  thorpej {
    307  1.1  thorpej 	struct priq_classinfo *priq_clinfo, *parent_clinfo;
    308  1.1  thorpej 	int error;
    309  1.1  thorpej 
    310  1.1  thorpej 	priq_clinfo = clinfo->private;
    311  1.1  thorpej 	if (clinfo->parent == NULL)
    312  1.1  thorpej 		return (QOPERR_CLASS_INVAL);
    313  1.1  thorpej 	parent_clinfo = clinfo->parent->private;
    314  1.1  thorpej 
    315  1.1  thorpej 	priq_clinfo->pri = pri;
    316  1.1  thorpej 	priq_clinfo->qlimit = qlimit;
    317  1.1  thorpej 	priq_clinfo->flags = flags;
    318  1.1  thorpej 
    319  1.1  thorpej 	error = qop_modify_class(clinfo, NULL);
    320  1.1  thorpej 	if (error == 0)
    321  1.1  thorpej 		return (0);
    322  1.1  thorpej 	return (error);
    323  1.1  thorpej }
    324  1.1  thorpej 
    325  1.1  thorpej /*
    326  1.1  thorpej  * sanity check at enabling priq:
    327  1.1  thorpej  *  1. there must one default class for an interface
    328  1.1  thorpej  */
    329  1.1  thorpej static int
    330  1.1  thorpej qop_priq_enable_hook(struct ifinfo *ifinfo)
    331  1.1  thorpej {
    332  1.1  thorpej 	struct priq_ifinfo *priq_ifinfo;
    333  1.1  thorpej 
    334  1.1  thorpej 	priq_ifinfo = ifinfo->private;
    335  1.1  thorpej 	if (priq_ifinfo->default_class == NULL) {
    336  1.1  thorpej 		LOG(LOG_ERR, 0, "priq: no default class on interface %s!\n",
    337  1.1  thorpej 		    ifinfo->ifname);
    338  1.1  thorpej 		return (QOPERR_CLASS);
    339  1.1  thorpej 	}
    340  1.1  thorpej 	return (0);
    341  1.1  thorpej }
    342  1.1  thorpej 
    343  1.1  thorpej /*
    344  1.1  thorpej  *  system call interfaces for qdisc_ops
    345  1.1  thorpej  */
    346  1.1  thorpej static int
    347  1.1  thorpej priq_attach(struct ifinfo *ifinfo)
    348  1.1  thorpej {
    349  1.1  thorpej 	struct priq_interface iface;
    350  1.1  thorpej 
    351  1.1  thorpej 	memset(&iface, 0, sizeof(iface));
    352  1.1  thorpej 	strncpy(iface.ifname, ifinfo->ifname, IFNAMSIZ);
    353  1.1  thorpej 
    354  1.1  thorpej 	if (priq_fd < 0 &&
    355  1.1  thorpej 	    (priq_fd = open(PRIQ_DEVICE, O_RDWR)) < 0 &&
    356  1.1  thorpej 	    (priq_fd = open_module(PRIQ_DEVICE, O_RDWR)) < 0) {
    357  1.1  thorpej 		LOG(LOG_ERR, errno, "PRIQ open\n");
    358  1.1  thorpej 		return (QOPERR_SYSCALL);
    359  1.1  thorpej 	}
    360  1.1  thorpej 
    361  1.1  thorpej 	priq_refcount++;
    362  1.1  thorpej 	memset(&iface, 0, sizeof(iface));
    363  1.1  thorpej 	strncpy(iface.ifname, ifinfo->ifname, IFNAMSIZ);
    364  1.1  thorpej 	iface.arg = ifinfo->bandwidth;
    365  1.1  thorpej 
    366  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_IF_ATTACH, &iface) < 0)
    367  1.1  thorpej 		return (QOPERR_SYSCALL);
    368  1.1  thorpej 	return (0);
    369  1.1  thorpej }
    370  1.1  thorpej 
    371  1.1  thorpej static int
    372  1.1  thorpej priq_detach(struct ifinfo *ifinfo)
    373  1.1  thorpej {
    374  1.1  thorpej 	struct priq_interface iface;
    375  1.1  thorpej 
    376  1.1  thorpej 	memset(&iface, 0, sizeof(iface));
    377  1.1  thorpej 	strncpy(iface.ifname, ifinfo->ifname, IFNAMSIZ);
    378  1.1  thorpej 
    379  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_IF_DETACH, &iface) < 0)
    380  1.1  thorpej 		return (QOPERR_SYSCALL);
    381  1.1  thorpej 
    382  1.1  thorpej 	if (--priq_refcount == 0) {
    383  1.1  thorpej 		close(priq_fd);
    384  1.1  thorpej 		priq_fd = -1;
    385  1.1  thorpej 	}
    386  1.1  thorpej 	return (0);
    387  1.1  thorpej }
    388  1.1  thorpej 
    389  1.1  thorpej static int
    390  1.1  thorpej priq_clear(struct ifinfo *ifinfo)
    391  1.1  thorpej {
    392  1.1  thorpej 	struct priq_interface iface;
    393  1.1  thorpej 
    394  1.1  thorpej 	memset(&iface, 0, sizeof(iface));
    395  1.1  thorpej 	strncpy(iface.ifname, ifinfo->ifname, IFNAMSIZ);
    396  1.1  thorpej 
    397  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_CLEAR, &iface) < 0)
    398  1.1  thorpej 		return (QOPERR_SYSCALL);
    399  1.1  thorpej 	return (0);
    400  1.1  thorpej }
    401  1.1  thorpej 
    402  1.1  thorpej static int
    403  1.1  thorpej priq_enable(struct ifinfo *ifinfo)
    404  1.1  thorpej {
    405  1.1  thorpej 	struct priq_interface iface;
    406  1.1  thorpej 
    407  1.1  thorpej 	memset(&iface, 0, sizeof(iface));
    408  1.1  thorpej 	strncpy(iface.ifname, ifinfo->ifname, IFNAMSIZ);
    409  1.1  thorpej 
    410  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_ENABLE, &iface) < 0)
    411  1.1  thorpej 		return (QOPERR_SYSCALL);
    412  1.1  thorpej 	return (0);
    413  1.1  thorpej }
    414  1.1  thorpej 
    415  1.1  thorpej static int
    416  1.1  thorpej priq_disable(struct ifinfo *ifinfo)
    417  1.1  thorpej {
    418  1.1  thorpej 	struct priq_interface iface;
    419  1.1  thorpej 
    420  1.1  thorpej 	memset(&iface, 0, sizeof(iface));
    421  1.1  thorpej 	strncpy(iface.ifname, ifinfo->ifname, IFNAMSIZ);
    422  1.1  thorpej 
    423  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_DISABLE, &iface) < 0)
    424  1.1  thorpej 		return (QOPERR_SYSCALL);
    425  1.1  thorpej 	return (0);
    426  1.1  thorpej }
    427  1.1  thorpej 
    428  1.1  thorpej static int
    429  1.1  thorpej priq_add_class(struct classinfo *clinfo)
    430  1.1  thorpej {
    431  1.1  thorpej 	struct priq_add_class class_add;
    432  1.1  thorpej 	struct priq_classinfo *priq_clinfo;
    433  1.1  thorpej 	struct priq_ifinfo *priq_ifinfo;
    434  1.1  thorpej 
    435  1.1  thorpej 	priq_ifinfo = clinfo->ifinfo->private;
    436  1.1  thorpej 	priq_clinfo = clinfo->private;
    437  1.1  thorpej 
    438  1.1  thorpej 	memset(&class_add, 0, sizeof(class_add));
    439  1.1  thorpej 	strncpy(class_add.iface.ifname, clinfo->ifinfo->ifname, IFNAMSIZ);
    440  1.1  thorpej 
    441  1.1  thorpej 	class_add.pri = priq_clinfo->pri;
    442  1.1  thorpej 	class_add.qlimit = priq_clinfo->qlimit;
    443  1.1  thorpej 	class_add.flags = priq_clinfo->flags;
    444  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_ADD_CLASS, &class_add) < 0) {
    445  1.1  thorpej 		clinfo->handle = PRIQ_NULLCLASS_HANDLE;
    446  1.1  thorpej 		return (QOPERR_SYSCALL);
    447  1.1  thorpej 	}
    448  1.1  thorpej 	clinfo->handle = class_add.class_handle;
    449  1.1  thorpej 	return (0);
    450  1.1  thorpej }
    451  1.1  thorpej 
    452  1.1  thorpej static int
    453  1.1  thorpej priq_modify_class(struct classinfo *clinfo, void *arg)
    454  1.1  thorpej {
    455  1.1  thorpej 	struct priq_modify_class class_mod;
    456  1.1  thorpej 	struct priq_classinfo *priq_clinfo;
    457  1.1  thorpej 
    458  1.1  thorpej 	priq_clinfo = clinfo->private;
    459  1.1  thorpej 
    460  1.1  thorpej 	memset(&class_mod, 0, sizeof(class_mod));
    461  1.1  thorpej 	strncpy(class_mod.iface.ifname, clinfo->ifinfo->ifname, IFNAMSIZ);
    462  1.1  thorpej 	class_mod.class_handle = clinfo->handle;
    463  1.1  thorpej 
    464  1.1  thorpej 	class_mod.pri = priq_clinfo->pri;
    465  1.1  thorpej 	class_mod.qlimit = priq_clinfo->qlimit;
    466  1.1  thorpej 	class_mod.flags = priq_clinfo->flags;
    467  1.1  thorpej 
    468  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_MOD_CLASS, &class_mod) < 0)
    469  1.1  thorpej 		return (QOPERR_SYSCALL);
    470  1.1  thorpej 	return (0);
    471  1.1  thorpej }
    472  1.1  thorpej 
    473  1.1  thorpej static int
    474  1.1  thorpej priq_delete_class(struct classinfo *clinfo)
    475  1.1  thorpej {
    476  1.1  thorpej 	struct priq_delete_class class_delete;
    477  1.1  thorpej 
    478  1.1  thorpej 	if (clinfo->handle == PRIQ_NULLCLASS_HANDLE)
    479  1.1  thorpej 		return (0);
    480  1.1  thorpej 
    481  1.1  thorpej 	memset(&class_delete, 0, sizeof(class_delete));
    482  1.1  thorpej 	strncpy(class_delete.iface.ifname, clinfo->ifinfo->ifname,
    483  1.1  thorpej 		IFNAMSIZ);
    484  1.1  thorpej 	class_delete.class_handle = clinfo->handle;
    485  1.1  thorpej 
    486  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_DEL_CLASS, &class_delete) < 0)
    487  1.1  thorpej 		return (QOPERR_SYSCALL);
    488  1.1  thorpej 	return (0);
    489  1.1  thorpej }
    490  1.1  thorpej 
    491  1.1  thorpej static int
    492  1.1  thorpej priq_add_filter(struct fltrinfo *fltrinfo)
    493  1.1  thorpej {
    494  1.1  thorpej 	struct priq_add_filter fltr_add;
    495  1.1  thorpej 
    496  1.1  thorpej 	memset(&fltr_add, 0, sizeof(fltr_add));
    497  1.1  thorpej 	strncpy(fltr_add.iface.ifname, fltrinfo->clinfo->ifinfo->ifname,
    498  1.1  thorpej 		IFNAMSIZ);
    499  1.1  thorpej 	fltr_add.class_handle = fltrinfo->clinfo->handle;
    500  1.1  thorpej 	fltr_add.filter = fltrinfo->fltr;
    501  1.1  thorpej 
    502  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_ADD_FILTER, &fltr_add) < 0)
    503  1.1  thorpej 		return (QOPERR_SYSCALL);
    504  1.1  thorpej 	fltrinfo->handle = fltr_add.filter_handle;
    505  1.1  thorpej 	return (0);
    506  1.1  thorpej }
    507  1.1  thorpej 
    508  1.1  thorpej static int
    509  1.1  thorpej priq_delete_filter(struct fltrinfo *fltrinfo)
    510  1.1  thorpej {
    511  1.1  thorpej 	struct priq_delete_filter fltr_del;
    512  1.1  thorpej 
    513  1.1  thorpej 	memset(&fltr_del, 0, sizeof(fltr_del));
    514  1.1  thorpej 	strncpy(fltr_del.iface.ifname, fltrinfo->clinfo->ifinfo->ifname,
    515  1.1  thorpej 		IFNAMSIZ);
    516  1.1  thorpej 	fltr_del.filter_handle = fltrinfo->handle;
    517  1.1  thorpej 
    518  1.1  thorpej 	if (ioctl(priq_fd, PRIQ_DEL_FILTER, &fltr_del) < 0)
    519  1.1  thorpej 		return (QOPERR_SYSCALL);
    520  1.1  thorpej 	return (0);
    521  1.1  thorpej }
    522  1.1  thorpej 
    523  1.1  thorpej 
    524