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