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