]>
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
41 # skip comments and empty lines
42 next if (/^\s*(#|$)/);
50 if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
51 $protodetail{$1}->{'longhelp'} = $2;
58 my @f = split(/,/, $_);
59 unless (@f == 7 || @f == 8) {
60 die "invalid input on route_types line $.\n";
64 $f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
65 $f[6] = $1 if ($f[6] =~ /^"(.*)"$/);
67 $protodetail{$proto} = {
68 "number" => scalar @protos,
82 } unless ($f[2] eq "NULL");
86 printf <<EOF, $ARGV[0];
87 /* Auto-generated from route_types.txt by %s. */
90 #ifndef _FRR_ROUTE_TYPES_H
91 #define _FRR_ROUTE_TYPES_H
93 /* Zebra route's' types. */
96 push @protos, "ZEBRA_ROUTE_MAX";
97 my (@protosv4, @protosv6) = ((), ());
98 for (my $c = 0; $c < @protos; $c++) {
100 printf "#define %-32s %d\n", $p, $c;
101 push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
102 push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
109 my $str = " \"Codes: ";
110 for my $p (@protos) {
111 my $s = sprintf("%s - %s, ",
112 $protodetail{$p}->{"char"},
113 $protodetail{$p}->{"shorthelp"});
114 if (length($str . $s) > 70) {
116 push @lines, $str . "%s\" \\\n";
122 push @lines, $str . "%s\" \\\n";
123 push @lines, " \" > - selected route, * - FIB route%s%s\", \\\n";
125 for (my $c = 0; $c < @lines + 1; $c++) {
126 push @nl, "VTY_NEWLINE
"
128 return join("", @lines) ." ". join(", ", @nl);
132 printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist(@protosv4);
133 printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist
(@protosv6);
137 my ($daemon, $ipv4, $ipv6, $any) = @_;
138 my (@names, @help) = ((), ());
139 for my $p (@protos) {
140 next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
141 next if ($protodetail{$p}->{"restrict2"} ne "" &&
142 $protodetail{$p}->{"restrict2"} ne $daemon);
143 next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
144 || ($ipv6 && $protodetail{$p}->{"ipv6"}));
145 push @names, $protodetail{$p}->{"cname"};
146 push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
150 push @help, " \"Any of the above protocols\\n\"";
152 return ("\"<" . join("|", @names) . ">\"", join(" \\\n", @help));
155 for my $daemon (sort keys %daemons) {
156 next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
157 printf "/* %s */\n", $daemon;
158 if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
159 my ($names, $help) = collect
($daemon, 1, 1, 0);
160 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
161 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
163 ($names, $help) = collect
($daemon, 1, 0, 0);
164 printf "#define FRR_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
165 printf "#define FRR_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
167 ($names, $help) = collect
($daemon, 0, 1, 0);
168 printf "#define FRR_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
169 printf "#define FRR_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
171 if ($daemon eq "zebra") {
172 ($names, $help) = collect
($daemon, 1, 0, 1);
173 printf "#define FRR_IP_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
174 printf "#define FRR_IP_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
176 ($names, $help) = collect
($daemon, 0, 1, 1);
177 printf "#define FRR_IP6_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
178 printf "#define FRR_IP6_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
181 my ($names, $help) = collect
($daemon,
182 $daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"}, 0);
183 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
184 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
191 #ifdef FRR_DEFINE_DESC_TABLE
193 struct zebra_desc_table
200 #define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
201 static const struct zebra_desc_table route_types[] = {
204 for (my $c = 0; $c < @protos; $c++) {
206 printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
207 $p.",", $protodetail{$p}->{"cname
"}, $protodetail{$p}->{"char
"};
214 #endif /* FRR_DEFINE_DESC_TABLE */
216 #endif /* _FRR_ROUTE_TYPES_H */