diff mbox series

[bpf-next,v3,20/21] selftests/bpf: Check VLAN tag and proto in xdp_metadata

Message ID 20230719183734.21681-21-larysa.zaremba@intel.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series XDP metadata via kfuncs for ice | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/apply fail Patch does not apply to bpf-next
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for veristat

Commit Message

Larysa Zaremba July 19, 2023, 6:37 p.m. UTC
Verify, whether VLAN tag and proto are set correctly.

To simulate "stripped" VLAN tag on veth, send test packet from VLAN
interface.

Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
---
 .../selftests/bpf/prog_tests/xdp_metadata.c   | 22 +++++++++++++++++--
 .../selftests/bpf/progs/xdp_metadata.c        |  4 ++++
 2 files changed, 24 insertions(+), 2 deletions(-)

Comments

Stanislav Fomichev July 20, 2023, 10:14 p.m. UTC | #1
On 07/19, Larysa Zaremba wrote:
> Verify, whether VLAN tag and proto are set correctly.
> 
> To simulate "stripped" VLAN tag on veth, send test packet from VLAN
> interface.
> 
> Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>

Acked-by: Stanislav Fomichev <sdf@google.com>

> ---
>  .../selftests/bpf/prog_tests/xdp_metadata.c   | 22 +++++++++++++++++--
>  .../selftests/bpf/progs/xdp_metadata.c        |  4 ++++
>  2 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> index 1877e5c6d6c7..6665cf0c59cc 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> @@ -38,7 +38,15 @@
>  #define TX_MAC "00:00:00:00:00:01"
>  #define RX_MAC "00:00:00:00:00:02"
>  
> +#define VLAN_ID 59
> +#define VLAN_ID_STR "59"

I was looking whether we have some str(x) macro in the selftests,
but doesn't look like we have any...

> +#define VLAN_PROTO "802.1Q"
> +#define VLAN_PID htons(ETH_P_8021Q)
> +#define TX_NAME_VLAN TX_NAME "." VLAN_ID_STR
> +#define RX_NAME_VLAN RX_NAME "." VLAN_ID_STR
> +
>  #define XDP_RSS_TYPE_L4 BIT(3)
> +#define VLAN_VID_MASK 0xfff
>  
>  struct xsk {
>  	void *umem_area;
> @@ -215,6 +223,12 @@ static int verify_xsk_metadata(struct xsk *xsk)
>  	if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
>  		return -1;
>  
> +	if (!ASSERT_EQ(meta->rx_vlan_tci & VLAN_VID_MASK, VLAN_ID, "rx_vlan_tci"))
> +		return -1;
> +
> +	if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
> +		return -1;
> +
>  	xsk_ring_cons__release(&xsk->rx, 1);
>  	refill_rx(xsk, comp_addr);
>  
> @@ -248,10 +262,14 @@ void test_xdp_metadata(void)
>  
>  	SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
>  	SYS(out, "ip link set dev " TX_NAME " up");
> -	SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
> +
> +	SYS(out, "ip link add link " TX_NAME " " TX_NAME_VLAN
> +		 " type vlan proto " VLAN_PROTO " id " VLAN_ID_STR);
> +	SYS(out, "ip link set dev " TX_NAME_VLAN " up");
> +	SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME_VLAN);
>  
>  	/* Avoid ARP calls */
> -	SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME);
> +	SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME_VLAN);
>  	close_netns(tok);
>  
>  	tok = open_netns(RX_NETNS_NAME);
> diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> index d151d406a123..d3111649170e 100644
> --- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
> +++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> @@ -23,6 +23,9 @@ extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
>  					 __u64 *timestamp) __ksym;
>  extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
>  				    enum xdp_rss_hash_type *rss_type) __ksym;
> +extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
> +					__u16 *vlan_tci,
> +					__be16 *vlan_proto) __ksym;
>  
>  SEC("xdp")
>  int rx(struct xdp_md *ctx)
> @@ -57,6 +60,7 @@ int rx(struct xdp_md *ctx)
>  		meta->rx_timestamp = 1;
>  
>  	bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
> +	bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
>  
>  	return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
>  }
> -- 
> 2.41.0
>
Larysa Zaremba July 21, 2023, 7:46 a.m. UTC | #2
On Thu, Jul 20, 2023 at 03:14:15PM -0700, Stanislav Fomichev wrote:
> On 07/19, Larysa Zaremba wrote:
> > Verify, whether VLAN tag and proto are set correctly.
> > 
> > To simulate "stripped" VLAN tag on veth, send test packet from VLAN
> > interface.
> > 
> > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> 
> Acked-by: Stanislav Fomichev <sdf@google.com>
> 
> > ---
> >  .../selftests/bpf/prog_tests/xdp_metadata.c   | 22 +++++++++++++++++--
> >  .../selftests/bpf/progs/xdp_metadata.c        |  4 ++++
> >  2 files changed, 24 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > index 1877e5c6d6c7..6665cf0c59cc 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > @@ -38,7 +38,15 @@
> >  #define TX_MAC "00:00:00:00:00:01"
> >  #define RX_MAC "00:00:00:00:00:02"
> >  
> > +#define VLAN_ID 59
> > +#define VLAN_ID_STR "59"
> 
> I was looking whether we have some str(x) macro in the selftests,
> but doesn't look like we have any...
> 

