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