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