2009-09-16 01:52:42 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
##
|
|
|
|
## Scan a file of route-type definitions (see eg route_types.txt) and
|
|
|
|
## generate a corresponding header file with:
|
|
|
|
##
|
|
|
|
## - enum of Zserv route-types
|
|
|
|
## - redistribute strings for the various Quagga daemons
|
|
|
|
##
|
|
|
|
## See route_types.txt for the format.
|
|
|
|
##
|
|
|
|
##
|
|
|
|
## Copyright (C) 2009 David Lamparter.
|
|
|
|
## This file is part of GNU Zebra.
|
|
|
|
##
|
|
|
|
## GNU Zebra is free software; you can redistribute it and/or modify it
|
|
|
|
## under the terms of the GNU General Public License as published by the
|
|
|
|
## Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
## later version.
|
|
|
|
##
|
|
|
|
## GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
## WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
## General Public License for more details.
|
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with GNU Zebra; see the file COPYING. If not, write to the Free
|
|
|
|
## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
## 02111-1307, USA.
|
|
|
|
##
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
# input processing
|
|
|
|
#
|
|
|
|
my @protos;
|
|
|
|
my %protodetail;
|
|
|
|
|
|
|
|
my %daemons;
|
|
|
|
|
|
|
|
while (<STDIN>) {
|
|
|
|
# skip comments and empty lines
|
|
|
|
next if (/^\s*(#|$)/);
|
|
|
|
|
|
|
|
# strip whitespace
|
|
|
|
chomp;
|
|
|
|
$_ =~ s/^\s*//;
|
|
|
|
$_ =~ s/\s*$//;
|
|
|
|
|
|
|
|
# match help strings
|
|
|
|
if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
|
|
|
|
$protodetail{$1}->{'longhelp'} = $2;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
$_ =~ s/\s*,\s*/,/g;
|
|
|
|
|
|
|
|
# else: 7-field line
|
|
|
|
my @f = split(/,/, $_);
|
2016-11-04 17:47:36 +01:00
|
|
|
unless (@f == 7 || @f == 8) {
|
2009-09-16 01:52:42 +02:00
|
|
|
die "invalid input on route_types line $.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $proto = $f[0];
|
|
|
|
$f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
|
|
|
|
$f[6] = $1 if ($f[6] =~ /^"(.*)"$/);
|
|
|
|
|
|
|
|
$protodetail{$proto} = {
|
|
|
|
"number" => scalar @protos,
|
|
|
|
"type" => $f[0],
|
|
|
|
"cname" => $f[1],
|
|
|
|
"daemon" => $f[2],
|
|
|
|
"char" => $f[3],
|
|
|
|
"ipv4" => int($f[4]),
|
|
|
|
"ipv6" => int($f[5]),
|
|
|
|
"shorthelp" => $f[6],
|
2016-11-04 17:47:36 +01:00
|
|
|
"restrict2" => $f[7],
|
2009-09-16 01:52:42 +02:00
|
|
|
};
|
|
|
|
push @protos, $proto;
|
|
|
|
$daemons{$f[2]} = {
|
|
|
|
"ipv4" => int($f[4]),
|
|
|
|
"ipv6" => int($f[5])
|
|
|
|
} unless ($f[2] eq "NULL");
|
|
|
|
}
|
|
|
|
|
|
|
|
# output
|
|
|
|
printf <<EOF, $ARGV[0];
|
|
|
|
/* Auto-generated from route_types.txt by %s. */
|
|
|
|
/* Do not edit! */
|
|
|
|
|
2016-12-20 18:31:42 +01:00
|
|
|
#ifndef _FRR_ROUTE_TYPES_H
|
|
|
|
#define _FRR_ROUTE_TYPES_H
|
2009-09-16 01:52:42 +02:00
|
|
|
|
2015-05-20 02:47:20 +02:00
|
|
|
/* Zebra route's' types. */
|
2009-09-16 01:52:42 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
push @protos, "ZEBRA_ROUTE_MAX";
|
|
|
|
my (@protosv4, @protosv6) = ((), ());
|
|
|
|
for (my $c = 0; $c < @protos; $c++) {
|
|
|
|
my $p = $protos[$c];
|
|
|
|
printf "#define %-32s %d\n", $p, $c;
|
|
|
|
push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
|
|
|
|
push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
|
|
|
|
}
|
|
|
|
pop @protos;
|
|
|
|
|
|
|
|
sub codelist {
|
|
|
|
my (@protos) = @_;
|
|
|
|
my (@lines) = ();
|
|
|
|
my $str = " \"Codes: ";
|
|
|
|
for my $p (@protos) {
|
|
|
|
my $s = sprintf("%s - %s, ",
|
|
|
|
$protodetail{$p}->{"char"},
|
|
|
|
$protodetail{$p}->{"shorthelp"});
|
|
|
|
if (length($str . $s) > 70) {
|
|
|
|
$str =~ s/ $//;
|
2017-07-13 20:17:06 +02:00
|
|
|
push @lines, $str . "\\n\" \\\n";
|
2009-09-16 01:52:42 +02:00
|
|
|
$str = " \" ";
|
|
|
|
}
|
|
|
|
$str .= $s;
|
|
|
|
}
|
|
|
|
$str =~ s/ $//;
|
2017-07-13 20:17:06 +02:00
|
|
|
push @lines, $str . "\\n\" \\\n";
|
|
|
|
push @lines, " \" > - selected route, * - FIB route\\n\\n\"";
|
|
|
|
return join("", @lines);
|
2009-09-16 01:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
print "\n";
|
|
|
|
printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist(@protosv4);
|
|
|
|
printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist(@protosv6);
|
|
|
|
print "\n";
|
|
|
|
|
|
|
|
sub collect {
|
2015-05-20 02:47:20 +02:00
|
|
|
my ($daemon, $ipv4, $ipv6, $any) = @_;
|
2009-09-16 01:52:42 +02:00
|
|
|
my (@names, @help) = ((), ());
|
|
|
|
for my $p (@protos) {
|
|
|
|
next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
|
2016-11-04 17:47:36 +01:00
|
|
|
next if ($protodetail{$p}->{"restrict2"} ne "" &&
|
|
|
|
$protodetail{$p}->{"restrict2"} ne $daemon);
|
2009-09-16 01:52:42 +02:00
|
|
|
next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
|
|
|
|
|| ($ipv6 && $protodetail{$p}->{"ipv6"}));
|
|
|
|
push @names, $protodetail{$p}->{"cname"};
|
|
|
|
push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
|
|
|
|
}
|
2015-05-20 02:47:20 +02:00
|
|
|
if ($any == 1) {
|
|
|
|
push @names, "any";
|
|
|
|
push @help, " \"Any of the above protocols\\n\"";
|
|
|
|
}
|
2017-01-27 21:36:09 +01:00
|
|
|
return ("\"<" . join("|", @names) . ">\"", join(" \\\n", @help));
|
2009-09-16 01:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for my $daemon (sort keys %daemons) {
|
|
|
|
next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
|
|
|
|
printf "/* %s */\n", $daemon;
|
|
|
|
if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
|
2015-05-20 02:47:20 +02:00
|
|
|
my ($names, $help) = collect($daemon, 1, 1, 0);
|
2016-12-20 18:31:42 +01:00
|
|
|
printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
|
|
|
|
printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
|
2016-05-11 15:12:08 +02:00
|
|
|
|
2015-05-20 02:47:20 +02:00
|
|
|
($names, $help) = collect($daemon, 1, 0, 0);
|
2016-12-20 18:31:42 +01:00
|
|
|
printf "#define FRR_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
|
|
|
|
printf "#define FRR_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
|
2016-05-11 15:12:08 +02:00
|
|
|
|
2015-05-20 02:47:20 +02:00
|
|
|
($names, $help) = collect($daemon, 0, 1, 0);
|
2016-12-20 18:31:42 +01:00
|
|
|
printf "#define FRR_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
|
|
|
|
printf "#define FRR_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
|
2016-05-11 15:12:08 +02:00
|
|
|
|
2015-05-20 02:47:20 +02:00
|
|
|
if ($daemon eq "zebra") {
|
2016-05-11 15:12:08 +02:00
|
|
|
($names, $help) = collect($daemon, 1, 0, 1);
|
2016-12-20 18:31:42 +01:00
|
|
|
printf "#define FRR_IP_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
|
|
|
|
printf "#define FRR_IP_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
|
2016-05-11 15:12:08 +02:00
|
|
|
|
|
|
|
($names, $help) = collect($daemon, 0, 1, 1);
|
2016-12-20 18:31:42 +01:00
|
|
|
printf "#define FRR_IP6_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
|
|
|
|
printf "#define FRR_IP6_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
|
2015-05-20 02:47:20 +02:00
|
|
|
}
|
2009-09-16 01:52:42 +02:00
|
|
|
} else {
|
|
|
|
my ($names, $help) = collect($daemon,
|
2015-05-20 02:47:20 +02:00
|
|
|
$daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"}, 0);
|
2016-12-20 18:31:42 +01:00
|
|
|
printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
|
|
|
|
printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
|
2009-09-16 01:52:42 +02:00
|
|
|
}
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print <<EOF;
|
|
|
|
|
2016-12-20 18:31:42 +01:00
|
|
|
#ifdef FRR_DEFINE_DESC_TABLE
|
2009-09-16 01:52:42 +02:00
|
|
|
|
|
|
|
struct zebra_desc_table
|
|
|
|
{
|
|
|
|
unsigned int type;
|
|
|
|
const char *string;
|
|
|
|
char chr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
|
|
|
|
static const struct zebra_desc_table route_types[] = {
|
|
|
|
EOF
|
|
|
|
|
|
|
|
for (my $c = 0; $c < @protos; $c++) {
|
|
|
|
my $p = $protos[$c];
|
|
|
|
printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
|
|
|
|
$p.",", $protodetail{$p}->{"cname"}, $protodetail{$p}->{"char"};
|
|
|
|
}
|
|
|
|
|
|
|
|
print <<EOF;
|
|
|
|
};
|
|
|
|
#undef DESC_ENTRY
|
|
|
|
|
2016-12-20 18:31:42 +01:00
|
|
|
#endif /* FRR_DEFINE_DESC_TABLE */
|
2009-09-16 01:52:42 +02:00
|
|
|
|
2016-12-20 18:31:42 +01:00
|
|
|
#endif /* _FRR_ROUTE_TYPES_H */
|
2009-09-16 01:52:42 +02:00
|
|
|
EOF
|
|
|
|
|