selftests/bpf: Allow VLAN packets in xdp_hw_metadata
authorLarysa Zaremba <larysa.zaremba@intel.com>
Tue, 5 Dec 2023 21:08:44 +0000 (22:08 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 14 Dec 2023 00:16:41 +0000 (16:16 -0800)
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>
tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
tools/testing/selftests/bpf/xdp_metadata.h

index f6d1cc9ad892991658309ac2ec19d754a4f0887d..8767d919c881b59228a3a9d93fd5bac06e6c8f64 100644 (file)
@@ -26,15 +26,23 @@ int rx(struct xdp_md *ctx)
 {
        void *data, *data_meta, *data_end;
        struct ipv6hdr *ip6h = NULL;
-       struct ethhdr *eth = NULL;
        struct udphdr *udp = NULL;
        struct iphdr *iph = NULL;
        struct xdp_meta *meta;
+       struct ethhdr *eth;
        int err;
 
        data = (void *)(long)ctx->data;
        data_end = (void *)(long)ctx->data_end;
        eth = data;
+
+       if (eth + 1 < data_end && (eth->h_proto == bpf_htons(ETH_P_8021AD) ||
+                                  eth->h_proto == bpf_htons(ETH_P_8021Q)))
+               eth = (void *)eth + sizeof(struct vlan_hdr);
+
+       if (eth + 1 < data_end && eth->h_proto == bpf_htons(ETH_P_8021Q))
+               eth = (void *)eth + sizeof(struct vlan_hdr);
+
        if (eth + 1 < data_end) {
                if (eth->h_proto == bpf_htons(ETH_P_IP)) {
                        iph = (void *)(eth + 1);
index 938a729bd3072f96dac570d04ab68cb9dcde0379..6664893c2c77db228a8e5c91f28d35a9404a63c1 100644 (file)
@@ -9,6 +9,14 @@
 #define ETH_P_IPV6 0x86DD
 #endif
 
+#ifndef ETH_P_8021Q
+#define ETH_P_8021Q 0x8100
+#endif
+
+#ifndef ETH_P_8021AD
+#define ETH_P_8021AD 0x88A8
+#endif
+
 struct xdp_meta {
        __u64 rx_timestamp;
        __u64 xdp_timestamp;