blob: 480d114d81e140480b7900ef81a3b03389f51568 [file] [log] [blame]
gdtfc9d0742004-06-30 14:25:12 +00001#! @PERL@
paul718e3742002-12-13 20:15:29 +00002##
paulb63dc1f2004-09-13 12:59:08 +00003## @configure_input@
4##
paul718e3742002-12-13 20:15:29 +00005## 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
26print <<EOF;
27#include <zebra.h>
28#include "command.h"
29#include "vtysh.h"
30
31EOF
32
33$ignore{'"interface IFNAME"'} = "ignore";
Feng Lu471ea392015-05-22 11:40:00 +020034$ignore{'"interface IFNAME " "vrf <0-65535>"'} = "ignore";
Olivier Dugeonac10d302016-04-19 18:33:42 +020035$ignore{'"link-params"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000036$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";
Paul Jakma10895fd2008-07-03 19:34:48 +000042$ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
43$ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
hassoc25e4582003-12-23 10:39:08 +000044$ignore{'"router isis WORD"'} = "ignore";
hasso528bed42005-04-07 18:42:09 +000045$ignore{'"router zebra"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000046$ignore{'"address-family ipv4"'} = "ignore";
47$ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
48$ignore{'"address-family ipv6"'} = "ignore";
viveka4f40292015-11-09 20:21:46 -050049$ignore{'"address-family ipv6 (unicast|multicast)"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000050$ignore{'"address-family vpnv4"'} = "ignore";
51$ignore{'"address-family vpnv4 unicast"'} = "ignore";
52$ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
Lou Bergera3fda882016-01-12 13:42:04 -050053$ignore{'"address-family encap"'} = "ignore";
54$ignore{'"address-family encapv4"'} = "ignore";
55$ignore{'"address-family encapv6"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000056$ignore{'"exit-address-family"'} = "ignore";
57$ignore{'"key chain WORD"'} = "ignore";
58$ignore{'"key <0-2147483647>"'} = "ignore";
59$ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
60$ignore{'"show route-map"'} = "ignore";
hassoe7168df2004-10-03 20:11:32 +000061$ignore{'"line vty"'} = "ignore";
62$ignore{'"who"'} = "ignore";
63$ignore{'"terminal monitor"'} = "ignore";
64$ignore{'"terminal no monitor"'} = "ignore";
65$ignore{'"show history"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000066
Donald Sharpb1891fb2015-06-09 20:22:42 -040067my $cli_stomp = 0;
68
paul718e3742002-12-13 20:15:29 +000069foreach (@ARGV) {
70 $file = $_;
71
Serj Kalicheved6e2972012-09-07 13:29:42 +040072 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 |");
paul718e3742002-12-13 20:15:29 +000073 local $/; undef $/;
74 $line = <FH>;
75 close (FH);
76
77 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
Ang Way Chuang0b42c702012-01-27 20:52:27 +040078 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
paul718e3742002-12-13 20:15:29 +000079
paul718e3742002-12-13 20:15:29 +000080 # DEFUN process
81 foreach (@defun) {
82 my (@defun_array);
83 @defun_array = split (/,/);
84 $defun_array[0] = '';
85
86
87 # Actual input command string.
88 $str = "$defun_array[2]";
89 $str =~ s/^\s+//g;
90 $str =~ s/\s+$//g;
91
92 # Get VTY command structure. This is needed for searching
93 # install_element() command.
94 $cmd = "$defun_array[1]";
95 $cmd =~ s/^\s+//g;
96 $cmd =~ s/\s+$//g;
97
paul68980082003-03-25 05:07:42 +000098 # $protocol is VTYSH_PROTO format for redirection of user input
Joakim Tjernlund844ee102013-02-23 19:38:37 +010099 if ($file =~ /lib\/keychain\.c$/) {
100 $protocol = "VTYSH_RIPD";
101 }
102 elsif ($file =~ /lib\/routemap\.c$/) {
103 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
104 }
105 elsif ($file =~ /lib\/filter\.c$/) {
106 $protocol = "VTYSH_ALL";
107 }
Feng Lu55cfa2f2014-07-03 18:24:34 +0800108 elsif ($file =~ /lib\/vrf\.c$/) {
109 $protocol = "VTYSH_ZEBRA";
110 }
Joakim Tjernlund844ee102013-02-23 19:38:37 +0100111 elsif ($file =~ /lib\/plist\.c$/) {
112 if ($defun_array[1] =~ m/ipv6/) {
113 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
114 } else {
115 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
116 }
117 }
118 elsif ($file =~ /lib\/distribute\.c$/) {
119 if ($defun_array[1] =~ m/ipv6/) {
120 $protocol = "VTYSH_RIPNGD";
121 } else {
122 $protocol = "VTYSH_RIPD";
123 }
124 }
125 elsif ($file =~ /lib\/if_rmap\.c$/) {
126 if ($defun_array[1] =~ m/ipv6/) {
127 $protocol = "VTYSH_RIPNGD";
128 } else {
129 $protocol = "VTYSH_RIPD";
130 }
131 }
132 elsif ($file =~ /lib\/vty\.c$/) {
133 $protocol = "VTYSH_ALL";
134 }
135 else {
paul0e82d0e2004-09-13 05:00:18 +0000136 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
paul68980082003-03-25 05:07:42 +0000137 $protocol = "VTYSH_" . uc $protocol;
138 }
139
paul718e3742002-12-13 20:15:29 +0000140 # Append _vtysh to structure then build DEFUN again
141 $defun_array[1] = $cmd . "_vtysh";
142 $defun_body = join (", ", @defun_array);
143
144 # $cmd -> $str hash for lookup
Donald Sharpb1891fb2015-06-09 20:22:42 -0400145 if (exists($cmd2str{$cmd})) {
146 warn "Duplicate CLI Function: $cmd\n";
147 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
148 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
149 $cli_stomp++;
150 }
paul718e3742002-12-13 20:15:29 +0000151 $cmd2str{$cmd} = $str;
152 $cmd2defun{$cmd} = $defun_body;
153 $cmd2proto{$cmd} = $protocol;
154 }
155
156 # install_element() process
157 foreach (@install) {
158 my (@element_array);
159 @element_array = split (/,/);
160
161 # Install node
162 $enode = $element_array[0];
163 $enode =~ s/^\s+//g;
164 $enode =~ s/\s+$//g;
165 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
166
167 # VTY command structure.
168 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
169 $ecmd =~ s/^\s+//g;
170 $ecmd =~ s/\s+$//g;
171
172 # Register $ecmd
173 if (defined ($cmd2str{$ecmd})
174 && ! defined ($ignore{$cmd2str{$ecmd}})) {
175 my ($key);
176 $key = $enode . "," . $cmd2str{$ecmd};
177 $ocmd{$key} = $ecmd;
178 $odefun{$key} = $cmd2defun{$ecmd};
179 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
180 }
181 }
182}
183
Christian Frankeacf98652015-11-12 14:24:22 +0100184my $bad_cli_stomps = 89;
Donald Sharpb1891fb2015-06-09 20:22:42 -0400185# Currently we have $bad_cli_stomps. This was determined by
186# running this script and counting up the collisions from what
187# was returned.
188#
189# When we have cli commands that map to the same function name, we
190# can introduce subtle bugs due to code not being called when
191# we think it is.
192#
193# If extract.pl fails with a error message and you've been
194# modifying the cli, then go back and fix your code to
195# not have cli command function collisions.
196#
197# If you've removed a cli overwrite, you can safely subtract
198# one from $bad_cli_stomps. If you've added to the problem
199# please fix your code before submittal
200if ($cli_stomp != $bad_cli_stomps) {
201 warn "Expected $bad_cli_stomps command line stomps, but got $cli_stomp instead\n";
202 exit $cli_stomp;
203}
204
paul718e3742002-12-13 20:15:29 +0000205# Check finaly alive $cmd;
206foreach (keys %odefun) {
207 my ($node, $str) = (split (/,/));
208 my ($cmd) = $ocmd{$_};
209 $live{$cmd} = $_;
210}
211
212# Output DEFSH
213foreach (keys %live) {
214 my ($proto);
215 my ($key);
216 $key = $live{$_};
217 $proto = join ("|", @{$oproto{$key}});
218 printf "DEFSH ($proto$odefun{$key})\n\n";
219}
220
221# Output install_element
222print <<EOF;
223void
224vtysh_init_cmd ()
225{
226EOF
227
228foreach (keys %odefun) {
229 my ($node, $str) = (split (/,/));
230 $cmd = $ocmd{$_};
231 $cmd =~ s/_cmd/_cmd_vtysh/;
232 printf " install_element ($node, &$cmd);\n";
233}
234
235print <<EOF
236}
237EOF