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