summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2019-12-04 14:11:04 -0500
committerGitHub <noreply@github.com>2019-12-04 14:11:04 -0500
commite302caaa818a2e582a98f16eaa807bc3928bf617 (patch)
treecb6561db9a055c41f910e764f8178cf31637d3ad /lib
parent86637de7f9e93ae64e7be226a5e69e80fb0e2ae4 (diff)
parent0eb97b860dc94329cf9add9f8f3d3a2c7f539568 (diff)
Merge pull request #5416 from mjstapp/re_nhe_pointer
lib,zebra: use shared nexthop-group in route_entry
Diffstat (limited to 'lib')
-rw-r--r--lib/nexthop.c88
-rw-r--r--lib/nexthop.h16
-rw-r--r--lib/nexthop_group.c4
-rw-r--r--lib/nexthop_group.h2
-rw-r--r--lib/nexthop_group_private.h2
5 files changed, 108 insertions, 4 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c
index d05fa8e6d7..f314fea697 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -33,6 +33,7 @@
#include "mpls.h"
#include "jhash.h"
#include "printfrr.h"
+#include "vrf.h"
DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop")
DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label")
@@ -281,6 +282,93 @@ bool nexthop_same_no_labels(const struct nexthop *nh1,
return true;
}
+/*
+ * Allocate a new nexthop object and initialize it from various args.
+ */
+struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id)
+{
+ struct nexthop *nexthop;
+
+ nexthop = nexthop_new();
+ nexthop->type = NEXTHOP_TYPE_IFINDEX;
+ nexthop->ifindex = ifindex;
+ nexthop->vrf_id = vrf_id;
+
+ return nexthop;
+}
+
+struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4,
+ const struct in_addr *src,
+ vrf_id_t vrf_id)
+{
+ struct nexthop *nexthop;
+
+ nexthop = nexthop_new();
+ nexthop->type = NEXTHOP_TYPE_IPV4;
+ nexthop->vrf_id = vrf_id;
+ nexthop->gate.ipv4 = *ipv4;
+ if (src)
+ nexthop->src.ipv4 = *src;
+
+ return nexthop;
+}
+
+struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4,
+ const struct in_addr *src,
+ ifindex_t ifindex, vrf_id_t vrf_id)
+{
+ struct nexthop *nexthop;
+
+ nexthop = nexthop_new();
+ nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
+ nexthop->vrf_id = vrf_id;
+ nexthop->gate.ipv4 = *ipv4;
+ if (src)
+ nexthop->src.ipv4 = *src;
+ nexthop->ifindex = ifindex;
+
+ return nexthop;
+}
+
+struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6,
+ vrf_id_t vrf_id)
+{
+ struct nexthop *nexthop;
+
+ nexthop = nexthop_new();
+ nexthop->vrf_id = vrf_id;
+ nexthop->type = NEXTHOP_TYPE_IPV6;
+ nexthop->gate.ipv6 = *ipv6;
+
+ return nexthop;
+}
+
+struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6,
+ ifindex_t ifindex, vrf_id_t vrf_id)
+{
+ struct nexthop *nexthop;
+
+ nexthop = nexthop_new();
+ nexthop->vrf_id = vrf_id;
+ nexthop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
+ nexthop->gate.ipv6 = *ipv6;
+ nexthop->ifindex = ifindex;
+
+ return nexthop;
+}
+
+struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type)
+{
+ struct nexthop *nexthop;
+
+ nexthop = nexthop_new();
+ nexthop->vrf_id = VRF_DEFAULT;
+ nexthop->type = NEXTHOP_TYPE_BLACKHOLE;
+ nexthop->bh_type = bh_type;
+
+ return nexthop;
+}
+
/* Update nexthop with label information. */
void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t type,
uint8_t num_labels, mpls_label_t *label)
diff --git a/lib/nexthop.h b/lib/nexthop.h
index fe029f1867..72a4acedb2 100644
--- a/lib/nexthop.h
+++ b/lib/nexthop.h
@@ -122,6 +122,22 @@ void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t,
void nexthop_del_labels(struct nexthop *);
/*
+ * Allocate a new nexthop object and initialize it from various args.
+ */
+struct nexthop *nexthop_from_ifindex(ifindex_t ifindex, vrf_id_t vrf_id);
+struct nexthop *nexthop_from_ipv4(const struct in_addr *ipv4,
+ const struct in_addr *src,
+ vrf_id_t vrf_id);
+struct nexthop *nexthop_from_ipv4_ifindex(const struct in_addr *ipv4,
+ const struct in_addr *src,
+ ifindex_t ifindex, vrf_id_t vrf_id);
+struct nexthop *nexthop_from_ipv6(const struct in6_addr *ipv6,
+ vrf_id_t vrf_id);
+struct nexthop *nexthop_from_ipv6_ifindex(const struct in6_addr *ipv6,
+ ifindex_t ifindex, vrf_id_t vrf_id);
+struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type);
+
+/*
* Hash a nexthop. Suitable for use with hash tables.
*
* This function uses the following values when computing the hash:
diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c
index 9552f89568..3e08f1811e 100644
--- a/lib/nexthop_group.c
+++ b/lib/nexthop_group.c
@@ -233,8 +233,8 @@ void _nexthop_add(struct nexthop **target, struct nexthop *nexthop)
nexthop->prev = last;
}
-void _nexthop_group_add_sorted(struct nexthop_group *nhg,
- struct nexthop *nexthop)
+void nexthop_group_add_sorted(struct nexthop_group *nhg,
+ struct nexthop *nexthop)
{
struct nexthop *position, *prev, *tail;
diff --git a/lib/nexthop_group.h b/lib/nexthop_group.h
index 391775c69c..5105cbf188 100644
--- a/lib/nexthop_group.h
+++ b/lib/nexthop_group.h
@@ -50,6 +50,8 @@ void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg);
uint32_t nexthop_group_hash(const struct nexthop_group *nhg);
void nexthop_group_mark_duplicates(struct nexthop_group *nhg);
+void nexthop_group_add_sorted(struct nexthop_group *nhg,
+ struct nexthop *nexthop);
/* The following for loop allows to iterate over the nexthop
* structure of routes.
diff --git a/lib/nexthop_group_private.h b/lib/nexthop_group_private.h
index cdd0df0ab3..4abda624ae 100644
--- a/lib/nexthop_group_private.h
+++ b/lib/nexthop_group_private.h
@@ -35,8 +35,6 @@ extern "C" {
void _nexthop_add(struct nexthop **target, struct nexthop *nexthop);
void _nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop);
-void _nexthop_group_add_sorted(struct nexthop_group *nhg,
- struct nexthop *nexthop);
#ifdef __cplusplus
}