summaryrefslogtreecommitdiffstats
path: root/lib/nexthop.c
diff options
context:
space:
mode:
authorHiroki Shirokura <slank.dev@gmail.com>2020-12-17 14:45:58 +0100
committerMark Stapp <mjs@voltanet.io>2021-06-02 16:24:47 +0200
commit2aa01034f3c437e076cf12f1ea4e4b7b5b6b9075 (patch)
tree98533279860fb8dd44b502adb78aae3e5c698a81 /lib/nexthop.c
parentdoc: add new section for srv6 configuration (step2) (diff)
downloadfrr-2aa01034f3c437e076cf12f1ea4e4b7b5b6b9075.tar.xz
frr-2aa01034f3c437e076cf12f1ea4e4b7b5b6b9075.zip
lib: add new nexthop's attributes seg6 (step3)
This commit add new nexthop's addional object for SRv6 routing about seg6 route. Before this commit, we can add MPLS info as additional object on nexthop. This commit make it add more support about seg6 routes. seg6 routes are ones of the LWT routing mechanism, so configuration of seg6local routes is performed by ZEBRA_ROUTE_SEND, it's same as MPLS configuration. Real configuration implementation isn't implemented at this commit. later commit add that. This commit add only nexthop additional object and some misc functions. Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
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 3c36dbf69..d0cc5dc25 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,