Home | History | Annotate | Line # | Download | only in altq
altq_var.h revision 1.7
      1  1.7     perry /*	$NetBSD: altq_var.h,v 1.7 2005/12/24 20:10:16 perry Exp $	*/
      2  1.1   thorpej /*	$KAME: altq_var.h,v 1.7 2000/12/14 08:12:46 thorpej Exp $	*/
      3  1.1   thorpej 
      4  1.1   thorpej /*
      5  1.1   thorpej  * Copyright (C) 1998-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 #ifndef _ALTQ_ALTQ_VAR_H_
     30  1.1   thorpej #define	_ALTQ_ALTQ_VAR_H_
     31  1.1   thorpej 
     32  1.1   thorpej #ifdef _KERNEL
     33  1.1   thorpej 
     34  1.1   thorpej #include <sys/param.h>
     35  1.1   thorpej #include <sys/kernel.h>
     36  1.1   thorpej #include <sys/queue.h>
     37  1.1   thorpej 
     38  1.1   thorpej /*
     39  1.1   thorpej  * filter structure for altq common classifier
     40  1.1   thorpej  */
     41  1.1   thorpej struct acc_filter {
     42  1.1   thorpej 	LIST_ENTRY(acc_filter)	f_chain;
     43  1.1   thorpej 	void			*f_class;	/* pointer to the class */
     44  1.1   thorpej 	u_long			f_handle;	/* filter id */
     45  1.1   thorpej 	u_int32_t		f_fbmask;	/* filter bitmask */
     46  1.1   thorpej 	struct flow_filter	f_filter;	/* filter value */
     47  1.1   thorpej };
     48  1.1   thorpej 
     49  1.1   thorpej /*
     50  1.1   thorpej  * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix
     51  1.1   thorpej  * the handle assignment.
     52  1.1   thorpej  */
     53  1.1   thorpej #define	ACC_FILTER_TABLESIZE	(256+1)
     54  1.1   thorpej #define	ACC_FILTER_MASK		(ACC_FILTER_TABLESIZE - 2)
     55  1.1   thorpej #define	ACC_WILDCARD_INDEX	(ACC_FILTER_TABLESIZE - 1)
     56  1.1   thorpej #ifdef __GNUC__
     57  1.1   thorpej #define	ACC_GET_HASH_INDEX(addr) \
     58  1.1   thorpej 	({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;})
     59  1.1   thorpej #else
     60  1.1   thorpej #define	ACC_GET_HASH_INDEX(addr) \
     61  1.1   thorpej 	(((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \
     62  1.1   thorpej 	& ACC_FILTER_MASK)
     63  1.1   thorpej #endif
     64  1.1   thorpej #define	ACC_GET_HINDEX(handle) ((handle) >> 20)
     65  1.1   thorpej 
     66  1.1   thorpej struct acc_classifier {
     67  1.1   thorpej 	u_int32_t			acc_fbmask;
     68  1.1   thorpej 	LIST_HEAD(filt, acc_filter)	acc_filters[ACC_FILTER_TABLESIZE];
     69  1.1   thorpej };
     70  1.1   thorpej 
     71  1.1   thorpej /*
     72  1.1   thorpej  * flowinfo mask bits used by classifier
     73  1.1   thorpej  */
     74  1.1   thorpej /* for ipv4 */
     75  1.1   thorpej #define	FIMB4_PROTO	0x0001
     76  1.1   thorpej #define	FIMB4_TOS	0x0002
     77  1.1   thorpej #define	FIMB4_DADDR	0x0004
     78  1.1   thorpej #define	FIMB4_SADDR	0x0008
     79  1.1   thorpej #define	FIMB4_DPORT	0x0010
     80  1.1   thorpej #define	FIMB4_SPORT	0x0020
     81  1.1   thorpej #define	FIMB4_GPI	0x0040
     82  1.1   thorpej #define	FIMB4_ALL	0x007f
     83  1.1   thorpej /* for ipv6 */
     84  1.1   thorpej #define	FIMB6_PROTO	0x0100
     85  1.1   thorpej #define	FIMB6_TCLASS	0x0200
     86  1.1   thorpej #define	FIMB6_DADDR	0x0400
     87  1.1   thorpej #define	FIMB6_SADDR	0x0800
     88  1.1   thorpej #define	FIMB6_DPORT	0x1000
     89  1.1   thorpej #define	FIMB6_SPORT	0x2000
     90  1.1   thorpej #define	FIMB6_GPI	0x4000
     91  1.1   thorpej #define	FIMB6_FLABEL	0x8000
     92  1.1   thorpej #define	FIMB6_ALL	0xff00
     93  1.1   thorpej 
     94  1.1   thorpej #define	FIMB_ALL	(FIMB4_ALL|FIMB6_ALL)
     95  1.1   thorpej 
     96  1.1   thorpej #define	FIMB4_PORTS	(FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI)
     97  1.1   thorpej #define	FIMB6_PORTS	(FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI)
     98  1.1   thorpej 
     99  1.1   thorpej /*
    100  1.1   thorpej  * machine dependent clock
    101  1.1   thorpej  * a 64bit high resolution time counter.
    102  1.1   thorpej  */
    103  1.1   thorpej extern u_int32_t machclk_freq;
    104  1.1   thorpej extern u_int32_t machclk_per_tick;
    105  1.1   thorpej extern void init_machclk(void);
    106  1.3    itojun 
    107  1.3    itojun #if defined(__i386__) && !defined(I586_CPU) && !defined(I686_CPU)
    108  1.3    itojun #ifndef ALTQ_NOPCC
    109  1.3    itojun #define	ALTQ_NOPCC	/* TSC is not available, ALTQ_NOPCC needed */
    110  1.3    itojun #endif
    111  1.3    itojun #endif
    112  1.1   thorpej 
    113  1.1   thorpej #if defined(__i386__) && !defined(ALTQ_NOPCC)
    114  1.1   thorpej /* for pentium tsc */
    115  1.1   thorpej #include <machine/cpufunc.h>
    116  1.1   thorpej 
    117  1.1   thorpej #define	read_machclk()		rdtsc()
    118  1.1   thorpej #ifdef __OpenBSD__
    119  1.7     perry static inline u_int64_t
    120  1.1   thorpej rdtsc(void)
    121  1.1   thorpej {
    122  1.1   thorpej 	u_int64_t rv;
    123  1.7     perry 	__asm volatile(".byte 0x0f, 0x31" : "=A" (rv));
    124  1.1   thorpej 	return (rv);
    125  1.1   thorpej }
    126  1.1   thorpej #endif /* __OpenBSD__ */
    127  1.1   thorpej 
    128  1.1   thorpej #elif defined(__alpha__) && !defined(ALTQ_NOPCC)
    129  1.1   thorpej /* for alpha rpcc */
    130  1.1   thorpej extern u_int64_t read_machclk(void);
    131  1.1   thorpej 
    132  1.1   thorpej #else /* !i386 && !alpha */
    133  1.1   thorpej /* emulate 256MHz using microtime() */
    134  1.1   thorpej #define	MACHCLK_SHIFT	8
    135  1.7     perry static inline u_int64_t
    136  1.1   thorpej read_machclk(void)
    137  1.1   thorpej {
    138  1.1   thorpej 	struct timeval tv;
    139  1.1   thorpej 	microtime(&tv);
    140  1.1   thorpej 	return (((u_int64_t)(tv.tv_sec - boottime.tv_sec) * 1000000
    141  1.1   thorpej 		 + tv.tv_usec) << MACHCLK_SHIFT);
    142  1.1   thorpej }
    143  1.1   thorpej #endif /* !i386 && !alpha */
    144  1.1   thorpej 
    145  1.1   thorpej /*
    146  1.1   thorpej  * debug support
    147  1.1   thorpej  */
    148  1.1   thorpej #ifdef ALTQ_DEBUG
    149  1.1   thorpej #ifdef __STDC__
    150  1.1   thorpej #define	ASSERT(e)	((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e))
    151  1.1   thorpej #else	/* PCC */
    152  1.1   thorpej #define	ASSERT(e)	((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e"))
    153  1.1   thorpej #endif
    154  1.1   thorpej #else
    155  1.1   thorpej #define	ASSERT(e)	((void)0)
    156  1.1   thorpej #endif
    157  1.1   thorpej 
    158  1.1   thorpej /*
    159  1.1   thorpej  * misc stuff for compatibility
    160  1.1   thorpej  */
    161  1.1   thorpej /* ioctl cmd type */
    162  1.1   thorpej #if defined(__FreeBSD__) && (__FreeBSD__ < 3)
    163  1.1   thorpej typedef int ioctlcmd_t;
    164  1.1   thorpej #else
    165  1.1   thorpej typedef u_long ioctlcmd_t;
    166  1.1   thorpej #endif
    167  1.1   thorpej 
    168  1.1   thorpej /*
    169  1.1   thorpej  * queue macros:
    170  1.1   thorpej  * the interface of TAILQ_LAST macro changed after the introduction
    171  1.1   thorpej  * of softupdate. redefine it here to make it work with pre-2.2.7.
    172  1.1   thorpej  */
    173  1.1   thorpej #undef TAILQ_LAST
    174  1.1   thorpej #define	TAILQ_LAST(head, headname) \
    175  1.1   thorpej 	(*(((struct headname *)((head)->tqh_last))->tqh_last))
    176  1.1   thorpej 
    177  1.1   thorpej #ifndef TAILQ_EMPTY
    178  1.1   thorpej #define	TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
    179  1.1   thorpej #endif
    180  1.1   thorpej #ifndef TAILQ_FOREACH
    181  1.1   thorpej #define TAILQ_FOREACH(var, head, field)					\
    182  1.1   thorpej 	for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
    183  1.1   thorpej #endif
    184  1.1   thorpej 
    185  1.1   thorpej /* macro for timeout/untimeout */
    186  1.1   thorpej #if (__FreeBSD_version > 300000) || defined(__NetBSD__)
    187  1.1   thorpej /* use callout */
    188  1.1   thorpej #include <sys/callout.h>
    189  1.1   thorpej 
    190  1.1   thorpej #define	CALLOUT_INIT(c)		callout_init((c))
    191  1.1   thorpej #define	CALLOUT_RESET(c,t,f,a)	callout_reset((c),(t),(f),(a))
    192  1.1   thorpej #define	CALLOUT_STOP(c)		callout_stop((c))
    193  1.1   thorpej #ifndef CALLOUT_INITIALIZER
    194  1.1   thorpej #define	CALLOUT_INITIALIZER	{ { { NULL } }, 0, NULL, NULL, 0 }
    195  1.1   thorpej #endif
    196  1.1   thorpej #else
    197  1.1   thorpej /* use old-style timeout/untimeout */
    198  1.1   thorpej /* dummy callout structure */
    199  1.1   thorpej struct callout {
    200  1.1   thorpej 	void		*c_arg;			/* function argument */
    201  1.1   thorpej 	void		(*c_func) __P((void *));/* functiuon to call */
    202  1.1   thorpej };
    203  1.5  christos #define	CALLOUT_INIT(c)		do {	(void)memset((c), 0, sizeof(*(c))); \
    204  1.5  christos 				} while (/*CONSTCOND*/ 0)
    205  1.1   thorpej #define	CALLOUT_RESET(c,t,f,a)	do {	(c)->c_arg = (a);	\
    206  1.1   thorpej 					(c)->c_func = (f);	\
    207  1.5  christos 					timeout((f),(a),(t));	\
    208  1.5  christos 				} while (/*CONSTCOND*/ 0)
    209  1.1   thorpej #define	CALLOUT_STOP(c)		untimeout((c)->c_func,(c)->c_arg)
    210  1.1   thorpej #define	CALLOUT_INITIALIZER	{ NULL, NULL }
    211  1.1   thorpej #endif
    212  1.1   thorpej #if !defined(__FreeBSD__)
    213  1.1   thorpej typedef void (timeout_t)(void *);
    214  1.1   thorpej #endif
    215  1.1   thorpej 
    216  1.1   thorpej #define	m_pktlen(m)		((m)->m_pkthdr.len)
    217  1.1   thorpej 
    218  1.1   thorpej struct ifnet; struct mbuf; struct flowinfo;
    219  1.1   thorpej 
    220  1.1   thorpej void *altq_lookup __P((char *, int));
    221  1.1   thorpej int altq_extractflow __P((struct mbuf *, int, struct flowinfo *, u_int32_t));
    222  1.1   thorpej int acc_add_filter __P((struct acc_classifier *, struct flow_filter *,
    223  1.1   thorpej 			   void *, u_long *));
    224  1.1   thorpej int acc_delete_filter __P((struct acc_classifier *, u_long));
    225  1.1   thorpej int acc_discard_filters __P((struct acc_classifier *, void *, int));
    226  1.1   thorpej void *acc_classify __P((void *, struct mbuf *, int));
    227  1.1   thorpej u_int8_t read_dsfield __P((struct mbuf *, struct altq_pktattr *));
    228  1.1   thorpej void write_dsfield __P((struct mbuf *, struct altq_pktattr *, u_int8_t));
    229  1.1   thorpej void altq_assert __P((const char *, int, const char *));
    230  1.1   thorpej int tbr_set __P((struct ifaltq *, struct tb_profile *));
    231  1.1   thorpej int tbr_get __P((struct ifaltq *, struct tb_profile *));
    232  1.1   thorpej 
    233  1.1   thorpej #endif /* _KERNEL */
    234  1.1   thorpej #endif /* _ALTQ_ALTQ_VAR_H_ */
    235