0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-09-19 20:05:21 +00:00
Commit Graph

581 Commits

Author SHA1 Message Date
Ondrej Zajicek (work)
cb339a3067 Filter: Implement for loops
For loops allow to iterate over elements in compound data like BGP paths
or community lists. The syntax is:

  for [ <type> ] <variable> in <expr> do <command-body>
2022-06-27 21:13:32 +02:00
Ondrej Zajicek (work)
1ac8e11bba Filter: Implement mixed declarations of local variables
Allow variable declarations mixed with code, also in nested blocks with
proper scoping, and with variable initializers. E.g:

function fn(int a)
{
  int b;
  int c = 10;

  if a > 20 then
  {
    b = 30;
    int d = c * 2;
    print a, b, c, d;
  }

  string s = "Hello";
}
2022-06-27 21:13:32 +02:00
Ondrej Zajicek (work)
a2527ee53d Filter: Improve handling of stack frames in filter bytecode
When f_line is done, we have to pop the stack frame. The old code just
removed nominal number of args/vars. Change it to use stored ventry value
modified by number of returned values. This allows to allocate variables
on a stack frame during execution of f_lines instead of just at start.

But we need to know the number of returned values for a f_line. It is 1
for term, 0 for cmd. Store that to f_line during linearization.
2022-06-27 21:13:32 +02:00
Ondrej Zajicek (work)
f31f4e6eef Filter: Simplify handling of command sequences
Command sequences in curly braces used a separate nonterminal in grammar.
Handle them as a regular command.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
1e6acf34bb Filter: Fix bug in variable shadowing
When a new variable used the same name as an existing symbol in an outer
scope, then offset number was defined based on a scope of the existing
symbol ($3) instead of a scope of the new symbol (sym_). That can lead
to two variables sharing the same memory slot.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
26bc4f9904 Filter: Implement direct recursion
Direct recursion almost worked, just crashed on function signature check.
Split function parsing such that function signature is saved before
function body is processed. Recursive calls are marked so they can be
avoided during f_same() and similar code walking.

Also, include tower of hanoi solver as a test case.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
fb1d8f6513 Filter: Apply constant promotion for FI_EQ / FI_NEQ
Equality comparison is defined on all values, even of different
types, but we still want to do constant promotion if possible.
2022-06-27 21:13:31 +02:00
Alexander Zubkov
b2d6d2948a Filter: Add literal for empty set
Add literal for empty set [], which works both for tree-based sets
and prefix sets by using existing constant promotion mechanism.

Minor changes by committer.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
8f3c6151b4 Nest: Cleanups in as_path_filter()
Use struct f_val as a common argument for as_path_filter(), as suggested
by Alexander Zubkov. That allows to use NULL sets as valid arguments.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
9b302c133f Filter: Ensure that all expressions declared return type
All instructions with a return value (i.e. expressions, ones with
non-zero outval, third argument in INST()) should declare their return
type. Check that automatically by M4 macros.

Set outval of FI_RETURN to 0. The instruction adds one value to stack,
but syntactically it is a statement, not an expression.

Add fake return type declaration to FI_CALL, otherwise the automatic
check would fail builds.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
cde8094c1f Filter: Improve description of type system 2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
93d6096c87 Filter: Implement type checks for function calls
Keep list of function parameters in f_line and use it to verify
types of arguments for function calls. Only static type checks
are implemented.
2022-06-27 21:13:31 +02:00
Ondrej Zajicek (work)
4c0c507b1f Filter: Clean up function call instruction
Pass instructions of function call arguments as vararg arguments to
FI_CALL instruction constructor and move necessary magic from parser
code to interpreter / instruction code.
2022-06-27 21:13:31 +02:00
Alexander Zubkov
5299fb9db0 Fixed spurious undef of route attributes 2022-05-04 15:37:23 +02:00
Maria Matejka
0f68515263 Unsetting route attributes without messing with type system 2022-04-06 18:14:08 +02:00
Maria Matejka
63cf5d5d8c Eattr flags (originated and fresh) get their own struct fields 2022-04-06 18:14:08 +02:00
Maria Matejka
24773af9e0 Merge commit 'e42eedb9' into haugesund 2022-03-09 11:02:55 +01:00
Maria Matejka
83d9920f90 Merge commit '5cff1d5f' into haugesund
Conflicts:
      proto/bgp/attrs.c
      proto/pipe/pipe.c
