altq_qop.h revision 1.10 1 1.10 kre /* $NetBSD: altq_qop.h,v 1.10 2024/12/24 12:13:05 kre Exp $ */
2 1.3 itojun /* $KAME: altq_qop.h,v 1.5 2002/02/12 10:14:01 kjc Exp $ */
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (C) 1999-2000
5 1.1 thorpej * Sony Computer Science Laboratories, Inc. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej *
16 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 thorpej * SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej #ifndef _ALTQ_QOP_H_
29 1.1 thorpej #define _ALTQ_QOP_H_
30 1.1 thorpej
31 1.1 thorpej #include <sys/queue.h>
32 1.10 kre #include <sys/types.h>
33 1.1 thorpej #include <altq/altq.h>
34 1.1 thorpej #include <altq/altq_red.h>
35 1.1 thorpej
36 1.1 thorpej struct ifinfo;
37 1.1 thorpej struct classinfo;
38 1.1 thorpej struct fltrinfo;
39 1.1 thorpej
40 1.1 thorpej /* queueing discipline specific command parsers */
41 1.1 thorpej struct qdisc_parser {
42 1.5 xtraeme const char *qname;
43 1.1 thorpej int (*interface_parser)(const char *ifname, int argc, char **argv);
44 1.1 thorpej int (*class_parser)(const char *ifname, const char *clname,
45 1.1 thorpej const char *parent, int argc, char **argv);
46 1.1 thorpej };
47 1.1 thorpej
48 1.1 thorpej /* queueing discipline specific operations */
49 1.1 thorpej struct qdisc_ops {
50 1.5 xtraeme int qdisc_type; /* discipline type (e.g., ALTQT_CBQ) */
51 1.5 xtraeme const char *qname; /* discipline name (e.g., cbq) */
52 1.1 thorpej
53 1.1 thorpej /* interface operations */
54 1.1 thorpej int (*attach)(struct ifinfo *);
55 1.1 thorpej int (*detach)(struct ifinfo *);
56 1.1 thorpej int (*clear)(struct ifinfo *);
57 1.1 thorpej int (*enable)(struct ifinfo *);
58 1.1 thorpej int (*disable)(struct ifinfo *);
59 1.1 thorpej
60 1.1 thorpej /* class operations (optional) */
61 1.1 thorpej int (*add_class)(struct classinfo *);
62 1.1 thorpej int (*modify_class)(struct classinfo *, void *);
63 1.1 thorpej int (*delete_class)(struct classinfo *);
64 1.1 thorpej
65 1.1 thorpej /* filter operations (optional) */
66 1.1 thorpej int (*add_filter)(struct fltrinfo *);
67 1.1 thorpej int (*delete_filter)(struct fltrinfo *);
68 1.1 thorpej };
69 1.1 thorpej
70 1.1 thorpej /*
71 1.1 thorpej * interface info
72 1.1 thorpej */
73 1.1 thorpej struct ifinfo {
74 1.1 thorpej LIST_ENTRY(ifinfo) next; /* next entry on iflist */
75 1.1 thorpej char *ifname; /* interface name */
76 1.9 ozaki uint64_t bandwidth; /* bandwidth in bps */
77 1.1 thorpej u_int ifmtu; /* mtu of the interface */
78 1.1 thorpej u_int ifindex; /* interface index */
79 1.1 thorpej int enabled; /* hfsc on/off state */
80 1.1 thorpej LIST_HEAD(, classinfo) cllist; /* class list */
81 1.1 thorpej LIST_HEAD(, fltrinfo) fltr_rules; /* filter rule list */
82 1.1 thorpej
83 1.1 thorpej struct classinfo *resv_class; /* special class for rsvp */
84 1.1 thorpej
85 1.1 thorpej /* discipline info */
86 1.1 thorpej struct qdisc_ops *qdisc; /* qdisc system interface */
87 1.1 thorpej void *private; /* discipline specific data */
88 1.1 thorpej int (*enable_hook)(struct ifinfo *);
89 1.1 thorpej int (*delete_hook)(struct ifinfo *);
90 1.1 thorpej };
91 1.1 thorpej
92 1.1 thorpej /*
93 1.1 thorpej * class info
94 1.1 thorpej */
95 1.1 thorpej struct classinfo {
96 1.1 thorpej LIST_ENTRY(classinfo) next; /* next entry on cllist
97 1.1 thorpej of ifinfo */
98 1.1 thorpej u_long handle; /* class handle */
99 1.1 thorpej char *clname; /* class name */
100 1.1 thorpej struct ifinfo *ifinfo; /* back pointer to ifinfo */
101 1.1 thorpej struct classinfo *parent; /* parent class */
102 1.1 thorpej struct classinfo *sibling; /* sibling class */
103 1.1 thorpej struct classinfo *child; /* child class */
104 1.1 thorpej LIST_HEAD(, fltrinfo) fltrlist; /* filters for this class */
105 1.1 thorpej
106 1.1 thorpej void *private; /* discipline specific data */
107 1.1 thorpej int (*delete_hook)(struct classinfo *);
108 1.1 thorpej };
109 1.1 thorpej
110 1.1 thorpej /*
111 1.1 thorpej * filter info
112 1.1 thorpej */
113 1.1 thorpej struct fltrinfo {
114 1.1 thorpej LIST_ENTRY(fltrinfo) next; /* next entry on fltrlist
115 1.1 thorpej of classinfo */
116 1.1 thorpej LIST_ENTRY(fltrinfo) nextrule; /* next entry on fltr_rules
117 1.1 thorpej of ifinfo */
118 1.1 thorpej u_long handle; /* filter handle */
119 1.1 thorpej char *flname; /* filter name, if specified */
120 1.1 thorpej struct flow_filter fltr; /* filter value */
121 1.1 thorpej struct classinfo *clinfo; /* back pointer to classinfo */
122 1.1 thorpej
123 1.1 thorpej /* for consistency check */
124 1.1 thorpej int line_no; /* config file line number */
125 1.7 msaitoh int dontwarn; /* suppress warning msg */
126 1.1 thorpej };
127 1.1 thorpej
128 1.3 itojun int do_command(FILE *infp);
129 1.1 thorpej int qcmd_enable(const char *ifname);
130 1.1 thorpej int qcmd_disable(const char *ifname);
131 1.1 thorpej int qcmd_delete_if(const char *ifname);
132 1.1 thorpej int qcmd_clear_hierarchy(const char *ifname);
133 1.1 thorpej int qcmd_enableall(void);
134 1.1 thorpej int qcmd_disableall(void);
135 1.1 thorpej int qcmd_config(void);
136 1.1 thorpej int qcmd_init(void);
137 1.1 thorpej int qcmd_clear(const char *ifname);
138 1.1 thorpej int qcmd_destroyall(void);
139 1.1 thorpej int qcmd_restart(void);
140 1.1 thorpej int qcmd_delete_class(const char *ifname, const char *clname);
141 1.1 thorpej int qcmd_add_filter(const char *ifname, const char *clname, const char *flname,
142 1.1 thorpej const struct flow_filter *fltr);
143 1.1 thorpej int qcmd_delete_filter(const char *ifname, const char *clname,
144 1.1 thorpej const char *flname);
145 1.9 ozaki int qcmd_tbr_register(const char *ifname, uint64_t rate, u_int size);
146 1.1 thorpej int qop_enable(struct ifinfo *ifinfo);
147 1.1 thorpej int qop_disable(struct ifinfo *ifinfo);
148 1.1 thorpej int qop_delete_if(struct ifinfo *ifinfo);
149 1.1 thorpej int qop_clear(struct ifinfo *ifinfo);
150 1.1 thorpej
151 1.9 ozaki int qop_add_if(struct ifinfo **rp, const char *ifname, uint64_t bandwidth,
152 1.1 thorpej struct qdisc_ops *qdisc_ops, void *if_private);
153 1.1 thorpej int qop_delete_if(struct ifinfo *ifinfo);
154 1.1 thorpej
155 1.1 thorpej int qop_add_class(struct classinfo **rp, const char *clname,
156 1.1 thorpej struct ifinfo *ifinfo, struct classinfo *parent,
157 1.1 thorpej void *class_private);
158 1.1 thorpej int qop_modify_class(struct classinfo *clinfo, void *arg);
159 1.1 thorpej int qop_delete_class(struct classinfo *clinfo);
160 1.1 thorpej
161 1.1 thorpej int qop_add_filter(struct fltrinfo **rp,
162 1.1 thorpej struct classinfo *clinfo,
163 1.1 thorpej const char *flname,
164 1.1 thorpej const struct flow_filter *fltr,
165 1.1 thorpej struct fltrinfo **conflict);
166 1.1 thorpej int qop_delete_filter(struct fltrinfo *fltr);
167 1.1 thorpej
168 1.1 thorpej int is_q_enabled(const char *ifname);
169 1.1 thorpej struct ifinfo *ifname2ifinfo(const char *ifname);
170 1.1 thorpej struct ifinfo *input_ifname2ifinfo(const char *ifname);
171 1.1 thorpej struct classinfo *clname2clinfo(const struct ifinfo *ifinfo,
172 1.1 thorpej const char *clname);
173 1.1 thorpej struct classinfo * clhandle2clinfo(struct ifinfo *ifinfo, u_long handle);
174 1.1 thorpej struct fltrinfo *flname2flinfo(const struct classinfo *clinfo,
175 1.1 thorpej const char *flname);
176 1.1 thorpej struct fltrinfo *flhandle2fltrinfo(struct ifinfo *ifinfo, u_long handle);
177 1.1 thorpej void print_filter(const struct flow_filter *filt);
178 1.1 thorpej const char *qoperror(int qoperrno);
179 1.1 thorpej u_int get_ifindex(const char *ifname);
180 1.1 thorpej struct classinfo *get_rootclass(struct ifinfo *ifinfo);
181 1.1 thorpej struct classinfo *get_nextclass(struct classinfo *clinfo);
182 1.10 kre uint64_t atobps(const char *s);
183 1.1 thorpej u_long atobytes(const char *s);
184 1.1 thorpej int qop_red_set_defaults(int th_min, int th_max, int inv_pmax);
185 1.1 thorpej int qop_rio_set_defaults(struct redparams *params);
186 1.1 thorpej int open_module(const char *devname, int flags);
187 1.1 thorpej int client_input(FILE *fp);
188 1.1 thorpej
189 1.1 thorpej /* misc system errors */
190 1.1 thorpej #define QOPERR_OK 0 /* no error */
191 1.1 thorpej #define QOPERR_SYSCALL 1 /* syscall err; see errno */
192 1.1 thorpej #define QOPERR_NOMEM 2 /* not enough memory */
193 1.1 thorpej #define QOPERR_INVAL 3 /* invalid parameter */
194 1.1 thorpej #define QOPERR_RANGE 4 /* out of range */
195 1.1 thorpej #define QOPERR_BADIF 5 /* bad interface name */
196 1.1 thorpej #define QOPERR_BADCLASS 6 /* bad class name */
197 1.1 thorpej #define QOPERR_BADFILTER 7 /* bad filter name */
198 1.1 thorpej
199 1.1 thorpej /* class errors */
200 1.1 thorpej #define QOPERR_CLASS 8 /* class failure */
201 1.1 thorpej #define QOPERR_CLASS_INVAL 9 /* bad class value */
202 1.1 thorpej #define QOPERR_CLASS_PERM 10 /* class operation not permitted */
203 1.1 thorpej
204 1.1 thorpej /* filter errors */
205 1.1 thorpej #define QOPERR_FILTER 11 /* filter failure */
206 1.1 thorpej #define QOPERR_FILTER_INVAL 12 /* bad filter value */
207 1.1 thorpej #define QOPERR_FILTER_SHADOW 13 /* shadows an existing filter */
208 1.1 thorpej
209 1.8 andvar /* admission errors */
210 1.1 thorpej #define QOPERR_ADMISSION 14 /* admission control failure */
211 1.1 thorpej #define QOPERR_ADMISSION_NOBW 15 /* insufficient bandwidth */
212 1.1 thorpej #define QOPERR_ADMISSION_DELAY 16 /* cannot meet delay bound req */
213 1.1 thorpej #define QOPERR_ADMISSION_NOSVC 17 /* no service available */
214 1.1 thorpej
215 1.1 thorpej /* policy errors */
216 1.1 thorpej #define QOPERR_POLICY 18 /* policy control failure */
217 1.1 thorpej
218 1.1 thorpej #define QOPERR_MAX 18
219 1.1 thorpej
220 1.7 msaitoh extern int filter_dontwarn;/* suppress warning for the current filter */
221 1.5 xtraeme extern const char *altqconfigfile; /* config file name */
222 1.1 thorpej extern const char *qop_errlist[]; /* error string list */
223 1.1 thorpej extern struct qdisc_ops nop_qdisc;
224 1.1 thorpej extern char *cur_ifname(void);
225 1.1 thorpej extern struct qdisc_parser qdisc_parser[];
226 1.1 thorpej
227 1.1 thorpej #ifndef RSVPD
228 1.1 thorpej /* rename LOG() to log_write() */
229 1.1 thorpej #define LOG log_write
230 1.1 thorpej void log_write(int, int, const char *, ...);
231 1.1 thorpej
232 1.1 thorpej /* stuff defined in rsvp headers */
233 1.1 thorpej #define IsDebug(type) (l_debug >= LOG_DEBUG && (m_debug & (type)))
234 1.1 thorpej #define DEBUG_ALTQ 0x40
235 1.1 thorpej
236 1.1 thorpej #define ntoh16(x) ((u_int16_t)ntohs((u_int16_t)(x)))
237 1.1 thorpej #define ntoh32(x) ((u_int32_t)ntohl((u_int32_t)(x)))
238 1.1 thorpej #define hton16(x) ((u_int16_t)htons((u_int16_t)(x)))
239 1.1 thorpej #define hton32(x) ((u_int32_t)htonl((u_int32_t)(x)))
240 1.1 thorpej
241 1.1 thorpej extern int if_num; /* number of phyints */
242 1.1 thorpej extern int m_debug; /* Debug output control bits */
243 1.1 thorpej extern int l_debug; /* Logging severity level */
244 1.1 thorpej extern int line_no; /* current line number in config file */
245 1.1 thorpej extern int daemonize; /* log_write uses stderr if daemonize is 0 */
246 1.1 thorpej
247 1.1 thorpej #endif /* !RSVPD */
248 1.1 thorpej
249 1.1 thorpej #ifdef INET6
250 1.6 christos static inline uint32_t IN6ADDR32_GET(const struct in6_addr *a, size_t i) {
251 1.6 christos uint32_t ret;
252 1.6 christos memcpy(&ret, &(a)->s6_addr[i << 2], sizeof(ret));
253 1.6 christos return ret;
254 1.6 christos }
255 1.6 christos static inline void IN6ADDR32_SET(struct in6_addr *a, size_t i, uint32_t val) {
256 1.6 christos memcpy(&(a)->s6_addr[i << 2], &val, sizeof(val));
257 1.6 christos }
258 1.1 thorpej #endif
259 1.1 thorpej
260 1.1 thorpej #endif /* _ALTQ_QOP_H_ */
261