Commit 0ba98502 authored by Shmulik Ladkani's avatar Shmulik Ladkani Committed by Daniel Borkmann

flow_dissector: Make 'bpf_flow_dissect' return the bpf program retcode

Let 'bpf_flow_dissect' callers know the BPF program's retcode and act
accordingly.
Signed-off-by: default avatarShmulik Ladkani <shmulik.ladkani@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarStanislav Fomichev <sdf@google.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220821113519.116765-2-shmulik.ladkani@gmail.com
parent b979f005
...@@ -1460,8 +1460,8 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector, ...@@ -1460,8 +1460,8 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
unsigned int key_count); unsigned int key_count);
struct bpf_flow_dissector; struct bpf_flow_dissector;
bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
__be16 proto, int nhoff, int hlen, unsigned int flags); __be16 proto, int nhoff, int hlen, unsigned int flags);
bool __skb_flow_dissect(const struct net *net, bool __skb_flow_dissect(const struct net *net,
const struct sk_buff *skb, const struct sk_buff *skb,
......
...@@ -1445,7 +1445,7 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, ...@@ -1445,7 +1445,7 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
bpf_test_timer_enter(&t); bpf_test_timer_enter(&t);
do { do {
retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN, retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN,
size, flags); size, flags) == BPF_OK;
} while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration)); } while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration));
bpf_test_timer_leave(&t); bpf_test_timer_leave(&t);
......
...@@ -866,8 +866,8 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys, ...@@ -866,8 +866,8 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
} }
} }
bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
__be16 proto, int nhoff, int hlen, unsigned int flags) __be16 proto, int nhoff, int hlen, unsigned int flags)
{ {
struct bpf_flow_keys *flow_keys = ctx->flow_keys; struct bpf_flow_keys *flow_keys = ctx->flow_keys;
u32 result; u32 result;
...@@ -892,7 +892,7 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx, ...@@ -892,7 +892,7 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
flow_keys->thoff = clamp_t(u16, flow_keys->thoff, flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
flow_keys->nhoff, hlen); flow_keys->nhoff, hlen);
return result == BPF_OK; return result;
} }
static bool is_pppoe_ses_hdr_valid(const struct pppoe_hdr *hdr) static bool is_pppoe_ses_hdr_valid(const struct pppoe_hdr *hdr)
...@@ -1008,6 +1008,7 @@ bool __skb_flow_dissect(const struct net *net, ...@@ -1008,6 +1008,7 @@ bool __skb_flow_dissect(const struct net *net,
}; };
__be16 n_proto = proto; __be16 n_proto = proto;
struct bpf_prog *prog; struct bpf_prog *prog;
u32 result;
if (skb) { if (skb) {
ctx.skb = skb; ctx.skb = skb;
...@@ -1019,12 +1020,12 @@ bool __skb_flow_dissect(const struct net *net, ...@@ -1019,12 +1020,12 @@ bool __skb_flow_dissect(const struct net *net,
} }
prog = READ_ONCE(run_array->items[0].prog); prog = READ_ONCE(run_array->items[0].prog);
ret = bpf_flow_dissect(prog, &ctx, n_proto, nhoff, result = bpf_flow_dissect(prog, &ctx, n_proto, nhoff,
hlen, flags); hlen, flags);
__skb_flow_bpf_to_target(&flow_keys, flow_dissector, __skb_flow_bpf_to_target(&flow_keys, flow_dissector,
target_container); target_container);
rcu_read_unlock(); rcu_read_unlock();
return ret; return result == BPF_OK;
} }
rcu_read_unlock(); rcu_read_unlock();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment