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

selftests/bpf: fix compilation failure when CONFIG_NF_FLOW_TABLE=m

In many cases, kernel netfilter functionality is built as modules.
If CONFIG_NF_FLOW_TABLE=m in particular, progs/xdp_flowtable.c
(and hence selftests) will fail to compile, so add a ___local
version of "struct flow_ports".

Fixes: c77e572d3a8c ("selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc")
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Link: https://lore.kernel.org/r/20240710150051.192598-1-alan.maguire@oracle.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Alan Maguire and committed by
Alexei Starovoitov
eeb23b54 c13fda93

+7 -3
+7 -3
tools/testing/selftests/bpf/progs/xdp_flowtable.c
··· 58 58 return true; 59 59 } 60 60 61 + struct flow_ports___local { 62 + __be16 source, dest; 63 + } __attribute__((preserve_access_index)); 64 + 61 65 SEC("xdp.frags") 62 66 int xdp_flowtable_do_lookup(struct xdp_md *ctx) 63 67 { ··· 73 69 }; 74 70 void *data = (void *)(long)ctx->data; 75 71 struct ethhdr *eth = data; 76 - struct flow_ports *ports; 72 + struct flow_ports___local *ports; 77 73 __u32 *val, key = 0; 78 74 79 75 if (eth + 1 > data_end) ··· 83 79 case bpf_htons(ETH_P_IP): { 84 80 struct iphdr *iph = data + sizeof(*eth); 85 81 86 - ports = (struct flow_ports *)(iph + 1); 82 + ports = (struct flow_ports___local *)(iph + 1); 87 83 if (ports + 1 > data_end) 88 84 return XDP_PASS; 89 85 ··· 110 106 struct in6_addr *dst = (struct in6_addr *)tuple.ipv6_dst; 111 107 struct ipv6hdr *ip6h = data + sizeof(*eth); 112 108 113 - ports = (struct flow_ports *)(ip6h + 1); 109 + ports = (struct flow_ports___local *)(ip6h + 1); 114 110 if (ports + 1 > data_end) 115 111 return XDP_PASS; 116 112