From: David Ahern <dsahern@gmail.com>
To: netdev@vger.kernel.org
Cc: roopa@cumulusnetworks.com, David Ahern <dsahern@gmail.com>
Subject: [PATCH v2 net-next 6/9] net: mpls: Pull common label check into helper
Date: Sat, 27 May 2017 16:19:30 -0600 [thread overview]
Message-ID: <20170527221933.57644-7-dsahern@gmail.com> (raw)
In-Reply-To: <20170527221933.57644-1-dsahern@gmail.com>
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 <dsahern@gmail.com>
---
net/mpls/af_mpls.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index f3830951fb1c..726eafecc793 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -856,6 +856,19 @@ static int mpls_nh_build_multi(struct mpls_route_config *cfg,
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;
@@ -875,12 +888,7 @@ static int mpls_route_add(struct mpls_route_config *cfg)
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 */
@@ -952,12 +960,7 @@ static int mpls_route_del(struct mpls_route_config *cfg)
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);
@@ -1735,10 +1738,9 @@ static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh,
&cfg->rc_label, NULL))
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:
--
2.11.0 (Apple Git-81)
next prev parent reply other threads:[~2017-05-27 22:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-27 22:19 [PATCH v2 net-next 0/9] net: another round of extack handling for routing David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 1/9] net: ipv4: refactor key and length checks David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 2/9] net: ipv4: Add extack message for invalid prefix or length David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 3/9] net: lwtunnel: Add extack to encap attr validation David Ahern
2017-05-28 1:02 ` kbuild test robot
2017-05-28 2:44 ` David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 4/9] net: add extack arg to lwtunnel build state David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 5/9] net: Fill in extack for mpls lwt encap David Ahern
2017-05-27 22:19 ` David Ahern [this message]
2017-05-27 22:19 ` [PATCH v2 net-next 7/9] net: mpls: Add extack messages for route add and delete failures David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 8/9] net: mpls: Make nla_get_via in af_mpls.c David Ahern
2017-05-27 22:19 ` [PATCH v2 net-next 9/9] net: mpls: remove unnecessary initialization of err David Ahern
2017-05-30 15:55 ` [PATCH v2 net-next 0/9] net: another round of extack handling for routing David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170527221933.57644-7-dsahern@gmail.com \
--to=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@cumulusnetworks.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).