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 | |
Dmitrij Tejblum | 566b36e | 2011-09-27 19:27:17 +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_srcdir@/isisd/topology @SNMP_INCLUDES@ @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); |
| 71 | @install = ($line =~ /install_element \(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg); |
| 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 |
| 92 | if ($file =~ /lib/) { |
| 93 | if ($file =~ /keychain.c/) { |
| 94 | $protocol = "VTYSH_RIPD"; |
| 95 | } |
| 96 | if ($file =~ /routemap.c/) { |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 97 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 98 | } |
| 99 | if ($file =~ /filter.c/) { |
hasso | 43fb135 | 2004-10-13 08:47:32 +0000 | [diff] [blame] | 100 | $protocol = "VTYSH_ALL"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 101 | } |
| 102 | if ($file =~ /plist.c/) { |
| 103 | if ($defun_array[1] =~ m/ipv6/) { |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 104 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 105 | } else { |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 106 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
paul | ba23a69 | 2003-04-19 15:55:08 +0000 | [diff] [blame] | 109 | if ($file =~ /distribute.c/) { |
| 110 | if ($defun_array[1] =~ m/ipv6/) { |
| 111 | $protocol = "VTYSH_RIPNGD"; |
| 112 | } else { |
| 113 | $protocol = "VTYSH_RIPD"; |
| 114 | } |
| 115 | } |
hasso | 0750d21 | 2003-05-24 21:41:49 +0000 | [diff] [blame] | 116 | if ($file =~ /if_rmap.c/) { |
hasso | 4f84947 | 2003-05-25 15:13:49 +0000 | [diff] [blame] | 117 | if ($defun_array[1] =~ m/ipv6/) { |
| 118 | $protocol = "VTYSH_RIPNGD"; |
| 119 | } else { |
| 120 | $protocol = "VTYSH_RIPD"; |
| 121 | } |
hasso | 0750d21 | 2003-05-24 21:41:49 +0000 | [diff] [blame] | 122 | } |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 123 | if ($file =~ /vty.c/) { |
| 124 | $protocol = "VTYSH_ALL"; |
| 125 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 126 | } else { |
paul | 0e82d0e | 2004-09-13 05:00:18 +0000 | [diff] [blame] | 127 | ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 128 | $protocol = "VTYSH_" . uc $protocol; |
| 129 | } |
| 130 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 131 | # Append _vtysh to structure then build DEFUN again |
| 132 | $defun_array[1] = $cmd . "_vtysh"; |
| 133 | $defun_body = join (", ", @defun_array); |
| 134 | |
| 135 | # $cmd -> $str hash for lookup |
| 136 | $cmd2str{$cmd} = $str; |
| 137 | $cmd2defun{$cmd} = $defun_body; |
| 138 | $cmd2proto{$cmd} = $protocol; |
| 139 | } |
| 140 | |
| 141 | # install_element() process |
| 142 | foreach (@install) { |
| 143 | my (@element_array); |
| 144 | @element_array = split (/,/); |
| 145 | |
| 146 | # Install node |
| 147 | $enode = $element_array[0]; |
| 148 | $enode =~ s/^\s+//g; |
| 149 | $enode =~ s/\s+$//g; |
| 150 | ($enode) = ($enode =~ /([0-9A-Z_]+)$/); |
| 151 | |
| 152 | # VTY command structure. |
| 153 | ($ecmd) = ($element_array[1] =~ /&([^\)]+)/); |
| 154 | $ecmd =~ s/^\s+//g; |
| 155 | $ecmd =~ s/\s+$//g; |
| 156 | |
| 157 | # Register $ecmd |
| 158 | if (defined ($cmd2str{$ecmd}) |
| 159 | && ! defined ($ignore{$cmd2str{$ecmd}})) { |
| 160 | my ($key); |
| 161 | $key = $enode . "," . $cmd2str{$ecmd}; |
| 162 | $ocmd{$key} = $ecmd; |
| 163 | $odefun{$key} = $cmd2defun{$ecmd}; |
| 164 | push (@{$oproto{$key}}, $cmd2proto{$ecmd}); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | # Check finaly alive $cmd; |
| 170 | foreach (keys %odefun) { |
| 171 | my ($node, $str) = (split (/,/)); |
| 172 | my ($cmd) = $ocmd{$_}; |
| 173 | $live{$cmd} = $_; |
| 174 | } |
| 175 | |
| 176 | # Output DEFSH |
| 177 | foreach (keys %live) { |
| 178 | my ($proto); |
| 179 | my ($key); |
| 180 | $key = $live{$_}; |
| 181 | $proto = join ("|", @{$oproto{$key}}); |
| 182 | printf "DEFSH ($proto$odefun{$key})\n\n"; |
| 183 | } |
| 184 | |
| 185 | # Output install_element |
| 186 | print <<EOF; |
| 187 | void |
| 188 | vtysh_init_cmd () |
| 189 | { |
| 190 | EOF |
| 191 | |
| 192 | foreach (keys %odefun) { |
| 193 | my ($node, $str) = (split (/,/)); |
| 194 | $cmd = $ocmd{$_}; |
| 195 | $cmd =~ s/_cmd/_cmd_vtysh/; |
| 196 | printf " install_element ($node, &$cmd);\n"; |
| 197 | } |
| 198 | |
| 199 | print <<EOF |
| 200 | } |
| 201 | EOF |