2022-03-09 10:56:06 +01:00
Maria Matejka
d814a8cb93 Replaced custom linpools in tests for the common tmp_linpool 2022-03-02 12:13:49 +01:00
Maria Matejka
d071aca7aa Merge commit '2c13759136951ef0e70a3e3c2b2d3c9a387f7ed9' into haugesund 2022-03-02 10:01:44 +01:00
Ondrej Zajicek (work)
53a2540687 Merge branch 'oz-trie-table' 2022-02-06 23:42:10 +01:00
Ondrej Zajicek (work)
24600c642a Trie: Fix trie format
After switching to 16-way tries, trie format ignored unaligned / internal
prefixes and only reported the primary prefix of a trie node.

Fix trie format by showing internal prefixes based on the 'local' bitmask
of a node. Also do basic (intra-node) reconstruction of prefix patterns
by finding common subtrees in 'local' bitmask.

In future, we could improve that by doing inter-node reconstruction, so
prefixes entered as one pattern for a subtree (e.g. 192.168.0.0/18+)
would be reported as such, like with aligned prefixes.
2022-02-06 23:27:13 +01:00
Ondrej Zajicek (work)
ba5aec94cd Trie: Add prefix counter
Add counter of prefixes stored in trie. Works only for 'restricted' tries
composed of explicit prefixes (pxlen == l == h), like ones used in rtables.
2022-02-06 23:27:13 +01:00
Ondrej Zajicek (work)
29dda184e5 Conf: Fix parsing full-length IPv6 addresses
Lexer expression for bytestring was too loose, accepting also
full-length IPv6 addresses. It should be restricted such that
colon is used between every byte or never.

Fix the regex and also add some test cases for it.

Thanks to Alexander Zubkov for the bugreport
2022-01-05 16:38:49 +01:00
Alexander Zubkov
0e1fd7ea6a Filter: Add operators to find minimum and maximum element of sets
Add operators .min and .max to find minumum or maximum element in sets
of types: clist, eclist, lclist. Example usage:

bgp_community.min
bgp_ext_community.max
filter(bgp_large_community, [(as1, as2, *)]).min

Signed-off-by: Alexander Zubkov <green@qrator.net>
2021-12-28 04:07:09 +01:00
Alexander Zubkov
a2a268da4f Filter: Add operators to pick community components
Add operators that can be used to pick components from
pair (standard community) or lc (large community) types.
For example:

(10, 20).asn --> 10
(10, 20).data --> 20

(10, 20, 30).asn --> 10
(10, 20, 30).data1 --> 20
(10, 20, 30).data2 --> 30

Signed-off-by: Alexander Zubkov <green@qrator.net>
2021-12-28 04:07:00 +01:00
Ondrej Zajicek (work)
78ddfd2600 Trie: Clarify handling of less-common net types
For convenience, Trie functions generally accept as input values not only
NET_IPx types of nets, but also NET_VPNx and NET_ROAx types. But returned
values are always NET_IPx types.
2021-12-02 03:35:29 +01:00
Ondrej Zajicek (work)
14fc24f3a5 Trie: Implement longest-prefix-match queries and walks
The prefix trie now supports longest-prefix-match query by function
trie_match_longest_ipX() and it can be extended to iteration over all
covering prefixes for a given prefix (from longest to shortest) using
TRIE_WALK_TO_ROOT_IPx() macro.
2021-11-26 03:26:36 +01:00
Ondrej Zajicek (work)
062e69bf52 Trie: Implement trie walking code
Trie walking allows enumeration of prefixes in a trie in the usual
lexicographic order. Optionally, trie enumeration can be restricted
to a chosen subnet (and its descendants).
2021-11-19 18:04:32 +01:00
Ondrej Zajicek (work)
71c18d9f53 Trie: Simplify network matching code
Introduce ipX_prefix_equal() and use it to simplify network matching code.
2021-11-13 21:11:18 +01:00
Maria Matejka
5cff1d5f02 Route: moved rte_src pointer from rta to rte
It is an auxiliary key in the routing table, not a route attribute.
2021-10-13 19:09:04 +02:00
Maria Matejka
3660f19dd5 Dropping the RTS_DUMMY temporary route storage.
Kernel route sync is done by other ways now and this code is not used
currently.
2021-10-13 19:09:04 +02:00
Maria Matejka
eb937358c0 Preference moved to RTA and set explicitly in protocols 2021-10-13 19:09:04 +02:00
Ondrej Zajicek (work)
067f69a56d Filter: Add prefix trie benchmarks
Add trie tests intended as benchmarks that use external datasets
instead of generated prefixes. As datasets are not included, they
are commented out by default.
2021-09-25 16:06:43 +02:00
Ondrej Zajicek (work)
e709dc09e6 Filter: Improve prefix trie tests
Add tests explicitly matching insides and outsides of trie and update
tests to do testing of both IPv4 and IPv6 tries.
2021-09-25 16:06:43 +02:00
Ondrej Zajicek (work)
dd61278c9d Filter: Update trie documentation 2021-09-25 16:06:43 +02:00
Ondrej Zajicek (work)
562a2b8c29 Filter: Fix trie test
Generated prefixes must be valid.
2021-09-25 16:06:43 +02:00
Ondrej Zajicek (work)
13225f1dbf Filter: Faster prefix sets
Use 16-way (4bit) branching in prefix trie instead of basic binary
branching. The change makes IPv4 prefix sets almost 3x faster, but
with more memory consumption and much more complicated algorithm.

