altq_var.h revision 130365
1130365Smlaier/* $KAME: altq_var.h,v 1.16 2003/10/03 05:05:15 kjc Exp $ */ 2130365Smlaier 3130365Smlaier/* 4130365Smlaier * Copyright (C) 1998-2003 5130365Smlaier * Sony Computer Science Laboratories Inc. All rights reserved. 6130365Smlaier * 7130365Smlaier * Redistribution and use in source and binary forms, with or without 8130365Smlaier * modification, are permitted provided that the following conditions 9130365Smlaier * are met: 10130365Smlaier * 1. Redistributions of source code must retain the above copyright 11130365Smlaier * notice, this list of conditions and the following disclaimer. 12130365Smlaier * 2. Redistributions in binary form must reproduce the above copyright 13130365Smlaier * notice, this list of conditions and the following disclaimer in the 14130365Smlaier * documentation and/or other materials provided with the distribution. 15130365Smlaier * 16130365Smlaier * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 17130365Smlaier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18130365Smlaier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19130365Smlaier * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 20130365Smlaier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21130365Smlaier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22130365Smlaier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23130365Smlaier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24130365Smlaier * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25130365Smlaier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26130365Smlaier * SUCH DAMAGE. 27130365Smlaier */ 28130365Smlaier#ifndef _ALTQ_ALTQ_VAR_H_ 29130365Smlaier#define _ALTQ_ALTQ_VAR_H_ 30130365Smlaier 31130365Smlaier#ifdef _KERNEL 32130365Smlaier 33130365Smlaier#include <sys/param.h> 34130365Smlaier#include <sys/kernel.h> 35130365Smlaier#include <sys/queue.h> 36130365Smlaier 37130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 38130365Smlaier/* 39130365Smlaier * filter structure for altq common classifier 40130365Smlaier */ 41130365Smlaierstruct acc_filter { 42130365Smlaier LIST_ENTRY(acc_filter) f_chain; 43130365Smlaier void *f_class; /* pointer to the class */ 44130365Smlaier u_long f_handle; /* filter id */ 45130365Smlaier u_int32_t f_fbmask; /* filter bitmask */ 46130365Smlaier struct flow_filter f_filter; /* filter value */ 47130365Smlaier}; 48130365Smlaier 49130365Smlaier/* 50130365Smlaier * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix 51130365Smlaier * the handle assignment. 52130365Smlaier */ 53130365Smlaier#define ACC_FILTER_TABLESIZE (256+1) 54130365Smlaier#define ACC_FILTER_MASK (ACC_FILTER_TABLESIZE - 2) 55130365Smlaier#define ACC_WILDCARD_INDEX (ACC_FILTER_TABLESIZE - 1) 56130365Smlaier#ifdef __GNUC__ 57130365Smlaier#define ACC_GET_HASH_INDEX(addr) \ 58130365Smlaier ({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;}) 59130365Smlaier#else 60130365Smlaier#define ACC_GET_HASH_INDEX(addr) \ 61130365Smlaier (((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \ 62130365Smlaier & ACC_FILTER_MASK) 63130365Smlaier#endif 64130365Smlaier#define ACC_GET_HINDEX(handle) ((handle) >> 20) 65130365Smlaier 66130365Smlaier#if (__FreeBSD_version > 500000) 67130365Smlaier#define ACC_LOCK_INIT(ac) mtx_init(&(ac)->acc_mtx, "classifier", MTX_DEF) 68130365Smlaier#define ACC_LOCK_DESTROY(ac) mtx_destroy(&(ac)->acc_mtx) 69130365Smlaier#define ACC_LOCK(ac) mtx_lock(&(ac)->acc_mtx) 70130365Smlaier#define ACC_UNLOCK(ac) mtx_unlock(&(ac)->acc_mtx) 71130365Smlaier#else 72130365Smlaier#define ACC_LOCK_INIT(ac) 73130365Smlaier#define ACC_LOCK_DESTROY(ac) 74130365Smlaier#define ACC_LOCK(ac) 75130365Smlaier#define ACC_UNLOCK(ac) 76130365Smlaier#endif 77130365Smlaier 78130365Smlaierstruct acc_classifier { 79130365Smlaier u_int32_t acc_fbmask; 80130365Smlaier LIST_HEAD(filt, acc_filter) acc_filters[ACC_FILTER_TABLESIZE]; 81130365Smlaier 82130365Smlaier#if (__FreeBSD_version > 500000) 83130365Smlaier struct mtx acc_mtx; 84130365Smlaier#endif 85130365Smlaier}; 86130365Smlaier 87130365Smlaier/* 88130365Smlaier * flowinfo mask bits used by classifier 89130365Smlaier */ 90130365Smlaier/* for ipv4 */ 91130365Smlaier#define FIMB4_PROTO 0x0001 92130365Smlaier#define FIMB4_TOS 0x0002 93130365Smlaier#define FIMB4_DADDR 0x0004 94130365Smlaier#define FIMB4_SADDR 0x0008 95130365Smlaier#define FIMB4_DPORT 0x0010 96130365Smlaier#define FIMB4_SPORT 0x0020 97130365Smlaier#define FIMB4_GPI 0x0040 98130365Smlaier#define FIMB4_ALL 0x007f 99130365Smlaier/* for ipv6 */ 100130365Smlaier#define FIMB6_PROTO 0x0100 101130365Smlaier#define FIMB6_TCLASS 0x0200 102130365Smlaier#define FIMB6_DADDR 0x0400 103130365Smlaier#define FIMB6_SADDR 0x0800 104130365Smlaier#define FIMB6_DPORT 0x1000 105130365Smlaier#define FIMB6_SPORT 0x2000 106130365Smlaier#define FIMB6_GPI 0x4000 107130365Smlaier#define FIMB6_FLABEL 0x8000 108130365Smlaier#define FIMB6_ALL 0xff00 109130365Smlaier 110130365Smlaier#define FIMB_ALL (FIMB4_ALL|FIMB6_ALL) 111130365Smlaier 112130365Smlaier#define FIMB4_PORTS (FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI) 113130365Smlaier#define FIMB6_PORTS (FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI) 114130365Smlaier#endif /* ALTQ3_CLFIER_COMPAT */ 115130365Smlaier 116130365Smlaier/* 117130365Smlaier * machine dependent clock 118130365Smlaier * a 64bit high resolution time counter. 119130365Smlaier */ 120130365Smlaierextern int machclk_usepcc; 121130365Smlaierextern u_int32_t machclk_freq; 122130365Smlaierextern u_int32_t machclk_per_tick; 123130365Smlaierextern void init_machclk(void); 124130365Smlaierextern u_int64_t read_machclk(void); 125130365Smlaier 126130365Smlaier/* 127130365Smlaier * debug support 128130365Smlaier */ 129130365Smlaier#ifdef ALTQ_DEBUG 130130365Smlaier#ifdef __STDC__ 131130365Smlaier#define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e)) 132130365Smlaier#else /* PCC */ 133130365Smlaier#define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e")) 134130365Smlaier#endif 135130365Smlaier#else 136130365Smlaier#define ASSERT(e) ((void)0) 137130365Smlaier#endif 138130365Smlaier 139130365Smlaier/* 140130365Smlaier * misc stuff for compatibility 141130365Smlaier */ 142130365Smlaier/* ioctl cmd type */ 143130365Smlaier#if defined(__FreeBSD__) && (__FreeBSD__ < 3) 144130365Smlaiertypedef int ioctlcmd_t; 145130365Smlaier#else 146130365Smlaiertypedef u_long ioctlcmd_t; 147130365Smlaier#endif 148130365Smlaier 149130365Smlaier/* 150130365Smlaier * queue macros: 151130365Smlaier * the interface of TAILQ_LAST macro changed after the introduction 152130365Smlaier * of softupdate. redefine it here to make it work with pre-2.2.7. 153130365Smlaier */ 154130365Smlaier#undef TAILQ_LAST 155130365Smlaier#define TAILQ_LAST(head, headname) \ 156130365Smlaier (*(((struct headname *)((head)->tqh_last))->tqh_last)) 157130365Smlaier 158130365Smlaier#ifndef TAILQ_EMPTY 159130365Smlaier#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 160130365Smlaier#endif 161130365Smlaier#ifndef TAILQ_FOREACH 162130365Smlaier#define TAILQ_FOREACH(var, head, field) \ 163130365Smlaier for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) 164130365Smlaier#endif 165130365Smlaier 166130365Smlaier/* macro for timeout/untimeout */ 167130365Smlaier#if (__FreeBSD_version > 300000) || defined(__NetBSD__) 168130365Smlaier/* use callout */ 169130365Smlaier#include <sys/callout.h> 170130365Smlaier 171130365Smlaier#if (__FreeBSD_version > 500000) 172130365Smlaier#define CALLOUT_INIT(c) callout_init((c), 0) 173130365Smlaier#else 174130365Smlaier#define CALLOUT_INIT(c) callout_init((c)) 175130365Smlaier#endif 176130365Smlaier#define CALLOUT_RESET(c,t,f,a) callout_reset((c),(t),(f),(a)) 177130365Smlaier#define CALLOUT_STOP(c) callout_stop((c)) 178130365Smlaier#ifndef CALLOUT_INITIALIZER 179130365Smlaier#define CALLOUT_INITIALIZER { { { NULL } }, 0, NULL, NULL, 0 } 180130365Smlaier#endif 181130365Smlaier#elif defined(__OpenBSD__) 182130365Smlaier#include <sys/timeout.h> 183130365Smlaier/* callout structure as a wrapper of struct timeout */ 184130365Smlaierstruct callout { 185130365Smlaier struct timeout c_to; 186130365Smlaier}; 187130365Smlaier#define CALLOUT_INIT(c) do { bzero((c), sizeof(*(c))); } while (/*CONSTCOND*/ 0) 188130365Smlaier#define CALLOUT_RESET(c,t,f,a) do { if (!timeout_initialized(&(c)->c_to)) \ 189130365Smlaier timeout_set(&(c)->c_to, (f), (a)); \ 190130365Smlaier timeout_add(&(c)->c_to, (t)); } while (/*CONSTCOND*/ 0) 191130365Smlaier#define CALLOUT_STOP(c) timeout_del(&(c)->c_to) 192130365Smlaier#define CALLOUT_INITIALIZER { { { NULL }, NULL, NULL, 0, 0 } } 193130365Smlaier#else 194130365Smlaier/* use old-style timeout/untimeout */ 195130365Smlaier/* dummy callout structure */ 196130365Smlaierstruct callout { 197130365Smlaier void *c_arg; /* function argument */ 198130365Smlaier void (*c_func)(void *); /* functiuon to call */ 199130365Smlaier}; 200130365Smlaier#define CALLOUT_INIT(c) do { bzero((c), sizeof(*(c))); } while (/*CONSTCOND*/ 0) 201130365Smlaier#define CALLOUT_RESET(c,t,f,a) do { (c)->c_arg = (a); \ 202130365Smlaier (c)->c_func = (f); \ 203130365Smlaier timeout((f),(a),(t)); } while (/*CONSTCOND*/ 0) 204130365Smlaier#define CALLOUT_STOP(c) untimeout((c)->c_func,(c)->c_arg) 205130365Smlaier#define CALLOUT_INITIALIZER { NULL, NULL } 206130365Smlaier#endif 207130365Smlaier#if !defined(__FreeBSD__) 208130365Smlaiertypedef void (timeout_t)(void *); 209130365Smlaier#endif 210130365Smlaier 211130365Smlaier#define m_pktlen(m) ((m)->m_pkthdr.len) 212130365Smlaier 213130365Smlaierstruct ifnet; struct mbuf; 214130365Smlaierstruct pf_altq; 215130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 216130365Smlaierstruct flowinfo; 217130365Smlaier#endif 218130365Smlaier 219130365Smlaiervoid *altq_lookup(char *, int); 220130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 221130365Smlaierint altq_extractflow(struct mbuf *, int, struct flowinfo *, u_int32_t); 222130365Smlaierint acc_add_filter(struct acc_classifier *, struct flow_filter *, 223130365Smlaier void *, u_long *); 224130365Smlaierint acc_delete_filter(struct acc_classifier *, u_long); 225130365Smlaierint acc_discard_filters(struct acc_classifier *, void *, int); 226130365Smlaiervoid *acc_classify(void *, struct mbuf *, int); 227130365Smlaier#endif 228130365Smlaieru_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *); 229130365Smlaiervoid write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t); 230130365Smlaiervoid altq_assert(const char *, int, const char *); 231130365Smlaierint tbr_set(struct ifaltq *, struct tb_profile *); 232130365Smlaierint tbr_get(struct ifaltq *, struct tb_profile *); 233130365Smlaier 234130365Smlaierint altq_pfattach(struct pf_altq *); 235130365Smlaierint altq_pfdetach(struct pf_altq *); 236130365Smlaierint altq_add(struct pf_altq *); 237130365Smlaierint altq_remove(struct pf_altq *); 238130365Smlaierint altq_add_queue(struct pf_altq *); 239130365Smlaierint altq_remove_queue(struct pf_altq *); 240130365Smlaierint altq_getqstats(struct pf_altq *, void *, int *); 241130365Smlaier 242130365Smlaierint cbq_pfattach(struct pf_altq *); 243130365Smlaierint cbq_add_altq(struct pf_altq *); 244130365Smlaierint cbq_remove_altq(struct pf_altq *); 245130365Smlaierint cbq_add_queue(struct pf_altq *); 246130365Smlaierint cbq_remove_queue(struct pf_altq *); 247130365Smlaierint cbq_getqstats(struct pf_altq *, void *, int *); 248130365Smlaier 249130365Smlaierint priq_pfattach(struct pf_altq *); 250130365Smlaierint priq_add_altq(struct pf_altq *); 251130365Smlaierint priq_remove_altq(struct pf_altq *); 252130365Smlaierint priq_add_queue(struct pf_altq *); 253130365Smlaierint priq_remove_queue(struct pf_altq *); 254130365Smlaierint priq_getqstats(struct pf_altq *, void *, int *); 255130365Smlaier 256130365Smlaierint hfsc_pfattach(struct pf_altq *); 257130365Smlaierint hfsc_add_altq(struct pf_altq *); 258130365Smlaierint hfsc_remove_altq(struct pf_altq *); 259130365Smlaierint hfsc_add_queue(struct pf_altq *); 260130365Smlaierint hfsc_remove_queue(struct pf_altq *); 261130365Smlaierint hfsc_getqstats(struct pf_altq *, void *, int *); 262130365Smlaier 263130365Smlaier#endif /* _KERNEL */ 264130365Smlaier#endif /* _ALTQ_ALTQ_VAR_H_ */ 265