]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: let FIB stand for its respective VRF
authorFeng Lu <lu.feng@6wind.com>
Fri, 22 May 2015 09:40:02 +0000 (11:40 +0200)
committerVipin Kumar <vipin@cumulusnetworks.com>
Fri, 30 Oct 2015 06:38:03 +0000 (23:38 -0700)
A new member "vrf_id" is added to "struct rib", reflecting the VRF
which it belongs to.

A new parameter "vrf_id" is added to the relative functions where
need, except those:
- which already have the parameter "vrf_id"; or
- which have a parameter in type of "struct rib"; or
- which have a parameter in type of "struct interface".

All incoming routes are set to default VRF.

In fact, all routes in FIB are kept in default VRF. And the logic
is not changed.

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
[DL: conflicts fixed + compile warning fix]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Conflicts:
zebra/connected.c
zebra/kernel_socket.c
zebra/rib.h
zebra/rt_netlink.c
zebra/zebra_rib.c
zebra/zserv.c

Conflicts:
zebra/connected.c
zebra/interface.c
zebra/kernel_socket.c
zebra/rib.h
zebra/rt_netlink.c
zebra/rtread_getmsg.c
zebra/zebra_rib.c
zebra/zebra_vty.c
zebra/zserv.c

lib/prefix.c
lib/prefix.h
zebra/connected.c
zebra/interface.c
zebra/kernel_socket.c
zebra/rib.h
zebra/rt_netlink.c
zebra/rtread_getmsg.c
zebra/zebra_rib.c
zebra/zebra_vty.c
zebra/zserv.c

index 739764842d0784df9276b401409a9dd6bb77e655..43331d155230166d0480884b6b433df0a4793348 100644 (file)
@@ -766,14 +766,15 @@ str2prefix (const char *str, struct prefix *p)
   return 0;
 }
 
-int
-prefix2str (const struct prefix *p, char *str, int size)
+const char *
+prefix2str (union prefix46constptr pu, char *str, int size)
 {
+  const struct prefix *p = pu.p;
   char buf[BUFSIZ];
 
   inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ);
   snprintf (str, size, "%s/%d", buf, p->prefixlen);
-  return 0;
+  return str;
 }
 
 struct prefix *
index cc4bbe280dac40068d8c03fd1893c2694332cab6..7fef37e3ff5267b32f8802b5a2d6a81289ad49eb 100644 (file)
@@ -179,7 +179,7 @@ extern void prefix_free (struct prefix *);
 extern const char *prefix_family_str (const struct prefix *);
 extern int prefix_blen (const struct prefix *);
 extern int str2prefix (const char *, struct prefix *);
-extern int prefix2str (const struct prefix *, char *, int);
+extern const char *prefix2str (union prefix46constptr, char *, int);
 extern int prefix_match (const struct prefix *, const struct prefix *);
 extern int prefix_same (const struct prefix *, const struct prefix *);
 extern int prefix_cmp (const struct prefix *, const struct prefix *);
index 2ec6911d77ec474dbeb49b2007428aaf9f209ac6..0d2407a3e0322fdf1b49366d6d956fd47cce960e 100644 (file)
@@ -209,15 +209,15 @@ connected_up_ipv4 (struct interface *ifp, struct connected *ifc)
     return;
 
   rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex,
-       RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST);
+       ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST);
 
   rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex,
-       RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST);
+       ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST);
 
   if (IS_ZEBRA_DEBUG_RIB)
     zlog_debug ("%s: calling rib_update", __func__);
 
-  rib_update ();
+  rib_update (ifp->vrf_id);
 }
 
 /* Add connected IPv4 route to the interface. */
@@ -327,14 +327,16 @@ connected_down_ipv4 (struct interface *ifp, struct connected *ifc)
     return;
 
   /* Same logic as for connected_up_ipv4(): push the changes into the head. */
-  rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_UNICAST);
+  rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0,
+                   SAFI_UNICAST);
 
-  rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_MULTICAST);
+  rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0,
+                   SAFI_MULTICAST);
 
   if (IS_ZEBRA_DEBUG_RIB)
     zlog_debug ("%s: calling rib_update_static", __func__);
 
-  rib_update_static ();
+  rib_update_static (ifp->vrf_id);
 }
 
 void
@@ -397,7 +399,7 @@ connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
   if (IS_ZEBRA_DEBUG_RIB)
     zlog_debug ("%s: calling rib_update_static", __func__);
 
-  rib_update_static();
+  rib_update_static(ifp->vrf_id);
 }
 
 #ifdef HAVE_IPV6
@@ -420,13 +422,13 @@ connected_up_ipv6 (struct interface *ifp, struct connected *ifc)
     return;
 #endif
 
-  rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, RT_TABLE_MAIN,
-                ifp->metric, 0, SAFI_UNICAST);
+  rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id,
+                RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST);
 
   if (IS_ZEBRA_DEBUG_RIB)
     zlog_debug ("%s: calling rib_update", __func__);
 
-  rib_update ();
+  rib_update (ifp->vrf_id);
 }
 
 /* Add connected IPv6 route to the interface. */
@@ -509,12 +511,13 @@ connected_down_ipv6 (struct interface *ifp, struct connected *ifc)
   if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix))
     return;
 
-  rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_UNICAST);
+  rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex,
+                   ifp->vrf_id, 0, SAFI_UNICAST);
 
   if (IS_ZEBRA_DEBUG_RIB)
     zlog_debug ("%s: calling rib_update_static", __func__);
 
-  rib_update_static ();
+  rib_update_static (ifp->vrf_id);
 }
 
 void
@@ -538,6 +541,6 @@ connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address,
   if (IS_ZEBRA_DEBUG_RIB)
     zlog_debug ("%s: calling rib_update_static", __func__);
 
-  rib_update_static();
+  rib_update_static(ifp->vrf_id);
 }
 #endif /* HAVE_IPV6 */
index 2ae2b0bf5117276685c5ca51c82386a7c80946a5..a3d297d327b6eba753a60e94ef1f0d59d0788ea0 100644 (file)
@@ -644,7 +644,7 @@ if_up (struct interface *ifp)
                 ifp->name);
 
   /* Examine all static routes. */
-  rib_update ();
+  rib_update (ifp->vrf_id);
 }
 
 /* Interface goes down.  We have to manage different behavior of based
@@ -681,7 +681,7 @@ if_down (struct interface *ifp)
     zlog_debug ("%s: calling rib_update_static on interface %s down", __func__,
                 ifp->name);
 
-  rib_update_static ();
+  rib_update_static (ifp->vrf_id);
 
   if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp);
 
index 03f3eaeb6a5d930d281108b79f459bd71669dfeb..a1002a4d865c9ae2c58706e432cac35bb827a616 100644 (file)
@@ -32,6 +32,7 @@
 #include "table.h"
 #include "rib.h"
 #include "privs.h"
+#include "vrf.h"
 
 #include "zebra/interface.h"
 #include "zebra/zserv.h"
@@ -870,8 +871,8 @@ rtm_read (struct rt_msghdr *rtm)
         int ret;
         if (! IS_ZEBRA_DEBUG_RIB)
           return;
-        ret = rib_lookup_ipv4_route (&p, &gate); 
-        inet_ntop (AF_INET, &p.prefix, buf, INET_ADDRSTRLEN);
+        ret = rib_lookup_ipv4_route (&p, &gate, VRF_DEFAULT);
+        prefix2str (&p, buf, sizeof(buf));
         switch (rtm->rtm_type)
         {
           case RTM_ADD:
@@ -935,16 +936,16 @@ rtm_read (struct rt_msghdr *rtm)
        */
       if (rtm->rtm_type == RTM_CHANGE)
         rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p,
-                         NULL, 0, 0, SAFI_UNICAST);
+                         NULL, 0, VRF_DEFAULT, SAFI_UNICAST);
       
       if (rtm->rtm_type == RTM_GET 
           || rtm->rtm_type == RTM_ADD
           || rtm->rtm_type == RTM_CHANGE)
        rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
-                     &p, &gate.sin.sin_addr, NULL, 0, 0, 0, 0, SAFI_UNICAST);
+                     &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, 0, 0, SAFI_UNICAST);
       else
        rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0 zebra_flags,
-                     &p, &gate.sin.sin_addr, 0, 0, SAFI_UNICAST);
+                     &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, SAFI_UNICAST);
     }
 #ifdef HAVE_IPV6
   if (dest.sa.sa_family == AF_INET6)
@@ -977,16 +978,16 @@ rtm_read (struct rt_msghdr *rtm)
        */
       if (rtm->rtm_type == RTM_CHANGE)
         rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p,
-                         NULL, 0, 0, SAFI_UNICAST);
+                         NULL, 0, VRF_DEFAULT, SAFI_UNICAST);
       
       if (rtm->rtm_type == RTM_GET 
           || rtm->rtm_type == RTM_ADD
           || rtm->rtm_type == RTM_CHANGE)
        rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
-                     &p, &gate.sin6.sin6_addr, ifindex, 0, 0, 0, SAFI_UNICAST);
+                     &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, 0, SAFI_UNICAST);
       else
        rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags,
-                        &p, &gate.sin6.sin6_addr, ifindex, 0, SAFI_UNICAST);
+                        &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, SAFI_UNICAST);
     }
 #endif /* HAVE_IPV6 */
 }
index 8c82a7eec356d2a3f1a3fb334c38a240d97601c3..6908e9d81654ab12e8f8bba413c82ba0913c696c 100644 (file)
@@ -52,6 +52,9 @@ struct rib
   /* Source protocol instance */
   u_short instance;
 
+  /* VRF identifier. */
+  vrf_id_t vrf_id;
+
   /* Which routing table */
   uint32_t table;
 
