altq_var.h revision 130365
1267843Sdelphij/*	$KAME: altq_var.h,v 1.16 2003/10/03 05:05:15 kjc Exp $	*/
2267843Sdelphij
3267843Sdelphij/*
4267843Sdelphij * Copyright (C) 1998-2003
5267843Sdelphij *	Sony Computer Science Laboratories Inc.  All rights reserved.
6267843Sdelphij *
7267843Sdelphij * Redistribution and use in source and binary forms, with or without
8267843Sdelphij * modification, are permitted provided that the following conditions
9267843Sdelphij * are met:
10267843Sdelphij * 1. Redistributions of source code must retain the above copyright
11267843Sdelphij *    notice, this list of conditions and the following disclaimer.
12267843Sdelphij * 2. Redistributions in binary form must reproduce the above copyright
13267843Sdelphij *    notice, this list of conditions and the following disclaimer in the
14267843Sdelphij *    documentation and/or other materials provided with the distribution.
15267843Sdelphij *
16267843Sdelphij * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17267843Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18267843Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19267843Sdelphij * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20267843Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21267843Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22267843Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23267843Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24267843Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25267843Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26267843Sdelphij * SUCH DAMAGE.
27267843Sdelphij */
28267843Sdelphij#ifndef _ALTQ_ALTQ_VAR_H_
29267843Sdelphij#define	_ALTQ_ALTQ_VAR_H_
30267843Sdelphij
31267843Sdelphij#ifdef _KERNEL
32267843Sdelphij
33267843Sdelphij#include <sys/param.h>
34267843Sdelphij#include <sys/kernel.h>
35267843Sdelphij#include <sys/queue.h>
36267843Sdelphij
37267843Sdelphij#ifdef ALTQ3_CLFIER_COMPAT
38267843Sdelphij/*
39267843Sdelphij * filter structure for altq common classifier
40267843Sdelphij */
41267843Sdelphijstruct acc_filter {
42267843Sdelphij	LIST_ENTRY(acc_filter)	f_chain;
43267843Sdelphij	void			*f_class;	/* pointer to the class */
44267843Sdelphij	u_long			f_handle;	/* filter id */
45267843Sdelphij	u_int32_t		f_fbmask;	/* filter bitmask */
46267843Sdelphij	struct flow_filter	f_filter;	/* filter value */
47267843Sdelphij};
48267843Sdelphij
49267843Sdelphij/*
50267843Sdelphij * XXX ACC_FILTER_TABLESIZE can't be larger than 2048 unless we fix
51267843Sdelphij * the handle assignment.
52267843Sdelphij */
53267843Sdelphij#define	ACC_FILTER_TABLESIZE	(256+1)
54267843Sdelphij#define	ACC_FILTER_MASK		(ACC_FILTER_TABLESIZE - 2)
55267843Sdelphij#define	ACC_WILDCARD_INDEX	(ACC_FILTER_TABLESIZE - 1)
56267843Sdelphij#ifdef __GNUC__
57267843Sdelphij#define	ACC_GET_HASH_INDEX(addr) \
58267843Sdelphij	({int x = (addr) + ((addr) >> 16); (x + (x >> 8)) & ACC_FILTER_MASK;})
59267843Sdelphij#else
60267843Sdelphij#define	ACC_GET_HASH_INDEX(addr) \
61267843Sdelphij	(((addr) + ((addr) >> 8) + ((addr) >> 16) + ((addr) >> 24)) \
62267843Sdelphij	& ACC_FILTER_MASK)
63267843Sdelphij#endif
64267843Sdelphij#define	ACC_GET_HINDEX(handle) ((handle) >> 20)
65267843Sdelphij
66267843Sdelphij#if (__FreeBSD_version > 500000)
67267843Sdelphij#define ACC_LOCK_INIT(ac)	mtx_init(&(ac)->acc_mtx, "classifier", MTX_DEF)
68267843Sdelphij#define ACC_LOCK_DESTROY(ac)	mtx_destroy(&(ac)->acc_mtx)
69267843Sdelphij#define ACC_LOCK(ac)		mtx_lock(&(ac)->acc_mtx)
70267843Sdelphij#define ACC_UNLOCK(ac)		mtx_unlock(&(ac)->acc_mtx)
71267843Sdelphij#else
72267843Sdelphij#define ACC_LOCK_INIT(ac)
73267843Sdelphij#define ACC_LOCK_DESTROY(ac)
74267843Sdelphij#define ACC_LOCK(ac)
75267843Sdelphij#define ACC_UNLOCK(ac)
76267843Sdelphij#endif
77267843Sdelphij
78267843Sdelphijstruct acc_classifier {
79267843Sdelphij	u_int32_t			acc_fbmask;
80267843Sdelphij	LIST_HEAD(filt, acc_filter)	acc_filters[ACC_FILTER_TABLESIZE];
81267843Sdelphij
82267843Sdelphij#if (__FreeBSD_version > 500000)
83267843Sdelphij	struct	mtx acc_mtx;
84267843Sdelphij#endif
85267843Sdelphij};
86267843Sdelphij
87267843Sdelphij/*
88267843Sdelphij * flowinfo mask bits used by classifier
89267843Sdelphij */
90267843Sdelphij/* for ipv4 */
91267843Sdelphij#define	FIMB4_PROTO	0x0001
92267843Sdelphij#define	FIMB4_TOS	0x0002
93267843Sdelphij#define	FIMB4_DADDR	0x0004
94300899Sdelphij#define	FIMB4_SADDR	0x0008
95300899Sdelphij#define	FIMB4_DPORT	0x0010
96300899Sdelphij#define	FIMB4_SPORT	0x0020
97300899Sdelphij#define	FIMB4_GPI	0x0040
98300899Sdelphij#define	FIMB4_ALL	0x007f
99300899Sdelphij/* for ipv6 */
100300899Sdelphij#define	FIMB6_PROTO	0x0100
101300899Sdelphij#define	FIMB6_TCLASS	0x0200
102300899Sdelphij#define	FIMB6_DADDR	0x0400
103300899Sdelphij#define	FIMB6_SADDR	0x0800
104300899Sdelphij#define	FIMB6_DPORT	0x1000
105300899Sdelphij#define	FIMB6_SPORT	0x2000
106300899Sdelphij#define	FIMB6_GPI	0x4000
107300899Sdelphij#define	FIMB6_FLABEL	0x8000
108300899Sdelphij#define	FIMB6_ALL	0xff00
109300899Sdelphij
110300899Sdelphij#define	FIMB_ALL	(FIMB4_ALL|FIMB6_ALL)
111267843Sdelphij
112267843Sdelphij#define	FIMB4_PORTS	(FIMB4_DPORT|FIMB4_SPORT|FIMB4_GPI)
113267843Sdelphij#define	FIMB6_PORTS	(FIMB6_DPORT|FIMB6_SPORT|FIMB6_GPI)
114267843Sdelphij#endif /* ALTQ3_CLFIER_COMPAT */
115267843Sdelphij
116267843Sdelphij/*
117267843Sdelphij * machine dependent clock
118267843Sdelphij * a 64bit high resolution time counter.
119267843Sdelphij */
120267843Sdelphijextern int machclk_usepcc;
121267843Sdelphijextern u_int32_t machclk_freq;
122267843Sdelphijextern u_int32_t machclk_per_tick;
123267843Sdelphijextern void init_machclk(void);
124267843Sdelphijextern u_int64_t read_machclk(void);
125267843Sdelphij
126267843Sdelphij/*
127267843Sdelphij * debug support
128267843Sdelphij */
129267843Sdelphij#ifdef ALTQ_DEBUG
130267843Sdelphij#ifdef __STDC__
131267843Sdelphij#define	ASSERT(e)	((e) ? (void)0 : altq_assert(__FILE__, __LINE__, #e))
132267843Sdelphij#else	/* PCC */
133267843Sdelphij#define	ASSERT(e)	((e) ? (void)0 : altq_assert(__FILE__, __LINE__, "e"))
134267843Sdelphij#endif
135267843Sdelphij#else
136267843Sdelphij#define	ASSERT(e)	((void)0)
137267843Sdelphij#endif
138267843Sdelphij
139267843Sdelphij/*
140267843Sdelphij * misc stuff for compatibility
141267843Sdelphij */
142267843Sdelphij/* ioctl cmd type */
143267843Sdelphij#if defined(__FreeBSD__) && (__FreeBSD__ < 3)
144267843Sdelphijtypedef int ioctlcmd_t;
145267843Sdelphij#else
146267843Sdelphijtypedef u_long ioctlcmd_t;
147267843Sdelphij#endif
148267843Sdelphij
149267843Sdelphij/*
150267843Sdelphij * queue macros:
151267843Sdelphij * the interface of TAILQ_LAST macro changed after the introduction
152267843Sdelphij * of softupdate. redefine it here to make it work with pre-2.2.7.
153267843Sdelphij */
154267843Sdelphij#undef TAILQ_LAST
155267843Sdelphij#define	TAILQ_LAST(head, headname) \
156267843Sdelphij	(*(((struct headname *)((head)->tqh_last))->tqh_last))
157267843Sdelphij
158267843Sdelphij#ifndef TAILQ_EMPTY
159267843Sdelphij#define	TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
160267843Sdelphij#endif
161267843Sdelphij#ifndef TAILQ_FOREACH
162267843Sdelphij#define TAILQ_FOREACH(var, head, field)					\
163267843Sdelphij	for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field))
164267843Sdelphij#endif
165267843Sdelphij
166267843Sdelphij/* macro for timeout/untimeout */
167267843Sdelphij#if (__FreeBSD_version > 300000) || defined(__NetBSD__)
168267843Sdelphij/* use callout */
169267843Sdelphij#include <sys/callout.h>
170267843Sdelphij
171267843Sdelphij#if (__FreeBSD_version > 500000)
172267843Sdelphij#define	CALLOUT_INIT(c)		callout_init((c), 0)
173267843Sdelphij#else
174267843Sdelphij#define	CALLOUT_INIT(c)		callout_init((c))
175267843Sdelphij#endif
176267843Sdelphij#define	CALLOUT_RESET(c,t,f,a)	callout_reset((c),(t),(f),(a))
177267843Sdelphij#define	CALLOUT_STOP(c)		callout_stop((c))
178267843Sdelphij#ifndef CALLOUT_INITIALIZER
179267843Sdelphij#define	CALLOUT_INITIALIZER	{ { { NULL } }, 0, NULL, NULL, 0 }
180267843Sdelphij#endif
181267843Sdelphij#elif defined(__OpenBSD__)
182267843Sdelphij#include <sys/timeout.h>
183267843Sdelphij/* callout structure as a wrapper of struct timeout */
184267843Sdelphijstruct callout {
185267843Sdelphij	struct timeout	c_to;
186267843Sdelphij};
187267843Sdelphij#define	CALLOUT_INIT(c)		do { bzero((c), sizeof(*(c))); } while (/*CONSTCOND*/ 0)
188267843Sdelphij#define	CALLOUT_RESET(c,t,f,a)	do { if (!timeout_initialized(&(c)->c_to))  \
189267843Sdelphij					 timeout_set(&(c)->c_to, (f), (a)); \
190267843Sdelphij				     timeout_add(&(c)->c_to, (t)); } while (/*CONSTCOND*/ 0)
191267843Sdelphij#define	CALLOUT_STOP(c)		timeout_del(&(c)->c_to)
192267843Sdelphij#define	CALLOUT_INITIALIZER	{ { { NULL }, NULL, NULL, 0, 0 } }
193267843Sdelphij#else
194267843Sdelphij/* use old-style timeout/untimeout */
195267843Sdelphij/* dummy callout structure */
196267843Sdelphijstruct callout {
197267843Sdelphij	void		*c_arg;			/* function argument */
198267843Sdelphij	void		(*c_func)(void *);	/* functiuon to call */
199267843Sdelphij};
200267843Sdelphij#define	CALLOUT_INIT(c)		do { bzero((c), sizeof(*(c))); } while (/*CONSTCOND*/ 0)
201267843Sdelphij#define	CALLOUT_RESET(c,t,f,a)	do {	(c)->c_arg = (a);	\
202267843Sdelphij					(c)->c_func = (f);	\
203267843Sdelphij					timeout((f),(a),(t)); } while (/*CONSTCOND*/ 0)
204267843Sdelphij#define	CALLOUT_STOP(c)		untimeout((c)->c_func,(c)->c_arg)
205267843Sdelphij#define	CALLOUT_INITIALIZER	{ NULL, NULL }
206267843Sdelphij#endif
207267843Sdelphij#if !defined(__FreeBSD__)
208267843Sdelphijtypedef void (timeout_t)(void *);
209267843Sdelphij#endif
210267843Sdelphij
211267843Sdelphij#define	m_pktlen(m)		((m)->m_pkthdr.len)
212267843Sdelphij
213267843Sdelphijstruct ifnet; struct mbuf;
214267843Sdelphijstruct pf_altq;
215267843Sdelphij#ifdef ALTQ3_CLFIER_COMPAT
216267843Sdelphijstruct flowinfo;
217267843Sdelphij#endif
218267843Sdelphij
219267843Sdelphijvoid	*altq_lookup(char *, int);
220267843Sdelphij#ifdef ALTQ3_CLFIER_COMPAT
221267843Sdelphijint	altq_extractflow(struct mbuf *, int, struct flowinfo *, u_int32_t);
222267843Sdelphijint	acc_add_filter(struct acc_classifier *, struct flow_filter *,
223267843Sdelphij	    void *, u_long *);
224267843Sdelphijint	acc_delete_filter(struct acc_classifier *, u_long);
225267843Sdelphijint	acc_discard_filters(struct acc_classifier *, void *, int);
226267843Sdelphijvoid	*acc_classify(void *, struct mbuf *, int);
227267843Sdelphij#endif
228267843Sdelphiju_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *);
229267843Sdelphijvoid	write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t);
230267843Sdelphijvoid	altq_assert(const char *, int, const char *);
231267843Sdelphijint	tbr_set(struct ifaltq *, struct tb_profile *);
232267843Sdelphijint	tbr_get(struct ifaltq *, struct tb_profile *);
233267843Sdelphij
234267843Sdelphijint	altq_pfattach(struct pf_altq *);
235267843Sdelphijint	altq_pfdetach(struct pf_altq *);
236267843Sdelphijint	altq_add(struct pf_altq *);
237267843Sdelphijint	altq_remove(struct pf_altq *);
238267843Sdelphijint	altq_add_queue(struct pf_altq *);
239267843Sdelphijint	altq_remove_queue(struct pf_altq *);
240267843Sdelphijint	altq_getqstats(struct pf_altq *, void *, int *);
241267843Sdelphij
242267843Sdelphijint	cbq_pfattach(struct pf_altq *);
243267843Sdelphijint	cbq_add_altq(struct pf_altq *);
244267843Sdelphijint	cbq_remove_altq(struct pf_altq *);
245267843Sdelphijint	cbq_add_queue(struct pf_altq *);
246267843Sdelphijint	cbq_remove_queue(struct pf_altq *);
247267843Sdelphijint	cbq_getqstats(struct pf_altq *, void *, int *);
248267843Sdelphij
249267843Sdelphijint	priq_pfattach(struct pf_altq *);
250267843Sdelphijint	priq_add_altq(struct pf_altq *);
251267843Sdelphijint	priq_remove_altq(struct pf_altq *);
252int	priq_add_queue(struct pf_altq *);
253int	priq_remove_queue(struct pf_altq *);
254int	priq_getqstats(struct pf_altq *, void *, int *);
255
256int	hfsc_pfattach(struct pf_altq *);
257int	hfsc_add_altq(struct pf_altq *);
258int	hfsc_remove_altq(struct pf_altq *);
259int	hfsc_add_queue(struct pf_altq *);
260int	hfsc_remove_queue(struct pf_altq *);
261int	hfsc_getqstats(struct pf_altq *, void *, int *);
262
263#endif /* _KERNEL */
264#endif /* _ALTQ_ALTQ_VAR_H_ */
265