5 ## Virtual terminal interface shell command extractor.
6 ## Copyright (C) 2000 Kunihiro Ishiguro
8 ## This file is part of GNU Zebra.
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
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.
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
33 $ignore{'"interface IFNAME"'} = "ignore";
34 $ignore{'"interface IFNAME " "vrf <0-65535>"'} = "ignore";
35 $ignore{'"link-params"'} = "ignore";
36 $ignore{'"ip vrf NAME"'} = "ignore";
37 $ignore{'"router rip"'} = "ignore";
38 $ignore{'"router ripng"'} = "ignore";
39 $ignore{'"router ospf"'} = "ignore";
40 $ignore{'"router ospf <0-65535>"'} = "ignore";
41 $ignore{'"router ospf6"'} = "ignore";
42 $ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
43 $ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
44 $ignore{'"router isis WORD"'} = "ignore";
45 $ignore{'"router zebra"'} = "ignore";
46 $ignore{'"address-family ipv4"'} = "ignore";
47 $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
48 $ignore{'"address-family ipv6"'} = "ignore";
49 $ignore{'"address-family ipv6 (unicast|multicast)"'} = "ignore";
50 $ignore{'"address-family vpnv4"'} = "ignore";
51 $ignore{'"address-family vpnv4 unicast"'} = "ignore";
52 $ignore{'"address-family vpnv6"'} = "ignore";
53 $ignore{'"address-family vpnv6 unicast"'} = "ignore";
54 $ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
55 $ignore{'"address-family encap"'} = "ignore";
56 $ignore{'"address-family encapv4"'} = "ignore";
57 $ignore{'"address-family encapv6"'} = "ignore";
58 $ignore{'"exit-address-family"'} = "ignore";
59 $ignore{'"exit-link-params"'} = "ignore";
60 $ignore{'"vnc defaults"'} = "ignore";
61 $ignore{'"vnc nve-group NAME"'} = "ignore";
62 $ignore{'"exit-vnc"'} = "ignore";
63 $ignore{'"key chain WORD"'} = "ignore";
64 $ignore{'"key <0-2147483647>"'} = "ignore";
65 $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
66 $ignore{'"show route-map"'} = "ignore";
67 $ignore{'"line vty"'} = "ignore";
68 $ignore{'"who"'} = "ignore";
69 $ignore{'"terminal monitor"'} = "ignore";
70 $ignore{'"terminal no monitor"'} = "ignore";
71 $ignore{'"show history"'} = "ignore";
78 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 |");
83 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
84 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
89 @defun_array = split (/,/);
93 # Actual input command string.
94 $str = "$defun_array[2]";
98 # Get VTY command structure. This is needed for searching
99 # install_element() command.
100 $cmd = "$defun_array[1]";
104 # $protocol is VTYSH_PROTO format for redirection of user input
105 if ($file =~ /lib\/keychain\.c$/) {
106 $protocol = "VTYSH_RIPD";
108 elsif ($file =~ /lib\/routemap\.c$/) {
109 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
111 elsif ($file =~ /lib\/filter\.c$/) {
112 $protocol = "VTYSH_ALL";
114 elsif ($file =~ /lib\/vrf\.c$/) {
115 $protocol = "VTYSH_ZEBRA";
117 elsif ($file =~ /lib\/plist\.c$/) {
118 if ($defun_array[1] =~ m/ipv6/) {
119 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
121 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
124 elsif ($file =~ /lib\/distribute\.c$/) {
125 if ($defun_array[1] =~ m/ipv6/) {
126 $protocol = "VTYSH_RIPNGD";
128 $protocol = "VTYSH_RIPD";
131 elsif ($file =~ /lib\/if_rmap\.c$/) {
132 if ($defun_array[1] =~ m/ipv6/) {
133 $protocol = "VTYSH_RIPNGD";
135 $protocol = "VTYSH_RIPD";
138 elsif ($file =~ /lib\/vty\.c$/) {
139 $protocol = "VTYSH_ALL";
142 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
143 $protocol = "VTYSH_" . uc $protocol;
146 # Append _vtysh to structure then build DEFUN again
147 $defun_array[1] = $cmd . "_vtysh";
148 $defun_body = join (", ", @defun_array);
150 # $cmd -> $str hash for lookup
151 if (exists($cmd2str{$cmd})) {
152 warn "Duplicate CLI Function: $cmd\n";
153 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
154 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
157 $cmd2str{$cmd} = $str;
158 $cmd2defun{$cmd} = $defun_body;
159 $cmd2proto{$cmd} = $protocol;
162 # install_element() process
165 @element_array = split (/,/);
168 $enode = $element_array[0];
171 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
173 # VTY command structure.
174 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
179 if (defined ($cmd2str{$ecmd})
180 && ! defined ($ignore{$cmd2str{$ecmd}})) {
182 $key = $enode . "," . $cmd2str{$ecmd};
184 $odefun{$key} = $cmd2defun{$ecmd};
185 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
190 my $bad_cli_stomps = 102;
191 # Currently we have $bad_cli_stomps. This was determined by
192 # running this script and counting up the collisions from what
195 # When we have cli commands that map to the same function name, we
196 # can introduce subtle bugs due to code not being called when
199 # If extract.pl fails with a error message and you've been
200 # modifying the cli, then go back and fix your code to
201 # not have cli command function collisions.
203 # If you've removed a cli overwrite, you can safely subtract
204 # one from $bad_cli_stomps. If you've added to the problem
205 # please fix your code before submittal
206 if ($cli_stomp != $bad_cli_stomps) {
207 warn "Expected $bad_cli_stomps command line stomps, but got $cli_stomp instead\n";
211 # Check finaly alive $cmd;
212 foreach (keys %odefun) {
213 my ($node, $str) = (split (/,/));
214 my ($cmd) = $ocmd{$_};
219 foreach (keys %live) {
223 $proto = join ("|", @{$oproto{$key}});
224 printf "DEFSH ($proto$odefun{$key})\n\n";
227 # Output install_element
230 vtysh_init_cmd (void)
234 foreach (keys %odefun) {
235 my ($node, $str) = (split (/,/));
237 $cmd =~ s/_cmd/_cmd_vtysh/;
238 printf " install_element ($node, &$cmd);\n";