blob: 99d80ed4ad60ff5c5436b6598dc22d2b6e980266 [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";
Paul Jakma10895fd2008-07-03 19:34:48 +000040$ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
41$ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
hassoc25e4582003-12-23 10:39:08 +000042$ignore{'"router isis WORD"'} = "ignore";
hasso528bed42005-04-07 18:42:09 +000043$ignore{'"router zebra"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000044$ignore{'"address-family ipv4"'} = "ignore";
45$ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
46$ignore{'"address-family ipv6"'} = "ignore";
47$ignore{'"address-family ipv6 unicast"'} = "ignore";
48$ignore{'"address-family vpnv4"'} = "ignore";
49$ignore{'"address-family vpnv4 unicast"'} = "ignore";
50$ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
51$ignore{'"exit-address-family"'} = "ignore";
52$ignore{'"key chain WORD"'} = "ignore";
53$ignore{'"key <0-2147483647>"'} = "ignore";
54$ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
55$ignore{'"show route-map"'} = "ignore";
hassoe7168df2004-10-03 20:11:32 +000056$ignore{'"line vty"'} = "ignore";
57$ignore{'"who"'} = "ignore";
58$ignore{'"terminal monitor"'} = "ignore";
59$ignore{'"terminal no monitor"'} = "ignore";
60$ignore{'"show history"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000061
62foreach (@ARGV) {
63 $file = $_;
64
Serj Kalicheved6e2972012-09-07 13:29:42 +040065 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 +000066 local $/; undef $/;
67 $line = <FH>;
68 close (FH);
69
70 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
Ang Way Chuang0b42c702012-01-27 20:52:27 +040071 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
paul718e3742002-12-13 20:15:29 +000072
paul718e3742002-12-13 20:15:29 +000073 # DEFUN process
74 foreach (@defun) {
75 my (@defun_array);
76 @defun_array = split (/,/);
77 $defun_array[0] = '';
78
79
80 # Actual input command string.
81 $str = "$defun_array[2]";
82 $str =~ s/^\s+//g;
83 $str =~ s/\s+$//g;
84
85 # Get VTY command structure. This is needed for searching
86 # install_element() command.
87 $cmd = "$defun_array[1]";
88 $cmd =~ s/^\s+//g;
89 $cmd =~ s/\s+$//g;
90
paul68980082003-03-25 05:07:42 +000091 # $protocol is VTYSH_PROTO format for redirection of user input
Joakim Tjernlund844ee102013-02-23 19:38:37 +010092 if ($file =~ /lib\/keychain\.c$/) {
93 $protocol = "VTYSH_RIPD";
94 }
95 elsif ($file =~ /lib\/routemap\.c$/) {
96 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
97 }
98 elsif ($file =~ /lib\/filter\.c$/) {
99 $protocol = "VTYSH_ALL";
100 }
101 elsif ($file =~ /lib\/plist\.c$/) {
102 if ($defun_array[1] =~ m/ipv6/) {
103 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
104 } else {
105 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
106 }
107 }
108 elsif ($file =~ /lib\/distribute\.c$/) {
109 if ($defun_array[1] =~ m/ipv6/) {
110 $protocol = "VTYSH_RIPNGD";
111 } else {
112 $protocol = "VTYSH_RIPD";
113 }
114 }
115 elsif ($file =~ /lib\/if_rmap\.c$/) {
116 if ($defun_array[1] =~ m/ipv6/) {
117 $protocol = "VTYSH_RIPNGD";
118 } else {
119 $protocol = "VTYSH_RIPD";
120 }
121 }
122 elsif ($file =~ /lib\/vty\.c$/) {
123 $protocol = "VTYSH_ALL";
124 }
125 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