1*953d0b89Stsutsui /* $NetBSD: altq_var.h,v 1.12 2008/11/25 15:59:10 tsutsui Exp $ */ 2dd191f37Speter /* $KAME: altq_var.h,v 1.18 2005/04/13 03:44:25 suz Exp $ */ 368de460fSthorpej 468de460fSthorpej /* 5dd191f37Speter * Copyright (C) 1998-2003 668de460fSthorpej * Sony Computer Science Laboratories Inc. All rights reserved. 768de460fSthorpej * 868de460fSthorpej * Redistribution and use in source and binary forms, with or without 968de460fSthorpej * modification, are permitted provided that the following conditions 1068de460fSthorpej * are met: 1168de460fSthorpej * 1. Redistributions of source code must retain the above copyright 1268de460fSthorpej * notice, this list of conditions and the following disclaimer. 1368de460fSthorpej * 2. Redistributions in binary form must reproduce the above copyright 1468de460fSthorpej * notice, this list of conditions and the following disclaimer in the 1568de460fSthorpej * documentation and/or other materials provided with the distribution. 1668de460fSthorpej * 1768de460fSthorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 1868de460fSthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1968de460fSthorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2068de460fSthorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 2168de460fSthorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2268de460fSthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2368de460fSthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2468de460fSthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2568de460fSthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2668de460fSthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2768de460fSthorpej * SUCH DAMAGE. 2868de460fSthorpej */ 2968de460fSthorpej #ifndef _ALTQ_ALTQ_VAR_H_ 3068de460fSthorpej #define _ALTQ_ALTQ_VAR_H_ 3168de460fSthorpej 3268de460fSthorpej #ifdef _KERNEL 3368de460fSthorpej 3468de460fSthorpej #include <sys/param.h> 3568de460fSthorpej #include <sys/kernel.h> 3668de460fSthorpej #include <sys/queue.h> 3768de460fSthorpej 38dd191f37Speter #ifdef ALTQ3_CLFIER_COMPAT 3968de460fSthorpej /* 4068de460fSthorpej * filter structure for altq common classifier 4168de460fSthorpej */ 4268de460fSthorpej struct acc_filter { 4368de460fSthorpej LIST_ENTRY(acc_filter) f_chain; 4468de460fSthorpej void *f_class; /* pointer to the class */ 4568de460fSthorpej u_long f_handle; /* filter id */ 4668de460fSthorpej u_int32_t f_fbmask; /* filter bitmask */ 4768de460fSthorpej struct flow_filter f_filter; /* filter value */ 4868de460fSthorpej }; 4968de460fSthorpej 5068de460fSthorpej /* 5168de460fSthorpej * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix 5268de460fSthorpej * the handle assignment. 5368de460fSthorpej */ 5468de460fSthorpej #define ACC_FILTER_TABLESIZE (256+1) 5568de460fSthorpej #define ACC_FILTER_MASK (ACC_FILTER_TABLESIZE - 2) 5668de460fSthorpej #define ACC_WILDCARD_INDEX (ACC_FILTER_TABLESIZE - 1) 5768de460fSthorpej #ifdef __GNUC__ 5868de460fSthorpej #define ACC_GET_HASH_INDEX(addr) \ 5968de460fSthorpej ({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;}) 6068de460fSthorpej #else 6168de460fSthorpej #define ACC_GET_HASH_INDEX(addr) \ 6268de460fSthorpej (((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \ 6368de460fSthorpej & ACC_FILTER_MASK) 6468de460fSthorpej #endif 6568de460fSthorpej #define ACC_GET_HINDEX(handle) ((handle) >> 20) 6668de460fSthorpej 67dd191f37Speter #if (__FreeBSD_version > 500000) 68dd191f37Speter #define ACC_LOCK_INIT(ac) mtx_init(&(ac)->acc_mtx, "classifier", MTX_DEF) 69dd191f37Speter #define ACC_LOCK_DESTROY(ac) mtx_destroy(&(ac)->acc_mtx) 70dd191f37Speter #define ACC_LOCK(ac) mtx_lock(&(ac)->acc_mtx) 71dd191f37Speter #define ACC_UNLOCK(ac) mtx_unlock(&(ac)->acc_mtx) 72dd191f37Speter #else 73dd191f37Speter #define ACC_LOCK_INIT(ac) 74dd191f37Speter #define ACC_LOCK_DESTROY(ac) 75dd191f37Speter #define ACC_LOCK(ac) 76dd191f37Speter #define ACC_UNLOCK(ac) 77dd191f37Speter #endif 78dd191f37Speter 7968de460fSthorpej struct acc_classifier { 8068de460fSthorpej u_int32_t acc_fbmask; 8168de460fSthorpej LIST_HEAD(filt, acc_filter) acc_filters[ACC_FILTER_TABLESIZE]; 82dd191f37Speter 83dd191f37Speter #if (__FreeBSD_version > 500000) 84dd191f37Speter struct mtx acc_mtx; 85dd191f37Speter #endif 8668de460fSthorpej }; 8768de460fSthorpej 8868de460fSthorpej /* 8968de460fSthorpej * flowinfo mask bits used by classifier 9068de460fSthorpej */ 9168de460fSthorpej /* for ipv4 */ 9268de460fSthorpej #define FIMB4_PROTO 0x0001 9368de460fSthorpej #define FIMB4_TOS 0x0002 9468de460fSthorpej #define FIMB4_DADDR 0x0004 9568de460fSthorpej #define FIMB4_SADDR 0x0008 9668de460fSthorpej #define FIMB4_DPORT 0x0010 9768de460fSthorpej #define FIMB4_SPORT 0x0020 9868de460fSthorpej #define FIMB4_GPI 0x0040 9968de460fSthorpej #define FIMB4_ALL 0x007f 10068de460fSthorpej /* for ipv6 */ 10168de460fSthorpej #define FIMB6_PROTO 0x0100 10268de460fSthorpej #define FIMB6_TCLASS 0x0200 10368de460fSthorpej #define FIMB6_DADDR 0x0400 10468de460fSthorpej #define FIMB6_SADDR 0x0800 10568de460fSthorpej #define FIMB6_DPORT 0x1000 10668de460fSthorpej #define FIMB6_SPORT 0x2000 10768de460fSthorpej #define FIMB6_GPI 0x4000 10868de460fSthorpej #define FIMB6_FLABEL 0x8000 10968de460fSthorpej #define FIMB6_ALL 0xff00 11068de460fSthorpej 11168de460fSthorpej #define FIMB_ALL (FIMB4_ALL|FIMB6_ALL) 11268de460fSthorpej 11368de460fSthorpej #define FIMB4_PORTS (FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI) 11468de460fSthorpej #define FIMB6_PORTS (FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI) 115dd191f37Speter #endif /* ALTQ3_CLFIER_COMPAT */ 11668de460fSthorpej 11768de460fSthorpej /* 11868de460fSthorpej * machine dependent clock 11968de460fSthorpej * a 64bit high resolution time counter. 12068de460fSthorpej */ 12168de460fSthorpej extern u_int32_t machclk_freq; 12268de460fSthorpej extern u_int32_t machclk_per_tick; 12368de460fSthorpej extern void init_machclk(void); 12468de460fSthorpej extern u_int64_t read_machclk(void); 12568de460fSthorpej 12668de460fSthorpej /* 12768de460fSthorpej * debug support 12868de460fSthorpej */ 12968de460fSthorpej #ifdef ALTQ_DEBUG 13068de460fSthorpej #ifdef __STDC__ 13168de460fSthorpej #define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e)) 13268de460fSthorpej #else /* PCC */ 13368de460fSthorpej #define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e")) 13468de460fSthorpej #endif 13568de460fSthorpej #else 13668de460fSthorpej #define ASSERT(e) ((void)0) 13768de460fSthorpej #endif 13868de460fSthorpej 13968de460fSthorpej /* 14068de460fSthorpej * misc stuff for compatibility 14168de460fSthorpej */ 14268de460fSthorpej /* ioctl cmd type */ 14368de460fSthorpej typedef u_long ioctlcmd_t; 14468de460fSthorpej 14568de460fSthorpej /* 14668de460fSthorpej * queue macros: 14768de460fSthorpej * the interface of TAILQ_LAST macro changed after the introduction 14868de460fSthorpej * of softupdate. redefine it here to make it work with pre-2.2.7. 14968de460fSthorpej */ 15068de460fSthorpej #undef TAILQ_LAST 15168de460fSthorpej #define TAILQ_LAST(head, headname) \ 15268de460fSthorpej (*(((struct headname *)((head)->tqh_last))->tqh_last)) 15368de460fSthorpej 15468de460fSthorpej #ifndef TAILQ_EMPTY 15568de460fSthorpej #define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 15668de460fSthorpej #endif 15768de460fSthorpej #ifndef TAILQ_FOREACH 15868de460fSthorpej #define TAILQ_FOREACH(var, head, field) \ 15968de460fSthorpej for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) 16068de460fSthorpej #endif 16168de460fSthorpej 16268de460fSthorpej /* macro for timeout/untimeout */ 16368de460fSthorpej #if (__FreeBSD_version > 300000) || defined(__NetBSD__) 16468de460fSthorpej /* use callout */ 16568de460fSthorpej #include <sys/callout.h> 16668de460fSthorpej 16788ab7da9Sad #if (__FreeBSD_version > 500000) || defined(__NetBSD__) 168dd191f37Speter #define CALLOUT_INIT(c) callout_init((c), 0) 169dd191f37Speter #else 17068de460fSthorpej #define CALLOUT_INIT(c) callout_init((c)) 171dd191f37Speter #endif 17268de460fSthorpej #define CALLOUT_RESET(c,t,f,a) callout_reset((c),(t),(f),(a)) 17368de460fSthorpej #define CALLOUT_STOP(c) callout_stop((c)) 17468de460fSthorpej #ifndef CALLOUT_INITIALIZER 17568de460fSthorpej #define CALLOUT_INITIALIZER { { { NULL } }, 0, NULL, NULL, 0 } 17668de460fSthorpej #endif 177dd191f37Speter #elif defined(__OpenBSD__) 178dd191f37Speter #include <sys/timeout.h> 179dd191f37Speter /* callout structure as a wrapper of struct timeout */ 180dd191f37Speter struct callout { 181dd191f37Speter struct timeout c_to; 182dd191f37Speter }; 183dd191f37Speter #define CALLOUT_INIT(c) do { (void)memset((c), 0, sizeof(*(c))); } while (/*CONSTCOND*/ 0) 184dd191f37Speter #define CALLOUT_RESET(c,t,f,a) do { if (!timeout_initialized(&(c)->c_to)) \ 185dd191f37Speter timeout_set(&(c)->c_to, (f), (a)); \ 186dd191f37Speter timeout_add(&(c)->c_to, (t)); } while (/*CONSTCOND*/ 0) 187dd191f37Speter #define CALLOUT_STOP(c) timeout_del(&(c)->c_to) 188dd191f37Speter #define CALLOUT_INITIALIZER { { { NULL }, NULL, NULL, 0, 0 } } 18968de460fSthorpej #else 19068de460fSthorpej /* use old-style timeout/untimeout */ 19168de460fSthorpej /* dummy callout structure */ 19268de460fSthorpej struct callout { 19368de460fSthorpej void *c_arg; /* function argument */ 194dd191f37Speter void (*c_func)(void *); /* functiuon to call */ 19568de460fSthorpej }; 196dd191f37Speter #define CALLOUT_INIT(c) do { (void)memset((c), 0, sizeof(*(c))); } while (/*CONSTCOND*/ 0) 19768de460fSthorpej #define CALLOUT_RESET(c,t,f,a) do { (c)->c_arg = (a); \ 19868de460fSthorpej (c)->c_func = (f); \ 199dd191f37Speter timeout((f),(a),(t)); } while (/*CONSTCOND*/ 0) 20068de460fSthorpej #define CALLOUT_STOP(c) untimeout((c)->c_func,(c)->c_arg) 20168de460fSthorpej #define CALLOUT_INITIALIZER { NULL, NULL } 20268de460fSthorpej #endif 20368de460fSthorpej #if !defined(__FreeBSD__) 20468de460fSthorpej typedef void (timeout_t)(void *); 20568de460fSthorpej #endif 20668de460fSthorpej 20768de460fSthorpej #define m_pktlen(m) ((m)->m_pkthdr.len) 20868de460fSthorpej 209dd191f37Speter struct ifnet; struct mbuf; 210dd191f37Speter struct pf_altq; 211dd191f37Speter #ifdef ALTQ3_CLFIER_COMPAT 212dd191f37Speter struct flowinfo; 213dd191f37Speter #endif 214dd191f37Speter 215dd191f37Speter void *altq_lookup(char *, int); 216dd191f37Speter #ifdef ALTQ3_CLFIER_COMPAT 217dd191f37Speter int altq_extractflow(struct mbuf *, int, struct flowinfo *, u_int32_t); 218dd191f37Speter int acc_add_filter(struct acc_classifier *, struct flow_filter *, 219dd191f37Speter void *, u_long *); 220dd191f37Speter int acc_delete_filter(struct acc_classifier *, u_long); 221dd191f37Speter int acc_discard_filters(struct acc_classifier *, void *, int); 222dd191f37Speter void *acc_classify(void *, struct mbuf *, int); 223dd191f37Speter #endif 224dd191f37Speter u_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *); 225dd191f37Speter void write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t); 226dd191f37Speter void altq_assert(const char *, int, const char *); 227dd191f37Speter int tbr_set(struct ifaltq *, struct tb_profile *); 228dd191f37Speter int tbr_get(struct ifaltq *, struct tb_profile *); 229dd191f37Speter 230dd191f37Speter int altq_pfattach(struct pf_altq *); 231dd191f37Speter int altq_pfdetach(struct pf_altq *); 232dd191f37Speter int altq_add(struct pf_altq *); 233dd191f37Speter int altq_remove(struct pf_altq *); 234dd191f37Speter int altq_add_queue(struct pf_altq *); 235dd191f37Speter int altq_remove_queue(struct pf_altq *); 236dd191f37Speter int altq_getqstats(struct pf_altq *, void *, int *); 237dd191f37Speter 238dd191f37Speter int cbq_pfattach(struct pf_altq *); 239dd191f37Speter int cbq_add_altq(struct pf_altq *); 240dd191f37Speter int cbq_remove_altq(struct pf_altq *); 241dd191f37Speter int cbq_add_queue(struct pf_altq *); 242dd191f37Speter int cbq_remove_queue(struct pf_altq *); 243dd191f37Speter int cbq_getqstats(struct pf_altq *, void *, int *); 244dd191f37Speter 245dd191f37Speter int priq_pfattach(struct pf_altq *); 246dd191f37Speter int priq_add_altq(struct pf_altq *); 247dd191f37Speter int priq_remove_altq(struct pf_altq *); 248dd191f37Speter int priq_add_queue(struct pf_altq *); 249dd191f37Speter int priq_remove_queue(struct pf_altq *); 250dd191f37Speter int priq_getqstats(struct pf_altq *, void *, int *); 251dd191f37Speter 252dd191f37Speter int hfsc_pfattach(struct pf_altq *); 253dd191f37Speter int hfsc_add_altq(struct pf_altq *); 254dd191f37Speter int hfsc_remove_altq(struct pf_altq *); 255dd191f37Speter int hfsc_add_queue(struct pf_altq *); 256dd191f37Speter int hfsc_remove_queue(struct pf_altq *); 257dd191f37Speter int hfsc_getqstats(struct pf_altq *, void *, int *); 25868de460fSthorpej 25968de460fSthorpej #endif /* _KERNEL */ 26068de460fSthorpej #endif /* _ALTQ_ALTQ_VAR_H_ */ 261