]>
git.proxmox.com Git - mirror_frr.git/blob - lib/route_types.pl
3 ## Scan a file of route-type definitions (see eg route_types.txt) and
4 ## generate a corresponding header file with:
6 ## - enum of Zserv route-types
7 ## - redistribute strings for the various Quagga daemons
9 ## See route_types.txt for the format.
12 ## Copyright (C) 2009 David Lamparter.
13 ## This file is part of GNU Zebra.
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
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.
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
43 GetOptions
("enabled=s" => \
@enabled);
44 @enabled = split(/,/,join(',',@enabled));
47 # skip comments and empty lines
48 next if (/^\s*(#|$)/);
56 if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
57 $protodetail{$1}->{'longhelp'} = $2;
64 my @f = split(/,/, $_);
65 unless (@f == 9 || @f == 10) {
66 die "invalid input on route_types line $.\n";
70 $f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
71 $f[7] = $1 if ($f[7] =~ /^"(.*)"$/);
73 $protodetail{$proto} = {
74 "number" => scalar @protos,
81 "redist" => int($f[6]),
90 } unless ($f[2] eq "NULL");
94 printf <<EOF, $ARGV[0];
95 /* Auto-generated from route_types.txt by %s. */
98 #ifndef _FRR_ROUTE_TYPES_H
99 #define _FRR_ROUTE_TYPES_H
101 /* Zebra route's' types. */
104 push @protos, "ZEBRA_ROUTE_MAX";
105 my (@protosv4, @protosv6) = ((), ());
106 for (my $c = 0; $c < @protos; $c++) {
108 printf "#define %-32s %d\n", $p, $c;
109 push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
110 push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
117 my $str = " \"Codes: ";
118 for my $p (@protos) {
119 next unless (grep $_ eq $protodetail{$p}->{"enabled"}, @enabled);
120 my $s = sprintf("%s - %s, ",
121 $protodetail{$p}->{"char"},
122 $protodetail{$p}->{"shorthelp"});
123 if (length($str . $s) > 70) {
125 push @lines, $str . "\\n\" \\\n";
131 push @lines, $str . "\\n\" \\\n";
132 push @lines, " \" > - selected route, * - FIB route, q - queued, r - rejected, b - backup\\n\"";
133 push @lines, " \" t - trapped, o - offload failure\\n\\n\"";
136 return join("", @lines);
140 printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist
(@protosv4);
141 printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist
(@protosv6);
145 my ($daemon, $ipv4, $ipv6, $any) = @_;
146 my (@names, @help) = ((), ());
147 for my $p (@protos) {
148 next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
149 next if ($protodetail{$p}->{"restrict2"} ne "" &&
150 $protodetail{$p}->{"restrict2"} ne $daemon);
151 next if ($protodetail{$p}->{"redist"} eq 0);
152 next unless (grep $_ eq $protodetail{$p}->{"enabled"}, @enabled);
153 next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
154 || ($ipv6 && $protodetail{$p}->{"ipv6"}));
155 push @names, $protodetail{$p}->{"cname"};
156 push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
160 push @help, " \"Any of the above protocols\\n\"";
162 return ("\"<" . join("|", @names) . ">\"", join(" \\\n", @help));
165 for my $daemon (sort keys %daemons) {
166 next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
167 printf "/* %s */\n", $daemon;
168 if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
169 my ($names, $help) = collect
($daemon, 1, 1, 0);
170 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
171 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
173 ($names, $help) = collect
($daemon, 1, 0, 0);
174 printf "#define FRR_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
175 printf "#define FRR_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
177 ($names, $help) = collect
($daemon, 0, 1, 0);
178 printf "#define FRR_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
179 printf "#define FRR_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
181 if ($daemon eq "zebra") {
182 ($names, $help) = collect
($daemon, 1, 0, 1);
183 printf "#define FRR_IP_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
184 printf "#define FRR_IP_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
186 ($names, $help) = collect
($daemon, 0, 1, 1);
187 printf "#define FRR_IP6_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
188 printf "#define FRR_IP6_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
191 my ($names, $help) = collect
($daemon,
192 $daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"}, 0);
193 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
194 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
201 #ifdef FRR_DEFINE_DESC_TABLE
203 struct zebra_desc_table
210 #define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
211 static const struct zebra_desc_table route_types[] = {
214 for (my $c = 0; $c < @protos; $c++) {
216 printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
217 $p.",", $protodetail{$p}->{"cname
"}, $protodetail{$p}->{"char
"};
224 #endif /* FRR_DEFINE_DESC_TABLE */
226 #endif /* _FRR_ROUTE_TYPES_H */