@@ -367,7 +370,8 @@ extern void rib_lookup_and_pushup (struct prefix_ipv4 *);
 #define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib)
 extern void _rib_dump (const char *,
                       union prefix46constptr, const struct rib *);
-extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *);
+extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *,
+                                  vrf_id_t);
 #define ZEBRA_RIB_LOOKUP_ERROR -1
 #define ZEBRA_RIB_FOUND_EXACT 0
 #define ZEBRA_RIB_FOUND_NOGATE 1
@@ -401,21 +405,21 @@ extern int zebra_check_addr (struct prefix *p);
  * also implicitly withdraw equal prefix of same type. */
 extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
                         struct in_addr *gate, struct in_addr *src,
-                        unsigned int ifindex, u_int32_t vrf_id,
+                        unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id,
                         u_int32_t, u_char, safi_t);
 
 extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t);
 
 extern int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
                            struct in_addr *gate, unsigned int ifindex, 
-                           u_int32_t, safi_t safi);
+                           vrf_id_t, u_int32_t, safi_t safi);
 
-extern struct rib *rib_match_ipv4 (struct in_addr);
+extern struct rib *rib_match_ipv4 (struct in_addr, vrf_id_t);
 
-extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
+extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t);
 
-extern void rib_update (void);
-extern void rib_update_static (void);
+extern void rib_update (vrf_id_t);
+extern void rib_update_static (vrf_id_t);
 extern void rib_weed_tables (void);
 extern void rib_sweep_route (void);
 extern void rib_close (void);
@@ -427,32 +431,33 @@ extern void rib_queue_add (struct zebra_t *zebra, struct route_node *rn);
 
 extern int
 static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
-                 u_char flags, u_short tag, u_char distance, u_int32_t vrf_id);
+                 u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id);
 
 extern int
 static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
-                   u_short tag, u_char distance, u_int32_t vrf_id);
+                   u_short tag, u_char distance, vrf_id_t vrf_id);
 
 #ifdef HAVE_IPV6
 extern int
 rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
-             struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id,
-             u_int32_t metric, u_char distance, safi_t safi);
+             struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+              u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi);
 
 extern int
 rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
-                struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi);
+                struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+                 u_int32_t table_id, safi_t safi);
 
-extern struct rib *rib_lookup_ipv6 (struct in6_addr *);
+extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t);
 
-extern struct rib *rib_match_ipv6 (struct in6_addr *);
+extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t);
 
 extern struct route_table *rib_table_ipv6;
 
 extern int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
                 const char *ifname, u_char flags, u_short tag,
-                 u_char distance, u_int32_t vrf_id);
+                 u_char distance, vrf_id_t vrf_id);
 
 extern int
 rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t,
@@ -461,7 +466,7 @@ rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t,
 extern int
 static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
                    const char *ifname, u_short tag, u_char distance,
-                    u_int32_t vrf_id);
+                    vrf_id_t vrf_id);
 
 #endif /* HAVE_IPV6 */
 
index 4c16df61a1bff1f6e67f66bfede73bb8792898c5..e312801e5593bc93a1a7cce54ca7a6655536b1da 100644 (file)
@@ -37,6 +37,7 @@
 #include "thread.h"
 #include "privs.h"
 #include "nexthop.h"
+#include "vrf.h"
 
 #include "zebra/zserv.h"
 #include "zebra/rt.h"
@@ -755,7 +756,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
 
       if (!tb[RTA_MULTIPATH])
           rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, src, index,
-                        table, metric, 0, SAFI_UNICAST);
+                        VRF_DEFAULT, table, metric, 0, SAFI_UNICAST);
       else
         {
           /* This is a multipath route */
@@ -771,6 +772,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
           rib->distance = 0;
           rib->flags = flags;
           rib->metric = metric;
+          rib->vrf_id = VRF_DEFAULT;
           rib->table = table;
           rib->nexthop_num = 0;
           rib->uptime = time (NULL);
@@ -821,8 +823,8 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
       memcpy (&p.prefix, dest, 16);
       p.prefixlen = rtm->rtm_dst_len;
 
-      rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, table,
-                   metric, 0, SAFI_UNICAST);
+      rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, VRF_DEFAULT,
+                    table, metric, 0, SAFI_UNICAST);
     }
 #endif /* HAVE_IPV6 */
 
@@ -958,8 +960,8 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
       if (h->nlmsg_type == RTM_NEWROUTE)
         {
           if (!tb[RTA_MULTIPATH])
-            rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, table,
-                          metric, 0, SAFI_UNICAST);
+            rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, VRF_DEFAULT,
+                          table, metric, 0, SAFI_UNICAST);
           else
             {
               /* This is a multipath route */
@@ -975,6 +977,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
               rib->distance = 0;
               rib->flags = 0;
               rib->metric = metric;
+              rib->vrf_id = VRF_DEFAULT;
               rib->table = table;
               rib->nexthop_num = 0;
               rib->uptime = time (NULL);
@@ -1020,7 +1023,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
         }
       else
         rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index,