I could add one, if you could hint me at the file, where it would need to go.
Or just add it locally for now?

> > +#define VLAN_PROTO "802.1Q"
> > +#define VLAN_PID htons(ETH_P_8021Q)
> > +#define TX_NAME_VLAN TX_NAME "." VLAN_ID_STR
> > +#define RX_NAME_VLAN RX_NAME "." VLAN_ID_STR
> > +
> >  #define XDP_RSS_TYPE_L4 BIT(3)
> > +#define VLAN_VID_MASK 0xfff
> >  
> >  struct xsk {
> >  	void *umem_area;
> > @@ -215,6 +223,12 @@ static int verify_xsk_metadata(struct xsk *xsk)
> >  	if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
> >  		return -1;
> >  
> > +	if (!ASSERT_EQ(meta->rx_vlan_tci & VLAN_VID_MASK, VLAN_ID, "rx_vlan_tci"))
> > +		return -1;
> > +
> > +	if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
> > +		return -1;
> > +
> >  	xsk_ring_cons__release(&xsk->rx, 1);
> >  	refill_rx(xsk, comp_addr);
> >  
> > @@ -248,10 +262,14 @@ void test_xdp_metadata(void)
> >  
> >  	SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
> >  	SYS(out, "ip link set dev " TX_NAME " up");
> > -	SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
> > +
> > +	SYS(out, "ip link add link " TX_NAME " " TX_NAME_VLAN
> > +		 " type vlan proto " VLAN_PROTO " id " VLAN_ID_STR);
> > +	SYS(out, "ip link set dev " TX_NAME_VLAN " up");
> > +	SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME_VLAN);
> >  
> >  	/* Avoid ARP calls */
> > -	SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME);
> > +	SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME_VLAN);
> >  	close_netns(tok);
> >  
> >  	tok = open_netns(RX_NETNS_NAME);
> > diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > index d151d406a123..d3111649170e 100644
> > --- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > +++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > @@ -23,6 +23,9 @@ extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
> >  					 __u64 *timestamp) __ksym;
> >  extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
> >  				    enum xdp_rss_hash_type *rss_type) __ksym;
> > +extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
> > +					__u16 *vlan_tci,
> > +					__be16 *vlan_proto) __ksym;
> >  
> >  SEC("xdp")
> >  int rx(struct xdp_md *ctx)
> > @@ -57,6 +60,7 @@ int rx(struct xdp_md *ctx)
> >  		meta->rx_timestamp = 1;
> >  
> >  	bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
> > +	bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
> >  
> >  	return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
> >  }
> > -- 
> > 2.41.0
> > 
>
Stanislav Fomichev July 21, 2023, 4:44 p.m. UTC | #3
On Fri, Jul 21, 2023 at 12:47 AM Zaremba, Larysa
<larysa.zaremba@intel.com> wrote:
>
> On Thu, Jul 20, 2023 at 03:14:15PM -0700, Stanislav Fomichev wrote:
> > On 07/19, Larysa Zaremba wrote:
> > > Verify, whether VLAN tag and proto are set correctly.
> > >
> > > To simulate "stripped" VLAN tag on veth, send test packet from VLAN
> > > interface.
> > >
> > > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> >
> > Acked-by: Stanislav Fomichev <sdf@google.com>
> >
> > > ---
> > >  .../selftests/bpf/prog_tests/xdp_metadata.c   | 22 +++++++++++++++++--
> > >  .../selftests/bpf/progs/xdp_metadata.c        |  4 ++++
> > >  2 files changed, 24 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > > index 1877e5c6d6c7..6665cf0c59cc 100644
> > > --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > > @@ -38,7 +38,15 @@
> > >  #define TX_MAC "00:00:00:00:00:01"
> > >  #define RX_MAC "00:00:00:00:00:02"
> > >
> > > +#define VLAN_ID 59
> > > +#define VLAN_ID_STR "59"
> >
> > I was looking whether we have some str(x) macro in the selftests,
> > but doesn't look like we have any...
> >
>
> I could add one, if you could hint me at the file, where it would need to go.
> Or just add it locally for now?

