bird.sgml 82 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
Ondrej Filip <it/&lt;feela@network.cz&gt;/,
Pavel Machek <it/&lt;pavel@ucw.cz&gt;/,
Ondrej Filip's avatar
Ondrej Filip committed
26
27
Martin Mares <it/&lt;mj@ucw.cz&gt;/,
Ondrej Zajicek <it/&lt;santiago@crfreenet.org&gt;/
28
</author>
29
30

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

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

<!-- Begin the document -->

39
<chapt>Introduction
40

41
<sect>What is BIRD
42

43
44
45
46
47
48
49
50
51
52
53
<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
54
communicate with each other. They also communicate with the other routers in the Internet to discover
55
the topology of the network which allows them to find optimal (in terms of some metric) rules for
56
forwarding of packets (which are called routing tables) and to adapt themselves to the
57
58
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
59
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 
60
61
62
63
64
65
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
66
67
68
69
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.
70
71

<p>BIRD is an Internet Routing Daemon designed to avoid all of these shortcomings,
Martin Mareš's avatar
Martin Mareš committed
72
to support all the routing technology used in the today's Internet or planned to be
73
74
75
76
77
78
79
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)
80
	<item>the Routing Information Protocol (RIPv2)
81
	<item>the Open Shortest Path First protocol (OSPFv2)
82
	<item>a virtual protocol for exchange of routes between different routing tables on a single host
83
84
85
86
	<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
87
		and notify BIRD to re-read it and it will smoothly switch itself
88
89
		to the new configuration, not disturbing routing protocols
		unless they are affected by the configuration changes)
90
	<item>a powerful language for route filtering
91
92
93
</itemize>

<p>BIRD has been developed at the Faculty of Math and Physics, Charles University, Prague,
94
Czech Republic as a student project. It can be freely distributed under the terms of the GNU General
95
96
97
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
98
99
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.
100

101
<sect>Installing BIRD
102

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

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

113
114
115
116
117
<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.
118
119
<file>/usr/local</file>.

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

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

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

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

131
	<tag>-D <m/filename of debug log/</tag>
132
133
134
135
	log debugging information to given file instead of stderr.

	<tag>-p</tag>
	just parse the config file and exit.
Pavel Machek's avatar
Pavel Machek committed
136
137

	<tag>-s <m/name of communication socket/</tag>
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
138
	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
139
</descrip>
140

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

143
144
<chapt>About routing tables

145
146
147
<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
148
149
150
known routes. Each route consists of:

<itemize>
151
152
153
	<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
154
	<item>IP address of router we should forward the packets to
155
156
	using this route
	<item>other attributes common to all routes
157
158
	<item>dynamic attributes defined by protocols which may or
	may not be present (typically protocol metrics)
159
160
</itemize>

161
162
163
164
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
165
there are more entries with the same preference and they are from the same
166
167
168
169
170
171
172
173
174
175
176
177
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.
178

179
<chapt>Configuration
Pavel Machek's avatar
Pavel Machek committed
180

181
<sect>Introduction
182

