altq_var.h revision 302408
1219019Sgabor/*- 2219019Sgabor * Copyright (C) 1998-2003 3219019Sgabor * Sony Computer Science Laboratories Inc. All rights reserved. 4219019Sgabor * 5219019Sgabor * Redistribution and use in source and binary forms, with or without 6219019Sgabor * modification, are permitted provided that the following conditions 7219019Sgabor * are met: 8219019Sgabor * 1. Redistributions of source code must retain the above copyright 9219019Sgabor * notice, this list of conditions and the following disclaimer. 10219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 11219019Sgabor * notice, this list of conditions and the following disclaimer in the 12219019Sgabor * documentation and/or other materials provided with the distribution. 13219019Sgabor * 14219019Sgabor * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 15219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 18219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24219019Sgabor * SUCH DAMAGE. 25219019Sgabor * 26219019Sgabor * $KAME: altq_var.h,v 1.16 2003/10/03 05:05:15 kjc Exp $ 27219019Sgabor * $FreeBSD: stable/11/sys/net/altq/altq_var.h 287009 2015-08-21 22:02:22Z loos $ 28219019Sgabor */ 29219019Sgabor#ifndef _ALTQ_ALTQ_VAR_H_ 30219019Sgabor#define _ALTQ_ALTQ_VAR_H_ 31219019Sgabor 32219019Sgabor#ifdef _KERNEL 33219019Sgabor 34219019Sgabor#include <sys/param.h> 35219019Sgabor#include <sys/kernel.h> 36219019Sgabor#include <sys/queue.h> 37219019Sgabor 38219019Sgabor#ifdef ALTQ3_CLFIER_COMPAT 39219019Sgabor/* 40219019Sgabor * filter structure for altq common classifier 41219019Sgabor */ 42219019Sgaborstruct acc_filter { 43219019Sgabor LIST_ENTRY(acc_filter) f_chain; 44219019Sgabor void *f_class; /* pointer to the class */ 45219019Sgabor u_long f_handle; /* filter id */ 46219019Sgabor u_int32_t f_fbmask; /* filter bitmask */ 47219019Sgabor struct flow_filter f_filter; /* filter value */ 48219019Sgabor}; 49219019Sgabor 50219019Sgabor/* 51219019Sgabor * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix 52219019Sgabor * the handle assignment. 53219019Sgabor */ 54219019Sgabor#define ACC_FILTER_TABLESIZE (256+1) 55219019Sgabor#define ACC_FILTER_MASK (ACC_FILTER_TABLESIZE - 2) 56219019Sgabor#define ACC_WILDCARD_INDEX (ACC_FILTER_TABLESIZE - 1) 57219019Sgabor#ifdef __GNUC__ 58219019Sgabor#define ACC_GET_HASH_INDEX(addr) \ 59219019Sgabor ({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;}) 60219019Sgabor#else 61219019Sgabor#define ACC_GET_HASH_INDEX(addr) \ 62219019Sgabor (((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \ 63219019Sgabor & ACC_FILTER_MASK) 64219019Sgabor#endif 65219019Sgabor#define ACC_GET_HINDEX(handle) ((handle) >> 20) 66219019Sgabor 67219019Sgabor#if (__FreeBSD_version > 500000) 68219019Sgabor#define ACC_LOCK_INIT(ac) mtx_init(&(ac)->acc_mtx, "classifier", MTX_DEF) 69219019Sgabor#define ACC_LOCK_DESTROY(ac) mtx_destroy(&(ac)->acc_mtx) 70219019Sgabor#define ACC_LOCK(ac) mtx_lock(&(ac)->acc_mtx) 71219019Sgabor#define ACC_UNLOCK(ac) mtx_unlock(&(ac)->acc_mtx) 72219019Sgabor#else 73219019Sgabor#define ACC_LOCK_INIT(ac) 74219019Sgabor#define ACC_LOCK_DESTROY(ac) 75219019Sgabor#define ACC_LOCK(ac) 76219019Sgabor#define ACC_UNLOCK(ac) 77219019Sgabor#endif 78219019Sgabor 79219019Sgaborstruct acc_classifier { 80219019Sgabor u_int32_t acc_fbmask; 81219019Sgabor LIST_HEAD(filt, acc_filter) acc_filters[ACC_FILTER_TABLESIZE]; 82219019Sgabor 83219019Sgabor#if (__FreeBSD_version > 500000) 84219019Sgabor struct mtx acc_mtx; 85219019Sgabor#endif 86219019Sgabor}; 87219019Sgabor 88219019Sgabor/* 89219019Sgabor * flowinfo mask bits used by classifier 90219019Sgabor */ 91219019Sgabor/* for ipv4 */ 92219019Sgabor#define FIMB4_PROTO 0x0001 93219019Sgabor#define FIMB4_TOS 0x0002 94219019Sgabor#define FIMB4_DADDR 0x0004 95219019Sgabor#define FIMB4_SADDR 0x0008 96219019Sgabor#define FIMB4_DPORT 0x0010 97219019Sgabor#define FIMB4_SPORT 0x0020 98219019Sgabor#define FIMB4_GPI 0x0040 99219019Sgabor#define FIMB4_ALL 0x007f 100219019Sgabor/* for ipv6 */ 101219019Sgabor#define FIMB6_PROTO 0x0100 102219019Sgabor#define FIMB6_TCLASS 0x0200 103219019Sgabor#define FIMB6_DADDR 0x0400 104219019Sgabor#define FIMB6_SADDR 0x0800 105219019Sgabor#define FIMB6_DPORT 0x1000 106219019Sgabor#define FIMB6_SPORT 0x2000 107219019Sgabor#define FIMB6_GPI 0x4000 108219019Sgabor#define FIMB6_FLABEL 0x8000 109219019Sgabor#define FIMB6_ALL 0xff00 110219019Sgabor 111219019Sgabor#define FIMB_ALL (FIMB4_ALL|FIMB6_ALL) 112219019Sgabor 113219019Sgabor#define FIMB4_PORTS (FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI) 114219019Sgabor#define FIMB6_PORTS (FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI) 115219019Sgabor#endif /* ALTQ3_CLFIER_COMPAT */ 116219019Sgabor 117219019Sgabor/* 118219019Sgabor * machine dependent clock 119219019Sgabor * a 64bit high resolution time counter. 120219019Sgabor */ 121219019Sgaborextern int machclk_usepcc; 122219019Sgaborextern u_int32_t machclk_freq; 123219019Sgaborextern u_int32_t machclk_per_tick; 124219019Sgaborextern void init_machclk(void); 125219019Sgaborextern u_int64_t read_machclk(void); 126219019Sgabor 127219019Sgabor/* 128219019Sgabor * debug support 129219019Sgabor */ 130219019Sgabor#ifdef ALTQ_DEBUG 131219019Sgabor#ifdef __STDC__ 132219019Sgabor#define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e)) 133219019Sgabor#else /* PCC */ 134219019Sgabor#define ASSERT(e) ((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e")) 135219019Sgabor#endif 136219019Sgabor#else 137219019Sgabor#define ASSERT(e) ((void)0) 138219019Sgabor#endif 139219019Sgabor 140219019Sgabor/* 141219019Sgabor * misc stuff for compatibility 142219019Sgabor */ 143219019Sgabor/* ioctl cmd type */ 144219019Sgabortypedef u_long ioctlcmd_t; 145219019Sgabor 146219019Sgabor/* 147219019Sgabor * queue macros: 148219019Sgabor * the interface of TAILQ_LAST macro changed after the introduction 149219019Sgabor * of softupdate. redefine it here to make it work with pre-2.2.7. 150219019Sgabor */ 151219019Sgabor#undef TAILQ_LAST 152219019Sgabor#define TAILQ_LAST(head, headname) \ 153219019Sgabor (*(((struct headname *)((head)->tqh_last))->tqh_last)) 154219019Sgabor 155219019Sgabor#ifndef TAILQ_EMPTY 156219019Sgabor#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) 157219019Sgabor#endif 158219019Sgabor#ifndef TAILQ_FOREACH 159219019Sgabor#define TAILQ_FOREACH(var, head, field) \ 160219019Sgabor for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) 161219019Sgabor#endif 162219019Sgabor 163219019Sgabor/* macro for timeout/untimeout */ 164219019Sgabor/* use callout */ 165219019Sgabor#include <sys/callout.h> 166219019Sgabor 167219019Sgabor#if (__FreeBSD_version > 500000) 168219019Sgabor#define CALLOUT_INIT(c) callout_init((c), 0) 169219019Sgabor#else 170219019Sgabor#define CALLOUT_INIT(c) callout_init((c)) 171219019Sgabor#endif 172219019Sgabor#define CALLOUT_RESET(c,t,f,a) callout_reset((c),(t),(f),(a)) 173219019Sgabor#define CALLOUT_STOP(c) callout_stop((c)) 174219019Sgabor#if !defined(CALLOUT_INITIALIZER) && (__FreeBSD_version < 600000) 175219019Sgabor#define CALLOUT_INITIALIZER { { { NULL } }, 0, NULL, NULL, 0 } 176219019Sgabor#endif 177219019Sgabor 178219019Sgabor#define m_pktlen(m) ((m)->m_pkthdr.len) 179219019Sgabor 180219019Sgaborstruct ifnet; struct mbuf; 181219019Sgaborstruct pf_altq; 182219019Sgabor#ifdef ALTQ3_CLFIER_COMPAT 183219019Sgaborstruct flowinfo; 184219019Sgabor#endif 185219019Sgabor 186219019Sgaborvoid *altq_lookup(char *, int); 187219019Sgabor#ifdef ALTQ3_CLFIER_COMPAT 188219019Sgaborint altq_extractflow(struct mbuf *, int, struct flowinfo *, u_int32_t); 189219019Sgaborint acc_add_filter(struct acc_classifier *, struct flow_filter *, 190219019Sgabor void *, u_long *); 191219019Sgaborint acc_delete_filter(struct acc_classifier *, u_long); 192219019Sgaborint acc_discard_filters(struct acc_classifier *, void *, int); 193219019Sgaborvoid *acc_classify(void *, struct mbuf *, int); 194219019Sgabor#endif 195219019Sgaboru_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *); 196219019Sgaborvoid write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t); 197219019Sgaborvoid altq_assert(const char *, int, const char *); 198219019Sgaborint tbr_set(struct ifaltq *, struct tb_profile *); 199219019Sgaborint tbr_get(struct ifaltq *, struct tb_profile *); 200219019Sgabor 201219019Sgaborint altq_pfattach(struct pf_altq *); 202219019Sgaborint altq_pfdetach(struct pf_altq *); 203219019Sgaborint altq_add(struct pf_altq *); 204219019Sgaborint altq_remove(struct pf_altq *); 205219019Sgaborint altq_add_queue(struct pf_altq *); 206219019Sgaborint altq_remove_queue(struct pf_altq *); 207219019Sgaborint altq_getqstats(struct pf_altq *, void *, int *); 208219019Sgabor 209219019Sgaborint cbq_pfattach(struct pf_altq *); 210219019Sgaborint cbq_add_altq(struct pf_altq *); 211219019Sgaborint cbq_remove_altq(struct pf_altq *); 212219019Sgaborint cbq_add_queue(struct pf_altq *); 213219019Sgaborint cbq_remove_queue(struct pf_altq *); 214219019Sgaborint cbq_getqstats(struct pf_altq *, void *, int *); 215219019Sgabor 216219019Sgaborint codel_pfattach(struct pf_altq *); 217219019Sgaborint codel_add_altq(struct pf_altq *); 218219019Sgaborint codel_remove_altq(struct pf_altq *); 219219019Sgaborint codel_getqstats(struct pf_altq *, void *, int *); 220219019Sgabor 221219019Sgaborint priq_pfattach(struct pf_altq *); 222219019Sgaborint priq_add_altq(struct pf_altq *); 223219019Sgaborint priq_remove_altq(struct pf_altq *); 224219019Sgaborint priq_add_queue(struct pf_altq *); 225219019Sgaborint priq_remove_queue(struct pf_altq *); 226219019Sgaborint priq_getqstats(struct pf_altq *, void *, int *); 227219019Sgabor 228219019Sgaborint hfsc_pfattach(struct pf_altq *); 229219019Sgaborint hfsc_add_altq(struct pf_altq *); 230219019Sgaborint hfsc_remove_altq(struct pf_altq *); 231219019Sgaborint hfsc_add_queue(struct pf_altq *); 232219019Sgaborint hfsc_remove_queue(struct pf_altq *); 233219019Sgaborint hfsc_getqstats(struct pf_altq *, void *, int *); 234219019Sgabor 235219019Sgaborint fairq_pfattach(struct pf_altq *); 236219019Sgaborint fairq_add_altq(struct pf_altq *); 237219019Sgaborint fairq_remove_altq(struct pf_altq *); 238219019Sgaborint fairq_add_queue(struct pf_altq *); 239219019Sgaborint fairq_remove_queue(struct pf_altq *); 240219019Sgaborint fairq_getqstats(struct pf_altq *, void *, int *); 241219019Sgabor 242219019Sgabor#endif /* _KERNEL */ 243219019Sgabor#endif /* _ALTQ_ALTQ_VAR_H_ */ 244219019Sgabor