-                         table, SAFI_UNICAST);
+                         VRF_DEFAULT, table, SAFI_UNICAST);
     }
 
 #ifdef HAVE_IPV6
@@ -1046,10 +1049,11 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
         }
 
       if (h->nlmsg_type == RTM_NEWROUTE)
-        rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, table, metric, 0, SAFI_UNICAST);
+        rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, VRF_DEFAULT,
+                      table, metric, 0, SAFI_UNICAST);
       else
         rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index,
-                         table, SAFI_UNICAST);
+                         VRF_DEFAULT, table, SAFI_UNICAST);
     }
 #endif /* HAVE_IPV6 */
 
index 17d75b283a6e77117b13aa1f703aa014cf59330a..f9bfb338a08850995a3902839ea47a82db0b625b 100644 (file)
@@ -25,6 +25,7 @@
 #include "prefix.h"
 #include "log.h"
 #include "if.h"
+#include "vrf.h"
 
 #include "zebra/rib.h"
 #include "zebra/zserv.h"
@@ -90,7 +91,7 @@ handle_route_entry (mib2_ipRouteEntry_t *routeEntry)
        gateway.s_addr = routeEntry->ipRouteNextHop;
 
        rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &prefix,
-                     &gateway, NULL, 0, 0, 0, 0, SAFI_UNICAST);
+                     &gateway, NULL, 0, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST);
 }
 
 void
index b15cbd3cdb5f15adeb526eb9fd8bd4e1c0cbb080..79aa989814b33320eecee4d9f9a8f29db6233002 100644 (file)
@@ -483,7 +483,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
   p.prefix = nexthop->gate.ipv4;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, rib->vrf_id);
   if (! table)
     return 0;
 
@@ -692,7 +692,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
   p.prefix = nexthop->gate.ipv6;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, rib->vrf_id);
   if (! table)
     return 0;
 
@@ -846,7 +846,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
 #endif /* HAVE_IPV6 */
 
 struct rib *
-rib_match_ipv4 (struct in_addr addr)
+rib_match_ipv4 (struct in_addr addr, vrf_id_t vrf_id)
 {
   struct prefix_ipv4 p;
   struct route_table *table;
@@ -856,7 +856,7 @@ rib_match_ipv4 (struct in_addr addr)
   int recursing;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return 0;
 
@@ -908,7 +908,7 @@ rib_match_ipv4 (struct in_addr addr)
 }
 
 struct rib *
-rib_lookup_ipv4 (struct prefix_ipv4 *p)
+rib_lookup_ipv4 (struct prefix_ipv4 *p, vrf_id_t vrf_id)
 {
   struct route_table *table;
   struct route_node *rn;
@@ -917,7 +917,7 @@ rib_lookup_ipv4 (struct prefix_ipv4 *p)
   int recursing;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return 0;
 
@@ -964,7 +964,8 @@ rib_lookup_ipv4 (struct prefix_ipv4 *p)
  * 3: no matches found
  */
 int
-rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate)
+rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate,
+    vrf_id_t vrf_id)
 {
   struct route_table *table;
   struct route_node *rn;
@@ -974,7 +975,7 @@ rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate)
   int nexthops_active;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! table)
     return ZEBRA_RIB_LOOKUP_ERROR;
 
@@ -1030,7 +1031,7 @@ rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate)
 
 #ifdef HAVE_IPV6
 struct rib *
-rib_match_ipv6 (struct in6_addr *addr)
+rib_match_ipv6 (struct in6_addr *addr, vrf_id_t vrf_id)
 {
   struct prefix_ipv6 p;
   struct route_table *table;
@@ -1040,7 +1041,7 @@ rib_match_ipv6 (struct in6_addr *addr)
   int recursing;
 
   /* Lookup table.  */
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! table)
     return 0;
 
