diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index e238b17f554cc150e36e1430f238af194f9e9b55..02a899bec1969fcb6511722d41fe20009b6f2dbc 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -514,12 +514,15 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info) saddr = iph->daddr; if (!(rt->rt_flags & RTCF_LOCAL)) { - /* This is broken, skb_in->dev points to the outgoing device - * after the packet passes through ip_output(). - */ - if (skb_in->dev && sysctl_icmp_errors_use_inbound_ifaddr) - saddr = inet_select_addr(skb_in->dev, 0, RT_SCOPE_LINK); - else + struct net_device *dev = NULL; + + if (rt->fl.iif && sysctl_icmp_errors_use_inbound_ifaddr) + dev = dev_get_by_index(rt->fl.iif); + + if (dev) { + saddr = inet_select_addr(dev, 0, RT_SCOPE_LINK); + dev_put(dev); + } else saddr = 0; }