xref: /freebsd/sys/netpfil/pf/pf_altq.h (revision edf8578117e8844e02c0121147f45e4609b30680)
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  */
33 
34 #ifndef	_NET_PF_ALTQ_H_
35 #define	_NET_PF_ALTQ_H_
36 
37 struct cbq_opts {
38 	u_int		minburst;
39 	u_int		maxburst;
40 	u_int		pktsize;
41 	u_int		maxpktsize;
42 	u_int		ns_per_byte;
43 	u_int		maxidle;
44 	int		minidle;
45 	u_int		offtime;
46 	int		flags;
47 };
48 
49 struct codel_opts {
50 	u_int		target;
51 	u_int		interval;
52 	int		ecn;
53 };
54 
55 struct priq_opts {
56 	int		flags;
57 };
58 
59 struct hfsc_opts_v0 {
60 	/* real-time service curve */
61 	u_int		rtsc_m1;	/* slope of the 1st segment in bps */
62 	u_int		rtsc_d;		/* the x-projection of m1 in msec */
63 	u_int		rtsc_m2;	/* slope of the 2nd segment in bps */
64 	/* link-sharing service curve */
65 	u_int		lssc_m1;
66 	u_int		lssc_d;
67 	u_int		lssc_m2;
68 	/* upper-limit service curve */
69 	u_int		ulsc_m1;
70 	u_int		ulsc_d;
71 	u_int		ulsc_m2;
72 	int		flags;
73 };
74 
75 struct hfsc_opts_v1 {
76 	/* real-time service curve */
77 	u_int64_t	rtsc_m1;	/* slope of the 1st segment in bps */
78 	u_int		rtsc_d;		/* the x-projection of m1 in msec */
79 	u_int64_t	rtsc_m2;	/* slope of the 2nd segment in bps */
80 	/* link-sharing service curve */
81 	u_int64_t	lssc_m1;
82 	u_int		lssc_d;
83 	u_int64_t	lssc_m2;
84 	/* upper-limit service curve */
85 	u_int64_t	ulsc_m1;
86 	u_int		ulsc_d;
87 	u_int64_t	ulsc_m2;
88 	int		flags;
89 };
90 
91 /*
92  * struct hfsc_opts doesn't have a version indicator macro or
93  * backwards-compat and convenience macros because both in the kernel and
94  * the pfctl parser, there are struct hfsc_opts instances named 'hfsc_opts'.
95  * It is believed that only in-tree code uses struct hfsc_opts, so
96  * backwards-compat macros are not necessary.  The few in-tree uses can just
97  * be updated to the latest versioned struct tag.
98  */
99 
100 /*
101  * XXX this needs some work
102  */
103 struct fairq_opts {
104 	u_int           nbuckets;
105 	u_int           hogs_m1;
106 	int             flags;
107 
108 	/* link sharing service curve */
109 	u_int           lssc_m1;
110 	u_int           lssc_d;
111 	u_int           lssc_m2;
112 };
113 
114 /*
115  * struct pf_altq_v0, struct pf_altq_v1, etc. are the ioctl argument
116  * structures corresponding to struct pfioc_altq_v0, struct pfioc_altq_v1,
117  * etc.
118  *
119  */
120 struct pf_altq_v0 {
121 	char			 ifname[IFNAMSIZ];
122 
123 	/*
124 	 * This member is a holdover from when the kernel state structure
125 	 * was reused as the ioctl argument structure, and remains to
126 	 * preserve the size and layout of this struct for backwards compat.
127 	 */
128 	void			*unused1;
129 	TAILQ_ENTRY(pf_altq_v0)	 entries;
130 
131 	/* scheduler spec */
132 	uint8_t			 scheduler;	/* scheduler type */
133 	uint16_t		 tbrsize;	/* tokenbucket regulator size */
134 	uint32_t		 ifbandwidth;	/* interface bandwidth */
135 
136 	/* queue spec */
137 	char			 qname[PF_QNAME_SIZE];	/* queue name */
138 	char			 parent[PF_QNAME_SIZE];	/* parent name */
139 	uint32_t		 parent_qid;	/* parent queue id */
140 	uint32_t		 bandwidth;	/* queue bandwidth */
141 	uint8_t			 priority;	/* priority */
142 	uint8_t			 local_flags;	/* dynamic interface */
143 #define	PFALTQ_FLAG_IF_REMOVED		0x01
144 
145 	uint16_t		 qlimit;	/* queue size limit */
146 	uint16_t		 flags;		/* misc flags */
147 	union {
148 		struct cbq_opts		 cbq_opts;
149 		struct codel_opts	 codel_opts;
150 		struct priq_opts	 priq_opts;
151 		struct hfsc_opts_v0	 hfsc_opts;
152 		struct fairq_opts        fairq_opts;
153 	} pq_u;
154 
155 	uint32_t		 qid;		/* return value */
156 };
157 
158 struct pf_altq_v1 {
159 	char			 ifname[IFNAMSIZ];
160 
161 	TAILQ_ENTRY(pf_altq_v1)	 entries;
162 
163 	/* scheduler spec */
164 	uint8_t			 scheduler;	/* scheduler type */
165 	uint32_t		 tbrsize;	/* tokenbucket regulator size */
166 	uint64_t		 ifbandwidth;	/* interface bandwidth */
167 
168 	/* queue spec */
169 	char			 qname[PF_QNAME_SIZE];	/* queue name */
170 	char			 parent[PF_QNAME_SIZE];	/* parent name */
171 	uint32_t		 parent_qid;	/* parent queue id */
172 	uint64_t		 bandwidth;	/* queue bandwidth */
173 	uint8_t			 priority;	/* priority */
174 	uint8_t			 local_flags;	/* dynamic interface, see _v0 */
175 
176 	uint16_t		 qlimit;	/* queue size limit */
177 	uint16_t		 flags;		/* misc flags */
178 	union {
179 		struct cbq_opts		 cbq_opts;
180 		struct codel_opts	 codel_opts;
181 		struct priq_opts	 priq_opts;
182 		struct hfsc_opts_v1	 hfsc_opts;
183 		struct fairq_opts        fairq_opts;
184 	} pq_u;
185 
186 	uint32_t		 qid;		/* return value */
187 };
188 
189 /* Latest version of struct pf_altq_vX */
190 #define PF_ALTQ_VERSION	1
191 
192 #ifdef _KERNEL
193 struct pf_kaltq {
194 	char			 ifname[IFNAMSIZ];
195 
196 	void			*altq_disc;	/* discipline-specific state */
197 	TAILQ_ENTRY(pf_kaltq)	 entries;
198 
199 	/* scheduler spec */
200 	uint8_t			 scheduler;	/* scheduler type */
201 	uint32_t		 tbrsize;	/* tokenbucket regulator size */
202 	uint64_t		 ifbandwidth;	/* interface bandwidth */
203 
204 	/* queue spec */
205 	char			 qname[PF_QNAME_SIZE];	/* queue name */
206 	char			 parent[PF_QNAME_SIZE];	/* parent name */
207 	uint32_t		 parent_qid;	/* parent queue id */
208 	uint64_t		 bandwidth;	/* queue bandwidth */
209 	uint8_t			 priority;	/* priority */
210 	uint8_t			 local_flags;	/* dynamic interface, see _v0 */
211 
212 	uint16_t		 qlimit;	/* queue size limit */
213 	uint16_t		 flags;		/* misc flags */
214 	union {
215 		struct cbq_opts		 cbq_opts;
216 		struct codel_opts	 codel_opts;
217 		struct priq_opts	 priq_opts;
218 		struct hfsc_opts_v1	 hfsc_opts;
219 		struct fairq_opts        fairq_opts;
220 	} pq_u;
221 
222 	uint16_t		 qid;		/* return value */
223 };
224 #endif /* _KERNEL */
225 
226 /*
227  * Compatibility and convenience macros
228  */
229 #ifdef _KERNEL
230 /*
231  * Avoid a patch with 100+ lines of name substitution.
232  */
233 #define pf_altq pf_kaltq
234 
235 #else /* _KERNEL */
236 
237 #ifdef PFIOC_USE_LATEST
238 /*
239  * Maintaining in-tree consumers of the ioctl interface is easier when that
240  * code can be written in terms old names that refer to the latest interface
241  * version as that reduces the required changes in the consumers to those
242  * that are functionally necessary to accommodate a new interface version.
243  */
244 #define	pf_altq		__CONCAT(pf_altq_v, PF_ALTQ_VERSION)
245 
246 #else /* PFIOC_USE_LATEST */
247 /*
248  * When building out-of-tree code that is written for the old interface,
249  * such as may exist in ports for example, resolve the old pf_altq struct
250  * tag to the v0 version.
251  */
252 #define	pf_altq		__CONCAT(pf_altq_v, 0)
253 
254 #endif /* PFIOC_USE_LATEST */
255 #endif /* _KERNEL */
256 
257 #endif	/* _NET_PF_ALTQ_H_ */
258