altq_qop.h revision 1.6 1 1.6 christos /* $NetBSD: altq_qop.h,v 1.6 2011/08/16 12:49:13 christos 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.1 thorpej #include <altq/altq.h>
33 1.1 thorpej #include <altq/altq_red.h>
34 1.1 thorpej
35 1.1 thorpej struct ifinfo;
36 1.1 thorpej struct classinfo;
37 1.1 thorpej struct fltrinfo;
38 1.1 thorpej
39 1.1 thorpej /* queueing discipline specific command parsers */
40 1.1 thorpej struct qdisc_parser {
41 1.5 xtraeme const char *qname;
42 1.1 thorpej int (*interface_parser)(const char *ifname, int argc, char **argv);
43 1.1 thorpej int (*class_parser)(const char *ifname, const char *clname,
44 1.1 thorpej const char *parent, int argc, char **argv);
45 1.1 thorpej };
46 1.1 thorpej
47 1.1 thorpej /* queueing discipline specific operations */
48 1.1 thorpej struct qdisc_ops {
49 1.5 xtraeme int qdisc_type; /* discipline type (e.g., ALTQT_CBQ) */
50 1.5 xtraeme const char *qname; /* discipline name (e.g., cbq) */
51 1.1 thorpej
52 1.1 thorpej /* interface operations */
53 1.1 thorpej int (*attach)(struct ifinfo *);
54 1.1 thorpej int (*detach)(struct ifinfo *);
55 1.1 thorpej int (*clear)(struct ifinfo *);
56 1.1 thorpej int (*enable)(struct ifinfo *);
57 1.1 thorpej int (*disable)(struct ifinfo *);
58 1.1 thorpej
59 1.1 thorpej /* class operations (optional) */
60 1.1 thorpej int (*add_class)(struct classinfo *);
61 1.1 thorpej int (*modify_class)(struct classinfo *, void *);
62 1.1 thorpej int (*delete_class)(struct classinfo *);
63 1.1 thorpej
64 1.1 thorpej /* filter operations (optional) */
65 1.1 thorpej int (*add_filter)(struct fltrinfo *);
66 1.1 thorpej int (*delete_filter)(struct fltrinfo *);
67 1.1 thorpej };
68 1.1 thorpej
69 1.1 thorpej /*
70 1.1 thorpej * interface info
71 1.1 thorpej */
72 1.1 thorpej struct ifinfo {
73 1.1 thorpej LIST_ENTRY(ifinfo) next; /* next entry on iflist */
74 1.1 thorpej char *ifname; /* interface name */
75 1.1 thorpej u_int bandwidth; /* bandwidth in bps */
76 1.1 thorpej u_int ifmtu; /* mtu of the interface */
77 1.1 thorpej u_int ifindex; /* interface index */
78 1.1 thorpej int enabled; /* hfsc on/off state */
79 1.1 thorpej LIST_HEAD(, classinfo) cllist; /* class list */
80 1.1 thorpej LIST_HEAD(, fltrinfo) fltr_rules; /* filter rule list */
81 1.1 thorpej
82 1.1 thorpej struct classinfo *resv_class; /* special class for rsvp */
83 1.1 thorpej
84 1.1 thorpej /* discipline info */
85 1.1 thorpej struct qdisc_ops *qdisc; /* qdisc system interface */
86 1.1 thorpej void *private; /* discipline specific data */
87 1.1 thorpej int (*enable_hook)(struct ifinfo *);
88 1.1 thorpej int (*delete_hook)(struct ifinfo *);
89 1.1 thorpej };
90 1.1 thorpej
91 1.1 thorpej /*
92 1.1 thorpej * class info
93 1.1 thorpej */
94 1.1 thorpej struct classinfo {
95 1.1 thorpej LIST_ENTRY(classinfo) next; /* next entry on cllist
96 1.1 thorpej of ifinfo */
97 1.1 thorpej u_long handle; /* class handle */
98 1.1 thorpej char *clname; /* class name */
99 1.1 thorpej struct ifinfo *ifinfo; /* back pointer to ifinfo */
100 1.1 thorpej struct classinfo *parent; /* parent class */
101 1.1 thorpej struct classinfo *sibling; /* sibling class */
102 1.1 thorpej struct classinfo *child; /* child class */
103 1.1 thorpej LIST_HEAD(, fltrinfo) fltrlist; /* filters for this class */
104 1.1 thorpej
105 1.1 thorpej void *private; /* discipline specific data */
106 1.1 thorpej int (*delete_hook)(struct classinfo *);
107 1.1 thorpej };
108 1.1 thorpej
109 1.1 thorpej /*
110 1.1 thorpej * filter info
111 1.1 thorpej */
112 1.1 thorpej struct fltrinfo {
113 1.1 thorpej LIST_ENTRY(fltrinfo) next; /* next entry on fltrlist
114 1.1 thorpej of classinfo */
115 1.1 thorpej LIST_ENTRY(fltrinfo) nextrule; /* next entry on fltr_rules
116 1.1 thorpej of ifinfo */
117 1.1 thorpej u_long handle; /* filter handle */
118 1.1 thorpej char *flname; /* filter name, if specified */
119 1.1 thorpej struct flow_filter fltr; /* filter value */
120 1.1 thorpej struct classinfo *clinfo; /* back pointer to classinfo */
121 1.1 thorpej
122 1.1 thorpej /* for consistency check */
123 1.1 thorpej int line_no; /* config file line number */
124 1.1 thorpej int dontwarn; /* supress warning msg */
125 1.1 thorpej };
126 1.1 thorpej
127 1.3 itojun int do_command(FILE *infp);
128 1.1 thorpej int qcmd_enable(const char *ifname);
129 1.1 thorpej int qcmd_disable(const char *ifname);
130 1.1 thorpej int qcmd_delete_if(const char *ifname);
131 1.1 thorpej int qcmd_clear_hierarchy(const char *ifname);
132 1.1 thorpej int qcmd_enableall(void);
133 1.1 thorpej int qcmd_disableall(void);
134 1.1 thorpej int qcmd_config(void);
135 1.1 thorpej int qcmd_init(void);
136 1.1 thorpej int qcmd_clear(const char *ifname);
137 1.1 thorpej int qcmd_destroyall(void);
138 1.1 thorpej int qcmd_restart(void);
139 1.1 thorpej int qcmd_delete_class(const char *ifname, const char *clname);
140 1.1 thorpej int qcmd_add_filter(const char *ifname, const char *clname, const char *flname,
141 1.1 thorpej const struct flow_filter *fltr);
142 1.1 thorpej int qcmd_delete_filter(const char *ifname, const char *clname,
143 1.1 thorpej const char *flname);
144 1.1 thorpej int qcmd_tbr_register(const char *ifname, u_int rate, u_int size);
145 1.1 thorpej int qop_enable(struct ifinfo *ifinfo);
146 1.1 thorpej int qop_disable(struct ifinfo *ifinfo);
147 1.1 thorpej int qop_delete_if(struct ifinfo *ifinfo);
148 1.1 thorpej int qop_clear(struct ifinfo *ifinfo);
149 1.1 thorpej
150 1.1 thorpej int qop_add_if(struct ifinfo **rp, const char *ifname, u_int bandwidth,
151 1.1 thorpej struct qdisc_ops *qdisc_ops, void *if_private);
152 1.1 thorpej int qop_delete_if(struct ifinfo *ifinfo);
153 1.1 thorpej
154 1.1 thorpej int qop_add_class(struct classinfo **rp, const char *clname,
155 1.1 thorpej struct ifinfo *ifinfo, struct classinfo *parent,
156 1.1 thorpej void *class_private);
157 1.1 thorpej int qop_modify_class(struct classinfo *clinfo, void *arg);
158 1.1 thorpej int qop_delete_class(struct classinfo *clinfo);
159 1.1 thorpej
160 1.1 thorpej int qop_add_filter(struct fltrinfo **rp,
161 1.1 thorpej struct classinfo *clinfo,
162 1.1 thorpej const char *flname,
163 1.1 thorpej const struct flow_filter *fltr,
164 1.1 thorpej struct fltrinfo **conflict);
165 1.1 thorpej int qop_delete_filter(struct fltrinfo *fltr);
166 1.1 thorpej
167 1.1 thorpej int is_q_enabled(const char *ifname);
168 1.1 thorpej struct ifinfo *ifname2ifinfo(const char *ifname);
169 1.1 thorpej struct ifinfo *input_ifname2ifinfo(const char *ifname);
170 1.1 thorpej struct classinfo *clname2clinfo(const struct ifinfo *ifinfo,
171 1.1 thorpej const char *clname);
172 1.1 thorpej struct classinfo * clhandle2clinfo(struct ifinfo *ifinfo, u_long handle);
173 1.1 thorpej struct fltrinfo *flname2flinfo(const struct classinfo *clinfo,
174 1.1 thorpej const char *flname);
175 1.1 thorpej struct fltrinfo *flhandle2fltrinfo(struct ifinfo *ifinfo, u_long handle);
176 1.1 thorpej void print_filter(const struct flow_filter *filt);
177 1.1 thorpej const char *qoperror(int qoperrno);
178 1.1 thorpej u_int get_ifindex(const char *ifname);
179 1.1 thorpej struct classinfo *get_rootclass(struct ifinfo *ifinfo);
180 1.1 thorpej struct classinfo *get_nextclass(struct classinfo *clinfo);
181 1.1 thorpej u_long atobps(const char *s);
182 1.1 thorpej u_long atobytes(const char *s);
183 1.1 thorpej int qop_red_set_defaults(int th_min, int th_max, int inv_pmax);
184 1.1 thorpej int qop_rio_set_defaults(struct redparams *params);
185 1.1 thorpej int open_module(const char *devname, int flags);
186 1.1 thorpej int client_input(FILE *fp);
187 1.1 thorpej
188 1.1 thorpej /* misc system errors */
189 1.1 thorpej #define QOPERR_OK 0 /* no error */
190 1.1 thorpej #define QOPERR_SYSCALL 1 /* syscall err; see errno */
191 1.1 thorpej #define QOPERR_NOMEM 2 /* not enough memory */
192 1.1 thorpej #define QOPERR_INVAL 3 /* invalid parameter */
193 1.1 thorpej #define QOPERR_RANGE 4 /* out of range */
194 1.1 thorpej #define QOPERR_BADIF 5 /* bad interface name */
195 1.1 thorpej #define QOPERR_BADCLASS 6 /* bad class name */
196 1.1 thorpej #define QOPERR_BADFILTER 7 /* bad filter name */
197 1.1 thorpej
198 1.1 thorpej /* class errors */
199 1.1 thorpej #define QOPERR_CLASS 8 /* class failure */
200 1.1 thorpej #define QOPERR_CLASS_INVAL 9 /* bad class value */
201 1.1 thorpej #define QOPERR_CLASS_PERM 10 /* class operation not permitted */
202 1.1 thorpej
203 1.1 thorpej /* filter errors */
204 1.1 thorpej #define QOPERR_FILTER 11 /* filter failure */
205 1.1 thorpej #define QOPERR_FILTER_INVAL 12 /* bad filter value */
206 1.1 thorpej #define QOPERR_FILTER_SHADOW 13 /* shadows an existing filter */
207 1.1 thorpej
208 1.1 thorpej /* addmission errors */
209 1.1 thorpej #define QOPERR_ADMISSION 14 /* admission control failure */
210 1.1 thorpej #define QOPERR_ADMISSION_NOBW 15 /* insufficient bandwidth */
211 1.1 thorpej #define QOPERR_ADMISSION_DELAY 16 /* cannot meet delay bound req */
212 1.1 thorpej #define QOPERR_ADMISSION_NOSVC 17 /* no service available */
213 1.1 thorpej
214 1.1 thorpej /* policy errors */
215 1.1 thorpej #define QOPERR_POLICY 18 /* policy control failure */
216 1.1 thorpej
217 1.1 thorpej #define QOPERR_MAX 18
218 1.1 thorpej
219 1.1 thorpej extern int filter_dontwarn;/* supress warning for the current filter */
220 1.5 xtraeme extern const char *altqconfigfile; /* config file name */
221 1.1 thorpej extern const char *qop_errlist[]; /* error string list */
222 1.1 thorpej extern struct qdisc_ops nop_qdisc;
223 1.1 thorpej extern char *cur_ifname(void);
224 1.1 thorpej extern struct qdisc_parser qdisc_parser[];
225 1.1 thorpej
226 1.1 thorpej #ifndef RSVPD
227 1.1 thorpej /* rename LOG() to log_write() */
228 1.1 thorpej #define LOG log_write
229 1.1 thorpej void log_write(int, int, const char *, ...);
230 1.1 thorpej
231 1.1 thorpej /* stuff defined in rsvp headers */
232 1.1 thorpej #define IsDebug(type) (l_debug >= LOG_DEBUG && (m_debug & (type)))
233 1.1 thorpej #define DEBUG_ALTQ 0x40
234 1.1 thorpej
235 1.1 thorpej #define ntoh16(x) ((u_int16_t)ntohs((u_int16_t)(x)))
236 1.1 thorpej #define ntoh32(x) ((u_int32_t)ntohl((u_int32_t)(x)))
237 1.1 thorpej #define hton16(x) ((u_int16_t)htons((u_int16_t)(x)))
238 1.1 thorpej #define hton32(x) ((u_int32_t)htonl((u_int32_t)(x)))
239 1.1 thorpej
240 1.1 thorpej extern int if_num; /* number of phyints */
241 1.1 thorpej extern int m_debug; /* Debug output control bits */
242 1.1 thorpej extern int l_debug; /* Logging severity level */
243 1.1 thorpej extern int line_no; /* current line number in config file */
244 1.1 thorpej extern int daemonize; /* log_write uses stderr if daemonize is 0 */
245 1.1 thorpej
246 1.1 thorpej #endif /* !RSVPD */
247 1.1 thorpej
248 1.1 thorpej #ifdef INET6
249 1.6 christos static inline uint32_t IN6ADDR32_GET(const struct in6_addr *a, size_t i) {
250 1.6 christos uint32_t ret;
251 1.6 christos memcpy(&ret, &(a)->s6_addr[i << 2], sizeof(ret));
252 1.6 christos return ret;
253 1.6 christos }
254 1.6 christos static inline void IN6ADDR32_SET(struct in6_addr *a, size_t i, uint32_t val) {
255 1.6 christos memcpy(&(a)->s6_addr[i << 2], &val, sizeof(val));
256 1.6 christos }
257 1.1 thorpej #endif
258 1.1 thorpej
259 1.1 thorpej #endif /* _ALTQ_QOP_H_ */
260