]>
Commit | Line | Data |
---|---|---|
fc9d0745 | 1 | #! @PERL@ |
718e3744 | 2 | ## |
b63dc1f3 | 3 | ## @configure_input@ |
4 | ## | |
718e3744 | 5 | ## 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 | ||
26 | print <<EOF; | |
27 | #include <zebra.h> | |
988225dd | 28 | |
718e3744 | 29 | #include "command.h" |
988225dd DL |
30 | #include "linklist.h" |
31 | ||
718e3744 | 32 | #include "vtysh.h" |
33 | ||
34 | EOF | |
35 | ||
36 | $ignore{'"interface IFNAME"'} = "ignore"; | |
cd2a8a42 | 37 | $ignore{'"interface IFNAME " "vrf <0-65535>"'} = "ignore"; |
e9d94ea7 | 38 | $ignore{'"interface IFNAME " "vrf NAME"'} = "ignore"; |
16f1b9ee | 39 | $ignore{'"link-params"'} = "ignore"; |
e9d94ea7 | 40 | $ignore{'"vrf NAME"'} = "ignore"; |
718e3744 | 41 | $ignore{'"ip vrf NAME"'} = "ignore"; |
42 | $ignore{'"router rip"'} = "ignore"; | |
43 | $ignore{'"router ripng"'} = "ignore"; | |
44 | $ignore{'"router ospf"'} = "ignore"; | |
7c8ff89e | 45 | $ignore{'"router ospf <1-65535>"'} = "ignore"; |
718e3744 | 46 | $ignore{'"router ospf6"'} = "ignore"; |
4fcbf6e2 RW |
47 | $ignore{'"mpls ldp"'} = "ignore"; |
48 | $ignore{'"l2vpn WORD type vpls"'} = "ignore"; | |
49 | $ignore{'"member pseudowire IFNAME"'} = "ignore"; | |
2385a876 | 50 | $ignore{'"router bgp"'} = "ignore"; |
10895fd6 | 51 | $ignore{'"router bgp " "<1-4294967295>"'} = "ignore"; |
e9d94ea7 | 52 | $ignore{'"router bgp " "<1-4294967295>" " (view|vrf) WORD"'} = "ignore"; |
c25e458a | 53 | $ignore{'"router isis WORD"'} = "ignore"; |
528bed4a | 54 | $ignore{'"router zebra"'} = "ignore"; |
718e3744 | 55 | $ignore{'"address-family ipv4"'} = "ignore"; |
56 | $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore"; | |
57 | $ignore{'"address-family ipv6"'} = "ignore"; | |
01a2af45 | 58 | $ignore{'"address-family ipv6 (unicast|multicast)"'} = "ignore"; |
718e3744 | 59 | $ignore{'"address-family vpnv4"'} = "ignore"; |
60 | $ignore{'"address-family vpnv4 unicast"'} = "ignore"; | |
61 | $ignore{'"address-family ipv4 vrf NAME"'} = "ignore"; | |
8b1fb8be LB |
62 | $ignore{'"address-family encap"'} = "ignore"; |
63 | $ignore{'"address-family encapv4"'} = "ignore"; | |
64 | $ignore{'"address-family encapv6"'} = "ignore"; | |
df08c28e SK |
65 | $ignore{'"address-family vpnv6"'} = "ignore"; |
66 | $ignore{'"address-family vpnv6 unicast"'} = "ignore"; | |
718e3744 | 67 | $ignore{'"exit-address-family"'} = "ignore"; |
65efcfce LB |
68 | $ignore{'"vnc defaults"'} = "ignore"; |
69 | $ignore{'"vnc nve-group NAME"'} = "ignore"; | |
70 | $ignore{'"exit-vnc"'} = "ignore"; | |
718e3744 | 71 | $ignore{'"key chain WORD"'} = "ignore"; |
72 | $ignore{'"key <0-2147483647>"'} = "ignore"; | |
73 | $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore"; | |
74 | $ignore{'"show route-map"'} = "ignore"; | |
e7168df4 | 75 | $ignore{'"line vty"'} = "ignore"; |
76 | $ignore{'"who"'} = "ignore"; | |
77 | $ignore{'"terminal monitor"'} = "ignore"; | |
78 | $ignore{'"terminal no monitor"'} = "ignore"; | |
79 | $ignore{'"show history"'} = "ignore"; | |
718e3744 | 80 | |
b623cda4 DS |
81 | my $cli_stomp = 0; |
82 | ||
718e3744 | 83 | foreach (@ARGV) { |
84 | $file = $_; | |
85 | ||
65efcfce | 86 | 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 -I@top_srcdir@/bgpd -I@top_srcdir@/@LIBRFP@ -I@top_srcdir@/bgpd/rfapi @CPPFLAGS@ $file |"); |
718e3744 | 87 | local $/; undef $/; |
88 | $line = <FH>; | |
89 | close (FH); | |
90 | ||
abaaab4e DW |
91 | # ?: makes a group non-capturing |
92 | @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg); | |
0b42c708 | 93 | @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg); |
718e3744 | 94 | |
718e3744 | 95 | # DEFUN process |
96 | foreach (@defun) { | |
abaaab4e DW |
97 | # $_ will contain the entire string including the DEFUN, ALIAS, etc. |
98 | # We need to extract the DEFUN/ALIAS from everything in ()s. | |
99 | # The /s at the end tells the regex to allow . to match newlines. | |
8d9e99a6 | 100 | $_ =~ /^(.*?)\s*\((.*)\)$/s; |
abaaab4e DW |
101 | |
102 | my (@defun_array); | |
103 | $defun_or_alias = $1; | |
104 | @defun_array = split (/,/, $2); | |
105 | ||
106 | if ($defun_or_alias =~ /_HIDDEN/) { | |
107 | $hidden = 1; | |
108 | } else { | |
109 | $hidden = 0; | |
110 | } | |
718e3744 | 111 | |
abaaab4e | 112 | $defun_array[0] = ''; |
718e3744 | 113 | |
abaaab4e DW |
114 | # Actual input command string. |
115 | $str = "$defun_array[2]"; | |
116 | $str =~ s/^\s+//g; | |
117 | $str =~ s/\s+$//g; | |
718e3744 | 118 | |
abaaab4e DW |
119 | # Get VTY command structure. This is needed for searching |
120 | # install_element() command. | |
121 | $cmd = "$defun_array[1]"; | |
122 | $cmd =~ s/^\s+//g; | |
123 | $cmd =~ s/\s+$//g; | |
718e3744 | 124 | |
68980084 | 125 | # $protocol is VTYSH_PROTO format for redirection of user input |
844ee104 JT |
126 | if ($file =~ /lib\/keychain\.c$/) { |
127 | $protocol = "VTYSH_RIPD"; | |
128 | } | |
129 | elsif ($file =~ /lib\/routemap\.c$/) { | |
28b0c6b3 | 130 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD"; |
844ee104 | 131 | } |
abaaab4e DW |
132 | elsif ($file =~ /lib\/vrf\.c$/) { |
133 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; | |
134 | } | |
844ee104 JT |
135 | elsif ($file =~ /lib\/filter\.c$/) { |
136 | $protocol = "VTYSH_ALL"; | |
137 | } | |
13460c44 FL |
138 | elsif ($file =~ /lib\/ns\.c$/) { |
139 | $protocol = "VTYSH_ZEBRA"; | |
140 | } | |
844ee104 JT |
141 | elsif ($file =~ /lib\/plist\.c$/) { |
142 | if ($defun_array[1] =~ m/ipv6/) { | |
143 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; | |
144 | } else { | |
28b0c6b3 | 145 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD"; |
844ee104 JT |
146 | } |
147 | } | |
148 | elsif ($file =~ /lib\/distribute\.c$/) { | |
149 | if ($defun_array[1] =~ m/ipv6/) { | |
150 | $protocol = "VTYSH_RIPNGD"; | |
151 | } else { | |
152 | $protocol = "VTYSH_RIPD"; | |
153 | } | |
154 | } | |
155 | elsif ($file =~ /lib\/if_rmap\.c$/) { | |
156 | if ($defun_array[1] =~ m/ipv6/) { | |
157 | $protocol = "VTYSH_RIPNGD"; | |
158 | } else { | |
159 | $protocol = "VTYSH_RIPD"; | |
160 | } | |
161 | } | |
162 | elsif ($file =~ /lib\/vty\.c$/) { | |
163 | $protocol = "VTYSH_ALL"; | |
164 | } | |
65efcfce LB |
165 | elsif ($file =~ /librfp\/.*\.c$/ || $file =~ /rfapi\/.*\.c$/) { |
166 | $protocol = "VTYSH_BGPD"; | |
167 | } | |
168 | else { | |
0e82d0e1 | 169 | ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); |
68980084 | 170 | $protocol = "VTYSH_" . uc $protocol; |
171 | } | |
172 | ||
abaaab4e DW |
173 | # Append _vtysh to structure then build DEFUN again |
174 | $defun_array[1] = $cmd . "_vtysh"; | |
175 | $defun_body = join (", ", @defun_array); | |
718e3744 | 176 | |
b623cda4 DS |
177 | # $cmd -> $str hash for lookup |
178 | if (exists($cmd2str{$cmd})) { | |
179 | warn "Duplicate CLI Function: $cmd\n"; | |
180 | warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n"; | |
181 | warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n"; | |
182 | $cli_stomp++; | |
183 | } | |
abaaab4e DW |
184 | $cmd2str{$cmd} = $str; |
185 | $cmd2defun{$cmd} = $defun_body; | |
186 | $cmd2proto{$cmd} = $protocol; | |
187 | $cmd2hidden{$cmd} = $hidden; | |
718e3744 | 188 | } |
189 | ||
190 | # install_element() process | |
191 | foreach (@install) { | |
abaaab4e DW |
192 | my (@element_array); |
193 | @element_array = split (/,/); | |
194 | ||
195 | # Install node | |
196 | $enode = $element_array[0]; | |
197 | $enode =~ s/^\s+//g; | |
198 | $enode =~ s/\s+$//g; | |
199 | ($enode) = ($enode =~ /([0-9A-Z_]+)$/); | |
200 | ||
201 | # VTY command structure. | |
202 | ($ecmd) = ($element_array[1] =~ /&([^\)]+)/); | |
203 | $ecmd =~ s/^\s+//g; | |
204 | $ecmd =~ s/\s+$//g; | |
205 | ||
206 | # Register $ecmd | |
207 | if (defined ($cmd2str{$ecmd}) | |
208 | && ! defined ($ignore{$cmd2str{$ecmd}})) { | |
209 | my ($key); | |
210 | $key = $enode . "," . $cmd2str{$ecmd}; | |
211 | $ocmd{$key} = $ecmd; | |
212 | $odefun{$key} = $cmd2defun{$ecmd}; | |
213 | ||
214 | if ($cmd2hidden{$ecmd}) { | |
215 | $defsh{$key} = "DEFSH_HIDDEN" | |
216 | } else { | |
217 | $defsh{$key} = "DEFSH" | |
218 | } | |
219 | push (@{$oproto{$key}}, $cmd2proto{$ecmd}); | |
220 | } | |
718e3744 | 221 | } |
222 | } | |
223 | ||
49d41a26 | 224 | my $bad_cli_stomps = 108; |
b623cda4 DS |
225 | # Currently we have $bad_cli_stomps. This was determined by |
226 | # running this script and counting up the collisions from what | |
227 | # was returned. | |
228 | # | |
229 | # When we have cli commands that map to the same function name, we | |
230 | # can introduce subtle bugs due to code not being called when | |
231 | # we think it is. | |
232 | # | |
233 | # If extract.pl fails with a error message and you've been | |
234 | # modifying the cli, then go back and fix your code to | |
235 | # not have cli command function collisions. | |
236 | # | |
237 | # If you've removed a cli overwrite, you can safely subtract | |
238 | # one from $bad_cli_stomps. If you've added to the problem | |
239 | # please fix your code before submittal | |
240 | if ($cli_stomp != $bad_cli_stomps) { | |
241 | warn "Expected $bad_cli_stomps command line stomps, but got $cli_stomp instead\n"; | |
598a7bcb RW |
242 | if ($cli_stomp > $bad_cli_stomps) { |
243 | exit $cli_stomp; | |
244 | } | |
b623cda4 DS |
245 | } |
246 | ||
718e3744 | 247 | # Check finaly alive $cmd; |
248 | foreach (keys %odefun) { | |
249 | my ($node, $str) = (split (/,/)); | |
250 | my ($cmd) = $ocmd{$_}; | |
251 | $live{$cmd} = $_; | |
252 | } | |
253 | ||
254 | # Output DEFSH | |
255 | foreach (keys %live) { | |
256 | my ($proto); | |
257 | my ($key); | |
258 | $key = $live{$_}; | |
259 | $proto = join ("|", @{$oproto{$key}}); | |
abaaab4e | 260 | printf "$defsh{$key} ($proto$odefun{$key})\n\n"; |
718e3744 | 261 | } |
262 | ||
263 | # Output install_element | |
264 | print <<EOF; | |
265 | void | |
266 | vtysh_init_cmd () | |
267 | { | |
268 | EOF | |
269 | ||
270 | foreach (keys %odefun) { | |
271 | my ($node, $str) = (split (/,/)); | |
272 | $cmd = $ocmd{$_}; | |
273 | $cmd =~ s/_cmd/_cmd_vtysh/; | |
274 | printf " install_element ($node, &$cmd);\n"; | |
275 | } | |
276 | ||
277 | print <<EOF | |
278 | } | |
279 | EOF |