Martin Mareš's avatar
Fixes.    
Martin Mareš committed
183
<p>BIRD is configured using a text configuration file. Upon startup, BIRD reads <it/prefix/<file>/etc/bird.conf</file> (unless the
184
185
186
187
<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.
188
189
190
191

<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
192
193
is case sensitive.

194
195
196
<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.
197

198

199
<code>
200
protocol kernel {
Pavel Machek's avatar
Pavel Machek committed
201
	persist;		# Don't remove routes on BIRD shutdown
202
203
204
205
206
207
208
209
210
211
212
	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;
Ondřej Zajíček's avatar
Ondřej Zajíček committed
213
	interface "*";
214
}
215
</code>
216

217

218
<sect>Global options
Pavel Machek's avatar
Pavel Machek committed
219

220
<p><descrip>
221
	<tag>log "<m/filename/"|syslog|stderr all|{ <m/list of classes/ }</tag> 
222
	Set logging of messages having the given class (either <cf/all/ or <cf/{
223
	error, trace }/ etc.) into selected destination. Classes are:
224
	<cf/info/, <cf/warning/, <cf/error/ and <cf/fatal/ for messages about local problems,
225
	<cf/debug/ for debugging messages, 
226
227
228
	<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
229
	<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
230
	destinations. Default: log everything to the system log.
231

232
	<tag>debug protocols all|off|{ states, routes, filters, interfaces, events, packets }</tag>
Pavel Machek's avatar
Pavel Machek committed
233
234
235
236
237
238
	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.
239

240
	<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
241
	in the following chapter. 
242

243
	<tag>function <m/name/ (<m/parameters/) <m/local variables/ { <m/commands/ }</tag> Define a function. You can learn more
244
	about functions in the following chapter.
245
 
246
	<tag>protocol rip|ospf|bgp|... <m/[name]/ { <m>protocol options</m> }</tag> Define a protocol
247
	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
248
	about configuring protocols in their own chapters. You can run more than one instance of
Pavel Machek's avatar
Pavel Machek committed
249
	most protocols (like RIP or BGP). By default, no instances are configured.
250

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

Pavel Machek's avatar
Pavel Machek committed
254
	<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. 
255

256
	<tag>listen bgp [address <m/address/] [port <m/port/] [v6only]</tag>
Ondřej Zajíček's avatar
Ondřej Zajíček committed
257
258
259
260
261
262
263
264
	This option allows to specify address and port where BGP
	protocol should listen. It is global option as listening
	socket is common to all BGP instances. Default is to listen on
	all addresses (0.0.0.0) and port 179. In IPv6 mode, option
	<cf/v6only/ can be used to specify that BGP socket should
	listen to IPv6 connections only. This is needed if you want to
	run both bird and bird6 on the same port.

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

269
	<tag>eval <m/expr/</tag> Evaluates given filter expression. It
270
	is used by us for testing of filters.
271
272
</descrip>

273
<sect>Protocol options
274

Pavel Machek's avatar
Pavel Machek committed
275
276
277
<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).
278

Pavel Machek's avatar
Pavel Machek committed
279
280
281
282
283
<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").
284

Pavel Machek's avatar
Pavel Machek committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<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.

303
304
305
306
	<tag>router id <m/IPv4 address/</tag> This option can be used to override global
	router id for a given protocol. This option is not yet implemented for OSPF
	protocol. Default: uses global router id.

Pavel Machek's avatar
Pavel Machek committed
307
	<tag>import all | none | filter <m/name/ | filter { <m/filter commands/ } | where <m/filter expression/</tag> 
308
	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/.
309

310
311
	<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
312

313
314
315
316
	<tag>description "<m/text/"</tag> This is an optional
	description of the protocol. It is displayed as a part of the
	output of 'show route all' command.

317
	<tag>table <m/name/</tag> Connect this protocol to a non-default routing table.
318
319
</descrip>

320
<p>There are several options that give sense only with certain protocols:
321
322

