]>
Commit | Line | Data |
---|---|---|
6054c1eb | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
aba5acdf SH |
2 | #ifndef _TC_UTIL_H_ |
3 | #define _TC_UTIL_H_ 1 | |
4 | ||
2373fde9 | 5 | #define MAX_MSG 16384 |
d421bb4e | 6 | #include <limits.h> |
b317557f SH |
7 | #include <linux/if.h> |
8 | ||
aba5acdf SH |
9 | #include <linux/pkt_sched.h> |
10 | #include <linux/pkt_cls.h> | |
e5879dc6 | 11 | #include <linux/gen_stats.h> |
b317557f | 12 | |
aba5acdf | 13 | #include "tc_core.h" |
c91d262f | 14 | #include "json_print.h" |
aba5acdf | 15 | |
5a67f8f9 SH |
16 | /* This is the deprecated multiqueue interface */ |
17 | #ifndef TCA_PRIO_MAX | |
18 | enum | |
19 | { | |
20 | TCA_PRIO_UNSPEC, | |
21 | TCA_PRIO_MQ, | |
22 | __TCA_PRIO_MAX | |
23 | }; | |
24 | ||
25 | #define TCA_PRIO_MAX (__TCA_PRIO_MAX - 1) | |
26 | #endif | |
27 | ||
b317557f SH |
28 | #define FILTER_NAMESZ 16 |
29 | ||
4bd62446 | 30 | struct qdisc_util { |
2373fde9 | 31 | struct qdisc_util *next; |
6dc9f016 | 32 | const char *id; |
9ffc80b1 | 33 | int (*parse_qopt)(struct qdisc_util *qu, int argc, |
927e3cfb | 34 | char **argv, struct nlmsghdr *n, const char *dev); |
9ffc80b1 PS |
35 | int (*print_qopt)(struct qdisc_util *qu, |
36 | FILE *f, struct rtattr *opt); | |
37 | int (*print_xstats)(struct qdisc_util *qu, | |
38 | FILE *f, struct rtattr *xstats); | |
39 | ||
40 | int (*parse_copt)(struct qdisc_util *qu, int argc, | |
927e3cfb | 41 | char **argv, struct nlmsghdr *n, const char *dev); |
9ffc80b1 | 42 | int (*print_copt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt); |
aba5acdf SH |
43 | }; |
44 | ||
eefcbc72 | 45 | extern __u16 f_proto; |
4bd62446 | 46 | struct filter_util { |
aba5acdf | 47 | struct filter_util *next; |
b317557f | 48 | char id[FILTER_NAMESZ]; |
9ffc80b1 PS |
49 | int (*parse_fopt)(struct filter_util *qu, char *fhandle, |
50 | int argc, char **argv, struct nlmsghdr *n); | |
51 | int (*print_fopt)(struct filter_util *qu, | |
52 | FILE *f, struct rtattr *opt, __u32 fhandle); | |
aba5acdf SH |
53 | }; |
54 | ||
4bd62446 | 55 | struct action_util { |
9ffc80b1 | 56 | struct action_util *next; |
b317557f | 57 | char id[FILTER_NAMESZ]; |
9ffc80b1 PS |
58 | int (*parse_aopt)(struct action_util *a, int *argc, |
59 | char ***argv, int code, struct nlmsghdr *n); | |
60 | int (*print_aopt)(struct action_util *au, FILE *f, struct rtattr *opt); | |
61 | int (*print_xstats)(struct action_util *au, | |
62 | FILE *f, struct rtattr *xstats); | |
2373fde9 | 63 | }; |
aba5acdf | 64 | |
4bd62446 | 65 | struct exec_util { |
9ffc80b1 | 66 | struct exec_util *next; |
b317557f | 67 | char id[FILTER_NAMESZ]; |
9ffc80b1 | 68 | int (*parse_eopt)(struct exec_util *eu, int argc, char **argv); |
4bd62446 DB |
69 | }; |
70 | ||
9ffc80b1 PS |
71 | const char *get_tc_lib(void); |
72 | ||
73 | struct qdisc_util *get_qdisc_kind(const char *str); | |
74 | struct filter_util *get_filter_kind(const char *str); | |
75 | ||
927e3cfb | 76 | int parse_percent_rate(char *rate, const char *str, const char *dev); |
9ffc80b1 PS |
77 | int get_qdisc_handle(__u32 *h, const char *str); |
78 | int get_rate(unsigned int *rate, const char *str); | |
927e3cfb | 79 | int get_percent_rate(unsigned int *rate, const char *str, const char *dev); |
9ffc80b1 | 80 | int get_rate64(__u64 *rate, const char *str); |
927e3cfb | 81 | int get_percent_rate64(__u64 *rate, const char *str, const char *dev); |
9ffc80b1 PS |
82 | int get_size(unsigned int *size, const char *str); |
83 | int get_size_and_cell(unsigned int *size, int *cell_log, char *str); | |
84 | int get_time(unsigned int *time, const char *str); | |
85 | int get_linklayer(unsigned int *val, const char *arg); | |
86 | ||
87 | void print_rate(char *buf, int len, __u64 rate); | |
88 | void print_size(char *buf, int len, __u32 size); | |
89 | void print_qdisc_handle(char *buf, int len, __u32 h); | |
90 | void print_time(char *buf, int len, __u32 time); | |
91 | void print_linklayer(char *buf, int len, unsigned int linklayer); | |
2d165c08 | 92 | void print_devname(enum output_type type, int ifindex); |
9ffc80b1 PS |
93 | |
94 | char *sprint_rate(__u64 rate, char *buf); | |
95 | char *sprint_size(__u32 size, char *buf); | |
96 | char *sprint_qdisc_handle(__u32 h, char *buf); | |
97 | char *sprint_tc_classid(__u32 h, char *buf); | |
98 | char *sprint_time(__u32 time, char *buf); | |
99 | char *sprint_ticks(__u32 ticks, char *buf); | |
100 | char *sprint_linklayer(unsigned int linklayer, char *buf); | |
101 | ||
102 | void print_tcstats_attr(FILE *fp, struct rtattr *tb[], | |
103 | char *prefix, struct rtattr **xstats); | |
104 | void print_tcstats2_attr(FILE *fp, struct rtattr *rta, | |
105 | char *prefix, struct rtattr **xstats); | |
106 | ||
107 | int get_tc_classid(__u32 *h, const char *str); | |
108 | int print_tc_classid(char *buf, int len, __u32 h); | |
109 | char *sprint_tc_classid(__u32 h, char *buf); | |
110 | ||
111 | int tc_print_police(FILE *f, struct rtattr *tb); | |
112 | int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n); | |
113 | ||
e67aba55 JP |
114 | int parse_action_control(int *argc_p, char ***argv_p, |
115 | int *result_p, bool allow_num); | |
116 | void parse_action_control_dflt(int *argc_p, char ***argv_p, | |
117 | int *result_p, bool allow_num, | |
118 | int default_result); | |
119 | int parse_action_control_slash(int *argc_p, char ***argv_p, | |
120 | int *result1_p, int *result2_p, bool allow_num); | |
121 | void print_action_control(FILE *f, const char *prefix, | |
122 | int action, const char *suffix); | |
9ffc80b1 PS |
123 | int act_parse_police(struct action_util *a, int *argc_p, |
124 | char ***argv_p, int tca_id, struct nlmsghdr *n); | |
125 | int print_police(struct action_util *a, FILE *f, struct rtattr *tb); | |
126 | int police_print_xstats(struct action_util *a, FILE *f, struct rtattr *tb); | |
9e713525 | 127 | int tc_print_action(FILE *f, const struct rtattr *tb, unsigned short tot_acts); |
9ffc80b1 PS |
128 | int tc_print_ipt(FILE *f, const struct rtattr *tb); |
129 | int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n); | |
130 | void print_tm(FILE *f, const struct tcf_t *tm); | |
131 | int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt); | |
132 | ||
133 | int cls_names_init(char *path); | |
134 | void cls_names_uninit(void); | |
4612d04d | 135 | |
6f7df6b2 PS |
136 | int action_a2n(char *arg, int *result, bool allow_num); |
137 | ||
d0bcedd5 JP |
138 | bool tc_qdisc_block_exists(__u32 block_index); |
139 | ||
aba5acdf | 140 | #endif |