]>
git.proxmox.com Git - mirror_frr.git/blob - vtysh/extract.pl.in
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
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";
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 |");
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);
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;
104 $defun_or_alias = $1;
105 @defun_array = split (/,/, $2);
107 if ($defun_or_alias =~ /_HIDDEN/) {
113 $defun_array[0] = '';
115 # Actual input command string.
116 $str = "$defun_array[2]";
120 # Get VTY command structure. This is needed for searching
121 # install_element() command.
122 $cmd = "$defun_array[1]";
126 # $protocol is VTYSH_PROTO format for redirection of user input
127 if ($file =~ /lib\/keychain\
.c
$/) {
128 $protocol = "VTYSH_RIPD";
130 elsif ($file =~ /lib\/routemap\
.c
$/) {
131 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD";
133 elsif ($file =~ /lib\/vrf\
.c
$/) {
134 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
136 elsif ($file =~ /lib\/filter\
.c
$/) {
137 $protocol = "VTYSH_ALL";
139 elsif ($file =~ /lib\/ns\
.c
$/) {
140 $protocol = "VTYSH_ZEBRA";
142 elsif ($file =~ /lib\/plist\
.c
$/) {
143 if ($defun_array[1] =~ m/ipv6/) {
144 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
146 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD";
149 elsif ($file =~ /lib\/distribute\
.c
$/) {
150 if ($defun_array[1] =~ m/ipv6/) {
151 $protocol = "VTYSH_RIPNGD";
153 $protocol = "VTYSH_RIPD";
156 elsif ($file =~ /lib\/if_rmap\
.c
$/) {
157 if ($defun_array[1] =~ m/ipv6/) {
158 $protocol = "VTYSH_RIPNGD";
160 $protocol = "VTYSH_RIPD";
163 elsif ($file =~ /lib\/vty\
.c
$/) {
164 $protocol = "VTYSH_ALL";
166 elsif ($file =~ /librfp\/.*\
.c
$/ || $file =~ /rfapi\
/.*\.c$/) {
167 $protocol = "VTYSH_BGPD";
170 ($protocol) = ($file =~ /^.*\/([a-z0-9
]+)\
/[a-zA-Z0-9_\-]+\.c$/);
171 $protocol = "VTYSH_" . uc $protocol;
174 # Append _vtysh to structure then build DEFUN again
175 $defun_array[1] = $cmd . "_vtysh";
176 $defun_body = join (", ", @defun_array);
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";
185 $cmd2str{$cmd} = $str;
186 $cmd2defun{$cmd} = $defun_body;
187 $cmd2proto{$cmd} = $protocol;
188 $cmd2hidden{$cmd} = $hidden;
191 # install_element() process
194 @element_array = split (/,/);
197 $enode = $element_array[0];
200 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
202 # VTY command structure.
203 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
208 if (defined ($cmd2str{$ecmd})
209 && ! defined ($ignore{$cmd2str{$ecmd}})) {
211 $key = $enode . "," . $cmd2str{$ecmd};
213 $odefun{$key} = $cmd2defun{$ecmd};
215 if ($cmd2hidden{$ecmd}) {
216 $defsh{$key} = "DEFSH_HIDDEN"
218 $defsh{$key} = "DEFSH"
220 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
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
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
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.
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) {
248 # Check finaly alive $cmd;
249 foreach (keys %odefun) {
250 my ($node, $str) = (split (/,/));
251 my ($cmd) = $ocmd{$_};
256 foreach (keys %live) {
260 $proto = join ("|", @{$oproto{$key}});
261 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
264 # Output install_element
271 foreach (keys %odefun) {
272 my ($node, $str) = (split (/,/));
274 $cmd =~ s/_cmd/_cmd_vtysh/;
275 printf " install_element ($node, &$cmd);\n";