]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/ip_common.h
Merge branch 'master' into net-next
[mirror_iproute2.git] / ip / ip_common.h
1 struct link_filter {
2 int ifindex;
3 int family;
4 int oneline;
5 int showqueue;
6 inet_prefix pfx;
7 int scope, scopemask;
8 int flags, flagmask;
9 int up;
10 char *label;
11 int flushed;
12 char *flushb;
13 int flushp;
14 int flushe;
15 int group;
16 int master;
17 char *kind;
18 char *slave_kind;
19 };
20
21 int get_operstate(const char *name);
22 int print_linkinfo(const struct sockaddr_nl *who,
23 struct nlmsghdr *n, void *arg);
24 int print_linkinfo_brief(const struct sockaddr_nl *who,
25 struct nlmsghdr *n, void *arg,
26 struct link_filter *filter);
27 int print_addrinfo(const struct sockaddr_nl *who,
28 struct nlmsghdr *n, void *arg);
29 int print_addrlabel(const struct sockaddr_nl *who,
30 struct nlmsghdr *n, void *arg);
31 int print_neigh(const struct sockaddr_nl *who,
32 struct nlmsghdr *n, void *arg);
33 int ipaddr_list_link(int argc, char **argv);
34 void ipaddr_get_vf_rate(int, int *, int *, int);
35 void iplink_usage(void) __attribute__((noreturn));
36
37 void iproute_reset_filter(int ifindex);
38 void ipmroute_reset_filter(int ifindex);
39 void ipaddr_reset_filter(int oneline, int ifindex);
40 void ipneigh_reset_filter(int ifindex);
41 void ipnetconf_reset_filter(int ifindex);
42
43 int print_route(const struct sockaddr_nl *who,
44 struct nlmsghdr *n, void *arg);
45 int print_mroute(const struct sockaddr_nl *who,
46 struct nlmsghdr *n, void *arg);
47 int print_prefix(const struct sockaddr_nl *who,
48 struct nlmsghdr *n, void *arg);
49 int print_rule(const struct sockaddr_nl *who,
50 struct nlmsghdr *n, void *arg);
51 int print_netconf(const struct sockaddr_nl *who,
52 struct rtnl_ctrl_data *ctrl,
53 struct nlmsghdr *n, void *arg);
54 void netns_map_init(void);
55 void netns_nsid_socket_init(void);
56 int print_nsid(const struct sockaddr_nl *who,
57 struct nlmsghdr *n, void *arg);
58 int do_ipaddr(int argc, char **argv);
59 int do_ipaddrlabel(int argc, char **argv);
60 int do_iproute(int argc, char **argv);
61 int do_iprule(int argc, char **argv);
62 int do_ipneigh(int argc, char **argv);
63 int do_ipntable(int argc, char **argv);
64 int do_iptunnel(int argc, char **argv);
65 int do_ip6tunnel(int argc, char **argv);
66 int do_iptuntap(int argc, char **argv);
67 int do_iplink(int argc, char **argv);
68 int do_ipmacsec(int argc, char **argv);
69 int do_ipmonitor(int argc, char **argv);
70 int do_multiaddr(int argc, char **argv);
71 int do_multiroute(int argc, char **argv);
72 int do_multirule(int argc, char **argv);
73 int do_netns(int argc, char **argv);
74 int do_xfrm(int argc, char **argv);
75 int do_ipl2tp(int argc, char **argv);
76 int do_ipfou(int argc, char **argv);
77 extern int do_ipila(int argc, char **argv);
78 int do_tcp_metrics(int argc, char **argv);
79 int do_ipnetconf(int argc, char **argv);
80 int do_iptoken(int argc, char **argv);
81 int do_ipvrf(int argc, char **argv);
82 void vrf_reset(void);
83 int netns_identify_pid(const char *pidstr, char *name, int len);
84 int do_seg6(int argc, char **argv);
85
86 int iplink_get(unsigned int flags, char *name, __u32 filt_mask);
87 int iplink_ifla_xstats(int argc, char **argv);
88
89 int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
90 struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo);
91 void free_nlmsg_chain(struct nlmsg_chain *info);
92
93 static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
94 {
95 __u32 table = r->rtm_table;
96
97 if (tb[RTA_TABLE])
98 table = rta_getattr_u32(tb[RTA_TABLE]);
99 return table;
100 }
101
102 extern struct rtnl_handle rth;
103
104 #include <stdbool.h>
105
106 struct link_util {
107 struct link_util *next;
108 const char *id;
109 int maxattr;
110 int (*parse_opt)(struct link_util *, int, char **,
111 struct nlmsghdr *);
112 void (*print_opt)(struct link_util *, FILE *,
113 struct rtattr *[]);
114 void (*print_xstats)(struct link_util *, FILE *,
115 struct rtattr *);
116 void (*print_help)(struct link_util *, int, char **,
117 FILE *);
118 int (*parse_ifla_xstats)(struct link_util *,
119 int, char **);
120 int (*print_ifla_xstats)(const struct sockaddr_nl *,
121 struct nlmsghdr *, void *);
122 };
123
124 struct link_util *get_link_kind(const char *kind);
125
126 void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
127 int bridge_parse_xstats(struct link_util *lu, int argc, char **argv);
128 int bridge_print_xstats(const struct sockaddr_nl *who,
129 struct nlmsghdr *n, void *arg);
130
131 __u32 ipvrf_get_table(const char *name);
132 int name_is_vrf(const char *name);
133
134 #ifndef INFINITY_LIFE_TIME
135 #define INFINITY_LIFE_TIME 0xFFFFFFFFU
136 #endif
137
138 #ifndef LABEL_MAX_MASK
139 #define LABEL_MAX_MASK 0xFFFFFU
140 #endif
141
142 void print_num(FILE *fp, unsigned int width, uint64_t count);
143
144 #include "json_writer.h"
145
146 json_writer_t *get_json_writer(void);
147 /*
148 * use:
149 * - PRINT_ANY for context based output
150 * - PRINT_FP for non json specific output
151 * - PRINT_JSON for json specific output
152 */
153 enum output_type {
154 PRINT_FP = 1,
155 PRINT_JSON = 2,
156 PRINT_ANY = 4,
157 };
158
159 void new_json_obj(int json, FILE *fp);
160 void delete_json_obj(void);
161
162 bool is_json_context(void);
163
164 void set_current_fp(FILE *fp);
165
166 void fflush_fp(void);
167
168 void open_json_object(const char *str);
169 void close_json_object(void);
170 void open_json_array(enum output_type type, const char *delim);
171 void close_json_array(enum output_type type, const char *delim);
172
173 #include "color.h"
174
175 #define _PRINT_FUNC(type_name, type) \
176 void print_color_##type_name(enum output_type t, \
177 enum color_attr color, \
178 const char *key, \
179 const char *fmt, \
180 type value); \
181 \
182 static inline void print_##type_name(enum output_type t, \
183 const char *key, \
184 const char *fmt, \
185 type value) \
186 { \
187 print_color_##type_name(t, -1, key, fmt, value); \
188 }
189 _PRINT_FUNC(int, int);
190 _PRINT_FUNC(bool, bool);
191 _PRINT_FUNC(null, const char*);
192 _PRINT_FUNC(string, const char*);
193 _PRINT_FUNC(uint, uint64_t);
194 _PRINT_FUNC(hu, unsigned short);
195 _PRINT_FUNC(hex, unsigned int);
196 _PRINT_FUNC(0xhex, unsigned int);
197 _PRINT_FUNC(lluint, unsigned long long int);
198 #undef _PRINT_FUNC