git: 57673d166940 - main - bpf: retire struct bpf_if_ext
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 03 Dec 2025 23:20:00 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=57673d166940feafe09f411294b57fa6c8af3585
commit 57673d166940feafe09f411294b57fa6c8af3585
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2025-12-03 23:16:15 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2025-12-03 23:19:44 +0000
bpf: retire struct bpf_if_ext
The struct was used for bpf_if to bif_dlist masking, that is used to
optimize bpf_peers_present() call. The only functional change here is
that bif_dlist and bif_next swap their places in the structure. Both
belong to the first cache line anyway.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D53867
---
sys/net/bpf.c | 13 ++++++-------
sys/net/bpf.h | 13 ++++---------
2 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 23a23fbfe22e..f5302059d5eb 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -93,14 +93,11 @@
MALLOC_DEFINE(M_BPF, "BPF", "BPF data");
-static const struct bpf_if_ext dead_bpf_if = {
- .bif_dlist = CK_LIST_HEAD_INITIALIZER()
-};
+static const struct bpfd_list dead_bpf_if = CK_LIST_HEAD_INITIALIZER();
struct bpf_if {
-#define bif_next bif_ext.bif_next
-#define bif_dlist bif_ext.bif_dlist
- struct bpf_if_ext bif_ext; /* public members */
+ struct bpfd_list bif_dlist; /* list of all interfaces */
+ CK_LIST_ENTRY(bpf_if) bif_next; /* descriptor list */
u_int bif_dlt; /* link layer type */
u_int bif_hdrlen; /* length of link header */
struct bpfd_list bif_wlist; /* writer-only list */
@@ -110,7 +107,9 @@ struct bpf_if {
struct epoch_context epoch_ctx;
};
-CTASSERT(offsetof(struct bpf_if, bif_ext) == 0);
+/* See bpf_peers_present() in bpf.h. */
+_Static_assert(offsetof(struct bpf_if, bif_dlist) == 0,
+ "bpf_if shall start with bif_dlist");
struct bpf_program_buffer {
struct epoch_context epoch_ctx;
diff --git a/sys/net/bpf.h b/sys/net/bpf.h
index dfb8373bb329..b18840bfd2bf 100644
--- a/sys/net/bpf.h
+++ b/sys/net/bpf.h
@@ -410,11 +410,6 @@ SYSCTL_DECL(_net_bpf);
struct bpf_if;
CK_LIST_HEAD(bpfd_list, bpf_d);
-struct bpf_if_ext {
- CK_LIST_ENTRY(bpf_if) bif_next; /* list of all interfaces */
- struct bpfd_list bif_dlist; /* descriptor list */
-};
-
void bpf_bufheld(struct bpf_d *d);
int bpf_validate(const struct bpf_insn *, int);
void bpf_tap(struct bpf_if *, u_char *, u_int);
@@ -435,12 +430,12 @@ void bpfilterattach(int);
u_int bpf_filter(const struct bpf_insn *, u_char *, u_int, u_int);
static __inline bool
-bpf_peers_present(struct bpf_if *bpf)
+bpf_peers_present(const struct bpf_if *bpf)
{
- struct bpf_if_ext *ext;
+ const struct bpfd_list *dlist;
- ext = (struct bpf_if_ext *)bpf;
- return (!CK_LIST_EMPTY(&ext->bif_dlist));
+ dlist = (const struct bpfd_list *)bpf;
+ return (!CK_LIST_EMPTY(dlist));
}
#define BPF_TAP(_ifp, _pkt, _pktlen) \