]> git.puffer.fish Git - mirror/frr.git/commitdiff
Zebra: Fix static NHT to work properly in a VRF
authorvivek <vivek@cumulusnetworks.com>
Fri, 26 Feb 2016 19:13:34 +0000 (19:13 +0000)
committervivek <vivek@cumulusnetworks.com>
Fri, 26 Feb 2016 19:13:34 +0000 (19:13 +0000)
Implement VRF support for static nexthop resolution (NHT). This is
achieved by ensuring the correct VRF is passed as a parameter to
the NHT functions and is stored in the registered nexthop data
structure.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
Ticket: CM-9457
Reviewed By: CCR-4185
Testing Done: Manual verification

zebra/zebra_rib.c
zebra/zebra_rnh.c
zebra/zebra_rnh.h
zebra/zebra_rnh_null.c

index 39b9d452ca3954146bbea6c7c05ef3bb3506f540..9679afe068e76e513010b1919668c55a973f28fc 100644 (file)
@@ -308,7 +308,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
   if (set)
     {
       UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
-      zebra_deregister_rnh_static_nexthops(nexthop->resolved, top);
+      zebra_deregister_rnh_static_nexthops(rib->vrf_id, nexthop->resolved, top);
       nexthops_free(nexthop->resolved);
       nexthop->resolved = NULL;
     }
@@ -532,7 +532,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
   if (set)
     {
       UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
-      zebra_deregister_rnh_static_nexthops (nexthop->resolved, top);
+      zebra_deregister_rnh_static_nexthops (rib->vrf_id, nexthop->resolved, top);
       nexthops_free(nexthop->resolved);
       nexthop->resolved = NULL;
     }
@@ -1964,7 +1964,7 @@ rib_unlink (struct route_node *rn, struct rib *rib)
     }
 
   /* free RIB and nexthops */
-  zebra_deregister_rnh_static_nexthops (rib->nexthop, rn);
+  zebra_deregister_rnh_static_nexthops (rib->vrf_id, rib->nexthop, rn);
   nexthops_free(rib->nexthop);
   XFREE (MTYPE_RIB, rib);
 
@@ -2560,7 +2560,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
          nh_p.family = AF_INET;
          nh_p.prefixlen = IPV4_MAX_BITLEN;
          nh_p.u.prefix4 = si->addr.ipv4;
-         zebra_register_rnh_static_nh(&nh_p, rn);
+         zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn);
          break;
        case STATIC_IFINDEX:
          rib_nexthop_ifindex_add (rib, si->ifindex);
@@ -2573,7 +2573,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
          nh_p.family = AF_INET6;
          nh_p.prefixlen = IPV6_MAX_BITLEN;
          nh_p.u.prefix6 = si->addr.ipv6;
-         zebra_register_rnh_static_nh(&nh_p, rn);
+         zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn);
          break;
        case STATIC_IPV6_GATEWAY_IFINDEX:
          rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex);
@@ -2618,7 +2618,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
          nh_p.family = AF_INET;
          nh_p.prefixlen = IPV4_MAX_BITLEN;
          nh_p.u.prefix4 = si->addr.ipv4;
-         zebra_register_rnh_static_nh(&nh_p, rn);
+         zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn);
          break;
        case STATIC_IFINDEX:
          rib_nexthop_ifindex_add (rib, si->ifindex);
@@ -2631,7 +2631,7 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
          nh_p.family = AF_INET6;
          nh_p.prefixlen = IPV6_MAX_BITLEN;
          nh_p.u.prefix6 = si->addr.ipv6;
-         zebra_register_rnh_static_nh(&nh_p, rn);
+         zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn);
          break;
        case STATIC_IPV6_GATEWAY_IFINDEX:
          rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex);
@@ -2788,7 +2788,7 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_
          nh_p.u.prefix6 = nexthop->gate.ipv6;
        }
       rib_nexthop_delete (rib, nexthop);