Up to you. I feel like it's fine as is.

I was expecting to find something like the following in
tools/testing/selftests/bpf/testing_helpers.h:

#define __TO_STR(x) #x
#define TO_STR(x) __TO_STR(x)

We have similar patterns in:
tools/testing/selftests/bpf/sdt.h (_SDT_ARG_CONSTRAINT_STRING)
tools/testing/selftests/kvm/x86_64/smm_test.c (XSTR)
tools/tracing/rtla/src/utils.c (STR)

But nothing "generic" it seems...

> > > +#define VLAN_PROTO "802.1Q"
> > > +#define VLAN_PID htons(ETH_P_8021Q)
> > > +#define TX_NAME_VLAN TX_NAME "." VLAN_ID_STR
> > > +#define RX_NAME_VLAN RX_NAME "." VLAN_ID_STR
> > > +
> > >  #define XDP_RSS_TYPE_L4 BIT(3)
> > > +#define VLAN_VID_MASK 0xfff
> > >
> > >  struct xsk {
> > >     void *umem_area;
> > > @@ -215,6 +223,12 @@ static int verify_xsk_metadata(struct xsk *xsk)
> > >     if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
> > >             return -1;
> > >
> > > +   if (!ASSERT_EQ(meta->rx_vlan_tci & VLAN_VID_MASK, VLAN_ID, "rx_vlan_tci"))
> > > +           return -1;
> > > +
> > > +   if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
> > > +           return -1;
> > > +
> > >     xsk_ring_cons__release(&xsk->rx, 1);
> > >     refill_rx(xsk, comp_addr);
> > >
> > > @@ -248,10 +262,14 @@ void test_xdp_metadata(void)
> > >
> > >     SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
> > >     SYS(out, "ip link set dev " TX_NAME " up");
> > > -   SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
> > > +
> > > +   SYS(out, "ip link add link " TX_NAME " " TX_NAME_VLAN
> > > +            " type vlan proto " VLAN_PROTO " id " VLAN_ID_STR);
> > > +   SYS(out, "ip link set dev " TX_NAME_VLAN " up");
> > > +   SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME_VLAN);
> > >
> > >     /* Avoid ARP calls */
> > > -   SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME);
> > > +   SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME_VLAN);
> > >     close_netns(tok);
> > >
> > >     tok = open_netns(RX_NETNS_NAME);
> > > diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > > index d151d406a123..d3111649170e 100644
> > > --- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > > +++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > > @@ -23,6 +23,9 @@ extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
> > >                                      __u64 *timestamp) __ksym;
> > >  extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
> > >                                 enum xdp_rss_hash_type *rss_type) __ksym;
> > > +extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
> > > +                                   __u16 *vlan_tci,
> > > +                                   __be16 *vlan_proto) __ksym;
> > >
> > >  SEC("xdp")
> > >  int rx(struct xdp_md *ctx)
> > > @@ -57,6 +60,7 @@ int rx(struct xdp_md *ctx)
> > >             meta->rx_timestamp = 1;
> > >
> > >     bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
> > > +   bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
> > >
> > >     return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
> > >  }
> > > --
> > > 2.41.0
> > >
> >
Larysa Zaremba July 25, 2023, 7:11 a.m. UTC | #4
On Fri, Jul 21, 2023 at 09:44:17AM -0700, Stanislav Fomichev wrote:
> On Fri, Jul 21, 2023 at 12:47 AM Zaremba, Larysa
> <larysa.zaremba@intel.com> wrote:
> >
> > On Thu, Jul 20, 2023 at 03:14:15PM -0700, Stanislav Fomichev wrote:
> > > On 07/19, Larysa Zaremba wrote:
> > > > Verify, whether VLAN tag and proto are set correctly.
> > > >
> > > > To simulate "stripped" VLAN tag on veth, send test packet from VLAN
> > > > interface.
> > > >
> > > > Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
> > >
> > > Acked-by: Stanislav Fomichev <sdf@google.com>
> > >
> > > > ---
> > > >  .../selftests/bpf/prog_tests/xdp_metadata.c   | 22 +++++++++++++++++--
> > > >  .../selftests/bpf/progs/xdp_metadata.c        |  4 ++++
> > > >  2 files changed, 24 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > > > index 1877e5c6d6c7..6665cf0c59cc 100644
> > > > --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > > > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
> > > > @@ -38,7 +38,15 @@
> > > >  #define TX_MAC "00:00:00:00:00:01"
> > > >  #define RX_MAC "00:00:00:00:00:02"
> > > >
> > > > +#define VLAN_ID 59
> > > > +#define VLAN_ID_STR "59"
> > >
> > > I was looking whether we have some str(x) macro in the selftests,
> > > but doesn't look like we have any...
> > >
> >
> > I could add one, if you could hint me at the file, where it would need to go.
> > Or just add it locally for now?
> 
> Up to you. I feel like it's fine as is.
>

