Skip to content

Commit 9cb3a50

Browse files
klassertdavem330
authored andcommitted
ipv4: Invalidate the socket cached route on pmtu events if possible
The route lookup in ipv4_sk_update_pmtu() might return a route different from the route we cached at the socket. This is because standart routes are per cpu, so each cpu has it's own struct rtable. This means that we do not invalidate the socket cached route if the NET_RX_SOFTIRQ is not served by the same cpu that the sending socket uses. As a result, the cached route reused until we disconnect. With this patch we invalidate the socket cached route if possible. If the socket is owened by the user, we can't update the cached route directly. A followup patch will implement socket release callback functions for datagram sockets to handle this case. Reported-by: Yurij M. Plotnikov <Yurij.Plotnikov@oktetlabs.ru> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent bc9540c commit 9cb3a50

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

‎net/ipv4/route.c‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ void ipv4_update_pmtu(struct sk_buff *skb, struct net *net, u32 mtu,
965965
}
966966
EXPORT_SYMBOL_GPL(ipv4_update_pmtu);
967967

968-
void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
968+
static void __ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
969969
{
970970
const struct iphdr *iph = (const struct iphdr *) skb->data;
971971
struct flowi4 fl4;
@@ -978,6 +978,46 @@ void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
978978
ip_rt_put(rt);
979979
}
980980
}
981+
982+
void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
983+
{
984+
const struct iphdr *iph = (const struct iphdr *) skb->data;
985+
struct flowi4 fl4;
986+
struct rtable *rt;
987+
struct dst_entry *dst;
988+
989+
bh_lock_sock(sk);
990+
rt = (struct rtable *) __sk_dst_get(sk);
991+
992+
if (sock_owned_by_user(sk) || !rt) {
993+
__ipv4_sk_update_pmtu(skb, sk, mtu);
994+
goto out;
995+
}
996+
997+
__build_flow_key(&fl4, sk, iph, 0, 0, 0, 0, 0);
998+
999+
if (!__sk_dst_check(sk, 0)) {
1000+
rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
1001+
if (IS_ERR(rt))
1002+
goto out;
1003+
}
1004+
1005+
__ip_rt_update_pmtu((struct rtable *) rt->dst.path, &fl4, mtu);
1006+
1007+
dst = dst_check(&rt->dst, 0);
1008+
if (!dst) {
1009+
rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
1010+
if (IS_ERR(rt))
1011+
goto out;
1012+
1013+
dst = &rt->dst;
1014+
}
1015+
1016+
__sk_dst_set(sk, dst);
1017+
1018+
out:
1019+
bh_unlock_sock(sk);
1020+
}
9811021
EXPORT_SYMBOL_GPL(ipv4_sk_update_pmtu);
9821022

9831023
void ipv4_redirect(struct sk_buff *skb, struct net *net,

0 commit comments

Comments
 (0)