[PATCH v4 4/5] bpf: add test for Rx and Tx filtering

Stephen Hemminger stephen at networkplumber.org
Sat Nov 8 02:11:14 CET 2025


On Fri, 7 Nov 2025 17:30:51 +0000
Marat Khalili <marat.khalili at huawei.com> wrote:

> Thank you for doing this! See comments below.
> 
> > -----Original Message-----
> > From: Stephen Hemminger <stephen at networkplumber.org>
> > Sent: Tuesday 4 November 2025 16:07
> > To: dev at dpdk.org
> > Cc: Stephen Hemminger <stephen at networkplumber.org>; Konstantin Ananyev <konstantin.ananyev at huawei.com>
> > Subject: [PATCH v4 4/5] bpf: add test for Rx and Tx filtering
> > 
> > New test using null device to test filtering with BPF.
> > 
> > Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> > ---
> >  app/test/bpf/filter.c    |  53 +++++++
> >  app/test/bpf/meson.build |   1 +
> >  app/test/test_bpf.c      | 304 +++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 358 insertions(+)
> >  create mode 100644 app/test/bpf/filter.c
> > 
> > diff --git a/app/test/bpf/filter.c b/app/test/bpf/filter.c
> > new file mode 100644
> > index 0000000000..d47233a47a
> > --- /dev/null
> > +++ b/app/test/bpf/filter.c
> > @@ -0,0 +1,53 @@
> > +/* SPDX-License-Identifier: BSD-3-Clause
> > + * BPF TX filter program for testing rte_bpf_eth_tx_elf_load
> > + */
> > +
> > +typedef unsigned char uint8_t;
> > +typedef unsigned short uint16_t;
> > +typedef unsigned int uint32_t;
> > +typedef unsigned long uint64_t;
> > +
> > +/*
> > + * Simple TX filter that accepts TCP packets
> > + *
> > + * BPF TX programs receive pointer to data and should return:
> > + *   0 = drop packet
> > + *   non-zero = rx/tx packet
> > + *
> > + * This filter checks:
> > + * 1. Packet is IPv4
> > + * 2. Protocol is TCP (IPPROTO_TCP = 6)
> > + */
> > +__attribute__((section("filter"), used))  
> 
> Could this section (and function) be called better, e.g. filter_ip_tcp?
> 
> > +uint64_t
> > +test_filter(void *pkt)
> > +{
> > +	uint8_t *data = pkt;  
> 
> Does pkt point to packet data or an mbuf? I would think we need mbuf functions
> here to access data. Not sure why the test is not failing though, maybe I
> misunderstand it.

The API for DPDK BPF gives option for packet data or mbuf.
See rte_bpf_arg_type.

This test uses packet data. Mostly because it is easier, using mbuf
requires more overhead and BPF validator often doesn't like it.


More information about the dev mailing list