gdt | fc9d074 | 2004-06-30 14:25:12 +0000 | [diff] [blame] | 1 | #! @PERL@ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2 | ## |
paul | b63dc1f | 2004-09-13 12:59:08 +0000 | [diff] [blame] | 3 | ## @configure_input@ |
| 4 | ## |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | #include "command.h" |
| 29 | #include "vtysh.h" |
| 30 | |
| 31 | EOF |
| 32 | |
| 33 | $ignore{'"interface IFNAME"'} = "ignore"; |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 34 | $ignore{'"interface IFNAME " "vrf <0-65535>"'} = "ignore"; |
Olivier Dugeon | ac10d30 | 2016-04-19 18:33:42 +0200 | [diff] [blame] | 35 | $ignore{'"link-params"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | $ignore{'"ip vrf NAME"'} = "ignore"; |
| 37 | $ignore{'"router rip"'} = "ignore"; |
| 38 | $ignore{'"router ripng"'} = "ignore"; |
| 39 | $ignore{'"router ospf"'} = "ignore"; |
| 40 | $ignore{'"router ospf <0-65535>"'} = "ignore"; |
| 41 | $ignore{'"router ospf6"'} = "ignore"; |
Paul Jakma | 10895fd | 2008-07-03 19:34:48 +0000 | [diff] [blame] | 42 | $ignore{'"router bgp " "<1-4294967295>"'} = "ignore"; |
| 43 | $ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore"; |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 44 | $ignore{'"router isis WORD"'} = "ignore"; |
hasso | 528bed4 | 2005-04-07 18:42:09 +0000 | [diff] [blame] | 45 | $ignore{'"router zebra"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | $ignore{'"address-family ipv4"'} = "ignore"; |
| 47 | $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore"; |
| 48 | $ignore{'"address-family ipv6"'} = "ignore"; |
vivek | a4f4029 | 2015-11-09 20:21:46 -0500 | [diff] [blame] | 49 | $ignore{'"address-family ipv6 (unicast|multicast)"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 50 | $ignore{'"address-family vpnv4"'} = "ignore"; |
| 51 | $ignore{'"address-family vpnv4 unicast"'} = "ignore"; |
| 52 | $ignore{'"address-family ipv4 vrf NAME"'} = "ignore"; |
Lou Berger | a3fda88 | 2016-01-12 13:42:04 -0500 | [diff] [blame] | 53 | $ignore{'"address-family encap"'} = "ignore"; |
| 54 | $ignore{'"address-family encapv4"'} = "ignore"; |
| 55 | $ignore{'"address-family encapv6"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 56 | $ignore{'"exit-address-family"'} = "ignore"; |
Donald Sharp | 2c0adbf | 2016-11-18 15:42:41 -0500 | [diff] [blame] | 57 | $ignore{'"exit-link-params"'} = "ignore"; |
| 58 | $ignore{'"vnc defaults"'} = "ignore"; |
| 59 | $ignore{'"vnc nve-group NAME"'} = "ignore"; |
| 60 | $ignore{'"exit-vnc"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 61 | $ignore{'"key chain WORD"'} = "ignore"; |
| 62 | $ignore{'"key <0-2147483647>"'} = "ignore"; |
| 63 | $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore"; |
| 64 | $ignore{'"show route-map"'} = "ignore"; |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 65 | $ignore{'"line vty"'} = "ignore"; |
| 66 | $ignore{'"who"'} = "ignore"; |
| 67 | $ignore{'"terminal monitor"'} = "ignore"; |
| 68 | $ignore{'"terminal no monitor"'} = "ignore"; |
| 69 | $ignore{'"show history"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 70 | |
Donald Sharp | b1891fb | 2015-06-09 20:22:42 -0400 | [diff] [blame] | 71 | my $cli_stomp = 0; |
| 72 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | foreach (@ARGV) { |
| 74 | $file = $_; |
| 75 | |
Serj Kalichev | ed6e297 | 2012-09-07 13:29:42 +0400 | [diff] [blame] | 76 | 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 |"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 77 | local $/; undef $/; |
| 78 | $line = <FH>; |
| 79 | close (FH); |
| 80 | |
| 81 | @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg); |
Ang Way Chuang | 0b42c70 | 2012-01-27 20:52:27 +0400 | [diff] [blame] | 82 | @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 83 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | # DEFUN process |
| 85 | foreach (@defun) { |
| 86 | my (@defun_array); |
| 87 | @defun_array = split (/,/); |
| 88 | $defun_array[0] = ''; |
| 89 | |
| 90 | |
| 91 | # Actual input command string. |
| 92 | $str = "$defun_array[2]"; |
| 93 | $str =~ s/^\s+//g; |
| 94 | $str =~ s/\s+$//g; |
| 95 | |
| 96 | # Get VTY command structure. This is needed for searching |
| 97 | # install_element() command. |
| 98 | $cmd = "$defun_array[1]"; |
| 99 | $cmd =~ s/^\s+//g; |
| 100 | $cmd =~ s/\s+$//g; |
| 101 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 102 | # $protocol is VTYSH_PROTO format for redirection of user input |
Joakim Tjernlund | 844ee10 | 2013-02-23 19:38:37 +0100 | [diff] [blame] | 103 | if ($file =~ /lib\/keychain\.c$/) { |
| 104 | $protocol = "VTYSH_RIPD"; |
| 105 | } |
| 106 | elsif ($file =~ /lib\/routemap\.c$/) { |
| 107 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; |
| 108 | } |
| 109 | elsif ($file =~ /lib\/filter\.c$/) { |
| 110 | $protocol = "VTYSH_ALL"; |
| 111 | } |
Feng Lu | 55cfa2f | 2014-07-03 18:24:34 +0800 | [diff] [blame] | 112 | elsif ($file =~ /lib\/vrf\.c$/) { |
| 113 | $protocol = "VTYSH_ZEBRA"; |
| 114 | } |
Joakim Tjernlund | 844ee10 | 2013-02-23 19:38:37 +0100 | [diff] [blame] | 115 | elsif ($file =~ /lib\/plist\.c$/) { |
| 116 | if ($defun_array[1] =~ m/ipv6/) { |
| 117 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; |
| 118 | } else { |
| 119 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA"; |
| 120 | } |
| 121 | } |
| 122 | elsif ($file =~ /lib\/distribute\.c$/) { |
| 123 | if ($defun_array[1] =~ m/ipv6/) { |
| 124 | $protocol = "VTYSH_RIPNGD"; |
| 125 | } else { |
| 126 | $protocol = "VTYSH_RIPD"; |
| 127 | } |
| 128 | } |
| 129 | elsif ($file =~ /lib\/if_rmap\.c$/) { |
| 130 | if ($defun_array[1] =~ m/ipv6/) { |
| 131 | $protocol = "VTYSH_RIPNGD"; |
| 132 | } else { |
| 133 | $protocol = "VTYSH_RIPD"; |
| 134 | } |
| 135 | } |
| 136 | elsif ($file =~ /lib\/vty\.c$/) { |
| 137 | $protocol = "VTYSH_ALL"; |
| 138 | } |
| 139 | else { |
paul | 0e82d0e | 2004-09-13 05:00:18 +0000 | [diff] [blame] | 140 | ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 141 | $protocol = "VTYSH_" . uc $protocol; |
| 142 | } |
| 143 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | # Append _vtysh to structure then build DEFUN again |
| 145 | $defun_array[1] = $cmd . "_vtysh"; |
| 146 | $defun_body = join (", ", @defun_array); |
| 147 | |
| 148 | # $cmd -> $str hash for lookup |
Donald Sharp | b1891fb | 2015-06-09 20:22:42 -0400 | [diff] [blame] | 149 | if (exists($cmd2str{$cmd})) { |
| 150 | warn "Duplicate CLI Function: $cmd\n"; |
| 151 | warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n"; |
| 152 | warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n"; |
| 153 | $cli_stomp++; |
| 154 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | $cmd2str{$cmd} = $str; |
| 156 | $cmd2defun{$cmd} = $defun_body; |
| 157 | $cmd2proto{$cmd} = $protocol; |
| 158 | } |
| 159 | |
| 160 | # install_element() process |
| 161 | foreach (@install) { |
| 162 | my (@element_array); |
| 163 | @element_array = split (/,/); |
| 164 | |
| 165 | # Install node |
| 166 | $enode = $element_array[0]; |
| 167 | $enode =~ s/^\s+//g; |
| 168 | $enode =~ s/\s+$//g; |
| 169 | ($enode) = ($enode =~ /([0-9A-Z_]+)$/); |
| 170 | |
| 171 | # VTY command structure. |
| 172 | ($ecmd) = ($element_array[1] =~ /&([^\)]+)/); |
| 173 | $ecmd =~ s/^\s+//g; |
| 174 | $ecmd =~ s/\s+$//g; |
| 175 | |
| 176 | # Register $ecmd |
| 177 | if (defined ($cmd2str{$ecmd}) |
| 178 | && ! defined ($ignore{$cmd2str{$ecmd}})) { |
| 179 | my ($key); |
| 180 | $key = $enode . "," . $cmd2str{$ecmd}; |
| 181 | $ocmd{$key} = $ecmd; |
| 182 | $odefun{$key} = $cmd2defun{$ecmd}; |
| 183 | push (@{$oproto{$key}}, $cmd2proto{$ecmd}); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
Piotr Chytła | 605aa33 | 2015-12-01 10:03:54 -0500 | [diff] [blame] | 188 | my $bad_cli_stomps = 102; |
Donald Sharp | b1891fb | 2015-06-09 20:22:42 -0400 | [diff] [blame] | 189 | # Currently we have $bad_cli_stomps. This was determined by |
| 190 | # running this script and counting up the collisions from what |
| 191 | # was returned. |
| 192 | # |
| 193 | # When we have cli commands that map to the same function name, we |
| 194 | # can introduce subtle bugs due to code not being called when |
| 195 | # we think it is. |
| 196 | # |
| 197 | # If extract.pl fails with a error message and you've been |
| 198 | # modifying the cli, then go back and fix your code to |
| 199 | # not have cli command function collisions. |
| 200 | # |
| 201 | # If you've removed a cli overwrite, you can safely subtract |
| 202 | # one from $bad_cli_stomps. If you've added to the problem |
| 203 | # please fix your code before submittal |
| 204 | if ($cli_stomp != $bad_cli_stomps) { |
| 205 | warn "Expected $bad_cli_stomps command line stomps, but got $cli_stomp instead\n"; |
| 206 | exit $cli_stomp; |
| 207 | } |
| 208 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | # Check finaly alive $cmd; |
| 210 | foreach (keys %odefun) { |
| 211 | my ($node, $str) = (split (/,/)); |
| 212 | my ($cmd) = $ocmd{$_}; |
| 213 | $live{$cmd} = $_; |
| 214 | } |
| 215 | |
| 216 | # Output DEFSH |
| 217 | foreach (keys %live) { |
| 218 | my ($proto); |
| 219 | my ($key); |
| 220 | $key = $live{$_}; |
| 221 | $proto = join ("|", @{$oproto{$key}}); |
| 222 | printf "DEFSH ($proto$odefun{$key})\n\n"; |
| 223 | } |
| 224 | |
| 225 | # Output install_element |
| 226 | print <<EOF; |
| 227 | void |
Daniel Walton | 62f936e | 2015-11-09 20:21:59 -0500 | [diff] [blame] | 228 | vtysh_init_cmd (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 229 | { |
| 230 | EOF |
| 231 | |
| 232 | foreach (keys %odefun) { |
| 233 | my ($node, $str) = (split (/,/)); |
| 234 | $cmd = $ocmd{$_}; |
| 235 | $cmd =~ s/_cmd/_cmd_vtysh/; |
| 236 | printf " install_element ($node, &$cmd);\n"; |
| 237 | } |
| 238 | |
| 239 | print <<EOF |
| 240 | } |
| 241 | EOF |