Skip to content

Commit d77763d

Browse files
dsaherngregkh
authored andcommitted
net: mpls: Pull common label check into helper
commit b7b386f 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 <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9b7d723 commit d77763d

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

net/mpls/af_mpls.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,19 @@ static int mpls_nh_build_multi(struct mpls_route_config *cfg,
756756
return err;
757757
}
758758

759+
static bool mpls_label_ok(struct net *net, unsigned int index)
760+
{
761+
/* Reserved labels may not be set */
762+
if (index < MPLS_LABEL_FIRST_UNRESERVED)
763+
return false;
764+
765+
/* The full 20 bit range may not be supported. */
766+
if (index >= net->mpls.platform_labels)
767+
return false;
768+
769+
return true;
770+
}
771+
759772
static int mpls_route_add(struct mpls_route_config *cfg)
760773
{
761774
struct mpls_route __rcu **platform_label;
@@ -774,12 +787,7 @@ static int mpls_route_add(struct mpls_route_config *cfg)
774787
index = find_free_label(net);
775788
}
776789

777-
/* Reserved labels may not be set */
778-
if (index < MPLS_LABEL_FIRST_UNRESERVED)
779-
goto errout;
780-
781-
/* The full 20 bit range may not be supported. */
782-
if (index >= net->mpls.platform_labels)
790+
if (!mpls_label_ok(net, index))
783791
goto errout;
784792

785793
/* Append makes no sense with mpls */
@@ -840,12 +848,7 @@ static int mpls_route_del(struct mpls_route_config *cfg)
840848

841849
index = cfg->rc_label;
842850

843-
/* Reserved labels may not be removed */
844-
if (index < MPLS_LABEL_FIRST_UNRESERVED)
845-
goto errout;
846-
847-
/* The full 20 bit range may not be supported */
848-
if (index >= net->mpls.platform_labels)
851+
if (!mpls_label_ok(net, index))
849852
goto errout;
850853

851854
mpls_route_update(net, index, NULL, &cfg->rc_nlinfo);
@@ -1279,10 +1282,9 @@ static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh,
12791282
&cfg->rc_label))
12801283
goto errout;
12811284

1282-
/* Reserved labels may not be set */
1283-
if (cfg->rc_label < MPLS_LABEL_FIRST_UNRESERVED)
1285+
if (!mpls_label_ok(cfg->rc_nlinfo.nl_net,
1286+
cfg->rc_label))
12841287
goto errout;
1285-
12861288
break;
12871289
}
12881290
case RTA_VIA:

0 commit comments

Comments
 (0)