I need to send v4 with some minor changes anyway, so will add in v4.

> I was expecting to find something like the following in
> tools/testing/selftests/bpf/testing_helpers.h:
> 
> #define __TO_STR(x) #x
> #define TO_STR(x) __TO_STR(x)
> 
> We have similar patterns in:
> tools/testing/selftests/bpf/sdt.h (_SDT_ARG_CONSTRAINT_STRING)
> tools/testing/selftests/kvm/x86_64/smm_test.c (XSTR)
> tools/tracing/rtla/src/utils.c (STR)
> 
> But nothing "generic" it seems...
> 
> > > > +#define VLAN_PROTO "802.1Q"
> > > > +#define VLAN_PID htons(ETH_P_8021Q)
> > > > +#define TX_NAME_VLAN TX_NAME "." VLAN_ID_STR
> > > > +#define RX_NAME_VLAN RX_NAME "." VLAN_ID_STR
> > > > +
> > > >  #define XDP_RSS_TYPE_L4 BIT(3)
> > > > +#define VLAN_VID_MASK 0xfff
> > > >
> > > >  struct xsk {
> > > >     void *umem_area;
> > > > @@ -215,6 +223,12 @@ static int verify_xsk_metadata(struct xsk *xsk)
> > > >     if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
> > > >             return -1;
> > > >
> > > > +   if (!ASSERT_EQ(meta->rx_vlan_tci & VLAN_VID_MASK, VLAN_ID, "rx_vlan_tci"))
> > > > +           return -1;
> > > > +
> > > > +   if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
> > > > +           return -1;
> > > > +
> > > >     xsk_ring_cons__release(&xsk->rx, 1);
> > > >     refill_rx(xsk, comp_addr);
> > > >
> > > > @@ -248,10 +262,14 @@ void test_xdp_metadata(void)
> > > >
> > > >     SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
> > > >     SYS(out, "ip link set dev " TX_NAME " up");
> > > > -   SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
> > > > +
> > > > +   SYS(out, "ip link add link " TX_NAME " " TX_NAME_VLAN
> > > > +            " type vlan proto " VLAN_PROTO " id " VLAN_ID_STR);
> > > > +   SYS(out, "ip link set dev " TX_NAME_VLAN " up");
> > > > +   SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME_VLAN);
> > > >
> > > >     /* Avoid ARP calls */
> > > > -   SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME);
> > > > +   SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME_VLAN);
> > > >     close_netns(tok);
> > > >
> > > >     tok = open_netns(RX_NETNS_NAME);
> > > > diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > > > index d151d406a123..d3111649170e 100644
> > > > --- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > > > +++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
> > > > @@ -23,6 +23,9 @@ extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
> > > >                                      __u64 *timestamp) __ksym;
> > > >  extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
> > > >                                 enum xdp_rss_hash_type *rss_type) __ksym;
> > > > +extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
> > > > +                                   __u16 *vlan_tci,
> > > > +                                   __be16 *vlan_proto) __ksym;
> > > >
> > > >  SEC("xdp")
> > > >  int rx(struct xdp_md *ctx)
> > > > @@ -57,6 +60,7 @@ int rx(struct xdp_md *ctx)
> > > >             meta->rx_timestamp = 1;
> > > >
> > > >     bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
> > > > +   bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
> > > >
> > > >     return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
> > > >  }
> > > > --
> > > > 2.41.0
> > > >
> > >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
index 1877e5c6d6c7..6665cf0c59cc 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
@@ -38,7 +38,15 @@ 
 #define TX_MAC "00:00:00:00:00:01"
 #define RX_MAC "00:00:00:00:00:02"
 
+#define VLAN_ID 59
+#define VLAN_ID_STR "59"
+#define VLAN_PROTO "802.1Q"
+#define VLAN_PID htons(ETH_P_8021Q)
+#define TX_NAME_VLAN TX_NAME "." VLAN_ID_STR
+#define RX_NAME_VLAN RX_NAME "." VLAN_ID_STR
+
 #define XDP_RSS_TYPE_L4 BIT(3)
+#define VLAN_VID_MASK 0xfff
 
 struct xsk {
 	void *umem_area;
@@ -215,6 +223,12 @@  static int verify_xsk_metadata(struct xsk *xsk)
 	if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
 		return -1;
 
+	if (!ASSERT_EQ(meta->rx_vlan_tci & VLAN_VID_MASK, VLAN_ID, "rx_vlan_tci"))
+		return -1;
+
+	if (!ASSERT_EQ(meta->rx_vlan_proto, VLAN_PID, "rx_vlan_proto"))
+		return -1;
+
 	xsk_ring_cons__release(&xsk->rx, 1);
 	refill_rx(xsk, comp_addr);
 
@@ -248,10 +262,14 @@  void test_xdp_metadata(void)
 
 	SYS(out, "ip link set dev " TX_NAME " address " TX_MAC);
 	SYS(out, "ip link set dev " TX_NAME " up");
-	SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME);
+
+	SYS(out, "ip link add link " TX_NAME " " TX_NAME_VLAN
+		 " type vlan proto " VLAN_PROTO " id " VLAN_ID_STR);
+	SYS(out, "ip link set dev " TX_NAME_VLAN " up");
+	SYS(out, "ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME_VLAN);
 
 	/* Avoid ARP calls */
-	SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME);
+	SYS(out, "ip -4 neigh add " RX_ADDR " lladdr " RX_MAC " dev " TX_NAME_VLAN);
 	close_netns(tok);
 
 	tok = open_netns(RX_NETNS_NAME);
diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
index d151d406a123..d3111649170e 100644
--- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
@@ -23,6 +23,9 @@  extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx,
 					 __u64 *timestamp) __ksym;
 extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
 				    enum xdp_rss_hash_type *rss_type) __ksym;
+extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
+					__u16 *vlan_tci,
+					__be16 *vlan_proto) __ksym;
 
 SEC("xdp")
 int rx(struct xdp_md *ctx)
@@ -57,6 +60,7 @@  int rx(struct xdp_md *ctx)
 		meta->rx_timestamp = 1;
 
 	bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
+	bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_tci, &meta->rx_vlan_proto);
 
 	return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
 }