Home | History | Annotate | Line # | Download | only in altq
altq.h revision 1.1
      1 /*	$KAME: altq.h,v 1.6 2000/12/14 08:12:45 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1998-2000
      5  *	Sony Computer Science Laboratories Inc.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 #ifndef _ALTQ_ALTQ_H_
     29 #define	_ALTQ_ALTQ_H_
     30 
     31 #include <sys/param.h>
     32 #include <sys/ioccom.h>
     33 #include <sys/queue.h>
     34 #include <netinet/in.h>
     35 
     36 #ifndef IFNAMSIZ
     37 #define	IFNAMSIZ	16
     38 #endif
     39 
     40 /* altq discipline type */
     41 #define	ALTQT_NONE		0	/* reserved */
     42 #define	ALTQT_CBQ		1	/* cbq */
     43 #define	ALTQT_WFQ		2	/* wfq */
     44 #define	ALTQT_AFMAP		3	/* afmap */
     45 #define	ALTQT_FIFOQ		4	/* fifoq */
     46 #define	ALTQT_RED		5	/* red */
     47 #define	ALTQT_RIO		6	/* rio */
     48 #define	ALTQT_LOCALQ		7	/* local use */
     49 #define	ALTQT_HFSC		8	/* hfsc */
     50 #define	ALTQT_CDNR		9	/* traffic conditioner */
     51 #define	ALTQT_BLUE		10	/* blue */
     52 #define	ALTQT_PRIQ		11	/* priority queue */
     53 #define	ALTQT_MAX		12	/* should be max discipline type + 1 */
     54 
     55 struct	altqreq {
     56 	char	ifname[IFNAMSIZ];	/* if name, e.g. "en0" */
     57 	u_long	arg;			/* request-specific argument */
     58 };
     59 
     60 /* simple token backet meter profile */
     61 struct	tb_profile {
     62 	u_int	rate;	/* rate in bit-per-sec */
     63 	u_int	depth;	/* depth in bytes */
     64 };
     65 
     66 struct	tbrreq {
     67 	char	ifname[IFNAMSIZ];	/* if name, e.g. "en0" */
     68 	struct	tb_profile tb_prof;	/* token bucket profile */
     69 };
     70 
     71 /*
     72  * common network flow info structure
     73  */
     74 struct flowinfo {
     75 	u_char		fi_len;		/* total length */
     76 	u_char		fi_family;	/* address family */
     77 	u_int8_t	fi_data[46];	/* actually longer; address family
     78 					   specific flow info. */
     79 };
     80 
     81 /*
     82  * flow info structure for internet protocol family.
     83  * (currently this is the only protocol family supported)
     84  */
     85 struct flowinfo_in {
     86 	u_char		fi_len;		/* sizeof(struct flowinfo_in) */
     87 	u_char		fi_family;	/* AF_INET */
     88 	u_int8_t	fi_proto;	/* IPPROTO_XXX */
     89 	u_int8_t	fi_tos;		/* type-of-service */
     90 	struct in_addr	fi_dst;		/* dest address */
     91 	struct in_addr	fi_src;		/* src address */
     92 	u_int16_t	fi_dport;	/* dest port */
     93 	u_int16_t	fi_sport;	/* src port */
     94 	u_int32_t	fi_gpi;		/* generalized port id for ipsec */
     95 	u_int8_t	_pad[28];	/* make the size equal to
     96 					   flowinfo_in6 */
     97 };
     98 
     99 #ifdef SIN6_LEN
    100 struct flowinfo_in6 {
    101 	u_char		fi6_len;	/* sizeof(struct flowinfo_in6) */
    102 	u_char		fi6_family;	/* AF_INET6 */
    103 	u_int8_t	fi6_proto;	/* IPPROTO_XXX */
    104 	u_int8_t	fi6_tclass;	/* traffic class */
    105 	u_int32_t	fi6_flowlabel;	/* ipv6 flowlabel */
    106 	u_int16_t	fi6_dport;	/* dest port */
    107 	u_int16_t	fi6_sport;	/* src port */
    108 	u_int32_t	fi6_gpi;	/* generalized port id */
    109 	struct in6_addr fi6_dst;	/* dest address */
    110 	struct in6_addr fi6_src;	/* src address */
    111 };
    112 #endif /* INET6 */
    113 
    114 /*
    115  * flow filters for AF_INET and AF_INET6
    116  */
    117 struct flow_filter {
    118 	int			ff_ruleno;
    119 	struct flowinfo_in	ff_flow;
    120 	struct {
    121 		struct in_addr	mask_dst;
    122 		struct in_addr	mask_src;
    123 		u_int8_t	mask_tos;
    124 		u_int8_t	_pad[3];
    125 	} ff_mask;
    126 	u_int8_t _pad2[24];	/* make the size equal to flow_filter6 */
    127 };
    128 
    129 #ifdef SIN6_LEN
    130 struct flow_filter6 {
    131 	int			ff_ruleno;
    132 	struct flowinfo_in6	ff_flow6;
    133 	struct {
    134 		struct in6_addr	mask6_dst;
    135 		struct in6_addr	mask6_src;
    136 		u_int8_t	mask6_tclass;
    137 		u_int8_t	_pad[3];
    138 	} ff_mask6;
    139 };
    140 #endif /* INET6 */
    141 
    142 /*
    143  * generic packet counter
    144  */
    145 struct pktcntr {
    146 	u_int64_t	packets;
    147 	u_int64_t	bytes;
    148 };
    149 
    150 #define	PKTCNTR_ADD(cntr, len)	\
    151 	do { (cntr)->packets++; (cntr)->bytes += len; } while (0)
    152 
    153 /*
    154  * altq related ioctls
    155  */
    156 #define	ALTQGTYPE	_IOWR('q', 0, struct altqreq)	/* get queue type */
    157 #if 0
    158 /*
    159  * these ioctls are currently discipline-specific but could be shared
    160  * in the future.
    161  */
    162 #define	ALTQATTACH	_IOW('q', 1, struct altqreq)	/* attach discipline */
    163 #define	ALTQDETACH	_IOW('q', 2, struct altqreq)	/* detach discipline */
    164 #define	ALTQENABLE	_IOW('q', 3, struct altqreq)	/* enable discipline */
    165 #define	ALTQDISABLE	_IOW('q', 4, struct altqreq)	/* disable discipline*/
    166 #define	ALTQCLEAR	_IOW('q', 5, struct altqreq)	/* (re)initialize */
    167 #define	ALTQCONFIG	_IOWR('q', 6, struct altqreq)	/* set config params */
    168 #define	ALTQADDCLASS	_IOWR('q', 7, struct altqreq)	/* add a class */
    169 #define	ALTQMODCLASS	_IOWR('q', 8, struct altqreq)	/* modify a class */
    170 #define	ALTQDELCLASS	_IOWR('q', 9, struct altqreq)	/* delete a class */
    171 #define	ALTQADDFILTER	_IOWR('q', 10, struct altqreq)	/* add a filter */
    172 #define	ALTQDELFILTER	_IOWR('q', 11, struct altqreq)	/* delete a filter */
    173 #define	ALTQGETSTATS	_IOWR('q', 12, struct altqreq)	/* get statistics */
    174 #define	ALTQGETCNTR	_IOWR('q', 13, struct altqreq)	/* get a pkt counter */
    175 #endif /* 0 */
    176 #define	ALTQTBRSET	_IOW('q', 14, struct tbrreq)	/* set tb regulator */
    177 #define	ALTQTBRGET	_IOWR('q', 15, struct tbrreq)	/* get tb regulator */
    178 
    179 /* queue macros only in FreeBSD */
    180 #ifndef LIST_EMPTY
    181 #define	LIST_EMPTY(head) ((head)->lh_first == NULL)
    182 #endif
    183 #ifndef LIST_FOREACH
    184 #define	LIST_FOREACH(var, head, field)					\
    185 	for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next)
    186 #endif
    187 
    188 #ifdef KERNEL
    189 #ifndef _KERNEL
    190 #define	_KERNEL
    191 #endif
    192 #endif
    193 
    194 #ifdef _KERNEL
    195 #include <altq/altq_var.h>
    196 #endif
    197 
    198 #endif /* _ALTQ_ALTQ_H_ */
    199