Received: by 10.223.185.111 with SMTP id b44csp914210wrg; Fri, 9 Mar 2018 16:44:07 -0800 (PST) X-Google-Smtp-Source: AG47ELstJBbl3UR01xDmKXoGPECBGYNyEwlSI+xfSpTjVCh//Su70geAlJCOKHhNTE52ptEiNlLD X-Received: by 10.98.9.130 with SMTP id 2mr346795pfj.149.1520642647102; Fri, 09 Mar 2018 16:44:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642647; cv=none; d=google.com; s=arc-20160816; b=wdJlf6xxWnwm7brChGBSUmYBLQ4YAvIKLq+aJH/xLsQkPuj4tefmD5HCM16ILOAjoq zRLozUK+lQSZq8oazwEajzZhy31SEs/Ah+4Wa/eJoUZAZV0+BHEOXnB5W5aN7910Jcnr pRoYtYhBqiQ/ZA1P9u5a1BQECEoz6MEFcaHqArPN9Umr/cwUItaR5V+rcP7c0PY15XbH weUImo++IGiUcsU16HfgxBsPbbzGXRbuNMvt1nKewCxPC7wJkwGu7uYWMZNT+BGCVRuW ScBvnAbA7bgTE3xJpTe991NEp2Q978RrxKA7f2zb7+gdVL7jxkLot286h1dpuDtm+xkU tGqw== 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=yF0g3bT1DzAAGNu95QAbbkV8klCQO4U6OJLlw0MQ2nY=; b=yOCiMnehnAk0Xye9fX2KAep0jzIxYYzZCXXiz1P/jD2D+yklCAJ/mwpGsP7lwfK0ae vuSrMOVMzKEqZym8ir8cPTP2spH1cZ3Ia9VpXf4rg2RPluTHeEaVlvk+O7ijKNZ3VD7S vHUV+Zmz+M4EdPeVwR+x/7MgI4yZxmTcmN8JNmoLxyQcnnVFlLpXJUOBEPX4PI2lLurB WKK2SOm20/A3LSplQylGdf46+vUHCmbgFKg8WxuuMnl9Ozfxgvqyz5wdaCJ5TVRZ/5or JKG9cen43yB6arrsdbeAvIbfbfNZ9+MjKBN7Q8Nu2VwHlzR2uqyzd7vC8U9QWFYj8EFO 1HGQ== 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 d3-v6si1709681pll.1.2018.03.09.16.43.53; Fri, 09 Mar 2018 16:44:07 -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 S933591AbeCJAnC (ORCPT + 99 others); Fri, 9 Mar 2018 19:43:02 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39314 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933519AbeCJAUu (ORCPT ); Fri, 9 Mar 2018 19:20:50 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E2213106B; Sat, 10 Mar 2018 00:20:49 +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.4 32/36] net: mpls: Pull common label check into helper Date: Fri, 9 Mar 2018 16:18:48 -0800 Message-Id: <20180310001809.138665604@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001807.213987241@linuxfoundation.org> References: <20180310001807.213987241@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.4-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 @@ -714,6 +714,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; @@ -732,12 +745,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 */ @@ -798,12 +806,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); @@ -1162,10 +1165,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: