]> git.proxmox.com Git - mirror_frr.git/blob - vtysh/extract.pl.in
*: get rid of "MTYPE 0"
[mirror_frr.git] / vtysh / extract.pl.in
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
26 print <<EOF;
27 #include <zebra.h>
28
29 #include "command.h"
30 #include "linklist.h"
31
32 #include "vtysh.h"
33
34 EOF
35
36 $ignore{'"interface IFNAME"'} = "ignore";
37 $ignore{'"interface IFNAME " "vrf <0-65535>"'} = "ignore";
38 $ignore{'"interface IFNAME " "vrf NAME"'} = "ignore";
39 $ignore{'"vrf NAME"'} = "ignore";
40 $ignore{'"ip vrf NAME"'} = "ignore";
41 $ignore{'"router rip"'} = "ignore";
42 $ignore{'"router ripng"'} = "ignore";
43 $ignore{'"router ospf"'} = "ignore";
44 $ignore{'"router ospf <1-65535>"'} = "ignore";
45 $ignore{'"router ospf6"'} = "ignore";
46 $ignore{'"router bgp"'} = "ignore";
47 $ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
48 $ignore{'"router bgp " "<1-4294967295>" " (view|vrf) WORD"'} = "ignore";
49 $ignore{'"router isis WORD"'} = "ignore";
50 $ignore{'"router zebra"'} = "ignore";
51 $ignore{'"address-family ipv4"'} = "ignore";
52 $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
53 $ignore{'"address-family ipv6"'} = "ignore";
54 $ignore{'"address-family ipv6 (unicast|multicast)"'} = "ignore";
55 $ignore{'"address-family vpnv4"'} = "ignore";
56 $ignore{'"address-family vpnv4 unicast"'} = "ignore";
57 $ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
58 $ignore{'"address-family encap"'} = "ignore";
59 $ignore{'"address-family encapv4"'} = "ignore";
60 $ignore{'"address-family encapv6"'} = "ignore";
61 $ignore{'"address-family vpnv6"'} = "ignore";
62 $ignore{'"address-family vpnv6 unicast"'} = "ignore";
63 $ignore{'"exit-address-family"'} = "ignore";
64 $ignore{'"key chain WORD"'} = "ignore";
65 $ignore{'"key <0-2147483647>"'} = "ignore";
66 $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
67 $ignore{'"show route-map"'} = "ignore";
68 $ignore{'"line vty"'} = "ignore";
69 $ignore{'"who"'} = "ignore";
70 $ignore{'"terminal monitor"'} = "ignore";
71 $ignore{'"terminal no monitor"'} = "ignore";
72 $ignore{'"show history"'} = "ignore";
73
74 my $cli_stomp = 0;
75
76 foreach (@ARGV) {
77 $file = $_;
78
79 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 |");
80 local $/; undef $/;
81 $line = <FH>;
82 close (FH);
83
84 # ?: makes a group non-capturing
85 @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg);
86 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
87
88 # DEFUN process
89 foreach (@defun) {
90 # $_ will contain the entire string including the DEFUN, ALIAS, etc.
91 # We need to extract the DEFUN/ALIAS from everything in ()s.
92 # The /s at the end tells the regex to allow . to match newlines.
93 $_ =~ /^(.*?) \((.*)\)$/s;
94
95 my (@defun_array);
96 $defun_or_alias = $1;
97 @defun_array = split (/,/, $2);
98
99 if ($defun_or_alias =~ /_HIDDEN/) {
100 $hidden = 1;
101 } else {
102 $hidden = 0;
103 }
104
105 $defun_array[0] = '';
106
107 # Actual input command string.
108 $str = "$defun_array[2]";
109 $str =~ s/^\s+//g;
110 $str =~ s/\s+$//g;
111
112 # Get VTY command structure. This is needed for searching
113 # install_element() command.
114 $cmd = "$defun_array[1]";
115 $cmd =~ s/^\s+//g;
116 $cmd =~ s/\s+$//g;
117
118 # $protocol is VTYSH_PROTO format for redirection of user input
119 if ($file =~ /lib\/keychain\.c$/) {
120 $protocol = "VTYSH_RIPD";
121 }
122 elsif ($file =~ /lib\/routemap\.c$/) {
123 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
124 }
125 elsif ($file =~ /lib\/vrf\.c$/) {
126 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
127 }
128 elsif ($file =~ /lib\/filter\.c$/) {
129 $protocol = "VTYSH_ALL";
130 }
131 elsif ($file =~ /lib\/plist\.c$/) {
132 if ($defun_array[1] =~ m/ipv6/) {
133 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
134 } else {
135 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
136 }
137 }
138 elsif ($file =~ /lib\/distribute\.c$/) {
139 if ($defun_array[1] =~ m/ipv6/) {
140 $protocol = "VTYSH_RIPNGD";
141 } else {
142 $protocol = "VTYSH_RIPD";
143 }
144 }
145 elsif ($file =~ /lib\/if_rmap\.c$/) {
146 if ($defun_array[1] =~ m/ipv6/) {
147 $protocol = "VTYSH_RIPNGD";
148 } else {
149 $protocol = "VTYSH_RIPD";
150 }
151 }
152 elsif ($file =~ /lib\/vty\.c$/) {
153 $protocol = "VTYSH_ALL";
154 }
155 else {
156 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
157 $protocol = "VTYSH_" . uc $protocol;
158 }
159
160 # Append _vtysh to structure then build DEFUN again
161 $defun_array[1] = $cmd . "_vtysh";
162 $defun_body = join (", ", @defun_array);
163
164 # $cmd -> $str hash for lookup
165 if (exists($cmd2str{$cmd})) {
166 warn "Duplicate CLI Function: $cmd\n";
167 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
168 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
169 $cli_stomp++;
170 }
171 $cmd2str{$cmd} = $str;
172 $cmd2defun{$cmd} = $defun_body;
173 $cmd2proto{$cmd} = $protocol;
174 $cmd2hidden{$cmd} = $hidden;
175 }
176
177 # install_element() process
178 foreach (@install) {
179 my (@element_array);
180 @element_array = split (/,/);
181
182 # Install node
183 $enode = $element_array[0];
184 $enode =~ s/^\s+//g;
185 $enode =~ s/\s+$//g;
186 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
187
188 # VTY command structure.
189 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
190 $ecmd =~ s/^\s+//g;
191 $ecmd =~ s/\s+$//g;
192
193 # Register $ecmd
194 if (defined ($cmd2str{$ecmd})
195 && ! defined ($ignore{$cmd2str{$ecmd}})) {
196 my ($key);
197 $key = $enode . "," . $cmd2str{$ecmd};
198 $ocmd{$key} = $ecmd;
199 $odefun{$key} = $cmd2defun{$ecmd};
200
201 if ($cmd2hidden{$ecmd}) {
202 $defsh{$key} = "DEFSH_HIDDEN"
203 } else {
204 $defsh{$key} = "DEFSH"
205 }
206 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
207 }
208 }
209 }
210
211 my $bad_cli_stomps = 109;
212 # Currently we have $bad_cli_stomps. This was determined by
213 # running this script and counting up the collisions from what
214 # was returned.
215 #
216 # When we have cli commands that map to the same function name, we
217 # can introduce subtle bugs due to code not being called when
218 # we think it is.
219 #
220 # If extract.pl fails with a error message and you've been
221 # modifying the cli, then go back and fix your code to
222 # not have cli command function collisions.
223 #
224 # If you've removed a cli overwrite, you can safely subtract
225 # one from $bad_cli_stomps. If you've added to the problem
226 # please fix your code before submittal
227 if ($cli_stomp != $bad_cli_stomps) {
228 warn "Expected $bad_cli_stomps command line stomps, but got $cli_stomp instead\n";
229 exit $cli_stomp;
230 }
231
232 # Check finaly alive $cmd;
233 foreach (keys %odefun) {
234 my ($node, $str) = (split (/,/));
235 my ($cmd) = $ocmd{$_};
236 $live{$cmd} = $_;
237 }
238
239 # Output DEFSH
240 foreach (keys %live) {
241 my ($proto);
242 my ($key);
243 $key = $live{$_};
244 $proto = join ("|", @{$oproto{$key}});
245 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
246 }
247
248 # Output install_element
249 print <<EOF;
250 void
251 vtysh_init_cmd ()
252 {
253 EOF
254
255 foreach (keys %odefun) {
256 my ($node, $str) = (split (/,/));
257 $cmd = $ocmd{$_};
258 $cmd =~ s/_cmd/_cmd_vtysh/;
259 printf " install_element ($node, &$cmd);\n";
260 }
261
262 print <<EOF
263 }
264 EOF