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