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