]> git.proxmox.com Git - mirror_frr.git/blame - lib/route_types.pl
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / route_types.pl
CommitLineData
e0ca5fde
DL
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
31use strict;
32
33# input processing
34#
35my @protos;
36my %protodetail;
37
38my %daemons;
39
40while (<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
82557cf0 57 # else: 8-field line
e0ca5fde 58 my @f = split(/,/, $_);
82557cf0 59 unless (@f == 8 || @f == 9) {
e0ca5fde
DL
60 die "invalid input on route_types line $.\n";
61 }
62
63 my $proto = $f[0];
64 $f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
82557cf0 65 $f[7] = $1 if ($f[7] =~ /^"(.*)"$/);
e0ca5fde
DL
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]),
82557cf0
DS
75 "redist" => int($f[6]),
76 "shorthelp" => $f[7],
77 "restrict2" => $f[8],
e0ca5fde
DL
78 };
79 push @protos, $proto;
80 $daemons{$f[2]} = {
81 "ipv4" => int($f[4]),
82 "ipv6" => int($f[5])
83 } unless ($f[2] eq "NULL");
84}
85
86# output
87printf <<EOF, $ARGV[0];
88/* Auto-generated from route_types.txt by %s. */
89/* Do not edit! */
90
ab0181ee
DL
91#ifndef _FRR_ROUTE_TYPES_H
92#define _FRR_ROUTE_TYPES_H
e0ca5fde 93
9f0ea7d4 94/* Zebra route's' types. */
e0ca5fde
DL
95EOF
96
97push @protos, "ZEBRA_ROUTE_MAX";
98my (@protosv4, @protosv6) = ((), ());
99for (my $c = 0; $c < @protos; $c++) {
100 my $p = $protos[$c];
101 printf "#define %-32s %d\n", $p, $c;
102 push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
103 push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
104}
105pop @protos;
106
107sub codelist {
108 my (@protos) = @_;
109 my (@lines) = ();
110 my $str = " \"Codes: ";
111 for my $p (@protos) {
112 my $s = sprintf("%s - %s, ",
113 $protodetail{$p}->{"char"},
114 $protodetail{$p}->{"shorthelp"});
115 if (length($str . $s) > 70) {
116 $str =~ s/ $//;
625e016d 117 push @lines, $str . "\\n\" \\\n";
e0ca5fde
DL
118 $str = " \" ";
119 }
120 $str .= $s;
121 }
122 $str =~ s/ $//;
625e016d
DL
123 push @lines, $str . "\\n\" \\\n";
124 push @lines, " \" > - selected route, * - FIB route\\n\\n\"";
125 return join("", @lines);
e0ca5fde
DL
126}
127
128print "\n";
129printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist(@protosv4);
130printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist(@protosv6);
131print "\n";
132
133sub collect {
9f0ea7d4 134 my ($daemon, $ipv4, $ipv6, $any) = @_;
e0ca5fde
DL
135 my (@names, @help) = ((), ());
136 for my $p (@protos) {
137 next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
5ee62c66
PZ
138 next if ($protodetail{$p}->{"restrict2"} ne "" &&
139 $protodetail{$p}->{"restrict2"} ne $daemon);
82557cf0 140 next if ($protodetail{$p}->{"redist"} eq 0);
e0ca5fde 141 next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
82557cf0 142 || ($ipv6 && $protodetail{$p}->{"ipv6"}));
e0ca5fde
DL
143 push @names, $protodetail{$p}->{"cname"};
144 push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
145 }
9f0ea7d4
DS
146 if ($any == 1) {
147 push @names, "any";
148 push @help, " \"Any of the above protocols\\n\"";
149 }
c3d89003 150 return ("\"<" . join("|", @names) . ">\"", join(" \\\n", @help));
e0ca5fde
DL
151}
152
153for my $daemon (sort keys %daemons) {
154 next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
155 printf "/* %s */\n", $daemon;
156 if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
9f0ea7d4 157 my ($names, $help) = collect($daemon, 1, 1, 0);
ab0181ee
DL
158 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
159 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
de69c444 160
9f0ea7d4 161 ($names, $help) = collect($daemon, 1, 0, 0);
ab0181ee
DL
162 printf "#define FRR_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
163 printf "#define FRR_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
de69c444 164
9f0ea7d4 165 ($names, $help) = collect($daemon, 0, 1, 0);
ab0181ee
DL
166 printf "#define FRR_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
167 printf "#define FRR_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
de69c444 168
9f0ea7d4 169 if ($daemon eq "zebra") {
de69c444 170 ($names, $help) = collect($daemon, 1, 0, 1);
ab0181ee
DL
171 printf "#define FRR_IP_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
172 printf "#define FRR_IP_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
de69c444
DW
173
174 ($names, $help) = collect($daemon, 0, 1, 1);
ab0181ee
DL
175 printf "#define FRR_IP6_PROTOCOL_MAP_STR_%s \\\n %s\n", uc $daemon, $names;
176 printf "#define FRR_IP6_PROTOCOL_MAP_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
9f0ea7d4 177 }
e0ca5fde
DL
178 } else {
179 my ($names, $help) = collect($daemon,
9f0ea7d4 180 $daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"}, 0);
ab0181ee
DL
181 printf "#define FRR_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
182 printf "#define FRR_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
e0ca5fde
DL
183 }
184 print "\n";
185}
186
187print <<EOF;
188
ab0181ee 189#ifdef FRR_DEFINE_DESC_TABLE
e0ca5fde
DL
190
191struct zebra_desc_table
192{
193 unsigned int type;
194 const char *string;
195 char chr;
196};
197
198#define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
199static const struct zebra_desc_table route_types[] = {
200EOF
201
202for (my $c = 0; $c < @protos; $c++) {
203 my $p = $protos[$c];
204 printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
205 $p.",", $protodetail{$p}->{"cname"}, $protodetail{$p}->{"char"};
206}
207
208print <<EOF;
209};
210#undef DESC_ENTRY
211
ab0181ee 212#endif /* FRR_DEFINE_DESC_TABLE */
e0ca5fde 213
ab0181ee 214#endif /* _FRR_ROUTE_TYPES_H */
e0ca5fde
DL
215EOF
216