1*68de460fSthorpej /* $KAME: altq_var.h,v 1.7 2000/12/14 08:12:46 thorpej Exp $ */ 2*68de460fSthorpej 3*68de460fSthorpej /* 4*68de460fSthorpej * Copyright (C) 1998-2000 5*68de460fSthorpej * Sony Computer Science Laboratories Inc. All rights reserved. 6*68de460fSthorpej * 7*68de460fSthorpej * Redistribution and use in source and binary forms, with or without 8*68de460fSthorpej * modification, are permitted provided that the following conditions 9*68de460fSthorpej * are met: 10*68de460fSthorpej * 1. Redistributions of source code must retain the above copyright 11*68de460fSthorpej * notice, this list of conditions and the following disclaimer. 12*68de460fSthorpej * 2. Redistributions in binary form must reproduce the above copyright 13*68de460fSthorpej * notice, this list of conditions and the following disclaimer in the 14*68de460fSthorpej * documentation and/or other materials provided with the distribution. 15*68de460fSthorpej * 16*68de460fSthorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 17*68de460fSthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*68de460fSthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*68de460fSthorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 20*68de460fSthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*68de460fSthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*68de460fSthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*68de460fSthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*68de460fSthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*68de460fSthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*68de460fSthorpej * SUCH DAMAGE. 27*68de460fSthorpej */ 28*68de460fSthorpej #ifndef _ALTQ_ALTQ_VAR_H_ 29*68de460fSthorpej #define _ALTQ_ALTQ_VAR_H_ 30*68de460fSthorpej 31*68de460fSthorpej #ifdef _KERNEL 32*68de460fSthorpej 33*68de460fSthorpej #include <sys/param.h> 34*68de460fSthorpej #include <sys/kernel.h> 35*68de460fSthorpej #include <sys/queue.h> 36*68de460fSthorpej 37*68de460fSthorpej /* 38*68de460fSthorpej * filter structure for altq common classifier 39*68de460fSthorpej */ 40*68de460fSthorpej struct acc_filter { 41*68de460fSthorpej LIST_ENTRY(acc_filter) f_chain; 42*68de460fSthorpej void *f_class; /* pointer to the class */ 43*68de460fSthorpej u_long f_handle; /* filter id */ 44*68de460fSthorpej u_int32_t f_fbmask; /* filter bitmask */ 45*68de460fSthorpej struct flow_filter f_filter; /* filter value */ 46*68de460fSthorpej }; 47*68de460fSthorpej 48*68de460fSthorpej /* 49*68de460fSthorpej * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix 50*68de460fSthorpej * the handle assignment. 51*68de460fSthorpej */ 52*68de460fSthorpej #define ACC_FILTER_TABLESIZE (256+1) 53*68de460fSthorpej #define ACC_FILTER_MASK (ACC_FILTER_TABLESIZE - 2) 54*68de460fSthorpej #define ACC_WILDCARD_INDEX (ACC_FILTER_TABLESIZE - 1) 55*68de460fSthorpej #ifdef __GNUC__ 56*68de460fSthorpej #define ACC_GET_HASH_INDEX(addr) \ 57*68de460fSthorpej ({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;}) 58*68de460fSthorpej #else 59*68de460fSthorpej #define ACC_GET_HASH_INDEX(addr) \ 60*68de460fSthorpej (((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \ 61*68de460fSthorpej & ACC_FILTER_MASK) 62*68de460fSthorpej #endif 63*68de460fSthorpej #define ACC_GET_HINDEX(handle) ((handle) >> 20) 64*68de460fSthorpej 65*68de460fSthorpej struct acc_classifier { 66*68de460fSthorpej u_int32_t acc_fbmask; 67*68de460fSthorpej LIST_HEAD(filt, acc_filter) acc_filters[ACC_FILTER_TABLESIZE]; 68*68de460fSthorpej }; 69*68de460fSthorpej 70*68de460fSthorpej /* 71*68de460fSthorpej * flowinfo mask bits used by classifier 72*68de460fSthorpej */ 73*68de460fSthorpej /* for ipv4 */ 74*68de460fSthorpej #define FIMB4_PROTO 0x0001 75*68de460fSthorpej #define FIMB4_TOS 0x0002 76*68de460fSthorpej #define FIMB4_DADDR 0x0004 77*68de460fSthorpej #define FIMB4_SADDR 0x0008 78*68de460fSthorpej #define FIMB4_DPORT 0x0010 79*68de460fSthorpej #define FIMB4_SPORT 0x0020 80*68de460fSthorpej #define FIMB4_GPI 0x0040 81*68de460fSthorpej #define FIMB4_ALL 0x007f 82*68de460fSthorpej /* for ipv6 */ 83*68de460fSthorpej #define FIMB6_PROTO 0x0100 84*68de460fSthorpej #define FIMB6_TCLASS 0x0200 85*68de460fSthorpej #define FIMB6_DADDR 0x0400 86*68de460fSthorpej #define FIMB6_SADDR 0x0800 87*68de460fSthorpej #define FIMB6_DPORT 0x1000 88*68de460fSthorpej #define FIMB6_SPORT 0x2000 89*68de460fSthorpej #define FIMB6_GPI 0x4000 90*68de460fSthorpej #define FIMB6_FLABEL 0x8000 91*68de460fSthorpej #define FIMB6_ALL 0xff00 92*68de460fSthorpej 93*68de460fSthorpej #define FIMB_ALL (FIMB4_ALL|FIMB6_ALL) 94*68de460fSthorpej 95*68de460fSthorpej #define FIMB4_PORTS (FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI) 96*68de460fSthorpej #define FIMB6_PORTS (FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI) 97*68de460fSthorpej 98*68de460fSthorpej /* 99*68de460fSthorpej * machine dependent clock 100*68de460fSthorpej * a 64bit high resolution time counter. 101*68de460fSthorpej */ 102*68de460fSthorpej extern u_int32_t machclk_freq; 103*68de460fSthorpej extern u_int32_t machclk_per_tick; 104*68de460fSthorpej extern void init_machclk(void); 105*68de460fSthorpej 106*68de460fSthorpej #if defined(__i386__) && !defined(ALTQ_NOPCC) 107*68de460fSthorpej /* for pentium tsc */ 108*68de460fSthorpej #include <machine/cpufunc.h> 109*68de460fSthorpej 110*68de460fSthorpej #define read_machclk() rdtsc() 111*68de460fSthorpej #ifdef __OpenBSD__ 112*68de460fSthorpej static __inline u_int64_t 113*68de460fSthorpej rdtsc(void) 114*68de460fSthorpej { 115*68de460fSthorpej u_int64_t rv; 116*68de460fSthorpej __asm __volatile(".byte 0x0f, 0x31" : "=A" (rv)); 117*68de460fSthorpej return (rv); 118*68de460fSthorpej } 119*68de460fSthorpej #endif /* __OpenBSD__ */ 120*68de460fSthorpej 121*68de460fSthorpej #elif defined(__alpha__) && !defined(ALTQ_NOPCC) 122*68de460fSthorpej /* for alpha rpcc */ 123*68de460fSthorpej extern u_int64_t read_machclk(void); 124*68de460fSthorpej 125*68de460fSthorpej #else /* !i386 && !alpha */ 126*68de460fSthorpej /* emulate 256MHz using microtime() */ 127*68de460fSthorpej #define MACHCLK_SHIFT 8 128*68de460fSthorpej static __inline u_int64_t 129*68de460fSthorpej read_machclk(void) 130*68de460fSthorpej { 131*68de460fSthorpej struct timeval tv; 132*68de460fSthorpej microtime(&tv); 133*68de460fSthorpej return (((u_int64_t)(tv.tv_sec - boottime.tv_sec) * 1000000 134*68de460fSthorpej + tv.tv_usec) << MACHCLK_SHIFT); 135*68de460fSthorpej } 136*68de460fSthorpej #endif /* !i386 && !alpha */ 137*68de460fSthorpej 138*68de460fSthorpej /* 139*68de460fSthorpej * debug support 140*68de460fSthorpej */ 141*68de460fSthorpej #ifdef ALTQ_DEBUG 142*68de460fSthorpej #ifdef __STDC__ 143*68de460fSthorpej #define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e)) 144*68de460fSthorpej #else /* PCC */ 145*68de460fSthorpej #define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e")) 146*68de460fSthorpej #endif 147*68de460fSthorpej #else 148*68de460fSthorpej #define ASSERT(e) ((void)0) 149*68de460fSthorpej #endif 150*68de460fSthorpej 151*68de460fSthorpej /* 152*68de460fSthorpej * misc stuff for compatibility 153*68de460fSthorpej */ 154*68de460fSthorpej /* ioctl cmd type */ 155*68de460fSthorpej #if defined(__FreeBSD__) && (__FreeBSD__ < 3) 156*68de460fSthorpej typedef int ioctlcmd_t; 157*68de460fSthorpej #else 158*68de460fSthorpej typedef u_long ioctlcmd_t; 159*68de460fSthorpej #endif 160*68de460fSthorpej 161*68de460fSthorpej /* 162*68de460fSthorpej * queue macros: 163*68de460fSthorpej * the interface of TAILQ_LAST macro changed after the introduction 164*68de460fSthorpej * of softupdate. redefine it here to make it work with pre-2.2.7. 165*68de460fSthorpej */ 166*68de460fSthorpej #undef TAILQ_LAST 167*68de460fSthorpej #define TAILQ_LAST(head, headname) \ 168*68de460fSthorpej (*(((struct headname *)((head)->tqh_last))->tqh_last)) 169*68de460fSthorpej 170*68de460fSthorpej #ifndef TAILQ_EMPTY 171*68de460fSthorpej #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 172*68de460fSthorpej #endif 173*68de460fSthorpej #ifndef TAILQ_FOREACH 174*68de460fSthorpej #define TAILQ_FOREACH(var, head, field) \ 175*68de460fSthorpej for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) 176*68de460fSthorpej #endif 177*68de460fSthorpej 178*68de460fSthorpej /* macro for timeout/untimeout */ 179*68de460fSthorpej #if (__FreeBSD_version > 300000) || defined(__NetBSD__) 180*68de460fSthorpej /* use callout */ 181*68de460fSthorpej #include <sys/callout.h> 182*68de460fSthorpej 183*68de460fSthorpej #define CALLOUT_INIT(c) callout_init((c)) 184*68de460fSthorpej #define CALLOUT_RESET(c,t,f,a) callout_reset((c),(t),(f),(a)) 185*68de460fSthorpej #define CALLOUT_STOP(c) callout_stop((c)) 186*68de460fSthorpej #ifndef CALLOUT_INITIALIZER 187*68de460fSthorpej #define CALLOUT_INITIALIZER { { { NULL } }, 0, NULL, NULL, 0 } 188*68de460fSthorpej #endif 189*68de460fSthorpej #else 190*68de460fSthorpej /* use old-style timeout/untimeout */ 191*68de460fSthorpej /* dummy callout structure */ 192*68de460fSthorpej struct callout { 193*68de460fSthorpej void *c_arg; /* function argument */ 194*68de460fSthorpej void (*c_func) __P((void *));/* functiuon to call */ 195*68de460fSthorpej }; 196*68de460fSthorpej #define CALLOUT_INIT(c) do { bzero((c), sizeof(*(c))); } while (0) 197*68de460fSthorpej #define CALLOUT_RESET(c,t,f,a) do { (c)->c_arg = (a); \ 198*68de460fSthorpej (c)->c_func = (f); \ 199*68de460fSthorpej timeout((f),(a),(t)); } while (0) 200*68de460fSthorpej #define CALLOUT_STOP(c) untimeout((c)->c_func,(c)->c_arg) 201*68de460fSthorpej #define CALLOUT_INITIALIZER { NULL, NULL } 202*68de460fSthorpej #endif 203*68de460fSthorpej #if !defined(__FreeBSD__) 204*68de460fSthorpej typedef void (timeout_t)(void *); 205*68de460fSthorpej #endif 206*68de460fSthorpej 207*68de460fSthorpej #define m_pktlen(m) ((m)->m_pkthdr.len) 208*68de460fSthorpej 209*68de460fSthorpej struct ifnet; struct mbuf; struct flowinfo; 210*68de460fSthorpej 211*68de460fSthorpej void *altq_lookup __P((char *, int)); 212*68de460fSthorpej int altq_extractflow __P((struct mbuf *, int, struct flowinfo *, u_int32_t)); 213*68de460fSthorpej int acc_add_filter __P((struct acc_classifier *, struct flow_filter *, 214*68de460fSthorpej void *, u_long *)); 215*68de460fSthorpej int acc_delete_filter __P((struct acc_classifier *, u_long)); 216*68de460fSthorpej int acc_discard_filters __P((struct acc_classifier *, void *, int)); 217*68de460fSthorpej void *acc_classify __P((void *, struct mbuf *, int)); 218*68de460fSthorpej u_int8_t read_dsfield __P((struct mbuf *, struct altq_pktattr *)); 219*68de460fSthorpej void write_dsfield __P((struct mbuf *, struct altq_pktattr *, u_int8_t)); 220*68de460fSthorpej void altq_assert __P((const char *, int, const char *)); 221*68de460fSthorpej int tbr_set __P((struct ifaltq *, struct tb_profile *)); 222*68de460fSthorpej int tbr_get __P((struct ifaltq *, struct tb_profile *)); 223*68de460fSthorpej 224*68de460fSthorpej #endif /* _KERNEL */ 225*68de460fSthorpej #endif /* _ALTQ_ALTQ_VAR_H_ */ 226