Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp468650yba; Wed, 15 May 2019 04:39:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfP0MQTjJss/dfAcGCfxdF5QgkQJeg8idi8rrd9hGInkYoEv7EMJ1nu26L/hwhFyBrDo5A X-Received: by 2002:a17:902:8c85:: with SMTP id t5mr43496451plo.23.1557920388961; Wed, 15 May 2019 04:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920388; cv=none; d=google.com; s=arc-20160816; b=ErgUZnRXz2S8J7s13qsKkWPAeENZt3B7aZ1PCxBl9N8bKYWbzU0D9DY3qlq//qQnUX 5S9rtFZQuY7uk6m4mC+LPH1voS/U5alSgxtQZY09tXzTMZqr0Sa/ZDuO2xxYWqeNGILD /u6LOTzW+MxsqTeTXA8ZboDZV9I+5f5qEzotNzXDQhXABzxrI186BvkNkNCDr6wey58B JUqxuwjL8zcTyt5OBxcgVBaEHP1xTgWuqLXYQuQWn7dENbDkLeNpguArapE4eXht7nKe IrF0xsNJhY/hJBrzjB/1LQ66sHd8lpgWC3dZdQPP7Q/eB4c1VEye2GIdB/c2moeDSv6D a7nQ== 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=HO5lne5XfA7uhc/iSVS8U4jzbBtks/pZnVYxHHPE2oSH/Fx7boYKdT98OCVMVKwteU iaTBgBDkvFyI6tSDjlGzXw1GUtCI6RqqhQ3A32D9xanGerK1CYROUhXRh9fO2FVfuqB9 P9SS7fIgofIVcYOLOUD0xdQk/Ztmi0oo2nPoALSUh2EVIiHoCDberDXOp6N43Jk1pBQk v5HzRp2jtfLFRQPoCIrkIZJktk3cW2x9mk/86AsWITbZ5SEOF6EO23aYDxPZNTXfmvKP Ai5cfyd7TNfmTE3Oxd5Fk80jm9mIHwBhKajMMXGV92YWeYZl9w44OcGfC/9iYirbv5d3 qcvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z0L8jsMI; 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 ay3si1530076plb.298.2019.05.15.04.39.34; Wed, 15 May 2019 04:39:48 -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=z0L8jsMI; 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 S1732000AbfEOLgm (ORCPT + 99 others); Wed, 15 May 2019 07:36:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:44302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733028AbfEOLc1 (ORCPT ); Wed, 15 May 2019 07:32:27 -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 B92F7206BF; Wed, 15 May 2019 11:32:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919947; bh=kndu8SAtUtlE6O5XFX8Lvk1NrcXtcxLc7hvEAE7f7uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z0L8jsMIcJBTjfLYMA6JVl5h2gHlg/SUsgwEKscHuI6UquwUAyBp2W7H1dpsE2JMe vIqHgWjjWEXP4tnh7pxGavOgoSLGpGc4823lfvqJ50jBal7wHcFsYy9nUc23igixz/ NCF548m+UNExj5M17woA3ur7ZRaIznVAqAKTxKZw= 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.1 17/46] fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied Date: Wed, 15 May 2019 12:56:41 +0200 Message-Id: <20190515090623.324742464@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090616.670410738@linuxfoundation.org> References: <20190515090616.670410738@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; }