]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Add the ability to use a VRF to bgp
authorDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 2 Feb 2016 12:36:20 +0000 (04:36 -0800)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 2 Feb 2016 12:36:20 +0000 (04:36 -0800)
Signed-off-by: Vipin Kumar <vipin@cumulusnetworks.com>
13 files changed:
bgpd/bgp_main.c
bgpd/bgp_network.c
bgpd/bgp_nexthop.c
bgpd/bgp_nexthop.h
bgpd/bgp_nht.c
bgpd/bgp_nht.h
bgpd/bgp_route.c
bgpd/bgp_route.h
bgpd/bgp_vty.c
bgpd/bgp_zebra.c
bgpd/bgp_zebra.h
bgpd/bgpd.c
bgpd/bgpd.h

index c61940833c28ba12c50bab4a1af0b70961c610fd..8d15b34612eeaaa3025baa4245adb8274d1ef0dc 100644 (file)
@@ -223,7 +223,6 @@ bgp_exit (int status)
 {
   struct bgp *bgp;
   struct listnode *node, *nnode;
-  struct interface *ifp;
   extern struct zclient *zclient;
 
   /* it only makes sense for this to be called on a clean exit */
@@ -239,6 +238,8 @@ bgp_exit (int status)
   /* reverse bgp_zebra_init/if_init */
   if (retain_mode)
     if_add_hook (IF_DELETE_HOOK, NULL);
+  /*Pending: Must-Do, this needs to be moved in a loop for all the instances..
+    Do the iflist lookup for vrf associated with the instance
   for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
     {
       struct listnode *c_node, *c_nnode;
@@ -247,6 +248,7 @@ bgp_exit (int status)
       for (ALL_LIST_ELEMENTS (ifp->connected, c_node, c_nnode, c))
         bgp_connected_delete (c);
     }
+    */
 
   /* reverse bgp_attr_init */
   bgp_attr_finish ();
@@ -288,9 +290,6 @@ bgp_exit (int status)
   if (bgp_ifindices_buf)
     stream_free (bgp_ifindices_buf);
 
-  /* reverse bgp_scan_init */
-  bgp_scan_finish ();
-
   /* reverse bgp_master_init */
   if (bm->master)
     thread_master_free (bm->master);
index bdb8e4c065c38418f66bb9c6f84d4f4950117d94..ae747332ae64a04daf59e9011912a0efa249824c 100644 (file)
@@ -228,6 +228,10 @@ bgp_accept (struct thread *thread)
   struct peer *peer;
   struct peer *peer1;
   char buf[SU_ADDRSTRLEN];
+  struct bgp *bgp;
+  char name[VRF_NAMSIZ + 1];
+  int rc;
+  socklen_t name_len = VRF_NAMSIZ;
 
   sockunion_init (&su);
 
@@ -249,15 +253,48 @@ bgp_accept (struct thread *thread)
     }
   set_nonblocking (bgp_sock);
 
+  name[0] = '\0';
+  rc = getsockopt(bgp_sock, SOL_SOCKET, SO_BINDTODEVICE, name, &name_len);
+  if (rc != 0)
+    {
+      zlog_err ("[Error] BGP SO_BINDTODEVICE get failed (%s)", safe_strerror (errno));
+      return -1;
+    }
+  else if (name[0] != '\0')
+    {
+      /* Pending:
+         - Cleanup/add proper debugs in this area.
+         - Test/find a way to implement interface config within a VRF.
+       */
+      zlog_debug ("BGP accept vrf/interface %s, %u", name, name_len);
+      bgp = bgp_lookup_by_name (name);
+      if (bgp)
+        {
+          if (bgp->vrf_id)
+            zlog_debug ("BGP SO_BINDTODEVICE vrf-id in BGP %u", bgp->vrf_id);
+          else
+           {
+             zlog_debug ("BGP vrf not active!");
+             return -1;
+           }
+        }
+       /* if socket is interface bound, control may reach here, because name
+          may be equal to the interface name */
+    }
+  else
+    {
+      bgp = NULL;
+    }
+
   /* Set socket send buffer size */
   bgp_update_sock_send_buffer_size(bgp_sock);
 
   /* Check remote IP address */
-  peer1 = peer_lookup (NULL, &su);
+  peer1 = peer_lookup (bgp, &su);
 
   if (! peer1)
     {
-      peer1 = peer_lookup_dynamic_neighbor (NULL, &su);
+      peer1 = peer_lookup_dynamic_neighbor (bgp, &su);
       if (peer1)
         {
           /* Dynamic neighbor has been created, let it proceed */
@@ -382,10 +419,12 @@ bgp_bind (struct peer *peer)
   int ret;
   char *name;
 
-  if (! peer->ifname && !peer->conf_if)
+  if (!peer->bgp->vrf_id && ! peer->ifname && !peer->conf_if)
     return 0;
 
-  name = (peer->conf_if ? peer->conf_if : peer->ifname);
+  name = (peer->conf_if ? peer->conf_if : (peer->ifname ? peer->ifname : peer->bgp->name));
+
+  zlog_debug ("Binding to interface %s\n", name);
 
   if ( bgpd_privs.change (ZPRIVS_RAISE) )
        zlog_err ("bgp_bind: could not raise privs");
index 856e6c464d357284109f08d3fda282fc4e1d1bce..a5e56725af38984dce69d524f4b400fb79bda90b 100644 (file)
@@ -47,15 +47,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
 
 
-/* Route table for next-hop lookup cache. */
-struct bgp_table *bgp_nexthop_cache_table[AFI_MAX];
-
-/* Route table for connected route. */
-static struct bgp_table *bgp_connected_table[AFI_MAX];
-
-/* Route table for import-check */
-struct bgp_table *bgp_import_check_table[AFI_MAX];
-
 char *
 bnc_str (struct bgp_nexthop_cache *bnc, char *buf, int size)
 {
@@ -116,8 +107,6 @@ struct bgp_addr
   int refcnt;
 };
 
-static struct hash *bgp_address_hash;
-
 static void *
 bgp_address_hash_alloc (void *p)
 {
@@ -149,21 +138,21 @@ bgp_address_hash_cmp (const void *p1, const void *p2)
 }
 
 void
-bgp_address_init (void)
+bgp_address_init (struct bgp *bgp)
 {
-  bgp_address_hash = hash_create (bgp_address_hash_key_make,
+  bgp->address_hash = hash_create (bgp_address_hash_key_make,
                                   bgp_address_hash_cmp);
 }
 
 static void
-bgp_address_add (struct prefix *p)
+bgp_address_add (struct bgp *bgp, struct prefix *p)
 {
   struct bgp_addr tmp;
   struct bgp_addr *addr;
 
   tmp.addr = p->u.prefix4;
 
-  addr = hash_get (bgp_address_hash, &tmp, bgp_address_hash_alloc);
+  addr = hash_get (bgp->address_hash, &tmp, bgp_address_hash_alloc);
   if (!addr)
     return;
 
@@ -171,14 +160,14 @@ bgp_address_add (struct prefix *p)
 }
 
 static void
-bgp_address_del (struct prefix *p)
+bgp_address_del (struct bgp *bgp, struct prefix *p)
 {
   struct bgp_addr tmp;
   struct bgp_addr *addr;
 
   tmp.addr = p->u.prefix4;
 
-  addr = hash_lookup (bgp_address_hash, &tmp);
+  addr = hash_lookup (bgp->address_hash, &tmp);
   /* may have been deleted earlier by bgp_interface_down() */
   if (addr == NULL)
     return;
@@ -187,7 +176,7 @@ bgp_address_del (struct prefix *p)
 
   if (addr->refcnt == 0)
     {
-      hash_release (bgp_address_hash, addr);
+      hash_release (bgp->address_hash, addr);
       XFREE (MTYPE_BGP_ADDR, addr);
     }
 }
@@ -199,14 +188,13 @@ struct bgp_connected_ref
 };
 
 void
-bgp_connected_add (struct connected *ifc)
+bgp_connected_add (struct bgp *bgp, struct connected *ifc)
 {
   struct prefix p;
   struct prefix *addr;
   struct bgp_node *rn;
   struct bgp_connected_ref *bc;
-  struct listnode *node, *nnode, *mnode;
-  struct bgp *bgp;
+  struct listnode *node, *nnode;
   struct peer *peer;
 
   addr = ifc->address;
@@ -219,9 +207,9 @@ bgp_connected_add (struct connected *ifc)
       if (prefix_ipv4_any ((struct prefix_ipv4 *) &p))
        return;
 
-      bgp_address_add (addr);
+      bgp_address_add (bgp, addr);
 
-      rn = bgp_node_get (bgp_connected_table[AFI_IP], (struct prefix *) &p);
+      rn = bgp_node_get (bgp->connected_table[AFI_IP], (struct prefix *) &p);
       if (rn->info)
        {
          bc = rn->info;
@@ -234,19 +222,16 @@ bgp_connected_add (struct connected *ifc)
          rn->info = bc;
        }
 
-      for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp))
-       {
-         for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
-           {
-             if (peer->conf_if && (strcmp (peer->conf_if, ifc->ifp->name) == 0) &&
-                 !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
-               {
-                 if (peer_active(peer))
-                   BGP_EVENT_ADD (peer, BGP_Stop);
-                 BGP_EVENT_ADD (peer, BGP_Start);
-               }
-           }
-       }
+      for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
+        {
+          if (peer->conf_if && (strcmp (peer->conf_if, ifc->ifp->name) == 0) &&
+              !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY))
+            {
+              if (peer_active(peer))
+                BGP_EVENT_ADD (peer, BGP_Stop);
+              BGP_EVENT_ADD (peer, BGP_Start);
+            }
+        }
     }
 #ifdef HAVE_IPV6
   else if (addr->family == AF_INET6)
@@ -259,7 +244,7 @@ bgp_connected_add (struct connected *ifc)
       if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
        return;
 
-      rn = bgp_node_get (bgp_connected_table[AFI_IP6], (struct prefix *) &p);
+      rn = bgp_node_get (bgp->connected_table[AFI_IP6], (struct prefix *) &p);
       if (rn->info)
        {
          bc = rn->info;
@@ -276,7 +261,7 @@ bgp_connected_add (struct connected *ifc)
 }
 
 void
-bgp_connected_delete (struct connected *ifc)
+bgp_connected_delete (struct bgp *bgp, struct connected *ifc)
 {
   struct prefix p;
   struct prefix *addr;
@@ -293,9 +278,9 @@ bgp_connected_delete (struct connected *ifc)
       if (prefix_ipv4_any ((struct prefix_ipv4 *) &p))
        return;
 
-      bgp_address_del (addr);
+      bgp_address_del (bgp, addr);
 
-      rn = bgp_node_lookup (bgp_connected_table[AFI_IP], &p);
+      rn = bgp_node_lookup (bgp->connected_table[AFI_IP], &p);
       if (! rn)
        return;
 
@@ -320,7 +305,7 @@ bgp_connected_delete (struct connected *ifc)
       if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
        return;
 
-      rn = bgp_node_lookup (bgp_connected_table[AFI_IP6], (struct prefix *) &p);
+      rn = bgp_node_lookup (bgp->connected_table[AFI_IP6], (struct prefix *) &p);
       if (! rn)
        return;
 
@@ -338,13 +323,13 @@ bgp_connected_delete (struct connected *ifc)
 }
 
 int
-bgp_nexthop_self (struct attr *attr)
+bgp_nexthop_self (struct bgp *bgp, struct attr *attr)
 {
   struct bgp_addr tmp, *addr;
 
   tmp.addr = attr->nexthop;
 
-  addr = hash_lookup (bgp_address_hash, &tmp);
+  addr = hash_lookup (bgp->address_hash, &tmp);
   if (addr)
     return 1;
 
@@ -363,7 +348,7 @@ bgp_multiaccess_check_v4 (struct in_addr nexthop, struct peer *peer)
   p.prefixlen = IPV4_MAX_BITLEN;
   p.u.prefix4 = nexthop;
 
-  rn1 = bgp_node_match (bgp_connected_table[AFI_IP], &p);
+  rn1 = bgp_node_match (peer->bgp->connected_table[AFI_IP], &p);
   if (!rn1)
     return 0;
 
@@ -371,7 +356,7 @@ bgp_multiaccess_check_v4 (struct in_addr nexthop, struct peer *peer)
   p.prefixlen = IPV4_MAX_BITLEN;
   p.u.prefix4 = peer->su.sin.sin_addr;
 
-  rn2 = bgp_node_match (bgp_connected_table[AFI_IP], &p);
+  rn2 = bgp_node_match (peer->bgp->connected_table[AFI_IP], &p);
   if (!rn2)
     {
       bgp_unlock_node(rn1);
@@ -387,7 +372,7 @@ bgp_multiaccess_check_v4 (struct in_addr nexthop, struct peer *peer)
 }
 
 static int
-show_ip_bgp_nexthop_table (struct vty *vty, int detail)
+show_ip_bgp_nexthop_table (struct vty *vty, const char *name, int detail)
 {
   struct bgp_node *rn;
   struct bgp_nexthop_cache *bnc;
@@ -395,11 +380,22 @@ show_ip_bgp_nexthop_table (struct vty *vty, int detail)
   struct nexthop *nexthop;
   time_t tbuf;
   afi_t afi;
+ struct bgp *bgp;
+
+ if (name)
+   bgp = bgp_lookup_by_name (name);
+ else
+   bgp = bgp_get_default ();
+ if (!bgp)
+   {
+     vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
+     return CMD_WARNING;
+   }
 
   vty_out (vty, "Current BGP nexthop cache:%s", VTY_NEWLINE);
   for (afi = AFI_IP ; afi < AFI_MAX ; afi++)
     {
-      for (rn = bgp_table_top (bgp_nexthop_cache_table[afi]); rn; rn = bgp_route_next (rn))
+      for (rn = bgp_table_top (bgp->nexthop_cache_table[afi]); rn; rn = bgp_route_next (rn))
        {
          if ((bnc = rn->info) != NULL)
            {
@@ -473,7 +469,7 @@ DEFUN (show_ip_bgp_nexthop,
        BGP_STR
        "BGP nexthop table\n")
 {
-  return show_ip_bgp_nexthop_table (vty, 0);
+  return show_ip_bgp_nexthop_table (vty, NULL, 0);
 }
 
 DEFUN (show_ip_bgp_nexthop_detail,
@@ -484,20 +480,20 @@ DEFUN (show_ip_bgp_nexthop_detail,
        BGP_STR
        "BGP nexthop table\n")
 {
-  return show_ip_bgp_nexthop_table (vty, 1);
+  return show_ip_bgp_nexthop_table (vty, NULL, 1);
 }
 
 void
-bgp_scan_init (void)
+bgp_scan_init (struct bgp *bgp)
 {
-  bgp_nexthop_cache_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
-  bgp_connected_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
-  bgp_import_check_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
+  bgp->nexthop_cache_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
+  bgp->connected_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
+  bgp->import_check_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST);
 
 #ifdef HAVE_IPV6
-  bgp_nexthop_cache_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
-  bgp_connected_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
-  bgp_import_check_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
+  bgp->nexthop_cache_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
+  bgp->connected_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
+  bgp->import_check_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST);
 #endif /* HAVE_IPV6 */
 
 }
@@ -512,31 +508,31 @@ bgp_scan_vty_init (void)
 }
 
 void
-bgp_scan_finish (void)
+bgp_scan_finish (struct bgp *bgp)
 {
   /* Only the current one needs to be reset. */
-  bgp_nexthop_cache_reset (bgp_nexthop_cache_table[AFI_IP]);
+  bgp_nexthop_cache_reset (bgp->nexthop_cache_table[AFI_IP]);
 
-  bgp_table_unlock (bgp_nexthop_cache_table[AFI_IP]);
-  bgp_nexthop_cache_table[AFI_IP] = NULL;
+  bgp_table_unlock (bgp->nexthop_cache_table[AFI_IP]);
+  bgp->nexthop_cache_table[AFI_IP] = NULL;
 
-  bgp_table_unlock (bgp_connected_table[AFI_IP]);
-  bgp_connected_table[AFI_IP] = NULL;
+  bgp_table_unlock (bgp->connected_table[AFI_IP]);
+  bgp->connected_table[AFI_IP] = NULL;
 
-  bgp_table_unlock (bgp_import_check_table[AFI_IP]);
-  bgp_import_check_table[AFI_IP] = NULL;
+  bgp_table_unlock (bgp->import_check_table[AFI_IP]);
+  bgp->import_check_table[AFI_IP] = NULL;
 
 #ifdef HAVE_IPV6
   /* Only the current one needs to be reset. */
-  bgp_nexthop_cache_reset (bgp_nexthop_cache_table[AFI_IP6]);
+  bgp_nexthop_cache_reset (bgp->nexthop_cache_table[AFI_IP6]);
 
-  bgp_table_unlock (bgp_nexthop_cache_table[AFI_IP6]);
-  bgp_nexthop_cache_table[AFI_IP6] = NULL;
+  bgp_table_unlock (bgp->nexthop_cache_table[AFI_IP6]);
+  bgp->nexthop_cache_table[AFI_IP6] = NULL;
 
-  bgp_table_unlock (bgp_connected_table[AFI_IP6]);
-  bgp_connected_table[AFI_IP6] = NULL;
+  bgp_table_unlock (bgp->connected_table[AFI_IP6]);
+  bgp->connected_table[AFI_IP6] = NULL;
 
-  bgp_table_unlock (bgp_import_check_table[AFI_IP6]);
-  bgp_import_check_table[AFI_IP6] = NULL;
+  bgp_table_unlock (bgp->import_check_table[AFI_IP6]);
+  bgp->import_check_table[AFI_IP6] = NULL;
 #endif /* HAVE_IPV6 */
 }
index 5485bb2c133f19ca66d443d207ab5c89a747c272..ff18e7dc430b5820cc9ab47c03d4089e5c1225fe 100644 (file)
@@ -59,17 +59,18 @@ struct bgp_nexthop_cache
 
 extern int bgp_nexthop_lookup (afi_t, struct peer *peer, struct bgp_info *,
                        int *, int *);
-extern void bgp_connected_add (struct connected *c);
-extern void bgp_connected_delete (struct connected *c);
+extern void bgp_connected_add (struct bgp *bgp, struct connected *c);
+extern void bgp_connected_delete (struct bgp *bgp, struct connected *c);
 extern int bgp_multiaccess_check_v4 (struct in_addr, struct peer *);
 extern int bgp_config_write_scan_time (struct vty *);
-extern int bgp_nexthop_self (struct attr *);
-extern void bgp_address_init (void);
+extern int bgp_nexthop_self (struct bgp *, struct attr *);
+extern void bgp_address_init (struct bgp *);
 extern struct bgp_nexthop_cache *bnc_new(void);
 extern void bnc_free(struct bgp_nexthop_cache *bnc);
 extern void bnc_nexthop_free(struct bgp_nexthop_cache *bnc);
 extern char *bnc_str(struct bgp_nexthop_cache *bnc, char *buf, int size);
-extern void bgp_scan_init(void);
+extern void bgp_scan_init(struct bgp *bgp);
+extern void bgp_scan_finish(struct bgp *bgp);
 extern void bgp_scan_vty_init(void);
 
 #endif /* _QUAGGA_BGP_NEXTHOP_H */
index b68ab1c8c247234366d3190b2956b92ec35637a3..5b54c4b1f0d87e86858fdfa1b89a1200e05e2740 100644 (file)
@@ -42,8 +42,6 @@
 #include "bgpd/bgp_fsm.h"
 
 extern struct zclient *zclient;
-extern struct bgp_table *bgp_nexthop_cache_table[AFI_MAX];
-extern struct bgp_table *bgp_import_check_table[AFI_MAX];
 
 static void register_zebra_rnh(struct bgp_nexthop_cache *bnc,
                           int is_bgp_static_route);
@@ -148,9 +146,9 @@ bgp_find_or_add_nexthop (struct bgp *bgp, afi_t afi, struct bgp_info *ri,
     return 0;
 
   if (is_bgp_static_route)
-    rn = bgp_node_get (bgp_import_check_table[afi], &p);
+    rn = bgp_node_get (bgp->import_check_table[afi], &p);
   else
-    rn = bgp_node_get (bgp_nexthop_cache_table[afi], &p);
+    rn = bgp_node_get (bgp->nexthop_cache_table[afi], &p);
 
   if (!rn->info)
     {
@@ -267,7 +265,7 @@ bgp_delete_connected_nexthop (afi_t afi, struct peer *peer)
   else
     return;
 
-  rn = bgp_node_lookup(bgp_nexthop_cache_table[family2afi(p.family)], &p);
+  rn = bgp_node_lookup(peer->bgp->nexthop_cache_table[family2afi(p.family)], &p);
   if (!rn || !rn->info)
     {
       if (BGP_DEBUG(nht, NHT))
@@ -316,6 +314,14 @@ bgp_parse_nexthop_update (int command, vrf_id_t vrf_id)
   u_char nexthop_num;
   struct prefix p;
   int i;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    {
+      zlog_err("parse nexthop update: instance not found for vrf_id %d", vrf_id);
+      return;
+    }
 
   s = zclient->ibuf;
 
@@ -335,9 +341,9 @@ bgp_parse_nexthop_update (int command, vrf_id_t vrf_id)
     }
 
   if (command == ZEBRA_NEXTHOP_UPDATE)
-    rn = bgp_node_lookup(bgp_nexthop_cache_table[family2afi(p.family)], &p);
+    rn = bgp_node_lookup(bgp->nexthop_cache_table[family2afi(p.family)], &p);
   else if (command == ZEBRA_IMPORT_CHECK_UPDATE)
-    rn = bgp_node_lookup(bgp_import_check_table[family2afi(p.family)], &p);
+    rn = bgp_node_lookup(bgp->import_check_table[family2afi(p.family)], &p);
 
   if (!rn || !rn->info)
     {
@@ -534,10 +540,11 @@ sendmsg_zebra_rnh (struct bgp_nexthop_cache *bnc, int command)
   /* Check socket. */
   if (!zclient || zclient->sock < 0)
     {
-      /* Pending: hiding this error now, because bgp_nht_register_all() is implemented.
+      /* Hiding this error now, because bgp_nht_register_all() is implemented.
          which tries it after zclient_connect()
          zlog_debug("%s: Can't send NH register, Zebra client not established",
                 __FUNCTION__);
+         Pending: remove this comment after reviewing to see if no message is needed in this case
        */
       return;
     }
@@ -545,7 +552,7 @@ sendmsg_zebra_rnh (struct bgp_nexthop_cache *bnc, int command)
   p = &(bnc->node->p);
   s = zclient->obuf;
   stream_reset (s);
-  zclient_create_header (s, command, VRF_DEFAULT);
+  zclient_create_header (s, command, bnc->bgp->vrf_id);
   if (CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED) ||
       CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH))
     stream_putc(s, 1);
@@ -696,31 +703,39 @@ evaluate_paths (struct bgp_nexthop_cache *bnc)
 }
 
 void
-bgp_nht_register_all (void)
+bgp_nht_register_all (vrf_id_t vrf_id)
 {
   struct bgp_node *rn;
   struct bgp_nexthop_cache *bnc;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    {
+      zlog_err("bgp_nht_register_all: instance not found for vrf_id %d", vrf_id);
+      return;
+    }
 
-  for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP]); rn; rn = bgp_route_next (rn))
+  for (rn = bgp_table_top (bgp->nexthop_cache_table[AFI_IP]); rn; rn = bgp_route_next (rn))
     if ((bnc = rn->info) != NULL &&
         !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED))
       {
         register_zebra_rnh(bnc, 0);
       }
-  for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); rn; rn = bgp_route_next (rn))
+  for (rn = bgp_table_top (bgp->nexthop_cache_table[AFI_IP6]); rn; rn = bgp_route_next (rn))
     if ((bnc = rn->info) != NULL &&
         !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED))
       {
         register_zebra_rnh(bnc, 0);
       }
 
-  for (rn = bgp_table_top (bgp_import_check_table[AFI_IP]); rn; rn = bgp_route_next (rn))
+  for (rn = bgp_table_top (bgp->import_check_table[AFI_IP]); rn; rn = bgp_route_next (rn))
     if ((bnc = rn->info) != NULL &&
         !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED))
       {
         register_zebra_rnh(bnc, 1);
       }
-  for (rn = bgp_table_top (bgp_import_check_table[AFI_IP6]); rn; rn = bgp_route_next (rn))
+  for (rn = bgp_table_top (bgp->import_check_table[AFI_IP6]); rn; rn = bgp_route_next (rn))
     if ((bnc = rn->info) != NULL &&
         !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED))
       {
index aeb0e407f43a5f110126947c049bb6c8b045bb2e..4fc45e88d0bece39ad922bcdd1649ada898ebf57 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef _BGP_NHT_H
 #define _BGP_NHT_H
 
-extern void bgp_nht_register_all (void);
+extern void bgp_nht_register_all (vrf_id_t);
 
 /**
  * bgp_parse_nexthop_update() - parse a nexthop update message from Zebra.
index 492694a94e9d186013c34aa6fc35a6a0c7c61e4e..fb0e8b3831325eb42a9a179ba5bab6da3a7d1b42 100644 (file)
@@ -1828,7 +1828,7 @@ bgp_process_main (struct work_queue *wq, void *data)
   group_announce_route(bgp, afi, safi, rn, new_select);
 
   /* FIB update. */
-  if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
+  if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp_flag_check(bgp, BGP_FLAG_INSTANCE_TYPE_VIEW) &&
       ! bgp_option_check (BGP_OPT_NO_FIB)))
     {
       if (new_select 
@@ -2102,7 +2102,7 @@ bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf)
 
 /* Check if received nexthop is valid or not. */
 static int
-bgp_update_martian_nexthop (afi_t afi, safi_t safi, struct attr *attr)
+bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr *attr)
 {
   struct attr_extra *attre = attr->extra;
   int ret = 0;
@@ -2116,7 +2116,7 @@ bgp_update_martian_nexthop (afi_t afi, safi_t safi, struct attr *attr)
     {
       if (attr->nexthop.s_addr == 0 ||
           IPV4_CLASS_DE (ntohl (attr->nexthop.s_addr)) ||
-          bgp_nexthop_self (attr))
+          bgp_nexthop_self (bgp, attr))
         ret = 1;
     }
 
@@ -2248,7 +2248,7 @@ bgp_update_main (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
     }
 
   /* next hop check.  */
-  if (bgp_update_martian_nexthop (afi, safi, &new_attr))
+  if (bgp_update_martian_nexthop (bgp, afi, safi, &new_attr))
     {
        reason = "martian or self next-hop;";
        bgp_attr_flush (&new_attr);
@@ -3684,6 +3684,41 @@ bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
   return CMD_SUCCESS;
 }
 
+void
+bgp_static_add (struct bgp *bgp)
+{
+  afi_t afi;
+  safi_t safi;
+  struct bgp_node *rn;
+  struct bgp_node *rm;
+  struct bgp_table *table;
+  struct bgp_static *bgp_static;
+
+  for (afi = AFI_IP; afi < AFI_MAX; afi++)
+    for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
+      for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
+       if (rn->info != NULL)
+         {      
+           if (safi == SAFI_MPLS_VPN)
+             {
+               table = rn->info;
+
+               for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
+                 {
+                   bgp_static = rn->info;
+                   bgp_static_update_vpnv4 (bgp, &rm->p,
+                                             AFI_IP, SAFI_MPLS_VPN,
+                                            (struct prefix_rd *)&rn->p,
+                                            bgp_static->tag);
+                 }
+             }
+           else
+             {
+               bgp_static_update (bgp, &rn->p, rn->info, afi, safi);
+             }
+         }
+}
+
 /* Called from bgp_delete().  Delete all static routes from the BGP
    instance. */
 void
@@ -5234,12 +5269,10 @@ ALIAS (no_ipv6_aggregate_address_summary_only,
 
 /* Redistribute route treatment. */
 void
-bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
+bgp_redistribute_add (struct bgp *bgp, struct prefix *p, const struct in_addr *nexthop,
                      const struct in6_addr *nexthop6, unsigned int ifindex,
                      u_int32_t metric, u_char type, u_short instance, u_short tag)
 {
-  struct bgp *bgp;
-  struct listnode *node, *nnode;
   struct bgp_info *new;
   struct bgp_info *bi;
   struct bgp_info info;
@@ -5269,104 +5302,101 @@ bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
   attr.extra->tag = tag;
 
-  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
+  afi = family2afi (p->family);
+
+  red = bgp_redist_lookup(bgp, afi, type, instance);
+  if (red)
     {
-      afi = family2afi (p->family);
+      struct attr attr_new;
+      struct attr_extra extra_new;
 
-      red = bgp_redist_lookup(bgp, afi, type, instance);
-      if (red)
-       {
-         struct attr attr_new;
-         struct attr_extra extra_new;
+      /* Copy attribute for modification. */
+      attr_new.extra = &extra_new;
+      bgp_attr_dup (&attr_new, &attr);
 
-         /* Copy attribute for modification. */
-         attr_new.extra = &extra_new;
-         bgp_attr_dup (&attr_new, &attr);
+      if (red->redist_metric_flag)
+        attr_new.med = red->redist_metric;
 
-         if (red->redist_metric_flag)
-           attr_new.med = red->redist_metric;
+      /* Apply route-map. */
+      if (red->rmap.name)
+        {
+          info.peer = bgp->peer_self;
+          info.attr = &attr_new;
 
-         /* Apply route-map. */
-         if (red->rmap.name)
-           {
-             info.peer = bgp->peer_self;
-             info.attr = &attr_new;
+          SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
 
-              SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
+          ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
 
-             ret = route_map_apply (red->rmap.map, p, RMAP_BGP, &info);
+          bgp->peer_self->rmap_type = 0;
 
-              bgp->peer_self->rmap_type = 0;
+          if (ret == RMAP_DENYMATCH)
+            {
+              /* Free uninterned attribute. */
+              bgp_attr_flush (&attr_new);
+
+              /* Unintern original. */
+              aspath_unintern (&attr.aspath);
+              bgp_attr_extra_free (&attr);
+              bgp_redistribute_delete (bgp, p, type, instance);
+              return;
+            }
+        }
 
-             if (ret == RMAP_DENYMATCH)
-               {
-                 /* Free uninterned attribute. */
-                 bgp_attr_flush (&attr_new);
-
-                 /* Unintern original. */
-                 aspath_unintern (&attr.aspath);
-                 bgp_attr_extra_free (&attr);
-                 bgp_redistribute_delete (p, type, instance);
-                 return;
-               }
-           }
+      bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], 
+                             afi, SAFI_UNICAST, p, NULL);
 
-          bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], 
-                                 afi, SAFI_UNICAST, p, NULL);
-          
-         new_attr = bgp_attr_intern (&attr_new);
+      new_attr = bgp_attr_intern (&attr_new);
 
