bgpd, lib, vtysh: hook up bgp ENCAP CLI node

Signed-off-by: Lou Berger <lberger@labn.net>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in
index 82532da..ca869b6 100755
--- a/vtysh/extract.pl.in
+++ b/vtysh/extract.pl.in
@@ -49,6 +49,9 @@
 $ignore{'"address-family vpnv4"'} = "ignore";
 $ignore{'"address-family vpnv4 unicast"'} = "ignore";
 $ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
+$ignore{'"address-family encap"'} = "ignore";
+$ignore{'"address-family encapv4"'} = "ignore";
+$ignore{'"address-family encapv6"'} = "ignore";
 $ignore{'"exit-address-family"'} = "ignore";
 $ignore{'"key chain WORD"'} = "ignore";
 $ignore{'"key <0-2147483647>"'} = "ignore";
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index a39889d..63b596a 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -281,6 +281,7 @@
   if (ret == CMD_SUCCESS || ret == CMD_SUCCESS_DAEMON || ret == CMD_WARNING)
     {
       if ((saved_node == BGP_VPNV4_NODE || saved_node == BGP_VPNV6_NODE
+	   || saved_node == BGP_ENCAP_NODE || saved_node == BGP_ENCAPV6_NODE
            || saved_node == BGP_IPV4_NODE
 	   || saved_node == BGP_IPV6_NODE || saved_node == BGP_IPV4M_NODE
 	   || saved_node == BGP_IPV6M_NODE)
@@ -691,6 +692,18 @@
   "%s(config-router-af)# "
 };
 
+static struct cmd_node bgp_encap_node =
+{
+  BGP_ENCAP_NODE,
+  "%s(config-router-af)# "
+};
+
+static struct cmd_node bgp_encapv6_node =
+{
+  BGP_ENCAPV6_NODE,
+  "%s(config-router-af)# "
+};
+
 static struct cmd_node bgp_ipv4_node =
 {
   BGP_IPV4_NODE,
@@ -849,6 +862,39 @@
 }
 
 DEFUNSH (VTYSH_BGPD,
+	 address_family_encap,
+	 address_family_encap_cmd,
+	 "address-family encap",
+	 "Enter Address Family command mode\n"
+	 "Address family\n")
+{
+  vty->node = BGP_ENCAP_NODE;
+  return CMD_SUCCESS;
+}
+
+DEFUNSH (VTYSH_BGPD,
+	 address_family_encapv4,
+	 address_family_encapv4_cmd,
+	 "address-family encapv4",
+	 "Enter Address Family command mode\n"
+	 "Address family\n")
+{
+  vty->node = BGP_ENCAP_NODE;
+  return CMD_SUCCESS;
+}
+
+DEFUNSH (VTYSH_BGPD,
+	 address_family_encapv6,
+	 address_family_encapv6_cmd,
+	 "address-family encapv6",
+	 "Enter Address Family command mode\n"
+	 "Address family\n")
+{
+  vty->node = BGP_ENCAPV6_NODE;
+  return CMD_SUCCESS;
+}
+
+DEFUNSH (VTYSH_BGPD,
 	 address_family_ipv4_unicast,
 	 address_family_ipv4_unicast_cmd,
 	 "address-family ipv4 unicast",
@@ -1074,6 +1120,8 @@
       break;
     case BGP_VPNV4_NODE:
     case BGP_VPNV6_NODE:
+    case BGP_ENCAP_NODE:
+    case BGP_ENCAPV6_NODE:
     case BGP_IPV4_NODE:
     case BGP_IPV4M_NODE:
     case BGP_IPV6_NODE:
@@ -1113,6 +1161,8 @@
       || vty->node == BGP_IPV4M_NODE
       || vty->node == BGP_VPNV4_NODE
       || vty->node == BGP_VPNV6_NODE
+      || vty->node == BGP_ENCAP_NODE
+      || vty->node == BGP_ENCAPV6_NODE
       || vty->node == BGP_IPV6_NODE
       || vty->node == BGP_IPV6M_NODE)
     vty->node = BGP_NODE;
@@ -2308,6 +2358,8 @@
   install_node (&zebra_node, NULL);
   install_node (&bgp_vpnv4_node, NULL);
   install_node (&bgp_vpnv6_node, NULL);
+  install_node (&bgp_encap_node, NULL);
+  install_node (&bgp_encapv6_node, NULL);
   install_node (&bgp_ipv4_node, NULL);
   install_node (&bgp_ipv4m_node, NULL);
 /* #ifdef HAVE_IPV6 */
@@ -2335,6 +2387,8 @@
   vtysh_install_default (ZEBRA_NODE);
   vtysh_install_default (BGP_VPNV4_NODE);
   vtysh_install_default (BGP_VPNV6_NODE);
+  vtysh_install_default (BGP_ENCAP_NODE);
+  vtysh_install_default (BGP_ENCAPV6_NODE);
   vtysh_install_default (BGP_IPV4_NODE);
   vtysh_install_default (BGP_IPV4M_NODE);
   vtysh_install_default (BGP_IPV6_NODE);
@@ -2373,6 +2427,10 @@
   install_element (BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd);
   install_element (BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd);
   install_element (BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd);
+  install_element (BGP_ENCAP_NODE, &vtysh_exit_bgpd_cmd);
+  install_element (BGP_ENCAP_NODE, &vtysh_quit_bgpd_cmd);
+  install_element (BGP_ENCAPV6_NODE, &vtysh_exit_bgpd_cmd);
+  install_element (BGP_ENCAPV6_NODE, &vtysh_quit_bgpd_cmd);
   install_element (BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd);
   install_element (BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd);
   install_element (BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd);
@@ -2405,6 +2463,8 @@
   install_element (BGP_IPV4M_NODE, &vtysh_end_all_cmd);
   install_element (BGP_VPNV4_NODE, &vtysh_end_all_cmd);
   install_element (BGP_VPNV6_NODE, &vtysh_end_all_cmd);
+  install_element (BGP_ENCAP_NODE, &vtysh_end_all_cmd);
+  install_element (BGP_ENCAPV6_NODE, &vtysh_end_all_cmd);
   install_element (BGP_IPV6_NODE, &vtysh_end_all_cmd);
   install_element (BGP_IPV6M_NODE, &vtysh_end_all_cmd);
   install_element (ISIS_NODE, &vtysh_end_all_cmd);
@@ -2433,6 +2493,8 @@
   install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd);
   install_element (BGP_NODE, &address_family_vpnv6_cmd);
   install_element (BGP_NODE, &address_family_vpnv6_unicast_cmd);
