Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d24406c8 authored by Wei Wang's avatar Wei Wang Committed by David S. Miller
Browse files

udp: call dst_hold_safe() in udp_sk_rx_set_dst()



In udp_v4/6_early_demux() code, we try to hold dst->__refcnt for
dst with DST_NOCACHE flag. This is because later in udp_sk_rx_dst_set()
function, we will try to cache this dst in sk for connected case.
However, a better way to achieve this is to not try to hold dst in
early_demux(), but in udp_sk_rx_dst_set(), call dst_hold_safe(). This
approach is also more consistant with how tcp is handling it. And it
will make later changes simpler.

Signed-off-by: default avatarWei Wang <weiwan@google.com>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1758fd46
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -1977,10 +1977,11 @@ static void udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
{
	struct dst_entry *old;

	dst_hold(dst);
	if (dst_hold_safe(dst)) {
		old = xchg(&sk->sk_rx_dst, dst);
		dst_release(old);
	}
}

/*
 *	Multicasts and broadcasts go to each listener.
@@ -2303,15 +2304,13 @@ void udp_v4_early_demux(struct sk_buff *skb)
	if (dst)
		dst = dst_check(dst, 0);
	if (dst) {
		/* DST_NOCACHE can not be used without taking a reference */
		if (dst->flags & DST_NOCACHE) {
			if (likely(atomic_inc_not_zero(&dst->__refcnt)))
				skb_dst_set(skb, dst);
		} else {
		/* set noref for now.
		 * any place which wants to hold dst has to call
		 * dst_hold_safe()
		 */
		skb_dst_set_noref(skb, dst);
	}
}
}

int udp_rcv(struct sk_buff *skb)
{
+5 −6
Original line number Diff line number Diff line
@@ -920,14 +920,13 @@ static void udp_v6_early_demux(struct sk_buff *skb)
	if (dst)
		dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie);
	if (dst) {
		if (dst->flags & DST_NOCACHE) {
			if (likely(atomic_inc_not_zero(&dst->__refcnt)))
				skb_dst_set(skb, dst);
		} else {
		/* set noref for now.
		 * any place which wants to hold dst has to call
		 * dst_hold_safe()
		 */
		skb_dst_set_noref(skb, dst);
	}
}
}

static __inline__ int udpv6_rcv(struct sk_buff *skb)
{