bird.sgml 89.3 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;/,
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, OSPFv3)
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
98
tested under Linux 2.0 to 2.6, and then ported to FreeBSD, NetBSD and OpenBSD, porting to other
Ondřej Filip's avatar
Ondřej Filip committed
99
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
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
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
	log debugging information to given file instead of stderr.

	<tag>-p</tag>
Ondřej Zajíček's avatar
Ondřej Zajíček committed
135 136
	just parse the config file and exit. Return value is zero if the config file is valid,
	nonzero if there are some errors.
Pavel Machek's avatar
Pavel Machek committed
137 138

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

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

144 145
<chapt>About routing tables

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

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

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

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

182
<sect>Introduction
183

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

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

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

199

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

218

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

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

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

242 243 244 245 246 247 248 249
	<tag>mrtdump "<m/filename/"</tag>
	Set MRTdump file name. This option must be specified to allow MRTdump feature.
	Default: no dump file.

	<tag>mrtdump protocols all|off|{ states, messages }</tag>
	Set global defaults of MRTdump options. See <cf/mrtdump/ in the following section.
	Default: off.

250
	<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
251
	in the following chapter. 
252

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

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

Pavel Machek's avatar
Pavel Machek committed
264
	<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. 
265

266
	<tag>listen bgp [address <m/address/] [port <m/port/] [v6only]</tag>
Ondřej Zajíček's avatar
Ondřej Zajíček committed
267 268 269 270 271 272 273 274
	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.

275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
	<tag>timeformat route|protocol|base|log "<m/format1/" [<m/limit> "<m/format2/"]</tag>
	This option allows to specify a format of date/time used by
	BIRD.  The first argument specifies for which purpose such
	format is used. <cf/route/ is a format used in 'show route'
	command output, <cf/protocol/ is used in 'show protocols'
	command output, <cf/base/ is used for other commands and
	<cf/log/ is used in a log file.

	"<m/format1/" is a format string using <i/strftime(3)/
	notation (see <i/man strftime/ for details). <m/limit> and
	"<m/format2/" allow to specify the second format string for
	times in past deeper than <m/limit/ seconds. There are two
	shorthands: <cf/iso long/ is a ISO 8601 date/time format
	(YYYY-MM-DD hh:mm:ss) that can be also specified using <cf/"%F
	%T"/. <cf/iso short/ is a variant of ISO 8601 that uses just
	the time format (hh:mm:ss) for near times (up to 20 hours in
	the past) and the date format (YYYY-MM-DD) for far times. This
	is a shorthand for <cf/"%T" 72000 "%F"/.

	By default, BIRD uses an short, ad-hoc format for <cf/route/
	and <cf/protocol/ times, and a <cf/iso long/ similar format
	(DD-MM-YYYY hh:mm:ss) for <cf/base/ and <cf/log/. These
	defaults are here for a compatibility with older versions
	and might change in the future.

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

304
	<tag>eval <m/expr/</tag> Evaluates given filter expression. It
305
	is used by us for testing of filters.
306 307
</descrip>

308
<sect>Protocol options
309

Pavel Machek's avatar
Pavel Machek committed
310 311 312
<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).
313

Pavel Machek's avatar
Pavel Machek committed
314 315 316 317 318
<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").
319

Pavel Machek's avatar
Pavel Machek committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
<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.

338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
	<tag>mrtdump all|off|{ states, messages }</tag>

	Set protocol MRTdump flags. MRTdump is a standard binary
	format for logging information from routing protocols and
	daemons.  These flags control what kind of information is
	logged from the protocol to the MRTdump file (which must be
	specified by global <cf/mrtdump/ option, see the previous
	section). Although these flags are similar to flags of
	<cf/debug/ option, their meaning is different and
	protocol-specific. For BGP protocol, <cf/states/ logs BGP
	state changes and <cf/messages/ logs received BGP messages.
	Other protocols does not support MRTdump yet.

	<tag>router id <m/IPv4 address/</tag> This option can be used
	to override global router id for a given protocol. Default:
	uses global router id.
354

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

358 359
	<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
360

361 362 363 364
	<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.

