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