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