summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-07-13 14:14:37 +0200
committerMaria Matejka <mq@ucw.cz>2022-07-13 14:14:37 +0200
commit68a2c9d4c91a36c90a768926495f7894324287c5 (patch)
tree996387a4741746aa1c5cad1d238b886cfe7620d6 /doc
parentaf0d5ec2797bab2a928fa8ce2caf81608a3f7443 (diff)
parent2e5bfeb73ac25e236a24b6c1a88d0f2221ca303f (diff)
Merge commit '2e5bfeb73ac25e236a24b6c1a88d0f2221ca303f' into thread-next
Diffstat (limited to 'doc')
-rw-r--r--doc/bird.sgml49
1 files changed, 33 insertions, 16 deletions
diff --git a/doc/bird.sgml b/doc/bird.sgml
index ea126fa2..c48b064c 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -1262,8 +1262,8 @@ this:
<code>
filter not_too_far
-int var;
{
+ int var;
if defined( rip_metric ) then
var = rip_metric;
else {
@@ -1292,9 +1292,9 @@ local variables. Recursion is not allowed. Function definitions look like this:
<code>
function name ()
-int local_variable;
{
- local_variable = 5;
+ int local_variable;
+ int another_variable = 5;
}
function with_parameters (int parameter)
@@ -1303,16 +1303,19 @@ function with_parameters (int parameter)
}
</code>
-<p>Unlike in C, variables are declared after the <cf/function/ line, but before
-the first <cf/{/. You can't declare variables in nested blocks. Functions are
-called like in C: <cf>name(); with_parameters(5);</cf>. Function may return
-values using the <cf>return <m/[expr]/</cf> command. Returning a value exits
-from current function (this is similar to C).
+<p>Like in C programming language, variables are declared inside function body,
+either at the beginning, or mixed with other statements. Declarations may
+contain initialization. You can also declare variables in nested blocks, such
+variables have scope restricted to such block. There is a deprecated syntax to
+declare variables after the <cf/function/ line, but before the first <cf/{/.
+Functions are called like in C: <cf>name(); with_parameters(5);</cf>. Function
+may return values using the <cf>return <m/[expr]/</cf> command. Returning a
+value exits from current function (this is similar to C).
-<p>Filters are defined in a way similar to functions except they can't have
+<p>Filters are defined in a way similar to functions except they cannot have
explicit parameters. They get a route table entry as an implicit parameter, it
is also passed automatically to any functions called. The filter must terminate
-with either <cf/accept/ or <cf/reject/ statement. If there's a runtime error in
+with either <cf/accept/ or <cf/reject/ statement. If there is a runtime error in
filter, the route is rejected.
<p>A nice trick to debug filters is to use <cf>show route filter <m/name/</cf>
@@ -1682,7 +1685,8 @@ prefix and an ASN as arguments.
<sect>Control structures
<label id="control-structures">
-<p>Filters support two control structures: conditions and case switches.
+<p>Filters support several control structures: conditions, for loops and case
+switches.
<p>Syntax of a condition is: <cf>if <M>boolean expression</M> then <m/commandT/;
else <m/commandF/;</cf> and you can use <cf>{ <m/command1/; <m/command2/;
@@ -1690,6 +1694,14 @@ else <m/commandF/;</cf> and you can use <cf>{ <m/command1/; <m/command2/;
omitted. If the <cf><m>boolean expression</m></cf> is true, <m/commandT/ is
executed, otherwise <m/commandF/ is executed.
+<p>For loops allow to iterate over elements in compound data like BGP paths or
+community lists. The syntax is: <cf>for [ <m/type/ ] <m/variable/ in <m/expr/
+do <m/command/;</cf> and you can also use compound command like in conditions.
+The expression is evaluated to a compound data, then for each element from such
+data the command is executed with the item assigned to the variable. A variable
+may be an existing one (when just name is used) or a locally defined (when type
+and name is used). In both cases, it must have the same type as elements.
+
<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
@@ -1702,16 +1714,21 @@ neither of the <cf/:/ clauses, the statements after <cf/else:/ are executed.
<p>Here is example that uses <cf/if/ and <cf/case/ structures:
<code>
+if 1234 = i then printn "."; else {
+ print "not 1234";
+ print "You need {} around multiple commands";
+}
+
+for int asn in bgp_path do {
+ printn "ASN: ", asn;
+ if asn < 65536 then print " (2B)"; else print " (4B)";
+}
+
case arg1 {
2: print "two"; print "I can do more commands without {}";
3 .. 5: print "three to five";
else: print "something else";
}
-
-if 1234 = i then printn "."; else {
- print "not 1234";
- print "You need {} around multiple commands";
-}
</code>