From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
Martin KaFai Lau <kafai@fb.com>
Subject: [PATCH bpf-next v2 11/15] tools/bpf: refactor some net macros to libbpf bpf_tracing_net.h
Date: Sat, 20 Jun 2020 22:55:13 -0700 [thread overview]
Message-ID: <20200621055513.2630301-1-yhs@fb.com> (raw)
In-Reply-To: <20200621055459.2629116-1-yhs@fb.com>
Refactor bpf_iter_ipv6_route.c and bpf_iter_netlink.c
so net macros, originally from various include/linux header
files, are moved to a new libbpf installable header file
bpf_tracing_net.h. The goal is to improve reuse so
networking tracing programs do not need to
copy these macros every time they use them.
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/lib/bpf/Makefile | 1 +
tools/lib/bpf/bpf_tracing_net.h | 16 ++++++++++++++++
.../selftests/bpf/progs/bpf_iter_ipv6_route.c | 7 +------
.../selftests/bpf/progs/bpf_iter_netlink.c | 4 +---
4 files changed, 19 insertions(+), 9 deletions(-)
create mode 100644 tools/lib/bpf/bpf_tracing_net.h
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index bf8ed134cb8a..3d766c80eb78 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -257,6 +257,7 @@ install_headers: $(BPF_HELPER_DEFS)
$(call do_install,bpf_helpers.h,$(prefix)/include/bpf,644); \
$(call do_install,$(BPF_HELPER_DEFS),$(prefix)/include/bpf,644); \
$(call do_install,bpf_tracing.h,$(prefix)/include/bpf,644); \
+ $(call do_install,bpf_tracing_net.h,$(prefix)/include/bpf,644); \
$(call do_install,bpf_endian.h,$(prefix)/include/bpf,644); \
$(call do_install,bpf_core_read.h,$(prefix)/include/bpf,644);
diff --git a/tools/lib/bpf/bpf_tracing_net.h b/tools/lib/bpf/bpf_tracing_net.h
new file mode 100644
index 000000000000..1f38a1098727
--- /dev/null
+++ b/tools/lib/bpf/bpf_tracing_net.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
+#ifndef __BPF_TRACING_NET_H__
+#define __BPF_TRACING_NET_H__
+
+#define IFNAMSIZ 16
+
+#define RTF_GATEWAY 0x0002
+
+#define fib_nh_dev nh_common.nhc_dev
+#define fib_nh_gw_family nh_common.nhc_gw_family
+#define fib_nh_gw6 nh_common.nhc_gw.ipv6
+
+#define sk_rmem_alloc sk_backlog.rmem_alloc
+#define sk_refcnt __sk_common.skc_refcnt
+
+#endif
diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c b/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
index 93a452d1d136..64f952d68710 100644
--- a/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
+++ b/tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c
@@ -3,17 +3,12 @@
#include "bpf_iter.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_tracing_net.h>
char _license[] SEC("license") = "GPL";
extern bool CONFIG_IPV6_SUBTREES __kconfig __weak;
-#define RTF_GATEWAY 0x0002
-#define IFNAMSIZ 16
-#define fib_nh_gw_family nh_common.nhc_gw_family
-#define fib_nh_gw6 nh_common.nhc_gw.ipv6
-#define fib_nh_dev nh_common.nhc_dev
-
SEC("iter/ipv6_route")
int dump_ipv6_route(struct bpf_iter__ipv6_route *ctx)
{
diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c b/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
index fda5036fdf75..cde88ad957a2 100644
--- a/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
+++ b/tools/testing/selftests/bpf/progs/bpf_iter_netlink.c
@@ -3,12 +3,10 @@
#include "bpf_iter.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_tracing_net.h>
char _license[] SEC("license") = "GPL";
-#define sk_rmem_alloc sk_backlog.rmem_alloc
-#define sk_refcnt __sk_common.skc_refcnt
-
static inline struct inode *SOCK_INODE(struct socket *socket)
{
return &container_of(socket, struct socket_alloc, socket)->vfs_inode;
--
2.24.1
next prev parent reply other threads:[~2020-06-21 5:55 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 5:54 [PATCH bpf-next v2 00/15] implement bpf iterator for tcp and udp sockets Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 01/15] bpf: add bpf_seq_afinfo in tcp_iter_state Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 02/15] net: bpf: implement bpf iterator for tcp Yonghong Song
2020-06-22 18:15 ` Martin KaFai Lau
2020-06-21 5:55 ` [PATCH bpf-next v2 03/15] bpf: support 'X' in bpf_seq_printf() helper Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 04/15] bpf: allow tracing programs to use bpf_jiffies64() helper Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 05/15] bpf: add bpf_skc_to_tcp6_sock() helper Yonghong Song
2020-06-22 20:50 ` Martin KaFai Lau
2020-06-21 5:55 ` [PATCH bpf-next v2 06/15] bpf: add bpf_skc_to_{tcp,tcp_timewait,tcp_request}_sock() helpers Yonghong Song
2020-06-22 21:18 ` Martin KaFai Lau
2020-06-21 5:55 ` [PATCH bpf-next v2 07/15] bpf: add bpf_seq_afinfo in udp_iter_state Yonghong Song
2020-06-22 21:47 ` Martin KaFai Lau
2020-06-21 5:55 ` [PATCH bpf-next v2 08/15] net: bpf: implement bpf iterator for udp Yonghong Song
2020-06-22 22:00 ` [Potential Spoof] " Martin KaFai Lau
2020-06-21 5:55 ` [PATCH bpf-next v2 09/15] bpf: add bpf_skc_to_udp6_sock() helper Yonghong Song
2020-06-22 22:05 ` Martin KaFai Lau
2020-06-21 5:55 ` [PATCH bpf-next v2 10/15] bpf/selftests: move newer bpf_iter_* type redefining to a new header file Yonghong Song
2020-06-21 5:55 ` Yonghong Song [this message]
2020-06-21 5:55 ` [PATCH bpf-next v2 12/15] tools/libbpf: add more common macros to bpf_tracing_net.h Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 13/15] tools/bpf: selftests: implement sample tcp/tcp6 bpf_iter programs Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 14/15] tools/bpf: add udp4/udp6 bpf iterator Yonghong Song
2020-06-21 5:55 ` [PATCH bpf-next v2 15/15] bpf/selftests: add tcp/udp iterator programs to selftests Yonghong Song
2020-06-22 20:08 ` [PATCH bpf-next v2 00/15] implement bpf iterator for tcp and udp sockets Jakub Kicinski
2020-06-22 20:34 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200621055513.2630301-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.