1 #ifndef _IP_COMMON_H_
2 #define _IP_COMMON_H_
3
4 #include <stdbool.h>
5
6 #include "json_print.h"
7
8 struct link_filter {
9 int ifindex;
10 int family;
11 int oneline;
12 int showqueue;
13 inet_prefix pfx;
14 int scope, scopemask;
15 int flags, flagmask;
16 int up;
17 char *label;
18 int flushed;
19 char *flushb;
20 int flushp;
21 int flushe;
22 int group;
23 int master;
24 char *kind;
25 char *slave_kind;
26 };
27
28 int get_operstate(const char *name);
29 int print_linkinfo(const struct sockaddr_nl *who,
30 struct nlmsghdr *n, void *arg);
31 int print_linkinfo_brief(const struct sockaddr_nl *who,
32 struct nlmsghdr *n, void *arg,
33 struct link_filter *filter);
34 int print_addrinfo(const struct sockaddr_nl *who,
35 struct nlmsghdr *n, void *arg);
36 int print_addrlabel(const struct sockaddr_nl *who,
37 struct nlmsghdr *n, void *arg);
38 int print_neigh(const struct sockaddr_nl *who,
39 struct nlmsghdr *n, void *arg);
40 int ipaddr_list_link(int argc, char **argv);
41 void ipaddr_get_vf_rate(int, int *, int *, int);
42 void iplink_usage(void) __attribute__((noreturn));
43
44 void iproute_reset_filter(int ifindex);
45 void ipmroute_reset_filter(int ifindex);
46 void ipaddr_reset_filter(int oneline, int ifindex);
47 void ipneigh_reset_filter(int ifindex);
48 void ipnetconf_reset_filter(int ifindex);
49
50 int print_route(const struct sockaddr_nl *who,
51 struct nlmsghdr *n, void *arg);
52 int print_mroute(const struct sockaddr_nl *who,
53 struct nlmsghdr *n, void *arg);
54 int print_prefix(const struct sockaddr_nl *who,
55 struct nlmsghdr *n, void *arg);
56 int print_rule(const struct sockaddr_nl *who,
57 struct nlmsghdr *n, void *arg);
58 int print_netconf(const struct sockaddr_nl *who,
59 struct rtnl_ctrl_data *ctrl,
60 struct nlmsghdr *n, void *arg);
61 void netns_map_init(void);
62 void netns_nsid_socket_init(void);
63 int print_nsid(const struct sockaddr_nl *who,
64 struct nlmsghdr *n, void *arg);
65 int do_ipaddr(int argc, char **argv);
66 int do_ipaddrlabel(int argc, char **argv);
67 int do_iproute(int argc, char **argv);
68 int do_iprule(int argc, char **argv);
69 int do_ipneigh(int argc, char **argv);
70 int do_ipntable(int argc, char **argv);
71 int do_iptunnel(int argc, char **argv);
72 int do_ip6tunnel(int argc, char **argv);
73 int do_iptuntap(int argc, char **argv);
74 int do_iplink(int argc, char **argv);
75 int do_ipmacsec(int argc, char **argv);
76 int do_ipmonitor(int argc, char **argv);
77 int do_multiaddr(int argc, char **argv);
78 int do_multiroute(int argc, char **argv);
79 int do_multirule(int argc, char **argv);
80 int do_netns(int argc, char **argv);
81 int do_xfrm(int argc, char **argv);
82 int do_ipl2tp(int argc, char **argv);
83 int do_ipfou(int argc, char **argv);
84 extern int do_ipila(int argc, char **argv);
85 int do_tcp_metrics(int argc, char **argv);
86 int do_ipnetconf(int argc, char **argv);
87 int do_iptoken(int argc, char **argv);
88 int do_ipvrf(int argc, char **argv);
89 void vrf_reset(void);
90 int netns_identify_pid(const char *pidstr, char *name, int len);
91 int do_seg6(int argc, char **argv);
92
93 int iplink_get(unsigned int flags, char *name, __u32 filt_mask);
94 int iplink_ifla_xstats(int argc, char **argv);
95
96 int ip_linkaddr_list(int family, req_filter_fn_t filter_fn,
97 struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo);
98 void free_nlmsg_chain(struct nlmsg_chain *info);
99
rtm_get_table(struct rtmsg * r,struct rtattr ** tb)100 static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
101 {
102 __u32 table = r->rtm_table;
103
104 if (tb[RTA_TABLE])
105 table = rta_getattr_u32(tb[RTA_TABLE]);
106 return table;
107 }
108
109 extern struct rtnl_handle rth;
110
111 struct link_util {
112 struct link_util *next;
113 const char *id;
114 int maxattr;
115 int (*parse_opt)(struct link_util *, int, char **,
116 struct nlmsghdr *);
117 void (*print_opt)(struct link_util *, FILE *,
118 struct rtattr *[]);
119 void (*print_xstats)(struct link_util *, FILE *,
120 struct rtattr *);
121 void (*print_help)(struct link_util *, int, char **,
122 FILE *);
123 int (*parse_ifla_xstats)(struct link_util *,
124 int, char **);
125 int (*print_ifla_xstats)(const struct sockaddr_nl *,
126 struct nlmsghdr *, void *);
127 };
128
129 struct link_util *get_link_kind(const char *kind);
130
131 void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
132 int bridge_parse_xstats(struct link_util *lu, int argc, char **argv);
133 int bridge_print_xstats(const struct sockaddr_nl *who,
134 struct nlmsghdr *n, void *arg);
135
136 __u32 ipvrf_get_table(const char *name);
137 int name_is_vrf(const char *name);
138
139 #ifndef INFINITY_LIFE_TIME
140 #define INFINITY_LIFE_TIME 0xFFFFFFFFU
141 #endif
142
143 #ifndef LABEL_MAX_MASK
144 #define LABEL_MAX_MASK 0xFFFFFU
145 #endif
146
147 void print_num(FILE *fp, unsigned int width, uint64_t count);
148
149 #endif /* _IP_COMMON_H_ */
150