+  install_element (BGP_NODE, &address_family_encap_cmd);
+  install_element (BGP_NODE, &address_family_encapv6_cmd);
   install_element (BGP_NODE, &address_family_ipv4_unicast_cmd);
   install_element (BGP_NODE, &address_family_ipv4_multicast_cmd);
 #ifdef HAVE_IPV6
@@ -2441,6 +2503,8 @@
 #endif
   install_element (BGP_VPNV4_NODE, &exit_address_family_cmd);
   install_element (BGP_VPNV6_NODE, &exit_address_family_cmd);
+  install_element (BGP_ENCAP_NODE, &exit_address_family_cmd);
+  install_element (BGP_ENCAPV6_NODE, &exit_address_family_cmd);
   install_element (BGP_IPV4_NODE, &exit_address_family_cmd);
   install_element (BGP_IPV4M_NODE, &exit_address_family_cmd);
   install_element (BGP_IPV6_NODE, &exit_address_family_cmd);
diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
index dcbb70f..a069164 100644
--- a/vtysh/vtysh_config.c
+++ b/vtysh/vtysh_config.c
@@ -172,6 +172,12 @@
 	  else if (strncmp (line, " address-family vpn6",
 	      strlen (" address-family vpn6")) == 0)
 	    config = config_get (BGP_VPNV6_NODE, line);
+	  else if (strncmp (line, " address-family encapv6",
+	      strlen (" address-family encapv6")) == 0)
+	    config = config_get (BGP_ENCAPV6_NODE, line);
+	  else if (strncmp (line, " address-family encap",
+	      strlen (" address-family encap")) == 0)
+	    config = config_get (BGP_ENCAP_NODE, line);
 	  else if (strncmp (line, " address-family ipv4 multicast",
 		   strlen (" address-family ipv4 multicast")) == 0)
 	    config = config_get (BGP_IPV4M_NODE, line);