From: Stanislav Fomichev <sdf@google•com>
To: netdev@vger•kernel.org
Cc: davem@davemloft•net, ast@kernel•org, daniel@iogearbox•net,
simon.horman@netronome•com, willemb@google•com,
Stanislav Fomichev <sdf@google•com>
Subject: [RFC bpf-next 5/7] bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode
Date: Tue, 5 Feb 2019 09:36:27 -0800 [thread overview]
Message-ID: <20190205173629.160717-6-sdf@google.com> (raw)
In-Reply-To: <20190205173629.160717-1-sdf@google.com>
Now that we have __flow_bpf_dissect which works on raw data (by
constructing temporary on-stack skb), use it when doing
BPF_PROG_TEST_RUN for flow dissector.
This should help us catch any possible bugs due to missing shinfo on
the on-stack skb.
Note that existing __skb_flow_bpf_dissect swallows L2 headers and returns
nhoff=0, we need to preserve the existing behavior.
Signed-off-by: Stanislav Fomichev <sdf@google•com>
---
net/bpf/test_run.c | 52 +++++++++++++++-------------------------------
1 file changed, 17 insertions(+), 35 deletions(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 2c5172b33209..502ae0e866d3 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -249,10 +249,8 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
u32 repeat = kattr->test.repeat;
struct bpf_flow_keys flow_keys;
u64 time_start, time_spent = 0;
- struct bpf_skb_data_end *cb;
+ const struct ethhdr *eth;
u32 retval, duration;
- struct sk_buff *skb;
- struct sock *sk;
void *data;
int ret;
u32 i;
@@ -260,35 +258,14 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
if (prog->type != BPF_PROG_TYPE_FLOW_DISSECTOR)
return -EINVAL;
- data = bpf_test_init(kattr, size, NET_SKB_PAD + NET_IP_ALIGN,
- SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
+ if (size < ETH_HLEN)
+ return -EINVAL;
+
+ data = bpf_test_init(kattr, size, 0, 0);
if (IS_ERR(data))
return PTR_ERR(data);
- sk = kzalloc(sizeof(*sk), GFP_USER);
- if (!sk) {
- kfree(data);
- return -ENOMEM;
- }
- sock_net_set(sk, current->nsproxy->net_ns);
- sock_init_data(NULL, sk);
-
- skb = build_skb(data, 0);
- if (!skb) {
- kfree(data);
- kfree(sk);
- return -ENOMEM;
- }
- skb->sk = sk;
-
- skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
- __skb_put(skb, size);
- skb->protocol = eth_type_trans(skb,
- current->nsproxy->net_ns->loopback_dev);
- skb_reset_network_header(skb);
-
- cb = (struct bpf_skb_data_end *)skb->cb;
- cb->qdisc_cb.flow_keys = &flow_keys;
+ eth = (struct ethhdr *)data;
if (!repeat)
repeat = 1;
@@ -297,9 +274,15 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
for (i = 0; i < repeat; i++) {
preempt_disable();
rcu_read_lock();
- retval = __skb_flow_bpf_dissect(prog, skb,
- &flow_keys_dissector,
- &flow_keys);
+ retval = __flow_bpf_dissect(prog, data,
+ eth->h_proto, ETH_HLEN,
+ size,
+ &flow_keys_dissector,
+ &flow_keys);
+ if (flow_keys.nhoff >= ETH_HLEN)
+ flow_keys.nhoff -= ETH_HLEN;
+ if (flow_keys.thoff >= ETH_HLEN)
+ flow_keys.thoff -= ETH_HLEN;
rcu_read_unlock();
preempt_enable();
@@ -317,8 +300,7 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
ret = bpf_test_finish(kattr, uattr, &flow_keys, sizeof(flow_keys),
retval, duration);
-
- kfree_skb(skb);
- kfree(sk);
+ kfree(data);
return ret;
+
}
--
2.20.1.611.gfbb209baf1-goog
next prev parent reply other threads:[~2019-02-05 17:36 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-05 17:36 [RFC bpf-next 0/7] net: flow_dissector: trigger BPF hook when called from eth_get_headlen Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 1/7] net: introduce __init_skb and __init_skb_shinfo helpers Stanislav Fomichev
2019-02-05 20:18 ` Willem de Bruijn
2019-02-05 17:36 ` [RFC bpf-next 2/7] net: introduce skb_net helper Stanislav Fomichev
2019-02-05 20:19 ` Willem de Bruijn
2019-02-05 20:42 ` Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 3/7] net: plumb network namespace into __skb_flow_dissect Stanislav Fomichev
2019-02-05 20:19 ` Willem de Bruijn
2019-02-05 20:40 ` Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 4/7] net: flow_dissector: handle no-skb use case Stanislav Fomichev
2019-02-05 20:19 ` Willem de Bruijn
2019-02-05 20:45 ` Stanislav Fomichev
2019-02-05 17:36 ` Stanislav Fomichev [this message]
2019-02-05 20:19 ` [RFC bpf-next 5/7] bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode Willem de Bruijn
2019-02-05 17:36 ` [RFC bpf-next 6/7] selftests/bpf: add flow dissector bpf_skb_load_bytes helper test Stanislav Fomichev
2019-02-05 17:36 ` [RFC bpf-next 7/7] net: flow_dissector: pass net argument to the eth_get_headlen Stanislav Fomichev
2019-02-05 20:18 ` [RFC bpf-next 0/7] net: flow_dissector: trigger BPF hook when called from eth_get_headlen Willem de Bruijn
2019-02-05 20:40 ` Stanislav Fomichev
2019-02-06 0:47 ` Alexei Starovoitov
2019-02-06 0:59 ` Stanislav Fomichev
2019-02-06 3:12 ` Alexei Starovoitov
2019-02-06 3:56 ` Stanislav Fomichev
2019-02-06 4:11 ` Alexei Starovoitov
2019-02-06 5:49 ` Stanislav Fomichev
2019-02-12 17:02 ` Stanislav Fomichev
2019-02-14 4:39 ` Alexei Starovoitov
2019-02-14 5:57 ` Stanislav Fomichev
2019-02-14 6:38 ` Alexei Starovoitov
2019-02-14 17:35 ` Stanislav Fomichev
2019-02-25 20:33 ` Stanislav Fomichev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190205173629.160717-6-sdf@google.com \
--to=sdf@google$(echo .)com \
--cc=ast@kernel$(echo .)org \
--cc=daniel@iogearbox$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=netdev@vger$(echo .)kernel.org \
--cc=simon.horman@netronome$(echo .)com \
--cc=willemb@google$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox