]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: add some nexthop ctors
authorMark Stapp <mjs@voltanet.io>
Fri, 22 Nov 2019 16:10:42 +0000 (11:10 -0500)
committerMark Stapp <mjs@voltanet.io>
Fri, 22 Nov 2019 16:10:42 +0000 (11:10 -0500)
Add some apis that allocate and init nexthop objects
from various kinds of arguments: ip addrs, interfaces,
blackhole types.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
lib/nexthop.c
lib/nexthop.h

index 73c2de0cd80ead88df7a117b94b0c456665ac1b2..655a596f503df4795f21488529992b8e628e8288 100644 (file)
@@ -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)
index fe029f1867932345182852d4d006cf7fc4c61cc4..72a4acedb28a7f50a94f74f561b0dc2b79336e71 100644 (file)
@@ -121,6 +121,22 @@ void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t,
                        mpls_label_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.
  *