Re: adding fields to struct mbuf

Vadim Goncharov <[email protected]>
Newsgroups gmane.os.freebsd.devel.net
Message-ID <[email protected]>
On Thu, 31 Jul 2025 13:03:22 +0200
Kajetan Staszkiewicz <[email protected]> wrote:

> Hello group,
> 
> I'm researching loop prevention in pfil. There are cases where packets
> are reinjected into the network stack and would be handled by the same
> hooks again, i.e. pf + dummynet where currently pf itself handles loop
> prevention on its own. My current experiment's approach to making loop
> prevention a general, non-pf-specific thing is to create a new mtag with
> pointer to the last hook and update it in pfil.c/pfil_mbuf_common().
> That works good so far, but it means memory allocation when pfil hooks
> are involved. I'm unsure what the impact on performance would be.
> Another approach would be to extend struct mbuf, or probably rather
> struct m_pkthdr, to contain the aforementioned pointer. But is changing
> that struct something that can be easily done and approved and merged?

First, you certainly don't need it in every mbuf - just first in chain with
struct pkthdr (where mtags also start).

Second.
The "last hook ptr" does not look like general solution for all cases and
occupies 8 bytes. What about idea from network itself - TTL ? It occupies less
bytes, the main problem is to decide where to decrement (e.g. each netgraph
hook, etc.)

Third.
What about redoing mtag allocator so that it reuses m_pktdat[] when M_EXT is
set? This could optimize performance for many tags, not just yours.

> For those curious the experiment will be uploaded to Phabricator soon-ish.

-- 
WBR, @nuclight
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.