]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/extract.pl.in
zebra: Convert socket interface to use `union sockunion`
[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
8b7668ec 32#include "vtysh/vtysh.h"
718e3744 33
34EOF
35
b623cda4
DS
36my $cli_stomp = 0;
37
770ccdf8
CF
38sub scan_file {
39 my ( $file, $fabricd) = @_;
40
41 $cppadd = $fabricd ? "-DFABRICD=1" : "";
718e3744 42
8b7668ec 43 open (FH, "@CPP@ -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -Ivtysh/@top_builddir@ -Ivtysh/@top_srcdir@ -Ivtysh/@top_srcdir@/lib -Ivtysh/@top_builddir@/lib -Ivtysh/@top_srcdir@/bgpd -Ivtysh/@top_srcdir@/bgpd/rfapi @CPPFLAGS@ $cppadd $file |");
718e3744 44 local $/; undef $/;
45 $line = <FH>;
46 close (FH);
47
abaaab4e
DW
48 # ?: makes a group non-capturing
49 @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg);
0b42c708 50 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
718e3744 51
718e3744 52 # DEFUN process
53 foreach (@defun) {
abaaab4e
DW
54 # $_ will contain the entire string including the DEFUN, ALIAS, etc.
55 # We need to extract the DEFUN/ALIAS from everything in ()s.
56 # The /s at the end tells the regex to allow . to match newlines.
8d9e99a6 57 $_ =~ /^(.*?)\s*\((.*)\)$/s;
abaaab4e
DW
58
59 my (@defun_array);
60 $defun_or_alias = $1;
61 @defun_array = split (/,/, $2);
62
63 if ($defun_or_alias =~ /_HIDDEN/) {
64 $hidden = 1;
65 } else {
66 $hidden = 0;
67 }
718e3744 68
abaaab4e 69 $defun_array[0] = '';
718e3744 70
abaaab4e
DW
71 # Actual input command string.
72 $str = "$defun_array[2]";
73 $str =~ s/^\s+//g;
74 $str =~ s/\s+$//g;
718e3744 75
abaaab4e
DW
76 # Get VTY command structure. This is needed for searching
77 # install_element() command.
78 $cmd = "$defun_array[1]";
79 $cmd =~ s/^\s+//g;
80 $cmd =~ s/\s+$//g;
718e3744 81
770ccdf8
CF
82 if ($fabricd) {
83 $cmd = "fabricd_" . $cmd;
84 }
85
68980084 86 # $protocol is VTYSH_PROTO format for redirection of user input
844ee104 87 if ($file =~ /lib\/keychain\.c$/) {
3a3a24c8 88 $protocol = "VTYSH_RIPD|VTYSH_EIGRPD";
844ee104
JT
89 }
90 elsif ($file =~ /lib\/routemap\.c$/) {
1753f727 91 $protocol = "VTYSH_RMAP";
844ee104 92 }
abaaab4e 93 elsif ($file =~ /lib\/vrf\.c$/) {
34c46274 94 $protocol = "VTYSH_VRF";
abaaab4e 95 }
91e5b43a
RW
96 elsif ($file =~ /lib\/if\.c$/) {
97 $protocol = "VTYSH_INTERFACE";
98 }
f5d20fdb
PG
99 elsif ($file =~ /lib\/logicalrouter\.c$/) {
100 $protocol = "VTYSH_ALL";
101 }
844ee104
JT
102 elsif ($file =~ /lib\/filter\.c$/) {
103 $protocol = "VTYSH_ALL";
104 }
62ff928b
DS
105 elsif ($file =~ /lib\/agentx\.c$/) {
106 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
107 }
13460c44
FL
108 elsif ($file =~ /lib\/ns\.c$/) {
109 $protocol = "VTYSH_ZEBRA";
110 }
e5c83d9b
DS
111 elsif ($file =~ /lib\/nexthop_group\.c$/) {
112 $protocol = "VTYSH_PBRD";
113 }
844ee104
JT
114 elsif ($file =~ /lib\/plist\.c$/) {
115 if ($defun_array[1] =~ m/ipv6/) {
770ccdf8 116 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD";
844ee104 117 } else {
770ccdf8 118 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD";
844ee104
JT
119 }
120 }
121 elsif ($file =~ /lib\/distribute\.c$/) {
122 if ($defun_array[1] =~ m/ipv6/) {
123 $protocol = "VTYSH_RIPNGD";
124 } else {
125 $protocol = "VTYSH_RIPD";
126 }
127 }
128 elsif ($file =~ /lib\/if_rmap\.c$/) {
129 if ($defun_array[1] =~ m/ipv6/) {
130 $protocol = "VTYSH_RIPNGD";
131 } else {
132 $protocol = "VTYSH_RIPD";
133 }
134 }
135 elsif ($file =~ /lib\/vty\.c$/) {
136 $protocol = "VTYSH_ALL";
137 }
65efcfce
LB
138 elsif ($file =~ /librfp\/.*\.c$/ || $file =~ /rfapi\/.*\.c$/) {
139 $protocol = "VTYSH_BGPD";
140 }
770ccdf8
CF
141 elsif ($fabricd) {
142 $protocol = "VTYSH_FABRICD";
143 }
abaaab4e 144 else {
0e82d0e1 145 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
68980084 146 $protocol = "VTYSH_" . uc $protocol;
147 }
148
abaaab4e
DW
149 # Append _vtysh to structure then build DEFUN again
150 $defun_array[1] = $cmd . "_vtysh";
151 $defun_body = join (", ", @defun_array);
718e3744 152
b623cda4
DS
153 # $cmd -> $str hash for lookup
154 if (exists($cmd2str{$cmd})) {
155 warn "Duplicate CLI Function: $cmd\n";
156 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
157 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
158 $cli_stomp++;
159 }
abaaab4e
DW
160 $cmd2str{$cmd} = $str;
161 $cmd2defun{$cmd} = $defun_body;
162 $cmd2proto{$cmd} = $protocol;
163 $cmd2hidden{$cmd} = $hidden;
718e3744 164 }
165
166 # install_element() process
167 foreach (@install) {
abaaab4e
DW
168 my (@element_array);
169 @element_array = split (/,/);
170
171 # Install node
172 $enode = $element_array[0];
173 $enode =~ s/^\s+//g;
174 $enode =~ s/\s+$//g;
175 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
176
177 # VTY command structure.
178 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
179 $ecmd =~ s/^\s+//g;
180 $ecmd =~ s/\s+$//g;
181
770ccdf8
CF
182 if ($fabricd) {
183 $ecmd = "fabricd_" . $ecmd;
184 }
185
abaaab4e 186 # Register $ecmd
16807aab 187 if (defined ($cmd2str{$ecmd})) {
abaaab4e
DW
188 my ($key);
189 $key = $enode . "," . $cmd2str{$ecmd};
190 $ocmd{$key} = $ecmd;
191 $odefun{$key} = $cmd2defun{$ecmd};
192
193 if ($cmd2hidden{$ecmd}) {
194 $defsh{$key} = "DEFSH_HIDDEN"
195 } else {
196 $defsh{$key} = "DEFSH"
197 }
198 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
199 }
718e3744 200 }
201}
770ccdf8
CF
202
203foreach (@ARGV) {
770ccdf8 204 if (/\/isisd\//) {
ef020087
CF
205 # We scan all the IS-IS files twice, once for isisd,
206 # once for fabricd. Exceptions are made for the files
207 # that are not shared between the two.
208 if (/isis_vty_isisd.c/) {
209 scan_file($_, 0);
210 } elsif (/isis_vty_fabricd.c/) {
211 scan_file($_, 1);
212 } else {
213 scan_file($_, 0);
214 scan_file($_, 1);
215 }
216 } else {
217 scan_file($_, 0);
770ccdf8
CF
218 }
219}
718e3744 220
b623cda4
DS
221# When we have cli commands that map to the same function name, we
222# can introduce subtle bugs due to code not being called when
223# we think it is.
224#
225# If extract.pl fails with a error message and you've been
226# modifying the cli, then go back and fix your code to
227# not have cli command function collisions.
b623cda4 228# please fix your code before submittal
82f97584
DW
229if ($cli_stomp) {
230 warn "There are $cli_stomp command line stomps\n";
b623cda4
DS
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
74818bb1 241foreach (sort keys %live) {
718e3744 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
74818bb1 256foreach (sort keys %odefun) {
718e3744 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