aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorAndrey Ignatov <rdna@fb.com>2018-10-03 18:26:39 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-10-04 10:04:16 -0400
commitaae57780107d92de2463e605cb054656ebd233d1 (patch)
treebdc8e03b94f862740ca6b488accd61dd4e55c95a /tools/lib/bpf
parent434fe9d4b4bfa8becb0959ef32b9b9fa628ef6fe (diff)
libbpf: Consistent prefixes for interfaces in libbpf.h.
libbpf is used more and more outside kernel tree. That means the library should follow good practices in library design and implementation to play well with third party code that uses it. One of such practices is to have a common prefix (or a few) for every interface, function or data structure, library provides. I helps to avoid name conflicts with other libraries and keeps API consistent. Inconsistent names in libbpf already cause problems in real life. E.g. an application can't use both libbpf and libnl due to conflicting symbols. Having common prefix will help to fix current and avoid future problems. libbpf already uses the following prefixes for its interfaces: * bpf_ for bpf system call wrappers, program/map/elf-object abstractions and a few other things; * btf_ for BTF related API; * libbpf_ for everything else. The patch adds libbpf_ prefix to functions and typedef in libbpf.h that use none of mentioned above prefixes and doesn't fit well into the first two categories. Since affected part of API is used in bpftool, the patch applies corresponding change to bpftool as well. Having it in a separate patch will cause a state of tree where bpftool is broken what may not be a good idea. Signed-off-by: Andrey Ignatov <rdna@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/libbpf.h20
-rw-r--r--tools/lib/bpf/netlink.c37
2 files changed, 30 insertions, 27 deletions
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 8388be525388..710ff5724980 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -305,14 +305,14 @@ int bpf_perf_event_read_simple(void *mem, unsigned long size,
305 bpf_perf_event_print_t fn, void *priv); 305 bpf_perf_event_print_t fn, void *priv);
306 306
307struct nlattr; 307struct nlattr;
308typedef int (*dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb); 308typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);
309int bpf_netlink_open(unsigned int *nl_pid); 309int libbpf_netlink_open(unsigned int *nl_pid);
310int nl_get_link(int sock, unsigned int nl_pid, dump_nlmsg_t dump_link_nlmsg, 310int libbpf_nl_get_link(int sock, unsigned int nl_pid,
311 void *cookie); 311 libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie);
312int nl_get_class(int sock, unsigned int nl_pid, int ifindex, 312int libbpf_nl_get_class(int sock, unsigned int nl_pid, int ifindex,
313 dump_nlmsg_t dump_class_nlmsg, void *cookie); 313 libbpf_dump_nlmsg_t dump_class_nlmsg, void *cookie);
314int nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex, 314int libbpf_nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
315 dump_nlmsg_t dump_qdisc_nlmsg, void *cookie); 315 libbpf_dump_nlmsg_t dump_qdisc_nlmsg, void *cookie);
316int nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle, 316int libbpf_nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle,
317 dump_nlmsg_t dump_filter_nlmsg, void *cookie); 317 libbpf_dump_nlmsg_t dump_filter_nlmsg, void *cookie);
318#endif 318#endif
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
index da46d9358d9d..506bdfdbcab0 100644
--- a/tools/lib/bpf/netlink.c
+++ b/tools/lib/bpf/netlink.c
@@ -18,10 +18,10 @@
18#define SOL_NETLINK 270 18#define SOL_NETLINK 270
19#endif 19#endif
20 20
21typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, dump_nlmsg_t, 21typedef int (*__dump_nlmsg_t)(struct nlmsghdr *nlmsg, libbpf_dump_nlmsg_t,
22 void *cookie); 22 void *cookie);
23 23
24int bpf_netlink_open(__u32 *nl_pid) 24int libbpf_netlink_open(__u32 *nl_pid)
25{ 25{
26 struct sockaddr_nl sa; 26 struct sockaddr_nl sa;
27 socklen_t addrlen; 27 socklen_t addrlen;
@@ -65,7 +65,7 @@ cleanup:
65} 65}
66 66
67static int bpf_netlink_recv(int sock, __u32 nl_pid, int seq, 67static int bpf_netlink_recv(int sock, __u32 nl_pid, int seq,
68 __dump_nlmsg_t _fn, dump_nlmsg_t fn, 68 __dump_nlmsg_t _fn, libbpf_dump_nlmsg_t fn,
69 void *cookie) 69 void *cookie)
70{ 70{
71 bool multipart = true; 71 bool multipart = true;
@@ -133,7 +133,7 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
133 } req; 133 } req;
134 __u32 nl_pid; 134 __u32 nl_pid;
135 135
136 sock = bpf_netlink_open(&nl_pid); 136 sock = libbpf_netlink_open(&nl_pid);
137 if (sock < 0) 137 if (sock < 0)
138 return sock; 138 return sock;
139 139
@@ -181,8 +181,8 @@ cleanup:
181 return ret; 181 return ret;
182} 182}
183 183
184static int __dump_link_nlmsg(struct nlmsghdr *nlh, dump_nlmsg_t dump_link_nlmsg, 184static int __dump_link_nlmsg(struct nlmsghdr *nlh,
185 void *cookie) 185 libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie)
186{ 186{
187 struct nlattr *tb[IFLA_MAX + 1], *attr; 187 struct nlattr *tb[IFLA_MAX + 1], *attr;
188 struct ifinfomsg *ifi = NLMSG_DATA(nlh); 188 struct ifinfomsg *ifi = NLMSG_DATA(nlh);
@@ -196,8 +196,8 @@ static int __dump_link_nlmsg(struct nlmsghdr *nlh, dump_nlmsg_t dump_link_nlmsg,
196 return dump_link_nlmsg(cookie, ifi, tb); 196 return dump_link_nlmsg(cookie, ifi, tb);
197} 197}
198 198
199int nl_get_link(int sock, unsigned int nl_pid, dump_nlmsg_t dump_link_nlmsg, 199int libbpf_nl_get_link(int sock, unsigned int nl_pid,
200 void *cookie) 200 libbpf_dump_nlmsg_t dump_link_nlmsg, void *cookie)
201{ 201{
202 struct { 202 struct {
203 struct nlmsghdr nlh; 203 struct nlmsghdr nlh;
@@ -219,7 +219,8 @@ int nl_get_link(int sock, unsigned int nl_pid, dump_nlmsg_t dump_link_nlmsg,
219} 219}
220 220
221static int __dump_class_nlmsg(struct nlmsghdr *nlh, 221static int __dump_class_nlmsg(struct nlmsghdr *nlh,
222 dump_nlmsg_t dump_class_nlmsg, void *cookie) 222 libbpf_dump_nlmsg_t dump_class_nlmsg,
223 void *cookie)
223{ 224{
224 struct nlattr *tb[TCA_MAX + 1], *attr; 225 struct nlattr *tb[TCA_MAX + 1], *attr;
225 struct tcmsg *t = NLMSG_DATA(nlh); 226 struct tcmsg *t = NLMSG_DATA(nlh);
@@ -233,8 +234,8 @@ static int __dump_class_nlmsg(struct nlmsghdr *nlh,
233 return dump_class_nlmsg(cookie, t, tb); 234 return dump_class_nlmsg(cookie, t, tb);
234} 235}
235 236
236int nl_get_class(int sock, unsigned int nl_pid, int ifindex, 237int libbpf_nl_get_class(int sock, unsigned int nl_pid, int ifindex,
237 dump_nlmsg_t dump_class_nlmsg, void *cookie) 238 libbpf_dump_nlmsg_t dump_class_nlmsg, void *cookie)
238{ 239{
239 struct { 240 struct {
240 struct nlmsghdr nlh; 241 struct nlmsghdr nlh;
@@ -257,7 +258,8 @@ int nl_get_class(int sock, unsigned int nl_pid, int ifindex,
257} 258}
258 259
259static int __dump_qdisc_nlmsg(struct nlmsghdr *nlh, 260static int __dump_qdisc_nlmsg(struct nlmsghdr *nlh,
260 dump_nlmsg_t dump_qdisc_nlmsg, void *cookie) 261 libbpf_dump_nlmsg_t dump_qdisc_nlmsg,
262 void *cookie)
261{ 263{
262 struct nlattr *tb[TCA_MAX + 1], *attr; 264 struct nlattr *tb[TCA_MAX + 1], *attr;
263 struct tcmsg *t = NLMSG_DATA(nlh); 265 struct tcmsg *t = NLMSG_DATA(nlh);
@@ -271,8 +273,8 @@ static int __dump_qdisc_nlmsg(struct nlmsghdr *nlh,
271 return dump_qdisc_nlmsg(cookie, t, tb); 273 return dump_qdisc_nlmsg(cookie, t, tb);
272} 274}
273 275
274int nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex, 276int libbpf_nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
275 dump_nlmsg_t dump_qdisc_nlmsg, void *cookie) 277 libbpf_dump_nlmsg_t dump_qdisc_nlmsg, void *cookie)
276{ 278{
277 struct { 279 struct {
278 struct nlmsghdr nlh; 280 struct nlmsghdr nlh;
@@ -295,7 +297,8 @@ int nl_get_qdisc(int sock, unsigned int nl_pid, int ifindex,
295} 297}
296 298
297static int __dump_filter_nlmsg(struct nlmsghdr *nlh, 299static int __dump_filter_nlmsg(struct nlmsghdr *nlh,
298 dump_nlmsg_t dump_filter_nlmsg, void *cookie) 300 libbpf_dump_nlmsg_t dump_filter_nlmsg,
301 void *cookie)
299{ 302{
300 struct nlattr *tb[TCA_MAX + 1], *attr; 303 struct nlattr *tb[TCA_MAX + 1], *attr;
301 struct tcmsg *t = NLMSG_DATA(nlh); 304 struct tcmsg *t = NLMSG_DATA(nlh);
@@ -309,8 +312,8 @@ static int __dump_filter_nlmsg(struct nlmsghdr *nlh,
309 return dump_filter_nlmsg(cookie, t, tb); 312 return dump_filter_nlmsg(cookie, t, tb);
310} 313}
311 314
312int nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle, 315int libbpf_nl_get_filter(int sock, unsigned int nl_pid, int ifindex, int handle,
313 dump_nlmsg_t dump_filter_nlmsg, void *cookie) 316 libbpf_dump_nlmsg_t dump_filter_nlmsg, void *cookie)
314{ 317{
315 struct { 318 struct {
316 struct nlmsghdr nlh; 319 struct nlmsghdr nlh;