Home | History | Annotate | Download | only in tc
      1 #ifndef _TC_UTIL_H_
      2 #define _TC_UTIL_H_ 1
      3 
      4 #define MAX_MSG 16384
      5 #include <linux/pkt_sched.h>
      6 #include <linux/pkt_cls.h>
      7 #include <linux/gen_stats.h>
      8 #include "tc_core.h"
      9 
     10 #ifndef MIN
     11 #define MIN(x,y)        ((x)<(y)?(x):(y))
     12 #endif
     13 
     14 /* This is the deprecated multiqueue interface */
     15 #ifndef TCA_PRIO_MAX
     16 enum
     17 {
     18 	TCA_PRIO_UNSPEC,
     19 	TCA_PRIO_MQ,
     20 	__TCA_PRIO_MAX
     21 };
     22 
     23 #define TCA_PRIO_MAX    (__TCA_PRIO_MAX - 1)
     24 #endif
     25 
     26 struct qdisc_util
     27 {
     28 	struct  qdisc_util *next;
     29 	const char *id;
     30 	int	(*parse_qopt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n);
     31 	int	(*print_qopt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
     32 	int 	(*print_xstats)(struct qdisc_util *qu, FILE *f, struct rtattr *xstats);
     33 
     34 	int	(*parse_copt)(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n);
     35 	int	(*print_copt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
     36 };
     37 
     38 extern __u16 f_proto;
     39 struct filter_util
     40 {
     41 	struct filter_util *next;
     42 	char	id[16];
     43 	int	(*parse_fopt)(struct filter_util *qu, char *fhandle, int argc,
     44 			      char **argv, struct nlmsghdr *n);
     45 	int	(*print_fopt)(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 fhandle);
     46 };
     47 
     48 struct action_util
     49 {
     50 	struct  action_util *next;
     51 	char    id[16];
     52 	int     (*parse_aopt)(struct action_util *a, int *argc, char ***argv,
     53 			      int code, struct nlmsghdr *n);
     54 	int     (*print_aopt)(struct action_util *au, FILE *f, struct rtattr *opt);
     55 	int     (*print_xstats)(struct action_util *au, FILE *f, struct rtattr *xstats);
     56 };
     57 
     58 extern const char *get_tc_lib(void);
     59 
     60 extern struct qdisc_util *get_qdisc_kind(const char *str);
     61 extern struct filter_util *get_filter_kind(const char *str);
     62 
     63 extern int get_qdisc_handle(__u32 *h, const char *str);
     64 extern int get_rate(unsigned *rate, const char *str);
     65 extern int get_percent(unsigned *percent, const char *str);
     66 extern int get_size(unsigned *size, const char *str);
     67 extern int get_size_and_cell(unsigned *size, int *cell_log, char *str);
     68 extern int get_time(unsigned *time, const char *str);
     69 extern int get_linklayer(unsigned *val, const char *arg);
     70 
     71 extern void print_rate(char *buf, int len, __u32 rate);
     72 extern void print_size(char *buf, int len, __u32 size);
     73 extern void print_percent(char *buf, int len, __u32 percent);
     74 extern void print_qdisc_handle(char *buf, int len, __u32 h);
     75 extern void print_time(char *buf, int len, __u32 time);
     76 extern void print_linklayer(char *buf, int len, unsigned linklayer);
     77 extern char * sprint_rate(__u32 rate, char *buf);
     78 extern char * sprint_size(__u32 size, char *buf);
     79 extern char * sprint_qdisc_handle(__u32 h, char *buf);
     80 extern char * sprint_tc_classid(__u32 h, char *buf);
     81 extern char * sprint_time(__u32 time, char *buf);
     82 extern char * sprint_ticks(__u32 ticks, char *buf);
     83 extern char * sprint_percent(__u32 percent, char *buf);
     84 extern char * sprint_linklayer(unsigned linklayer, char *buf);
     85 
     86 extern void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtattr **xstats);
     87 extern void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats);
     88 
     89 extern int get_tc_classid(__u32 *h, const char *str);
     90 extern int print_tc_classid(char *buf, int len, __u32 h);
     91 extern char * sprint_tc_classid(__u32 h, char *buf);
     92 
     93 extern int tc_print_police(FILE *f, struct rtattr *tb);
     94 extern int parse_police(int *, char ***, int, struct nlmsghdr *);
     95 
     96 extern char *action_n2a(int action, char *buf, int len);
     97 extern int  action_a2n(char *arg, int *result);
     98 extern int  act_parse_police(struct action_util *a,int *, char ***, int, struct nlmsghdr *);
     99 extern int  print_police(struct action_util *a, FILE *f,
    100 			 struct rtattr *tb);
    101 extern int  police_print_xstats(struct action_util *a,FILE *f,
    102 				struct rtattr *tb);
    103 extern int  tc_print_action(FILE *f, const struct rtattr *tb);
    104 extern int  tc_print_ipt(FILE *f, const struct rtattr *tb);
    105 extern int  parse_action(int *, char ***, int, struct nlmsghdr *);
    106 extern void print_tm(FILE *f, const struct tcf_t *tm);
    107 
    108 #endif
    109