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