Together with a previous filter change, it makes IPv4 prefix sets
about ~4.3x faster and slightly smaller (on my test data).
2021-09-25 16:06:43 +02:00
Maria Matejka
2c13759136 Reducing filter stack size to allow for lesser thread stack size 2021-09-10 18:11:28 +02:00
Maria Matejka
eb20251655 Filter: Additional consistency checks 2021-09-10 17:37:46 +02:00
Ondrej Zajicek (work)
abc9ccc5cb Flowspec: Label field should use numeric operator and not bitmask operator 2021-05-18 20:23:08 +02:00
Ondrej Zajicek (work)
dd8481cc1c Flowspec: Do not use comma for bitmask operators
For numeric operators, comma is used for disjunction in expressions like
"10, 20, 30..40". But for bitmask operators, comma is used for
conjunction in a way that does not really make much sense. Use always
explicit logical operators (&& and ||) to connect bitmask operators.

Thanks to Matt Corallo for the bugreport.
2021-05-18 19:54:18 +02:00
Trisha Biswas
e5468d1685 Filter: Add MPLS label route attribute
Add support to set or read outgoing MPLS labels using filters. Currently
this supports the addition of one label per route for the first next hop.

Minor changes by committer.
2021-05-17 17:50:04 +02:00
Ondrej Zajicek (work)
94abefc00b Filter: Update 'gw' to handle IPv6 link-local addresses
When a link-local address is set, use the existing iface for scope.

Thanks to Marcel Krüger for the bugreport.
2021-03-15 18:37:18 +01:00
Ondrej Zajicek (work)
d06a875b04 Filter: Recursive filter iteration code
Add macros for recursive filter iteration that allows to examine
all instructions reachable from a filter.
2021-02-07 19:21:42 +01:00
Ondrej Zajicek (work)
9e2635505a Filter: Fix return on top-level
Broken detection of top-level case caused crash when return was called
from top-of-stack position. It should behave as reject/accept.

Thanks to Damian Zaremba for the bugreport.
2020-12-28 15:23:28 +01:00
Ondrej Zajicek (work)
8cc5bb09e3 Filter: Add 'weight' route attribute
Add 'weight' route attribute that allows to get and set ECMP weight of
nexthops. Similar to 'gw' attribute, it is limited to the first nexthop,
but it is useful for handling BGP multipath, where an ECMP route is
merged from multiple regular routes.
2020-12-02 05:02:26 +01:00
Ondrej Zajicek (work)
30b8468269 Minor cleanups with cfg_allocz()
Also fixes some more failed asserts due to add_tail().
2020-11-24 04:09:11 +01:00
Kazuki Yamaguchi
a948cf9a5c Filter: Improve handling of sets in BGP path masks
Compare the content of PM_ASN_SET in path masks. A reconfiguration
was not properly triggering a reload of affected protocols when the
members of a set in a path mask change.

