blob: 444fc9a544b3bbcc10bf5361baac859efe453403 [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";
34$ignore{'"ip vrf NAME"'} = "ignore";
35$ignore{'"router rip"'} = "ignore";
36$ignore{'"router ripng"'} = "ignore";
37$ignore{'"router ospf"'} = "ignore";
38$ignore{'"router ospf <0-65535>"'} = "ignore";
39$ignore{'"router ospf6"'} = "ignore";
40$ignore{'"router bgp <1-65535>"'} = "ignore";
41$ignore{'"router bgp <1-65535> view WORD"'} = "ignore";
hassoc25e4582003-12-23 10:39:08 +000042$ignore{'"router isis WORD"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000043$ignore{'"address-family ipv4"'} = "ignore";
44$ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
45$ignore{'"address-family ipv6"'} = "ignore";
46$ignore{'"address-family ipv6 unicast"'} = "ignore";
47$ignore{'"address-family vpnv4"'} = "ignore";
48$ignore{'"address-family vpnv4 unicast"'} = "ignore";
49$ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
50$ignore{'"exit-address-family"'} = "ignore";
51$ignore{'"key chain WORD"'} = "ignore";
52$ignore{'"key <0-2147483647>"'} = "ignore";
53$ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
54$ignore{'"show route-map"'} = "ignore";
hassoe7168df2004-10-03 20:11:32 +000055$ignore{'"line vty"'} = "ignore";
56$ignore{'"who"'} = "ignore";
57$ignore{'"terminal monitor"'} = "ignore";
58$ignore{'"terminal no monitor"'} = "ignore";
59$ignore{'"show history"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000060
61foreach (@ARGV) {
62 $file = $_;
63
hasso7f223962005-03-28 15:38:16 +000064 open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib @SNMP_INCLUDES@ $file |");
paul718e3742002-12-13 20:15:29 +000065 local $/; undef $/;
66 $line = <FH>;
67 close (FH);
68
69 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
70 @install = ($line =~ /install_element \(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
71
paul718e3742002-12-13 20:15:29 +000072 # DEFUN process
73 foreach (@defun) {
74 my (@defun_array);
75 @defun_array = split (/,/);
76 $defun_array[0] = '';
77
78
79 # Actual input command string.
80 $str = "$defun_array[2]";
81 $str =~ s/^\s+//g;
82 $str =~ s/\s+$//g;
83
84 # Get VTY command structure. This is needed for searching
85 # install_element() command.
86 $cmd = "$defun_array[1]";
87 $cmd =~ s/^\s+//g;
88 $cmd =~ s/\s+$//g;
89
paul68980082003-03-25 05:07:42 +000090 # $protocol is VTYSH_PROTO format for redirection of user input
91 if ($file =~ /lib/) {
92 if ($file =~ /keychain.c/) {
93 $protocol = "VTYSH_RIPD";
94 }
95 if ($file =~ /routemap.c/) {
paul73ffb252003-04-19 15:49:49 +000096 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +000097 }
98 if ($file =~ /filter.c/) {
hasso43fb1352004-10-13 08:47:32 +000099 $protocol = "VTYSH_ALL";
paul68980082003-03-25 05:07:42 +0000100 }
101 if ($file =~ /plist.c/) {
102 if ($defun_array[1] =~ m/ipv6/) {
paula304c1a2003-05-21 17:18:09 +0000103 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000104 } else {
paula304c1a2003-05-21 17:18:09 +0000105 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000106 }
107 }
paulba23a692003-04-19 15:55:08 +0000108 if ($file =~ /distribute.c/) {
109 if ($defun_array[1] =~ m/ipv6/) {
110 $protocol = "VTYSH_RIPNGD";
111 } else {
112 $protocol = "VTYSH_RIPD";
113 }
114 }
hasso0750d212003-05-24 21:41:49 +0000115 if ($file =~ /if_rmap.c/) {
hasso4f849472003-05-25 15:13:49 +0000116 if ($defun_array[1] =~ m/ipv6/) {
117 $protocol = "VTYSH_RIPNGD";
118 } else {
119 $protocol = "VTYSH_RIPD";
120 }
hasso0750d212003-05-24 21:41:49 +0000121 }
hassoe7168df2004-10-03 20:11:32 +0000122 if ($file =~ /vty.c/) {
123 $protocol = "VTYSH_ALL";
124 }
paul68980082003-03-25 05:07:42 +0000125 } else {
paul0e82d0e2004-09-13 05:00:18 +0000126 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
paul68980082003-03-25 05:07:42 +0000127 $protocol = "VTYSH_" . uc $protocol;
128 }
129
paul718e3742002-12-13 20:15:29 +0000130 # Append _vtysh to structure then build DEFUN again
131 $defun_array[1] = $cmd . "_vtysh";
132 $defun_body = join (", ", @defun_array);
133
134 # $cmd -> $str hash for lookup
135 $cmd2str{$cmd} = $str;
136 $cmd2defun{$cmd} = $defun_body;
137 $cmd2proto{$cmd} = $protocol;
138 }
139
140 # install_element() process
141 foreach (@install) {
142 my (@element_array);
143 @element_array = split (/,/);
144
145 # Install node
146 $enode = $element_array[0];
147 $enode =~ s/^\s+//g;
148 $enode =~ s/\s+$//g;
149 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
150
151 # VTY command structure.
152 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
153 $ecmd =~ s/^\s+//g;
154 $ecmd =~ s/\s+$//g;
155
156 # Register $ecmd
157 if (defined ($cmd2str{$ecmd})
158 && ! defined ($ignore{$cmd2str{$ecmd}})) {
159 my ($key);
160 $key = $enode . "," . $cmd2str{$ecmd};
161 $ocmd{$key} = $ecmd;
162 $odefun{$key} = $cmd2defun{$ecmd};
163 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
164 }
165 }
166}
167
168# Check finaly alive $cmd;
169foreach (keys %odefun) {
170 my ($node, $str) = (split (/,/));
171 my ($cmd) = $ocmd{$_};
172 $live{$cmd} = $_;
173}
174
175# Output DEFSH
176foreach (keys %live) {
177 my ($proto);
178 my ($key);
179 $key = $live{$_};
180 $proto = join ("|", @{$oproto{$key}});
181 printf "DEFSH ($proto$odefun{$key})\n\n";
182}
183
184# Output install_element
185print <<EOF;
186void
187vtysh_init_cmd ()
188{
189EOF
190
191foreach (keys %odefun) {
192 my ($node, $str) = (split (/,/));
193 $cmd = $ocmd{$_};
194 $cmd =~ s/_cmd/_cmd_vtysh/;
195 printf " install_element ($node, &$cmd);\n";
196}
197
198print <<EOF
199}
200EOF