bird.sgml 72.5 KB
Newer Older
1
<!doctype birddoc system>
2
3

<!--
Pavel Machek's avatar
Pavel Machek committed
4
	BIRD documentation
5

6
7
8
9
This documentation can have 4 forms: sgml (this is master copy), html,
ASCII text and dvi/postscript (generated from sgml using
sgmltools). You should always edit master copy.

Martin Mareš's avatar
Martin Mareš committed
10
This is a slightly modified linuxdoc dtd.  Anything in <descrip> tags is considered definition of
11
configuration primitives, <cf> is fragment of configuration within normal text, <m> is
Martin Mareš's avatar
Martin Mareš committed
12
"meta" information within fragment of configuration - something in config which is not keyword.
13
14
15
16
17
18
19

    (set-fill-column 100)

    Copyright 1999,2000 Pavel Machek <pavel@ucw.cz>, distribute under GPL version 2 or later.

 -->

20
<book>
21

22
<title>BIRD User's Guide
23
<author>
24
25
26
27
Ondrej Filip <it/&lt;feela@network.cz&gt;/,
Pavel Machek <it/&lt;pavel@ucw.cz&gt;/,
Martin Mares <it/&lt;mj@ucw.cz&gt;/
</author>
28
29

<abstract>
30
This document contains user documentation for the BIRD Internet Routing Daemon project.
31
32
33
34
35
36
37
</abstract>

<!-- Table of contents -->
<toc>

<!-- Begin the document -->

38
<chapt>Introduction
39

40
<sect>What is BIRD
41

42
43
44
45
46
47
48
49
50
51
52
<p><label id="intro">
The name `BIRD' is actually an acronym standing for `BIRD Internet Routing Daemon'.
Let's take a closer look at the meaning of the name:

