Skip to content

Commit

Permalink
selftests/bpf: fix compilation failure when CONFIG_NF_FLOW_TABLE=m
Browse files Browse the repository at this point in the history
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: c77e572 ("selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc")
Signed-off-by: Alan Maguire <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
alan-maguire authored and Alexei Starovoitov committed Jul 10, 2024
1 parent c13fda9 commit eeb23b5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/testing/selftests/bpf/progs/xdp_flowtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ static bool xdp_flowtable_offload_check_tcp_state(void *ports, void *data_end,
return true;
}

struct flow_ports___local {
__be16 source, dest;
} __attribute__((preserve_access_index));

SEC("xdp.frags")
int xdp_flowtable_do_lookup(struct xdp_md *ctx)
{
Expand All @@ -69,7 +73,7 @@ int xdp_flowtable_do_lookup(struct xdp_md *ctx)
};
void *data = (void *)(long)ctx->data;
struct ethhdr *eth = data;
struct flow_ports *ports;
struct flow_ports___local *ports;
__u32 *val, key = 0;

if (eth + 1 > data_end)
Expand All @@ -79,7 +83,7 @@ int xdp_flowtable_do_lookup(struct xdp_md *ctx)
case bpf_htons(ETH_P_IP): {
struct iphdr *iph = data + sizeof(*eth);

ports = (struct flow_ports *)(iph + 1);
ports = (struct flow_ports___local *)(iph + 1);
if (ports + 1 > data_end)
return XDP_PASS;

Expand All @@ -106,7 +110,7 @@ int xdp_flowtable_do_lookup(struct xdp_md *ctx)
struct in6_addr *dst = (struct in6_addr *)tuple.ipv6_dst;
struct ipv6hdr *ip6h = data + sizeof(*eth);

ports = (struct flow_ports *)(ip6h + 1);
ports = (struct flow_ports___local *)(ip6h + 1);
if (ports + 1 > data_end)
return XDP_PASS;

Expand Down

0 comments on commit eeb23b5

Please sign in to comment.