diff --git a/doc/bird.sgml b/doc/bird.sgml index 63f251ad..674adce4 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -45,7 +45,7 @@ License. Bird is designed to run on Unix and unix-like systems, it is primarily html) and dvi/postscript (generated from sgml using sgmltools). You should always edit master copy, it is slightly modified linuxdoc dtd. Anything in <descrip> tags is considered definition of configuration primitives, <cf> is fragment of configuration within normal text, <m> is -"meta" information -- something in config which is not keyword. +"meta" information within fragment of configuration -- something in config which is not keyword. Configuration @@ -71,9 +71,9 @@ protocol rip { } -

Everything on a line after # is a comment, whitespace is -ignored. If there's variable number of options, it is grouped using { -} brackets. +

Everything on a line after You can find example of more complicated configuration file in doc/bird.conf.example. @@ -108,7 +108,7 @@ ignored. If there's variable number of options, it is grouped using { table create new routing table. - eval evaluates give filter expression. It is basically mainly for testing. + eval evaluates given filter expression. It is used for testing. Per-protocol options @@ -154,20 +154,20 @@ ignored. If there's variable number of options, it is grouped using {

Bird contains rather simple programming language. (No, it can not yet read mail :-). There are two objects in this language: filters and functions. Filters are called by bird core when route is being passed between protocol and main routing table, and filters may call functions. Functions may -call other functions but recursion is not allowed. Filter language contains control structures such +call other functions, but recursion is not allowed. Filter language contains control structures such as if's and switches, but it allows no loops. Filters are interpreted. Filter using many features can be found in filter/test.conf. -

There's one strange thing with filter language: it does not permit you to create loops. There's -no equivalent of while() or for() command, and recursive functions are not permitted. -

You can find sources of filters language in filter/ directory. filter/config.Y contains filter grammar, and basically translates source from user into tree of f_inst structures. These trees are later interpreted using code in filter/filter.c. Filters internally work with values/variables in struct f_val, which contains type of value and value. -

Filter basically looks like this: +

Filter basically gets the route, looks at its attributes and +modifies some of them if it wishes. At the end, it decides, whether to +pass change route through (using filter not_too_far @@ -186,69 +186,13 @@ int var; } -

As you can see, filter has a header, list of local variables, and body. Header consists of As you can see, filter has a header, list of local variables, and body. Header consists of +type name;, where each pair defines one local variable. Body consists of { statements }. Statements are terminated by { statements } construction, that is useful if you want to make bigger block of code conditional. -Data types - -

Each variable and each value has certain type. Unlike C, filters distinguish between integers and -booleans (that is to prevent you from shooting in the foot). - - - .mask(num) - on values of type ip. It masks out all but first num bits from ip - address. So ip address/px len. There are two special operators on prefix: - set int looks like - [ 1, 2, 5..7 ]. As you can see, both simple values and ranges are permitted in - sets. Sets of prefixes are special: you can specify which prefixes should match them by - using [ 1.0.0.0/8+, 2.0.0.0/8-, 3.0.0.0/8{5,6} ]. 3.0.0.0/8{5,6} matches - prefixes 3.X.X.X, whose prefix length is 5 to 6. 3.0.0.0/8+ is shorthand for 3.0.0.0/{0,8}, - 3.0.0.0/8- is shorthand for 3.0.0.0/{0,7}. - - - -Operations - -

Filter language supports common integer operations (+,-,*,/), parenthesis Functions -

Bird supports functions, so that you don't have to repeat same blocks of code over and over. Functions can have zero or more parameters, and can have local variables. Function basically looks like this: @@ -273,7 +217,72 @@ syntax. Returning value exits from current function (this is similar to C).

Filters are declared in similar way to functions, except they can not have explicit parameters. They get route table entry as implicit parameter. Route table entry is passed implicitly -to any functions being called. +to any functions being called. Filter must terminate with either accept or reject statement. + +Data types + +

Each variable and each value has certain type. Unlike C, filters distinguish between integers and +booleans (that is to prevent you from shooting in the foot). + + + .mask(num) + on values of type ip. It masks out all but first num bits from ip + address. So ipaddress/pxlen, or + ipaddress/netmask There are two special + operators on prefix: + set int looks like + [ 1, 2, 5..7 ]. As you can see, both simple values and ranges are permitted in + sets. Sets of prefixes are special: you can specify which prefixes should match them by + using [ 1.0.0.0/8+, 2.0.0.0/8-, 3.0.0.0/8{5,6} ]. 3.0.0.0/8{5,6} matches + prefixes 3.X.X.X, whose prefix length is 5 to 6. 3.0.0.0/8+ is shorthand for 3.0.0.0/{0,8}, + 3.0.0.0/8- is shorthand for 3.0.0.0/{0,7}. + + + +Operations + +

Filter language supports common integer operations (+,-,*,/), parenthesis Control structures @@ -301,6 +310,29 @@ case arg1 { if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; } +Route attributes + +

Filter is implicitly passed route, and it can access its attributes, just like it accesses variables. + + + defined( attribute + returns TRUE if given attribute is defined. Access to undefined attribute results in runtime error. + + + +

Plus, there are protocol-specific attributes, which are described in protocol sections. + Protocols Rip