Fix build break in 64bit architectures
[platform/upstream/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 #include "json_print.h"
15
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
28 #define FILTER_NAMESZ   16
29
30 struct qdisc_util {
31         struct  qdisc_util *next;
32         const char *id;
33         int (*parse_qopt)(struct qdisc_util *qu, int argc,
34                           char **argv, struct nlmsghdr *n, const char *dev);
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,
41                           char **argv, struct nlmsghdr *n, const char *dev);
42         int (*print_copt)(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
43 };
44
45 extern __u16 f_proto;
46 struct filter_util {
47         struct filter_util *next;
48         char id[FILTER_NAMESZ];
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);
53 };
54
55 struct action_util {
56         struct action_util *next;
57         char id[FILTER_NAMESZ];
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);
63 };
64
65 struct exec_util {
66         struct exec_util *next;
67         char id[FILTER_NAMESZ];
68         int (*parse_eopt)(struct exec_util *eu, int argc, char **argv);
69 };
70
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
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_linklayer(unsigned int *val, const char *arg);
84
85 void print_rate(char *buf, int len, __u64 rate);
86 void print_devname(enum output_type type, int ifindex);
87
88 char *sprint_rate(__u64 rate, char *buf);
89 char *sprint_size(__u32 size, char *buf);
90 char *sprint_tc_classid(__u32 h, char *buf);
91 char *sprint_ticks(__u32 ticks, char *buf);
92 char *sprint_linklayer(unsigned int linklayer, char *buf);
93
94 void print_tcstats_attr(FILE *fp, struct rtattr *tb[],
95                         char *prefix, struct rtattr **xstats);
96 void print_tcstats2_attr(FILE *fp, struct rtattr *rta,
97                          char *prefix, struct rtattr **xstats);
98
99 int get_tc_classid(__u32 *h, const char *str);
100 int print_tc_classid(char *buf, int len, __u32 h);
101 char *sprint_tc_classid(__u32 h, char *buf);
102
103 int tc_print_police(FILE *f, struct rtattr *tb);
104 int parse_percent(double *val, const char *str);
105 int parse_police(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
106
107 int parse_action_control(int *argc_p, char ***argv_p,
108                          int *result_p, bool allow_num);
109 void parse_action_control_dflt(int *argc_p, char ***argv_p,
110                                int *result_p, bool allow_num,
111                                int default_result);
112 int parse_action_control_slash(int *argc_p, char ***argv_p,
113                                int *result1_p, int *result2_p, bool allow_num);
114 void print_action_control(FILE *f, const char *prefix,
115                           int action, const char *suffix);
116 int police_print_xstats(struct action_util *a, FILE *f, struct rtattr *tb);
117 int tc_print_action(FILE *f, const struct rtattr *tb, unsigned short tot_acts);
118 int tc_print_ipt(FILE *f, const struct rtattr *tb);
119 int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n);
120 void print_tm(FILE *f, const struct tcf_t *tm);
121 int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
122
123 int cls_names_init(char *path);
124 void cls_names_uninit(void);
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 #endif