diff --git a/drivers/net/wireguard/socket.c b/drivers/net/wireguard/socket.c
index ee7d9c675909..b311965269a1 100644
--- a/drivers/net/wireguard/socket.c
+++ b/drivers/net/wireguard/socket.c
@@ -46,7 +46,7 @@ static int send4(struct wg_device *wg, struct sk_buff *skb,
fl.fl4_sport = inet_sk(sock)->inet_sport;
if (cache)
- rt = dst_cache_get_ip4(cache, &fl.saddr);
+ rt = dst_cache_get_ip4_rcu(cache, &fl.saddr);
if (!rt) {
security_sk_classify_flow(sock, flowi4_to_flowi_common(&fl));@@ -78,14 +78,15 @@ static int send4(struct wg_device *wg, struct sk_buff *skb,
goto err;
}
if (cache)
- dst_cache_set_ip4(cache, &rt->dst, fl.saddr);
+ dst_cache_steal_ip4(cache, &rt->dst, fl.saddr);
}
skb->ignore_df = 1;
udp_tunnel_xmit_skb(rt, sock, skb, fl.saddr, fl.daddr, ds,
ip4_dst_hoplimit(&rt->dst), 0, fl.fl4_sport,
fl.fl4_dport, false, false, 0);
- ip_rt_put(rt);
+ if (!cache)
+ ip_rt_put(rt);
goto out;
err:
@@ -127,7 +128,7 @@ static int send6(struct wg_device *wg, struct sk_buff *skb,
fl.fl6_sport = inet_sk(sock)->inet_sport;
if (cache)
- dst = dst_cache_get_ip6(cache, &fl.saddr);
+ dst = dst_cache_get_ip6_rcu(cache, &fl.saddr);
if (!dst) {
security_sk_classify_flow(sock, flowi6_to_flowi_common(&fl));@@ -146,14 +147,15 @@ static int send6(struct wg_device *wg, struct sk_buff *skb,
goto err;
}
if (cache)
- dst_cache_set_ip6(cache, dst, &fl.saddr);
+ dst_cache_steal_ip6(cache, dst, &fl.saddr);
}
skb->ignore_df = 1;
udp_tunnel6_xmit_skb(dst, sock, skb, skb->dev, &fl.saddr, &fl.daddr, ds,
ip6_dst_hoplimit(dst), 0, fl.fl6_sport,
fl.fl6_dport, false, 0);
- dst_release(dst);
+ if (!cache)
+ dst_release(dst);
goto out;
err:
--
2.51.0