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