ipv4: Fix raw socket lookup for local traffic
authorDavid Ahern <dsahern@gmail.com>
Wed, 8 May 2019 03:44:59 +0000 (20:44 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 May 2019 17:41:29 +0000 (19:41 +0200)
[ Upstream commit 19e4e768064a87b073a4b4c138b55db70e0cfb9f ]

inet_iif should be used for the raw socket lookup. inet_iif considers
rt_iif which handles the case of local traffic.

As it stands, ping to a local address with the '-I <dev>' option fails
ever since ping was changed to use SO_BINDTODEVICE instead of
cmsg + IP_PKTINFO.

IPv6 works fine.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/raw.c

index 33df4d7..711a5c7 100644 (file)
@@ -174,6 +174,7 @@ static int icmp_filter(const struct sock *sk, const struct sk_buff *skb)
 static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
 {
        int sdif = inet_sdif(skb);
+       int dif = inet_iif(skb);
        struct sock *sk;
        struct hlist_head *head;
        int delivered = 0;
@@ -186,8 +187,7 @@ static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash)
 
        net = dev_net(skb->dev);
        sk = __raw_v4_lookup(net, __sk_head(head), iph->protocol,
-                            iph->saddr, iph->daddr,
-                            skb->dev->ifindex, sdif);
+                            iph->saddr, iph->daddr, dif, sdif);
 
        while (sk) {
                delivered = 1;