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