xref: /freebsd/sys/netpfil/pf/pf_altq.h (revision 190cef3d52236565eb22e18b33e9e865ec634aa3)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2001 Daniel Hartmeier
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *    - Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *    - Redistributions in binary form must reproduce the above
14  *      copyright notice, this list of conditions and the following
15  *      disclaimer in the documentation and/or other materials provided
16  *      with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  *	$OpenBSD: pfvar.h,v 1.282 2009/01/29 15:12:28 pyr Exp $
32  *	$FreeBSD$
33  */
34 
35 #ifndef	_NET_PF_ALTQ_H_
36 #define	_NET_PF_ALTQ_H_
37 
38 struct cbq_opts {
39 	u_int		minburst;
40 	u_int		maxburst;
41 	u_int		pktsize;
42 	u_int		maxpktsize;
43 	u_int		ns_per_byte;
44 	u_int		maxidle;
45 	int		minidle;
46 	u_int		offtime;
47 	int		flags;
48 };
49 
50 struct codel_opts {
51 	u_int		target;
52 	u_int		interval;
53 	int		ecn;
54 };
55 
56 struct priq_opts {
57 	int		flags;
58 };
59 
60 struct hfsc_opts_v0 {
61 	/* real-time service curve */
62 	u_int		rtsc_m1;	/* slope of the 1st segment in bps */
63 	u_int		rtsc_d;		/* the x-projection of m1 in msec */
64 	u_int		rtsc_m2;	/* slope of the 2nd segment in bps */
65 	/* link-sharing service curve */
66 	u_int		lssc_m1;
67 	u_int		lssc_d;
68 	u_int		lssc_m2;
69 	/* upper-limit service curve */
70 	u_int		ulsc_m1;
71 	u_int		ulsc_d;
72 	u_int		ulsc_m2;
73 	int		flags;
74 };
75 
76 struct hfsc_opts_v1 {
77 	/* real-time service curve */
78 	u_int64_t	rtsc_m1;	/* slope of the 1st segment in bps */
79 	u_int		rtsc_d;		/* the x-projection of m1 in msec */
80 	u_int64_t	rtsc_m2;	/* slope of the 2nd segment in bps */
81 	/* link-sharing service curve */
82 	u_int64_t	lssc_m1;
83 	u_int		lssc_d;
84 	u_int64_t	lssc_m2;
85 	/* upper-limit service curve */
86 	u_int64_t	ulsc_m1;
87 	u_int		ulsc_d;
88 	u_int64_t	ulsc_m2;
89 	int		flags;
90 };
91 
92 /*
93  * struct hfsc_opts doesn't have a version indicator macro or
94  * backwards-compat and convenience macros because both in the kernel and
95  * the pfctl parser, there are struct hfsc_opts instances named 'hfsc_opts'.
96  * It is believed that only in-tree code uses struct hfsc_opts, so
97  * backwards-compat macros are not necessary.  The few in-tree uses can just
98  * be updated to the latest versioned struct tag.
99  */
100 
101 /*
102  * XXX this needs some work
103  */
104 struct fairq_opts {
105 	u_int           nbuckets;
106 	u_int           hogs_m1;
107 	int             flags;
108 
109 	/* link sharing service curve */
110 	u_int           lssc_m1;
111 	u_int           lssc_d;
112 	u_int           lssc_m2;
113 };
114 
115 /*
116  * struct pf_altq_v0, struct pf_altq_v1, etc. are the ioctl argument
117  * structures corresponding to struct pfioc_altq_v0, struct pfioc_altq_v1,
118  * etc.
119  *
120  */
121 struct pf_altq_v0 {
122 	char			 ifname[IFNAMSIZ];
123 
124 	/*
125 	 * This member is a holdover from when the kernel state structure
126 	 * was reused as the ioctl argument structure, and remains to
127 	 * preserve the size and layout of this struct for backwards compat.
128 	 */
129 	void			*unused1;
130 	TAILQ_ENTRY(pf_altq_v0)	 entries;
131 
132 	/* scheduler spec */
133 	uint8_t			 scheduler;	/* scheduler type */
134 	uint16_t		 tbrsize;	/* tokenbucket regulator size */
135 	uint32_t		 ifbandwidth;	/* interface bandwidth */
136 
137 	/* queue spec */
138 	char			 qname[PF_QNAME_SIZE];	/* queue name */
139 	char			 parent[PF_QNAME_SIZE];	/* parent name */
140 	uint32_t		 parent_qid;	/* parent queue id */
141 	uint32_t		 bandwidth;	/* queue bandwidth */
142 	uint8_t			 priority;	/* priority */
143 	uint8_t			 local_flags;	/* dynamic interface */
144 #define	PFALTQ_FLAG_IF_REMOVED		0x01
145 
146 	uint16_t		 qlimit;	/* queue size limit */
147 	uint16_t		 flags;		/* misc flags */
148 	union {
149 		struct cbq_opts		 cbq_opts;
150 		struct codel_opts	 codel_opts;
151 		struct priq_opts	 priq_opts;
152 		struct hfsc_opts_v0	 hfsc_opts;
153 		struct fairq_opts        fairq_opts;
154 	} pq_u;
155 
156 	uint32_t		 qid;		/* return value */
157 };
158 
159 struct pf_altq_v1 {
160 	char			 ifname[IFNAMSIZ];
161 
162 	TAILQ_ENTRY(pf_altq_v1)	 entries;
163 
164 	/* scheduler spec */
165 	uint8_t			 scheduler;	/* scheduler type */
166 	uint32_t		 tbrsize;	/* tokenbucket regulator size */
167 	uint64_t		 ifbandwidth;	/* interface bandwidth */
168 
169 	/* queue spec */
170 	char			 qname[PF_QNAME_SIZE];	/* queue name */
171 	char			 parent[PF_QNAME_SIZE];	/* parent name */
172 	uint32_t		 parent_qid;	/* parent queue id */
173 	uint64_t		 bandwidth;	/* queue bandwidth */
174 	uint8_t			 priority;	/* priority */
175 	uint8_t			 local_flags;	/* dynamic interface, see _v0 */
176 
177 	uint16_t		 qlimit;	/* queue size limit */
178 	uint16_t		 flags;		/* misc flags */
179 	union {
180 		struct cbq_opts		 cbq_opts;
181 		struct codel_opts	 codel_opts;
182 		struct priq_opts	 priq_opts;
183 		struct hfsc_opts_v1	 hfsc_opts;
184 		struct fairq_opts        fairq_opts;
185 	} pq_u;
186 
187 	uint32_t		 qid;		/* return value */
188 };
189 
190 /* Latest version of struct pf_altq_vX */
191 #define PF_ALTQ_VERSION	1
192 
193 #ifdef _KERNEL
194 struct pf_kaltq {
195 	char			 ifname[IFNAMSIZ];
196 
197 	void			*altq_disc;	/* discipline-specific state */
198 	TAILQ_ENTRY(pf_kaltq)	 entries;
199 
200 	/* scheduler spec */
201 	uint8_t			 scheduler;	/* scheduler type */
202 	uint32_t		 tbrsize;	/* tokenbucket regulator size */
203 	uint64_t		 ifbandwidth;	/* interface bandwidth */
204 
205 	/* queue spec */
206 	char			 qname[PF_QNAME_SIZE];	/* queue name */
207 	char			 parent[PF_QNAME_SIZE];	/* parent name */
208 	uint32_t		 parent_qid;	/* parent queue id */
209 	uint64_t		 bandwidth;	/* queue bandwidth */
210 	uint8_t			 priority;	/* priority */
211 	uint8_t			 local_flags;	/* dynamic interface, see _v0 */
212 
213 	uint16_t		 qlimit;	/* queue size limit */
214 	uint16_t		 flags;		/* misc flags */
215 	union {
216 		struct cbq_opts		 cbq_opts;
217 		struct codel_opts	 codel_opts;
218 		struct priq_opts	 priq_opts;
219 		struct hfsc_opts_v1	 hfsc_opts;
220 		struct fairq_opts        fairq_opts;
221 	} pq_u;
222 
223 	uint32_t		 qid;		/* return value */
224 };
225 #endif /* _KERNEL */
226 
227 /*
228  * Compatibility and convenience macros
229  */
230 #ifdef _KERNEL
231 /*
232  * Avoid a patch with 100+ lines of name substitution.
233  */
234 #define pf_altq pf_kaltq
235 
236 #else /* _KERNEL */
237 
238 #ifdef PFIOC_USE_LATEST
239 /*
240  * Maintaining in-tree consumers of the ioctl interface is easier when that
241  * code can be written in terms old names that refer to the latest interface
242  * version as that reduces the required changes in the consumers to those
243  * that are functionally necessary to accommodate a new interface version.
244  */
245 #define	pf_altq		__CONCAT(pf_altq_v, PF_ALTQ_VERSION)
246 
247 #else /* PFIOC_USE_LATEST */
248 /*
249  * When building out-of-tree code that is written for the old interface,
250  * such as may exist in ports for example, resolve the old pf_altq struct
251  * tag to the v0 version.
252  */
253 #define	pf_altq		__CONCAT(pf_altq_v, 0)
254 
255 #endif /* PFIOC_USE_LATEST */
256 #endif /* _KERNEL */
257 
258 #endif	/* _NET_PF_ALTQ_H_ */
259