extract.pl.in 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #! @PERL@
  2. ##
  3. ## @configure_input@
  4. ##
  5. ## Virtual terminal interface shell command extractor.
  6. ## Copyright (C) 2000 Kunihiro Ishiguro
  7. ##
  8. ## This file is part of GNU Zebra.
  9. ##
  10. ## GNU Zebra is free software; you can redistribute it and/or modify it
  11. ## under the terms of the GNU General Public License as published by the
  12. ## Free Software Foundation; either version 2, or (at your option) any
  13. ## later version.
  14. ##
  15. ## GNU Zebra is distributed in the hope that it will be useful, but
  16. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. ## General Public License for more details.
  19. ##
  20. ## You should have received a copy of the GNU General Public License
  21. ## along with GNU Zebra; see the file COPYING. If not, write to the Free
  22. ## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ## 02111-1307, USA.
  24. ##
  25. print <<EOF;
  26. #include <zebra.h>
  27. #include "command.h"
  28. #include "vtysh.h"
  29. EOF
  30. $ignore{'"interface IFNAME"'} = "ignore";
  31. $ignore{'"ip vrf NAME"'} = "ignore";
  32. $ignore{'"router rip"'} = "ignore";
  33. $ignore{'"router ripng"'} = "ignore";
  34. $ignore{'"router ospf"'} = "ignore";
  35. $ignore{'"router ospf <0-65535>"'} = "ignore";
  36. $ignore{'"router ospf6"'} = "ignore";
  37. $ignore{'"router babel"'} = "ignore";
  38. $ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
  39. $ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
  40. $ignore{'"router isis WORD"'} = "ignore";
  41. $ignore{'"router zebra"'} = "ignore";
  42. $ignore{'"address-family ipv4"'} = "ignore";
  43. $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
  44. $ignore{'"address-family ipv6"'} = "ignore";
  45. $ignore{'"address-family ipv6 unicast"'} = "ignore";
  46. $ignore{'"address-family vpnv4"'} = "ignore";
  47. $ignore{'"address-family vpnv4 unicast"'} = "ignore";
  48. $ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
  49. $ignore{'"exit-address-family"'} = "ignore";
  50. $ignore{'"key chain WORD"'} = "ignore";
  51. $ignore{'"key <0-2147483647>"'} = "ignore";
  52. $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
  53. $ignore{'"show route-map"'} = "ignore";
  54. $ignore{'"line vty"'} = "ignore";
  55. $ignore{'"who"'} = "ignore";
  56. $ignore{'"terminal monitor"'} = "ignore";
  57. $ignore{'"terminal no monitor"'} = "ignore";
  58. $ignore{'"show history"'} = "ignore";
  59. foreach (@ARGV) {
  60. $file = $_;
  61. open (FH, "@CPP@ -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib -I@top_builddir@/lib -I@top_srcdir@/isisd/topology @CPPFLAGS@ $file |");
  62. local $/; undef $/;
  63. $line = <FH>;
  64. close (FH);
  65. @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
  66. @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
  67. # DEFUN process
  68. foreach (@defun) {
  69. my (@defun_array);
  70. @defun_array = split (/,/);
  71. $defun_array[0] = '';
  72. # Actual input command string.
  73. $str = "$defun_array[2]";
  74. $str =~ s/^\s+//g;
  75. $str =~ s/\s+$//g;
  76. # Get VTY command structure. This is needed for searching
  77. # install_element() command.
  78. $cmd = "$defun_array[1]";
  79. $cmd =~ s/^\s+//g;
  80. $cmd =~ s/\s+$//g;
  81. # $protocol is VTYSH_PROTO format for redirection of user input
  82. if ($file =~ /lib\/keychain\.c$/) {
  83. $protocol = "VTYSH_RIPD";
  84. }
  85. elsif ($file =~ /lib\/routemap\.c$/) {
  86. $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
  87. }
  88. elsif ($file =~ /lib\/filter\.c$/) {
  89. $protocol = "VTYSH_ALL";
  90. }
  91. elsif ($file =~ /lib\/plist\.c$/) {
  92. if ($defun_array[1] =~ m/ipv6/) {
  93. $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
  94. } else {
  95. $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
  96. }
  97. }
  98. elsif ($file =~ /lib\/distribute\.c$/) {
  99. if ($defun_array[1] =~ m/ipv6/) {
  100. $protocol = "VTYSH_RIPNGD";
  101. } else {
  102. $protocol = "VTYSH_RIPD";
  103. }
  104. }
  105. elsif ($file =~ /lib\/if_rmap\.c$/) {
  106. if ($defun_array[1] =~ m/ipv6/) {
  107. $protocol = "VTYSH_RIPNGD";
  108. } else {
  109. $protocol = "VTYSH_RIPD";
  110. }
  111. }
  112. elsif ($file =~ /lib\/vty\.c$/) {
  113. $protocol = "VTYSH_ALL";
  114. }
  115. else {
  116. ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
  117. $protocol = "VTYSH_" . uc $protocol;
  118. }
  119. # Append _vtysh to structure then build DEFUN again
  120. $defun_array[1] = $cmd . "_vtysh";
  121. $defun_body = join (", ", @defun_array);
  122. # $cmd -> $str hash for lookup
  123. $cmd2str{$cmd} = $str;
  124. $cmd2defun{$cmd} = $defun_body;
  125. $cmd2proto{$cmd} = $protocol;
  126. }
  127. # install_element() process
  128. foreach (@install) {
  129. my (@element_array);
  130. @element_array = split (/,/);
  131. # Install node
  132. $enode = $element_array[0];
  133. $enode =~ s/^\s+//g;
  134. $enode =~ s/\s+$//g;
  135. ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
  136. # VTY command structure.
  137. ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
  138. $ecmd =~ s/^\s+//g;
  139. $ecmd =~ s/\s+$//g;
  140. # Register $ecmd
  141. if (defined ($cmd2str{$ecmd})
  142. && ! defined ($ignore{$cmd2str{$ecmd}})) {
  143. my ($key);
  144. $key = $enode . "," . $cmd2str{$ecmd};
  145. $ocmd{$key} = $ecmd;
  146. $odefun{$key} = $cmd2defun{$ecmd};
  147. push (@{$oproto{$key}}, $cmd2proto{$ecmd});
  148. }
  149. }
  150. }
  151. # Check finaly alive $cmd;
  152. foreach (keys %odefun) {
  153. my ($node, $str) = (split (/,/));
  154. my ($cmd) = $ocmd{$_};
  155. $live{$cmd} = $_;
  156. }
  157. # Output DEFSH
  158. foreach (keys %live) {
  159. my ($proto);
  160. my ($key);
  161. $key = $live{$_};
  162. $proto = join ("|", @{$oproto{$key}});
  163. printf "DEFSH ($proto$odefun{$key})\n\n";
  164. }
  165. # Output install_element
  166. print <<EOF;
  167. void
  168. vtysh_init_cmd ()
  169. {
  170. EOF
  171. foreach (keys %odefun) {
  172. my ($node, $str) = (split (/,/));
  173. $cmd = $ocmd{$_};
  174. $cmd =~ s/_cmd/_cmd_vtysh/;
  175. printf " install_element ($node, &$cmd);\n";
  176. }
  177. print <<EOF
  178. }
  179. EOF