@@ -1124,7 +1125,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib,
   switch (nexthop->type)
     {
     case NEXTHOP_TYPE_IFINDEX:
-      ifp = if_lookup_by_index (nexthop->ifindex);
+      ifp = if_lookup_by_index_vrf (nexthop->ifindex, rib->vrf_id);
       if (ifp && if_is_operative(ifp))
        SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
       else
@@ -1133,7 +1134,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib,
     case NEXTHOP_TYPE_IPV6_IFNAME:
       family = AFI_IP6;
     case NEXTHOP_TYPE_IFNAME:
-      ifp = if_lookup_by_name (nexthop->ifname);
+      ifp = if_lookup_by_name_vrf (nexthop->ifname, rib->vrf_id);
       if (ifp && if_is_operative(ifp))
        {
          if (set)
@@ -1169,7 +1170,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib,
        family = AFI_IP6;
       if (IN6_IS_ADDR_LINKLOCAL (&nexthop->gate.ipv6))
        {
-         ifp = if_lookup_by_index (nexthop->ifindex);
+         ifp = if_lookup_by_index_vrf (nexthop->ifindex, rib->vrf_id);
          if (ifp && if_is_operative(ifp))
            SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
          else
@@ -2150,7 +2151,7 @@ rib_delnode (struct route_node *rn, struct rib *rib)
 int
 rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
              struct in_addr *gate, struct in_addr *src,
-             unsigned int ifindex, u_int32_t table_id,
+             unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id,
              u_int32_t metric, u_char distance, safi_t safi)
 {
   struct rib *rib;
@@ -2162,11 +2163,11 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
   /* Lookup table.  */
   if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
     {
-      table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+      table = zebra_vrf_table (AFI_IP, safi, vrf_id);
     }
   else
     {
-      table = zebra_vrf_other_route_table (AFI_IP, table_id, VRF_DEFAULT);
+      table = zebra_vrf_other_route_table (AFI_IP, table_id, vrf_id);
     }
   if (! table)
     return 0;
@@ -2226,6 +2227,7 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
   rib->flags = flags;
   rib->metric = metric;
   rib->table = table_id;
+  rib->vrf_id = vrf_id;
   rib->nexthop_num = 0;
   rib->uptime = time (NULL);
 
@@ -2279,8 +2281,8 @@ void _rib_dump (const char * func,
   struct nexthop *nexthop, *tnexthop;
   int recursing;
 
-  inet_ntop (p->family, &p->u.prefix, straddr, INET6_ADDRSTRLEN);
-  zlog_debug ("%s: dumping RIB entry %p for %s/%d", func, rib, straddr, p->prefixlen);
+  zlog_debug ("%s: dumping RIB entry %p for %s vrf %u", func, rib,
+              prefix2str(pp, straddr, sizeof(straddr)), rib->vrf_id);
   zlog_debug
   (
     "%s: refcnt == %lu, uptime == %lu, type == %u, instance == %d, table == %d",
@@ -2439,11 +2441,11 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi)
   /* Lookup table.  */
   if ((rib->table == zebrad.rtm_table_default) || (rib->table == RT_TABLE_MAIN))
     {
-      table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+      table = zebra_vrf_table (AFI_IP, safi, rib->vrf_id);
     }
   else
     {
-      table = zebra_vrf_other_route_table (AFI_IP, rib->table, VRF_DEFAULT);
+      table = zebra_vrf_other_route_table (AFI_IP, rib->table, rib->vrf_id);
     }
   if (! table)
     return 0;
@@ -2513,7 +2515,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi)
 /* XXX factor with rib_delete_ipv6 */
 int
 rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
-                struct in_addr *gate, unsigned int ifindex,
+                struct in_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
                 u_int32_t table_id, safi_t safi)
 {
   struct route_table *table;
@@ -2529,11 +2531,11 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
   /* Lookup table.  */
   if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
     {
-      table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT);
+      table = zebra_vrf_table (AFI_IP, safi, vrf_id);
     }
   else
     {
-      table = zebra_vrf_other_route_table(AFI_IP, table_id, VRF_DEFAULT);
+      table = zebra_vrf_other_route_table(AFI_IP, table_id, vrf_id);
     }
   if (! table)
     return 0;
@@ -2544,15 +2546,13 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
   if (IS_ZEBRA_DEBUG_KERNEL)
     {
       if (gate)
-       zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d",
-                   inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-                   p->prefixlen,
+       zlog_debug ("rib_delete_ipv4(): route delete %s vrf %u via %s ifindex %d",
+                   prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                    inet_ntoa (*gate),
                    ifindex);
       else
-       zlog_debug ("rib_delete_ipv4(): route delete %s/%d ifindex %d",
-                   inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-                   p->prefixlen,
+       zlog_debug ("rib_delete_ipv4(): route delete %s vrf %u ifindex %d",
+                   prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                    ifindex);
     }
 
@@ -2563,15 +2563,13 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
       if (IS_ZEBRA_DEBUG_KERNEL)
        {
          if (gate)
-           zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib",
-                      inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-                      p->prefixlen,
+           zlog_debug ("route %s vrf %u via %s ifindex %d doesn't exist in rib",
+                      prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                       inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
                       ifindex);
          else
-           zlog_debug ("route %s/%d ifindex %d doesn't exist in rib",
-                      inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-                      p->prefixlen,
+           zlog_debug ("route %s vrf %u ifindex %d doesn't exist in rib",
+                      prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                       ifindex);
        }
       return ZEBRA_ERR_RTNOEXIST;
@@ -2656,16 +2654,15 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p,
          if (IS_ZEBRA_DEBUG_KERNEL)
            {
              if (gate)
-               zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
-                          inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-                          p->prefixlen,
+               zlog_debug ("route %s vrf %u via %s ifindex %d type %d "
+                          "doesn't exist in rib",
+                          prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                           inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN),
                           ifindex,
                           type);
              else
-               zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib",
-                          inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
-                          p->prefixlen,
+               zlog_debug ("route %s vrf %u ifindex %d type %d doesn't exist in rib",
+                          prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                           ifindex,
                           type);
            }
@@ -2742,6 +2739,7 @@ static_install_ipv4 (struct prefix *p, struct static_ipv4 *si)
       rib->instance = 0;
       rib->distance = si->distance;
       rib->metric = 0;
+      rib->vrf_id = VRF_DEFAULT;
       rib->table = zebrad.rtm_table_default;
       rib->nexthop_num = 0;
       rib->tag = si->tag;
@@ -2876,7 +2874,7 @@ static_uninstall_ipv4 (struct prefix *p, struct static_ipv4 *si)
 /* Add static route into static route configuration. */
 int
 static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
-                u_char flags, u_short tag, u_char distance, u_int32_t vrf_id)
+                u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id)
 {
   u_char type = 0;
   struct route_node *rn;
@@ -2884,10 +2882,9 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
   struct static_ipv4 *pp;
   struct static_ipv4 *cp;
   struct static_ipv4 *update = NULL;
-  struct route_table *stable;
+  struct zebra_vrf *zvrf = vrf_info_get (vrf_id);
+  struct route_table *stable = zvrf->stable[AFI_IP][SAFI_UNICAST];
 
-  /* Lookup table.  */
-  stable = zebra_vrf_static_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (! stable)
     return -1;
   
@@ -2972,7 +2969,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
 /* Delete static route from static route configuration. */
 int
 static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
-                   u_short tag, u_char distance, u_int32_t vrf_id)
+                   u_short tag, u_char distance, vrf_id_t vrf_id)
 {
   u_char type = 0;
   struct route_node *rn;
@@ -3059,8 +3056,8 @@ rib_bogus_ipv6 (int type, struct prefix_ipv6 *p,
 
 int
 rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
-             struct in6_addr *gate, unsigned int ifindex, u_int32_t table_id,
-             u_int32_t metric, u_char distance, safi_t safi)
+             struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+              u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi)
 {
   struct rib *rib;
   struct rib *same = NULL;
@@ -3071,11 +3068,11 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
   /* Lookup table.  */
   if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
     {
-      table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+      table = zebra_vrf_table (AFI_IP6, safi, vrf_id);
     }
   else
     {
-      table = zebra_vrf_other_route_table(AFI_IP6, table_id, VRF_DEFAULT);
+      table = zebra_vrf_other_route_table(AFI_IP6, table_id, vrf_id);
     }
   if (! table)
     return 0;
@@ -3131,6 +3128,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
   rib->flags = flags;
   rib->metric = metric;
   rib->table = table_id;
+  rib->vrf_id = vrf_id;
   rib->nexthop_num = 0;
   rib->uptime = time (NULL);
 
@@ -3294,7 +3292,8 @@ rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi,
 /* XXX factor with rib_delete_ipv6 */
 int
 rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
-                struct in6_addr *gate, unsigned int ifindex, u_int32_t table_id, safi_t safi)
+                struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id,
+                 u_int32_t table_id, safi_t safi)
 {
   struct route_table *table;
   struct route_node *rn;
@@ -3312,7 +3311,7 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
   /* Lookup table.  */
   if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default))
     {
-      table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+      table = zebra_vrf_table (AFI_IP6, safi, vrf_id);
     }
   else
     {
@@ -3328,15 +3327,13 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
       if (IS_ZEBRA_DEBUG_KERNEL)
        {
          if (gate)
-           zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib",
-                      inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-                      p->prefixlen,
+           zlog_debug ("route %s vrf %u via %s ifindex %d doesn't exist in rib",
+                      prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                       inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN),
                       ifindex);
          else
-           zlog_debug ("route %s/%d ifindex %d doesn't exist in rib",
-                      inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-                      p->prefixlen,
+           zlog_debug ("route %s vrf %u ifindex %d doesn't exist in rib",
+                      prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                       ifindex);
        }
       return ZEBRA_ERR_RTNOEXIST;
@@ -3422,16 +3419,15 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p,
          if (IS_ZEBRA_DEBUG_KERNEL)
            {
              if (gate)
-               zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib",
-                          inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-                          p->prefixlen,
+               zlog_debug ("route %s vrf %u via %s ifindex %d type %d "
+                          "doesn't exist in rib",
+                          prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                           inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN),
                           ifindex,
                           type);
              else
-               zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib",
-                          inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN),
-                          p->prefixlen,
+               zlog_debug ("route %s vrf %u ifindex %d type %d doesn't exist in rib",
+                          prefix2str (p, buf1, sizeof(buf1)), vrf_id,
                           ifindex,
                           type);
            }
