Debian Codegraph @

tc/tc_util.h

raw
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 #include <stdbool.h>
9
10 #include <linux/pkt_sched.h>
11 #include <linux/pkt_cls.h>
12 #include <linux/gen_stats.h>
13
14 #include "tc_core.h"
15 #include "json_print.h"
16
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
29 #define FILTER_NAMESZ 16
30
31 struct qdisc_util {
32 struct qdisc_util *next;
33 const char *id;
34 int (*parse_qopt)(const struct qdisc_util *qu, int argc,
35 char **argv, struct nlmsghdr *n, const char *dev);
36 int (*print_qopt)(const struct qdisc_util *qu,
37 FILE *f, struct rtattr *opt);
38 int (*print_xstats)(const struct qdisc_util *qu,
39 FILE *f, struct rtattr *xstats);
40
41 int (*parse_copt)(const struct qdisc_util *qu, int argc,
42 char **argv, struct nlmsghdr *n, const char *dev);
43 int (*print_copt)(const struct qdisc_util *qu, FILE *f, struct rtattr *opt);
44 int (*has_block)(const struct qdisc_util *qu, struct rtattr *opt,
45 __u32 block_idx, bool *p_has);
46 };
47
48 extern __u16 f_proto;
49 struct filter_util {
50 struct filter_util *next;
51 char id[FILTER_NAMESZ];
52 int (*parse_fopt)(const struct filter_util *qu, char *fhandle,
53 int argc, char **argv, struct nlmsghdr *n);
54 int (*print_fopt)(const struct filter_util *qu,
55 FILE *f, struct rtattr *opt, __u32 fhandle);
56 };
57
58 struct action_util {
59 struct action_util *next;
60 char id[FILTER_NAMESZ];
61 int (*parse_aopt)(const struct action_util *a, int *argc,
62 char ***argv, int code, struct nlmsghdr *n);
63 int (*print_aopt)(const struct action_util *au, FILE *f, struct rtattr *opt);
64 int (*print_xstats)(const struct action_util *au,
65 FILE *f, struct rtattr *xstats);
66 };
67
68 struct exec_util {
69 struct exec_util *next;
70 char id[FILTER_NAMESZ];
71 int (*parse_eopt)(const struct exec_util *eu, int argc, char **argv);
72 };
73
74 const char *get_tc_lib(void);
75
76 const struct qdisc_util *get_qdisc_kind(const char *str);
77 const struct filter_util *get_filter_kind(const char *str);
78
79 int get_qdisc_handle(__u32 *h, const char *str);
80 int get_percent_rate(unsigned int *rate, const char *str, const char *dev);
81 int get_percent_rate64(__u64 *rate, const char *str, const char *dev);
82 int get_size_and_cell(unsigned int *size, int *cell_log, char *str);
83 int get_size64_and_cell(__u64 *size, int *cell_log, char *str);
84 int get_linklayer(unsigned int *val, const char *arg);
85
86 void tc_print_rate(enum output_type t, const char *key, const char *fmt,
87 unsigned long long rate);
88 void print_devname(enum output_type type, int ifindex);
89
90 char *sprint_tc_classid(__u32 h, char *buf);
91 char *sprint_linklayer(unsigned int linklayer, char *buf);
92
93 void print_tcstats_attr(FILE *fp, struct rtattr *tb[],
94 const char *prefix, struct rtattr **xstats);
95 void print_tcstats2_attr(struct rtattr *rta, const 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(struct rtattr *tb);
102 int parse_percent(double *val, const char *str);
103 int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
104
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(const char *prefix, int action, const char *suffix);
113 int police_print_xstats(const struct action_util *a, FILE *f, struct rtattr *tb);
114 int tc_print_action(FILE *f, const struct rtattr *tb, unsigned short tot_acts);
115 int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
116 void print_tm(const struct tcf_t *tm);
117 int prio_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt);
118
119 int cls_names_init(char *path);
120 void cls_names_uninit(void);
121
122 #define CLOCKID_INVALID (-1)
123 int get_clockid(__s32 *val, const char *arg);
124 const char *get_clock_name(clockid_t clockid);
125
126 int action_a2n(char *arg, int *result, bool allow_num);
127
128 bool tc_qdisc_block_exists(__u32 block_index);
129
130 void print_masked_u32(const char *name, struct rtattr *attr,
131 struct rtattr *mask_attr, bool newline);
132 void print_masked_u16(const char *name, struct rtattr *attr,
133 struct rtattr *mask_attr, bool newline);
134 void print_masked_u8(const char *name, struct rtattr *attr,
135 struct rtattr *mask_attr, bool newline);
136 void print_masked_be16(const char *name, struct rtattr *attr,
137 struct rtattr *mask_attr, bool newline);
138
139 void print_ext_msg(struct rtattr **tb);
140 #endif