<p><em/BIRD/: Well, we think we have already explained that. It's an acronym standing
for `BIRD Internet Routing Daemon', you remember, don't you? :-)

<p><em/Internet Routing/: It's a program (well, a daemon, as you are going to discover in a moment)
which works as a dynamic router in an Internet type network (that is, in a network running either
the IPv4 or the IPv6 protocol). Routers are devices which forward packets between interconnected
networks in order to allow hosts not connected directly to the same local area network to
53
communicate with each other. They also communicate with the other routers in the Internet to discover
54
the topology of the network which allows them to find optimal (in terms of some metric) rules for
55
forwarding of packets (which are called routing tables) and to adapt themselves to the
56
57
changing conditions such as outages of network links, building of new connections and so on. Most of
these routers are costly dedicated devices running obscure firmware which is hard to configure and
58
not open to any changes (on the other hand, their special hardware design allows them to keep up with lots of high-speed network interfaces, better than general-purpose computer does). Fortunately, most operating systems of the UNIX family allow an ordinary 
59
60
61
62
63
64
computer to act as a router and forward packets belonging to the other hosts, but only according to
a statically configured table.

<p>A <em/Routing Daemon/ is in UNIX terminology a non-interactive program running on
background which does the dynamic part of Internet routing, that is it communicates
with the other routers, calculates routing tables and sends them to the OS kernel
65
66
67
68
which does the actual packet forwarding. There already exist other such routing
daemons: routed (RIP only), GateD (non-free), Zebra<HTMLURL URL="http://www.zebra.org">
and MRTD<HTMLURL URL="http://sourceforge.net/projects/mrt">, but their capabilities are
limited and they are relatively hard to configure and maintain.
69
70

<p>BIRD is an Internet Routing Daemon designed to avoid all of these shortcomings,
Martin Mareš's avatar
Martin Mareš committed
71
to support all the routing technology used in the today's Internet or planned to be
72
73
74
75
76
77
78
used in near future and to have a clean extensible architecture allowing new routing
protocols to be incorporated easily. Among other features, BIRD supports:

<itemize>
	<item>both IPv4 and IPv6 protocols
	<item>multiple routing tables
	<item>the Border Gateway Protocol (BGPv4)
79
	<item>the Routing Information Protocol (RIPv2)
80
	<item>the Open Shortest Path First protocol (OSPFv2)
81
	<item>a virtual protocol for exchange of routes between different routing tables on a single host
82
83
84
85
	<item>a command-line interface allowing on-line control and inspection
		of status of the daemon
	<item>soft reconfiguration (no need to use complex online commands
		to change the configuration, just edit the configuration file
86
		and notify BIRD to re-read it and it will smoothly switch itself
87
88
		to the new configuration, not disturbing routing protocols
		unless they are affected by the configuration changes)
89
	<item>a powerful language for route filtering
90
91
92
</itemize>

<p>BIRD has been developed at the Faculty of Math and Physics, Charles University, Prague,
93
Czech Republic as a student project. It can be freely distributed under the terms of the GNU General
94
95
96
Public License.

<p>BIRD has been designed to work on all UNIX-like systems. It has been developed and
Ondřej Filip's avatar
Ondřej Filip committed
97
98
tested under Linux 2.0 to 2.4, and then ported to FreeBSD and NetBSD, porting to other
systems (even non-UNIX ones) should be relatively easy due to its highly modular architecture.
99

100
<sect>Installing BIRD
101

102
<p>On a recent UNIX system with GNU development tools (GCC, binutils, m4, make) and Perl, installing BIRD should be as easy as:
103
104
105
106
107
108

<code>
        ./configure
        make
        make install
        vi /usr/local/etc/bird.conf
Pavel Machek's avatar
Pavel Machek committed
109
	bird
110
111
</code>

112
113
114
115
116
<p>You can use <tt>./configure --help</tt> to get a list of configure
options. The most important ones are:
<tt/--enable-ipv6/ which enables building of an IPv6 version of BIRD,
<tt/--with-protocols=/ to produce a slightly smaller BIRD executable by configuring out routing protocols you don't use, and
<tt/--prefix=/ to install BIRD to a place different from.
117
118
<file>/usr/local</file>.

119
<sect>Running BIRD
Pavel Machek's avatar
Pavel Machek committed
120

Pavel Machek's avatar
Pavel Machek committed
121
<p>You can pass several command-line options to bird:
122

Pavel Machek's avatar
Pavel Machek committed
123
124
<descrip>
	<tag>-c <m/config name/</tag>
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
125
	use given configuration file instead of <it/prefix/<file>/etc/bird.conf</file>.
Pavel Machek's avatar
Pavel Machek committed
126
127

	<tag>-d</tag>
128
	enable debug messages and run bird in foreground.
Pavel Machek's avatar
Pavel Machek committed
129

130
131
	<tag>-D <m/filename of debug log/</tag>
	log debugging information to given file instead of stderr
Pavel Machek's avatar
Pavel Machek committed
132
133

	<tag>-s <m/name of communication socket/</tag>
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
134
	use given filename for a  socket for communications with the client, default is <it/prefix/<file>/var/run/bird.ctl</file>.
Pavel Machek's avatar
Pavel Machek committed
135
</descrip>
136

137
138
<p>BIRD writes messages about its work to log files or syslog (according to config).

139
140
<chapt>About routing tables

141
142
143
<p>BIRD has one or more routing tables which may or may not be
synchronized with OS kernel and which may or may not be synchronized with
each other (see the Pipe protocol). Each routing table contains a list of
144
145
146
known routes. Each route consists of:

<itemize>
147
148
149
	<item>network prefix this route is for (network address and prefix length -- the number of bits forming the network part of the address; also known as a netmask)
	<item>preference of this route
	<item>IP address of router which told us about this route
150
	<item>IP address of router we should forward the packets to
151
152
	using this route
	<item>other attributes common to all routes
153
154
	<item>dynamic attributes defined by protocols which may or
	may not be present (typically protocol metrics)
155
156
</itemize>

157
158
159
160
Routing table maintains multiple entries
for a network, but at most one entry for one network and one
protocol. The entry with the highest preference is used for routing (we
will call such an entry the <it/selected route/). If
161
there are more entries with the same preference and they are from the same
162
163
164
165
166
167
168
169
170
171
172
173
protocol, the protocol decides (typically according to metrics). If they aren't,
an internal ordering is used to break the tie. You can
get the list of route attributes in the Route attributes section.

<p>Each protocol is connected to a routing table through two filters
which can accept, reject and modify the routes. An <it/export/
filter checks routes passed from the routing table to the protocol,
an <it/import/ filter checks routes in the opposite direction.
When the routing table gets a route from a protocol, it recalculates
the selected route and broadcasts it to all protocols connected to
the table. The protocols typically send the update to other routers
in the network.
174

175
<chapt>Configuration
Pavel Machek's avatar
Pavel Machek committed
176

177
<sect>Introduction
178

Martin Mareš's avatar
Fixes.    
Martin Mareš committed
179
<p>BIRD is configured using a text configuration file. Upon startup, BIRD reads <it/prefix/<file>/etc/bird.conf</file> (unless the
180
181
182
183
<tt/-c/ command line option is given). Configuration may be changed at user's request: if you modify
the config file and then signal BIRD with <tt/SIGHUP/, it will adjust to the new
config. Then there's the client
which allows you to talk with BIRD in an extensive way.
184
185
186
187

<p>In the config, everything on a line after <cf/#/ or inside <cf>/*
*/</cf> is a comment, whitespace characters are treated as a single space. If there's a variable number of options, they are grouped using
the <cf/{ }/ brackets. Each option is terminated by a <cf/;/. Configuration
188
189
is case sensitive.

190
191
192
<p>Here is an example of a simple config file. It enables
synchronization of routing tables with OS kernel, scans for 
new network interfaces every 10 seconds and runs RIP on all network interfaces found.
193

194

195
<code>
196
protocol kernel {
Pavel Machek's avatar
Pavel Machek committed
197
	persist;		# Don't remove routes on BIRD shutdown
198
199
200
201
202
203
204
205
206
207
208
209
	scan time 20;		# Scan kernel routing table every 20 seconds
	export all;		# Default is export none
}

protocol device {
	scan time 10;		# Scan interfaces every 10 seconds
}

protocol rip {
	export all;
	import all;
}
210
</code>
211

212

213
<sect>Global options
Pavel Machek's avatar
Pavel Machek committed
214

215
<p><descrip>
216
	<tag>log "<m/filename/"|syslog|stderr all|{ <m/list of classes/ }</tag> 
217
	Set logging of messages having the given class (either <cf/all/ or <cf/{
218
	error, trace }/ etc.) into selected destination. Classes are:
219
	<cf/info/, <cf/warning/, <cf/error/ and <cf/fatal/ for messages about local problems,
220
	<cf/debug/ for debugging messages, 
221
222
223
	<cf/trace/ when you want to know what happens in the network, 
	<cf/remote/ for messages about misbehavior of remote machines, 
	<cf/auth/ about authentication failures,
Martin Mareš's avatar
Martin Mareš committed
224
	<cf/bug/ for internal BIRD bugs. You may specify more than one <cf/log/ line to establish logging to multiple
Pavel Machek's avatar
Pavel Machek committed
225
	destinations. Default: log everything to the system log.
226

227
	<tag>debug protocols all|off|{ states, routes, filters, interfaces, events, packets }</tag>
Pavel Machek's avatar
Pavel Machek committed
228
229
230
231
232
233
	Set global defaults of protocol debugging options. See <cf/debug/ in the following section. Default: off.

	<tag>debug commands <m/number/</tag>
	Control logging of client connections (0 for no logging, 1 for
	logging of connects and disconnects, 2 and higher for logging of
	all client commands). Default: 0.
234

235
	<tag>filter <m/name local variables/{ <m/commands/ }</tag> Define a filter. You can learn more about filters
Pavel Machek's avatar
Pavel Machek committed
236
	in the following chapter. 
237

238
	<tag>function <m/name/ (<m/parameters/) <m/local variables/ { <m/commands/ }</tag> Define a function. You can learn more
239
	about functions in the following chapter.
240
 
241
	<tag>protocol rip|ospf|bgp|... <m/[name]/ { <m>protocol options</m> }</tag> Define a protocol
242
	instance called <cf><m/name/</cf> (or with a name like "rip5" generated automatically if you don't specify any <cf><m/name/</cf>). You can learn more
Pavel Machek's avatar
Pavel Machek committed
243
	about configuring protocols in their own chapters. You can run more than one instance of
Pavel Machek's avatar
Pavel Machek committed
244
	most protocols (like RIP or BGP). By default, no instances are configured.
245

246
	<tag>define <m/constant/ = (<m/expression/)|<m/number/|<m/IP address/</tag> Define a constant. You can use it later in every place
247
	you could use a simple integer or an IP address.
248

Pavel Machek's avatar
Pavel Machek committed
249
	<tag>router id <m/IPv4 address/</tag> Set BIRD's router ID. It's a world-wide unique identification of your router, usually one of router's IPv4 addresses. Default: in IPv4 version, the lowest IP address of a non-loopback interface. In IPv6 version, this option is mandatory. 
250

251
	<tag>table <m/name/</tag> Create a new routing table. The default
252
253
	routing table is created implicitly, other routing tables have
	to be added by this command.
Pavel Machek's avatar
Pavel Machek committed
254

255
	<tag>eval <m/expr/</tag> Evaluates given filter expression. It
256
	is used by us for testing of filters.
257
258
</descrip>

259
<sect>Protocol options
260

Pavel Machek's avatar
Pavel Machek committed
261
262
263
<p>For each protocol instance, you can configure a bunch of options.
Some of them (those described in this section) are generic, some are
specific to the protocol (see sections talking about the protocols).
264

Pavel Machek's avatar
Pavel Machek committed
265
266
267
268
269
<p>Several options use a <cf><m/switch/</cf> argument. It can be either
<cf/on/, <cf/yes/ or a numeric expression with a non-zero value for the
option to be enabled or <cf/off/, <cf/no/ or a numeric expression evaluating
to zero to disable it. An empty <cf><m/switch/</cf> is equivalent to <cf/on/
("silence means agreement").
270

Pavel Machek's avatar
Pavel Machek committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<descrip>
	<tag>preference <m/expr/</tag> Sets the preference of routes generated by this protocol. Default: protocol dependent.

	<tag>disabled <m/switch/</tag> Disables the protocol. You can change the disable/enable status from the command
	line interface without needing to touch the configuration. Disabled protocols are not activated. Default: protocol is enabled.

	<tag>debug all|off|{ states, routes, filters, interfaces, events, packets }</tag>
	Set protocol debugging options. If asked, each protocol is capable of
	writing trace messages about its work to the log (with category
	<cf/trace/). You can either request printing of <cf/all/ trace messages
	or only of the types selected: <cf/states/ for protocol state changes
	(protocol going up, down, starting, stopping etc.),
	<cf/routes/ for routes exchanged with the routing table,
	<cf/filters/ for details on route filtering,
	<cf/interfaces/ for interface change events sent to the protocol,
	<cf/events/ for events internal to the protocol and
	<cf/packets/ for packets sent and received by the protocol. Default: off.

	<tag>import all | none | filter <m/name/ | filter { <m/filter commands/ } | where <m/filter expression/</tag> 
290
	Specify a filter to be used for filtering routes coming from the protocol to the routing table. <cf/all/ is shorthand for <cf/where true/ and <cf/none/ is shorthand for <cf/where false/. Default: <cf/all/.
291

292
293
	<tag>export <m/filter/</tag> This is similar to the <cf>import</cf> keyword, except that it
	works in the direction from the routing table to the protocol. Default: <cf/none/.
Pavel Machek's avatar
Pavel Machek committed
294

295
	<tag>table <m/name/</tag> Connect this protocol to a non-default routing table.
296
297
</descrip>

298
<p>There are several options that give sense only with certain protocols:
299
300
301

<descrip>
	<tag>passwords { password "<m/password/" from <m/time/ to <m/time/ passive <m/time/ id
302
	<m/num/ [...] }</tag> Specifies passwords to be used with this protocol. <cf>Passive <m/time/</cf> is
303
	time from which the password is not used for sending, but it is recognized on reception. <cf/id/ is password ID as needed by
Pavel Machek's avatar
Pavel Machek committed
304
	certain protocols. Format of <cf><m/time/</cf> is <tt>dd-mm-yyyy HH:MM:SS</tt>.
305

306
	<tag>interface "<m/mask/"|<m/prefix/ [ { <m/option/ ; [...] } ]</tag> Specifies which
307
308
	interfaces is this protocol active on and allows you to set options on a
	per-interface basis. Mask is specified as in shell-like patterns, thus <cf>interface
309
	"*" { mode broadcast; };</cf> will start the protocol on all interfaces with <cf>mode
310
	broadcast;</cf> option. If the first character of mask is <cf/-/, such interfaces are
311
	excluded. Masks are parsed left-to-right, thus <cf/interface "-eth*", "*";/ means all but
Pavel Machek's avatar
Pavel Machek committed
312
313
	the ethernets. Default: none.

314
</descrip>
315

Pavel Machek's avatar
Pavel Machek committed
316
<chapt>Remote control
Pavel Machek's avatar
Pavel Machek committed
317

318
<p>You can use the command-line client <file>birdc</file> to talk with
319
a running BIRD. Communication is done using a <file/bird.ctl/ UNIX domain
320
socket (unless changed with the <tt/-s/ option given to both the server and
321
322
323
the client). The commands can perform simple actions such as enabling/disabling
of protocols, telling BIRD to show various information, telling it to
show routing table filtered by filter, or asking BIRD to
Pavel Machek's avatar
Pavel Machek committed
324
reconfigure. Press <tt/?/ at any time to get online help. Option
325
<tt/-v/ can be passed to the client, to make it dump numeric return
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
326
codes along with the messages. You do not necessarily need to use <file/birdc/ to talk to BIRD, your
327
own applications could do that, too -- the format of communication between
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
328
BIRD and <file/birdc/ is stable (see the programmer's documentation).
Pavel Machek's avatar
Pavel Machek committed
329

Pavel Machek's avatar
Pavel Machek committed
330
<p>Here is a brief list of supported functions:
331
332

<descrip>
Pavel Machek's avatar
Pavel Machek committed
333
334
335
336
	<tag>dump resources|sockets|interfaces|neighbors|attributes|routes|protocols</tag>
	Dump contents of internal data structures to the debugging output.

	<tag>show status</tag>
337
	Show router status, that is BIRD version, uptime and time from last reconfiguration.
Pavel Machek's avatar
Pavel Machek committed
338
339

	<tag>show protocols [all]</tag>
340
	Show list of protocol instances along with tables they are connected to and protocol status, possibly giving verbose information, if <cf/all/ is specified.
341

Pavel Machek's avatar
Pavel Machek committed
342
343
	<tag>show ospf [interface|neighbors] [<m/name/] ["<m/interface/"]</tag>
	Show detailed information about OSPF protocol, possibly giving a verbose list of interfaces and neighbors. The <m/name/ of the protocol instance can be omitted if there exists only a single instance.
344

Pavel Machek's avatar
Pavel Machek committed
345
346
	<tag>show static [<m/name/]</tag>
	Show detailed information about static routes. The <m/name/ of the protocol instance can be omitted if there exists only a single instance.
347
	
Pavel Machek's avatar
Pavel Machek committed
348
	<tag>show interfaces [summary]</tag>
349
	Show the list of interfaces. For each interface, print its type, state, MTU and addresses assigned. 
Pavel Machek's avatar
Pavel Machek committed
350
351

	<tag>show symbols</tag>
352
	Show the list of symbols defined in the configuration (names of protocols, routing tables etc.).
Pavel Machek's avatar
Pavel Machek committed
353

354
	<tag>show route [[for] <m/prefix/|<m/IP/] [table <m/sym/] [filter <m/f/|where <m/c/] [(import|preimport) <m/p/] [protocol <m/p/] [<m/options/]</tag>
Pavel Machek's avatar
Pavel Machek committed
355
	Show contents of a routing table (by default of the main one),
356
	that is routes, their metrics and (in case the <cf/all/ switch is given)
Pavel Machek's avatar
Pavel Machek committed
357
358
359
360
361
362
363
364
365
366
367
368
	all their attributes.

	<p>You can specify a <m/prefix/ if you want to print routes for a
	specific network. If you use <cf>for <m/prefix or IP/</cf>, you'll get
	the entry which will be used for forwarding of packets to the given
	destination. By default, all routes for each network are printed with
	the selected one at the top, unless <cf/primary/ is given in which case
	only the selected route is shown.

	<p>You can also ask for printing only routes processed and accepted by
	a given filter (<cf>filter <m/name/</cf> or <cf>filter { <m/filter/ }
	</cf> or matching a given condition (<cf>where <m/condition/</cf>).
369
370
371
	The <cf/import/ and <cf/preimport/ switches ask for printing of entries
        that are imported to the specified protocol. With <cf/preimport/, the
	import filter of the protocol is skipped.
Pavel Machek's avatar
Pavel Machek committed
372

373
374
375
	<p>You can also select just routes added by a specific protocol.
	<cf>protocol <m/p/</cf>.

Pavel Machek's avatar
Pavel Machek committed
376
377
378
379
380
	<p>The <cf/stats/ switch requests showing of route statistics (the
	number of networks, number of routes before and after filtering). If
	you use <cf/count/ instead, only the statistics will be printed.

	<tag>enable|disable|restart <m/name/|"<m/pattern/"|all</tag>
381
	Enable, disable or restart a given protocol instance, instances matching the <cf><m/pattern/</cf> or <cf/all/ instances.
Pavel Machek's avatar
Pavel Machek committed
382
383
384
385
386
387

	<tag>configure ["<m/config file/"]</tag>
	Reload configuration from a given file.

	<tag/down/
	Shut BIRD down.
388

Pavel Machek's avatar
Pavel Machek committed
389
	<tag>debug <m/protocol/|<m/pattern/|all all|off|{ states | routes | filters | events | packets }</tag>
390
391
	Control protocol debugging.
</descrip>
Pavel Machek's avatar
Pavel Machek committed
392

393
<chapt>Filters
394

395
<sect>Introduction
396

397
398
399
400
<p>BIRD contains a simple programming language. (No, it can't yet read mail :-). There are
two objects in this language: filters and functions. Filters are interpreted by BIRD core when a route is
being passed between protocols and routing tables. The filter language contains control structures such
as if's and switches, but it allows no loops. An example of a filter using many features can be found in <file>filter/test.conf</file>. 
401

402
403
<p>Filter gets the route, looks at its attributes and
modifies some of them if it wishes. At the end, it decides whether to
404
pass the changed route through (using <cf/accept/) or whether to <cf/reject/ it. A simple filter looks
405
like this:
406

407
<code>
408
409
410
411
412
413
414
415
416
417
418
419
420
421
filter not_too_far
int var;
{
	if defined( rip_metric ) then
		var = rip_metric;
	else {
		var = 1;
		rip_metric = 1;
	}
	if rip_metric &gt; 10 then
		reject "RIP metric is too big";
	else
		accept "ok";
}
422
</code>
423

424
<p>As you can see, a filter has a header, a list of local variables, and a body. The header consists of
425
426
427
428
429
430
431
432
the <cf/filter/ keyword followed by a (unique) name of filter. The list of local variables consists of
<cf><M>type name</M>;</cf> pairs where each pair defines one local variable. The body consists of
<cf> { <M>statements</M> }</cf>. Each <m/statement/ is terminated by a <cf/;/. You can group
several statements to a single compound statement by using braces (<cf>{ <M>statements</M> }</cf>) which is useful if
you want to make a bigger block of code conditional.

<p>BIRD supports functions, so that you don't have to repeat the same blocks of code over and
over. Functions can have zero or more parameters and they can have local variables. Recursion is not allowed. Function definitions
433
look like this:
434
435
436
437
438
439
440
441
442
443
444
445
446
447

<code>
function name ()
int local_variable;
{
	local_variable = 5;
}

function with_parameters (int parameter)
{
	print parameter;
}
</code>

448
<p>Unlike in C, variables are declared after the <cf/function/ line, but before the first <cf/{/. You can't declare
449
variables in nested blocks. Functions are called like in C: <cf>name();
450
with_parameters(5);</cf>. Function may return values using the <cf>return <m/[expr]/</cf>
451
command. Returning a value exits from current function (this is similar to C).
452

453
<p>Filters are declared in a way similar to functions except they can't have explicit
454
parameters. They get a route table entry as an implicit parameter, it is also passed automatically 
455
to any functions called. The filter must terminate with either
456
<cf/accept/ or <cf/reject/ statement. If there's a runtime error in filter, the route
457
is rejected. 
458

459
460
<p>A nice trick to debug filters is to use <cf>show route filter
<m/name/</cf> from the command line client. An example session might look
Pavel Machek's avatar
Pavel Machek committed
461
462
463
464
465
466
467
468
469
470
like:

<code>
pavel@bug:~/bird$ ./birdc -s bird.ctl
BIRD 0.0.0 ready.
bird> show route
10.0.0.0/8         dev eth0 [direct1 23:21] (240)
195.113.30.2/32    dev tunl1 [direct1 23:21] (240)
127.0.0.0/8        dev lo [direct1 23:21] (240)
bird> show route ?
471
show route [<prefix>] [table <t>] [filter <f>] [all] [primary]...
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
472
bird> show route filter { if 127.0.0.5 &tilde; net then accept; }
Pavel Machek's avatar
Pavel Machek committed
473
474
475
476
127.0.0.0/8        dev lo [direct1 23:21] (240)
bird>
</code>

477
<sect>Data types
478

479
<p>Each variable and each value has certain type. Booleans, integers and enums are
480
incompatible with each other (that is to prevent you from shooting in the foot).
481
482

<descrip>
483
	<tag/bool/ This is a boolean type, it can have only two values, <cf/true/ and
484
	  <cf/false/. Boolean is the only type you can use in <cf/if/
485
	  statements.
486

487
488
	<tag/int/ This is a general integer type, you can expect it to store signed values from -2000000000
	  to +2000000000. Overflows are not checked. You can use <cf/0x1234/ syntax to write hexadecimal values.
489

490
491
	<tag/pair/ This is a pair of two short integers. Each component can have values from 0 to
	  65535. Literals of this type is written as <cf/(1234,5678)/.
492

493
494
495
	<tag/string/ This is a string of characters. There are no ways to modify strings in
	  filters. You can pass them between functions, assign them to variables of type <cf/string/, print
	  such variables, but you can't concatenate two strings. String literals
496
	  are written as <cf/"This is a string constant"/.
497

498
	<tag/ip/ This type can hold a single IP address. Depending on the compile-time configuration of BIRD you are using, it
Pavel Machek's avatar
Pavel Machek committed
499
	  is either an IPv4 or IPv6 address. IP addresses are written in the standard notation (<cf/10.20.30.40/ or <cf/fec0:3:4::1/). You can apply special operator <cf>.mask(<M>num</M>)</cf>
500
	  on values of type ip. It masks out all but first <cf><M>num</M></cf> bits from the IP
Pavel Machek's avatar
Pavel Machek committed
501
	  address. So <cf/1.2.3.4.mask(8) = 1.0.0.0/ is true.
502

503
	<tag/prefix/ This type can hold a network prefix consisting of IP address and prefix length. Prefix literals are written as
504
	  <cf><M>ipaddress</M>/<M>pxlen</M></cf>, or
505
506
507
508
	  <cf><m>ipaddress</m>/<m>netmask</m></cf>. There are two special
	  operators on prefixes:
	  <cf/.ip/ which extracts the IP address from the pair, and <cf/.len/, which separates prefix
	  length from the pair. So <cf>1.2.0.0/16.pxlen = 16</cf> is true.
509

510
	<tag/int|ip|prefix|pair|enum set/
511
512
	  Filters recognize four types of sets. Sets are similar to strings: you can pass them around
	  but you can't modify them. Literals of type <cf>set int</cf> look like <cf>
513
	  [ 1, 2, 5..7 ]</cf>. As you can see, both simple values and ranges are permitted in
514
515
516
517
518
519
	  sets.

	  Sets of prefixes are special: their literals does not allow ranges, but allows
	  prefix patterns that are written as <cf><M>ipaddress</M>/<M>pxlen</M>{<M>low</M>,<M>high</M>}</cf>.
	  Prefix <cf><m>ip1</m>/<m>len1</m></cf> matches prefix pattern <cf><m>ip2</m>/<m>len2</m>{<m>l</m>, <m>h</m>}</cf> iff 
	  the first <cf>min(len1, len2)</cf> bits of <cf/ip1/> and <cf/ip2/ are identical and <cf>len1 &le; ip1 &le; len2</cf>.
520
	  A valid prefix pattern has to satisfy <cf/low &le; high/, but <cf/pxlen/ is not constrained by <cf/low/
521
522
523
524
525
	  or <cf/high/. Obviously, a prefix matches a prefix set literal iff it matches any prefix pattern in the
	  prefix set literal.

	  There are also two shorthands for prefix patterns: <cf><m>address</m>/<m/len/+</cf> is a shorthand for
	  <cf><m>address</m>/<m/len/{<m/len/,<m/maxlen/}</cf> (where <cf><m>maxlen</m></c> is 32 for IPv4 and 128 for IPv6), 
Ondřej Zajíček's avatar
Ondřej Zajíček committed
526
527
528
	  that means network prefix <cf><m>address</m>/<m/len/</cf> and all its subnets. <cf><m>address</m>/<m/len/-</cf>
	  is a shorthand for <cf><m>address</m>/<m/len/{0,<m/len/}</cf>, that means network prefix <cf><m>address</m>/<m/len/</cf>
	  and all its supernets (network prefixes that contain it).
529
530
531
532
533
534
535
536
537
538
539
540

	  For example, <cf>[ 1.0.0.0/8, 2.0.0.0/8+, 3.0.0.0/8-, 4.0.0.0/8{16,24} ]</cf> matches
	  prefix <cf>1.0.0.0/8</cf>, all subprefixes of <cf>2.0.0.0/8</cf>, all superprefixes of <cf>3.0.0.0/8</cf> and prefixes
	  <cf/4.X.X.X/ whose prefix length is 16 to 24. <cf>[ 0.0.0.0/0{20,24} ]</cf> matches all prefixes (regardless of
	  IP address) whose prefix length is 20 to 24, <cf>[ 1.2.3.4/32- ]</cf> matches any prefix that contains IP address
	  <cf>1.2.3.4</cf>. <cf>1.2.0.0/16 &tilde; [ 1.0.0.0/8{ 15 , 17 } ]</cf> is true,
	  but <cf>1.0.0.0/16 &tilde; [ 1.0.0.0/8- ]</cf> is false.

	  Cisco-style patterns like <cf>10.0.0.0/8 ge 16 le 24</cf> can be expressed
	  in Bird as <cf>10.0.0.0/8{16,24}</cf>, <cf>192.168.0.0/16 le 24</cf> as 
	  <cf>192.168.0.0/16{16,24}</cf> and <cf>192.168.0.0/16 ge 24</cf> as
	  <cf>192.168.0.0/16{24,32}</cf>.
541
542

	<tag/enum/
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
543
	  Enumeration types are fixed sets of possibilities. You can't define your own
544
	  variables of such type, but some route attributes are of enumeration
545
	  type. Enumeration types are incompatible with each other.
546
547

	<tag/bgppath/
548
	  BGP path is a list of autonomous system numbers. You can't write literals of this type.
549

Pavel Machek's avatar
Pavel Machek committed
550
551
	<tag/bgpmask/
	  BGP masks are patterns used for BGP path matching
552
	  (using <cf>path &tilde; [= 2 3 5 * =]</cf> syntax). The masks
Pavel Machek's avatar
Pavel Machek committed
553
	  resemble wildcard patterns as used by UNIX shells. Autonomous
Ondřej Zajíček's avatar
Ondřej Zajíček committed
554
	  system numbers match themselves, <cf/*/ matches any (even empty)
555
556
	  sequence of arbitrary AS numbers and <cf/?/ matches one arbitrary AS number.
	  For example, if <cf>bgp_path</cf> is 4 3 2 1, then:
557
558
559
	  <tt>bgp_path &tilde; [= * 4 3 * =]</tt> is true, but 
	  <tt>bgp_path &tilde; [= * 4 5 * =]</tt> is false.
	  There is also old syntax that uses / .. / instead of [= .. =] and ? instead of *.
560
	<tag/clist/ 
561
	  Community list is similar to set of pairs,
562
	  except that unlike other sets, it can be modified.
563
	  There exist no literals of this type.
564

565
566
</descrip>

567
<sect>Operators
568

569
<p>The filter language supports common integer operators <cf>(+,-,*,/)</cf>, parentheses <cf/(a*(b+c))/, comparison
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
570
<cf/(a=b, a!=b, a&lt;b, a&gt;=b)/. Logical operations include unary not (<cf/!/), and (<cf/&amp;&amp;/) and or (<cf/&verbar;&verbar;/). 
571
Special operators include <cf/&tilde;/ for "is element of a set" operation - it can be
572
573
used on element and set of elements of the same type (returning true if element is contained in the given set), or
on two strings (returning true if first string matches a shell-like pattern stored in second string) or on IP and prefix (returning true if IP is within the range defined by that prefix), or on
574
prefix and prefix (returning true if first prefix is more specific than second one) or on bgppath and bgpmask (returning true if the path matches the mask) or on pair and clist (returning true if the community is element of the community list).
575

576

577
<sect>Control structures
578

579
580
<p>Filters support two control structures: conditions and case switches. 

581
<p>Syntax of a condition is: <cf>if
582
<M>boolean expression</M> then <M>command1</M>; else <M>command2</M>;</cf> and you can use <cf>{
583
584
<M>command_1</M>; <M>command_2</M>; <M>...</M> }</cf> instead of either command. The <cf>else</cf>
clause may be omitted. If the <cf><m>boolean expression</m></cf> is true, <cf><m>command1</m></cf> is executed, otherwise <cf><m>command2</m></cf> is executed.
585

586
587
588
589
590
<p>The <cf>case</cf> is similar to case from Pascal. Syntax is <cf>case <m/expr/ { else |
<m/num_or_prefix [ .. num_or_prefix]/: <m/statement/ ; [ ... ] }</cf>. The expression after
<cf>case</cf> can be of any type which can be on the left side of the &tilde; operator and anything that could
be a member of a set is allowed before <cf/:/. Multiple commands are allowed without <cf/{}/ grouping.
If <cf><m/expr/</cf> matches one of the <cf/:/ clauses, statements between it and next <cf/:/ statement are executed. If <cf><m/expr/</cf> matches neither of the <cf/:/ clauses, the statements after <cf/else:/ are executed.
591

592
<p>Here is example that uses <cf/if/ and <cf/case/ structures:
Pavel Machek's avatar
Pavel Machek committed
593
594
595
596
597
598

<code>
case arg1 {
	2: print "two"; print "I can do more commands without {}";
	3 .. 5: print "three to five";
	else: print "something else";
599
}
Pavel Machek's avatar
Pavel Machek committed
600

Pavel Machek's avatar
Pavel Machek committed
601
602
603
604
if 1234 = i then printn "."; else { 
  print "not 1234"; 
  print "You need {} around multiple commands"; 
}
Pavel Machek's avatar
Pavel Machek committed
605
606
</code>

607
<sect>Route attributes
608

609
610
<p>A filter is implicitly passed a route, and it can access its
attributes just like it accesses variables. Attempts to access undefined
611
attribute result in a runtime error; you can check if an attribute is
612
defined by using the <cf>defined( <m>attribute</m> )</cf> operator.
613

Pavel Machek's avatar
Pavel Machek committed
614
<descrip>
Martin Mareš's avatar
Martin Mareš committed
615
	<tag><m/prefix/ net</tag>
616
	Network the route is talking about. Read-only. (See the chapter about routing tables.)
617
618

	<tag><m/enum/ scope</tag>
Pavel Machek's avatar
Pavel Machek committed
619
	Address scope of the network (<cf/SCOPE_HOST/ for addresses local to this host, <cf/SCOPE_LINK/ for those specific for a physical link, <cf/SCOPE_SITE/ and <cf/SCOPE_ORGANIZATION/ for private addresses, <cf/SCOPE_UNIVERSE/ for globally visible addresses).
620

Martin Mareš's avatar
Martin Mareš committed
621
	<tag><m/int/ preference</tag>
622
	Preference of the route. (See the chapter about routing tables.)
Pavel Machek's avatar
Pavel Machek committed
623

Martin Mareš's avatar
Martin Mareš committed
624
	<tag><m/ip/ from</tag>
625
	The router which the route has originated from. Read-only.
626
	
Martin Mareš's avatar
Martin Mareš committed
627
	<tag><m/ip/ gw</tag>
628
	Next hop packets routed using this route should be forwarded to.
629

630
631
632
	<tag><m/string/ proto</tag>
	The name of the protocol which the route has been imported from. Read-only.

Martin Mareš's avatar
Martin Mareš committed
633
	<tag><m/enum/ source</tag>
Ondřej Filip's avatar
Ondřej Filip committed
634
	what protocol has told me about this route. Possible values: <cf/RTS_DUMMY/, <cf/RTS_STATIC/, <cf/RTS_INHERIT/, <cf/RTS_DEVICE/, <cf/RTS_STATIC_DEVICE/, <cf/RTS_REDIRECT/, <cf/RTS_RIP/, <cf/RTS_OSPF/, <cf/RTS_OSPF_IA/, <cf/RTS_OSPF_EXT/, <cf/RTS_BGP/, <cf/RTS_PIPE/.
Pavel Machek's avatar
Pavel Machek committed
635

Martin Mareš's avatar
Martin Mareš committed
636
	<tag><m/enum/ cast</tag>
637
	Route type (<cf/RTC_UNICAST/ for normal routes, <cf/RTC_BROADCAST/, <cf/RTC_MULTICAST/, <cf/RTC_ANYCAST/ for broadcast, multicast and anycast routes). Read-only.
Pavel Machek's avatar
Pavel Machek committed
638

Martin Mareš's avatar
Martin Mareš committed
639
	<tag><m/enum/ dest</tag>
Pavel Machek's avatar
Pavel Machek committed
640
	Type of destination the packets should be sent to (<cf/RTD_ROUTER/ for forwarding to a neighboring router, <cf/RTD_NETWORK/ for routing to a directly-connected network, <cf/RTD_BLACKHOLE/ for packets to be silently discarded, <cf/RTD_UNREACHABLE/, <cf/RTD_PROHIBIT/ for packets that should be returned with ICMP host unreachable / ICMP administratively prohibited messages). Read-only.
Pavel Machek's avatar
Pavel Machek committed
641
</descrip>
642

643
<p>There also exist some protocol-specific attributes which are described in the corresponding protocol sections.
644

645
<sect>Other statements
646

647
<p>The following statements are available:
648
649

<descrip>
650
	<tag><m/variable/ = <m/expr/</tag> Set variable to a given value.
651

652
	<tag>accept|reject [ <m/expr/ ]</tag> Accept or reject the route, possibly printing <cf><m>expr</m></cf>.
653

654
	<tag>return <m/expr/</tag> Return <cf><m>expr</m></cf> from the current function, the function ends at this point.
655

656
657
658
	<tag>print|printn <m/expr/ [<m/, expr.../]</tag>
	Prints given expressions; useful mainly while debugging
	filters. The <cf/printn/ variant does not terminate the line.
659
660

	<tag>quitbird</tag>
661
	Terminates BIRD. Useful when debugging the filter interpreter.
662
663
</descrip>

664
<chapt>Protocols
665

666
<sect>BGP
Martin Mareš's avatar
Martin Mareš committed
667

Martin Mareš's avatar
Martin Mareš committed
668
<p>The Border Gateway Protocol is the routing protocol used for backbone
Pavel Machek's avatar
Pavel Machek committed
669
level routing in the today's Internet. Contrary to the other protocols, its convergence
Martin Mareš's avatar
Martin Mareš committed
670
671
672
673
674
675
doesn't rely on all routers following the same rules for route selection,
making it possible to implement any routing policy at any router in the
network, the only restriction being that if a router advertises a route,
it must accept and forward packets according to it.

<p>BGP works in terms of autonomous systems (often abbreviated as AS). Each
Pavel Machek's avatar
Pavel Machek committed
676
677
AS is a part of the network with common management and common routing policy. It is identified by a unique 16-bit number.
Routers within each AS usually communicate with each other using either a interior routing
Martin Mareš's avatar
Martin Mareš committed
678
679
680
681
682
protocol (such as OSPF or RIP) or an interior variant of BGP (called iBGP).
Boundary routers at the border of the AS communicate with their peers
in the neighboring AS'es via exterior BGP (eBGP).

<p>Each BGP router sends to its neighbors updates of the parts of its
Pavel Machek's avatar
Pavel Machek committed
683
684
routing table it wishes to export along with complete path information
(a list of AS'es the packet will travel through if it uses the particular
Martin Mareš's avatar
Martin Mareš committed
685
686
route) in order to avoid routing loops.

Martin Mareš's avatar
Martin Mareš committed
687
<p>BIRD supports all requirements of the BGP4 standard as defined in
688
689
690
691
692
693
694
695
696
RFC 4271<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4271.txt">
It also supports the community attributes
(RFC 1997<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc1997.txt">),
capability negotiation
(RFC 3392<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc3392.txt">),
MD5 password authentication
(RFC 2385<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc2385.txt">),
route reflectors 
(RFC 4456<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4456.txt">),
697
698
multiprotocol extensions
(RFC 4760<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4760.txt">),
699
700
701
702
and 4B AS numbers 
(RFC 4893<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4893.txt">).


Martin Mareš's avatar
Martin Mareš committed
703
704
705
For IPv6, it uses the standard multiprotocol extensions defined in
RFC 2283<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc2283.txt">
including changes described in the
Pavel Machek's avatar
Pavel Machek committed
706
latest draft<htmlurl url="ftp://ftp.rfc-editor.org/internet-drafts/draft-ietf-idr-bgp4-multiprotocol-v2-05.txt">
Martin Mareš's avatar
Martin Mareš committed
707
708
709
and applied to IPv6 according to
RFC 2545<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc2545.txt">.

710
<sect1>Route selection rules
Martin Mareš's avatar
Martin Mareš committed
711
712
713

<p>BGP doesn't have any simple metric, so the rules for selection of an optimal
route among multiple BGP routes with the same preference are a bit more complex
Pavel Machek's avatar
Pavel Machek committed
714
and they are implemented according to the following algorithm. It starts the first
Martin Mareš's avatar
Martin Mareš committed
715
716
717
718
rule, if there are more "best" routes, then it uses the second rule to choose
among them and so on.

<itemize>
Pavel Machek's avatar
Pavel Machek committed
719
	<item>Prefer route with the highest Local Preference attribute.
Martin Mareš's avatar
Martin Mareš committed
720
721
722
	<item>Prefer route with the shortest AS path.
	<item>Prefer IGP origin over EGP and EGP over incomplete.
	<item>Prefer the lowest value of the Multiple Exit Discriminator.
Pavel Machek's avatar
Pavel Machek committed
723
724
	<item>Prefer internal routes over external ones.
	<item>Prefer the route with the lowest value of router ID of the
Martin Mareš's avatar
Martin Mareš committed
725
726
	advertising router.
</itemize>
Martin Mareš's avatar
Martin Mareš committed
727

728
<sect1>Configuration
Martin Mareš's avatar
Martin Mareš committed
729

Martin Mareš's avatar
Martin Mareš committed
730
<p>Each instance of the BGP corresponds to one neighboring router.
Pavel Machek's avatar
Pavel Machek committed
731
732
This allows to set routing policy and all the other parameters differently
for each neighbor using the following configuration parameters:
Martin Mareš's avatar
Martin Mareš committed
733
734
735
736
737
738
739

<descrip>
	<tag>local as <m/number/</tag> Define which AS we are part of. (Note that
	contrary to other IP routers, BIRD is able to act as a router located
	in multiple AS'es simultaneously, but in such cases you need to tweak
	the BGP paths manually in the filters to get consistent behavior.)
	This parameter is mandatory.
Pavel Machek's avatar
Pavel Machek committed
740

Martin Mareš's avatar
Martin Mareš committed
741
742
743
	<tag>neighbor <m/ip/ as <m/number/</tag> Define neighboring router
	this instance will be talking to and what AS it's located in. Unless
	you use the <cf/multihop/ clause, it must be directly connected to one
Martin Mareš's avatar
Martin Mareš committed
744
745
	of your router's interfaces. In case the neighbor is in the same AS
	as we are, we automatically switch to iBGP. This parameter is mandatory.
Pavel Machek's avatar
Pavel Machek committed
746

Martin Mareš's avatar
Martin Mareš committed
747
748
749
750
	<tag>multihop <m/number/ via <m/ip/</tag> Configure multihop BGP to a
	neighbor which is connected at most <m/number/ hops far and to which
	we should route via our direct neighbor with address <m/ip/.
	Default: switched off.
Pavel Machek's avatar
Pavel Machek committed
751

Martin Mareš's avatar
Martin Mareš committed
752
753
754
755
756
	<tag>next hop self</tag> Avoid calculation of the Next Hop attribute
	and always advertise our own source address (see below) as a next hop.
	This needs to be used only
	occasionally to circumvent misconfigurations of other routers.
	Default: disabled.
Pavel Machek's avatar
Pavel Machek committed
757

Martin Mareš's avatar
Martin Mareš committed
758
759
760
	<tag>source address <m/ip/</tag> Define local address we should use
	for next hop calculation. Default: the address of the local end
	of the interface our neighbor is connected to.
Pavel Machek's avatar
Pavel Machek committed
761

762
763
764
	<tag>password <m/string/</tag> Use this password for MD5 authentication
	of BGP sessions. Default: no authentication.

765
766
	<tag>rr client</tag> Be a route reflector and treat the neighbor as
	a route reflection client. Default: disabled.
767
768
769
770
771

	<tag>rr cluster id <m/IPv4 address/</tag> Route reflectors use cluster id
	to avoid route reflection loops. When there is one route reflector in a cluster
	it usually uses its router id as a cluster id, but when there are more route
	reflectors in a cluster, these need to be configured (using this option) to
Ondřej Zajíček's avatar
Ondřej Zajíček committed
772
773
	use a common cluster id. Clients in a cluster need not know their cluster
	id and this option is not allowed for them. Default: the same as router id.
774

775
776
777
778
779
780
781
782
783
	<tag>rs client</tag> Be a route server and treat the neighbor
	as a route server client. A route server is used as a
	replacement for full mesh EBGP routing in Internet exchange
	points in a similar way to route reflectors used in IBGP routing.
	Bird does not implement obsoleted RFC 1863, but uses ad-hoc implementation,
	which behaves like plain EBGP but reduces modifications to advertised route
	attributes to be transparent (for example does not prepend its AS number to
	AS PATH attribute and keep MED attribute). Default: disabled.

784
785
786
787
788
789
790
791
	<tag>enable as4 <m/switch/</tag> BGP protocol was designed to use 2B AS numbers
	and was extended later to allow 4B AS number. BIRD supports 4B AS extension,
	but by disabling this option it can be persuaded not to advertise it and
	to maintain old-style sessions with its neighbors. This might be useful for
	circumventing bugs in neighbor's implementation of 4B AS extension.
	Even when disabled (off), BIRD behaves internally as AS4-aware BGP router.
	Default: on.

792
793
794
795
796
797
798
799
800
801
802
803
804
	<tag>capabilities <m/switch/</tag> Use capability advertisement
	to advertise optional capabilities. This is standard behavior
	for newer BGP implementations, but there might be some older
	BGP implementations that reject such connection attempts.
	When disabled (off), features that request it (4B AS support)
	are also disabled. Default: on, with automatic fallback to
	off when received capability-related error.

	<tag>advertise ipv4 <m/switch/</tag> Advertise IPv4 multiprotocol capability.
	This is not a correct behavior according to the strict interpretation
	of RFC 4760, but it is widespread and required by some BGP
	implementations (Cisco and Quagga). This option is relevant
	to IPv4 mode with enabled capability advertisement only. Default: on.
805

Martin Mareš's avatar
Martin Mareš committed
806
807
	<tag>disable after error <m/switch/</tag> When an error is encountered (either
	locally or by the other side), disable the instance automatically
Pavel Machek's avatar
Pavel Machek committed
808
809
810
	and wait for an administrator to fix the problem manually. Default: off.

	<tag>hold time <m/number/</tag> Time in seconds to wait for a Keepalive
Martin Mareš's avatar
Martin Mareš committed
811
812
813
	message from the other side before considering the connection stale.
	Default: depends on agreement with the neighboring router, we prefer
	240 seconds if the other side is willing to accept it.
Pavel Machek's avatar
Pavel Machek committed
814

Martin Mareš's avatar
Martin Mareš committed
815
	<tag>startup hold time <m/number/</tag> Value of the hold timer used
Pavel Machek's avatar
Pavel Machek committed
816
	before the routers have a chance to exchange open messages and agree
Martin Mareš's avatar
Martin Mareš committed
817
	on the real value. Default: 240 seconds.
Pavel Machek's avatar
Pavel Machek committed
818

Martin Mareš's avatar
Martin Mareš committed
819
	<tag>keepalive time <m/number/</tag> Delay in seconds between sending
Pavel Machek's avatar
Pavel Machek committed
820
821
	of two consecutive Keepalive messages. Default: One third of the hold time.

Martin Mareš's avatar
Martin Mareš committed
822
	<tag>connect retry time <m/number/</tag> Time in seconds to wait before
Pavel Machek's avatar
Pavel Machek committed
823
824
	retrying a failed attempt to connect. Default: 120 seconds.

Martin Mareš's avatar
Martin Mareš committed
825
	<tag>start delay time <m/number/</tag> Delay in seconds between protocol
Pavel Machek's avatar
Pavel Machek committed
826
827
828
829
	startup and the first attempt to connect. Default: 5 seconds.

	<tag>error wait time <m/number/,<m/number/</tag> Minimum and maximum delay in seconds between a protocol
	failure (either local or reported by the peer) and automatic restart.
Martin Mareš's avatar
Martin Mareš committed
830
831
	Doesn't apply when <cf/disable after error/ is configured. If consecutive
	errors happen, the delay is increased exponentially until it reaches the maximum. Default: 60, 300.
Pavel Machek's avatar
Pavel Machek committed
832

Martin Mareš's avatar
Martin Mareš committed
833
834
835
	<tag>error forget time <m/number/</tag> Maximum time in seconds between two protocol
	failures to treat them as a error sequence which makes the <cf/error wait time/
	increase exponentially. Default: 300 seconds.
Pavel Machek's avatar
Pavel Machek committed
836

Martin Mareš's avatar
Martin Mareš committed
837
838
	<tag>path metric <m/switch/</tag> Enable comparison of path lengths
	when deciding which BGP route is the best one. Default: on.
Pavel Machek's avatar
Pavel Machek committed
839

Martin Mareš's avatar
Martin Mareš committed
840
841
	<tag>default bgp_med <m/number/</tag> Value of the Multiple Exit
	Discriminator to be used during route selection when the MED attribute
842
	is missing. Default: 0.
Pavel Machek's avatar
Pavel Machek committed
843

Martin Mareš's avatar
Martin Mareš committed
844
845
846
847
848
	<tag>default bgp_local_pref <m/number/</tag> Value of the Local Preference
	to be used during route selection when the Local Preference attribute
	is missing. Default: 0.
</descrip>

849
<sect1>Attributes
Martin Mareš's avatar
Martin Mareš committed
850

Pavel Machek's avatar
Pavel Machek committed
851
<p>BGP defines several route attributes. Some of them (those marked with `<tt/I/' in the
Martin Mareš's avatar
Martin Mareš committed
852
table below) are available on internal BGP connections only, some of them (marked
Pavel Machek's avatar
Pavel Machek committed
853
with `<tt/O/') are optional.
Martin Mareš's avatar
Martin Mareš committed
854
855

<descrip>
856
	<tag>bgppath <cf/bgp_path/</tag> Sequence of AS numbers describing the AS path
Pavel Machek's avatar
Pavel Machek committed
857
858
859
	the packet will travel through when forwarded according to the particular route. In case of 
	internal BGP it doesn't contain the number of the local AS.

Martin Mareš's avatar
Martin Mareš committed
860
861
862
	<tag>int <cf/bgp_local_pref/ [I]</tag> Local preference value used for
	selection among multiple BGP routes (see the selection rules above). It's
	used as an additional metric which is propagated through the whole local AS.
Pavel Machek's avatar
Pavel Machek committed
863

864
865
866
867
868
869
870
871
872
873
	<tag>int <cf/bgp_med/ [O]</tag> The Multiple Exit Discriminator of the route
	is an optional attribute which is used on on external (inter-AS) links to
	convey to an adjacent AS the optimal entry point into the local AS.
	The received attribute may be also propagated over internal BGP links
	(and this is default behavior). The attribute value is zeroed when a route
	is exported from a routing table to a BGP instance to ensure that the attribute
	received from a neighboring AS is not propagated to other neighboring ASes.
	A new value might be set in the export filter of a BGP instance.
	See RFC 4451<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4451.txt">
	for further discussion of BGP MED attribute.
Pavel Machek's avatar
Pavel Machek committed
874
875
876
877
878

	<tag>enum <cf/bgp_origin/</tag> Origin of the route: either <cf/ORIGIN_IGP/
	if the route has originated in an interior routing protocol or
	<cf/ORIGIN_EGP/ if it's been imported from the <tt>EGP</tt> protocol
	(nowadays it seems to be obsolete) or <cf/ORIGIN_INCOMPLETE/ if the origin
Martin Mareš's avatar
Martin Mareš committed
879
	is unknown.
Pavel Machek's avatar
Pavel Machek committed
880

Martin Mareš's avatar
Martin Mareš committed
881
882
883
884
885
886
	<tag>ip <cf/bgp_next_hop/</tag> Next hop to be used for forwarding of packets
	to this destination. On internal BGP connections, it's an address of the
	originating router if it's inside the local AS or a boundary router the
	packet will leave the AS through if it's an exterior route, so each BGP
	speaker within the AS has a chance to use the shortest interior path
	possible to this point.
Pavel Machek's avatar
Pavel Machek committed
887

Martin Mareš's avatar
Martin Mareš committed
888
	<tag>void <cf/bgp_atomic_aggr/ [O]</tag> This is an optional attribute
Pavel Machek's avatar
Pavel Machek committed
889
890
	which carries no value, but the sole presence of which indicates that the route
	has been aggregated from multiple routes by some router on the path from
Martin Mareš's avatar
Martin Mareš committed
891
	the originator.
Pavel Machek's avatar
Pavel Machek committed
892

Martin Mareš's avatar
Martin Mareš committed
893
894
895
896
897
<!-- we don't handle aggregators right since they are of a very obscure type
	<tag>bgp_aggregator</tag>
-->
	<tag>clist <cf/bgp_community/ [O]</tag> List of community values associated
	with the route. Each such value is a pair (represented as a <cf/pair/ data
Pavel Machek's avatar
Pavel Machek committed
898
899
	type inside the filters) of 16-bit integers, the first of them containing the number of the AS which defines
	the community and the second one being a per-AS identifier. There are lots
Martin Mareš's avatar
Martin Mareš committed
900
901
	of uses of the community mechanism, but generally they are used to carry
	policy information like "don't export to USA peers". As each AS can define
902
	its own routing policy, it also has a complete freedom about which community
Pavel Machek's avatar
Pavel Machek committed
903
	attributes it defines and what will their semantics be.
Martin Mareš's avatar
Martin Mareš committed
904
905
</descrip>

906
<sect1>Example
Martin Mareš's avatar
Martin Mareš committed
907

Martin Mareš's avatar
Martin Mareš committed
908
909
<p><code>
protocol bgp {
910
911
912
913
914
	local as 65000;			     # Use a private AS number
	neighbor 62.168.0.130 as 5588;	     # Our neighbor ...
	multihop 20 via 62.168.0.13;	     # ... which is connected indirectly
	export filter {			     # We use non-trivial export rules
		if source = RTS_STATIC then { # Export only static routes
915
916
917
		        # Assign our community
			bgp_community.add((65000,5678));
			# Artificially increase path length
Pavel Machek's avatar
Pavel Machek committed
918
			# by advertising local AS number twice
Ondřej Zajíček's avatar
Ondřej Zajíček committed
919
			if bgp_path ~ [= 65000 =] then	  
920
				bgp_path.prepend(65000);  
Martin Mareš's avatar
Martin Mareš committed
921
922
923
924
925
			accept;
		}
		reject;
	};
	import all;
926
	source address 62.168.0.1;	# Use a non-standard source address
Martin Mareš's avatar
Martin Mareš committed
927
928
929
}
</code>

930
<sect>Device
Martin Mareš's avatar
Martin Mareš committed
931

Pavel Machek's avatar
Pavel Machek committed
932
933
<p>The Device protocol is not a real routing protocol.  It doesn't generate
any routes and it only serves as a module for getting information about network
934
935
interfaces from the kernel.

936
<p>Except for very unusual circumstances, you probably should include
Pavel Machek's avatar
Pavel Machek committed
937
938
this protocol in the configuration since almost all other protocols
require network interfaces to be defined for them to work with.
939

Martin Mareš's avatar
Martin Mareš committed
940
<p>The only configurable thing is interface scan time:
941
942
943
944
945

<p><descrip>
	<tag>scan time <m/number/</tag> Time in seconds between two scans
	of the network interface list. On systems where we are notified about
	interface status changes asynchronously (such as newer versions of
Pavel Machek's avatar
Pavel Machek committed
946
947
	Linux), we need to scan the list only in order to avoid confusion by lost
	notification messages, so the default time is set to a large value.
948
949
950
</descrip>

<p>As the Device protocol doesn't generate any routes, it cannot have
951
any attributes. Example configuration looks really simple:
952
953
954
955
956
957
958

<p><code>
protocol device {
	scan time 10;		# Scan the interfaces often
}
</code>

959
<sect>Direct
Martin Mareš's avatar
Martin Mareš committed
960

961
962
963
964
965
966
<p>The Direct protocol is a simple generator of device routes for all the
directly connected networks according to the list of interfaces provided
by the kernel via the Device protocol.

<p>It's highly recommended to include this protocol in your configuration
unless you want to use BIRD as a route server or a route reflector, that is
Pavel Machek's avatar
Pavel Machek committed
967
on a machine which doesn't forward packets itself and only participates in
968
969
distribution of routing information.

Pavel Machek's avatar
Pavel Machek committed
970
<p>The only configurable thing about direct is what interfaces it watches:
971
972

<p><descrip>
973
	<tag>interface <m/pattern [, ...]/</tag> By default, the Direct
974
975
976
977
978
979
980
981
982
	protocol will generate device routes for all the interfaces
	available. If you want to restrict it to some subset of interfaces
	(for example if you're using multiple routing tables for policy
	routing and some of the policy domains don't contain all interfaces),
	just use this clause.
</descrip>

<p>Direct device routes don't contain any specific attributes.

983
<p>Example config might look like this:
984
985
986
987
988
989
990

<p><code>
protocol direct {
	interface "-arc*", "*";		# Exclude the ARCnets
}
</code>

991
<sect>Kernel
Martin Mareš's avatar
Martin Mareš committed
992

993
<p>The Kernel protocol is not a real routing protocol. Instead of communicating
Pavel Machek's avatar
Pavel Machek committed
994
995
the with other routers in the network, it performs synchronization of BIRD's routing
tables with the OS kernel. Basically, it sends all routing table updates to the kernel
996
997
and from time to time it scans the kernel tables to see whether some routes have
disappeared (for example due to unnoticed up/down transition of an interface)
Martin Mareš's avatar
Martin Mareš committed
998
or whether an `alien' route has been added by someone else (depending on the
Pavel Machek's avatar
Pavel Machek committed
999
<cf/learn/ switch, such routes are either deleted or accepted to our
Martin Mareš's avatar
Martin Mareš committed
1000
table).
1001
1002
1003

<p>If your OS supports only a single routing table, you can configure only one
instance of the Kernel protocol. If it supports multiple tables (in order to
Pavel Machek's avatar
Pavel Machek committed
1004
allow policy routing; such an OS is for example Linux 2.2), you can run as many instances as you want, but each of
1005
1006
1007
them must be connected to a different BIRD routing table and to a different
kernel table.

1008
<sect1>Configuration
1009
1010
1011

<p><descrip>
	<tag>persist <m/switch/</tag> Tell BIRD to leave all its routes in the
1012
	routing tables when it exits (instead of cleaning them up).
Pavel Machek's avatar
Pavel Machek committed
1013
	<tag>scan time <m/number/</tag> Time in seconds between two consecutive scans of the
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
	kernel routing table.
	<tag>learn <m/switch/</tag> Enable learning of routes added to the kernel
	routing tables by other routing daemons or by the system administrator.
	This is possible only on systems which support identification of route
	authorship.
	<tag>kernel table <m/number/</tag> Select which kernel table should
	this particular instance of the Kernel protocol work with. Available
	only on systems supporting multiple routing tables.
</descrip>

Pavel Machek's avatar
Pavel Machek committed
1024
<p>The Kernel protocol doesn't define any route attributes.
1025
<p>A simple configuration can look this way:
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045