Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp469810yba; Wed, 15 May 2019 04:41:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxT/GTKXsyFfOfECB29pGOz4yfapEEsIeFZmDWDm1DuiDsZLYw985/ZPA2YCeDXXa1Q56vI X-Received: by 2002:a63:171c:: with SMTP id x28mr43249327pgl.12.1557920482757; Wed, 15 May 2019 04:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920482; cv=none; d=google.com; s=arc-20160816; b=FKOv5b0nQsxRqYZ+FQYCTgeEyfKWuTOiv0rTU8EdKo9Y8SsK4mABgQzU2iSBCvZmkg 7Mae3ipJR94CPOMgPM6mgGx7bLU127kIxRUmiz1KlD1t/Ekju55rudmYHTY3GOihDV82 JyVTSYlVvWUkL9L/g/egaHU9+p1K6WfJk6GrFy3AsZVGt74zkAwuOnW5aimWpLZJqTYK lTkmprmDQqkiv9oRuK0UGHCAv9hk4cGFKCxdFPbV3jetYCvcVcm07a8CkxCDnzDQ3Hpk tlw50Ssu0ilqDu+iIgU6p9ntCzOgyHJevxASDCS5dYytVQYwbBlgHgfaB0fxlXAmTRMf +tfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=18IIsuTQBxl+esXsWZ9axA0YyUaigshw9ycYvNVu7cw=; b=n8DbdfwAtJIL5+pOoyU0JYItg6W+DQFM+PvDMWnjrJuwhP79G9ZMkBFl3knOQ3uE29 3U/9el8aGut3u9J8ZBPgjwokQlyxGQLaJSYKlJAbuQULs6rYW60aJxW/Vb6pxj24jFZi 6E51hLmsj9rlG9k7E++H6TCKMMSpUo7fusAt7+gbM7fkNr4q+/1tQ97W839a9LTSZdKb VzQHNbq8td/s34LKuqwpS+hVQeB7tOXhZUSAsksnDQSv5pq1NiGbC+hqUhJH3nkW2L5N mHx93AaZ+SHV9yNYJS/KKEyyX8DSOwqm6OjMKSZLs0kLN+rseJOXkIhJbDDLwNhg89vT t6ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="aiUlz/Y0"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10si1581532pgb.464.2019.05.15.04.41.08; Wed, 15 May 2019 04:41:22 -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=@kernel.org header.s=default header.b="aiUlz/Y0"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730486AbfEOLah (ORCPT + 99 others); Wed, 15 May 2019 07:30:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:42042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732730AbfEOLa3 (ORCPT ); Wed, 15 May 2019 07:30:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1FCF92084A; Wed, 15 May 2019 11:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919828; bh=kndu8SAtUtlE6O5XFX8Lvk1NrcXtcxLc7hvEAE7f7uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aiUlz/Y0lVSpQts8FqofY6rb3OhjvAs18FMoDWpGhwN8nYb8CEtTovd6t5HnjbHro ccMaROoMjaI7TsSgkEmaxvS9anewdNwK0UfXF4G5x2PnwyXbKTT57GMHQwhBjB+AMn nPE6HLOAwa3xWl1ypzG43nd/U/+c4+r8FUbh2Eh4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Haller , Hangbin Liu , "David S. Miller" Subject: [PATCH 5.0 108/137] fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied Date: Wed, 15 May 2019 12:56:29 +0200 Message-Id: <20190515090701.414733828@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hangbin Liu [ Upstream commit e9919a24d3022f72bcadc407e73a6ef17093a849 ] With commit 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule") we now able to check if a rule already exists. But this only works with iproute2. For other tools like libnl, NetworkManager, it still could add duplicate rules with only NLM_F_CREATE flag, like [localhost ~ ]# ip rule 0: from all lookup local 32766: from all lookup main 32767: from all lookup default 100000: from 192.168.7.5 lookup 5 100000: from 192.168.7.5 lookup 5 As it doesn't make sense to create two duplicate rules, let's just return 0 if the rule exists. Fixes: 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule") Reported-by: Thomas Haller Signed-off-by: Hangbin Liu Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/fib_rules.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -756,9 +756,9 @@ int fib_nl_newrule(struct sk_buff *skb, if (err) goto errout; - if ((nlh->nlmsg_flags & NLM_F_EXCL) && - rule_exists(ops, frh, tb, rule)) { - err = -EEXIST; + if (rule_exists(ops, frh, tb, rule)) { + if (nlh->nlmsg_flags & NLM_F_EXCL) + err = -EEXIST; goto errout_free; }