@@ -3509,6 +3505,7 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si)
       rib->instance = 0;
       rib->distance = si->distance;
       rib->metric = 0;
+      rib->vrf_id = VRF_DEFAULT;
       rib->table = zebrad.rtm_table_default;
       rib->nexthop_num = 0;
       rib->tag = si->tag;
@@ -3644,16 +3641,15 @@ static_uninstall_ipv6 (struct prefix *p, struct static_ipv6 *si)
 int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
                 const char *ifname, u_char flags, u_short tag,
-                 u_char distance, u_int32_t vrf_id)
+                 u_char distance, vrf_id_t vrf_id)
 {
   struct route_node *rn;
   struct static_ipv6 *si;
   struct static_ipv6 *pp;
   struct static_ipv6 *cp;
-  struct route_table *stable;
+  struct zebra_vrf *zvrf = vrf_info_get (vrf_id);
+  struct route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST];
 
-  /* Lookup table.  */
-  stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (! stable)
     return -1;
     
@@ -3734,7 +3730,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
 int
 static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
                    const char *ifname, u_short tag, u_char distance,
-                    u_int32_t vrf_id)
+                    vrf_id_t vrf_id)
 {
   struct route_node *rn;
   struct static_ipv6 *si;
@@ -3788,13 +3784,13 @@ static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
 
 /* RIB update function. */
 void
-rib_update_static (void)
+rib_update_static (vrf_id_t vrf_id)
 {
   struct route_node *rn;
   struct route_table *table;
   struct rib *rib, *next;
 
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (table)
     for (rn = route_top (table); rn; rn = route_next (rn))
       RNODE_FOREACH_RIB_SAFE (rn, rib, next)
@@ -3804,7 +3800,7 @@ rib_update_static (void)
             break;
           }
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (table)
     for (rn = route_top (table); rn; rn = route_next (rn))
       RNODE_FOREACH_RIB_SAFE (rn, rib, next)
@@ -3817,18 +3813,18 @@ rib_update_static (void)
 
 /* RIB update function. */
 void
-rib_update (void)
+rib_update (vrf_id_t vrf_id)
 {
   struct route_node *rn;
   struct route_table *table;
   
-  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (table)
     for (rn = route_top (table); rn; rn = route_next (rn))
       if (rnode_to_ribs (rn))
         rib_queue_add (&zebrad, rn);
 
-  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT);
+  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (table)
     for (rn = route_top (table); rn; rn = route_next (rn))
       if (rnode_to_ribs (rn))
@@ -3861,8 +3857,15 @@ rib_weed_table (struct route_table *table)
 void
 rib_weed_tables (void)
 {
-  rib_weed_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
-  rib_weed_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
+  vrf_iter_t iter;
+  struct zebra_vrf *zvrf;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      {
+        rib_weed_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+        rib_weed_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+      }
 }
 
 /* Delete self installed routes after zebra is relaunched.  */
@@ -3895,8 +3898,15 @@ rib_sweep_table (struct route_table *table)
 void
 rib_sweep_route (void)
 {
-  rib_sweep_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
-  rib_sweep_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
+  vrf_iter_t iter;
+  struct zebra_vrf *zvrf;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      {
+        rib_sweep_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+        rib_sweep_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+      }
 }
 
 /* Remove specific by protocol routes from 'table'. */
@@ -3928,8 +3938,16 @@ rib_score_proto_table (u_char proto, u_short instance, struct route_table *table
 unsigned long
 rib_score_proto (u_char proto, u_short instance)
 {
-  return  rib_score_proto_table (proto, instance, zebra_vrf_table (AFI_IP,  SAFI_UNICAST, VRF_DEFAULT))
-         +rib_score_proto_table (proto, instance, zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
+  vrf_iter_t iter;
+  struct zebra_vrf *zvrf;
+  unsigned long cnt = 0;
+
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    if ((zvrf = vrf_iter2info (iter)) != NULL)
+      cnt += rib_score_proto_table (proto, instance, zvrf->table[AFI_IP][SAFI_UNICAST])
+            +rib_score_proto_table (proto, instance, zvrf->table[AFI_IP6][SAFI_UNICAST]);
+
+  return cnt;
 }
 
 /* Close RIB and clean up kernel routes. */
@@ -3957,14 +3975,21 @@ rib_close_table (struct route_table *table)
 void
 rib_close (void)
 {
-  struct listnode *node, *nnode;
+  vrf_iter_t iter;
+  struct zebra_vrf *zvrf;
+  struct listnode *node;
   struct interface *ifp;
 
-  rib_close_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT));
-  rib_close_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT));
-
-  for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
-    if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
+  for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
+    {
+      if ((zvrf = vrf_iter2info (iter)) != NULL)
+        {
+          rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+          rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+        }
+      for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
+        if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
+    }
 }
 
 /* Routing information base initialize. */