<descrip>
Ondřej Zajíček's avatar
Ondřej Zajíček committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
	<tag><label id="dsc-iface">interface [-] [ "<m/mask/" ] [ <m/prefix/ ] [, ...] [ { <m/option/ ; [...] } ]</tag>

	Specifies a set of interfaces on which the protocol is activated with
	given interface-specific options. A set of interfaces specified by one
	interface option is described using an interface pattern. The
	interface pattern consists of a sequence of clauses (separted by
	commas), each clause may contain a mask, a prefix, or both of them. An
	interface matches the clause if its name matches the mask (if
	specified) and its address matches the prefix (if specified). Mask is
	specified as shell-like pattern.

	An interface matches the pattern if it matches any of its
	clauses. If the clause begins with <cf/-/, matching interfaces are
	excluded. Patterns are parsed left-to-right, thus
	<cf/interface "eth0", -"eth*", "*";/ means eth0 and all
	non-ethernets.

	An interface option can be used more times with different
	interfaces-specific options, in that case for given interface
	the first matching interface option is used.
	
	This option is allowed in Direct, OSPF and RIP protocols,
	but in OSPF protocol it is used in <cf/area/ subsection.

	Default: none.

	Examples:

	<cf>interface "*" { type broadcast; };</cf> - start the protocol on all interfaces with
	<cf>type broadcast</cf> option.

	<cf>interface "eth1", "eth4", "eth5" { type pointopoint; };</cf> - start the protocol
	on enumerated interfaces with <cf>type pointopoint</cf> option.
	
	<cf>interface -192.168.1.0/24, 192.168.0.0/16;</cf> - start the protocol on all
	interfaces that have address from 192.168.0.0/16, but not
	from 192.168.1.0/24.

	<cf>interface -192.168.1.0/24, 192.168.0.0/16;</cf> - start the protocol on all
	interfaces that have address from 192.168.0.0/16, but not
	from 192.168.1.0/24.

	<cf>interface "eth*" 192.168.1.0/24;</cf> - start the protocol on all
	ethernet interfaces that have address from 192.168.1.0/24.

	<tag><label id="dsc-pass">password "<m/password/" [ { id <m/num/; generate from <m/time/; generate to <m/time/; accept from <m/time/; accept to <m/time/; } ]</tag>
	Specifies a password that can be used by the protocol. Password option can
	be used more times to specify more passwords. If more passwords are
	specified, it is a protocol-dependent decision which one is really
	used. Specifying passwords does not mean that authentication is
	enabled, authentication can be enabled by separate, protocol-dependent
	<cf/authentication/ option.
	
	This option is allowed in OSPF and RIP protocols. BGP has also
	<cf/password/ option, but it is slightly different and described
	separately.

	Default: none.
</descrip>

<p>Password option can contain section with some (not necessary all) password sub-options:

<descrip>
	<tag>id <M>num</M></tag>
	 ID of the password, (0-255). If it's not used, BIRD will choose
	 ID based on an order of the password item in the interface. For
	 example, second password item in one interface will have default
	 ID 2. ID is used by some routing protocols to identify which
	 password was used to authenticate protocol packets.

	<tag>generate from "<m/time/"</tag>
	 The start time of the usage of the password for packet signing.
	 The format of <cf><m/time/</cf> is <tt>dd-mm-yyyy HH:MM:SS</tt>.

	<tag>generate to "<m/time/"</tag>
	 The last time of the usage of the password for packet signing.

	<tag>accept from "<m/time/"</tag>
	 The start time of the usage of the password for packet verification.
Pavel Machek's avatar
Pavel Machek committed
402

Ondřej Zajíček's avatar
Ondřej Zajíček committed
403
404
	<tag>accept to "<m/time/"</tag>
	 The last time of the usage of the password for packet verification.
405
</descrip>
406

Pavel Machek's avatar
Pavel Machek committed
407
<chapt>Remote control
Pavel Machek's avatar
Pavel Machek committed
408

