From patchwork Sat Aug 22 07:46:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guodeqing (A)" X-Patchwork-Id: 1349629 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BYVwZ0jrZz9sPB for ; Sat, 22 Aug 2020 17:52:30 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbgHVHw1 (ORCPT ); Sat, 22 Aug 2020 03:52:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57878 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727103AbgHVHw0 (ORCPT ); Sat, 22 Aug 2020 03:52:26 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id EAC197C982E4271AA703; Sat, 22 Aug 2020 15:52:24 +0800 (CST) Received: from huawei.com (10.179.179.12) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Sat, 22 Aug 2020 15:52:17 +0800 From: guodeqing To: CC: , , , Subject: [PATCH] ipv4: fix the problem of ping failure in some cases Date: Sat, 22 Aug 2020 15:46:37 +0800 Message-ID: <1598082397-115790-1-git-send-email-geffrey.guo@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.179.179.12] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ie., $ ifconfig eth0 9.9.9.9 netmask 255.255.255.0 $ ping -I lo 9.9.9.9 ping: Warning: source address might be selected on device other than lo. PING 9.9.9.9 (9.9.9.9) from 9.9.9.9 lo: 56(84) bytes of data. 4 packets transmitted, 0 received, 100% packet loss, time 3068ms This is because the return value of __raw_v4_lookup in raw_v4_input is null, the packets cannot be sent to the ping application. The reason of the __raw_v4_lookup failure is that sk_bound_dev_if and dif/sdif are not equal in raw_sk_bound_dev_eq. Here I add a check of whether the sk_bound_dev_if is LOOPBACK_IFINDEX to solve this problem. Fixes: 19e4e768064a8 ("ipv4: Fix raw socket lookup for local traffic") Signed-off-by: guodeqing --- include/net/inet_sock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index a3702d1..7707b1d 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -144,7 +144,7 @@ static inline bool inet_bound_dev_eq(bool l3mdev_accept, int bound_dev_if, { if (!bound_dev_if) return !sdif || l3mdev_accept; - return bound_dev_if == dif || bound_dev_if == sdif; + return bound_dev_if == dif || bound_dev_if == sdif || bound_dev_if == LOOPBACK_IFINDEX; } struct inet_cork {