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:
@@ -2288,6 +2288,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
|
||||
struct rtable *rt = skb_rtable(skb);
|
||||
__be32 saddr, daddr;
|
||||
struct net *net = dev_net(skb->dev);
|
||||
bool refcounted;
|
||||
|
||||
/*
|
||||
* Validate the packet.
|
||||
@@ -2313,7 +2314,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
|
||||
if (udp4_csum_init(skb, uh, proto))
|
||||
goto csum_error;
|
||||
|
||||
sk = skb_steal_sock(skb);
|
||||
sk = skb_steal_sock(skb, &refcounted);
|
||||
if (sk) {
|
||||
struct dst_entry *dst = skb_dst(skb);
|
||||
int ret;
|
||||
@@ -2322,7 +2323,8 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
|
||||
udp_sk_rx_dst_set(sk, dst);
|
||||
|
||||
ret = udp_unicast_rcv_skb(sk, skb, uh);
|
||||
sock_put(sk);
|
||||
if (refcounted)
|
||||
sock_put(sk);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user