]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: clean up rib and nhg headers
authorMark Stapp <mjs@voltanet.io>
Thu, 21 Nov 2019 20:05:52 +0000 (15:05 -0500)
committerMark Stapp <mjs@voltanet.io>
Thu, 21 Nov 2019 20:05:52 +0000 (15:05 -0500)
Clean up the relationships between zebra's rib and nexthop-group
headers as prep for adding a nexthop-group pointer to the
route_entry.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
zebra/rib.h
zebra/zebra_mpls.c
zebra/zebra_nhg.c
zebra/zebra_nhg.h
zebra/zebra_rib.c

index 35aa011c0d5020b19ad6c71b1fab6fcdbaf28f00..6a7b65c55f583a2f9051048ce2b10481b5e9c6ae 100644 (file)
@@ -35,6 +35,7 @@
 #include "if.h"
 #include "mpls.h"
 #include "srcdest_table.h"
+#include "zebra/zebra_nhg.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -334,6 +335,7 @@ extern void route_entry_nexthop_add(struct route_entry *re,
                                    struct nexthop *nexthop);
 extern void route_entry_copy_nexthops(struct route_entry *re,
                                      struct nexthop *nh);
+int route_entry_update_nhe(struct route_entry *re, struct nhg_hash_entry *new);
 
 #define route_entry_dump(prefix, src, re) _route_entry_dump(__func__, prefix, src, re)
 extern void _route_entry_dump(const char *func, union prefixconstptr pp,
index 6942a379894b1180173cf1e6086a896ad4065f91..3a44db9dc015e9e1bad6d78ebca25eed06710f6f 100644 (file)
@@ -2572,7 +2572,7 @@ static void mpls_zebra_nhg_update(struct route_entry *re, afi_t afi,
 
        nhe = zebra_nhg_rib_find(0, new_grp, afi);
 
-       zebra_nhg_re_update_ref(re, nhe);
+       route_entry_update_nhe(re, nhe);
 }
 
 static bool mpls_ftn_update_nexthop(int add, struct nexthop *nexthop,
index 2d7521d8be09b088fc1b8e77cd684155b5f576f0..1108cc45014ac7fbec5922d6a43e861f82df5297 100644 (file)
@@ -1704,7 +1704,7 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re)
 
                new_nhe = zebra_nhg_rib_find(0, &new_grp, rt_afi);
 
-               zebra_nhg_re_update_ref(re, new_nhe);
+               route_entry_update_nhe(re, new_nhe);
        }
 
        if (curr_active) {
@@ -1730,40 +1730,6 @@ int nexthop_active_update(struct route_node *rn, struct route_entry *re)
        return curr_active;
 }
 
-static void zebra_nhg_re_attach_ref(struct route_entry *re,
-                                   struct nhg_hash_entry *new)
-{
-       re->ng = new->nhg;
-       re->nhe_id = new->id;
-
-       zebra_nhg_increment_ref(new);
-}
-
-int zebra_nhg_re_update_ref(struct route_entry *re, struct nhg_hash_entry *new)
-{
-       struct nhg_hash_entry *old = NULL;
-       int ret = 0;
-
-       if (new == NULL) {
-               re->ng = NULL;
-               goto done;
-       }
-
-       if (re->nhe_id != new->id) {
-               old = zebra_nhg_lookup_id(re->nhe_id);
-
-               zebra_nhg_re_attach_ref(re, new);
-
-               if (old)
-                       zebra_nhg_decrement_ref(old);
-       } else if (!re->ng)
-               /* This is the first time it's being attached */
-               zebra_nhg_re_attach_ref(re, new);
-
-done:
-       return ret;
-}
-
 /* Convert a nhe into a group array */
 uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe,
                          int max_num)
index 1f695433c9689dc2733261511ba724ac6ab1df1d..4aa433a9a7059ea5ca8d5f8ede94ee89665e12b5 100644 (file)
 #ifndef __ZEBRA_NHG_H__
 #define __ZEBRA_NHG_H__
 
-#include "zebra/rib.h"
+#include "lib/nexthop.h"
 #include "lib/nexthop_group.h"
 
-#include "zebra/zebra_dplane.h"
-
 /* This struct is used exclusively for dataplane
  * interaction via a dataplane context.
  *
@@ -201,8 +199,6 @@ zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi);
 /* Reference counter functions */
 extern void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe);
 extern void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe);
-extern int zebra_nhg_re_update_ref(struct route_entry *re,
-                                  struct nhg_hash_entry *nhe);
 
 /* Check validity of nhe, if invalid will update dependents as well */
 extern void zebra_nhg_check_valid(struct nhg_hash_entry *nhe);
@@ -224,5 +220,6 @@ extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx);
 extern void zebra_nhg_sweep_table(struct hash *hash);
 
 /* Nexthop resolution processing */
+struct route_entry; /* Forward ref to avoid circular includes */
 extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
 #endif
index 781963793e4d5a9f688932ea4ee7ed1991c2cb3c..31d46e5a261bbe23dd336c104f53b42e133d64f0 100644 (file)
@@ -333,6 +333,40 @@ struct nexthop *route_entry_nexthop_blackhole_add(struct route_entry *re,
        return nexthop;
 }
 
+static void route_entry_attach_ref(struct route_entry *re,
+                                  struct nhg_hash_entry *new)
+{
+       re->ng = new->nhg;
+       re->nhe_id = new->id;
+
+       zebra_nhg_increment_ref(new);
+}
+
+int route_entry_update_nhe(struct route_entry *re, struct nhg_hash_entry *new)
+{
+       struct nhg_hash_entry *old = NULL;
+       int ret = 0;
+
+       if (new == NULL) {
+               re->ng = NULL;
+               goto done;
+       }
+
+       if (re->nhe_id != new->id) {
+               old = zebra_nhg_lookup_id(re->nhe_id);
+
+               route_entry_attach_ref(re, new);
+
+               if (old)
+                       zebra_nhg_decrement_ref(old);
+       } else if (!re->ng)
+               /* This is the first time it's being attached */
+               route_entry_attach_ref(re, new);
+
+done:
+       return ret;
+}
+
 struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id,
                              union g_addr *addr, struct route_node **rn_out)
 {
@@ -2708,7 +2742,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p,
         * level protocols, as the refcnt might be wrong, since it checks
         * if old_id != new_id.
         */
-       zebra_nhg_re_update_ref(re, nhe);
+       route_entry_update_nhe(re, nhe);
 
        /* Make it sure prefixlen is applied to the prefix. */
        apply_mask(p);