diff options
author | Stephen Worley <sworley@cumulusnetworks.com> | 2019-05-14 19:21:19 +0200 |
---|---|---|
committer | Stephen Worley <sworley@cumulusnetworks.com> | 2019-05-23 18:21:15 +0200 |
commit | ebc403dda50fda7735526798b13a35900f593b5c (patch) | |
tree | 138986db0925d622781ccec267c48166e9e66c72 /lib/nexthop.c | |
parent | lib: Add nexthop_cmp (diff) | |
download | frr-ebc403dda50fda7735526798b13a35900f593b5c.tar.xz frr-ebc403dda50fda7735526798b13a35900f593b5c.zip |
lib: Add nexthop labels cmp functions
Add a function to compare nexthop labels.
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib/nexthop.c')
-rw-r--r-- | lib/nexthop.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c index 2a65c4d54..c616ea857 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -36,6 +36,34 @@ DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop") DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label") +static int nexthop_labels_cmp(const struct nexthop *nh1, + const struct nexthop *nh2) +{ + const struct mpls_label_stack *nhl1 = NULL; + const struct mpls_label_stack *nhl2 = NULL; + + nhl1 = nh1->nh_label; + nhl2 = nh2->nh_label; + + /* No labels is a match */ + if (!nhl1 && !nhl2) + return 0; + + if (nhl1 && !nhl2) + return 1; + + if (nhl2 && !nhl1) + return -1; + + if (nhl1->num_labels > nhl2->num_labels) + return 1; + + if (nhl1->num_labels < nhl2->num_labels) + return -1; + + return memcmp(nhl1->label, nhl2->label, nhl1->num_labels); +} + int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2) { int ret; |