index 9728a28c0e517c0073ff71ddfa13f567700bf57e..1a50ab6990b9e4061bed73d8cf32b8d7ceae96c1 100644 (file)
@@ -961,7 +961,8 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
            case NEXTHOP_TYPE_IPV4_IFINDEX:
              vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4));
              if (nexthop->ifindex)
-               vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
+               vty_out (vty, ", via %s",
+                         ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
              break;
 #ifdef HAVE_IPV6
            case NEXTHOP_TYPE_IPV6:
@@ -972,12 +973,13 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
              if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
                vty_out (vty, ", %s", nexthop->ifname);
              else if (nexthop->ifindex)
-               vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex));
+               vty_out (vty, ", via %s",
+                         ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
              break;
 #endif /* HAVE_IPV6 */
            case NEXTHOP_TYPE_IFINDEX:
              vty_out (vty, " directly connected, %s",
-                      ifindex2ifname (nexthop->ifindex));
+                      ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
              break;
            case NEXTHOP_TYPE_IFNAME:
              vty_out (vty, " directly connected, %s", nexthop->ifname);
@@ -1073,7 +1075,8 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
        case NEXTHOP_TYPE_IPV4_IFINDEX:
          vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4));
          if (nexthop->ifindex)
-           vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
+           vty_out (vty, ", %s",
+                     ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
          break;
 #ifdef HAVE_IPV6
         case NEXTHOP_TYPE_IPV6:
@@ -1084,13 +1087,14 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
          if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME)
            vty_out (vty, ", %s", nexthop->ifname);
          else if (nexthop->ifindex)
