]> git.proxmox.com Git - mirror_frr.git/blob - lib/route_types.pl
"ip protocol" is missing ospf as an option
[mirror_frr.git] / lib / route_types.pl
1 #!/usr/bin/perl
2 ##
3 ## Scan a file of route-type definitions (see eg route_types.txt) and
4 ## generate a corresponding header file with:
5 ##
6 ## - enum of Zserv route-types
7 ## - redistribute strings for the various Quagga daemons
8 ##
9 ## See route_types.txt for the format.
10 ##
11 ##
12 ## Copyright (C) 2009 David Lamparter.
13 ## This file is part of GNU Zebra.
14 ##
15 ## GNU Zebra is free software; you can redistribute it and/or modify it
16 ## under the terms of the GNU General Public License as published by the
17 ## Free Software Foundation; either version 2, or (at your option) any
18 ## later version.
19 ##
20 ## GNU Zebra is distributed in the hope that it will be useful, but
21 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ## General Public License for more details.
24 ##
25 ## You should have received a copy of the GNU General Public License
26 ## along with GNU Zebra; see the file COPYING. If not, write to the Free
27 ## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 ## 02111-1307, USA.
29 ##
30
31 use strict;
32
33 # input processing
34 #
35 my @protos;
36 my %protodetail;
37
38 my %daemons;
39
40 while (<STDIN>) {
41 # skip comments and empty lines
42 next if (/^\s*(#|$)/);
43
44 # strip whitespace
45 chomp;
46 $_ =~ s/^\s*//;
47 $_ =~ s/\s*$//;
48
49 # match help strings
50 if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
51 $protodetail{$1}->{'longhelp'} = $2;
52 next;
53 }
54
55 $_ =~ s/\s*,\s*/,/g;
56
57 # else: 7-field line
58 my @f = split(/,/, $_);
59 unless (@f == 7) {
60 die "invalid input on route_types line $.\n";
61 }
62
63 my $proto = $f[0];
64 $f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
65 $f[6] = $1 if ($f[6] =~ /^"(.*)"$/);
66
67 $protodetail{$proto} = {
68 "number" => scalar @protos,
69 "type" => $f[0],
70 "cname" => $f[1],
71 "daemon" => $f[2],
72 "char" => $f[3],
73 "ipv4" => int($f[4]),
74 "ipv6" => int($f[5]),
75 "shorthelp" => $f[6],
76 };
77 push @protos, $proto;
78 $daemons{$f[2]} = {
79 "ipv4" => int($f[4]),
80 "ipv6" => int($f[5])
81 } unless ($f[2] eq "NULL");
82 }
83
84 # output
85 printf <<EOF, $ARGV[0];
86 /* Auto-generated from route_types.txt by %s. */
87 /* Do not edit! */
88
89 #ifndef _QUAGGA_ROUTE_TYPES_H
90 #define _QUAGGA_ROUTE_TYPES_H
91
92 /* Zebra route's' types. */
93 EOF
94
95 push @protos, "ZEBRA_ROUTE_MAX";
96 my (@protosv4, @protosv6) = ((), ());
97 for (my $c = 0; $c < @protos; $c++) {
98 my $p = $protos[$c];
99 printf "#define %-32s %d\n", $p, $c;
100 push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
101 push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
102 }
103 pop @protos;
104
105 sub codelist {
106 my (@protos) = @_;
107 my (@lines) = ();
108 my $str = " \"Codes: ";
109 for my $p (@protos) {
110 my $s = sprintf("%s - %s, ",
111 $protodetail{$p}->{"char"},
112 $protodetail{$p}->{"shorthelp"});
113 if (length($str . $s) > 70) {
114 $str =~ s/ $//;
115 push @lines, $str . "%s\" \\\n";
116 $str = " \" ";
117 }
118 $str .= $s;
119 }
120 $str =~ s/ $//;
121 push @lines, $str . "%s\" \\\n";
122 push @lines, " \" > - selected route, * - FIB route%s%s\", \\\n";
123 my @nl = ();
124 for (my $c = 0; $c < @lines + 1; $c++) {
125 push @nl, "VTY_NEWLINE"
126 }
127 return join("", @lines) ." ". join(", ", @nl);
128 }
129
130 print "\n";
131 printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist(@protosv4);
132 printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist(@protosv6);
133 print "\n";
134
135 sub collect {
136 my ($daemon, $ipv4, $ipv6, $any) = @_;
137 my (@names, @help) = ((), ());
138 for my $p (@protos) {
139 next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
140 next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
141 || ($ipv6 && $protodetail{$p}->{"ipv6"}));
142 push @names, $protodetail{$p}->{"cname"};
143 push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
144 }
145 if ($any == 1) {
146 push @names, "any";
147 push @help, " \"Any of the above protocols\\n\"";
148 }
149 return ("\"(" . join("|", @names) . ")\"", join(" \\\n", @help));
150 }
151
152 for my $daemon (sort keys %daemons) {
153 next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
154 printf "/* %s */\n", $daemon;
155 if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
156 my ($names, $help) = collect($daemon, 1, 1, 0);
157 printf "#define QUAGGA_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
158 printf "#define QUAGGA_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
159
160 ($names, $help) = collect($daemon, 1, 0, 0);
161 printf "#define QUAGGA_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
162 printf "#define QUAGGA_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
163
164 ($names, $help) = collect($daemon, 0, 1, 0);
165 printf "#define QUAGGA_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
166 printf "#define QUAGGA_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
167
168 if ($daemon eq "zebra") {
169 ($names, $help) = collect($daemon, 1, 0, 1);
170 printf "#define QUAGGA_IP_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
171 printf "#define QUAGGA_IP_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
172
173 ($names, $help) = collect($daemon, 0, 1, 1);
174 printf "#define QUAGGA_IP6_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
175 printf "#define QUAGGA_IP6_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
176 }
177 } else {
178 my ($names, $help) = collect($daemon,
179 $daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"}, 0);
180 printf "#define QUAGGA_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
181 printf "#define QUAGGA_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
182 }
183 print "\n";
184 }
185
186 print <<EOF;
187
188 #ifdef QUAGGA_DEFINE_DESC_TABLE
189
190 struct zebra_desc_table
191 {
192 unsigned int type;
193 const char *string;
194 char chr;
195 };
196
197 #define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
198 static const struct zebra_desc_table route_types[] = {
199 EOF
200
201 for (my $c = 0; $c < @protos; $c++) {
202 my $p = $protos[$c];
203 printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
204 $p.",", $protodetail{$p}->{"cname"}, $protodetail{$p}->{"char"};
205 }
206
207 print <<EOF;
208 };
209 #undef DESC_ENTRY
210
211 #endif /* QUAGGA_DEFINE_DESC_TABLE */
212
213 #endif /* _QUAGGA_ROUTE_TYPES_H */
214 EOF
215