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