From: Daniel Borkmann <daniel@iogearbox.net>
To: ast@kernel.org
Cc: andrii@kernel.org, martin.lau@linux.dev, razor@blackwall.org,
sdf@google.com, john.fastabend@gmail.com, kuba@kernel.org,
dxu@dxuuu.xyz, joe@cilium.io, toke@kernel.org,
davem@davemloft.net, bpf@vger.kernel.org, netdev@vger.kernel.org,
Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH bpf-next v3 5/8] libbpf: Add helper macro to clear opts structs
Date: Fri, 7 Jul 2023 19:24:52 +0200 [thread overview]
Message-ID: <20230707172455.7634-6-daniel@iogearbox.net> (raw)
In-Reply-To: <20230707172455.7634-1-daniel@iogearbox.net>
Add a small and generic LIBBPF_OPTS_CLEAR() helper macros which clears
an opts structure and reinitializes its .sz member to place the structure
size. I found this very useful when developing selftests, but it is also
generic enough as a macro next to the existing LIBBPF_OPTS() which hides
the .sz initialization, too.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
tools/lib/bpf/libbpf_common.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/lib/bpf/libbpf_common.h b/tools/lib/bpf/libbpf_common.h
index 9a7937f339df..eb180023aa97 100644
--- a/tools/lib/bpf/libbpf_common.h
+++ b/tools/lib/bpf/libbpf_common.h
@@ -70,4 +70,15 @@
}; \
})
+/* Helper macro to clear a libbpf options struct
+ *
+ * Small helper macro to reset all fields and to reinitialize the common
+ * structure size member.
+ */
+#define LIBBPF_OPTS_CLEAR(NAME) \
+ do { \
+ memset(&NAME, 0, sizeof(NAME)); \
+ NAME.sz = sizeof(NAME); \
+ } while (0)
+
#endif /* __LIBBPF_LIBBPF_COMMON_H */
--
2.34.1
next prev parent reply other threads:[~2023-07-07 17:26 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 17:24 [PATCH bpf-next v3 0/8] BPF link support for tc BPF programs Daniel Borkmann
2023-07-07 17:24 ` [PATCH bpf-next v3 1/8] bpf: Add generic attach/detach/query API for multi-progs Daniel Borkmann
2023-07-07 21:27 ` Stanislav Fomichev
2023-07-10 7:42 ` Daniel Borkmann
2023-07-10 14:26 ` Daniel Borkmann
2023-07-10 18:18 ` Stanislav Fomichev
2023-07-10 18:26 ` Alexei Starovoitov
2023-07-10 19:00 ` Stanislav Fomichev
2023-07-10 20:16 ` Alexei Starovoitov
2023-07-10 21:13 ` Stanislav Fomichev
2023-07-10 22:38 ` Alexei Starovoitov
2023-07-10 22:46 ` Stanislav Fomichev
2023-07-10 18:29 ` Daniel Borkmann
2023-07-09 17:17 ` Alexei Starovoitov
2023-07-10 7:10 ` Daniel Borkmann
2023-07-10 13:15 ` Daniel Borkmann
2023-07-07 17:24 ` [PATCH bpf-next v3 2/8] bpf: Add fd-based tcx multi-prog infra with link support Daniel Borkmann
2023-07-09 17:19 ` Alexei Starovoitov
2023-07-10 6:57 ` Daniel Borkmann
2023-07-07 17:24 ` [PATCH bpf-next v3 3/8] libbpf: Add opts-based attach/detach/query API for tcx Daniel Borkmann
2023-07-07 17:24 ` [PATCH bpf-next v3 4/8] libbpf: Add link-based " Daniel Borkmann
2023-07-07 17:24 ` Daniel Borkmann [this message]
2023-07-07 17:24 ` [PATCH bpf-next v3 6/8] bpftool: Extend net dump with tcx progs Daniel Borkmann
2023-07-07 21:31 ` Stanislav Fomichev
2023-07-10 6:53 ` Daniel Borkmann
2023-07-07 17:24 ` [PATCH bpf-next v3 7/8] selftests/bpf: Add mprog API tests for BPF tcx opts Daniel Borkmann
2023-07-07 17:24 ` [PATCH bpf-next v3 8/8] selftests/bpf: Add mprog API tests for BPF tcx links Daniel Borkmann
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=20230707172455.7634-6-daniel@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=dxu@dxuuu.xyz \
--cc=joe@cilium.io \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=razor@blackwall.org \
--cc=sdf@google.com \
--cc=toke@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox