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