Received: by 10.213.65.68 with SMTP id h4csp2119780imn; Sun, 8 Apr 2018 20:11:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/vjwEznrXuDKSJPnEhLkFrlCBOEpNIggpzfT/+kX7IjBTefc3M55EgZw92m/KnI3ytvlU1 X-Received: by 2002:a17:902:ba94:: with SMTP id k20-v6mr2757053pls.193.1523243498903; Sun, 08 Apr 2018 20:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243498; cv=none; d=google.com; s=arc-20160816; b=zm1Tt5QptB4G58fGnNr2hPBURncH8S8vuLkMxlib7FmxZOpXRdtaxmSsGnhSq3D8f8 p5TbId4f7iLQSV4sbt1mdsFk7F2lIqJIUaYw+KbCl83h8GYUcoELY3KMu0wT/3g7xhRx 3QuB0nZFJHXMSMXl32D+KzyFi2P00HCM5es3sf/Lfac/qV0zv1KDN96rZWU59uhpzk3w 7L0I+rww3UfjUDjFGJllFH8uupLJA+STrPYVtGCfrX4i92/l+6697ehR1Crx2fChprYm 0cItxAgue7hwAM/rm1mkugHbQVsabdBZkPz9Qdd3ttBSZ/bQaFVHGshZpMi7fGM1Hza+ X0lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=cmx2D6I9z957SIdpCmAL/M2PubD7JYt9vCMfHSulPLQ=; b=e8VTuVu1DJFluRd/1pjMSJuWqq3hxHCEBFmhn27wWpJBNFpe2q84hk8MY+qmuEbcB1 0CSo0DzGqF62i5/Mx6s+WLMykDo6V2MU6gsLmCsT/nzLaDfeYcPBWT4JgCnHA1bsGnG2 n+SoUZ/Oh0sha7ZRc1nbiilH9Gk0hLVRFE34KQ6EKWhnkY4Di2/ysHyBiHqYj3FkD7OM 3lNQQ6+GCgHF0f3syuqLSI+GGyXxa/iH8GanV+Bj2LZnJc3f9mQJv3kYTykf/6hpvyCw w5LHoiA+nt9Bh9vR4DWR1w/Fdg1RBBUwfwXfLeE4z9sOZ/g1QSGGn4xCBI7830xRhiOg CKpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=CH5saQqO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w23si10720054pgc.419.2018.04.08.20.11.02; Sun, 08 Apr 2018 20:11:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=CH5saQqO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932328AbeDICYK (ORCPT + 99 others); Sun, 8 Apr 2018 22:24:10 -0400 Received: from mail-by2nam03on0107.outbound.protection.outlook.com ([104.47.42.107]:6816 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754987AbeDIA3f (ORCPT ); Sun, 8 Apr 2018 20:29:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cmx2D6I9z957SIdpCmAL/M2PubD7JYt9vCMfHSulPLQ=; b=CH5saQqOgCDB4nuR9+f1OrV4ITa60nzi9CTDwRL4C66lgoNL/gbia2RquKXA3n5cuHPJ5gcWY9GiV6ba0ykXKIVy9fGv9JLdwGapGIxae8Opt3eQzQd0GBgDM+isFMIb4BtmLrW5KwC7KcfE5qWm9ZzRUb7Sedzim8vHMjdfKmQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0967.namprd21.prod.outlook.com (52.132.133.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:29:32 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:29:32 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Serhey Popovych , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 105/293] fib_rules: Resolve goto rules target on delete Thread-Topic: [PATCH AUTOSEL for 4.9 105/293] fib_rules: Resolve goto rules target on delete Thread-Index: AQHTz5kXvtbgERsx7Ees68HC9pKd4Q== Date: Mon, 9 Apr 2018 00:24:15 +0000 Message-ID: <20180409002239.163177-105-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0967;7:DQuZp2/mRWcDBrPQ4AGA9mnQRgevhpgKVD9xUD8PXuEQD1kHKqQ7BeCHsCrdycHpzqG4aDuJ0QfXHE4rs0953er51wP4YzSI5hgb4s3tcirc4yI7K134uagcGebCcm7zkmKCHYPxpcKJnXXiy/o5iIrWe+lFXnKjZbCY0js01kcat/kf+u6CzTERSc/w9WKFgC7bPLOxvmJABdIQ1PhdkS3oGKcCfYJoZnCym+AjkZVFMICFjZCQMAupzqTahy/E;20:6q5y2/LMkCadTFa9eE5P55+MVT11oR1bo/DvDxuOcKMij/j38dcDDDdy9pKs1Jojc8z5uCL/K7tcA5qs8B+omvNeoZUlHio80CDQkfL9wcZOwWsRm1FSVEhFSbWumUs/84zZBURdzXlamdNi8QP6RtrVWQj/2FSdwgzAfYo9lZw= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 9d6ec2d0-e328-40e5-c182-08d59db0f6e1 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0967; x-ms-traffictypediagnostic: DM5PR2101MB0967: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB0967;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0967; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(376002)(39380400002)(346002)(199004)(189003)(6506007)(486006)(575784001)(86362001)(14454004)(59450400001)(68736007)(102836004)(99286004)(26005)(3846002)(6116002)(186003)(476003)(2616005)(1076002)(3280700002)(86612001)(72206003)(4326008)(446003)(54906003)(76176011)(11346002)(2906002)(22452003)(3660700001)(110136005)(97736004)(316002)(6666003)(5660300001)(478600001)(8676002)(6512007)(8936002)(39060400002)(107886003)(6486002)(53936002)(81166006)(36756003)(81156014)(10290500003)(6436002)(10090500001)(25786009)(66066001)(106356001)(305945005)(7736002)(2501003)(5250100002)(105586002)(2900100001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0967;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: TneFZb5nXgtL5WU+woU2Xv0svtezJu676ah1QlrpxymMRXjYBg5ZBlaq4S44OuUeRsz/tuwGNb3+Bv0yUfZ0EoOmnOvgS8cOWuNXgiTD3fHXvv1LKNpuDJ5MP1ITMmyypoScwA9q95uuXh324beCU5d01bdKiggOlsOtLN/Ip+7uhRV5+Be4+zmxv4LO8txKE9RT1IlQnK+oYQv4mbqBj58ZVEEY1rYzRC2ysN9OXcayOqDswRC0KZIZJTkkUUr9JuHFpUEZJ+x4ZX/d1g2jyJ/yFzUBGtn9rCLt7d9iq0XBB6UrKrDsQ+h8zFfW6nb/dqTmzdjl9lv6R1a+GX2xEBvrgFezFD+S3bMZzS3Wd+LsIQGOnTQTwSrfPFzjmoVDq6eEyfYDENwqkneoMQkkHguikOoH23bIgvAtOVUBWTk= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d6ec2d0-e328-40e5-c182-08d59db0f6e1 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:15.6906 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0967 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serhey Popovych [ Upstream commit bdaf32c3ced3d111b692f0af585f880f82d686c5 ] We should avoid marking goto rules unresolved when their target is actually reachable after rule deletion. Consolder following sample scenario: # ip -4 ru sh 0: from all lookup local 32000: from all goto 32100 32100: from all lookup main 32100: from all lookup default 32766: from all lookup main 32767: from all lookup default # ip -4 ru del pref 32100 table main # ip -4 ru sh 0: from all lookup local 32000: from all goto 32100 [unresolved] 32100: from all lookup default 32766: from all lookup main 32767: from all lookup default After removal of first rule with preference 32100 we mark all goto rules as unreachable, even when rule with same preference as removed one still present. Check if next rule with same preference is available and make all rules with goto action pointing to it. Signed-off-by: Serhey Popovych Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/fib_rules.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index be4629c344a6..4524bfe7230b 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -495,7 +495,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr= *nlh) struct net *net =3D sock_net(skb->sk); struct fib_rule_hdr *frh =3D nlmsg_data(nlh); struct fib_rules_ops *ops =3D NULL; - struct fib_rule *rule, *tmp; + struct fib_rule *rule, *r; struct nlattr *tb[FRA_MAX+1]; int err =3D -EINVAL; =20 @@ -579,16 +579,23 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsgh= dr *nlh) =20 /* * Check if this rule is a target to any of them. If so, + * adjust to the next one with the same preference or * disable them. As this operation is eventually very - * expensive, it is only performed if goto rules have - * actually been added. + * expensive, it is only performed if goto rules, except + * current if it is goto rule, have actually been added. */ if (ops->nr_goto_rules > 0) { - list_for_each_entry(tmp, &ops->rules_list, list) { - if (rtnl_dereference(tmp->ctarget) =3D=3D rule) { - RCU_INIT_POINTER(tmp->ctarget, NULL); + struct fib_rule *n; + + n =3D list_next_entry(rule, list); + if (&n->list =3D=3D &ops->rules_list || n->pref !=3D rule->pref) + n =3D NULL; + list_for_each_entry(r, &ops->rules_list, list) { + if (rtnl_dereference(r->ctarget) !=3D rule) + continue; + rcu_assign_pointer(r->ctarget, n); + if (!n) ops->unresolved_rules++; - } } } =20 --=20 2.15.1