-      zebra_deregister_rnh_static_nh(&nh_p, rn);
+      zebra_deregister_rnh_static_nh(si->vrf_id, &nh_p, rn);
       nexthop_free (nexthop);
     }
   /* Unlock node. */
index 74e63d94671332113a6f03731b53386c308a59e1..a10b31c2af756d612a23a510d4355138e8a499ce 100644 (file)
@@ -49,7 +49,7 @@
 /* Default rtm_table for all clients */
 extern struct zebra_t zebrad;
 
-static void free_state(struct rib *rib, struct route_node *rn);
+static void free_state(vrf_id_t vrf_id, struct rib *rib, struct route_node *rn);
 static void copy_state(struct rnh *rnh, struct rib *rib,
                       struct route_node *rn);
 #define lookup_rnh_table(v, f)                  \
@@ -127,6 +127,7 @@ zebra_add_rnh (struct prefix *p, vrf_id_t vrfid, rnh_type_t type)
     {
       rnh = XCALLOC(MTYPE_RNH, sizeof(struct rnh));
       rnh->client_list = list_new();
+      rnh->vrf_id = vrfid;
       rnh->zebra_static_route_list = list_new();
       route_lock_node (rn);
       rn->info = rnh;
@@ -176,7 +177,7 @@ zebra_delete_rnh (struct rnh *rnh, rnh_type_t type)
   rnh->flags |= ZEBRA_NHT_DELETED;
   list_free(rnh->client_list);
   list_free(rnh->zebra_static_route_list);
-  free_state(rnh->state, rn);
+  free_state(rnh->vrf_id, rnh->state, rn);
   XFREE(MTYPE_RNH, rn->info);
   rn->info = NULL;
   route_unlock_node (rn);
@@ -218,11 +219,12 @@ zebra_remove_rnh_client (struct rnh *rnh, struct zserv *client, rnh_type_t type)
 }
 
 void
-zebra_register_rnh_static_nh(struct prefix *nh, struct route_node *static_rn)
+zebra_register_rnh_static_nh(vrf_id_t vrf_id, struct prefix *nh,
+                             struct route_node *static_rn)
 {
   struct rnh *rnh;
 
-  rnh = zebra_add_rnh(nh, 0, RNH_NEXTHOP_TYPE);
+  rnh = zebra_add_rnh(nh, vrf_id, RNH_NEXTHOP_TYPE);
   if (rnh && !listnode_lookup(rnh->zebra_static_route_list, static_rn))
     {
       listnode_add(rnh->zebra_static_route_list, static_rn);
@@ -230,11 +232,12 @@ zebra_register_rnh_static_nh(struct prefix *nh, struct route_node *static_rn)
 }
 
 void
-zebra_deregister_rnh_static_nh(struct prefix *nh, struct route_node *static_rn)
+zebra_deregister_rnh_static_nh(vrf_id_t vrf_id, struct prefix *nh,
+                               struct route_node *static_rn)
 {
   struct rnh *rnh;
 
-  rnh = zebra_lookup_rnh(nh, 0, RNH_NEXTHOP_TYPE);
+  rnh = zebra_lookup_rnh(nh, vrf_id, RNH_NEXTHOP_TYPE);
   if (!rnh || (rnh->flags & ZEBRA_NHT_DELETED))
     return;
 
@@ -246,7 +249,8 @@ zebra_deregister_rnh_static_nh(struct prefix *nh, struct route_node *static_rn)
 }
 
 void
-zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn)
+zebra_deregister_rnh_static_nexthops (vrf_id_t vrf_id, struct nexthop *nexthop,
+                                      struct route_node *rn)
 {
   struct nexthop *nh;
   struct prefix nh_p;
@@ -265,7 +269,7 @@ zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node
           nh_p.prefixlen = IPV6_MAX_BITLEN;
           nh_p.u.prefix6 = nh->gate.ipv6;
         }
