Skip to content

Commit a6affd2

Browse files
rshearmandavem330
authored andcommitted
mpls: Use definition for reserved label checks
In multiple locations there are checks for whether the label in hand is a reserved label or not using the arbritray value of 16. Factor this out into a #define for better maintainability and for documentation. Signed-off-by: Robert Shearman <[email protected]> Acked-by: Roopa Prabhu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c961b1c commit a6affd2

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

include/uapi/linux/mpls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ struct mpls_label {
4141
#define MPLS_LABEL_OAMALERT 14 /* RFC3429 */
4242
#define MPLS_LABEL_EXTENSION 15 /* RFC7274 */
4343

44+
#define MPLS_LABEL_FIRST_UNRESERVED 16 /* RFC3032 */
45+
4446
#endif /* _UAPI_MPLS_H */

net/mpls/af_mpls.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static void mpls_notify_route(struct net *net, unsigned index,
293293
struct mpls_route *rt = new ? new : old;
294294
unsigned nlm_flags = (old && new) ? NLM_F_REPLACE : 0;
295295
/* Ignore reserved labels for now */
296-
if (rt && (index >= 16))
296+
if (rt && (index >= MPLS_LABEL_FIRST_UNRESERVED))
297297
rtmsg_lfib(event, index, rt, nlh, net, portid, nlm_flags);
298298
}
299299

@@ -327,7 +327,8 @@ static unsigned find_free_label(struct net *net)
327327

328328
platform_label = rtnl_dereference(net->mpls.platform_label);
329329
platform_labels = net->mpls.platform_labels;
330-
for (index = 16; index < platform_labels; index++) {
330+
for (index = MPLS_LABEL_FIRST_UNRESERVED; index < platform_labels;
331+
index++) {
331332
if (!rtnl_dereference(platform_label[index]))
332333
return index;
333334
}
@@ -436,8 +437,8 @@ static int mpls_route_add(struct mpls_route_config *cfg)
436437
index = find_free_label(net);
437438
}
438439

439-
/* The first 16 labels are reserved, and may not be set */
440-
if (index < 16)
440+
/* Reserved labels may not be set */
441+
if (index < MPLS_LABEL_FIRST_UNRESERVED)
441442
goto errout;
442443

443444
/* The full 20 bit range may not be supported. */
@@ -516,8 +517,8 @@ static int mpls_route_del(struct mpls_route_config *cfg)
516517

517518
index = cfg->rc_label;
518519

519-
/* The first 16 labels are reserved, and may not be removed */
520-
if (index < 16)
520+
/* Reserved labels may not be removed */
521+
if (index < MPLS_LABEL_FIRST_UNRESERVED)
521522
goto errout;
522523

523524
/* The full 20 bit range may not be supported */
@@ -835,8 +836,8 @@ static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh,
835836
&cfg->rc_label))
836837
goto errout;
837838

838-
/* The first 16 labels are reserved, and may not be set */
839-
if (cfg->rc_label < 16)
839+
/* Reserved labels may not be set */
840+
if (cfg->rc_label < MPLS_LABEL_FIRST_UNRESERVED)
840841
goto errout;
841842

842843
break;
@@ -961,8 +962,8 @@ static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb)
961962
ASSERT_RTNL();
962963

963964
index = cb->args[0];
964-
if (index < 16)
965-
index = 16;
965+
if (index < MPLS_LABEL_FIRST_UNRESERVED)
966+
index = MPLS_LABEL_FIRST_UNRESERVED;
966967

967968
platform_label = rtnl_dereference(net->mpls.platform_label);
968969
platform_labels = net->mpls.platform_labels;

0 commit comments

Comments
 (0)