altq_qop.h revision 1.1 1 1.1 thorpej /* $KAME: altq_qop.h,v 1.4 2000/10/18 09:15:18 kjc Exp $ */
2 1.1 thorpej /*
3 1.1 thorpej * Copyright (C) 1999-2000
4 1.1 thorpej * Sony Computer Science Laboratories, Inc. All rights reserved.
5 1.1 thorpej *
6 1.1 thorpej * Redistribution and use in source and binary forms, with or without
7 1.1 thorpej * modification, are permitted provided that the following conditions
8 1.1 thorpej * are met:
9 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
10 1.1 thorpej * notice, this list of conditions and the following disclaimer.
11 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
13 1.1 thorpej * documentation and/or other materials provided with the distribution.
14 1.1 thorpej *
15 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
16 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
19 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 thorpej * SUCH DAMAGE.
26 1.1 thorpej */
27 1.1 thorpej #ifndef _ALTQ_QOP_H_
28 1.1 thorpej #define _ALTQ_QOP_H_
29 1.1 thorpej
30 1.1 thorpej #include <sys/queue.h>
31 1.1 thorpej #include <altq/altq.h>
32 1.1 thorpej #include <altq/altq_red.h>
33 1.1 thorpej
34 1.1 thorpej struct ifinfo;
35 1.1 thorpej struct classinfo;
36 1.1 thorpej struct fltrinfo;
37 1.1 thorpej
38 1.1 thorpej /* queueing discipline specific command parsers */
39 1.1 thorpej struct qdisc_parser {
40 1.1 thorpej char *qname;
41 1.1 thorpej int (*interface_parser)(const char *ifname, int argc, char **argv);
42 1.1 thorpej int (*class_parser)(const char *ifname, const char *clname,
43 1.1 thorpej const char *parent, int argc, char **argv);
44 1.1 thorpej };
45 1.1 thorpej
46 1.1 thorpej /* queueing discipline specific operations */
47 1.1 thorpej struct qdisc_ops {
48 1.1 thorpej int qdisc_type; /* discipline type (e.g., ALTQT_CBQ) */
49 1.1 thorpej char *qname; /* discipline name (e.g., cbq) */
50 1.1 thorpej
51 1.1 thorpej /* interface operations */
52 1.1 thorpej int (*attach)(struct ifinfo *);
53 1.1 thorpej int (*detach)(struct ifinfo *);
54 1.1 thorpej int (*clear)(struct ifinfo *);
55 1.1 thorpej int (*enable)(struct ifinfo *);
56 1.1 thorpej int (*disable)(struct ifinfo *);
57 1.1 thorpej
58 1.1 thorpej /* class operations (optional) */
59 1.1 thorpej int (*add_class)(struct classinfo *);
60 1.1 thorpej int (*modify_class)(struct classinfo *, void *);
61 1.1 thorpej int (*delete_class)(struct classinfo *);
62 1.1 thorpej
63 1.1 thorpej /* filter operations (optional) */
64 1.1 thorpej int (*add_filter)(struct fltrinfo *);
65 1.1 thorpej int (*delete_filter)(struct fltrinfo *);
66 1.1 thorpej };
67 1.1 thorpej
68 1.1 thorpej /*
69 1.1 thorpej * interface info
70 1.1 thorpej */
71 1.1 thorpej struct ifinfo {
72 1.1 thorpej LIST_ENTRY(ifinfo) next; /* next entry on iflist */
73 1.1 thorpej char *ifname; /* interface name */
74 1.1 thorpej u_int bandwidth; /* bandwidth in bps */
75 1.1 thorpej u_int ifmtu; /* mtu of the interface */
76 1.1 thorpej u_int ifindex; /* interface index */
77 1.1 thorpej int enabled; /* hfsc on/off state */
78 1.1 thorpej LIST_HEAD(, classinfo) cllist; /* class list */
79 1.1 thorpej LIST_HEAD(, fltrinfo) fltr_rules; /* filter rule list */
80 1.1 thorpej
81 1.1 thorpej struct classinfo *resv_class; /* special class for rsvp */
82 1.1 thorpej
83 1.1 thorpej /* discipline info */
84 1.1 thorpej struct qdisc_ops *qdisc; /* qdisc system interface */
85 1.1 thorpej void *private; /* discipline specific data */
86 1.1 thorpej int (*enable_hook)(struct ifinfo *);
87 1.1 thorpej int (*delete_hook)(struct ifinfo *);
88 1.1 thorpej };
89 1.1 thorpej
90 1.1 thorpej /*
91 1.1 thorpej * class info
92 1.1 thorpej */
93 1.1 thorpej struct classinfo {
94 1.1 thorpej LIST_ENTRY(classinfo) next; /* next entry on cllist
95 1.1 thorpej of ifinfo */
96 1.1 thorpej u_long handle; /* class handle */
97 1.1 thorpej char *clname; /* class name */
98 1.1 thorpej struct ifinfo *ifinfo; /* back pointer to ifinfo */
99 1.1 thorpej struct classinfo *parent; /* parent class */
100 1.1 thorpej struct classinfo *sibling; /* sibling class */
101 1.1 thorpej struct classinfo *child; /* child class */
102 1.1 thorpej LIST_HEAD(, fltrinfo) fltrlist; /* filters for this class */
103 1.1 thorpej
104 1.1 thorpej void *private; /* discipline specific data */
105 1.1 thorpej int (*delete_hook)(struct classinfo *);
106 1.1 thorpej };
107 1.1 thorpej
108 1.1 thorpej /*
109 1.1 thorpej * filter info
110 1.1 thorpej */
111 1.1 thorpej struct fltrinfo {
112 1.1 thorpej LIST_ENTRY(fltrinfo) next; /* next entry on fltrlist
113 1.1 thorpej of classinfo */
114 1.1 thorpej LIST_ENTRY(fltrinfo) nextrule; /* next entry on fltr_rules
115 1.1 thorpej of ifinfo */
116 1.1 thorpej u_long handle; /* filter handle */
117 1.1 thorpej char *flname; /* filter name, if specified */
118 1.1 thorpej struct flow_filter fltr; /* filter value */
119 1.1 thorpej struct classinfo *clinfo; /* back pointer to classinfo */
120 1.1 thorpej
121 1.1 thorpej /* for consistency check */
122 1.1 thorpej int line_no; /* config file line number */
123 1.1 thorpej int dontwarn; /* supress warning msg */
124 1.1 thorpej };
125 1.1 thorpej
126 1.1 thorpej int DoCommand(char *infile, FILE *infp);
127 1.1 thorpej
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.1 thorpej extern 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 extern int Debug_mode;
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.1 thorpej /* a macro to handle v6 address in 32-bit fields */
251 1.1 thorpej #define IN6ADDR32(a, i) (*(u_int32_t *)(&(a)->s6_addr[(i)<<2]))
252 1.1 thorpej #endif
253 1.1 thorpej
254 1.1 thorpej #endif /* _ALTQ_QOP_H_ */
255