-           vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex));
+           vty_out (vty, ", %s",
+                     ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
          break;
 #endif /* HAVE_IPV6 */
 
        case NEXTHOP_TYPE_IFINDEX:
          vty_out (vty, " is directly connected, %s",
-                  ifindex2ifname (nexthop->ifindex));
+                  ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
          break;
        case NEXTHOP_TYPE_IFNAME:
          vty_out (vty, " is directly connected, %s", nexthop->ifname);
index ba3c59aafb5a6d0235bdebcb1f9cef641edafe28..052c797f8babb6a42c45ec5f39dc3b05870f26ed 100644 (file)
@@ -37,6 +37,7 @@
 #include "network.h"
 #include "buffer.h"
 #include "nexthop.h"
+#include "vrf.h"
 
 #include "zebra/zserv.h"
 #include "zebra/router-id.h"
@@ -643,7 +644,7 @@ zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr)
   struct nexthop *nexthop;
 
   /* Lookup nexthop. */
-  rib = rib_match_ipv6 (addr);
+  rib = rib_match_ipv6 (addr, VRF_DEFAULT);
 
   /* Get output stream. */
   s = client->obuf;
@@ -710,7 +711,7 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr)
   struct nexthop *nexthop;
 
   /* Lookup nexthop. */
-  rib = rib_match_ipv4 (addr);
+  rib = rib_match_ipv4 (addr, VRF_DEFAULT);
 
   /* Get output stream. */
   s = client->obuf;
@@ -892,7 +893,7 @@ zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p)
   struct nexthop *nexthop;
 
   /* Lookup nexthop. */
-  rib = rib_lookup_ipv4 (p);
+  rib = rib_lookup_ipv4 (p, VRF_DEFAULT);
 
   /* Get output stream. */
   s = client->obuf;
@@ -1076,6 +1077,9 @@ zread_ipv4_add (struct zserv *client, u_short length)
   p.prefixlen = stream_getc (s);
   stream_get (&p.prefix, s, PSIZE (p.prefixlen));
 
+  /* VRF ID */
+  rib->vrf_id = VRF_DEFAULT;
+
   /* Nexthop parse. */
   if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP))
     {
@@ -1231,7 +1235,7 @@ zread_ipv4_delete (struct zserv *client, u_short length)
     api.tag = 0;
 
   rib_delete_ipv4 (api.type, api.instance, api.flags, &p, nexthop_p, ifindex,
-                  client->rtm_table, api.safi);
+                  VRF_DEFAULT, client->rtm_table, api.safi);
   client->v4_route_del_cnt++;
   return 0;
 }
@@ -1505,6 +1509,7 @@ zread_ipv6_add (struct zserv *client, u_short length)
 
   /* Table */
   rib->table=zebrad.rtm_table_default;
+  rib->vrf_id = VRF_DEFAULT;
   ret = rib_add_ipv6_multipath ((struct prefix *)&p, rib, safi, ifindex);
   /* Stats */
   if (ret > 0)
@@ -1584,9 +1589,11 @@ zread_ipv6_delete (struct zserv *client, u_short length)
     api.tag = 0;
 
   if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
-    rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex, client->rtm_table, api.safi);
+    rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex,
+                     VRF_DEFAULT, client->rtm_table, api.safi);
   else
-    rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex, client->rtm_table, api.safi);
+    rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex,
+                     VRF_DEFAULT, client->rtm_table, api.safi);
 
   client->v6_route_del_cnt++;
   return 0;