409
<p>You can use the command-line client <file>birdc</file> to talk with
410
a running BIRD. Communication is done using a <file/bird.ctl/ UNIX domain
411
socket (unless changed with the <tt/-s/ option given to both the server and
412
413
414
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
415
reconfigure. Press <tt/?/ at any time to get online help. Option
416
<tt/-v/ can be passed to the client, to make it dump numeric return
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
417
codes along with the messages. You do not necessarily need to use <file/birdc/ to talk to BIRD, your
418
own applications could do that, too -- the format of communication between
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
419
BIRD and <file/birdc/ is stable (see the programmer's documentation).
Pavel Machek's avatar
Pavel Machek committed
420

Ondřej Zajíček's avatar
Ondřej Zajíček committed
421
422
423
Many commands have the <m/name/ of the protocol instance as an argument.
This argument can be omitted if there exists only a single instance.

Pavel Machek's avatar
Pavel Machek committed
424
<p>Here is a brief list of supported functions:
425
426

<descrip>
Pavel Machek's avatar
Pavel Machek committed
427
428
429
430
	<tag>dump resources|sockets|interfaces|neighbors|attributes|routes|protocols</tag>
	Dump contents of internal data structures to the debugging output.

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

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

Ondřej Zajíček's avatar
Ondřej Zajíček committed
436
437
438
439
440
441
442
443
444
445
446
447
448
	<tag>show ospf interface [<m/name/] ["<m/interface/"]</tag>
	Show detailed information about OSPF interfaces.

	<tag>show ospf neighbors [<m/name/] ["<m/interface/"]</tag>
	Show a list of OSPF neighbors and a state of adjacency to them.

	<tag>show ospf state [<m/name/]</tag>
	Show detailed information about OSPF areas based on a content of link-state database.
	It shows network topology,  aggregated networks and routers from other areas and external routes.

	<tag>show ospf topology [<m/name/]</tag>
	Show a topology of OSPF areas based on a content of link-state database.
	It is just a stripped-down version of 'show ospf state'.
449

Pavel Machek's avatar
Pavel Machek committed
450
	<tag>show static [<m/name/]</tag>
Ondřej Zajíček's avatar
Ondřej Zajíček committed
451
452
	Show detailed information about static routes.

Pavel Machek's avatar
Pavel Machek committed
453
	<tag>show interfaces [summary]</tag>
454
	Show the list of interfaces. For each interface, print its type, state, MTU and addresses assigned. 
Pavel Machek's avatar
Pavel Machek committed
455
456

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

459
	<tag>show route [[for] <m/prefix/|<m/IP/] [table <m/sym/] [filter <m/f/|where <m/c/] [(export|preexport) <m/p/] [protocol <m/p/] [<m/options/]</tag>
Pavel Machek's avatar
Pavel Machek committed
460
	Show contents of a routing table (by default of the main one),
461
	that is routes, their metrics and (in case the <cf/all/ switch is given)
Pavel Machek's avatar
Pavel Machek committed
462
463
464
465
466
467
468
469
470
471
472
473
	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>).
474
475
476
	The <cf/export/ and <cf/preexport/ switches ask for printing of entries
	that are exported to the specified protocol. With <cf/preexport/, the
	export filter of the protocol is skipped.
Pavel Machek's avatar
Pavel Machek committed
477

478
479
480
	<p>You can also select just routes added by a specific protocol.
	<cf>protocol <m/p/</cf>.

Pavel Machek's avatar
Pavel Machek committed
481
482
483
484
485
	<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>
486
	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
487

Ondřej Zajíček's avatar
Ondřej Zajíček committed
488
489
490
491
492
	<tag>configure [soft] ["<m/config file/"]</tag>
	Reload configuration from a given file. BIRD will smoothly
	switch itself to the new configuration, protocols are
	reconfigured if possible, restarted otherwise. Changes in
	filters usualy lead to restart of affected protocols. If
493
	<cf/soft/ option is used, changes in filters does not cause
Ondřej Zajíček's avatar
Ondřej Zajíček committed
494
495
496
497
	BIRD to restart affected protocols, therefore already accepted
	routes (according to old filters) would be still propagated,
	but new routes would be processed according to the new
	filters.
Pavel Machek's avatar
Pavel Machek committed
498
499
500

	<tag/down/
	Shut BIRD down.
501

Pavel Machek's avatar
Pavel Machek committed
502
	<tag>debug <m/protocol/|<m/pattern/|all all|off|{ states | routes | filters | events | packets }</tag>
503
504
	Control protocol debugging.
</descrip>
Pavel Machek's avatar
Pavel Machek committed
505

506
<chapt>Filters
507

508
<sect>Introduction
509

510
511
512
513
<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>. 
514

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

520
<code>
521
522
523
524
525
526
527
528
529
530
531
532
533
534
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";
}
535
</code>
536

537
<p>As you can see, a filter has a header, a list of local variables, and a body. The header consists of
538
539
540
541
542
543
544
545
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
546
look like this:
547
548
549
550
551
552
553
554
555
556
557
558
559
560

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

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

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

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

572
573
<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
574
575
576
577
578
579
580
581
582
583
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 ?
584
show route [<prefix>] [table <t>] [filter <f>] [all] [primary]...
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
585
bird> show route filter { if 127.0.0.5 &tilde; net then accept; }
Pavel Machek's avatar
Pavel Machek committed
586
587
588
589
127.0.0.0/8        dev lo [direct1 23:21] (240)
bird>
</code>