-         for (bi = bn->info; bi; bi = bi->next)
-           if (bi->peer == bgp->peer_self
-               && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
-             break;
-         if (bi)
-           {
-              /* Ensure the (source route) type is updated. */
-              bi->type = type;
-             if (attrhash_cmp (bi->attr, new_attr) &&
-                 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
-               {
-                 bgp_attr_unintern (&new_attr);
-                 aspath_unintern (&attr.aspath);
-                 bgp_attr_extra_free (&attr);
-                 bgp_unlock_node (bn);
-                 return;
-               }
-             else
-               {
-                 /* The attribute is changed. */
-                 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
-                 /* Rewrite BGP route information. */
-                 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
-                   bgp_info_restore(bn, bi);
-                 else
-                   bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
-                 bgp_attr_unintern (&bi->attr);
-                 bi->attr = new_attr;
-                 bi->uptime = bgp_clock ();
-                 /* Process change. */
-                 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
-                 bgp_process (bgp, bn, afi, SAFI_UNICAST);
-                 bgp_unlock_node (bn);
-                 aspath_unintern (&attr.aspath);
-                 bgp_attr_extra_free (&attr);
-                 return;
-               }
-           }
+      for (bi = bn->info; bi; bi = bi->next)
+        if (bi->peer == bgp->peer_self
+            && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
+          break;
+
+      if (bi)
+        {
+          /* Ensure the (source route) type is updated. */
+          bi->type = type;
+          if (attrhash_cmp (bi->attr, new_attr) &&
+              !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
+            {
+              bgp_attr_unintern (&new_attr);
+              aspath_unintern (&attr.aspath);
+              bgp_attr_extra_free (&attr);
+              bgp_unlock_node (bn);
+              return;
+            }
+          else
+            {
+              /* The attribute is changed. */
+              bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
 
-         new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
-                         new_attr, bn);
-         SET_FLAG (new->flags, BGP_INFO_VALID);
+              /* Rewrite BGP route information. */
+              if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
+                bgp_info_restore(bn, bi);
+              else
+                bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
+              bgp_attr_unintern (&bi->attr);
+              bi->attr = new_attr;
+              bi->uptime = bgp_clock ();
+
+              /* Process change. */
+              bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
+              bgp_process (bgp, bn, afi, SAFI_UNICAST);
+              bgp_unlock_node (bn);
+              aspath_unintern (&attr.aspath);
+              bgp_attr_extra_free (&attr);
+              return;
+            }
+        }
 
-         bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
-         bgp_info_add (bn, new);
-         bgp_unlock_node (bn);
-         bgp_process (bgp, bn, afi, SAFI_UNICAST);
-       }
+      new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance, bgp->peer_self,
+                      new_attr, bn);
+      SET_FLAG (new->flags, BGP_INFO_VALID);
+
+      bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
+      bgp_info_add (bn, new);
+      bgp_unlock_node (bn);
+      bgp_process (bgp, bn, afi, SAFI_UNICAST);
     }
 
   /* Unintern original. */
@@ -5375,37 +5405,32 @@ bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
 }
 
 void
-bgp_redistribute_delete (struct prefix *p, u_char type, u_short instance)
+bgp_redistribute_delete (struct bgp *bgp, struct prefix *p, u_char type, u_short instance)
 {
-  struct bgp *bgp;
-  struct listnode *node, *nnode;
   afi_t afi;
   struct bgp_node *rn;
   struct bgp_info *ri;
   struct bgp_redist *red;
 
-  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
-    {
-      afi = family2afi (p->family);
+  afi = family2afi (p->family);
 
-      red = bgp_redist_lookup(bgp, afi, type, instance);
-      if (red)
-       {
-         rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
+  red = bgp_redist_lookup(bgp, afi, type, instance);
+  if (red)
+    {
+      rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
 
-         for (ri = rn->info; ri; ri = ri->next)
-           if (ri->peer == bgp->peer_self
-               && ri->type == type)
-             break;
+      for (ri = rn->info; ri; ri = ri->next)
+        if (ri->peer == bgp->peer_self
+            && ri->type == type)
+          break;
 
-         if (ri)
-           {
-             bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
-             bgp_info_delete (rn, ri);
-             bgp_process (bgp, rn, afi, SAFI_UNICAST);
-           }
-         bgp_unlock_node (rn);
-       }
+      if (ri)
+        {
+          bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
+          bgp_info_delete (rn, ri);
+          bgp_process (bgp, rn, afi, SAFI_UNICAST);
+        }
+      bgp_unlock_node (rn);
     }
 }
 
@@ -7468,7 +7493,7 @@ bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
       bgp = bgp_lookup_by_name (view_name);
       if (bgp == NULL)
        {
-         vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
+         vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
          return CMD_WARNING;
        }
     }
@@ -7800,21 +7825,21 @@ DEFUN (show_ip_bgp_vpnv4_rd_prefix,
 
 DEFUN (show_ip_bgp_view,
        show_ip_bgp_view_cmd,
-       "show ip bgp view WORD {json}",
+       "show ip bgp (view|vrf) WORD {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "JavaScript Object Notation\n")
 {
   struct bgp *bgp;
 
   /* BGP structure lookup. */
-  bgp = bgp_lookup_by_name (argv[0]);
+  bgp = bgp_lookup_by_name (argv[1]);
   if (bgp == NULL)
        {
-         vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+         vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
          return CMD_WARNING;
        }
 
@@ -7823,30 +7848,30 @@ DEFUN (show_ip_bgp_view,
 
 DEFUN (show_ip_bgp_view_route,
        show_ip_bgp_view_route_cmd,
-       "show ip bgp view WORD A.B.C.D {json}",
+       "show ip bgp (view|vrf) WORD A.B.C.D {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Network in the BGP routing table to display\n"
        "JavaScript Object Notation\n")
 {
-  return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
+  return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
 }
 
 DEFUN (show_ip_bgp_view_prefix,
        show_ip_bgp_view_prefix_cmd,
-       "show ip bgp view WORD A.B.C.D/M {json}",
+       "show ip bgp (view|vrf) WORD A.B.C.D/M {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
        "JavaScript Object Notation\n")
 {
-  return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
+  return bgp_show_route (vty, argv[1], argv[2], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
 }
 
 #ifdef HAVE_IPV6
@@ -8123,20 +8148,20 @@ DEFUN (show_ipv6_bgp_prefix,
 
 DEFUN (show_bgp_view,
        show_bgp_view_cmd,
-       "show bgp view WORD {json}",
+       "show bgp (view|vrf) WORD {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "JavaScript Object Notation\n")
 {
   struct bgp *bgp;
 
   /* BGP structure lookup. */
-  bgp = bgp_lookup_by_name (argv[0]);
+  bgp = bgp_lookup_by_name (argv[1]);
   if (bgp == NULL)
     {
-      vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+      vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
       return CMD_WARNING;
     }
 
@@ -8145,58 +8170,58 @@ DEFUN (show_bgp_view,
 
 ALIAS (show_bgp_view,
        show_bgp_view_ipv6_cmd,
-       "show bgp view WORD ipv6 {json}",
+       "show bgp (view|vrf) WORD ipv6 {json}",
        SHOW_STR
        BGP_STR             
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "JavaScript Object Notation\n")
   
 DEFUN (show_bgp_view_route,
        show_bgp_view_route_cmd,
-       "show bgp view WORD X:X::X:X {json}",
+       "show bgp (view|vrf) WORD X:X::X:X {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Network in the BGP routing table to display\n"
        "JavaScript Object Notation\n")
 {
-  return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
+  return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
 }
 
 ALIAS (show_bgp_view_route,
        show_bgp_view_ipv6_route_cmd,
-       "show bgp view WORD ipv6 X:X::X:X {json}",
+       "show bgp (view|vrf) WORD ipv6 X:X::X:X {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Network in the BGP routing table to display\n"
        "JavaScript Object Notation\n")
 
 DEFUN (show_bgp_view_prefix,
        show_bgp_view_prefix_cmd,
-       "show bgp view WORD X:X::X:X/M {json}",
+       "show bgp (view|vrf) WORD X:X::X:X/M {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"       
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"       
        "IPv6 prefix <network>/<length>\n"
        "JavaScript Object Notation\n")
 {
-  return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
+  return bgp_show_route (vty, argv[1], argv[2], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL, use_json(argc, argv));
 }
 
 ALIAS (show_bgp_view_prefix,
        show_bgp_view_ipv6_prefix_cmd,
-       "show bgp view WORD ipv6 X:X::X:X/M {json}",
+       "show bgp (view|vrf) WORD ipv6 X:X::X:X/M {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "IPv6 prefix <network>/<length>\n"
        "JavaScript Object Notation\n")
@@ -8849,7 +8874,7 @@ bgp_show_community (struct vty *vty, const char *view_name, int argc,
       bgp = bgp_lookup_by_name (view_name);
       if (bgp == NULL)
        {
-         vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
+         vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
          return CMD_WARNING;
        }
     }
@@ -9063,14 +9088,14 @@ ALIAS (show_ip_bgp_ipv4_community,
 DEFUN (show_bgp_view_afi_safi_community_all,
        show_bgp_view_afi_safi_community_all_cmd,
 #ifdef HAVE_IPV6
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community",
 #else
-       "show bgp view WORD ipv4 (unicast|multicast) community",
+       "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community",
 #endif
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
 #ifdef HAVE_IPV6
        "Address family\n"
@@ -9084,19 +9109,19 @@ DEFUN (show_bgp_view_afi_safi_community_all,
   struct bgp *bgp;
 
   /* BGP structure lookup. */
-  bgp = bgp_lookup_by_name (argv[0]);
+  bgp = bgp_lookup_by_name (argv[1]);
   if (bgp == NULL)
     {
-      vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+      vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
       return CMD_WARNING;
     }
 
 #ifdef HAVE_IPV6
-  afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
-  safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+  afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
+  safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
 #else
   afi = AFI_IP;
-  safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+  safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
 #endif
   return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL, 0);
 }
@@ -9104,14 +9129,14 @@ DEFUN (show_bgp_view_afi_safi_community_all,
 DEFUN (show_bgp_view_afi_safi_community,
        show_bgp_view_afi_safi_community_cmd,
 #ifdef HAVE_IPV6
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
 #else
-       "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
 #endif
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
 #ifdef HAVE_IPV6
        "Address family\n"
@@ -9128,27 +9153,27 @@ DEFUN (show_bgp_view_afi_safi_community,
   int safi;
 
 #ifdef HAVE_IPV6
-  afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
-  safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
-  return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
+  afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
+  safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+  return bgp_show_community (vty, argv[1], argc-4, &argv[4], 0, afi, safi);
 #else
   afi = AFI_IP;
-  safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
-  return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
+  safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+  return bgp_show_community (vty, argv[1], argc-3, &argv[3], 0, afi, safi);
 #endif
 }
 
 ALIAS (show_bgp_view_afi_safi_community,
        show_bgp_view_afi_safi_community2_cmd,
 #ifdef HAVE_IPV6
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
 #else
-       "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
 #endif
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
 #ifdef HAVE_IPV6
        "Address family\n"
@@ -9168,14 +9193,14 @@ ALIAS (show_bgp_view_afi_safi_community,
 ALIAS (show_bgp_view_afi_safi_community,
        show_bgp_view_afi_safi_community3_cmd,
 #ifdef HAVE_IPV6
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
 #else
-       "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
 #endif
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
 #ifdef HAVE_IPV6
        "Address family\n"
@@ -9199,14 +9224,14 @@ ALIAS (show_bgp_view_afi_safi_community,
 ALIAS (show_bgp_view_afi_safi_community,
        show_bgp_view_afi_safi_community4_cmd,
 #ifdef HAVE_IPV6
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
 #else
-       "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+       "show bgp (view|vrf) WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
 #endif
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
 #ifdef HAVE_IPV6
        "Address family\n"
@@ -10389,7 +10414,7 @@ peer_lookup_in_view (struct vty *vty, const char *view_name,
               json_object_free(json_no);
             }
           else
-            vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
+            vty_out (vty, "Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
           return NULL;
         }      
     }
@@ -10785,25 +10810,25 @@ ALIAS (show_bgp_statistics,
 
 DEFUN (show_bgp_statistics_view,
        show_bgp_statistics_view_cmd,
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) statistics",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "Address family\n"
        "Address family\n"
        "Address Family modifier\n"
        "Address Family modifier\n"
        "BGP RIB advertisement statistics\n")
 {
-  return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
+  return bgp_table_stats_vty (vty, NULL, argv[1], argv[2]);
 }
 
 ALIAS (show_bgp_statistics_view,
        show_bgp_statistics_view_vpnv4_cmd,
-       "show bgp view WORD (ipv4) (vpnv4) statistics",
+       "show bgp (view|vrf) WORD (ipv4) (vpnv4) statistics",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "Address family\n"
        "Address Family modifier\n"
        "BGP RIB advertisement statistics\n")
@@ -11342,12 +11367,12 @@ peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
 
 DEFUN (show_ip_bgp_view_neighbor_advertised_route,
        show_ip_bgp_view_neighbor_advertised_route_cmd,
-       "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
+       "show ip bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -11357,10 +11382,10 @@ DEFUN (show_ip_bgp_view_neighbor_advertised_route,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
-    peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+  if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
+    peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
   else
-    peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+    peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
 
   if (! peer) 
     return CMD_WARNING;
@@ -11464,11 +11489,11 @@ ALIAS (show_ip_bgp_ipv4_neighbor_advertised_route,
 #ifdef HAVE_IPV6
 DEFUN (show_bgp_view_neighbor_advertised_route,
        show_bgp_view_neighbor_advertised_route_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -11479,10 +11504,10 @@ DEFUN (show_bgp_view_neighbor_advertised_route,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
-    peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+  if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
+    peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
   else
-    peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+    peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
 
   if (! peer)
     return CMD_WARNING;
@@ -11492,11 +11517,11 @@ DEFUN (show_bgp_view_neighbor_advertised_route,
 
 ALIAS (show_bgp_view_neighbor_advertised_route,
        show_bgp_view_ipv6_neighbor_advertised_route_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) advertised-routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -11589,11 +11614,11 @@ DEFUN (ipv6_mbgp_neighbor_advertised_route,
 
 DEFUN (show_bgp_view_neighbor_received_routes,
        show_bgp_view_neighbor_received_routes_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -11606,17 +11631,17 @@ DEFUN (show_bgp_view_neighbor_received_routes,
 
   if (uj)
     {
-      if (argc == 3)
-        peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+      if (argc == 4)
+        peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
       else
-        peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+        peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
     }
   else
     {
-      if (argc == 2)
-        peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+      if (argc == 3)
+        peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
       else
-        peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+        peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
     }
 
   if (! peer)
@@ -11627,12 +11652,12 @@ DEFUN (show_bgp_view_neighbor_received_routes,
 
 DEFUN (show_ip_bgp_view_neighbor_received_routes,
        show_ip_bgp_view_neighbor_received_routes_cmd,
-       "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
+       "show ip bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -11643,10 +11668,10 @@ DEFUN (show_ip_bgp_view_neighbor_received_routes,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  if (argc == 3 || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
-    peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+  if (argc == 4 || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
+    peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
   else
-    peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+    peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
 
   if (! peer)
     return CMD_WARNING;
@@ -11656,11 +11681,11 @@ DEFUN (show_ip_bgp_view_neighbor_received_routes,
 
 ALIAS (show_bgp_view_neighbor_received_routes,
        show_bgp_view_ipv6_neighbor_received_routes_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received-routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -11763,14 +11788,14 @@ ALIAS (show_ip_bgp_ipv4_neighbor_received_routes,
 DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
        show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
 #ifdef HAVE_IPV6
-       "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
+       "show bgp (view|vrf) WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
 #else
-       "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
+       "show bgp (view|vrf) WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X|WORD) (advertised-routes|received-routes) {json}",
 #endif
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
 #ifdef HAVE_IPV6
        "Address family\n"
@@ -11791,14 +11816,14 @@ DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  peer = peer_lookup_in_view (vty, argv[0], argv[3], uj);
+  peer = peer_lookup_in_view (vty, argv[1], argv[4], uj);
 
   if (! peer)
     return CMD_WARNING;
 
-  afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
-  safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
-  in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
+  afi = (strncmp (argv[2], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
+  safi = (strncmp (argv[3], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+  in = (strncmp (argv[5], "r", 1) == 0) ? 1 : 0;
 
   return peer_adj_routes (vty, peer, afi, safi, in, NULL, uj);
 }
@@ -12173,11 +12198,11 @@ DEFUN (ipv6_mbgp_neighbor_received_routes,
 
 DEFUN (show_bgp_view_neighbor_received_prefix_filter,
        show_bgp_view_neighbor_received_prefix_filter_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -12194,7 +12219,7 @@ DEFUN (show_bgp_view_neighbor_received_prefix_filter,
   u_char uj = use_json(argc, argv);
 
   /* BGP structure lookup. */
-  bgp = bgp_lookup_by_name (argv[0]);
+  bgp = bgp_lookup_by_name (argv[1]);
   if (bgp == NULL)
     {
       if (uj)
@@ -12206,14 +12231,14 @@ DEFUN (show_bgp_view_neighbor_received_prefix_filter,
           json_object_free(json_no);
         }
       else
-        vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+        vty_out (vty, "Can't find BGP instance %s%s", argv[1], VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  ret = str2sockunion (argv[1], &su);
+  ret = str2sockunion (argv[2], &su);
   if (ret < 0)
     {
-      peer = peer_lookup_by_conf_if (bgp, argv[1]);
+      peer = peer_lookup_by_conf_if (bgp, argv[2]);
       if (! peer)
         {
           if (uj)
@@ -12223,13 +12248,13 @@ DEFUN (show_bgp_view_neighbor_received_prefix_filter,
               json_no = json_object_new_object();
               json_sub = json_object_new_object();
               json_object_string_add(json_no, "warning", "Malformed address or name");
-              json_object_string_add(json_sub, "warningCause", argv[1]);
+              json_object_string_add(json_sub, "warningCause", argv[2]);
               json_object_object_add(json_no, "detail", json_sub);
               vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
               json_object_free(json_no);
             }
           else
-            vty_out (vty, "%% Malformed address or name: %s%s", argv[1], VTY_NEWLINE);
+            vty_out (vty, "%% Malformed address or name: %s%s", argv[2], VTY_NEWLINE);
           return CMD_WARNING;
         }
     }
@@ -12266,11 +12291,11 @@ DEFUN (show_bgp_view_neighbor_received_prefix_filter,
 }
 ALIAS (show_bgp_view_neighbor_received_prefix_filter,
        show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) received prefix-filter {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -12409,11 +12434,11 @@ DEFUN (show_ip_bgp_ipv4_neighbor_routes,
 #ifdef HAVE_IPV6
 DEFUN (show_bgp_view_neighbor_routes,
        show_bgp_view_neighbor_routes_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -12424,11 +12449,11 @@ DEFUN (show_bgp_view_neighbor_routes,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
-      || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
-    peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+  if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
+      || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
+    peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
   else
-    peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+    peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
    
   if (! peer)
     return CMD_WARNING;
@@ -12439,11 +12464,11 @@ DEFUN (show_bgp_view_neighbor_routes,
 
 ALIAS (show_bgp_view_neighbor_routes,
        show_bgp_view_ipv6_neighbor_routes_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -12454,11 +12479,11 @@ ALIAS (show_bgp_view_neighbor_routes,
 
 DEFUN (show_bgp_view_neighbor_damp,
        show_bgp_view_neighbor_damp_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -12469,11 +12494,11 @@ DEFUN (show_bgp_view_neighbor_damp,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
-      || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
-    peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+  if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
+      || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
+    peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
   else
-    peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+    peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
 
   if (! peer)
     return CMD_WARNING;
@@ -12484,11 +12509,11 @@ DEFUN (show_bgp_view_neighbor_damp,
 
 ALIAS (show_bgp_view_neighbor_damp,
        show_bgp_view_ipv6_neighbor_damp_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) dampened-routes {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -12499,11 +12524,11 @@ ALIAS (show_bgp_view_neighbor_damp,
 
 DEFUN (show_bgp_view_neighbor_flap,
        show_bgp_view_neighbor_flap_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -12514,11 +12539,11 @@ DEFUN (show_bgp_view_neighbor_flap,
   struct peer *peer;
   u_char uj = use_json(argc, argv);
 
-  if ((argc == 3 && argv[2] && strcmp(argv[2], "json") == 0)
-      || (argc == 2 && argv[1] && strcmp(argv[1], "json") != 0))
-    peer = peer_lookup_in_view (vty, argv[0], argv[1], uj);
+  if ((argc == 4 && argv[3] && strcmp(argv[3], "json") == 0)
+      || (argc == 3 && argv[2] && strcmp(argv[2], "json") != 0))
+    peer = peer_lookup_in_view (vty, argv[1], argv[2], uj);
   else
-    peer = peer_lookup_in_view (vty, NULL, argv[0], uj);
+    peer = peer_lookup_in_view (vty, NULL, argv[1], uj);
 
   if (! peer)
     return CMD_WARNING;
@@ -12529,11 +12554,11 @@ DEFUN (show_bgp_view_neighbor_flap,
 
 ALIAS (show_bgp_view_neighbor_flap,
        show_bgp_view_ipv6_neighbor_flap_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) flap-statistics {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -13058,7 +13083,7 @@ bgp_clear_damp_route (struct vty *vty, const char *view_name,
       bgp = bgp_lookup_by_name (view_name);
       if (bgp == NULL)
        {
-         vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
+         vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
          return CMD_WARNING;
        }
     }
index faeb5d6a3c70db40178a4d478c3a32d230cc9377..3a2d9382896a4acd0d9f42137d9436c2b9f2b46f 100644 (file)
@@ -239,12 +239,13 @@ extern int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *);
 
 extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
 
-extern void bgp_redistribute_add (struct prefix *, const struct in_addr *,
+extern void bgp_redistribute_add (struct bgp *, struct prefix *, const struct in_addr *,
                                  const struct in6_addr *, unsigned int ifindex,
                                  u_int32_t, u_char, u_short, u_short);
-extern void bgp_redistribute_delete (struct prefix *, u_char, u_short);
+extern void bgp_redistribute_delete (struct bgp *, struct prefix *, u_char, u_short);
 extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int, u_short);
 
+extern void bgp_static_add (struct bgp *);
 extern void bgp_static_delete (struct bgp *);
 extern void bgp_static_redo_import_check (struct bgp *);
 extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
index db4d21533154830b97beb394684480f300d2fbee..a9ff7577806ba90cbaa27019311797f83e955907 100644 (file)
@@ -55,8 +55,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "bgpd/bgp_updgrp.h"
 #include "bgpd/bgp_bfd.h"
 
-extern struct in_addr router_id_zebra;
-
 static struct peer_group *
 listen_range_exists (struct bgp *bgp, struct prefix *range, int exact);
 
@@ -82,16 +80,16 @@ bgp_node_safi (struct vty *vty)
 }
 
 static int
-peer_address_self_check (union sockunion *su)
+peer_address_self_check (struct bgp *bgp, union sockunion *su)
 {
   struct interface *ifp = NULL;
 
   if (su->sa.sa_family == AF_INET)
-    ifp = if_lookup_by_ipv4_exact (&su->sin.sin_addr);
+    ifp = if_lookup_by_ipv4_exact (&su->sin.sin_addr, bgp->vrf_id);
 #ifdef HAVE_IPV6
   else if (su->sa.sa_family == AF_INET6)
     ifp = if_lookup_by_ipv6_exact (&su->sin6.sin6_addr,
-                                  su->sin6.sin6_scope_id);
+                                  su->sin6.sin6_scope_id, bgp->vrf_id);
 #endif /* HAVE IPV6 */
 
   if (ifp)
@@ -471,7 +469,7 @@ bgp_clear_vty (struct vty *vty, const char *name, afi_t afi, safi_t safi,
       bgp = bgp_lookup_by_name (name);
       if (bgp == NULL)
         {
-          vty_out (vty, "Can't find BGP view %s%s", name, VTY_NEWLINE);
+          vty_out (vty, "Can't find BGP instance %s%s", name, VTY_NEWLINE);
           return CMD_WARNING;
         }
     }
@@ -613,6 +611,7 @@ DEFUN (router_bgp,
   // "router bgp" without an ASN
   if (argc < 1)
     {
+      //Pending: Make VRF option available for ASN less config
       bgp = bgp_get_default();
 
       if (bgp == NULL)
@@ -633,8 +632,8 @@ DEFUN (router_bgp,
     {
       VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
 
-      if (argc == 2)
-        name = argv[1];
+      if (argc == 3)
+        name = argv[2];
 
       ret = bgp_get (&bgp, &as, name);
       switch (ret)
@@ -647,11 +646,17 @@ DEFUN (router_bgp,
           vty_out (vty, "BGP is already running; AS is %u%s", as, VTY_NEWLINE);
           return CMD_WARNING;
         case BGP_ERR_INSTANCE_MISMATCH:
-          vty_out (vty, "BGP view name and AS number mismatch%s", VTY_NEWLINE);
+          vty_out (vty, "BGP instance name and AS number mismatch%s", VTY_NEWLINE);
           vty_out (vty, "BGP instance is already running; AS is %u%s",
                    as, VTY_NEWLINE);
           return CMD_WARNING;
         }
+
+      /* Pending: handle when user tries to change a view to vrf n vv. */
+      if (argc == 3 && !strcmp(argv[1], "vrf")) 
+        bgp_flag_set (bgp, BGP_FLAG_INSTANCE_TYPE_VRF);
+      if (argc == 3 && !strcmp(argv[1], "view")) 
+        bgp_flag_set (bgp, BGP_FLAG_INSTANCE_TYPE_VIEW);
     }
 
   vty->node = BGP_NODE;
@@ -661,12 +666,12 @@ DEFUN (router_bgp,
 }
 
 ALIAS (router_bgp,
-       router_bgp_view_cmd,
-       "router bgp " CMD_AS_RANGE " view WORD",
+       router_bgp_instance_cmd,
+       "router bgp " CMD_AS_RANGE " (view|vrf) WORD",
        ROUTER_STR
        BGP_STR
        AS_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n")
 
 ALIAS (router_bgp,
@@ -690,8 +695,8 @@ DEFUN (no_router_bgp,
 
   VTY_GET_INTEGER_RANGE ("AS", as, argv[0], 1, BGP_AS4_MAX);
 
-  if (argc == 2)
-    name = argv[1];
+  if (argc == 3)
+    name = argv[2];
 
   /* Lookup bgp structure. */
   bgp = bgp_lookup (as, name);
@@ -707,13 +712,13 @@ DEFUN (no_router_bgp,
 }
 
 ALIAS (no_router_bgp,
-       no_router_bgp_view_cmd,
-       "no router bgp " CMD_AS_RANGE " view WORD",
+       no_router_bgp_instance_cmd,
+       "no router bgp " CMD_AS_RANGE " (view|vrf) WORD",
        NO_STR
        ROUTER_STR
        BGP_STR
        AS_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n")
 
 /* BGP router-id.  */
@@ -777,7 +782,7 @@ DEFUN (no_bgp_router_id,
     }
 
   bgp->router_id_static.s_addr = 0;
-  bgp_router_id_set (bgp, &router_id_zebra);
+  bgp_router_id_set (bgp, &bgp->router_id_zebra);
 
   return CMD_SUCCESS;
 }
@@ -2639,7 +2644,7 @@ peer_remote_as_vty (struct vty *vty, const char *peer_str,
     }
   else
     {
-      if (peer_address_self_check (&su))
+      if (peer_address_self_check (bgp, &su))
         {
           vty_out (vty, "%% Can not configure the local system as neighbor%s",
                    VTY_NEWLINE);
@@ -3252,7 +3257,7 @@ DEFUN (neighbor_set_peer_group,
     }
   else
     {
-      if (peer_address_self_check (&su))
+      if (peer_address_self_check (bgp, &su))
         {
           vty_out (vty, "%% Can not configure the local system as neighbor%s",
                    VTY_NEWLINE);
@@ -5870,7 +5875,7 @@ bgp_clear_prefix (struct vty *vty, char *view_name, const char *ip_str,
       bgp = bgp_lookup_by_name (view_name);
       if (bgp == NULL)
         {
-          vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
+          vty_out (vty, "%% Can't find BGP instance %s%s", view_name, VTY_NEWLINE);
           return CMD_WARNING;
         }
     }
@@ -5940,8 +5945,8 @@ DEFUN (clear_ip_bgp_all,
        BGP_STR
        "Clear all peers\n")
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], 0, 0, clear_all, BGP_CLEAR_SOFT_NONE, NULL);    
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], 0, 0, clear_all, BGP_CLEAR_SOFT_NONE, NULL);    
 
   return bgp_clear_vty (vty, NULL, 0, 0, clear_all, BGP_CLEAR_SOFT_NONE, NULL);
 }
@@ -5963,20 +5968,20 @@ ALIAS (clear_ip_bgp_all,
 
 ALIAS (clear_ip_bgp_all,
        clear_ip_bgp_instance_all_cmd,
-       "clear ip bgp view WORD *",
+       "clear ip bgp (view|vrf) WORD *",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n")
 
 ALIAS (clear_ip_bgp_all,
        clear_bgp_instance_all_cmd,
-       "clear bgp view WORD *",
+       "clear bgp (view|vrf) WORD *",
        CLEAR_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n")
 
@@ -6125,8 +6130,8 @@ DEFUN (clear_ip_bgp_all_soft_out,
        BGP_SOFT_STR
        BGP_SOFT_OUT_STR)
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all,
                           BGP_CLEAR_SOFT_OUT, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all,
@@ -6144,12 +6149,12 @@ ALIAS (clear_ip_bgp_all_soft_out,
 
 ALIAS (clear_ip_bgp_all_soft_out,
        clear_ip_bgp_instance_all_soft_out_cmd,
-       "clear ip bgp view WORD * soft out",
+       "clear ip bgp (view|vrf) WORD * soft out",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "view name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Clear all peers\n"
        BGP_SOFT_STR
        BGP_SOFT_OUT_STR)
@@ -6189,11 +6194,11 @@ ALIAS (clear_ip_bgp_all_ipv4_soft_out,
 
 DEFUN (clear_ip_bgp_instance_all_ipv4_soft_out,
        clear_ip_bgp_instance_all_ipv4_soft_out_cmd,
-       "clear ip bgp view WORD * ipv4 (unicast|multicast) soft out",
+       "clear ip bgp (view|vrf) WORD * ipv4 (unicast|multicast) soft out",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        "Address family\n"
@@ -6201,8 +6206,8 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft_out,
        "Address Family modifier\n"
        BGP_SOFT_OUT_STR)
 {
-  if (strncmp (argv[1], "m", 1) == 0)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_MULTICAST, clear_all,
+  if (strncmp (argv[2], "m", 1) == 0)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all,
                           BGP_CLEAR_SOFT_OUT, NULL);
 
   return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
@@ -6245,8 +6250,8 @@ DEFUN (clear_bgp_all_soft_out,
        BGP_SOFT_STR
        BGP_SOFT_OUT_STR)
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP6, SAFI_UNICAST, clear_all,
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, clear_all,
                           BGP_CLEAR_SOFT_OUT, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, clear_all,
@@ -6255,10 +6260,10 @@ DEFUN (clear_bgp_all_soft_out,
 
 ALIAS (clear_bgp_all_soft_out,
        clear_bgp_instance_all_soft_out_cmd,
-       "clear bgp view WORD * soft out",
+       "clear bgp (view|vrf) WORD * soft out",
        CLEAR_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        BGP_SOFT_STR
@@ -6779,8 +6784,8 @@ DEFUN (clear_ip_bgp_all_soft_in,
        BGP_SOFT_STR
        BGP_SOFT_IN_STR)
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all,
                           BGP_CLEAR_SOFT_IN, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all,
@@ -6789,11 +6794,11 @@ DEFUN (clear_ip_bgp_all_soft_in,
 
 ALIAS (clear_ip_bgp_all_soft_in,
        clear_ip_bgp_instance_all_soft_in_cmd,
-       "clear ip bgp view WORD * soft in",
+       "clear ip bgp (view|vrf) WORD * soft in",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        BGP_SOFT_STR
@@ -6818,8 +6823,8 @@ DEFUN (clear_ip_bgp_all_in_prefix_filter,
        BGP_SOFT_IN_STR
        "Push out prefix-list ORF and do inbound soft reconfig\n")
 {
-  if (argc== 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
+  if (argc== 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all,
                           BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all,
@@ -6828,11 +6833,11 @@ DEFUN (clear_ip_bgp_all_in_prefix_filter,
 
 ALIAS (clear_ip_bgp_all_in_prefix_filter,
        clear_ip_bgp_instance_all_in_prefix_filter_cmd,
-       "clear ip bgp view WORD * in prefix-filter",
+       "clear ip bgp (view|vrf) WORD * in prefix-filter",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        BGP_SOFT_IN_STR
@@ -6874,11 +6879,11 @@ ALIAS (clear_ip_bgp_all_ipv4_soft_in,
 
 DEFUN (clear_ip_bgp_instance_all_ipv4_soft_in,
        clear_ip_bgp_instance_all_ipv4_soft_in_cmd,
-       "clear ip bgp view WORD * ipv4 (unicast|multicast) soft in",
+       "clear ip bgp (view|vrf) WORD * ipv4 (unicast|multicast) soft in",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        "Address family\n"
@@ -6887,11 +6892,11 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft_in,
        BGP_SOFT_STR
        BGP_SOFT_IN_STR)
 {
-  if (strncmp (argv[1], "m", 1) == 0)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_MULTICAST, clear_all,
+  if (strncmp (argv[2], "m", 1) == 0)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all,
                           BGP_CLEAR_SOFT_IN, NULL);
 
-  return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
+  return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all,
                         BGP_CLEAR_SOFT_IN, NULL);
 }
 
@@ -6918,7 +6923,7 @@ DEFUN (clear_ip_bgp_all_ipv4_in_prefix_filter,
 
 DEFUN (clear_ip_bgp_instance_all_ipv4_in_prefix_filter,
        clear_ip_bgp_instance_all_ipv4_in_prefix_filter_cmd,
-       "clear ip bgp view WORD * ipv4 (unicast|multicast) in prefix-filter",
+       "clear ip bgp (view|vrf) WORD * ipv4 (unicast|multicast) in prefix-filter",
        CLEAR_STR
        IP_STR
        BGP_STR
@@ -6929,8 +6934,8 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_in_prefix_filter,
        BGP_SOFT_IN_STR
        "Push out prefix-list ORF and do inbound soft reconfig\n")
 {
-  if (strncmp (argv[1], "m", 1) == 0)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_MULTICAST, clear_all,
+  if (strncmp (argv[2], "m", 1) == 0)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all,
                           BGP_CLEAR_SOFT_IN_ORF_PREFIX, NULL);
 
   return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
@@ -6973,8 +6978,8 @@ DEFUN (clear_bgp_all_soft_in,
        BGP_SOFT_STR
        BGP_SOFT_IN_STR)
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP6, SAFI_UNICAST, clear_all,
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, clear_all,
                         BGP_CLEAR_SOFT_IN, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, clear_all,
@@ -6983,10 +6988,10 @@ DEFUN (clear_bgp_all_soft_in,
 
 ALIAS (clear_bgp_all_soft_in,
        clear_bgp_instance_all_soft_in_cmd,
-       "clear bgp view WORD * soft in",
+       "clear bgp (view|vrf) WORD * soft in",
        CLEAR_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        BGP_SOFT_STR
@@ -7754,8 +7759,8 @@ DEFUN (clear_ip_bgp_all_soft,
        "Clear all peers\n"
        BGP_SOFT_STR)
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, clear_all,
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, clear_all,
                         BGP_CLEAR_SOFT_BOTH, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all,
@@ -7764,11 +7769,11 @@ DEFUN (clear_ip_bgp_all_soft,
 
 ALIAS (clear_ip_bgp_all_soft,
        clear_ip_bgp_instance_all_soft_cmd,
-       "clear ip bgp view WORD * soft",
+       "clear ip bgp (view|vrf) WORD * soft",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        BGP_SOFT_STR)
@@ -7796,11 +7801,11 @@ DEFUN (clear_ip_bgp_all_ipv4_soft,
 
 DEFUN (clear_ip_bgp_instance_all_ipv4_soft,
        clear_ip_bgp_instance_all_ipv4_soft_cmd,
-       "clear ip bgp view WORD * ipv4 (unicast|multicast) soft",
+       "clear ip bgp (view|vrf) WORD * ipv4 (unicast|multicast) soft",
        CLEAR_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        "Address family\n"
@@ -7808,8 +7813,8 @@ DEFUN (clear_ip_bgp_instance_all_ipv4_soft,
        "Address Family Modifier\n"
        BGP_SOFT_STR)
 {
-  if (strncmp (argv[1], "m", 1) == 0)
-    return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_MULTICAST, clear_all,
+  if (strncmp (argv[2], "m", 1) == 0)
+    return bgp_clear_vty (vty, argv[1], AFI_IP, SAFI_MULTICAST, clear_all,
                           BGP_CLEAR_SOFT_BOTH, NULL);
 
   return bgp_clear_vty (vty, NULL, AFI_IP, SAFI_UNICAST, clear_all,
@@ -7839,8 +7844,8 @@ DEFUN (clear_bgp_all_soft,
        "Clear all peers\n"
        BGP_SOFT_STR)
 {
-  if (argc == 1)
-    return bgp_clear_vty (vty, argv[0], AFI_IP6, SAFI_UNICAST, clear_all,
+  if (argc == 2)
+    return bgp_clear_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, clear_all,
                         BGP_CLEAR_SOFT_BOTH, argv[0]);
  
   return bgp_clear_vty (vty, NULL, AFI_IP6, SAFI_UNICAST, clear_all,
@@ -7849,10 +7854,10 @@ DEFUN (clear_bgp_all_soft,
 
 ALIAS (clear_bgp_all_soft,
        clear_bgp_instance_all_soft_cmd,
-       "clear bgp view WORD * soft",
+       "clear bgp (view|vrf) WORD * soft",
        CLEAR_STR
        BGP_STR
-       "BGP view\n"
+       "BGP view\nBGP VRF\n"
        "view name\n"
        "Clear all peers\n"
        BGP_SOFT_STR)
@@ -8348,12 +8353,21 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
                 {
                   json_object_string_add(json, "routerId", inet_ntoa (bgp->router_id));
                   json_object_int_add(json, "as", bgp->as);
+
+                  if (bgp->vrf_id)
+                    json_object_int_add(json, "vrf-id", bgp->vrf_id);
+
                 }
               else
                 {
                   vty_out (vty,
-                           "BGP router identifier %s, local AS number %u%s",
-                           inet_ntoa (bgp->router_id), bgp->as, VTY_NEWLINE);
+                           "BGP router identifier %s, local AS number %u",
+                           inet_ntoa (bgp->router_id), bgp->as);
+
+                  if (bgp->vrf_id)
+                    vty_out (vty, " vrf-id %u", bgp->vrf_id);
+
+                  vty_out (vty, "%s", VTY_NEWLINE);
                 }
 
               if (bgp_update_delay_configured(bgp))
@@ -8657,17 +8671,17 @@ DEFUN (show_ip_bgp_summary,
 
 DEFUN (show_ip_bgp_instance_summary,
        show_ip_bgp_instance_summary_cmd,
-       "show ip bgp view WORD summary {json}",
+       "show ip bgp (view|vrf) WORD summary {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Summary of BGP neighbor status\n"
        "JavaScript Object Notation\n")
 {
   u_char uj = use_json(argc, argv);
-  return bgp_show_summary_vty (vty, argv[0], AFI_IP, SAFI_UNICAST, uj);
+  return bgp_show_summary_vty (vty, argv[1], AFI_IP, SAFI_UNICAST, uj);
 }
 
 DEFUN (show_ip_bgp_ipv4_summary, 
@@ -8787,15 +8801,15 @@ DEFUN (show_bgp_summary,
 
 DEFUN (show_bgp_instance_summary,
        show_bgp_instance_summary_cmd,
-       "show bgp view WORD summary {json}",
+       "show bgp (view|vrf) WORD summary {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Summary of BGP neighbor status\n"
        "JavaScript Object Notation\n")
 {
-  return bgp_show_summary_vty (vty, argv[0], AFI_IP6, SAFI_UNICAST, use_json(argc, argv));
+  return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, use_json(argc, argv));
 }
 
 ALIAS (show_bgp_summary, 
@@ -8808,11 +8822,11 @@ ALIAS (show_bgp_summary,
 
 ALIAS (show_bgp_instance_summary,
        show_bgp_instance_ipv6_summary_cmd,
-       "show bgp view WORD ipv6 summary {json}",
+       "show bgp (view|vrf) WORD ipv6 summary {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Summary of BGP neighbor status\n")
 
@@ -8836,11 +8850,11 @@ DEFUN (show_bgp_ipv6_safi_summary,
 
 DEFUN (show_bgp_instance_ipv6_safi_summary,
        show_bgp_instance_ipv6_safi_summary_cmd,
-       "show bgp view WORD ipv6 (unicast|multicast) summary {json}",
+       "show bgp (view|vrf) WORD ipv6 (unicast|multicast) summary {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Address Family modifier\n"
        "Address Family modifier\n"
@@ -8848,10 +8862,10 @@ DEFUN (show_bgp_instance_ipv6_safi_summary,
        "JavaScript Object Notation\n")
 {
   u_char uj = use_json(argc, argv);
-  if (strncmp (argv[1], "m", 1) == 0)
-    return bgp_show_summary_vty (vty, argv[0], AFI_IP6, SAFI_MULTICAST, uj);
+  if (strncmp (argv[2], "m", 1) == 0)
+    return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_MULTICAST, uj);
 
-  return bgp_show_summary_vty (vty, argv[0], AFI_IP6, SAFI_UNICAST, uj);
+  return bgp_show_summary_vty (vty, argv[1], AFI_IP6, SAFI_UNICAST, uj);
 }
 
 /* old command */
@@ -10770,49 +10784,49 @@ ALIAS (show_ip_bgp_neighbors_peer,
 
 DEFUN (show_ip_bgp_instance_neighbors,
        show_ip_bgp_instance_neighbors_cmd,
-       "show ip bgp view WORD neighbors {json}",
+       "show ip bgp (view|vrf) WORD neighbors {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "JavaScript Object Notation\n")
 {
   u_char uj = use_json(argc, argv);
 
-  return bgp_show_neighbor_vty (vty, argv[0], show_all, NULL, uj);
+  return bgp_show_neighbor_vty (vty, argv[1], show_all, NULL, uj);
 }
 
 ALIAS (show_ip_bgp_instance_neighbors,
        show_bgp_instance_neighbors_cmd,
-       "show bgp view WORD neighbors {json}",
+       "show bgp (view|vrf) WORD neighbors {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "JavaScript Object Notation\n")
 
 ALIAS (show_ip_bgp_instance_neighbors,
        show_bgp_instance_ipv6_neighbors_cmd,
-       "show bgp view WORD ipv6 neighbors {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "JavaScript Object Notation\n")
 
 DEFUN (show_ip_bgp_instance_neighbors_peer,
        show_ip_bgp_instance_neighbors_peer_cmd,
-       "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) {json}",
+       "show ip bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) {json}",
        SHOW_STR
        IP_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -10821,16 +10835,16 @@ DEFUN (show_ip_bgp_instance_neighbors_peer,
 {
   u_char uj = use_json(argc, argv);
 
-  return bgp_show_neighbor_vty (vty, argv[0], show_peer, argv[1], uj);
+  return bgp_show_neighbor_vty (vty, argv[1], show_peer, argv[2], uj);
 }
 
 ALIAS (show_ip_bgp_instance_neighbors_peer,
        show_bgp_instance_neighbors_peer_cmd,
-       "show bgp view WORD neighbors (A.B.C.D|X:X::X:X|WORD) {json}",
+       "show bgp (view|vrf) WORD neighbors (A.B.C.D|X:X::X:X|WORD) {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
        "Neighbor to display information about\n"
@@ -10839,11 +10853,11 @@ ALIAS (show_ip_bgp_instance_neighbors_peer,
 
 ALIAS (show_ip_bgp_instance_neighbors_peer,
        show_bgp_instance_ipv6_neighbors_peer_cmd,
-       "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) {json}",
+       "show bgp (view|vrf) WORD ipv6 neighbors (A.B.C.D|X:X::X:X|WORD) {json}",
        SHOW_STR
        BGP_STR
-       "BGP view\n"
-       "View name\n"
+       "BGP view\nBGP VRF\n"
+       "View/VRF name\n"
        "Address family\n"
        "Detailed information on TCP and BGP neighbor connections\n"
        "Neighbor to display information about\n"
@@ -11362,7 +11376,7 @@ DEFUN (show_ip_bgp_peer_groups,
 
 DEFUN (show_ip_bgp_instance_peer_groups,
        show_ip_bgp_instance_peer_groups_cmd,
-       "show ip bgp view WORD peer-group",
+       "show ip bgp (view|vrf) WORD peer-group",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -11386,7 +11400,7 @@ DEFUN (show_ip_bgp_peer_group,
 
 DEFUN (show_ip_bgp_instance_peer_group,
        show_ip_bgp_instance_peer_group_cmd,
-       "show ip bgp view WORD peer-group WORD",
+       "show ip bgp (view|vrf) WORD peer-group WORD",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -11414,7 +11428,7 @@ DEFUN (bgp_redistribute_ipv4,
       return CMD_WARNING;
     }
   bgp_redist_add(vty->index, AFI_IP, type, 0);
-  return bgp_redistribute_set (AFI_IP, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv4_rmap,
@@ -11437,7 +11451,7 @@ DEFUN (bgp_redistribute_ipv4_rmap,
 
   red = bgp_redist_add(vty->index, AFI_IP, type, 0);
   bgp_redistribute_rmap_set (red, argv[1]);
-  return bgp_redistribute_set (AFI_IP, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv4_metric,
@@ -11462,7 +11476,7 @@ DEFUN (bgp_redistribute_ipv4_metric,
 
   red = bgp_redist_add(vty->index, AFI_IP, type, 0);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric);
-  return bgp_redistribute_set (AFI_IP, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv4_rmap_metric,
@@ -11490,7 +11504,7 @@ DEFUN (bgp_redistribute_ipv4_rmap_metric,
   red = bgp_redist_add(vty->index, AFI_IP, type, 0);
   bgp_redistribute_rmap_set (red, argv[1]);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric);
-  return bgp_redistribute_set (AFI_IP, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv4_metric_rmap,
@@ -11518,7 +11532,7 @@ DEFUN (bgp_redistribute_ipv4_metric_rmap,
   red = bgp_redist_add(vty->index, AFI_IP, type, 0);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP, type, metric);
   bgp_redistribute_rmap_set (red, argv[2]);
-  return bgp_redistribute_set (AFI_IP, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv4_ospf,
@@ -11540,7 +11554,7 @@ DEFUN (bgp_redistribute_ipv4_ospf,
     protocol = ZEBRA_ROUTE_TABLE;
 
   bgp_redist_add(vty->index, AFI_IP, protocol, instance);
-  return bgp_redistribute_set (AFI_IP, protocol, instance);
+  return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
 }
 
 DEFUN (bgp_redistribute_ipv4_ospf_rmap,
@@ -11565,7 +11579,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap,
   VTY_GET_INTEGER ("Instance ID", instance, argv[1]);
   red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
   bgp_redistribute_rmap_set (red, argv[2]);
-  return bgp_redistribute_set (AFI_IP, protocol, instance);
+  return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
 }
 
 DEFUN (bgp_redistribute_ipv4_ospf_metric,
@@ -11593,7 +11607,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric,
 
   red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric);
-  return bgp_redistribute_set (AFI_IP, protocol, instance);
+  return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
 }
 
 DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
@@ -11624,7 +11638,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric,
   red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
   bgp_redistribute_rmap_set (red, argv[2]);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric);
-  return bgp_redistribute_set (AFI_IP, protocol, instance);
+  return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
 }
 
 DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
@@ -11655,7 +11669,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap,
   red = bgp_redist_add(vty->index, AFI_IP, protocol, instance);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP, protocol, metric);
   bgp_redistribute_rmap_set (red, argv[3]);
-  return bgp_redistribute_set (AFI_IP, protocol, instance);
+  return bgp_redistribute_set (vty->index, AFI_IP, protocol, instance);
 }
 
 DEFUN (no_bgp_redistribute_ipv4_ospf,
@@ -11802,7 +11816,7 @@ DEFUN (bgp_redistribute_ipv6,
     }
 
   bgp_redist_add(vty->index, AFI_IP6, type, 0);
-  return bgp_redistribute_set (AFI_IP6, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv6_rmap,
@@ -11825,7 +11839,7 @@ DEFUN (bgp_redistribute_ipv6_rmap,
 
   red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
   bgp_redistribute_rmap_set (red, argv[1]);
-  return bgp_redistribute_set (AFI_IP6, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv6_metric,
@@ -11850,7 +11864,7 @@ DEFUN (bgp_redistribute_ipv6_metric,
 
   red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP6, type, metric);
-  return bgp_redistribute_set (AFI_IP6, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv6_rmap_metric,
@@ -11878,7 +11892,7 @@ DEFUN (bgp_redistribute_ipv6_rmap_metric,
   red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
   bgp_redistribute_rmap_set (red, argv[1]);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP6, type, metric);
-  return bgp_redistribute_set (AFI_IP6, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
 }
 
 DEFUN (bgp_redistribute_ipv6_metric_rmap,
@@ -11906,7 +11920,7 @@ DEFUN (bgp_redistribute_ipv6_metric_rmap,
   red = bgp_redist_add(vty->index, AFI_IP6, type, 0);
   bgp_redistribute_metric_set(vty->index, red, AFI_IP6, SAFI_UNICAST, metric);
   bgp_redistribute_rmap_set (red, argv[2]);
-  return bgp_redistribute_set (AFI_IP6, type, 0);
+  return bgp_redistribute_set (vty->index, AFI_IP6, type, 0);
 }
 
 DEFUN (no_bgp_redistribute_ipv6,
@@ -12090,12 +12104,12 @@ bgp_vty_init (void)
 
   /* "router bgp" commands. */
   install_element (CONFIG_NODE, &router_bgp_cmd);
-  install_element (CONFIG_NODE, &router_bgp_view_cmd);
+  install_element (CONFIG_NODE, &router_bgp_instance_cmd);
   install_element (CONFIG_NODE, &router_bgp_noasn_cmd);
 
   /* "no router bgp" commands. */
   install_element (CONFIG_NODE, &no_router_bgp_cmd);
-  install_element (CONFIG_NODE, &no_router_bgp_view_cmd);
+  install_element (CONFIG_NODE, &no_router_bgp_instance_cmd);
 
   /* "bgp router-id" commands. */
   install_element (BGP_NODE, &bgp_router_id_cmd);
index 707476e818fc8f657f5d9729d9d88aba0b5149a9..4b80bbeafcdbdb1a4515b68772b36e9ac7caf2cb 100644 (file)
@@ -47,7 +47,6 @@ Boston, MA 02111-1307, USA.  */
 
 /* All information about zebra. */
 struct zclient *zclient = NULL;
-struct in_addr router_id_zebra;
 
 /* Growable buffer for nexthops sent to zebra */
 struct stream *bgp_nexthop_buf = NULL;
@@ -105,15 +104,33 @@ bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length,
     {
       char buf[PREFIX2STR_BUFFER];
       prefix2str(&router_id, buf, sizeof(buf));
-      zlog_debug("Zebra rcvd: router id update %s", buf);
+      zlog_debug("Zebra rcvd: router id update %s vrf %u", buf, vrf_id);
     }
 
-  router_id_zebra = router_id.u.prefix4;
+  if (!vrf_id)
+    {
+      /* This is to cover all the views */
+      for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
+        {
+          if (bgp_flag_check(bgp, BGP_FLAG_INSTANCE_TYPE_VRF))
+            continue;
 
-  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
+          bgp->router_id_zebra = router_id.u.prefix4;
+
+          if (!bgp->router_id_static.s_addr)
+            bgp_router_id_set (bgp, &router_id.u.prefix4);
+        }
+    }
+  else
     {
-      if (!bgp->router_id_static.s_addr)
-        bgp_router_id_set (bgp, &router_id.u.prefix4);
+      bgp = bgp_lookup_by_vrf_id (vrf_id);
+      if (bgp)
+        {
+          bgp->router_id_zebra = router_id.u.prefix4;
+
+          if (!bgp->router_id_static.s_addr)
+            bgp_router_id_set (bgp, &router_id.u.prefix4);
+        }
     }
 
   return 0;
@@ -137,30 +154,26 @@ bgp_read_import_check_update(int command, struct zclient *zclient,
 }
 
 static void
-bgp_start_interface_nbrs (struct interface *ifp)
+bgp_start_interface_nbrs (struct bgp *bgp, struct interface *ifp)
 {
-  struct listnode *node, *nnode, *mnode;
-  struct bgp *bgp;
+  struct listnode *node, *nnode;
   struct peer *peer;
 
-  for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp))
+  for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
     {
-      for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
+      if (peer->conf_if &&
+          (strcmp (peer->conf_if, ifp->name) == 0) &&
+          peer->status != Established)
         {
-          if (peer->conf_if &&
-              (strcmp (peer->conf_if, ifp->name) == 0) &&
-              peer->status != Established)
-            {
-              if (peer_active(peer))
-                BGP_EVENT_ADD (peer, BGP_Stop);
-              BGP_EVENT_ADD (peer, BGP_Start);
-            }
+          if (peer_active(peer))
+            BGP_EVENT_ADD (peer, BGP_Stop);
+          BGP_EVENT_ADD (peer, BGP_Start);
         }
     }
 }
 
 static void
-bgp_nbr_connected_add (struct nbr_connected *ifc)
+bgp_nbr_connected_add (struct bgp *bgp, struct nbr_connected *ifc)
 {
   struct listnode *node;
   struct connected *connected;
@@ -181,25 +194,21 @@ bgp_nbr_connected_add (struct nbr_connected *ifc)
   if (!connected)
     return;
 
-  bgp_start_interface_nbrs (ifp);
+  bgp_start_interface_nbrs (bgp, ifp);
 }
 
 static void
-bgp_nbr_connected_delete (struct nbr_connected *ifc, int del)
+bgp_nbr_connected_delete (struct bgp *bgp, struct nbr_connected *ifc, int del)
 {
-  struct listnode *node, *nnode, *mnode;
-  struct bgp *bgp;
+  struct listnode *node, *nnode;
   struct peer *peer;
   struct interface *ifp;
 
-  for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp))
+  for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
     {
-      for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
+      if (peer->conf_if && (strcmp (peer->conf_if, ifc->ifp->name) == 0))
         {
-          if (peer->conf_if && (strcmp (peer->conf_if, ifc->ifp->name) == 0))
-            {
-              BGP_EVENT_ADD (peer, BGP_Stop);
-            }
+          BGP_EVENT_ADD (peer, BGP_Stop);
         }
     }
   /* Free neighbor also, if we're asked to. */
@@ -211,6 +220,79 @@ bgp_nbr_connected_delete (struct nbr_connected *ifc, int del)
     }
 }
 
+/* Inteface addition message from zebra. */
+static int
+bgp_vrf_add (int command, struct zclient *zclient, zebra_size_t length,
+    vrf_id_t vrf_id)
+{
+  struct vrf *vrf;
+  struct bgp *bgp;
+
+  vrf = zebra_vrf_add_read (zclient->ibuf, vrf_id);
+
+  if (BGP_DEBUG (zebra, ZEBRA) && vrf)
+    zlog_debug("Zebra rcvd: vrf add %s", vrf->name);
+
+  bgp = bgp_lookup_by_name(vrf->name);
+  if (bgp)
+    {
+      bgp->vrf_id = vrf_id;
+
+      if (BGP_DEBUG (zebra, ZEBRA) && vrf)
+        zlog_debug("zclient_send_requests %u", vrf_id);
+
+      zclient_send_requests (zclient, vrf_id);
+
+      bgp_instance_up (bgp);
+      //Pending: See if the following can be moved inside bgp_instance_up ()
+      bgp_nht_register_all(vrf_id);
+      
+    }
+
+  return 0;
+}
+
+void
+bgp_vrf_update (struct bgp *bgp)
+{
+  struct vrf *vrf;
+
+  if (bgp->name)
+    {
+      vrf = vrf_lookup_by_name(bgp->name);
+      if (vrf)
+        bgp->vrf_id = vrf->vrf_id;
+    }
+
+  zclient_send_requests (zclient, bgp->vrf_id);
+  bgp_nht_register_all (bgp->vrf_id);
+}
+
+/* Inteface deletion message from zebra. */
+static int
+bgp_vrf_delete (int command, struct zclient *zclient, zebra_size_t length,
+    vrf_id_t vrf_id)
+{
+  struct vrf *vrf;
+  struct bgp *bgp;
+
+  vrf = zebra_vrf_state_read (zclient->ibuf, vrf_id);
+
+  if (BGP_DEBUG (zebra, ZEBRA) && vrf)
+    zlog_debug("Zebra rcvd: vrf delete %s", vrf->name);
+
+  bgp = bgp_lookup_by_name(vrf->name);
+  if (bgp)
+    {
+      bgp_instance_down (bgp);
+      bgp->vrf_id = 0;
+    }
+
+  return 0;
+}
+
+
+
 /* Inteface addition message from zebra. */
 static int
 bgp_interface_add (int command, struct zclient *zclient, zebra_size_t length,
@@ -252,6 +334,11 @@ bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length,
   struct connected *c;
   struct nbr_connected *nc;
   struct listnode *node, *nnode;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   s = zclient->ibuf;
   ifp = zebra_interface_state_read (s, vrf_id);
@@ -263,10 +350,10 @@ bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length,
     zlog_debug("Zebra rcvd: interface %s up", ifp->name);
 
   for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, c))
-    bgp_connected_add (c);
+    bgp_connected_add (bgp, c);
 
   for (ALL_LIST_ELEMENTS (ifp->nbr_connected, node, nnode, nc))
-    bgp_nbr_connected_add (nc);
+    bgp_nbr_connected_add (bgp, nc);
 
   return 0;
 }
@@ -280,6 +367,11 @@ bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length,
   struct connected *c;
   struct nbr_connected *nc;
   struct listnode *node, *nnode;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   s = zclient->ibuf;
   ifp = zebra_interface_state_read (s, vrf_id);
@@ -290,10 +382,10 @@ bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length,
     zlog_debug("Zebra rcvd: interface %s down", ifp->name);
 
   for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, c))
-    bgp_connected_delete (c);
+    bgp_connected_delete (bgp, c);
 
   for (ALL_LIST_ELEMENTS (ifp->nbr_connected, node, nnode, nc))
-    bgp_nbr_connected_delete (nc, 1);
+    bgp_nbr_connected_delete (bgp, nc, 1);
 
   /* Fast external-failover */
   {
@@ -341,14 +433,23 @@ bgp_interface_address_add (int command, struct zclient *zclient,
 
   if (if_is_operative (ifc->ifp))
     {
-      bgp_connected_add (ifc);
+      struct bgp *bgp;
+
+      bgp = bgp_lookup_by_vrf_id (vrf_id);
+      if (!bgp)
+        {
+          zlog_err("instance not found\n");
+          return 0;
+        }
+
+      bgp_connected_add (bgp, ifc);
       /* If we have learnt of any neighbors on this interface,
        * check to kick off any BGP interface-based neighbors,
        * but only if this is a link-local address.
        */
       if (IN6_IS_ADDR_LINKLOCAL(&ifc->address->u.prefix6) &&
           !list_isempty(ifc->ifp->nbr_connected))
-        bgp_start_interface_nbrs (ifc->ifp);
+        bgp_start_interface_nbrs (bgp, ifc->ifp);
     }
 
   return 0;
@@ -359,6 +460,11 @@ bgp_interface_address_delete (int command, struct zclient *zclient,
                              zebra_size_t length, vrf_id_t vrf_id)
 {
   struct connected *ifc;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   ifc = zebra_interface_address_read (command, zclient->ibuf, vrf_id);
 
@@ -374,7 +480,7 @@ bgp_interface_address_delete (int command, struct zclient *zclient,
     }
 
   if (if_is_operative (ifc->ifp))
-    bgp_connected_delete (ifc);
+    bgp_connected_delete (bgp, ifc);
 
   connected_free (ifc);
 
@@ -386,6 +492,11 @@ bgp_interface_nbr_address_add (int command, struct zclient *zclient,
                           zebra_size_t length, vrf_id_t vrf_id)
 {
   struct nbr_connected *ifc = NULL;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   ifc = zebra_interface_nbr_address_read (command, zclient->ibuf, vrf_id);
 
@@ -401,7 +512,7 @@ bgp_interface_nbr_address_add (int command, struct zclient *zclient,
     }
 
   if (if_is_operative (ifc->ifp))
-    bgp_nbr_connected_add (ifc);
+    bgp_nbr_connected_add (bgp, ifc);
 
   return 0;
 }
@@ -411,6 +522,11 @@ bgp_interface_nbr_address_delete (int command, struct zclient *zclient,
                              zebra_size_t length, vrf_id_t vrf_id)
 {
   struct nbr_connected *ifc = NULL;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   ifc = zebra_interface_nbr_address_read (command, zclient->ibuf, vrf_id);
 
@@ -426,7 +542,7 @@ bgp_interface_nbr_address_delete (int command, struct zclient *zclient,
     }
 
   if (if_is_operative (ifc->ifp))
-    bgp_nbr_connected_delete (ifc, 0);
+    bgp_nbr_connected_delete (bgp, ifc, 0);
 
   nbr_connected_free (ifc);
 
@@ -444,6 +560,11 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
   struct prefix_ipv4 p;
   unsigned int ifindex;
   int i;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   s = zclient->ibuf;
   nexthop.s_addr = 0;
@@ -513,11 +634,11 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
       for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
         {
           if (i != api.type)
-            bgp_redistribute_delete((struct prefix *)&p, i, api.instance);
+            bgp_redistribute_delete(bgp, (struct prefix *)&p, i, api.instance);
         }
 
       /* Now perform the add/update. */
-      bgp_redistribute_add((struct prefix *)&p, &nexthop, NULL, ifindex,
+      bgp_redistribute_add(bgp, (struct prefix *)&p, &nexthop, NULL, ifindex,
                           api.metric, api.type, api.instance, api.tag);
     }
   else if (command == ZEBRA_REDISTRIBUTE_IPV4_DEL)
@@ -534,7 +655,7 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
                     api.metric,
                     api.tag);
        }
-      bgp_redistribute_delete((struct prefix *)&p, api.type, api.instance);
+      bgp_redistribute_delete(bgp, (struct prefix *)&p, api.type, api.instance);
     }
 
   return 0;
@@ -552,6 +673,11 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length,
   struct prefix_ipv6 p;
   unsigned int ifindex;
   int i;
+  struct bgp *bgp;
+
+  bgp = bgp_lookup_by_vrf_id (vrf_id);
+  if (!bgp)
+    return 0;
 
   s = zclient->ibuf;
   memset (&nexthop, 0, sizeof (struct in6_addr));
@@ -627,10 +753,10 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length,
       for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
         {
           if (i != api.type)
-            bgp_redistribute_delete((struct prefix *)&p, i, api.instance);
+            bgp_redistribute_delete(bgp, (struct prefix *)&p, i, api.instance);
         }
 
-      bgp_redistribute_add ((struct prefix *)&p, NULL, &nexthop, ifindex,
+      bgp_redistribute_add (bgp, (struct prefix *)&p, NULL, &nexthop, ifindex,
                            api.metric, api.type, api.instance, api.tag);
     }
   else if (command == ZEBRA_REDISTRIBUTE_IPV6_DEL)
@@ -647,7 +773,7 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length,
                     api.metric,
                      api.tag);
        }
-      bgp_redistribute_delete ((struct prefix *) &p, api.type, api.instance);
+      bgp_redistribute_delete (bgp, (struct prefix *) &p, api.type, api.instance);
     }
   
   return 0;
@@ -655,7 +781,7 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length,
 #endif /* HAVE_IPV6 */
 
 struct interface *
-if_lookup_by_ipv4 (struct in_addr *addr)
+if_lookup_by_ipv4 (struct in_addr *addr, vrf_id_t vrf_id)
 {
   struct listnode *ifnode;
   struct listnode *cnode;
@@ -668,7 +794,7 @@ if_lookup_by_ipv4 (struct in_addr *addr)
   p.prefix = *addr;
   p.prefixlen = IPV4_MAX_BITLEN;
 
-  for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp))
+  for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id), ifnode, ifp))
     {
       for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
        {
@@ -683,7 +809,7 @@ if_lookup_by_ipv4 (struct in_addr *addr)
 }
 
 struct interface *
-if_lookup_by_ipv4_exact (struct in_addr *addr)
+if_lookup_by_ipv4_exact (struct in_addr *addr, vrf_id_t vrf_id)
 {
   struct listnode *ifnode;
   struct listnode *cnode;
@@ -691,7 +817,7 @@ if_lookup_by_ipv4_exact (struct in_addr *addr)
   struct connected *connected;
   struct prefix *cp; 
   
-  for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp))
+  for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id), ifnode, ifp))
     {
       for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
        {
@@ -707,7 +833,7 @@ if_lookup_by_ipv4_exact (struct in_addr *addr)
 
 #ifdef HAVE_IPV6
 struct interface *
-if_lookup_by_ipv6 (struct in6_addr *addr, unsigned int ifindex)
+if_lookup_by_ipv6 (struct in6_addr *addr, unsigned int ifindex, vrf_id_t vrf_id)
 {
   struct listnode *ifnode;
   struct listnode *cnode;
@@ -720,7 +846,7 @@ if_lookup_by_ipv6 (struct in6_addr *addr, unsigned int ifindex)
   p.prefix = *addr;
   p.prefixlen = IPV6_MAX_BITLEN;
 
-  for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp))
+  for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id), ifnode, ifp))
     {
       for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
        {
@@ -743,7 +869,7 @@ if_lookup_by_ipv6 (struct in6_addr *addr, unsigned int ifindex)
 }
 
 struct interface *
-if_lookup_by_ipv6_exact (struct in6_addr *addr, unsigned int ifindex)
+if_lookup_by_ipv6_exact (struct in6_addr *addr, unsigned int ifindex, vrf_id_t vrf_id)
 {
   struct listnode *ifnode;
   struct listnode *cnode;
@@ -751,7 +877,7 @@ if_lookup_by_ipv6_exact (struct in6_addr *addr, unsigned int ifindex)
   struct connected *connected;
   struct prefix *cp; 
 
-  for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp))
+  for (ALL_LIST_ELEMENTS_RO (vrf_iflist(vrf_id), ifnode, ifp))
     {
       for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
        {
@@ -853,9 +979,9 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
     {
       nexthop->v4 = local->sin.sin_addr;
       if (peer->update_if)
-        ifp = if_lookup_by_name (peer->update_if);
+        ifp = if_lookup_by_name_vrf (peer->update_if, peer->bgp->vrf_id);
       else
-        ifp = if_lookup_by_ipv4_exact (&local->sin.sin_addr);
+        ifp = if_lookup_by_ipv4_exact (&local->sin.sin_addr, peer->bgp->vrf_id);
     }
 #ifdef HAVE_IPV6
   if (local->sa.sa_family == AF_INET6)
@@ -863,13 +989,14 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
       if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr))
        {
          if (peer->conf_if || peer->ifname)
-           ifp = if_lookup_by_index (if_nametoindex (peer->conf_if ? peer->conf_if : peer->ifname));
+           ifp = if_lookup_by_index_vrf (if_nametoindex (peer->conf_if ? peer->conf_if : peer->ifname), peer->bgp->vrf_id);
        }
       else if (peer->update_if)
-        ifp = if_lookup_by_name (peer->update_if);
+        ifp = if_lookup_by_name_vrf (peer->update_if, peer->bgp->vrf_id);
       else
         ifp = if_lookup_by_ipv6_exact (&local->sin6.sin6_addr,
-                                      local->sin6.sin6_scope_id);
+                                      local->sin6.sin6_scope_id,
+                                       peer->bgp->vrf_id);
     }
 #endif /* HAVE_IPV6 */
 
@@ -899,7 +1026,7 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
       else
        if_get_ipv6_local (ifp, &nexthop->v6_local);
 
-      if (if_lookup_by_ipv4 (&remote->sin.sin_addr))
+      if (if_lookup_by_ipv4 (&remote->sin.sin_addr, peer->bgp->vrf_id))
         peer->shared_network = 1;
       else
         peer->shared_network = 0;
@@ -925,7 +1052,7 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
 
          /* If directory connected set link-local address. */
          direct = if_lookup_by_ipv6 (&remote->sin6.sin6_addr,
-                                     remote->sin6.sin6_scope_id);
+                                     remote->sin6.sin6_scope_id, peer->bgp->vrf_id);
          if (direct)
            if_get_ipv6_local (ifp, &nexthop->v6_local);
        }
@@ -949,7 +1076,8 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
        }
 
       if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr) ||
-          if_lookup_by_ipv6 (&remote->sin6.sin6_addr, remote->sin6.sin6_scope_id))
+          if_lookup_by_ipv6 (&remote->sin6.sin6_addr, remote->sin6.sin6_scope_id,
+                             peer->bgp->vrf_id))
         peer->shared_network = 1;
       else
         peer->shared_network = 0;
@@ -1046,9 +1174,9 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp,
     return;
 
   if ((p->family == AF_INET &&
-       !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP], VRF_DEFAULT))
+       !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP], bgp->vrf_id))
       || (p->family == AF_INET6 &&
-       !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP], VRF_DEFAULT)))
+       !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP], bgp->vrf_id)))
     return;
 
   if (bgp->main_zebra_update_hold)
@@ -1161,7 +1289,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp,
           valid_nh_count++;
         }
 
-      api.vrf_id = VRF_DEFAULT;
+      api.vrf_id = bgp->vrf_id;
       api.flags = flags;
       api.type = ZEBRA_ROUTE_BGP;
       api.instance = 0;
@@ -1344,7 +1472,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp,
         }
 
       /* Make Zebra API structure. */
-      api.vrf_id = VRF_DEFAULT;
+      api.vrf_id = bgp->vrf_id;
       api.flags = flags;
       api.type = ZEBRA_ROUTE_BGP;
       api.instance = 0;
@@ -1447,14 +1575,14 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi)
   if (zclient->sock < 0)
     return;
 
+  peer = info->peer;
+
   if ((p->family == AF_INET &&
-       !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP], VRF_DEFAULT))
+       !vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_BGP], peer->bgp->vrf_id))
       || (p->family == AF_INET6 &&
-       !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP], VRF_DEFAULT)))
+       !vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_BGP], peer->bgp->vrf_id)))
     return;
 
-  peer = info->peer;
-
   flags = 0;
 
   if (peer->sort == BGP_PEER_IBGP)
@@ -1472,7 +1600,7 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi)
     {
       struct zapi_ipv4 api;
 
-      api.vrf_id = VRF_DEFAULT;
+      api.vrf_id = peer->bgp->vrf_id;
       api.flags = flags;
 
       api.type = ZEBRA_ROUTE_BGP;
@@ -1511,7 +1639,7 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi)
       
       assert (info->attr->extra);
       
-      api.vrf_id = VRF_DEFAULT;
+      api.vrf_id = peer->bgp->vrf_id;
       api.flags = flags;
       api.type = ZEBRA_ROUTE_BGP;
       api.instance = 0;
@@ -1603,7 +1731,7 @@ bgp_redist_del (struct bgp *bgp, afi_t afi, u_char type, u_short instance)
 
 /* Other routes redistribution into BGP. */
 int
-bgp_redistribute_set (afi_t afi, int type, u_short instance)
+bgp_redistribute_set (struct bgp *bgp, afi_t afi, int type, u_short instance)
 {
 
   /* Return if already redistribute flag is set. */
@@ -1616,10 +1744,10 @@ bgp_redistribute_set (afi_t afi, int type, u_short instance)
     }
   else
     {
-      if (vrf_bitmap_check (zclient->redist[afi][type], VRF_DEFAULT))
+      if (vrf_bitmap_check (zclient->redist[afi][type], bgp->vrf_id))
         return CMD_WARNING;
 
-      vrf_bitmap_set (zclient->redist[afi][type], VRF_DEFAULT);
+      vrf_bitmap_set (zclient->redist[afi][type], bgp->vrf_id);
     }
 
   /* Return if zebra connection is not established. */
@@ -1632,7 +1760,7 @@ bgp_redistribute_set (afi_t afi, int type, u_short instance)
 
   /* Send distribute add message to zebra. */
   zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type,
-                           instance, VRF_DEFAULT);
+                           instance, bgp->vrf_id);
 
   return CMD_SUCCESS;
 }
@@ -1704,7 +1832,7 @@ bgp_redistribute_metric_set (struct bgp *bgp, struct bgp_redist *red, afi_t afi,
 
 /* Unset redistribution.  */
 int
-bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance)
+bgp_redistribute_unreg (struct bgp *bgp, afi_t afi, int type, u_short instance)
 {
   struct bgp_redist *red;
 
@@ -1712,18 +1840,6 @@ bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance)
   if (!red)
     return CMD_SUCCESS;
 
-  /* Unset route-map. */
-  if (red->rmap.name)
-    XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name);
-  red->rmap.name = NULL;
-  red->rmap.map = NULL;
-
-  /* Unset metric. */
-  red->redist_metric_flag = 0;
-  red->redist_metric = 0;
-
-  bgp_redist_del(bgp, afi, type, instance);
-
   /* Return if zebra connection is disabled. */
   if (instance)
     {
@@ -1733,9 +1849,9 @@ bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance)
     }
   else
     {
-      if (! vrf_bitmap_check (zclient->redist[afi][type], VRF_DEFAULT))
+      if (! vrf_bitmap_check (zclient->redist[afi][type], bgp->vrf_id))
         return CMD_WARNING;
-      vrf_bitmap_unset (zclient->redist[afi][type], VRF_DEFAULT);
+      vrf_bitmap_unset (zclient->redist[afi][type], bgp->vrf_id);
     }
 
   if (zclient->sock >= 0)
@@ -1745,7 +1861,7 @@ bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance)
        zlog_debug("Zebra send: redistribute delete afi %d %s %d",
                   afi, zebra_route_string(type), instance);
       zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, instance,
-                               VRF_DEFAULT);
+                               bgp->vrf_id);
     }
   
   /* Withdraw redistributed routes from current BGP's routing table. */
@@ -1754,6 +1870,33 @@ bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance)
   return CMD_SUCCESS;
 }
 
+/* Unset redistribution.  */
+int
+bgp_redistribute_unset (struct bgp *bgp, afi_t afi, int type, u_short instance)
+{
+  struct bgp_redist *red;
+
+  red = bgp_redist_lookup(bgp, afi, type, instance);
+  if (!red)
+    return CMD_SUCCESS;
+
+  bgp_redistribute_unreg(bgp, afi, type, instance);
+
+  /* Unset route-map. */
+  if (red->rmap.name)
+    XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name);
+  red->rmap.name = NULL;
+  red->rmap.map = NULL;
+
+  /* Unset metric. */
+  red->redist_metric_flag = 0;
+  red->redist_metric = 0;
+
+  bgp_redist_del(bgp, afi, type, instance);
+
+  return CMD_SUCCESS;
+}
+
 void
 bgp_zclient_reset (void)
 {
@@ -1763,11 +1906,14 @@ bgp_zclient_reset (void)
 static void
 bgp_zebra_connected (struct zclient *zclient)
 {
-  zclient_send_requests (zclient, VRF_DEFAULT);
+  struct listnode *node, *nnode;
+  struct bgp *bgp;
 
-  bgp_nht_register_all();
+  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
+    bgp_vrf_update (bgp);
 }
 
+
 void
 bgp_zebra_init (struct thread_master *master)
 {
@@ -1776,6 +1922,8 @@ bgp_zebra_init (struct thread_master *master)
   zclient_init (zclient, ZEBRA_ROUTE_BGP, 0);
   zclient->zebra_connected = bgp_zebra_connected;
   zclient->router_id_update = bgp_router_id_update;
+  zclient->vrf_add = bgp_vrf_add;
+  zclient->vrf_delete = bgp_vrf_delete;
   zclient->interface_add = bgp_interface_add;
   zclient->interface_delete = bgp_interface_delete;
   zclient->interface_address_add = bgp_interface_address_add;
index 81bd0fb42144dab3d9a0088372c94fec371530fa..e21141238ca84ac5ea9a4408be713c145609f742 100644 (file)
@@ -29,6 +29,7 @@ extern struct stream *bgp_ifindices_buf;
 
 extern void bgp_zebra_init(struct thread_master *master);
 extern int bgp_if_update_all (void);
+extern void bgp_vrf_update (struct bgp *);
 extern int bgp_config_write_maxpaths (struct vty *, struct bgp *, afi_t,
                                      safi_t, int *);
 extern int bgp_config_write_redistribute (struct vty *, struct bgp *, afi_t, safi_t,
@@ -40,18 +41,19 @@ extern void bgp_zebra_withdraw (struct prefix *, struct bgp_info *, safi_t);
 
 extern struct bgp_redist *bgp_redist_lookup (struct bgp *, afi_t, u_char, u_short);
 extern struct bgp_redist *bgp_redist_add (struct bgp *, afi_t, u_char, u_short);
-extern int bgp_redistribute_set (afi_t, int, u_short);
+extern int bgp_redistribute_set (struct bgp *, afi_t, int, u_short);
 extern int bgp_redistribute_resend (struct bgp *, afi_t, int, u_short);
 extern int bgp_redistribute_rmap_set (struct bgp_redist *, const char *);
 extern int bgp_redistribute_metric_set(struct bgp *, struct bgp_redist *,
                                       afi_t, int, u_int32_t);
 extern int bgp_redistribute_unset (struct bgp *, afi_t, int, u_short);
+extern int bgp_redistribute_unreg (struct bgp *, afi_t, int, u_short);
 
-extern struct interface *if_lookup_by_ipv4 (struct in_addr *);
-extern struct interface *if_lookup_by_ipv4_exact (struct in_addr *);
+extern struct interface *if_lookup_by_ipv4 (struct in_addr *, vrf_id_t);
+extern struct interface *if_lookup_by_ipv4_exact (struct in_addr *, vrf_id_t);
 #ifdef HAVE_IPV6
-extern struct interface *if_lookup_by_ipv6 (struct in6_addr *, unsigned int ifindex);
-extern struct interface *if_lookup_by_ipv6_exact (struct in6_addr *, unsigned int ifindex);
+extern struct interface *if_lookup_by_ipv6 (struct in6_addr *, unsigned int, vrf_id_t);
+extern struct interface *if_lookup_by_ipv6_exact (struct in6_addr *, unsigned int, vrf_id_t);
 #endif /* HAVE_IPV6 */
 
 #endif /* _QUAGGA_BGP_ZEBRA_H */
index c7f9232a89b7dba117bd2a4c2122a712399a25a5..dbecd599aa35ea497a5d72371dc5ec3650e66d1a 100644 (file)
@@ -74,8 +74,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 /* BGP process wide configuration.  */
 static struct bgp_master bgp_master;
 
-extern struct in_addr router_id_zebra;
-
 /* BGP process wide configuration pointer to export.  */
 struct bgp_master *bm;
 
@@ -2754,16 +2752,47 @@ bgp_create (as_t *as, const char *name)
   bgp->as = *as;
 
   if (name)
-    bgp->name = XSTRDUP(MTYPE_BGP, name);
+    {
+      bgp->name = XSTRDUP(MTYPE_BGP, name);
+    }
+  else
+    {
+      //Pending: See if calling bgp_instance_up() makes more sense.
+      THREAD_TIMER_ON (bm->master, bgp->t_startup, bgp_startup_timer_expire,
+                       bgp, bgp->restart_time);
+    }
 
   bgp->wpkt_quanta = BGP_WRITE_PACKET_MAX;
   bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
 
+  update_bgp_group_init(bgp);
+  return bgp;
+}
+
+void
+bgp_instance_up (struct bgp *bgp)
+{
+  struct peer *peer;
+  struct listnode *node, *next;
+  afi_t afi;
+  int i;
+
   THREAD_TIMER_ON (bm->master, bgp->t_startup, bgp_startup_timer_expire,
                    bgp, bgp->restart_time);
 
-  update_bgp_group_init(bgp);
-  return bgp;
+  /* Delete static route. */
+  bgp_static_add (bgp);
+
+  /* Set redistribution. */
+  for (afi = AFI_IP; afi < AFI_MAX; afi++)
+    for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
+      if (i != ZEBRA_ROUTE_BGP && bgp_redist_lookup(bgp, afi, i, 0))
+       bgp_redistribute_set (bgp, afi, i, 0);
+
+  for (ALL_LIST_ELEMENTS (bgp->peer, node, next, peer))
+    {
+      BGP_EVENT_ADD (peer, BGP_Start);
+    }
 }
 
 /* Return first entry of BGP. */
@@ -2804,6 +2833,20 @@ bgp_lookup_by_name (const char *name)
   return NULL;
 }
 
+/* Lookup BGP structure by view name. */
+//Pending: move this based on the vrf_hash lookup and find the linked bgp instance.
+struct bgp *
+bgp_lookup_by_vrf_id (vrf_id_t vrf_id)
+{
+  struct bgp *bgp;
+  struct listnode *node, *nnode;
+
+  for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
+    if (bgp->vrf_id == vrf_id)
+      return bgp;
+  return NULL;
+}
+
 /* Called from VTY commands. */
 int
 bgp_get (struct bgp **bgp_val, as_t *as, const char *name)
@@ -2852,7 +2895,9 @@ bgp_get (struct bgp **bgp_val, as_t *as, const char *name)
     }
 
   bgp = bgp_create (as, name);
-  bgp_router_id_set(bgp, &router_id_zebra);
+  bgp_router_id_set(bgp, &bgp->router_id_zebra);
+  bgp_address_init (bgp);
+  bgp_scan_init (bgp);
   *bgp_val = bgp;
 
   bgp->t_rmap_def_originate_eval = NULL;
@@ -2869,12 +2914,14 @@ bgp_get (struct bgp **bgp_val, as_t *as, const char *name)
 
   listnode_add (bm->bgp, bgp);
 
+  bgp_vrf_update (bgp);
+
   return 0;
 }
 
 /* Delete BGP instance. */
-int
-bgp_delete (struct bgp *bgp)
+void
+bgp_instance_down (struct bgp *bgp)
 {
   struct peer *peer;
   struct peer_group *group;
@@ -2906,7 +2953,7 @@ bgp_delete (struct bgp *bgp)
   for (afi = AFI_IP; afi < AFI_MAX; afi++)
     for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
       if (i != ZEBRA_ROUTE_BGP)
-       bgp_redistribute_unset (bgp, afi, i, 0);
+       bgp_redistribute_unreg (bgp, afi, i, 0);
 
   for (ALL_LIST_ELEMENTS (bgp->group, node, next, group))
     {
@@ -2918,7 +2965,6 @@ bgp_delete (struct bgp *bgp)
              bgp_notify_send (peer, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN);
            }
        }
-      peer_group_delete (group);
     }
 
   for (ALL_LIST_ELEMENTS (bgp->peer, node, next, peer))
@@ -2928,7 +2974,42 @@ bgp_delete (struct bgp *bgp)
          /* Send notify to remote peer. */
          bgp_notify_send (peer, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN);
        }
+    }
+
+  if (bgp->t_rmap_def_originate_eval)
+    {
+      BGP_TIMER_OFF(bgp->t_rmap_def_originate_eval);
+    }
+
+  return;
+}
 
+/* Delete BGP instance. */
+int
+bgp_delete (struct bgp *bgp)
+{
+  struct peer *peer;
+  struct peer_group *group;
+  struct listnode *node, *next;
+  afi_t afi;
+  int i;
+
+  /* Delete static route. */
+  bgp_static_delete (bgp);
+
+  /* Unset redistribution. */
+  for (afi = AFI_IP; afi < AFI_MAX; afi++)
+    for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
+      if (i != ZEBRA_ROUTE_BGP)
+       bgp_redistribute_unset (bgp, afi, i, 0);
+
+  for (ALL_LIST_ELEMENTS (bgp->group, node, next, group))
+    {
+      peer_group_delete (group);
+    }
+
+  for (ALL_LIST_ELEMENTS (bgp->peer, node, next, peer))
+    {
       peer_delete (peer);
     }
 
@@ -2939,7 +3020,6 @@ bgp_delete (struct bgp *bgp)
 
   if (bgp->t_rmap_def_originate_eval)
     {
-      BGP_TIMER_OFF(bgp->t_rmap_def_originate_eval);
       bgp_unlock(bgp);
     }
 
@@ -3088,6 +3168,12 @@ peer_lookup (struct bgp *bgp, union sockunion *su)
   
       for (ALL_LIST_ELEMENTS (bm->bgp, bgpnode, nbgpnode, bgp))
         {
+          /*
+           * Don't have to cross the instance boundaries for VRFs.
+           */
+          if (bgp_flag_check(bgp, BGP_FLAG_INSTANCE_TYPE_VRF))
+            continue;
+
           peer = hash_lookup(bgp->peerhash, &tmp_peer);
 
           if (peer)
@@ -6812,7 +6898,8 @@ bgp_config_write (struct vty *vty)
       if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE))
        {
          if (bgp->name)
-           vty_out (vty, " view %s", bgp->name);
+           vty_out (vty, " %s %s", (bgp_flag_check(bgp, BGP_FLAG_INSTANCE_TYPE_VIEW) ? 
+                                     "view" : "vrf"), bgp->name);
        }
       vty_out (vty, "%s", VTY_NEWLINE);
 
@@ -7043,7 +7130,6 @@ bgp_init (void)
 {
 
   /* allocates some vital data structures used by peer commands in vty_init */
-  bgp_scan_init ();
 
   /* Init zebra. */
   bgp_zebra_init(bm->master);
@@ -7057,7 +7143,6 @@ bgp_init (void)
   bgp_dump_init ();
   bgp_route_init ();
   bgp_route_map_init ();
-  bgp_address_init ();
   bgp_scan_vty_init();
   bgp_mplsvpn_init ();
 
index d9716c57000477351838bca90dae424098c985f3..9414da4d0999088b0da82956fc3b21c453a459e4 100644 (file)
@@ -22,6 +22,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #define _QUAGGA_BGPD_H
 
 #include "lib/json.h"
+#include "vrf.h"
+
 /* For union sockunion.  */
 #include "queue.h"
 #include "sockunion.h"
@@ -135,6 +137,8 @@ struct bgp
 
   /* Name of this BGP instance.  */
   char *name;
+
+  vrf_id_t vrf_id;
   
   /* Reference count to allow peer_delete to finish after bgp_delete */
   int lock;
@@ -184,6 +188,7 @@ struct bgp
   /* BGP router identifier.  */
   struct in_addr router_id;
   struct in_addr router_id_static;
+  struct in_addr router_id_zebra;
 
   /* BGP route reflector cluster ID.  */
   struct in_addr cluster_id;
@@ -251,11 +256,23 @@ struct bgp
 #define BGP_FLAG_MULTIPATH_RELAX_AS_SET   (1 << 17)
 #define BGP_FLAG_FORCE_STATIC_PROCESS     (1 << 18)
 #define BGP_FLAG_SHOW_HOSTNAME            (1 << 19)
+#define BGP_FLAG_INSTANCE_TYPE_VIEW       (1 << 20)
+#define BGP_FLAG_INSTANCE_TYPE_VRF        (1 << 21)
 
   /* BGP Per AF flags */
   u_int16_t af_flags[AFI_MAX][SAFI_MAX];
 #define BGP_CONFIG_DAMPENING              (1 << 0)
 
+  /* Route table for next-hop lookup cache. */
+  struct bgp_table *nexthop_cache_table[AFI_MAX];
+
+  /* Route table for import-check */
+  struct bgp_table *import_check_table[AFI_MAX];
+
+  struct bgp_table *connected_table[AFI_MAX];
+
+  struct hash *address_hash;
+
   /* Static route configuration.  */
   struct bgp_table *route[AFI_MAX][SAFI_MAX];
 
@@ -1092,6 +1109,7 @@ extern int bgp_nexthop_set (union sockunion *, union sockunion *,
 extern struct bgp *bgp_get_default (void);
 extern struct bgp *bgp_lookup (as_t, const char *);
 extern struct bgp *bgp_lookup_by_name (const char *);
+extern struct bgp *bgp_lookup_by_vrf_id (vrf_id_t);
 extern struct peer *peer_lookup (struct bgp *, union sockunion *);
 extern struct peer *peer_lookup_by_conf_if (struct bgp *, const char *);
 extern struct peer *peer_lookup_by_hostname(struct bgp *, const char *);
@@ -1143,6 +1161,8 @@ extern int bgp_option_unset (int);
 extern int bgp_option_check (int);
 
 extern int bgp_get (struct bgp **, as_t *, const char *);
+extern void bgp_instance_up (struct bgp *);
+extern void bgp_instance_down (struct bgp *);
 extern int bgp_delete (struct bgp *);
 
 extern int bgp_flag_set (struct bgp *, int);
@@ -1276,7 +1296,6 @@ extern struct peer_af * peer_af_create (struct peer *, afi_t, safi_t);
 extern struct peer_af * peer_af_find (struct peer *, afi_t, safi_t);
 extern int peer_af_delete (struct peer *, afi_t, safi_t);
 
-extern void bgp_scan_finish(void);
 extern void bgp_close(void);
 
 static inline int