summaryrefslogtreecommitdiff
path: root/lib/nexthop.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nexthop.c')
-rw-r--r--lib/nexthop.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c
index 3c36dbf69a..d0cc5dc258 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -37,6 +37,7 @@
DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop");
DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label");
DEFINE_MTYPE_STATIC(LIB, NH_SEG6LOCAL, "Nexthop seg6local");
+DEFINE_MTYPE_STATIC(LIB, NH_SEG6, "Nexthop seg6");
static int _nexthop_labels_cmp(const struct nexthop *nh1,
const struct nexthop *nh2)
@@ -89,6 +90,22 @@ static int _nexthop_seg6local_cmp(const struct nexthop *nh1,
sizeof(struct seg6local_context));
}
+static int _nexthop_seg6_cmp(const struct nexthop *nh1,
+ const struct nexthop *nh2)
+{
+ if (!nh1->nh_seg6_segs && !nh2->nh_seg6_segs)
+ return 0;
+
+ if (nh1->nh_seg6_segs && !nh2->nh_seg6_segs)
+ return 1;
+
+ if (!nh1->nh_seg6_segs && nh2->nh_seg6_segs)
+ return -1;
+
+ return memcmp(nh1->nh_seg6_segs, nh2->nh_seg6_segs,
+ sizeof(struct in6_addr));
+}
+
int nexthop_g_addr_cmp(enum nexthop_types_t type, const union g_addr *addr1,
const union g_addr *addr2)
{
@@ -226,6 +243,10 @@ int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2)
return ret;
ret = _nexthop_seg6local_cmp(next1, next2);
+ if (ret != 0)
+ return ret;
+
+ ret = _nexthop_seg6_cmp(next1, next2);
return ret;
}
@@ -381,6 +402,7 @@ void nexthop_free(struct nexthop *nexthop)
{
nexthop_del_labels(nexthop);
nexthop_del_seg6local(nexthop);
+ nexthop_del_seg6(nexthop);
if (nexthop->resolved)
nexthops_free(nexthop->resolved);
XFREE(MTYPE_NEXTHOP, nexthop);
@@ -572,6 +594,21 @@ void nexthop_del_seg6local(struct nexthop *nexthop)
nexthop->nh_seg6local_action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC;
}
+void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr *segs)
+{
+ struct in6_addr *nh_segs;
+
+ nh_segs = XCALLOC(MTYPE_NH_SEG6, sizeof(struct in6_addr));
+ if (segs)
+ *nh_segs = *segs;
+ nexthop->nh_seg6_segs = nh_segs;
+}
+
+void nexthop_del_seg6(struct nexthop *nexthop)
+{
+ XFREE(MTYPE_NH_SEG6, nexthop->nh_seg6_segs);
+}
+
const char *nexthop2str(const struct nexthop *nexthop, char *str, int size)
{
switch (nexthop->type) {
@@ -723,6 +760,10 @@ uint32_t nexthop_hash_quick(const struct nexthop *nexthop)
sizeof(nexthop->nh_seg6local_ctx), key);
}
+ if (nexthop->nh_seg6_segs)
+ key = jhash(nexthop->nh_seg6_segs,
+ sizeof(nexthop->nh_seg6_segs), key);
+
return key;
}
@@ -779,6 +820,9 @@ void nexthop_copy_no_recurse(struct nexthop *copy,
if (nexthop->nh_seg6local_ctx)
nexthop_add_seg6local(copy, nexthop->nh_seg6local_action,
nexthop->nh_seg6local_ctx);
+
+ if (nexthop->nh_seg6_segs)
+ nexthop_add_seg6(copy, nexthop->nh_seg6_segs);
}
void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,