From: Dmitry Yakunin <zeil@yandex-team.ru>
To: alexei.starovoitov@gmail.com, daniel@iogearbox.net,
netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: sdf@google.com
Subject: [PATCH bpf-next v5 1/2] bpf: setup socket family and addresses in bpf_prog_test_run_skb
Date: Mon, 3 Aug 2020 00:30:25 +0300 [thread overview]
Message-ID: <20200802213026.78731-2-zeil@yandex-team.ru> (raw)
In-Reply-To: <20200802213026.78731-1-zeil@yandex-team.ru>
Now it's impossible to test all branches of cgroup_skb bpf program which
accesses skb->family and skb->{local,remote}_ip{4,6} fields because they
are zeroed during socket allocation. This commit fills socket family and
addresses from related fields in constructed skb.
v2:
- fix build without CONFIG_IPV6 (kernel test robot <lkp@intel.com>)
v3:
- check skb length before access to inet headers (Eric Dumazet)
Signed-off-by: Dmitry Yakunin <zeil@yandex-team.ru>
---
net/bpf/test_run.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index b03c469..8d69295 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -449,6 +449,27 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
skb->protocol = eth_type_trans(skb, current->nsproxy->net_ns->loopback_dev);
skb_reset_network_header(skb);
+ switch (skb->protocol) {
+ case htons(ETH_P_IP):
+ sk->sk_family = AF_INET;
+ if (pskb_may_pull(skb, sizeof(struct iphdr))) {
+ sk->sk_rcv_saddr = ip_hdr(skb)->saddr;
+ sk->sk_daddr = ip_hdr(skb)->daddr;
+ }
+ break;
+#if IS_ENABLED(CONFIG_IPV6)
+ case htons(ETH_P_IPV6):
+ sk->sk_family = AF_INET6;
+ if (pskb_may_pull(skb, sizeof(struct ipv6hdr))) {
+ sk->sk_v6_rcv_saddr = ipv6_hdr(skb)->saddr;
+ sk->sk_v6_daddr = ipv6_hdr(skb)->daddr;
+ }
+ break;
+#endif
+ default:
+ break;
+ }
+
if (is_l2)
__skb_push(skb, hh_len);
if (is_direct_pkt_access)
--
2.7.4
next prev parent reply other threads:[~2020-08-02 21:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-02 21:30 [PATCH bpf-next v4 0/2] bpf: cgroup skb improvements for bpf_prog_test_run Dmitry Yakunin
2020-08-02 21:30 ` Dmitry Yakunin [this message]
2020-08-02 21:30 ` [PATCH bpf-next v5 2/2] bpf: allow to specify ifindex for skb in bpf_prog_test_run_skb Dmitry Yakunin
2020-08-02 21:35 ` [PATCH bpf-next v4 0/2] bpf: cgroup skb improvements for bpf_prog_test_run Dmitry Yakunin
2020-08-02 21:36 [PATCH bpf-next v5 " Dmitry Yakunin
2020-08-02 21:36 ` [PATCH bpf-next v5 1/2] bpf: setup socket family and addresses in bpf_prog_test_run_skb Dmitry Yakunin
2020-08-02 22:48 ` Alexei Starovoitov
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=20200802213026.78731-2-zeil@yandex-team.ru \
--to=zeil@yandex-team.ru \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).