Skip to content

Commit e71a9fa

Browse files
walking-machineAlexei Starovoitov
authored andcommitted
selftests/bpf: Allow VLAN packets in xdp_hw_metadata
Make VLAN c-tag and s-tag XDP hint testing more convenient by not skipping VLAN-ed packets. Allow both 802.1ad and 802.1Q headers. Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Larysa Zaremba <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7978bad commit e71a9fa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tools/testing/selftests/bpf/progs/xdp_hw_metadata.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,23 @@ int rx(struct xdp_md *ctx)
2626
{
2727
void *data, *data_meta, *data_end;
2828
struct ipv6hdr *ip6h = NULL;
29-
struct ethhdr *eth = NULL;
3029
struct udphdr *udp = NULL;
3130
struct iphdr *iph = NULL;
3231
struct xdp_meta *meta;
32+
struct ethhdr *eth;
3333
int err;
3434

3535
data = (void *)(long)ctx->data;
3636
data_end = (void *)(long)ctx->data_end;
3737
eth = data;
38+
39+
if (eth + 1 < data_end && (eth->h_proto == bpf_htons(ETH_P_8021AD) ||
40+
eth->h_proto == bpf_htons(ETH_P_8021Q)))
41+
eth = (void *)eth + sizeof(struct vlan_hdr);
42+
43+
if (eth + 1 < data_end && eth->h_proto == bpf_htons(ETH_P_8021Q))
44+
eth = (void *)eth + sizeof(struct vlan_hdr);
45+
3846
if (eth + 1 < data_end) {
3947
if (eth->h_proto == bpf_htons(ETH_P_IP)) {
4048
iph = (void *)(eth + 1);

tools/testing/selftests/bpf/xdp_metadata.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#define ETH_P_IPV6 0x86DD
1010
#endif
1111

12+
#ifndef ETH_P_8021Q
13+
#define ETH_P_8021Q 0x8100
14+
#endif
15+
16+
#ifndef ETH_P_8021AD
17+
#define ETH_P_8021AD 0x88A8
18+
#endif
19+
1220
struct xdp_meta {
1321
__u64 rx_timestamp;
1422
__u64 xdp_timestamp;

0 commit comments

Comments
 (0)