Also, update the printing code to so that it can display sets in a path
mask.
2020-06-28 15:37:01 +02:00
Kazuki Yamaguchi
4ef0a96639 Filter: Fix comparison of BGP path mask
Add a missing return statement. Path masks with the same length were all
considered the same. Comparing two with different length would cause
out-of-bounds memory access.
2020-06-28 15:33:26 +02:00
Ondrej Zajicek (work)
ec430a7fee Nest: Implement BGP path mask loop operator
Implement regex-like '+' operator in BGP path masks to match previous
path mask item multiple times. This is useful as ASNs may appear
multiple times in paths due to path prepending for traffic engineering
purposes.
2020-05-18 16:25:08 +02:00
Ondrej Zajicek (work)
82bfee76f0 Filter: Remove quitbird command
No need for this debug filter command and it can be abused from CLI.
2020-05-02 02:47:18 +02:00
Maria Matejka
d65a926a67 Filter: Don't alloc varargs array if its length would be zero 2020-05-01 15:19:12 +02:00
Maria Matejka
30ba7c1661 Filter: Removed forgotten dead code 2020-05-01 15:19:12 +02:00
Maria Matejka
124d860f64 Filter: fixed omitted overflow check in EC constructor 2020-04-28 16:21:06 +02:00
Maria Matejka
fd9f0c0640 Configuration strings are constant.
This is merely a const propagation. There was no problem in there.
2020-04-09 15:37:14 +02:00
Ondrej Zajicek (work)
c9d11e6230 Filter: Remove mixed address tests and fix formatting 2020-03-26 04:59:15 +01:00
Ondrej Zajicek (work)
2755002890 Filter: Optimize IPv4 prefix sets
Use separate IPv4 and IPv6 implementation of prefix sets. Just this
change makes IPv4 prefix sets 60% smaller and 50% faster.
2020-03-26 03:57:48 +01:00
Ondrej Zajicek (work)
ef8c45749c Filter: Fix typecheck for AND/OR.
Do not apply dynamic type check for second argument of AND/OR, as it is
not evaluated immediately like regular argument would be.

Thanks to Mikael for the bugreport.
2020-01-07 01:24:30 +01:00
Ondrej Zajicek (work)
3dabf7b8d0 Test: Improve filter_test
Initial parsing of test.conf must be done directly in filter_test main,
while reconfiguration is handled as a regular test. Also fix several
minor issues in test code.
2019-12-17 00:01:53 +01:00
Maria Matejka
d3aa4f2aed Filter: fix filter comparison test 2019-12-12 15:42:46 +01:00
Ondrej Zajicek (work)
dfb3eb7716 Filter: Fix function comparison
Check the SYM_FLAG_SAME in new symbols. The old code checked that
in old symbols (f2).
2019-12-10 18:53:16 +01:00
Ondrej Zajicek (work)
ff2ca10cba Filter: Add support for src/dst accessors for Flowspec and SADR 2019-12-09 04:23:01 +01:00
Ondrej Zajicek (work)
10c4cd9677 Filter: Add type info for more instructions 2019-11-05 15:30:20 +01:00
Ondrej Zajicek (work)
87512e9751 Filter: Improve typecheck error messages 2019-11-05 15:30:16 +01:00
Ondrej Zajicek (work)
c00c20a799 Filter: Better constant promotion
We use constant promotion from IPv4 to Router-ID values, as they have
same literals. Instead of ad-hoc code in filter instructions, add
constant promotion code to parse-time typecheck code.
2019-11-05 15:28:47 +01:00
Ondrej Zajicek (work)
26194bd684 Filter: Improved parse-time typechecks 2019-11-05 15:28:47 +01:00
Ondrej Zajicek
6fbcd8914a Filter: Parse-time typechecks
Most expressions can be type-validated in parse time. It is not
strong enough to eliminate runtime checks, but at least one gets
errors immediately during reconfigure.
2019-11-05 15:28:47 +01:00
Ondrej Zajicek (work)
0edf0c8cd9 Support for address family constants
We already had them defined on BGP level, but they are more general.
2019-11-03 22:25:44 +01:00
Ondrej Zajicek (work)
ea0917bcba Filter: Fix eval command 2019-09-24 00:18:48 +02:00
Maria Matejka
3f477ccb03 Filters: Function body comparison result now used.
Function bodies were compared in post-parse time, yet the result was not
used and the functions were incorrectly considered the same as before.

