extract.pl.in 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 bgp " "<1-4294967295>"'} = "ignore";
  38. $ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
  39. $ignore{'"router isis WORD"'} = "ignore";
  40. $ignore{'"router zebra"'} = "ignore";
  41. $ignore{'"address-family ipv4"'} = "ignore";
  42. $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
  43. $ignore{'"address-family ipv6"'} = "ignore";
  44. $ignore{'"address-family ipv6 unicast"'} = "ignore";
  45. $ignore{'"address-family vpnv4"'} = "ignore";
  46. $ignore{'"address-family vpnv4 unicast"'} = "ignore";
  47. $ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
  48. $ignore{'"exit-address-family"'} = "ignore";
  49. $ignore{'"key chain WORD"'} = "ignore";
  50. $ignore{'"key <0-2147483647>"'} = "ignore";
  51. $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
  52. $ignore{'"show route-map"'} = "ignore";
  53. $ignore{'"line vty"'} = "ignore";
  54. $ignore{'"who"'} = "ignore";
  55. $ignore{'"terminal monitor"'} = "ignore";
  56. $ignore{'"terminal no monitor"'} = "ignore";
  57. $ignore{'"show history"'} = "ignore";
  58. foreach (@ARGV) {
  59. $file = $_;
  60. 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 |");
  61. local $/; undef $/;
  62. $line = <FH>;
  63. close (FH);
  64. @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
  65. @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
  66. # DEFUN process
  67. foreach (@defun) {
  68. my (@defun_array);
  69. @defun_array = split (/,/);
  70. $defun_array[0] = '';
  71. # Actual input command string.
  72. $str = "$defun_array[2]";
  73. $str =~ s/^\s+//g;
  74. $str =~ s/\s+$//g;
  75. # Get VTY command structure. This is needed for searching
  76. # install_element() command.
  77. $cmd = "$defun_array[1]";
  78. $cmd =~ s/^\s+//g;
  79. $cmd =~ s/\s+$//g;
  80. # $protocol is VTYSH_PROTO format for redirection of user input
  81. if ($file =~ /lib\/keychain\.c$/) {
  82. $protocol = "VTYSH_RIPD";
  83. }
  84. elsif ($file =~ /lib\/routemap\.c$/) {
  85. $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
  86. }
  87. elsif ($file =~ /lib\/filter\.c$/) {
  88. $protocol = "VTYSH_ALL";
  89. }
  90. elsif ($file =~ /lib\/plist\.c$/) {
  91. if ($defun_array[1] =~ m/ipv6/) {
  92. $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
  93. } else {
  94. $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
  95. }
  96. }
  97. elsif ($file =~ /lib\/distribute\.c$/) {
  98. if ($defun_array[1] =~ m/ipv6/) {
  99. $protocol = "VTYSH_RIPNGD";
  100. } else {
  101. $protocol = "VTYSH_RIPD";
  102. }
  103. }
  104. elsif ($file =~ /lib\/if_rmap\.c$/) {
  105. if ($defun_array[1] =~ m/ipv6/) {
  106. $protocol = "VTYSH_RIPNGD";
  107. } else {
  108. $protocol = "VTYSH_RIPD";
  109. }
  110. }
  111. elsif ($file =~ /lib\/vty\.c$/) {
  112. $protocol = "VTYSH_ALL";
  113. }
  114. else {
  115. ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
  116. $protocol = "VTYSH_" . uc $protocol;
  117. }
  118. # Append _vtysh to structure then build DEFUN again
  119. $defun_array[1] = $cmd . "_vtysh";
  120. $defun_body = join (", ", @defun_array);
  121. # $cmd -> $str hash for lookup
  122. $cmd2str{$cmd} = $str;
  123. $cmd2defun{$cmd} = $defun_body;
  124. $cmd2proto{$cmd} = $protocol;
  125. }
  126. # install_element() process
  127. foreach (@install) {
  128. my (@element_array);
  129. @element_array = split (/,/);
  130. # Install node
  131. $enode = $element_array[0];
  132. $enode =~ s/^\s+//g;
  133. $enode =~ s/\s+$//g;
  134. ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
  135. # VTY command structure.
  136. ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
  137. $ecmd =~ s/^\s+//g;
  138. $ecmd =~ s/\s+$//g;
  139. # Register $ecmd
  140. if (defined ($cmd2str{$ecmd})
  141. && ! defined ($ignore{$cmd2str{$ecmd}})) {
  142. my ($key);
  143. $key = $enode . "," . $cmd2str{$ecmd};
  144. $ocmd{$key} = $ecmd;
  145. $odefun{$key} = $cmd2defun{$ecmd};
  146. push (@{$oproto{$key}}, $cmd2proto{$ecmd});
  147. }
  148. }
  149. }
  150. # Check finaly alive $cmd;
  151. foreach (keys %odefun) {
  152. my ($node, $str) = (split (/,/));
  153. my ($cmd) = $ocmd{$_};
  154. $live{$cmd} = $_;
  155. }
  156. # Output DEFSH
  157. foreach (keys %live) {
  158. my ($proto);
  159. my ($key);
  160. $key = $live{$_};
  161. $proto = join ("|", @{$oproto{$key}});
  162. printf "DEFSH ($proto$odefun{$key})\n\n";
  163. }
  164. # Output install_element
  165. print <<EOF;
  166. void
  167. vtysh_init_cmd ()
  168. {
  169. EOF
  170. foreach (keys %odefun) {
  171. my ($node, $str) = (split (/,/));
  172. $cmd = $ocmd{$_};
  173. $cmd =~ s/_cmd/_cmd_vtysh/;
  174. printf " install_element ($node, &$cmd);\n";
  175. }
  176. print <<EOF
  177. }
  178. EOF