590
<sect>Data types
591

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

<descrip>
596
	<tag/bool/ This is a boolean type, it can have only two values, <cf/true/ and
597
	  <cf/false/. Boolean is the only type you can use in <cf/if/
598
	  statements.
599

600
601
	<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.
602

603
	<tag/pair/ This is a pair of two short integers. Each component can have values from 0 to
604
605
	  65535. Literals of this type are written as <cf/(1234,5678)/. The same syntax can also be
	  used to construct a pair from two arbitrary integer expressions (for example <cf/(1+2,a)/).
606

607
608
609
	<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
610
	  are written as <cf/"This is a string constant"/.
611

612
	<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
613
	  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>
614
	  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
615
	  address. So <cf/1.2.3.4.mask(8) = 1.0.0.0/ is true.
616

617
	<tag/prefix/ This type can hold a network prefix consisting of IP address and prefix length. Prefix literals are written as
618
	  <cf><M>ipaddress</M>/<M>pxlen</M></cf>, or
619
620
621
622
	  <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.
623

624
	<tag/int|ip|prefix|pair|enum set/
625
626
	  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>
627
	  [ 1, 2, 5..7 ]</cf>. As you can see, both simple values and ranges are permitted in
628
629
630
631
	  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>.
Ondřej Zajíček's avatar
Ondřej Zajíček committed
632
633
634
	  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 &lt;= ip1 &lt;= len2</cf>.
	  A valid prefix pattern has to satisfy <cf>low &lt;= high</cf>, but <cf/pxlen/ is not constrained by <cf/low/
635
636
637
638
	  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
Ondřej Zajíček's avatar
Ondřej Zajíček committed
639
	  <cf><m>address</m>/<m/len/{<m/len/,<m/maxlen/}</cf> (where <cf><m>maxlen</m></cf> is 32 for IPv4 and 128 for IPv6), 
Ondřej Zajíček's avatar
Ondřej Zajíček committed
640
641
642
	  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).
643
644
645
646
647

	  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
Ondřej Zajíček's avatar
Ondřej Zajíček committed
648
	  <cf>1.2.3.4</cf>. <cf>1.2.0.0/16 &tilde; [ 1.0.0.0/8{15,17} ]</cf> is true,
649
650
651
	  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
652
	  in BIRD as <cf>10.0.0.0/8{16,24}</cf>, <cf>192.168.0.0/16 le 24</cf> as 
653
654
	  <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>.
655
656

	<tag/enum/
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
657
	  Enumeration types are fixed sets of possibilities. You can't define your own
658
	  variables of such type, but some route attributes are of enumeration
659
	  type. Enumeration types are incompatible with each other.
660
661

	<tag/bgppath/
662
	  BGP path is a list of autonomous system numbers. You can't write literals of this type.
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
	  There are several special operators on bgppaths:

	  <cf><m/P/.first</cf> returns the first ASN (the neighbor ASN) in path <m/P/.

          <cf><m/P/.last</cf> returns the last ASN (the source ASN) in path <m/P/.

	  Both <cf/first/ and <cf/last/ return zero if there is no appropriate ASN,
          for example if the path contains an AS set element as the first (or the last) part.

          <cf><m/P/.len</cf> returns the length of path <m/P/.

          <cf>prepend(<m/P/,<m/A/)</cf> prepends ASN <m/A/ to path <m/P/ and returns the result.
          Statement <cf><m/P/ = prepend(<m/P/, <m/A/);</cf> can be shortened to
          <cf><m/P/.prepend(<m/A/);</cf> if <m/P/ is appropriate route attribute
          (for example <cf/bgp_path/).
678

Pavel Machek's avatar
Pavel Machek committed
679
680
	<tag/bgpmask/
	  BGP masks are patterns used for BGP path matching
681
	  (using <cf>path &tilde; [= 2 3 5 * =]</cf> syntax). The masks