365
	<tag>table <m/name/</tag> Connect this protocol to a non-default routing table.
366 367
</descrip>

368
<p>There are several options that give sense only with certain protocols:
369 370

<descrip>
371 372 373 374 375
	<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
376
	interface pattern consists of a sequence of clauses (separated by
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 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
	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
450

451 452
	<tag>accept to "<m/time/"</tag>
	 The last time of the usage of the password for packet verification.
453
</descrip>
454

Pavel Machek's avatar
Pavel Machek committed
455
<chapt>Remote control
456

457
<p>You can use the command-line client <file>birdc</file> to talk with
458 459 460 461 462 463 464 465
a running BIRD. Communication is done using a <file/bird.ctl/ UNIX
domain socket (unless changed with the <tt/-s/ option given to both
the server and 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 reconfigure. Press <tt/?/ at any time to get online
help. Option <tt/-r/ can be used to enable a restricted mode of BIRD
client, which allows just read-only commands (<cf/show .../). Option
466
<tt/-v/ can be passed to the client, to make it dump numeric return
467 468 469 470
codes along with the messages. You do not necessarily need to use
<file/birdc/ to talk to BIRD, your own applications could do that, too
-- the format of communication between BIRD and <file/birdc/ is stable
(see the programmer's documentation).
Pavel Machek's avatar
Pavel Machek committed
471

472 473 474
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
475
<p>Here is a brief list of supported functions:
476 477

<descrip>
Pavel Machek's avatar
Pavel Machek committed
478 479 480 481
	<tag>dump resources|sockets|interfaces|neighbors|attributes|routes|protocols</tag>
	Dump contents of internal data structures to the debugging output.

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

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

487 488 489 490 491 492
	<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.

493 494 495 496 497 498 499 500 501 502 503 504
	<tag>show ospf state [all] [<m/name/]</tag>
	Show detailed information about OSPF areas based on a content
	of the link-state database. It shows network topology, stub
	networks, aggregated networks and routers from other areas and
	external routes. The command shows information about reachable
	network nodes, use option <cf/all/ to show information about
	all network nodes in the link-state database.

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

Pavel Machek's avatar
Pavel Machek committed
506
	<tag>show static [<m/name/]</tag>
507 508
	Show detailed information about static routes.

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

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

515
	<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
516
	Show contents of a routing table (by default of the main one),
517
	that is routes, their metrics and (in case the <cf/all/ switch is given)
Pavel Machek's avatar
Pavel Machek committed
518 519 520 521 522 523 524 525 526 527 528 529
	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>).
530 531 532
	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
533

534 535 536
	<p>You can also select just routes added by a specific protocol.
	<cf>protocol <m/p/</cf>.

Pavel Machek's avatar
Pavel Machek committed
537 538 539 540
	<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.

Ondřej Zajíček's avatar
Ondřej Zajíček committed
541 542 543 544
	<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
545
	filters usually lead to restart of affected protocols. If
546
	<cf/soft/ option is used, changes in filters does not cause
Ondřej Zajíček's avatar
Ondřej Zajíček committed
547 548 549 550
	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
551

552 553 554
	<tag>enable|disable|restart <m/name/|"<m/pattern/"|all</tag>
	Enable, disable or restart a given protocol instance, instances matching the <cf><m/pattern/</cf> or <cf/all/ instances.

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
	<tag>reload [in|out] <m/name/|"<m/pattern/"|all</tag>
	
	Reload a given protocol instance, that means re-import routes
	from the protocol instance and re-export preferred routes to
	the instance. If <cf/in/ or <cf/out/ options are used, the
	command is restricted to one direction (re-import or
	re-export).

	This command is useful if appropriate filters have changed but
	the protocol instance was not restarted (or reloaded),
	therefore it still propagates the old set of routes. For example
	when <cf/configure soft/ command was used to change filters.

	Re-export always succeeds, but re-import is protocol-dependent
	and might fail (for example, if BGP neighbor does not support
	route-refresh extension). In that case, re-export is also
571 572 573
	skipped. Note that for the pipe protocol, both directions are
	always reloaded together (<cf/in/ or <cf/out/ options are
	ignored in that case).
574

Pavel Machek's avatar
Pavel Machek committed
575 576
	<tag/down/
	Shut BIRD down.
577

Pavel Machek's avatar
Pavel Machek committed
578
	<tag>debug <m/protocol/|<m/pattern/|all all|off|{ states | routes | filters | events | packets }</tag>
579 580
	Control protocol debugging.
</descrip>
581

582
<chapt>Filters
583

584
<sect>Introduction
585

586 587 588 589
<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>. 
590

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

596
<code>
597 598 599 600 601 602 603 604 605 606 607 608 609 610
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";
}
611
</code>
612

613
<p>As you can see, a filter has a header, a list of local variables, and a body. The header consists of
614 615 616 617 618 619 620 621
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
622
look like this:
623 624 625 626 627 628 629 630 631 632 633 634 635 636

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

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

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

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

648 649
<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
650 651 652 653 654 655 656 657 658 659
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 ?
660
show route [<prefix>] [table <t>] [filter <f>] [all] [primary]...
Martin Mareš's avatar
Martin Mareš committed
661
bird> show route filter { if 127.0.0.5 &tilde; net then accept; }
Pavel Machek's avatar
Pavel Machek committed
662 663 664 665
127.0.0.0/8        dev lo [direct1 23:21] (240)
bird>
</code>

666
<sect>Data types
667

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

<descrip>
672
	<tag/bool/ This is a boolean type, it can have only two values, <cf/true/ and
673
	  <cf/false/. Boolean is the only type you can use in <cf/if/
674
	  statements.
675

676 677
	<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.
678

679
	<tag/pair/ This is a pair of two short integers. Each component can have values from 0 to
680 681
	  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)/).
