Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <sdf@google.com>
Signed-off-by: Larysa Zaremba <larysa.zaremba@intel.com>
Link: https://lore.kernel.org/r/20231205210847.28460-16-larysa.zaremba@intel.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Larysa Zaremba and committed by
Alexei Starovoitov
e71a9fa7 7978bad4

+17 -1
+9 -1
tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
··· 26 26 { 27 27 void *data, *data_meta, *data_end; 28 28 struct ipv6hdr *ip6h = NULL; 29 - struct ethhdr *eth = NULL; 30 29 struct udphdr *udp = NULL; 31 30 struct iphdr *iph = NULL; 32 31 struct xdp_meta *meta; 32 + struct ethhdr *eth; 33 33 int err; 34 34 35 35 data = (void *)(long)ctx->data; 36 36 data_end = (void *)(long)ctx->data_end; 37 37 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 + 38 46 if (eth + 1 < data_end) { 39 47 if (eth->h_proto == bpf_htons(ETH_P_IP)) { 40 48 iph = (void *)(eth + 1);
+8
tools/testing/selftests/bpf/xdp_metadata.h
··· 9 9 #define ETH_P_IPV6 0x86DD 10 10 #endif 11 11 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 + 12 20 struct xdp_meta { 13 21 __u64 rx_timestamp; 14 22 __u64 xdp_timestamp;