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