xref: /freebsd/sys/net/altq/altq_var.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
1da8ae05dSGleb Smirnoff /*-
2772e66a6SGleb Smirnoff  * Copyright (C) 1998-2003
3772e66a6SGleb Smirnoff  *	Sony Computer Science Laboratories Inc.  All rights reserved.
4772e66a6SGleb Smirnoff  *
5772e66a6SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
6772e66a6SGleb Smirnoff  * modification, are permitted provided that the following conditions
7772e66a6SGleb Smirnoff  * are met:
8772e66a6SGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
9772e66a6SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
10772e66a6SGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
11772e66a6SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
12772e66a6SGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
13772e66a6SGleb Smirnoff  *
14772e66a6SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
15772e66a6SGleb Smirnoff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16772e66a6SGleb Smirnoff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17772e66a6SGleb Smirnoff  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
18772e66a6SGleb Smirnoff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19772e66a6SGleb Smirnoff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20772e66a6SGleb Smirnoff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21772e66a6SGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22772e66a6SGleb Smirnoff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23772e66a6SGleb Smirnoff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24772e66a6SGleb Smirnoff  * SUCH DAMAGE.
25da8ae05dSGleb Smirnoff  *
26da8ae05dSGleb Smirnoff  * $KAME: altq_var.h,v 1.16 2003/10/03 05:05:15 kjc Exp $
27772e66a6SGleb Smirnoff  */
28772e66a6SGleb Smirnoff #ifndef _ALTQ_ALTQ_VAR_H_
29772e66a6SGleb Smirnoff #define	_ALTQ_ALTQ_VAR_H_
30772e66a6SGleb Smirnoff 
31772e66a6SGleb Smirnoff #ifdef _KERNEL
32772e66a6SGleb Smirnoff 
33772e66a6SGleb Smirnoff #include <sys/param.h>
34772e66a6SGleb Smirnoff #include <sys/kernel.h>
35772e66a6SGleb Smirnoff #include <sys/queue.h>
36772e66a6SGleb Smirnoff 
37772e66a6SGleb Smirnoff #ifdef ALTQ3_CLFIER_COMPAT
38772e66a6SGleb Smirnoff /*
39772e66a6SGleb Smirnoff  * filter structure for altq common classifier
40772e66a6SGleb Smirnoff  */
41772e66a6SGleb Smirnoff struct acc_filter {
42772e66a6SGleb Smirnoff 	LIST_ENTRY(acc_filter)	f_chain;
43772e66a6SGleb Smirnoff 	void			*f_class;	/* pointer to the class */
44772e66a6SGleb Smirnoff 	u_long			f_handle;	/* filter id */
45772e66a6SGleb Smirnoff 	u_int32_t		f_fbmask;	/* filter bitmask */
46772e66a6SGleb Smirnoff 	struct flow_filter	f_filter;	/* filter value */
47772e66a6SGleb Smirnoff };
48772e66a6SGleb Smirnoff 
49772e66a6SGleb Smirnoff /*
50772e66a6SGleb Smirnoff  * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix
51772e66a6SGleb Smirnoff  * the handle assignment.
52772e66a6SGleb Smirnoff  */
53772e66a6SGleb Smirnoff #define	ACC_FILTER_TABLESIZE	(256+1)
54772e66a6SGleb Smirnoff #define	ACC_FILTER_MASK		(ACC_FILTER_TABLESIZE - 2)
55772e66a6SGleb Smirnoff #define	ACC_WILDCARD_INDEX	(ACC_FILTER_TABLESIZE - 1)
56772e66a6SGleb Smirnoff #ifdef __GNUC__
57772e66a6SGleb Smirnoff #define	ACC_GET_HASH_INDEX(addr) \
58772e66a6SGleb Smirnoff 	({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;})
59772e66a6SGleb Smirnoff #else
60772e66a6SGleb Smirnoff #define	ACC_GET_HASH_INDEX(addr) \
61772e66a6SGleb Smirnoff 	(((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \
62772e66a6SGleb Smirnoff 	& ACC_FILTER_MASK)
63772e66a6SGleb Smirnoff #endif
64772e66a6SGleb Smirnoff #define	ACC_GET_HINDEX(handle) ((handle) >> 20)
65772e66a6SGleb Smirnoff 
66772e66a6SGleb Smirnoff #define ACC_LOCK_INIT(ac)	mtx_init(&(ac)->acc_mtx, "classifier", MTX_DEF)
67772e66a6SGleb Smirnoff #define ACC_LOCK_DESTROY(ac)	mtx_destroy(&(ac)->acc_mtx)
68772e66a6SGleb Smirnoff #define ACC_LOCK(ac)		mtx_lock(&(ac)->acc_mtx)
69772e66a6SGleb Smirnoff #define ACC_UNLOCK(ac)		mtx_unlock(&(ac)->acc_mtx)
70772e66a6SGleb Smirnoff 
71772e66a6SGleb Smirnoff struct acc_classifier {
72772e66a6SGleb Smirnoff 	u_int32_t			acc_fbmask;
73772e66a6SGleb Smirnoff 	LIST_HEAD(filt, acc_filter)	acc_filters[ACC_FILTER_TABLESIZE];
74772e66a6SGleb Smirnoff 	struct	mtx acc_mtx;
75772e66a6SGleb Smirnoff };
76772e66a6SGleb Smirnoff 
77772e66a6SGleb Smirnoff /*
78772e66a6SGleb Smirnoff  * flowinfo mask bits used by classifier
79772e66a6SGleb Smirnoff  */
80772e66a6SGleb Smirnoff /* for ipv4 */
81772e66a6SGleb Smirnoff #define	FIMB4_PROTO	0x0001
82772e66a6SGleb Smirnoff #define	FIMB4_TOS	0x0002
83772e66a6SGleb Smirnoff #define	FIMB4_DADDR	0x0004
84772e66a6SGleb Smirnoff #define	FIMB4_SADDR	0x0008
85772e66a6SGleb Smirnoff #define	FIMB4_DPORT	0x0010
86772e66a6SGleb Smirnoff #define	FIMB4_SPORT	0x0020
87772e66a6SGleb Smirnoff #define	FIMB4_GPI	0x0040
88772e66a6SGleb Smirnoff #define	FIMB4_ALL	0x007f
89772e66a6SGleb Smirnoff /* for ipv6 */
90772e66a6SGleb Smirnoff #define	FIMB6_PROTO	0x0100
91772e66a6SGleb Smirnoff #define	FIMB6_TCLASS	0x0200
92772e66a6SGleb Smirnoff #define	FIMB6_DADDR	0x0400
93772e66a6SGleb Smirnoff #define	FIMB6_SADDR	0x0800
94772e66a6SGleb Smirnoff #define	FIMB6_DPORT	0x1000
95772e66a6SGleb Smirnoff #define	FIMB6_SPORT	0x2000
96772e66a6SGleb Smirnoff #define	FIMB6_GPI	0x4000
97772e66a6SGleb Smirnoff #define	FIMB6_FLABEL	0x8000
98772e66a6SGleb Smirnoff #define	FIMB6_ALL	0xff00
99772e66a6SGleb Smirnoff 
100772e66a6SGleb Smirnoff #define	FIMB_ALL	(FIMB4_ALL|FIMB6_ALL)
101772e66a6SGleb Smirnoff 
102772e66a6SGleb Smirnoff #define	FIMB4_PORTS	(FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI)
103772e66a6SGleb Smirnoff #define	FIMB6_PORTS	(FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI)
104772e66a6SGleb Smirnoff #endif /* ALTQ3_CLFIER_COMPAT */
105772e66a6SGleb Smirnoff 
106772e66a6SGleb Smirnoff /*
107772e66a6SGleb Smirnoff  * machine dependent clock
108772e66a6SGleb Smirnoff  * a 64bit high resolution time counter.
109772e66a6SGleb Smirnoff  */
110772e66a6SGleb Smirnoff extern int machclk_usepcc;
111772e66a6SGleb Smirnoff extern u_int32_t machclk_freq;
112772e66a6SGleb Smirnoff extern u_int32_t machclk_per_tick;
113772e66a6SGleb Smirnoff extern void init_machclk(void);
114772e66a6SGleb Smirnoff extern u_int64_t read_machclk(void);
115772e66a6SGleb Smirnoff 
116772e66a6SGleb Smirnoff /*
117772e66a6SGleb Smirnoff  * debug support
118772e66a6SGleb Smirnoff  */
119772e66a6SGleb Smirnoff #ifdef ALTQ_DEBUG
120772e66a6SGleb Smirnoff #ifdef __STDC__
121772e66a6SGleb Smirnoff #define	ASSERT(e)	((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e))
122772e66a6SGleb Smirnoff #else	/* PCC */
123772e66a6SGleb Smirnoff #define	ASSERT(e)	((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e"))
124772e66a6SGleb Smirnoff #endif
125772e66a6SGleb Smirnoff #else
126772e66a6SGleb Smirnoff #define	ASSERT(e)	((void)0)
127772e66a6SGleb Smirnoff #endif
128772e66a6SGleb Smirnoff 
129772e66a6SGleb Smirnoff /*
130772e66a6SGleb Smirnoff  * misc stuff for compatibility
131772e66a6SGleb Smirnoff  */
132772e66a6SGleb Smirnoff /* ioctl cmd type */
133772e66a6SGleb Smirnoff typedef u_long ioctlcmd_t;
134772e66a6SGleb Smirnoff 
135772e66a6SGleb Smirnoff /*
136772e66a6SGleb Smirnoff  * queue macros:
137772e66a6SGleb Smirnoff  * the interface of TAILQ_LAST macro changed after the introduction
138772e66a6SGleb Smirnoff  * of softupdate. redefine it here to make it work with pre-2.2.7.
139772e66a6SGleb Smirnoff  */
140772e66a6SGleb Smirnoff #undef TAILQ_LAST
141772e66a6SGleb Smirnoff #define	TAILQ_LAST(head, headname) \
142772e66a6SGleb Smirnoff 	(*(((struct headname *)((head)->tqh_last))->tqh_last))
143772e66a6SGleb Smirnoff 
144772e66a6SGleb Smirnoff #ifndef TAILQ_EMPTY
145772e66a6SGleb Smirnoff #define	TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
146772e66a6SGleb Smirnoff #endif
147772e66a6SGleb Smirnoff #ifndef TAILQ_FOREACH
148772e66a6SGleb Smirnoff #define TAILQ_FOREACH(var, head, field)					\
149772e66a6SGleb Smirnoff 	for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
150772e66a6SGleb Smirnoff #endif
151772e66a6SGleb Smirnoff 
152772e66a6SGleb Smirnoff /* macro for timeout/untimeout */
153772e66a6SGleb Smirnoff /* use callout */
154772e66a6SGleb Smirnoff #include <sys/callout.h>
155772e66a6SGleb Smirnoff 
156*312f5f8aSKristof Provost #define	CALLOUT_INIT(c)		callout_init((c), 1)
157772e66a6SGleb Smirnoff #define	CALLOUT_RESET(c,t,f,a)	callout_reset((c),(t),(f),(a))
158772e66a6SGleb Smirnoff #define	CALLOUT_STOP(c)		callout_stop((c))
159772e66a6SGleb Smirnoff 
160772e66a6SGleb Smirnoff #define	m_pktlen(m)		((m)->m_pkthdr.len)
161772e66a6SGleb Smirnoff 
162772e66a6SGleb Smirnoff struct ifnet; struct mbuf;
163772e66a6SGleb Smirnoff struct pf_altq;
164772e66a6SGleb Smirnoff #ifdef ALTQ3_CLFIER_COMPAT
165772e66a6SGleb Smirnoff struct flowinfo;
166772e66a6SGleb Smirnoff #endif
167772e66a6SGleb Smirnoff 
168772e66a6SGleb Smirnoff void	*altq_lookup(char *, int);
169772e66a6SGleb Smirnoff #ifdef ALTQ3_CLFIER_COMPAT
170772e66a6SGleb Smirnoff int	altq_extractflow(struct mbuf *, int, struct flowinfo *, u_int32_t);
171772e66a6SGleb Smirnoff int	acc_add_filter(struct acc_classifier *, struct flow_filter *,
172772e66a6SGleb Smirnoff 	    void *, u_long *);
173772e66a6SGleb Smirnoff int	acc_delete_filter(struct acc_classifier *, u_long);
174772e66a6SGleb Smirnoff int	acc_discard_filters(struct acc_classifier *, void *, int);
175772e66a6SGleb Smirnoff void	*acc_classify(void *, struct mbuf *, int);
176772e66a6SGleb Smirnoff #endif
177772e66a6SGleb Smirnoff u_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *);
178772e66a6SGleb Smirnoff void	write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t);
179772e66a6SGleb Smirnoff void	altq_assert(const char *, int, const char *);
180772e66a6SGleb Smirnoff int	tbr_set(struct ifaltq *, struct tb_profile *);
181772e66a6SGleb Smirnoff 
182772e66a6SGleb Smirnoff int	altq_pfattach(struct pf_altq *);
183772e66a6SGleb Smirnoff int	altq_pfdetach(struct pf_altq *);
1848f2ac656SPatrick Kelsey int	altq_add(struct ifnet *, struct pf_altq *);
185772e66a6SGleb Smirnoff int	altq_remove(struct pf_altq *);
186772e66a6SGleb Smirnoff int	altq_add_queue(struct pf_altq *);
187772e66a6SGleb Smirnoff int	altq_remove_queue(struct pf_altq *);
188249cc75fSPatrick Kelsey int	altq_getqstats(struct pf_altq *, void *, int *, int);
189772e66a6SGleb Smirnoff 
190772e66a6SGleb Smirnoff int	cbq_pfattach(struct pf_altq *);
1918f2ac656SPatrick Kelsey int	cbq_add_altq(struct ifnet *, struct pf_altq *);
192772e66a6SGleb Smirnoff int	cbq_remove_altq(struct pf_altq *);
193772e66a6SGleb Smirnoff int	cbq_add_queue(struct pf_altq *);
194772e66a6SGleb Smirnoff int	cbq_remove_queue(struct pf_altq *);
195249cc75fSPatrick Kelsey int	cbq_getqstats(struct pf_altq *, void *, int *, int);
196772e66a6SGleb Smirnoff 
1970a70aaf8SLuiz Otavio O Souza int	codel_pfattach(struct pf_altq *);
1988f2ac656SPatrick Kelsey int	codel_add_altq(struct ifnet *, struct pf_altq *);
1990a70aaf8SLuiz Otavio O Souza int	codel_remove_altq(struct pf_altq *);
200249cc75fSPatrick Kelsey int	codel_getqstats(struct pf_altq *, void *, int *, int);
2010a70aaf8SLuiz Otavio O Souza 
202772e66a6SGleb Smirnoff int	priq_pfattach(struct pf_altq *);
2038f2ac656SPatrick Kelsey int	priq_add_altq(struct ifnet *, struct pf_altq *);
204772e66a6SGleb Smirnoff int	priq_remove_altq(struct pf_altq *);
205772e66a6SGleb Smirnoff int	priq_add_queue(struct pf_altq *);
206772e66a6SGleb Smirnoff int	priq_remove_queue(struct pf_altq *);
207249cc75fSPatrick Kelsey int	priq_getqstats(struct pf_altq *, void *, int *, int);
208772e66a6SGleb Smirnoff 
209772e66a6SGleb Smirnoff int	hfsc_pfattach(struct pf_altq *);
2108f2ac656SPatrick Kelsey int	hfsc_add_altq(struct ifnet *, struct pf_altq *);
211772e66a6SGleb Smirnoff int	hfsc_remove_altq(struct pf_altq *);
212772e66a6SGleb Smirnoff int	hfsc_add_queue(struct pf_altq *);
213772e66a6SGleb Smirnoff int	hfsc_remove_queue(struct pf_altq *);
214249cc75fSPatrick Kelsey int	hfsc_getqstats(struct pf_altq *, void *, int *, int);
215772e66a6SGleb Smirnoff 
216a5b789f6SErmal Luçi int	fairq_pfattach(struct pf_altq *);
2178f2ac656SPatrick Kelsey int	fairq_add_altq(struct ifnet *, struct pf_altq *);
218a5b789f6SErmal Luçi int	fairq_remove_altq(struct pf_altq *);
219a5b789f6SErmal Luçi int	fairq_add_queue(struct pf_altq *);
220a5b789f6SErmal Luçi int	fairq_remove_queue(struct pf_altq *);
221249cc75fSPatrick Kelsey int	fairq_getqstats(struct pf_altq *, void *, int *, int);
222a5b789f6SErmal Luçi 
223772e66a6SGleb Smirnoff #endif /* _KERNEL */
224772e66a6SGleb Smirnoff #endif /* _ALTQ_ALTQ_VAR_H_ */
225