-      zebra_deregister_rnh_static_nh(&nh_p, rn);
+      zebra_deregister_rnh_static_nh(vrf_id, &nh_p, rn);
     }
 }
 
@@ -788,14 +792,14 @@ zebra_cleanup_rnh_client (vrf_id_t vrfid, int family, struct zserv *client,
  * free_state - free up the rib structure associated with the rnh.
  */
 static void
-free_state (struct rib *rib, struct route_node *rn)
+free_state (vrf_id_t vrf_id, struct rib *rib, struct route_node *rn)
 {
 
   if (!rib)
     return;
 
   /* free RIB and nexthops */
-  zebra_deregister_rnh_static_nexthops (rib->nexthop, rn);
+  zebra_deregister_rnh_static_nexthops (vrf_id, rib->nexthop, rn);
   nexthops_free(rib->nexthop);
   XFREE (MTYPE_RIB, rib);
 }
@@ -808,7 +812,7 @@ copy_state (struct rnh *rnh, struct rib *rib, struct route_node *rn)
 
   if (rnh->state)
     {
-      free_state(rnh->state, rn);
+      free_state(rnh->vrf_id, rnh->state, rn);
       rnh->state = NULL;
     }
 
index b76651aa76cb94dca18674cd6511c9977fe49fa5..0732a4f92798b3aa362cf808296a910508de7f4a 100644 (file)
@@ -35,6 +35,9 @@ struct rnh
 #define ZEBRA_NHT_DELETED       0x2
 #define ZEBRA_NHT_EXACT_MATCH   0x4
 
+  /* VRF identifier. */
+  vrf_id_t vrf_id;
+
   struct rib *state;
   struct prefix resolved_route;
   struct list *client_list;
@@ -59,9 +62,10 @@ extern struct rnh *zebra_lookup_rnh(struct prefix *p, vrf_id_t vrfid,
 extern void zebra_delete_rnh(struct rnh *rnh, rnh_type_t type);
 extern void zebra_add_rnh_client(struct rnh *rnh, struct zserv *client, rnh_type_t type,
                                  vrf_id_t vrfid);
-extern void zebra_register_rnh_static_nh(struct prefix *, struct route_node *);
-extern void zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn);
-extern void zebra_deregister_rnh_static_nh(struct prefix *, struct route_node *);
+extern void zebra_register_rnh_static_nh(vrf_id_t, struct prefix *, struct route_node *);
+extern void zebra_deregister_rnh_static_nexthops (vrf_id_t, struct nexthop *nexthop,
+                                                  struct route_node *rn);
+extern void zebra_deregister_rnh_static_nh(vrf_id_t, struct prefix *, struct route_node *);
 extern void zebra_remove_rnh_client(struct rnh *rnh, struct zserv *client,
                                    rnh_type_t type);
 extern void zebra_evaluate_rnh(vrf_id_t vrfid, int family, int force, rnh_type_t type,
index f4a651c7782b1fa89fc561f8b924e1b85ce76eef..3ec8be027d31f8e7db6febab374e204c671ef99c 100644 (file)
@@ -14,11 +14,12 @@ void zebra_print_rnh_table (vrf_id_t vrfid, int family, struct vty *vty,
                            rnh_type_t type)
 {}
 
-void zebra_register_rnh_static_nh(struct prefix *p, struct route_node *rn)
+void zebra_register_rnh_static_nh(vrf_id_t vrfid, struct prefix *p, struct route_node *rn)
 {}
 
-void zebra_deregister_rnh_static_nh(struct prefix *p, struct route_node *rn)
+void zebra_deregister_rnh_static_nh(vrf_id_t vrfid, struct prefix *p, struct route_node *rn)
 {}
 
-void zebra_deregister_rnh_static_nexthops (struct nexthop *nexthop, struct route_node *rn)
+void zebra_deregister_rnh_static_nexthops (vrf_id_t vrfid, struct nexthop *nexthop,
+                                           struct route_node *rn)
 {}