[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200325055745.10710-3-joe@wand.net.nz>
Date:   Tue, 24 Mar 2020 22:57:42 -0700
From:   Joe Stringer <joe@...d.net.nz>
To:     bpf@...r.kernel.org
Cc:     netdev@...r.kernel.org, daniel@...earbox.net, ast@...nel.org,
        eric.dumazet@...il.com, lmb@...udflare.com, kafai@...com
Subject: [PATCHv2 bpf-next 2/5] bpf: Prefetch established socket destinations
Enhance the sk_assign logic to temporarily store the socket
receive destination, to save the route lookup later on. The dst
reference is kept alive by the caller's socket reference.
Suggested-by: Daniel Borkmann <daniel@...earbox.net>
Signed-off-by: Joe Stringer <joe@...d.net.nz>
---
v2: Provide cookie to dst_check() for IPv6 case
v1: Initial version
---
 net/core/filter.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff --git a/net/core/filter.c b/net/core/filter.c
index f7f9b6631f75..0fada7fe9b75 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5876,6 +5876,21 @@ BPF_CALL_3(bpf_sk_assign, struct sk_buff *, skb, struct sock *, sk, u64, flags)
 	skb_orphan(skb);
 	skb->sk = sk;
 	skb->destructor = sock_pfree;
+	if (sk_fullsock(sk)) {
+		struct dst_entry *dst = READ_ONCE(sk->sk_rx_dst);
+		u32 cookie = 0;
+
+#if IS_ENABLED(CONFIG_IPV6)
+		if (sk->sk_family == AF_INET6)
+			cookie = inet6_sk(sk)->rx_dst_cookie;
+#endif
+		if (dst)
+			dst = dst_check(dst, cookie);
+		if (dst) {
+			skb_dst_drop(skb);
+			skb_dst_set_noref(skb, dst);
+		}
+	}
 
 	return 0;
 }
-- 
2.20.1
Powered by blists - more mailing lists
 