Pavel Machek's avatar
Pavel Machek committed
682
	  resemble wildcard patterns as used by UNIX shells. Autonomous
Ondřej Zajíček's avatar
Ondřej Zajíček committed
683
	  system numbers match themselves, <cf/*/ matches any (even empty)
684
685
	  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:
686
687
	  <tt>bgp_path &tilde; [= * 4 3 * =]</tt> is true, but 
	  <tt>bgp_path &tilde; [= * 4 5 * =]</tt> is false.
688
689
	  BGP mask expressions can also contain integer expressions enclosed in parenthesis
	  and integer variables, for example <tt>[= * 4 (1+2) a =]</tt>.
690
	  There is also old syntax that uses / .. / instead of [= .. =] and ? instead of *.
691

692
	<tag/clist/ 
693
	  Community list is similar to set of pairs,
694
	  except that unlike other sets, it can be modified.
695
	  There exist no literals of this type.
696
697
698
699
700
701
702
703
704
	  There are two special operators on clists:

          <cf>add(<m/C/,<m/P/)</cf> adds pair <m/P/ to clist <m/C/ and returns the result.

          <cf>delete(<m/C/,<m/P/)</cf> deletes pair <m/P/ from clist <m/C/ and returns the result.

          Statement <cf><m/C/ = add(<m/C/, <m/P/);</cf> can be shortened to
          <cf><m/C/.add(<m/P/);</cf> if <m/C/ is appropriate route attribute
          (for example <cf/bgp_community/). Similarly for <cf/delete/.
705

706
707
</descrip>

708
<sect>Operators
709

710
<p>The filter language supports common integer operators <cf>(+,-,*,/)</cf>, parentheses <cf/(a*(b+c))/, comparison
Martin Mareš's avatar
Fixes.    
Martin Mareš committed
711
<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;/). 
712
Special operators include <cf/&tilde;/ for "is element of a set" operation - it can be
713
714
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
715
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).
716

717

718
<sect>Control structures
719

720
721
<p>Filters support two control structures: conditions and case switches. 

722
<p>Syntax of a condition is: <cf>if
723
<M>boolean expression</M> then <M>command1</M>; else <M>command2</M>;</cf> and you can use <cf>{
724
725
<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.
726

727
728
729
730
731
<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.
732

733
<p>Here is example that uses <cf/if/ and <cf/case/ structures:
Pavel Machek's avatar
Pavel Machek committed
734
735
736
737
738
739

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

Pavel Machek's avatar
Pavel Machek committed
742
743
744
745
if 1234 = i then printn "."; else { 
  print "not 1234"; 
  print "You need {} around multiple commands"; 
}
Pavel Machek's avatar
Pavel Machek committed
746
747
</code>

748
<sect>Route attributes
749

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

Pavel Machek's avatar
Pavel Machek committed
755
<descrip>
Martin Mareš's avatar
Martin Mareš committed
756
	<tag><m/prefix/ net</tag>
757
	Network the route is talking about. Read-only. (See the chapter about routing tables.)
758
759

	<tag><m/enum/ scope</tag>
Pavel Machek's avatar
Pavel Machek committed
760
	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).
761

Martin Mareš's avatar
Martin Mareš committed
762
	<tag><m/int/ preference</tag>
Ondřej Zajíček's avatar
Ondřej Zajíček committed
763
	Preference of the route. Valid values are 0-65535. (See the chapter about routing tables.)
Pavel Machek's avatar
Pavel Machek committed
764

Martin Mareš's avatar
Martin Mareš committed
765
	<tag><m/ip/ from</tag>
766
	The router which the route has originated from. Read-only.
767
	
Martin Mareš's avatar
Martin Mareš committed
768
	<tag><m/ip/ gw</tag>
769
	Next hop packets routed using this route should be forwarded to.
770

771
772
773
	<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
774
	<tag><m/enum/ source</tag>
Ondřej Filip's avatar
Ondřej Filip committed
775
	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
776

Martin Mareš's avatar
Martin Mareš committed
777
	<tag><m/enum/ cast</tag>
778
	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
779

Martin Mareš's avatar
Martin Mareš committed
780
	<tag><m/enum/ dest</tag>
Pavel Machek's avatar
Pavel Machek committed
781
	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
782
</descrip>
783

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

786
<sect>Other statements
787

788
<p>The following statements are available:
789
790

<descrip>
791
	<tag><m/variable/ = <m/expr/</tag> Set variable to a given value.
792

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

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

797
798
799
	<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.
800
801

	<tag>quitbird</tag>
802
	Terminates BIRD. Useful when debugging the filter interpreter.
803
804
</descrip>

805
<chapt>Protocols
806

807
<sect>BGP
Martin Mareš's avatar
Martin Mareš committed
808

Martin Mareš's avatar
Martin Mareš committed
809
<p>The Border Gateway Protocol is the routing protocol used for backbone
Pavel Machek's avatar
Pavel Machek committed
810
level routing in the today's Internet. Contrary to the other protocols, its convergence
Martin Mareš's avatar
Martin Mareš committed
811
812
813
814
815
816
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
817
818
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
819
820
821
822
823
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
824
825
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
826
827
route) in order to avoid routing loops.

Martin Mareš's avatar
Martin Mareš committed
828
<p>BIRD supports all requirements of the BGP4 standard as defined in
829
830
831
832
833
834
835
836
837
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">),
838
839
multiprotocol extensions
(RFC 4760<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4760.txt">),
840
841
842
843
and 4B AS numbers 
(RFC 4893<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4893.txt">).


Martin Mareš's avatar
Martin Mareš committed
844
845
846
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
847
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
848
849
850
and applied to IPv6 according to
RFC 2545<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc2545.txt">.

851
<sect1>Route selection rules
Martin Mareš's avatar
Martin Mareš committed
852
853
854

<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
855
and they are implemented according to the following algorithm. It starts the first
Martin Mareš's avatar
Martin Mareš committed
856
857
858
859
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
860
	<item>Prefer route with the highest Local Preference attribute.
Martin Mareš's avatar
Martin Mareš committed
861
862
863
	<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
864
865
	<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
866
867
	advertising router.
</itemize>
Martin Mareš's avatar
Martin Mareš committed
868

869
<sect1>Configuration
Martin Mareš's avatar
Martin Mareš committed
870

Martin Mareš's avatar
Martin Mareš committed
871
<p>Each instance of the BGP corresponds to one neighboring router.
Pavel Machek's avatar
Pavel Machek committed
872
873
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
874
875
876
877
878
879
880

<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
881

Martin Mareš's avatar
Martin Mareš committed
882
883
884
	<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
885
886
	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
887

Martin Mareš's avatar
Martin Mareš committed
888
889
890
891
	<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
892

893
894
895
896
	<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.
Martin Mareš's avatar
Martin Mareš committed
897
	Default: disabled.
Pavel Machek's avatar
Pavel Machek committed
898

899
900
901
902
903
904
905
	<tag>missing lladdr self|drop|ignore</tag>Next Hop attribute
	in BGP-IPv6 sometimes contains just the global IPv6 address,
	but sometimes it has to contain both global and link-local
	IPv6 addresses. This option specifies what to do if BIRD have
	to send both addresses but does not know link-local address.
	This situation might happen when routes from other protocols
	are exported to BGP, or when improper updates are received
906
907
908
	from BGP peers.  <cf/self/ means that BIRD advertises its own
	local address instead. <cf/drop/ means that BIRD skips that
	prefixes and logs error. <cf/ignore/ means that BIRD ignores
909
	the problem and sends just the global address (and therefore
910
911
912
	forms improper BGP update). Default: <cf/self/, unless BIRD
	is configured as a route server (option <cf/rs client/), in
	that case default is <cf/drop/, because route servers usually
913
914
	does not forward packets ifselves.
	
Martin Mareš's avatar
Martin Mareš committed
915
916
917
	<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
918

919
	<tag>password <m/string/</tag> Use this password for MD5 authentication
920
921
	of BGP sessions. Default: no authentication. Password has to be set by
	external utility (e.g. setkey(8)) on BSD systems.
922

Ondřej Zajíček's avatar
Ondřej Zajíček committed
923
924
925
926
927
	<tag>passive <m/switch/</tag> Standard BGP behavior is both
        initiating outgoing connections and accepting incoming
        connections. In passive mode, outgoing connections are not
        initiated. Default: off.

928
929
	<tag>rr client</tag> Be a route reflector and treat the neighbor as
	a route reflection client. Default: disabled.
930
931
932
933
934

	<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
935
936
	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.
937

938
939
940
941
	<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.
942
	BIRD does not implement obsoleted RFC 1863, but uses ad-hoc implementation,
943
944
945
946
	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.

947
948
949
950
951
952
953
954
	<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.

955
956
957
958
959
960
961
962
963
964
965
966
967
	<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.
968

969
970
971
972
	<tag>route limit <m/number/</tag> The maximal number of routes
	that may be imported from the protocol. If the route limit is
	exceeded, the connection is closed with error. Default: no limit.

Martin Mareš's avatar
Martin Mareš committed
973
974
	<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
975
976
977
	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
978
979
980
	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
981

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

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

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

Martin Mareš's avatar
Martin Mareš committed
992
	<tag>start delay time <m/number/</tag> Delay in seconds between protocol
Pavel Machek's avatar
Pavel Machek committed
993
994
995
996
	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
997
998
	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
999

Martin Mareš's avatar
Martin Mareš committed
1000
1001
1002
	<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
1003

Martin Mareš's avatar
Martin Mareš committed
1004
1005
	<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
1006

1007
1008
1009
1010
1011
	<tag>prefer older <m/switch/</tag> Standard route selection algorithm
	breaks ties by comparing router IDs. This changes the behavior
	to prefer older routes (when both are external and from different
	peer). For details, see RFC 5004. Default: off.

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

Martin Mareš's avatar
Martin Mareš committed
1016
1017
1018
1019
1020
	<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>

1021
<sect1>Attributes
Martin Mareš's avatar
Martin Mareš committed
1022

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

<descrip>
1028
	<tag>bgppath <cf/bgp_path/</tag> Sequence of AS numbers describing the AS path
Pavel Machek's avatar
Pavel Machek committed
1029
1030
1031
	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
1032
1033
1034
	<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
1035

1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
	<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
1046
1047
1048
1049
1050

	<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
1051
	is unknown.
Pavel Machek's avatar
Pavel Machek committed
1052

Martin Mareš's avatar
Martin Mareš committed
1053
1054
1055
1056
1057
1058
	<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
1059

Martin Mareš's avatar
Martin Mareš committed
1060
	<tag>void <cf/bgp_atomic_aggr/ [O]</tag> This is an optional attribute
Pavel Machek's avatar
Pavel Machek committed
1061
1062
	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
1063
	the originator.
Pavel Machek's avatar
Pavel Machek committed
1064

Martin Mareš's avatar
Martin Mareš committed
1065
1066
1067
1068
1069
<!-- 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
1070
1071
	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
1072
1073
	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
1074
	its own routing policy, it also has a complete freedom about which community
Pavel Machek's avatar
Pavel Machek committed
1075
	attributes it defines and what will their semantics be.
Martin Mareš's avatar
Martin Mareš committed
1076
1077
</descrip>

1078
<sect1>Example
Martin Mareš's avatar
Martin Mareš committed
1079

Martin Mareš's avatar
Martin Mareš committed
1080
1081
<p><code>
protocol bgp {
1082
1083
1084
1085
1086
	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
1087
1088
1089
		        # Assign our community
			bgp_community.add((65000,5678));
			# Artificially increase path length
Pavel Machek's avatar
Pavel Machek committed
1090
			# by advertising local AS number twice
Ondřej Zajíček's avatar
Ondřej Zajíček committed
1091
			if bgp_path ~ [= 65000 =] then	  
1092
				bgp_path.prepend(65000);  
Martin Mareš's avatar
Martin Mareš committed
1093
1094
1095
1096