net: Track socket refcounts in skb_steal_sock()

Refactor the UDP/TCP handlers slightly to allow skb_steal_sock() to make
the determination of whether the socket is reference counted in the case
where it is prefetched by earlier logic such as early_demux.

Signed-off-by: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200329225342.16317-3-joe@wand.net.nz
This commit is contained in:
Joe Stringer
2020-03-29 15:53:39 -07:00
committed by Alexei Starovoitov
parent cf7fbe660f
commit 71489e21d7
5 changed files with 21 additions and 10 deletions

View File

@@ -2537,15 +2537,23 @@ skb_sk_is_prefetched(struct sk_buff *skb)
#endif /* CONFIG_INET */
}
static inline struct sock *skb_steal_sock(struct sk_buff *skb)
/**
* skb_steal_sock
* @skb to steal the socket from
* @refcounted is set to true if the socket is reference-counted
*/
static inline struct sock *
skb_steal_sock(struct sk_buff *skb, bool *refcounted)
{
if (skb->sk) {
struct sock *sk = skb->sk;
*refcounted = true;
skb->destructor = NULL;
skb->sk = NULL;
return sk;
}
*refcounted = false;
return NULL;
}