682

683 684 685 686 687
	<tag/quad/ This is a dotted quad of numbers used to represent
	  router IDs (and others).  Each component can have a value
	  from 0 to 255. Literals of this type are written like IPv4
	  addresses.

688 689 690
	<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
691
	  are written as <cf/"This is a string constant"/.
692

693
	<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
694
	  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>
695
	  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
696
	  address. So <cf/1.2.3.4.mask(8) = 1.0.0.0/ is true.
697

698
	<tag/prefix/ This type can hold a network prefix consisting of IP address and prefix length. Prefix literals are written as
699
	  <cf><M>ipaddress</M>/<M>pxlen</M></cf>, or
700 701 702 703
	  <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.
704

705
	<tag/int|pair|quad|ip|prefix|enum set/
706
	  Filters recognize four types of sets. Sets are similar to strings: you can pass them around
707
	  but you can't modify them. Literals of type <cf>int set</cf> look like <cf>
708
	  [ 1, 2, 5..7 ]</cf>. As you can see, both simple values and ranges are permitted in
709 710 711 712
	  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>.
713 714 715
	  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/
716 717 718 719
	  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
720
	  <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
721 722 723
	  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).
724 725 726 727 728

	  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
729
	  <cf>1.2.3.4</cf>. <cf>1.2.0.0/16 &tilde; [ 1.0.0.0/8{15,17} ]</cf> is true,
730 731 732
	  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
733
	  in BIRD as <cf>10.0.0.0/8{16,24}</cf>, <cf>192.168.0.0/16 le 24</cf> as 
734 735
	  <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>.
736 737

	<tag/enum/
Martin Mareš's avatar
Martin Mareš committed
738
	  Enumeration types are fixed sets of possibilities. You can't define your own
739
	  variables of such type, but some route attributes are of enumeration
740
	  type. Enumeration types are incompatible with each other.
741 742

	<tag/bgppath/
743
	  BGP path is a list of autonomous system numbers. You can't write literals of this type.
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
	  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/).
759

Pavel Machek's avatar
Pavel Machek committed
760 761
	<tag/bgpmask/
	  BGP masks are patterns used for BGP path matching
762
	  (using <cf>path &tilde; [= 2 3 5 * =]</cf> syntax). The masks
Pavel Machek's avatar
Pavel Machek committed
763
	  resemble wildcard patterns as used by UNIX shells. Autonomous
