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