From patchwork Sat May 4 08:03:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 1095156 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=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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 [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44x1jY2Nt1z9s6w for ; Sat, 4 May 2019 18:04:01 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbfEDIDv (ORCPT ); Sat, 4 May 2019 04:03:51 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7719 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726258AbfEDIDv (ORCPT ); Sat, 4 May 2019 04:03:51 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 344A468EBF5E222164BB; Sat, 4 May 2019 16:03:47 +0800 (CST) Received: from [127.0.0.1] (10.184.189.20) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Sat, 4 May 2019 16:03:40 +0800 From: linmiaohe Subject: [PATCH] net: route: Fix vrf dst_entry ref count false increasing To: , , , , , , CC: mousuanming , Mingfangsen Message-ID: <76551ed7-47ef-7442-69de-6fb42fff4708@huawei.com> Date: Sat, 4 May 2019 16:03:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [10.184.189.20] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Suanming.Mou When config ip in default vrf same as the ip in specified vrf, fib_lookup will return the route from table local even if the in device is an enslaved l3mdev. Then the dst_entry will hold the vrf device rather than loopback device in local_input of function ip_route_input_slow. So vrf dst_entry is false increased by route from table local. Here is reproduce step: 1.enslave enp4s0 to vrf2, and config ip address: ip link add vrf2 type vrf table 1 ip link set vrf2 up ip link set enp4s0 master vrf2 ip addr ad 125.1.1.1/16 dev enp4s0 2.config same ip in default vrf: ip addr ad 125.1.1.1/16 dev enp6s0 3.config peer and ping: ip vrf exec vrf2 ping 125.1.1.2 -c 3 4.del vrf2 link: ip link del vrf2 And "unregister_netdevice: waiting for vrf2 to become free. Usage count = 1" will occur. Signed-off-by: Suanming.Mou Signed-off-by: Miaohe Lin --- net/core/fib_rules.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index ffbb827723a2..1a2c11ed1585 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -263,6 +263,11 @@ static int fib_rule_match(struct fib_rule *rule, struct fib_rules_ops *ops, if (rule->tun_id && (rule->tun_id != fl->flowi_tun_key.tun_id)) goto out; + if (!rule->l3mdev && + (netif_index_is_l3_master(rule->fr_net, fl->flowi_iif) || + netif_index_is_l3_master(rule->fr_net, fl->flowi_oif))) + goto out; + if (rule->l3mdev && !l3mdev_fib_rule_match(rule->fr_net, fl, arg)) goto out;