Ondřej Zajíček's avatar
Ondřej Zajíček committed
764
	  system numbers match themselves, <cf/*/ matches any (even empty)
765 766
	  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:
767 768
	  <tt>bgp_path &tilde; [= * 4 3 * =]</tt> is true, but 
	  <tt>bgp_path &tilde; [= * 4 5 * =]</tt> is false.
769 770
	  BGP mask expressions can also contain integer expressions enclosed in parenthesis
	  and integer variables, for example <tt>[= * 4 (1+2) a =]</tt>.
771
	  There is also old syntax that uses / .. / instead of [= .. =] and ? instead of *.
772

773 774 775 776 777 778
	<tag/clist/
	  Clist is similar to a set, except that unlike other sets, it
	  can be modified. The type is used for community list (a set
	  of pairs) and for cluster list (a set of quads). There exist
	  no literals of this type. There are two special operators on
	  clists:
779

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

782
          <cf>delete(<m/C/,<m/P/)</cf> deletes pair (or quad) <m/P/ from clist <m/C/ and returns the result.
783 784 785 786

          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/.
787

788 789
</descrip>

790
<sect>Operators
791

792
<p>The filter language supports common integer operators <cf>(+,-,*,/)</cf>, parentheses <cf/(a*(b+c))/, comparison
Martin Mareš's avatar
Martin Mareš committed
793
<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;/). 
794
Special operators include <cf/&tilde;/ for "is element of a set" operation - it can be
795 796
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
797
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 pair (or quad) is element of the clist).
798

799

800
<sect>Control structures
801

802 803
<p>Filters support two control structures: conditions and case switches. 

804
<p>Syntax of a condition is: <cf>if
805
<M>boolean expression</M> then <M>command1</M>; else <M>command2</M>;</cf> and you can use <cf>{
806 807
<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.
808

809 810 811 812 813
<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.
814

815
<p>Here is example that uses <cf/if/ and <cf/case/ structures:
Pavel Machek's avatar
Pavel Machek committed
816 817 818 819 820 821

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

Pavel Machek's avatar
Pavel Machek committed
824 825 826 827
if 1234 = i then printn "."; else { 
  print "not 1234"; 
  print "You need {} around multiple commands"; 
}
Pavel Machek's avatar
Pavel Machek committed
828 829
</code>

830
<sect>Route attributes
831

832 833
<p>A filter is implicitly passed a route, and it can access its
attributes just like it accesses variables. Attempts to access undefined
834
attribute result in a runtime error; you can check if an attribute is
835
defined by using the <cf>defined( <m>attribute</m> )</cf> operator.
836 837
One notable exception to this rule are attributes of clist type, where
undefined value is regarded as empty clist for most purposes.
838

839
<descrip>
Martin Mareš's avatar
Martin Mareš committed
840
	<tag><m/prefix/ net</tag>
841
	Network the route is talking about. Read-only. (See the chapter about routing tables.)
842 843

	<tag><m/enum/ scope</tag>
844 845 846 847 848 849 850 851
	The scope of the route. Possible values: <cf/SCOPE_HOST/ for
	routes local to this host, <cf/SCOPE_LINK/ for those specific
	for a physical link, <cf/SCOPE_SITE/ and
	<cf/SCOPE_ORGANIZATION/ for private routes and
	<cf/SCOPE_UNIVERSE/ for globally visible routes. This
	attribute is not interpreted by BIRD and can be used to mark
	routes in filters. The default value for new routes is
	<cf/SCOPE_UNIVERSE/.
852

Martin Mareš's avatar
Martin Mareš committed
853
	<tag><m/int/ preference</tag>
854
	Preference of the route. Valid values are 0-65535. (See the chapter about routing tables.)
Pavel Machek's avatar
Pavel Machek committed
855

Martin Mareš's avatar
Martin Mareš committed
856
	<tag><m/ip/ from</tag>
857
	The router which the route has originated from. Read-only.
858
	
Martin Mareš's avatar
Martin Mareš committed
859
	<tag><m/ip/ gw</tag>
860
	Next hop packets routed using this route should be forwarded to.
861

862 863 864
	<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
865
	<tag><m/enum/ source</tag>
866
	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
867

Martin Mareš's avatar
Martin Mareš committed
868
	<tag><m/enum/ cast</tag>
869 870 871 872 873

	Route type (Currently <cf/RTC_UNICAST/ for normal routes,
	<cf/RTC_BROADCAST/, <cf/RTC_MULTICAST/, <cf/RTC_ANYCAST/ will
	be used in the future for broadcast, multicast and anycast
	routes). Read-only.
Pavel Machek's avatar
Pavel Machek committed
874

Martin Mareš's avatar
Martin Mareš committed
875
	<tag><m/enum/ dest</tag>
876
	Type of destination the packets should be sent to (<cf/RTD_ROUTER/ for forwarding to a neighboring router, <cf/RTD_DEVICE/ 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
877
</descrip>
878

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

881
<sect>Other statements
882

883
<p>The following statements are available:
884 885

<descrip>
886
	<tag><m/variable/ = <m/expr/</tag> Set variable to a given value.
887

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

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

892 893 894
	<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.
895 896

	<tag>quitbird</tag>
897
	Terminates BIRD. Useful when debugging the filter interpreter.
898 899
</descrip>

900
<chapt>Protocols
901

902
<sect>BGP
Martin Mareš's avatar
Martin Mareš committed
903

904
<p>The Border Gateway Protocol is the routing protocol used for backbone
Pavel Machek's avatar
Pavel Machek committed
905
level routing in the today's Internet. Contrary to the other protocols, its convergence
906 907 908 909 910 911
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
912 913
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
914 915 916 917 918
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
919 920
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
921 922
route) in order to avoid routing loops.

Martin Mareš's avatar
Martin Mareš committed
923
<p>BIRD supports all requirements of the BGP4 standard as defined in
924 925 926 927 928 929 930 931 932
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">),
933 934
multiprotocol extensions
(RFC 4760<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4760.txt">),
935 936 937 938
and 4B AS numbers 
(RFC 4893<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc4893.txt">).


Martin Mareš's avatar
Martin Mareš committed
939 940 941
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
942
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
943 944 945
and applied to IPv6 according to
RFC 2545<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc2545.txt">.

946
<sect1>Route selection rules
Martin Mareš's avatar
Martin Mareš committed
947 948 949

<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
950
and they are implemented according to the following algorithm. It starts the first
Martin Mareš's avatar
Martin Mareš committed
951 952 953 954
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
955
	<item>Prefer route with the highest Local Preference attribute.
Martin Mareš's avatar
Martin Mareš committed
956 957 958
	<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
959 960
	<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
961 962
	advertising router.
</itemize>
963

964
<sect1>Configuration
965

Martin Mareš's avatar
Martin Mareš committed
966
<p>Each instance of the BGP corresponds to one neighboring router.
Pavel Machek's avatar
Pavel Machek committed
967 968
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
969 970 971 972 973 974 975

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

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

Martin Mareš's avatar
Martin Mareš committed
983 984 985 986
	<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
987

988 989 990 991
	<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
992
	Default: disabled.
Pavel Machek's avatar
Pavel Machek committed
993

994 995 996 997 998 999 1000
	<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
1001 1002 1003
	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
1004
	the problem and sends just the global address (and therefore
1005 1006 1007
	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
1008 1009
	does not forward packets ifselves.
	
Martin Mareš's avatar
Martin Mareš committed
1010 1011 1012
	<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
1013

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

Ondřej Zajíček's avatar
Ondřej Zajíček committed
1018 1019 1020 1021 1022
	<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.

1023 1024
	<tag>rr client</tag> Be a route reflector and treat the neighbor as
	a route reflection client. Default: disabled.
1025 1026 1027 1028 1029

	<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
1030 1031
	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.
1032

1033 1034 1035 1036
	<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.
1037
	BIRD does not implement obsoleted RFC 1863, but uses ad-hoc implementation,
1038 1039 1040 1041
	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.

1042 1043 1044 1045 1046
	<tag>enable route refresh <m/switch/</tag> When BGP speaker
	changes its import filter, it has to re-examine all routes
	received from its neighbor against the new filter. As these
	routes might not be available, there is a BGP protocol
	extension Route Refresh (specified in RFC 2918) that allows
1047
	BGP speaker to request re-advertisement of all routes from its
1048 1049 1050 1051
	neighbor. This option specifies whether BIRD advertises this
	capability and accepts such requests. Even when disabled, BIRD
	can send route refresh requests. Default: on.

1052 1053
	<tag>interpret communities <m/switch/</tag> RFC 1997 demands
	that BGP speaker should process well-known communities like
1054 1055
	no-export (65535, 65281) or no-advertise (65535, 65282). For
	example, received route carrying a no-adverise community
1056 1057 1058
	should not be advertised to any of its neighbors. If this
	option is enabled (which is by default), BIRD has such
	behavior automatically (it is evaluated when a route is
1059
	exported to the BGP protocol just before the export filter).
1060 1061 1062
	Otherwise, this integrated processing of well-known
	communities is disabled. In that case, similar behavior can be
	implemented in the export filter.  Default: on.
1063

1064 1065 1066 1067 1068 1069 1070 1071
	<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.

1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
	<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.
1085

1086 1087 1088 1089
	<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
1090 1091
	<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
1092 1093 1094
	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
1095 1096 1097
	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
1098

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

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

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

Martin Mareš's avatar
Martin Mareš committed
1109
	<tag>start delay time <m/number/</tag> Delay in seconds between protocol
Pavel Machek's avatar
Pavel Machek committed
1110 1111 1112 1113
	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
1114 1115
	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
1116

Martin Mareš's avatar
Martin Mareš committed
1117 1118 1119
	<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
1120

Martin Mareš's avatar
Martin Mareš committed
1121 1122
	<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
1123

1124 1125 1126 1127 1128
	<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
1129 1130
	<tag>default bgp_med <m/number/</tag> Value of the Multiple Exit
	Discriminator to be used during route selection when the MED attribute
1131
	is missing. Default: 0.
Pavel Machek's avatar
Pavel Machek committed
1132

1133 1134 1135 1136 1137 1138
	<tag>default bgp_local_pref <m/number/</tag> A default value
	for the Local Preference attribute. It is used when a new
	Local Preference attribute is attached to a route by the BGP
	protocol itself (for example, if a route is received through
	eBGP and therefore does not have such attribute). Default: 100
	(0 in pre-1.2.0 versions of BIRD).
Martin Mareš's avatar
Martin Mareš committed
1139 1140
</descrip>

1141
<sect1>Attributes
1142

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

<descrip>
1148
	<tag>bgppath <cf/bgp_path/</tag> Sequence of AS numbers describing the AS path
Pavel Machek's avatar
Pavel Machek committed
1149 1150 1151
	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
1152 1153 1154
	<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
1155

1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
	<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
1166 1167 1168 1169 1170

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

Martin Mareš's avatar
Martin Mareš committed
1173 1174 1175 1176 1177 1178
	<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
1179

Martin Mareš's avatar
Martin Mareš committed
1180
	<tag>void <cf/bgp_atomic_aggr/ [O]</tag> This is an optional attribute
Pavel Machek's avatar
Pavel Machek committed
1181 1182
	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
1183
	the originator.
Pavel Machek's avatar
Pavel Machek committed
1184

Martin Mareš's avatar
Martin Mareš committed
1185 1186 1187 1188 1189
<!-- 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
1190 1191
	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
1192 1193
	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
1194
	its own routing policy, it also has a complete freedom about which community
Pavel Machek's avatar
Pavel Machek committed
1195
	attributes it defines and what will their semantics be.
1196 1197 1198 1199 1200 1201 1202 1203

	<tag>quad <cf/bgp_originator_id/ [O]</tag> This attribute is created by the
	route reflector when reflecting the route and contains the router ID of the
	originator of the route in the local AS.

	<tag>clist <cf/bgp_cluster_list/ [O]</tag> This attribute contains a list
	of cluster IDs of route reflectors. Each route reflector prepends its
	cluster ID when reflecting the route.
Martin Mareš's avatar
Martin Mareš committed
1204 1205
</descrip>

1206
<sect1>Example
1207

Martin Mareš's avatar
Martin Mareš committed
1208 1209
<p><code>
protocol bgp {
1210 1211 1212 1213 1214
	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
1215 1216 1217
		        # Assign our community
			bgp_community.add((65000,5678));
			# Artificially increase path length
Pavel Machek's avatar
Pavel Machek committed
1218
			# by advertising local AS number twice
Ondřej Zajíček's avatar
Ondřej Zajíček committed
1219
			if bgp_path ~ [= 65000 =] then	  
1220
				bgp_path.prepend(65000);  
Martin Mareš's avatar
Martin Mareš committed
1221 1222 1223 1224 1225
			accept;
		}
		reject;
	};
	import all;
1226
	source address 62.168.0.1;	# Use a non-standard source address
Martin Mareš's avatar
Martin Mareš committed
1227 1228 1229
}
</code>

1230
<sect>Device
Martin Mareš's avatar
Martin Mareš committed
1231

Pavel Machek's avatar
Pavel Machek committed
1232 1233
<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
1234 1235
interfaces from the kernel.

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

1240
<sect1>Configuration
1241 1242 1243 1244 1245

<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
1246 1247
	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.
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265

	<tag>primary  [ "<m/mask/" ] <m/prefix/</tag>
	If a network interface has more than one network address,
	BIRD has to choose one of them as a primary one, because some
	routing protocols (for example OSPFv2) suppose there is only
	one network address per interface. By default, BIRD chooses
	the lexicographically smallest address as the primary one.

	This option allows to specify which network address should be
	chosen as a primary one. Network addresses that match
	<m/prefix/ are preferred to non-matching addresses. If more
	<cf/primary/ options are used, the first one has the highest
	preference. If "<m/mask/" is specified, then such
	<cf/primary/ option is relevant only to matching network
	interfaces.

	In all cases, an address marked by operating system as
	secondary cannot be chosen as the primary one. 
1266 1267 1268
</descrip>

<p>As the Device protocol doesn't generate any routes, it cannot have
1269
any attributes. Example configuration looks like this:
1270 1271 1272 1273

<p><code>
protocol device {
	scan time 10;		# Scan the interfaces often
1274 1275
	primary "eth0" 192.168.1.1;
	primary 192.168.0.0/16;
1276 1277 1278
}
</code>

1279
<sect>Direct
Martin Mareš's avatar
Martin Mareš committed
1280

1281 1282 1283 1284
<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.

1285 1286 1287 1288 1289 1290 1291 1292 1293
<p>The question is whether it is a good idea to have such device
routes in BIRD routing table. OS kernel usually handles device routes
for directly connected networks by itself so we don't need (and don't
want) to export these routes to the kernel protocol. OSPF protocol
creates device routes for its interfaces itself and BGP protocol is
usually used for exporting aggregate routes. Although there are some
use cases that use the direct protocol (like abusing eBGP as an IGP
routing protocol), in most cases it is not needed to have these device
routes in BIRD routing table and to use the direct protocol.
1294

Pavel Machek's avatar
Pavel Machek committed
1295
<p>The only configurable thing about direct is what interfaces it watches:
1296 1297

<p><descrip>
1298
	<tag>interface <m/pattern [, ...]/</tag> By default, the Direct
1299 1300 1301 1302 1303 1304 1305 1306 1307
	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.

1308
<p>Example config might look like this:
1309 1310 1311 1312 1313 1314 1315

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

1316
<sect>Kernel
Martin Mareš's avatar
Martin Mareš committed
1317

1318
<p>The Kernel protocol is not a real routing protocol. Instead of communicating
1319
with other routers in the network, it performs synchronization of BIRD's routing
Pavel Machek's avatar
Pavel Machek committed
1320
tables with the OS kernel. Basically, it sends all routing table updates to the kernel
1321 1322
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
1323
or whether an `alien' route has been added by someone else (depending on the
1324
<cf/learn/ switch, such routes are either ignored or accepted to our
Martin Mareš's avatar
Martin Mareš committed
1325
table).
1326

1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
<p>Unfortunately, there is one thing that makes the routing table
synchronization a bit more complicated. In the kernel routing table
there are also device routes for directly connected networks. These
routes are usually managed by OS itself (as a part of IP address
configuration) and we don't want to touch that.  They are completely
ignored during the scan of the kernel tables and also the export of
device routes from BIRD tables to kernel routing tables is restricted
to prevent accidental interference. This restriction can be disabled using
<cf/device routes/ switch.

1337 1338
<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
1339
allow policy routing; such an OS is for example Linux 2.2), you can run as many instances as you want, but each of
1340 1341 1342
them must be connected to a different BIRD routing table and to a different
kernel table.

1343
<sect1>Configuration
1344 1345 1346

<p><descrip>
	<tag>persist <m/switch/</tag> Tell BIRD to leave all its routes in the
1347
	routing tables when it exits (instead of cleaning them up).
Pavel Machek's avatar
Pavel Machek committed
1348
	<tag>scan time <m/number/</tag> Time in seconds between two consecutive scans of the
1349 1350 1351 1352 1353
	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.
1354 1355 1356 1357 1358 1359 1360 1361

	<tag>device routes <m/switch/</tag> Enable export of device
	routes to the kernel routing table. By default, such routes
	are rejected (with the exception of explicitly configured
	device routes from the static protocol) regardless of the
	export filter to protect device routes in kernel routing table
	(managed by OS itself) from accidental overwriting or erasing.

1362 1363 1364 1365 1366
	<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
1367
<p>The Kernel protocol doesn't define any route attributes.
1368
<p>A simple configuration can look this way:
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391

<p><code>
protocol kernel {
	import all;
	export all;
}
</code>

<p>Or for a system with two routing tables:

<p><code>
protocol kernel {		# Primary routing table
	learn;			# Learn alien routes from the kernel
	persist;		# Don't remove routes on bird shutdown
	scan time 10;		# Scan kernel routing table every 10 seconds
	import all;
	export all;
}

protocol kernel {		# Secondary routing table
	table auxtable;
	kernel table 100;
	export all;
1392
}
1393 1394
</code>

1395
<sect>OSPF
Martin Mareš's avatar
Martin Mareš committed
1396

1397 1398
<sect1>Introduction

1399
<p>Open Shortest Path First (OSPF) is a quite complex interior gateway
1400 1401 1402 1403 1404 1405 1406 1407 1408
protocol. The current IPv4 version (OSPFv2) is defined in RFC
2328<htmlurl url="ftp://ftp.rfc-editor.org/in-notes/rfc2328.txt"> and
the current IPv6 version (OSPFv3) is defined in RFC 5340<htmlurl
url="ftp://ftp.rfc-editor.org/in-notes/rfc5340.txt">  It's a link state
(a.k.a. shortest path first) protocol -- each router maintains a
database describing the autonomous system's topology. Each participating
router has an identical copy of the database and all routers run the
same algorithm calculating a shortest path tree with themselves as a
root. OSPF chooses the least cost path as the best path.
1409 1410 1411 1412 1413 1414 1415 1416 1417

<p>In OSPF, the autonomous system can be split to several areas in order
to reduce the amount of resources consumed for exchanging the routing
information and to protect the other areas from incorrect routing data.
Topology of the area is hidden to the rest of the autonomous system.

<p>Another very important feature of OSPF is that
it can keep routing information from other protocols (like Static or BGP)
in its link state database as external routes. Each external route can
1418
be tagged by the advertising router, making it possible to pass additional
1419 1420 1421
information between routers on the boundary of the autonomous system.

<p>OSPF quickly detects topological changes in the autonomous system (such
1422
as router interface failures) and calculates new loop-free routes after a short
Ondřej Filip's avatar
Ondřej Filip committed
1423
period of convergence. Only a minimal amount of 
1424
routing traffic is involved.
1425

1426 1427 1428 1429 1430
<p>Each router participating in OSPF routing periodically sends Hello messages
to all its interfaces. This allows neighbors to be discovered dynamically.
Then the neighbors exchange theirs parts of the link state database and keep it
identical by flooding updates. The flooding process is reliable and ensures
that each router detects all changes.
1431 1432 1433

<sect1>Configuration

1434 1435
<p>In the main part of configuration, there can be multiple definitions of
OSPF area witch different id included. These definitions includes many other