Now the result is used to reload affected protocols.
2019-09-23 14:03:26 +02:00
Ondrej Zajicek (work)
452e90ba72 Filter: Fix crash with 'where' filters and function calls
The old 'where' code computed size value incorrectly, which leads
to invalid instruction lines and filter errors or crashes.
2019-09-10 13:45:18 +02:00
Maria Matejka
dfe63ed84d Filter: Fixing empty block and never-executed-statement bug 2019-08-13 16:45:27 +02:00
Ondrej Zajicek (work)
9f3e098320 Filter: Allow to use set constants / expressions in path masks
Allow to not only use set literals in path masks, but also existing
set constants or set expressions.
2019-08-06 18:54:19 +02:00
Ondrej Zajicek (work)
ef113c6f72 Filter: Allow to use sets in path masks 2019-08-06 16:58:13 +02:00
Maria Matejka
2de1e2062e Conf: Fixed symbol redefinition 2019-07-30 14:28:40 +02:00
Maria Matejka
efd7c87b5b Filter: further split of print & die to FI_PRINT, FI_FLUSH and FI_DIE 2019-07-15 15:46:36 +02:00
Maria Matejka
3782454e8d Filter: Simpler filter context allocation 2019-07-15 15:46:36 +02:00
Maria Matejka
f634adc7dc Filter: FID_MEMBER debug string is a C constant string 2019-07-15 15:17:04 +02:00
Maria Matejka
c0999a149c Filter: Converted FI_PRINT and FI_PATHMASK_CONSTRUCT to VARARG 2019-07-15 15:12:18 +02:00
Maria Matejka
c29d73a06a Filter: fixed excessive stack allocation in functions with args but no local vars 2019-07-15 15:06:52 +02:00
Maria Matejka
0da06b7103 Filter: lots of documentation 2019-07-15 13:19:01 +02:00
Maria Matejka
1b9db6d4a7 Filter: Don't write out when re-evaluating filter for internal purposes. 2019-07-15 12:03:47 +02:00
Maria Matejka
547be53b8c Filter: Don't fail badly when trying to access non-existent route in config time 2019-07-15 12:03:13 +02:00
Ondrej Zajicek (work)
bfa15a642f Filter: Minor cleanups 2019-07-10 16:47:17 +02:00
Maria Matejka
8816b6cdd9 Merge branch 'mq-filter-stack' of gitlab.labs.nic.cz:labs/bird into mq-filter-stack 2019-07-03 08:44:42 +02:00
Maria Matejka
84ac62d396 Filter: CLI command to dump all the linearized filters 2019-07-03 08:27:56 +02:00
Maria Matejka
0206c070ac Filter: Split printing and dying 2019-07-03 08:27:56 +02:00
Maria Matejka
78976974e7 Dynamic attributes definition split whether it is bitmask or not. 2019-07-03 00:00:11 +02:00
Maria Matejka
263fa2c4a6 Filter: Dropped some more irrelevant whitespace from generated files 2019-07-02 22:57:00 +02:00
Maria Matejka
84c58aabd0 Filter: Nicer whitespaces in generated inst-gen.h 2019-07-02 17:59:21 +02:00
Maria Matejka
550a6488c9 Filter: documentation of the M4 preprocessor 2019-07-02 17:39:56 +02:00
Maria Matejka
c376555cec Filter: GCC, don't complain about indentation in generated code. 2019-07-02 13:13:29 +02:00
Maria Matejka
b40c0f028f Filter: Pre-evaluation of constant expressions 2019-07-02 10:45:53 +02:00
Maria Matejka
30667d5041 Filter: Resolving of defined constants in config time 2019-07-01 14:12:05 +02:00
Maria Matejka
26bfe59f45 Filter: Moved singleton member definitions to f-inst.c 2019-07-01 13:13:06 +02:00
Maria Matejka
4212c0e7e5 Filter: Moved f_inst allocation to separate function 2019-07-01 12:49:02 +02:00
Maria Matejka
f74d19765e Filter: Getting rid of RESULT_OK. Adding RESULT_VOID.
This is a preparation for filter pre-evaluation.
2019-07-01 12:07:06 +02:00
Maria Matejka
236828d06f Filter: The interpreter code now shares its diversion with constructor
This is a preparation for filter pre-evaluation.
2019-07-01 11:57:35 +02:00
Maria Matejka
63f49457dc Filter: renaming pointers for consistency
The struct f_inst * is now always "what"
and the union member pointer is always "whati".
2019-06-28 11:26:36 +02:00