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"; |
| 34 | $ignore{'"ip vrf NAME"'} = "ignore"; |
| 35 | $ignore{'"router rip"'} = "ignore"; |
| 36 | $ignore{'"router ripng"'} = "ignore"; |
| 37 | $ignore{'"router ospf"'} = "ignore"; |
| 38 | $ignore{'"router ospf <0-65535>"'} = "ignore"; |
| 39 | $ignore{'"router ospf6"'} = "ignore"; |
Paul Jakma | 10895fd | 2008-07-03 19:34:48 +0000 | [diff] [blame] | 40 | $ignore{'"router bgp " "<1-4294967295>"'} = "ignore"; |
| 41 | $ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore"; |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 42 | $ignore{'"router isis WORD"'} = "ignore"; |
hasso | 528bed4 | 2005-04-07 18:42:09 +0000 | [diff] [blame] | 43 | $ignore{'"router zebra"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 44 | $ignore{'"address-family ipv4"'} = "ignore"; |
| 45 | $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore"; |
| 46 | $ignore{'"address-family ipv6"'} = "ignore"; |
| 47 | $ignore{'"address-family ipv6 unicast"'} = "ignore"; |
| 48 | $ignore{'"address-family vpnv4"'} = "ignore"; |
| 49 | $ignore{'"address-family vpnv4 unicast"'} = "ignore"; |
| 50 | $ignore{'"address-family ipv4 vrf NAME"'} = "ignore"; |
| 51 | $ignore{'"exit-address-family"'} = "ignore"; |
| 52 | $ignore{'"key chain WORD"'} = "ignore"; |
| 53 | $ignore{'"key <0-2147483647>"'} = "ignore"; |
| 54 | $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore"; |
| 55 | $ignore{'"show route-map"'} = "ignore"; |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 56 | $ignore{'"line vty"'} = "ignore"; |
| 57 | $ignore{'"who"'} = "ignore"; |
| 58 | $ignore{'"terminal monitor"'} = "ignore"; |
| 59 | $ignore{'"terminal no monitor"'} = "ignore"; |
| 60 | $ignore{'"show history"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 61 | |
| 62 | foreach (@ARGV) { |
| 63 | $file = $_; |
| 64 | |
Serj Kalichev | ed6e297 | 2012-09-07 13:29:42 +0400 | [diff] [blame] | 65 | 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] | 66 | local $/; undef $/; |
| 67 | $line = <FH>; |
| 68 | close (FH); |
| 69 | |
| 70 | @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg); |
Ang Way Chuang | 0b42c70 | 2012-01-27 20:52:27 +0400 | [diff] [blame] | 71 | @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | # DEFUN process |
| 74 | foreach (@defun) { |
| 75 | my (@defun_array); |
| 76 | @defun_array = split (/,/); |
| 77 | $defun_array[0] = ''; |
| 78 | |
| 79 | |
| 80 | # Actual input command string. |
| 81 | $str = "$defun_array[2]"; |
| 82 | $str =~ s/^\s+//g; |
| 83 | $str =~ s/\s+$//g; |
| 84 | |
| 85 | # Get VTY command structure. This is needed for searching |
| 86 | # install_element() command. |
| 87 | $cmd = "$defun_array[1]"; |
| 88 | $cmd =~ s/^\s+//g; |
| 89 | $cmd =~ s/\s+$//g; |
| 90 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 91 | # $protocol is VTYSH_PROTO format for redirection of user input |
Joakim Tjernlund | 844ee10 | 2013-02-23 19:38:37 +0100 | [diff] [blame] | 92 | if ($file =~ /lib\/keychain\.c$/) { |
| 93 | $protocol = "VTYSH_RIPD"; |
| 94 | } |
| 95 | elsif ($file =~ /lib\/routemap\.c$/) { |
| 96 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; |
| 97 | } |
| 98 | elsif ($file =~ /lib\/filter\.c$/) { |
| 99 | $protocol = "VTYSH_ALL"; |
| 100 | } |
| 101 | elsif ($file =~ /lib\/plist\.c$/) { |
| 102 | if ($defun_array[1] =~ m/ipv6/) { |
| 103 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; |
| 104 | } else { |
| 105 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA"; |
| 106 | } |
| 107 | } |
| 108 | elsif ($file =~ /lib\/distribute\.c$/) { |
| 109 | if ($defun_array[1] =~ m/ipv6/) { |
| 110 | $protocol = "VTYSH_RIPNGD"; |
| 111 | } else { |
| 112 | $protocol = "VTYSH_RIPD"; |
| 113 | } |
| 114 | } |
| 115 | elsif ($file =~ /lib\/if_rmap\.c$/) { |
| 116 | if ($defun_array[1] =~ m/ipv6/) { |
| 117 | $protocol = "VTYSH_RIPNGD"; |
| 118 | } else { |
| 119 | $protocol = "VTYSH_RIPD"; |
| 120 | } |
| 121 | } |
| 122 | elsif ($file =~ /lib\/vty\.c$/) { |
| 123 | $protocol = "VTYSH_ALL"; |
| 124 | } |
| 125 | else { |
paul | 0e82d0e | 2004-09-13 05:00:18 +0000 | [diff] [blame] | 126 | ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 127 | $protocol = "VTYSH_" . uc $protocol; |
| 128 | } |
| 129 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | # Append _vtysh to structure then build DEFUN again |
| 131 | $defun_array[1] = $cmd . "_vtysh"; |
| 132 | $defun_body = join (", ", @defun_array); |
| 133 | |
| 134 | # $cmd -> $str hash for lookup |
| 135 | $cmd2str{$cmd} = $str; |
| 136 | $cmd2defun{$cmd} = $defun_body; |
| 137 | $cmd2proto{$cmd} = $protocol; |
| 138 | } |
| 139 | |
| 140 | # install_element() process |
| 141 | foreach (@install) { |
| 142 | my (@element_array); |
| 143 | @element_array = split (/,/); |
| 144 | |
| 145 | # Install node |
| 146 | $enode = $element_array[0]; |
| 147 | $enode =~ s/^\s+//g; |
| 148 | $enode =~ s/\s+$//g; |
| 149 | ($enode) = ($enode =~ /([0-9A-Z_]+)$/); |
| 150 | |
| 151 | # VTY command structure. |
| 152 | ($ecmd) = ($element_array[1] =~ /&([^\)]+)/); |
| 153 | $ecmd =~ s/^\s+//g; |
| 154 | $ecmd =~ s/\s+$//g; |
| 155 | |
| 156 | # Register $ecmd |
| 157 | if (defined ($cmd2str{$ecmd}) |
| 158 | && ! defined ($ignore{$cmd2str{$ecmd}})) { |
| 159 | my ($key); |
| 160 | $key = $enode . "," . $cmd2str{$ecmd}; |
| 161 | $ocmd{$key} = $ecmd; |
| 162 | $odefun{$key} = $cmd2defun{$ecmd}; |
| 163 | push (@{$oproto{$key}}, $cmd2proto{$ecmd}); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | # Check finaly alive $cmd; |
| 169 | foreach (keys %odefun) { |
| 170 | my ($node, $str) = (split (/,/)); |
| 171 | my ($cmd) = $ocmd{$_}; |
| 172 | $live{$cmd} = $_; |
| 173 | } |
| 174 | |
| 175 | # Output DEFSH |
| 176 | foreach (keys %live) { |
| 177 | my ($proto); |
| 178 | my ($key); |
| 179 | $key = $live{$_}; |
| 180 | $proto = join ("|", @{$oproto{$key}}); |
| 181 | printf "DEFSH ($proto$odefun{$key})\n\n"; |
| 182 | } |
| 183 | |
| 184 | # Output install_element |
| 185 | print <<EOF; |
| 186 | void |
| 187 | vtysh_init_cmd () |
| 188 | { |
| 189 | EOF |
| 190 | |
| 191 | foreach (keys %odefun) { |
| 192 | my ($node, $str) = (split (/,/)); |
| 193 | $cmd = $ocmd{$_}; |
| 194 | $cmd =~ s/_cmd/_cmd_vtysh/; |
| 195 | printf " install_element ($node, &$cmd);\n"; |
| 196 | } |
| 197 | |
| 198 | print <<EOF |
| 199 | } |
| 200 | EOF |