blob: 63186d7383126179098ba3bcd96bc3bd9dd8eb94 [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";
paul718e3742002-12-13 20:15:29 +000035$ignore{'"ip vrf NAME"'} = "ignore";
36$ignore{'"router rip"'} = "ignore";
37$ignore{'"router ripng"'} = "ignore";
38$ignore{'"router ospf"'} = "ignore";
39$ignore{'"router ospf <0-65535>"'} = "ignore";
40$ignore{'"router ospf6"'} = "ignore";
Paul Jakma10895fd2008-07-03 19:34:48 +000041$ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
42$ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
hassoc25e4582003-12-23 10:39:08 +000043$ignore{'"router isis WORD"'} = "ignore";
hasso528bed42005-04-07 18:42:09 +000044$ignore{'"router zebra"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000045$ignore{'"address-family ipv4"'} = "ignore";
46$ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
47$ignore{'"address-family ipv6"'} = "ignore";
48$ignore{'"address-family ipv6 unicast"'} = "ignore";
49$ignore{'"address-family vpnv4"'} = "ignore";
50$ignore{'"address-family vpnv4 unicast"'} = "ignore";
51$ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
52$ignore{'"exit-address-family"'} = "ignore";
53$ignore{'"key chain WORD"'} = "ignore";
54$ignore{'"key <0-2147483647>"'} = "ignore";
55$ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
56$ignore{'"show route-map"'} = "ignore";
hassoe7168df2004-10-03 20:11:32 +000057$ignore{'"line vty"'} = "ignore";
58$ignore{'"who"'} = "ignore";
59$ignore{'"terminal monitor"'} = "ignore";
60$ignore{'"terminal no monitor"'} = "ignore";
61$ignore{'"show history"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000062
Donald Sharpb1891fb2015-06-09 20:22:42 -040063my $cli_stomp = 0;
64
paul718e3742002-12-13 20:15:29 +000065foreach (@ARGV) {
66 $file = $_;
67
Serj Kalicheved6e2972012-09-07 13:29:42 +040068 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 +000069 local $/; undef $/;
70 $line = <FH>;
71 close (FH);
72
73 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
Ang Way Chuang0b42c702012-01-27 20:52:27 +040074 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
paul718e3742002-12-13 20:15:29 +000075
paul718e3742002-12-13 20:15:29 +000076 # DEFUN process
77 foreach (@defun) {
78 my (@defun_array);
79 @defun_array = split (/,/);
80 $defun_array[0] = '';
81
82
83 # Actual input command string.
84 $str = "$defun_array[2]";
85 $str =~ s/^\s+//g;
86 $str =~ s/\s+$//g;
87
88 # Get VTY command structure. This is needed for searching
89 # install_element() command.
90 $cmd = "$defun_array[1]";
91 $cmd =~ s/^\s+//g;
92 $cmd =~ s/\s+$//g;
93
paul68980082003-03-25 05:07:42 +000094 # $protocol is VTYSH_PROTO format for redirection of user input
Joakim Tjernlund844ee102013-02-23 19:38:37 +010095 if ($file =~ /lib\/keychain\.c$/) {
96 $protocol = "VTYSH_RIPD";
97 }
98 elsif ($file =~ /lib\/routemap\.c$/) {
99 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
100 }
101 elsif ($file =~ /lib\/filter\.c$/) {
102 $protocol = "VTYSH_ALL";
103 }
Feng Lu55cfa2f2014-07-03 18:24:34 +0800104 elsif ($file =~ /lib\/vrf\.c$/) {
105 $protocol = "VTYSH_ZEBRA";
106 }
Joakim Tjernlund844ee102013-02-23 19:38:37 +0100107 elsif ($file =~ /lib\/plist\.c$/) {
108 if ($defun_array[1] =~ m/ipv6/) {
109 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
110 } else {
111 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
112 }
113 }
114 elsif ($file =~ /lib\/distribute\.c$/) {
115 if ($defun_array[1] =~ m/ipv6/) {
116 $protocol = "VTYSH_RIPNGD";
117 } else {
118 $protocol = "VTYSH_RIPD";
119 }
120 }
121 elsif ($file =~ /lib\/if_rmap\.c$/) {
122 if ($defun_array[1] =~ m/ipv6/) {
123 $protocol = "VTYSH_RIPNGD";
124 } else {
125 $protocol = "VTYSH_RIPD";
126 }
127 }
128 elsif ($file =~ /lib\/vty\.c$/) {
129 $protocol = "VTYSH_ALL";
130 }
131 else {
paul0e82d0e2004-09-13 05:00:18 +0000132 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
paul68980082003-03-25 05:07:42 +0000133 $protocol = "VTYSH_" . uc $protocol;
134 }
135
paul718e3742002-12-13 20:15:29 +0000136 # Append _vtysh to structure then build DEFUN again
137 $defun_array[1] = $cmd . "_vtysh";
138 $defun_body = join (", ", @defun_array);
139
140 # $cmd -> $str hash for lookup
Donald Sharpb1891fb2015-06-09 20:22:42 -0400141 if (exists($cmd2str{$cmd})) {
142 warn "Duplicate CLI Function: $cmd\n";
143 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
144 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
145 $cli_stomp++;
146 }
paul718e3742002-12-13 20:15:29 +0000147 $cmd2str{$cmd} = $str;
148 $cmd2defun{$cmd} = $defun_body;
149 $cmd2proto{$cmd} = $protocol;
150 }
151
152 # install_element() process
153 foreach (@install) {
154 my (@element_array);
155 @element_array = split (/,/);
156
157 # Install node
158 $enode = $element_array[0];
159 $enode =~ s/^\s+//g;
160 $enode =~ s/\s+$//g;
161 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
162
163 # VTY command structure.
164 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
165 $ecmd =~ s/^\s+//g;
166 $ecmd =~ s/\s+$//g;
167
168 # Register $ecmd
169 if (defined ($cmd2str{$ecmd})
170 && ! defined ($ignore{$cmd2str{$ecmd}})) {
171 my ($key);
172 $key = $enode . "," . $cmd2str{$ecmd};
173 $ocmd{$key} = $ecmd;
174 $odefun{$key} = $cmd2defun{$ecmd};
175 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
176 }
177 }
178}
179
Paul Jakma60646132015-08-04 17:37:16 +0100180my $bad_cli_stomps = 76;
Donald Sharpb1891fb2015-06-09 20:22:42 -0400181# Currently we have $bad_cli_stomps. This was determined by
182# running this script and counting up the collisions from what
183# was returned.
184#
185# When we have cli commands that map to the same function name, we
186# can introduce subtle bugs due to code not being called when
187# we think it is.
188#
189# If extract.pl fails with a error message and you've been
190# modifying the cli, then go back and fix your code to
191# not have cli command function collisions.
192#
193# If you've removed a cli overwrite, you can safely subtract
194# one from $bad_cli_stomps. If you've added to the problem
195# please fix your code before submittal
196if ($cli_stomp != $bad_cli_stomps) {
197 warn "Expected $bad_cli_stomps command line stomps, but got $cli_stomp instead\n";
198 exit $cli_stomp;
199}
200
paul718e3742002-12-13 20:15:29 +0000201# Check finaly alive $cmd;
202foreach (keys %odefun) {
203 my ($node, $str) = (split (/,/));
204 my ($cmd) = $ocmd{$_};
205 $live{$cmd} = $_;
206}
207
208# Output DEFSH
209foreach (keys %live) {
210 my ($proto);
211 my ($key);
212 $key = $live{$_};
213 $proto = join ("|", @{$oproto{$key}});
214 printf "DEFSH ($proto$odefun{$key})\n\n";
215}
216
217# Output install_element
218print <<EOF;
219void
220vtysh_init_cmd ()
221{
222EOF
223
224foreach (keys %odefun) {
225 my ($node, $str) = (split (/,/));
226 $cmd = $ocmd{$_};
227 $cmd =~ s/_cmd/_cmd_vtysh/;
228 printf " install_element ($node, &$cmd);\n";
229}
230
231print <<EOF
232}
233EOF