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