blob: d2fc42ba9cfbcd2f3c250079cb2f77b6ccc5710a [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
paulb63dc1f2004-09-13 12:59:08 +000064 open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib $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/) {
99 if ($defun_array[1] =~ m/ipv6/) {
hasso6c0f9a72004-06-20 09:30:57 +0000100 $protocol = "VTYSH_ZEBRA|VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000101 } else {
hasso6c0f9a72004-06-20 09:30:57 +0000102 $protocol = "VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000103 }
104 }
105 if ($file =~ /plist.c/) {
106 if ($defun_array[1] =~ m/ipv6/) {
paula304c1a2003-05-21 17:18:09 +0000107 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000108 } else {
paula304c1a2003-05-21 17:18:09 +0000109 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000110 }
111 }
paulba23a692003-04-19 15:55:08 +0000112 if ($file =~ /distribute.c/) {
113 if ($defun_array[1] =~ m/ipv6/) {
114 $protocol = "VTYSH_RIPNGD";
115 } else {
116 $protocol = "VTYSH_RIPD";
117 }
118 }
hasso0750d212003-05-24 21:41:49 +0000119 if ($file =~ /if_rmap.c/) {
hasso4f849472003-05-25 15:13:49 +0000120 if ($defun_array[1] =~ m/ipv6/) {
121 $protocol = "VTYSH_RIPNGD";
122 } else {
123 $protocol = "VTYSH_RIPD";
124 }
hasso0750d212003-05-24 21:41:49 +0000125 }
hassoe7168df2004-10-03 20:11:32 +0000126 if ($file =~ /vty.c/) {
127 $protocol = "VTYSH_ALL";
128 }
paul68980082003-03-25 05:07:42 +0000129 } else {
paul0e82d0e2004-09-13 05:00:18 +0000130 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
paul68980082003-03-25 05:07:42 +0000131 $protocol = "VTYSH_" . uc $protocol;
132 }
133
paul718e3742002-12-13 20:15:29 +0000134 # Append _vtysh to structure then build DEFUN again
135 $defun_array[1] = $cmd . "_vtysh";
136 $defun_body = join (", ", @defun_array);
137
138 # $cmd -> $str hash for lookup
139 $cmd2str{$cmd} = $str;
140 $cmd2defun{$cmd} = $defun_body;
141 $cmd2proto{$cmd} = $protocol;
142 }
143
144 # install_element() process
145 foreach (@install) {
146 my (@element_array);
147 @element_array = split (/,/);
148
149 # Install node
150 $enode = $element_array[0];
151 $enode =~ s/^\s+//g;
152 $enode =~ s/\s+$//g;
153 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
154
155 # VTY command structure.
156 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
157 $ecmd =~ s/^\s+//g;
158 $ecmd =~ s/\s+$//g;
159
160 # Register $ecmd
161 if (defined ($cmd2str{$ecmd})
162 && ! defined ($ignore{$cmd2str{$ecmd}})) {
163 my ($key);
164 $key = $enode . "," . $cmd2str{$ecmd};
165 $ocmd{$key} = $ecmd;
166 $odefun{$key} = $cmd2defun{$ecmd};
167 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
168 }
169 }
170}
171
172# Check finaly alive $cmd;
173foreach (keys %odefun) {
174 my ($node, $str) = (split (/,/));
175 my ($cmd) = $ocmd{$_};
176 $live{$cmd} = $_;
177}
178
179# Output DEFSH
180foreach (keys %live) {
181 my ($proto);
182 my ($key);
183 $key = $live{$_};
184 $proto = join ("|", @{$oproto{$key}});
185 printf "DEFSH ($proto$odefun{$key})\n\n";
186}
187
188# Output install_element
189print <<EOF;
190void
191vtysh_init_cmd ()
192{
193EOF
194
195foreach (keys %odefun) {
196 my ($node, $str) = (split (/,/));
197 $cmd = $ocmd{$_};
198 $cmd =~ s/_cmd/_cmd_vtysh/;
199 printf " install_element ($node, &$cmd);\n";
200}
201
202print <<EOF
203}
204EOF