Received: by 10.223.185.111 with SMTP id b44csp906442wrg; Fri, 9 Mar 2018 16:31:53 -0800 (PST) X-Google-Smtp-Source: AG47ELvI7zvd+bTxHu5dRJ2WLGnHsCU87M2w8Wg5mocd93zqYx52JhkqWrXw7r7iNgxSWY6xjYDB X-Received: by 10.98.141.205 with SMTP id p74mr316152pfk.211.1520641913502; Fri, 09 Mar 2018 16:31:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641913; cv=none; d=google.com; s=arc-20160816; b=fIGnZXbVzCRXq4HavSIi3FN/JbFCv6SFWNYuMJ6+71ob5nsMhFBQZDgAW95wy6UpXs 5CmrOTzQ48Ocw8l6rJRktyU8URo2tbK3BuyXcSAJFQZkJmqelE88gENow4ECU4fEGM+w upbwaaeFoCvUBGgAeNsHQOZPF+/Vygwu7ELHoCgWugKsmEQJAz1q4ISUeU1LHOBSX3Df EmfuFf8tM9QRQe5qPA5OnXYi67cYl3139D37ONwLTlMoih4ithNidzLU0tjNZo9YAzSj CWfqP/SPBGrzo3yJBnKwLp8EDnnl6L9T5anozhAPjhr0ZBnEkohhubO1aeLR+NiRNXrR 5HFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IWzHZGIKBE/IVVHaaU26iKWh687Lxs57SV4DsZdcp74=; b=N917SRtmlZYtVW0ROfksyZlSUfYwkrZaw9b55KRraryyVFX4QKoUMeEgiW6JTMcceI W8Lxfr3gIlikpPlo2x+BBo8SXS2EtnJppu7+koAs7xtZ0cGRoH+5hFOhySlyl5pQS3uz A+Q+HCkyS53jqLtM/l88B51lFDx98dt7LlDNk771etWwKZt3O+NUvz8jSsTvSSVJh/Ky p6/F53iAJrT7pn6WohZx6EPXns5oY1D95IMruwwu7I8ynFlJVDOxgdW/oD6pmXNZtSTe RlY1X/R+wT4C/8CJof4kLCW7diyvYCleAsaul/1Gnkdog11CBQp2tHVrKlLmZtRx1I6x LrcQ== ARC-Authentication-Results: i=1; mx.google.com; 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 n5si1509900pgc.459.2018.03.09.16.31.39; Fri, 09 Mar 2018 16:31:53 -0800 (PST) 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; 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 S933960AbeCJAWp (ORCPT + 99 others); Fri, 9 Mar 2018 19:22:45 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40130 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933946AbeCJAWm (ORCPT ); Fri, 9 Mar 2018 19:22:42 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 03016118D; Sat, 10 Mar 2018 00:22:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Ahern , "David S. Miller" , Ben Hutchings Subject: [PATCH 4.9 57/65] net: mpls: Pull common label check into helper Date: Fri, 9 Mar 2018 16:18:57 -0800 Message-Id: <20180310001829.699068126@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Ahern commit b7b386f42f079b25b942c756820e36c6bd09b2ca upstream. mpls_route_add and mpls_route_del have the same checks on the label. Move to a helper. Avoid duplicate extack messages in the next patch. Signed-off-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- net/mpls/af_mpls.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) --- a/net/mpls/af_mpls.c +++ b/net/mpls/af_mpls.c @@ -756,6 +756,19 @@ errout: return err; } +static bool mpls_label_ok(struct net *net, unsigned int index) +{ + /* Reserved labels may not be set */ + if (index < MPLS_LABEL_FIRST_UNRESERVED) + return false; + + /* The full 20 bit range may not be supported. */ + if (index >= net->mpls.platform_labels) + return false; + + return true; +} + static int mpls_route_add(struct mpls_route_config *cfg) { struct mpls_route __rcu **platform_label; @@ -774,12 +787,7 @@ static int mpls_route_add(struct mpls_ro index = find_free_label(net); } - /* Reserved labels may not be set */ - if (index < MPLS_LABEL_FIRST_UNRESERVED) - goto errout; - - /* The full 20 bit range may not be supported. */ - if (index >= net->mpls.platform_labels) + if (!mpls_label_ok(net, index)) goto errout; /* Append makes no sense with mpls */ @@ -840,12 +848,7 @@ static int mpls_route_del(struct mpls_ro index = cfg->rc_label; - /* Reserved labels may not be removed */ - if (index < MPLS_LABEL_FIRST_UNRESERVED) - goto errout; - - /* The full 20 bit range may not be supported */ - if (index >= net->mpls.platform_labels) + if (!mpls_label_ok(net, index)) goto errout; mpls_route_update(net, index, NULL, &cfg->rc_nlinfo); @@ -1279,10 +1282,9 @@ static int rtm_to_route_config(struct sk &cfg->rc_label)) goto errout; - /* Reserved labels may not be set */ - if (cfg->rc_label < MPLS_LABEL_FIRST_UNRESERVED) + if (!mpls_label_ok(cfg->rc_nlinfo.nl_net, + cfg->rc_label)) goto errout; - break; } case RTA_VIA: