]>
git.proxmox.com Git - mirror_frr.git/blob - lib/route_types.pl
2 # SPDX-License-Identifier: GPL-2.0-or-later
4 ## Scan a file of route-type definitions (see eg route_types.txt) and
5 ## generate a corresponding header file with:
7 ## - enum of Zserv route-types
8 ## - redistribute strings for the various Quagga daemons
10 ## See route_types.txt for the format.
13 ## Copyright (C) 2009 David Lamparter.
28 GetOptions
("enabled=s" => \
@enabled);
29 @enabled = split(/,/,join(',',@enabled));
32 # skip comments and empty lines
33 next if (/^\s*(#|$)/);
41 if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
42 $protodetail{$1}->{'longhelp'} = $2;
49 my @f = split(/,/, $_);
50 unless (@f == 9 || @f == 10) {
51 die "invalid input on route_types line $.\n";
55 $f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
56 $f[7] = $1 if ($f[7] =~ /^"(.*)"$/);
58 $protodetail{$proto} = {
59 "number" => scalar @protos,
66 "redist" => int($f[6]),
75 } unless ($f[2] eq "NULL");
79 printf <<EOF, $ARGV[0];
80 /* Auto-generated from route_types.txt by %s. */
83 #ifndef _FRR_ROUTE_TYPES_H
84 #define _FRR_ROUTE_TYPES_H
86 /* Zebra route's' types. */
89 push @protos, "ZEBRA_ROUTE_MAX";
90 my (@protosv4, @protosv6) = ((), ());
91 for (my $c = 0; $c < @protos; $c++) {
93 printf "#define %-32s %d\n", $p, $c;
94 push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
95 push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
102 my $str = " \"Codes: ";
103 for my $p (@protos) {
104 next unless (grep $_ eq $protodetail{$p}->{"enabled"}, @enabled);
105 my $s = sprintf("%s - %s, ",
106 $protodetail{$p}->{"char"},
107 $protodetail{$p}->{"shorthelp"});
108 if (length($str . $s) > 70) {
110 push @lines, $str . "\\n\" \\\n";
116 push @lines, $str . "\\n\" \\\n";
117 push @lines, " \" > - selected route, * - FIB route, q - queued, r - rejected, b - backup\\n\"";
118 push @lines, " \" t - trapped, o - offload failure\\n\\n\"";
121 return join("", @lines);
125 printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist
(@protosv4);
126 printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist
(@protosv6);
130 my ($daemon, $ipv4, $ipv6, $any) = @_;
131 my (@names, @help) = ((), ());
132 for my $p (@protos) {
133 next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
134 next if ($protodetail{$p}->{"restrict2"} ne "" &&
135 $protodetail{$p}->{"restrict2"} ne $daemon);
136 next if ($protodetail{$p}->{"redist"} eq 0);
137 next unless (grep $_ eq $protodetail{$p}->{"enabled"}, @enabled);
138 next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
139 || ($ipv6 && $protodetail{$p}->{"ipv6"}));
140 push @names, $protodetail{$p}->{"cname"};
141 push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
145 push @help, " \"Any of the above protocols\\n\"";
147 return ("\"<" . join("|", @names) . ">\"", join(" \\\n", @help));
150 for my $daemon (sort keys %daemons) {
151 next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
152 printf "/* %s */\n", $daemon;
153 if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
154 my ($names, $help) = collect
($daemon, 1, 1, 0);
155 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
156 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
158 ($names, $help) = collect
($daemon, 1, 0, 0);
159 printf "#define FRR_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
160 printf "#define FRR_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
162 ($names, $help) = collect
($daemon, 0, 1, 0);
163 printf "#define FRR_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
164 printf "#define FRR_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
166 if ($daemon eq "zebra") {
167 ($names, $help) = collect
($daemon, 1, 0, 1);
168 printf "#define FRR_IP_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
169 printf "#define FRR_IP_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
171 ($names, $help) = collect
($daemon, 0, 1, 1);
172 printf "#define FRR_IP6_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
173 printf "#define FRR_IP6_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
176 my ($names, $help) = collect
($daemon,
177 $daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"}, 0);
178 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
179 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
186 #ifdef FRR_DEFINE_DESC_TABLE
188 struct zebra_desc_table
195 #define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
196 static const struct zebra_desc_table route_types[] = {
199 for (my $c = 0; $c < @protos; $c++) {
201 printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
202 $p.",", $protodetail{$p}->{"cname
"}, $protodetail{$p}->{"char
"};
209 #endif /* FRR_DEFINE_DESC_TABLE */
211 #endif /* _FRR_ROUTE_TYPES_H */