0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 18:08:45 +00:00
Commit Graph

757 Commits

Author SHA1 Message Date
Katerina Kubecova
f992e7e1fe krt.c: fixup lots of routes learn & unlearn 2023-11-06 09:38:13 +01:00
Maria Matejka
c6fba7d7e6 Merge branch 'thread-next' into HEAD 2023-11-02 14:43:15 +01:00
Katerina Kubecova
9680bf68e4 Automatic ROA reloads on channel import
This includes updating OSPF, Pipe and RIP to enable partial route reload
directly from the protocols' internal tables.
2023-11-02 14:37:27 +01:00
Maria Matejka
6f1485baf9 Debug file fix
It got mistakenly closed while applying the log configuration.
2023-11-01 18:25:15 +01:00
Maria Matejka
796f0af0cc Fixes to root pool and meta loop to allow resource dumps 2023-11-01 18:23:43 +01:00
Maria Matejka
ddf698ec99 Renamed nest/rt.h back to nest/route.h
Some [redacted] (yes, myself) had a really bad idea
to rename nest/route.h to nest/rt.h while refactoring
some data structures out of it.

This led to unnecessarily complex problems with
merging updates from v2. Reverting this change
to make my life a bit easier.

At least it needed only one find-sed command:

    find -name '*.[chlY]' -type f -exec sed -i 's#nest/rt.h#nest/route.h#' '{}' +
2023-10-29 16:29:26 +01:00
Maria Matejka
1a49a4aea8 Merge commit 'fc9d471b' into thread-next
Conflicts:
	conf/cf-lex.l
	conf/conf.h
	filter/config.Y
	filter/data.c
	filter/data.h
2023-10-28 23:42:21 +02:00
Maria Matejka
0ba22509a8 Merge commit '51f2e7af' into thread-next
Conflicts:
	conf/cf-lex.l
	conf/conf.h
	conf/confbase.Y
	filter/config.Y
	nest/config.Y
	nest/proto.c
	nest/rt-table.c
	proto/bgp/bgp.c
	sysdep/unix/main.c
2023-10-27 18:29:31 +02:00
Maria Matejka
767b7b22a0 Merge commit '5121101136cb80151a9361c63dc4822afeb44eef' into thread-next 2023-10-12 14:12:33 +02:00
Pavel Šorejs
e83beb70bd KRT: Allow to learn routes with RTPROT_KERNEL
The Kernel protocol, even with the option 'learn' enabled, ignores
direct routes created by the OS kernel (on Linux these are routes
with rtm_protocol == RTPROT_KERNEL).

Implement optional behavior where both OS kernel and third-party routes
are learned, it can be enabled by 'learn all' option.

Minor changes by committer.
2023-10-06 04:55:56 +02:00
Ondrej Zajicek
6a242b3ec6 IO: Fix race condition in event processing
When regular event was added from work event, we did remember that
regular event list was empty and therefore we did not use zero time
in poll(). This leads to ~3 s latency in route reload during
reconfiguration.
2023-10-04 17:36:03 +02:00
Ondrej Zajicek
333ddd4f98 MPLS subsystem
The MPLS subsystem manages MPLS labels and handles their allocation to
MPLS-aware routing protocols. These labels are then attached to IP or VPN
routes representing label switched paths -- LSPs.

There was already a preliminary MPLS support consisting of MPLS label
net_addr, MPLS routing tables with static MPLS routes, remote labels in
next hops, and kernel protocol support.

This patch adds the MPLS domain as a basic structure representing local
label space with dynamic label allocator and configurable label ranges.
To represent LSPs, allocated local labels can be attached as route
attributes to IP or VPN routes with local labels as attributes.

There are several steps for handling LSP routes in routing protocols --
deciding to which forwarding equivalence class (FEC) the LSP route
belongs, allocating labels for new FECs, announcing MPLS routes for new
FECs, attaching labels to LSP routes. The FEC map structure implements
basic code for managing FECs in routing protocols, therefore existing
protocols can be made MPLS-aware by adding FEC map and delegating
most work related to local label management to it.
2023-10-04 13:01:21 +02:00
Maria Matejka
8d1215dba6 Channel: Refeeding by an auxiliary request if needed.
If the protocol supports route refresh on export, we keep the stop-start
method of route refeed. This applies for BGP with ERR or with export
table on, for OSPF, Babel, RIP or Pipe.

For BGP without ERR or for future selective ROA reloads, we're adding an
auxiliary export request, doing the refeed while the main export request
is running, somehow resembling the original method of BIRD 2 refeed.

There is also a refeed request queue to keep track of different refeed
requests.
2023-10-03 09:54:39 +02:00
Maria Matejka
5cdc1b679c Kernel: refeed routes and delete them from kernel before actual shutdown 2023-09-24 23:23:08 +02:00
Maria Matejka
e65a5257b2 Protocols have now assigned startup phases
For now, there are 4 phases: Necessary (device), Connector (kernel, pipe), Generator (static, rpki) and Regular.
Started and reconfigured are from Necessary to Regular, shutdown backwards.

This way, kernel can flush routes before actually being shutdown.
2023-09-24 23:23:08 +02:00
Maria Matejka
144ac4c1d3 Logging: fixed size logfiles behaving as mmapped ringbuffers
This variant of logging avoids calling write() for every log line,
allowing for waitless logging. This makes heavy logging less heavy
and more useful for race condition debugging.
2023-09-24 20:43:04 +02:00
Maria Matejka
75a5936924 Logging limit enforcement moved into the rfile structure 2023-09-24 20:43:04 +02:00
Maria Matejka
427177edb7 Logging now doesn't lock with each message
The original logging routines were locking a common mutex. This led to
massive underperformance and unwanted serialization when heavily logging
due to lock contention. Now the logging is lockless, though still
serializing on write() syscalls to the same filedescriptor.

This change also brings in a persistent logging channel structures and
thus avoids writing into active configuration data structures during
regular run.
2023-09-24 20:43:04 +02:00
Maria Matejka
3c9429a282 Threads: added a generic method to run in all threads 2023-09-24 20:40:07 +02:00
Maria Matejka
32009cb6eb Logging: Abolished stdio in favor of write() to make the logging faster. 2023-09-24 20:40:06 +02:00
Maria Matejka
88307c31c5 CLI: Dropping the mechanism of echoing log messages
This is better done by running tail -f on a logfile.
2023-09-14 14:45:01 +02:00
Maria Matejka
51f2e7afaf Conf: Symbol manipulation gets its context explicitly 2023-09-12 15:36:46 +02:00
Maria Matejka
8659818391 Conf: Adding dummy thread-number setting for easier sharing of configuration between v2 and v3 2023-09-12 14:53:55 +02:00
Toke Høiland-Jørgensen
d8cf3cad51 IO: Add current_time_now() function for immediate timestamp
Add a current_time_now() function which gets an immediate monotonic
timestamp instead of using the cached value from the event loop. This is
useful for callers that need precise times, such as the Babel RTT
measurement code.

Minor changes by committer.
2023-06-02 00:26:41 +02:00
Maria Matejka
6a3e5c2ae8 Fixed abort when running in foreground but stdin is closed
A forgotten else-clause caused BIRD to treat some pseudo-random place in
memory as fd-pair. This was happening only on startup of the first
thread in group and the value there in memory was typically zero ... and
writing to stdin succeeded.

When running BIRD with stdin not present (like systemd does), it died on
this spurious write. Now it seems to work correctly.

Thanks to Daniel Suchy <danny@danysek.cz> for reporting.

http://trubka.network.cz/pipermail/bird-users/2023-May/016929.html
2023-05-13 20:33:35 +02:00
Maria Matejka
92d934f0d1 Fix use-after free in thread stopping code 2023-05-11 11:41:01 +02:00
Maria Matejka
b36d284788 Threads take loops faster 2023-05-11 11:41:01 +02:00
Maria Matejka
cb51ff1fbb IO Loop / Thread Groups Lock moved to level -attrs- to allow for page allocation while locked 2023-05-07 16:59:19 +02:00
Maria Matejka
62432affd9 Fixed loop movement to not collide on LTT_MOVE 2023-05-07 16:58:56 +02:00
Maria Matejka
e0c09e6bee Fix loop dropping routines 2023-05-07 16:58:52 +02:00
Maria Matejka
a95141111c Fixed a bug in hot page global storage
The original algorithm was suffering from an ABA race condition:

A: fp = page_stack
B: completely allocates the same page and writes into it some data
A: unsuspecting, loads (invalid) next = fp->next
B: finishes working with the page and returns it back to page_stack
A: compare-exchange page_stack: fp => next succeeds and writes garbage
to page_stack

Fixed this by using an implicit spinlock in hot page allocator.
2023-05-06 10:50:32 +02:00
Maria Matejka
00f30ac40b Debug: keep a circular log of memory page operations 2023-05-06 10:50:32 +02:00
Maria Matejka
1e998a4349 Fixed cold page cache leak
The empty_pages pointer wasn't being propagated into the ->next pointer
when more empty_pages were to be stored
2023-05-06 10:50:31 +02:00
Maria Matejka
b21909c6ee Debug: Explicit mprotect() on freed pages to better locate use-after-free bugs 2023-05-06 10:50:31 +02:00
Maria Matejka
fac6405669 Page allocator: indentation of messy ifdef blocks 2023-05-06 10:50:31 +02:00
Maria Matejka
fa973c2c15 First try of loop balancing
If a thread encounters timeout == 0 for poll, it considers itself
"busy" and with some hysteresis it tries to drop loops for others to
pick and thus better distribute work between threads.
2023-05-06 10:50:26 +02:00
Maria Matejka
9bc5cbd3c7 Show threads: Fixed problems with CLI buffer reallocation
... by allocating all the output locally and then sending it out at
once.
2023-05-03 21:30:29 +02:00
Maria Matejka
8bc27583ff Explicitly counting loops and threads 2023-05-03 21:30:29 +02:00
Maria Matejka
9c22310612 Loop spent time refactored to separate structures and functions 2023-05-03 21:30:29 +02:00
Maria Matejka
ab83bab9d1 Loops track also locking time 2023-04-26 19:34:29 +02:00
Maria Matejka
2ddb34c9d1 IO loops now actually measuring their time (show threads all works) 2023-04-26 19:10:52 +02:00
Maria Matejka
ce7495b49a Refactoring of domains connected to pools 2023-04-25 09:52:28 +02:00
Maria Matejka
19e79eb8ad Fix of failing show threads command 2023-04-24 11:35:05 +02:00
Maria Matejka
22f54eaee6 Resource pools are now bound with domains.
Memory allocation is a fragile part of BIRD and we need checking that
everybody is using the resource pools in an appropriate way. To assure
this, all the resource pools are associated with locking domains and
every resource manipulation is thoroughly checked whether the
appropriate locking domain is locked.

With transitive resource manipulation like resource dumping or mass free
operations, domains are locked and unlocked on the go, thus we require
pool domains to have higher order than their parent to allow for this
transitive operations.

Adding pool locking revealed some cases of insecure memory manipulation
and this commit fixes that as well.
2023-04-24 10:33:28 +02:00
Maria Matejka
6230d87c74 Protocols and tables now use the birdloop pools as primary 2023-04-22 21:20:19 +02:00
Maria Matejka
1141ce4e2d Resource pool closing has its dedicated function 2023-04-22 20:49:58 +02:00
Maria Matejka
b3f805ce29 Socket closing has its dedicated function 2023-04-22 20:48:42 +02:00
Maria Matejka
787fb56da3 IO: added a specific loop pickup group for BFD; to be done better in future 2023-04-17 13:30:14 +02:00
Maria Matejka
dc75d3e305 Merge commit '231c6385' into thread-next-iface 2023-04-14 14:00:54 +02:00
Maria Matejka
6e2f00ff93 Loop: keep running the same loop for some time if there is work to do 2023-04-06 20:18:04 +02:00
Maria Matejka
836e857b30 Sockets: Unified API for main and other loops
Now sk_open() requires an explicit IO loop to open the socket in. Also
specific functions for socket RX pause / resume are added to allow for
BGP corking.

And last but not least, socket reloop is now synchronous to resolve
weird cases of the target loop stopping before actually picking up the
relooped socket. Now the caller must ensure that both loops are locked
while relooping, and this way all sockets always have their respective
loop.
2023-04-04 17:00:59 +02:00
Maria Matejka
571c4f69bf More efficient IO loop event execution to avoid long loops
If there are lots of loops in a single thread and only some of the loops
are actually active, the other loops are now kept aside and not checked
until they actually get some timers, events or active sockets.

This should help with extreme loads like 100k tables and protocols.

Also ping and loop pickup mechanism was allowing subtle race
conditions. Now properly handling collisions between loop ping and pickup.
2023-04-04 17:00:59 +02:00
Maria Matejka
d9f0f4af7d Resource dumps also write out block addresses 2023-04-04 17:00:59 +02:00
Maria Matejka
d16321686e Misc allocator fixes 2023-04-04 17:00:59 +02:00
Maria Matejka
b8d0ba36e6 Allocator fix: thread local kept pages counter must be thread local 2023-04-04 17:00:58 +02:00
Maria Matejka
98f69aa419 Propagated const through route feed routines 2023-04-04 17:00:58 +02:00
Maria Matejka
958bb84f77 Temporarily switching off time annotations of debug log
The "dump *" commands are totally garbled by the time annotations.
2023-04-04 17:00:58 +02:00
Ondrej Zajicek
6b38285f58 Net: Replace runtime checks with STATIC_ASSERT() 2023-03-06 11:57:40 +01:00
Maria Matejka
a2fd889a3b Merge commit '0bb04d5390f21b0c96fc4894ba5d5510c541f0ef' into HEAD 2023-02-07 14:27:23 +01:00
Maria Matejka
c354e8f4c1 Interface updates are asynchronous
Instead of propagating interface updates as they are loaded from kernel,
they are enqueued and all the notifications are called from a
protocol-specific event. This change allows to break the locking loop
between protocols and interfaces.

Anyway, this change is based on v2 branch to keep the changes between v2
and v3 smaller.
2023-02-02 15:57:21 +01:00
Maria Matejka
e077d0e770 Moved interface list flush to device protocol cleanup hook.
The interface list must be flushed when device protocol is stopped. This
was done in a hardcoded specific hook inside generic protocol routines.
The cleanup hook was originally used for table reference counting late
cleanup, yet it can be also simply used for prettier interface list flush.
2023-02-02 14:40:00 +01:00
Maria Matejka
02b2a4ecaa Merge commit '3186ffe79714a48542d5ad61a94c81216b522fd0' into thread-next 2023-01-24 09:45:40 +01:00
Maria Matejka
3d96a16ae8 Merge commit '6bb992cb04926895be57dc97e7d569ea15a07db1' into thread-next 2023-01-24 09:44:43 +01:00
Maria Matejka
21b772fd43 Merge commit '928a1cb034e6f9e8edcdd1dc07264cd703e00827' into thread-next 2023-01-23 19:51:24 +01:00
Maria Matejka
758aabd96c Merge commit '7fb23041a52d01754c53ba963e2282e524813364' into thread-next 2023-01-23 19:46:26 +01:00
Maria Matejka
21c4c8eafb Merge commit '1e47b9f203aaaad0fb658d40a1670f1d0437f1f8' into thread-next 2023-01-21 23:49:52 +01:00
Maria Matejka
7a262bc999 Adding forgotten pthread.h #include in io-loop.h (breaks at openbsd 7.1) 2023-01-21 23:42:02 +01:00
Maria Matejka
343628d8c0 Fixed various build problems on FreeBSD and/or CLang 2023-01-20 18:31:57 +01:00
Maria Matejka
1127f19a7a Merge commit '140c534fb81d0e165b7d674e869c646455ed19d1' into thread-next 2023-01-19 18:17:05 +01:00
Maria Matejka
84c298465f Decoupling loops from threads to allow fixed thread count
On large configurations, too many threads would spawn with one thread
per loop. Therefore, threads may now run multiple loops at once. The
thread count is configurable and may be changed during run. All threads
are spawned on startup.

This change helps with memory bloating. BIRD filters need large
temporary memory blocks to store their stack and also memory management
keeps its hot page storage per-thread.

Known bugs:
* Thread autobalancing is not yet implemented.
* Low latency loops are executed together with standard loops.
2023-01-19 11:13:50 +01:00
Maria Matejka
59a5bf18f9 CLI closing fix when its action is run asynchronously.
Some CLI actions, notably "show route", are run by queuing an event
somewhere else. If the user closes the socket, in case such an action is
being executed, the CLI must free the socket immediately from the error
hook but the pool must remain until the asynchronous event finishes and
cleans everything up.
2023-01-19 11:03:31 +01:00
Ondrej Zajicek
804916daa9 Alloc: Minor cleanups
- Fix THP disable on old systems
 - Failed syscalls should use die() instead of bug()
 - Our printf uses %ld for s64 instead of long
2023-01-18 13:40:21 +01:00
Maria Matejka
6bb992cb04 Merge branch 'master' of https://gitlab.nic.cz/labs/bird 2023-01-18 12:33:06 +01:00
Maria Matejka
973aa37e1e Fix memory pre-allocation
When BIRD has no free memory mapped, it allocates several pages in
advance just to be sure that there is some memory available if needed.
This hysteresis tactics works quite well to reduce memory ping-ping with
kernel.

Yet it had a subtle bug: this pre-allocation didn't take a memory
coldlist into account, therefore requesting new pages from kernel even
in cases when there were other pages available. This led to slow memory
bloating.

To demonstrate this behavior fast enough to be seen well, you may:
  * temporarily set the values in sysdep/unix/alloc.c as follows to
    exacerbate the issue:
      #define KEEP_PAGES_MAIN_MAX    4096
      #define KEEP_PAGES_MAIN_MIN    1000
      #define CLEANUP_PAGES_BULK     4096
  * create a config file with several millions of static routes
  * periodically disable all static protocols and then reload config
  * log memory consumption

This should give you a steady growth rate of about 16kB per cycle. If
you don't set the values this high, the issue happens much more slowly,
yet after 14 days of running, you are going to see an OOM kill.

After this fix, pre-allocation uses the memory coldlist to get some hot
pages and the same test as described here gets you a perfectly stable
constant memory consumption (after some initial wobbling).

Thanks to NIX-CZ for reporting and helping to investigate this issue.
Thanks to Santiago for finding the cause in the code.
2023-01-18 09:39:45 +01:00
Ondrej Zajicek
928a1cb034 Alloc: Disable transparent huge pages
The usage pattern implemented in allocator seems to be incompatible with
transparent huge pages, as memory released using madvise(MADV_DONTNEED)
with regular page size and alignment does not seem to trigger demotion
of huge pages back to regular pages, even when significant number of
pages is released. Even if demotion is triggered when system memory
is low, it still breaks memory accounting.
2023-01-17 17:13:50 +01:00
Mike Crute
64a2b7aaa3 Log message before aborting
Log message before aborting due to watchdog timeout. We have to use
async-safe write to debug log, as it is done in signal handler.

Minor changes from committer.
2023-01-12 17:40:53 +01:00
Ondrej Zajicek
4c19a8a984 CLI: Fix for long-lived sessions during high loads
When there is a continuos stream of CLI commands, cli_get_command()
always returns 1 (there is a new command). Anyway, the socket receive
buffer was reset only when there was no command at all, leading to a
strange behavior: after a while, the CLI receive buffer came to its end,
then read() was called with zero size buffer, it returned 0 which was
interpreted as EOF.

The patch fixes that by resetting the buffer position after each command
and moving remaining data at the beginning of buffer.

Thanks to Maria Matejka for examining the bug and for the original bugfix.
2022-12-10 17:32:42 +01:00
Ondrej Zajicek
543c8ba097 BSD: Fix krt socket code w.r.t. rte/rta changes 2022-11-30 02:43:39 +01:00
Ondrej Zajicek
bbac9ca958 Conf: Make 'configure check' command restricted
While it does not directly change BIRD state, it can trigger reading
arbitrary files and eating significant memory.
2022-11-09 22:02:46 +01:00
Ondrej Zajicek
371eb49043 Conf: Free stored old config before parsing new one
BIRD keeps a previous (old) configuration for the purpose of undo. The
existing code frees it after a new configuration is successfully parsed
during reconfiguration. That causes memory usage spikes as there are
temporarily three configurations (old, current, and new). The patch
changes it to free the old one before parsing the new one (as user
already requested a new config). The disadvantage is that undo is
not available after failed reconfiguration.
2022-11-09 21:54:45 +01:00
Maria Matejka
47e4e97db4 Merge remote-tracking branch 'origin/master' into thread-next 2022-11-07 16:52:27 +01:00
Maria Matejka
d2d83c4777 Merge commit '0f2be469' into thread-next 2022-11-07 09:51:21 +01:00
Maria Matejka
57308fb277 Page allocator: Fixed minor bugs and added commentary 2022-11-03 12:38:57 +01:00
Maria Matejka
9d03c3f56c Memory pages are not munmapped, instead we just madvise()
Memory unmapping causes slow address space fragmentation, leading in
extreme cases to failing to allocate pages at all. Removing this problem
by keeping all the pages allocated to us, yet calling madvise() to let
kernel dispose of them.

This adds a little complexity and overhead as we have to keep the
pointers to the free pages, therefore to hold e.g. 1 GB of 4K pages with
8B pointers, we have to store 2 MB of data.
2022-11-02 12:56:54 +01:00
Maria Matejka
f182771f96 Fixed SSH known hosts checking with older versions of libssh 2022-10-12 11:01:38 +02:00
Maria Matejka
e1701128bf Poll errors must also drop a corefile. And we shouldn't run sockets when sockets have changed 2022-10-05 16:33:34 +02:00
Maria Matejka
4d687d7aec Fixed previously untested paths in RPKI 2022-10-05 16:33:34 +02:00
Maria Matejka
dc9351d326 Merge commit '67256d50' into HEAD 2022-10-04 16:15:36 +02:00
Maria Matejka
f69ba3921a Merge commit 'fb7fb674' into HEAD 2022-10-04 16:09:41 +02:00
Maria Matejka
0eba27c69f Merge commit 'a32cee78' into HEAD 2022-10-04 15:59:15 +02:00
Maria Matejka
4e1c582cad Merge commit '71b434a9' into HEAD 2022-10-04 15:53:12 +02:00
Maria Matejka
becca314e2 Merge commit '0072d11f' into tmp-learn 2022-10-04 15:40:52 +02:00
Maria Matejka
67256d5035 Merge branch 'tmp-bad-learn' into thread-next 2022-09-29 10:00:32 +02:00
Maria Matejka
61c127c021 Merge commit '9efaf6ba' into tmp-bad-learn
Also fixed forgotten best route selection among alien routes.
2022-09-29 09:59:32 +02:00
Maria Matejka
9be7aa9b45 Merge commit '4364ee' into tmp-bad-learn 2022-09-27 12:46:22 +02:00
Maria Matejka
32a67c93eb Merge commit 'cae5979871ee7aa341334f8b1af6bafc60ee9692' into tmp-bad-learn 2022-09-27 12:39:07 +02:00
Maria Matejka
57a34d466e KRT: Fix route learning
This is a reimplementation of commit 0f2be469f8
by Alexander Zubkov. In the master branch, changes in commit eb937358
broke setting of channel preference for alien routes learned during
scan. The preference was set only for async routes.

The original solution is extended here to accomodate for v3 specifics.
2022-09-27 12:17:05 +02:00
Alexander Zubkov
0f2be469f8 KRT: Fix setting default preference
Changes in commit eb937358 broke setting of channel preference for alien
routes learned during scan. The preference was set only for async routes.
Move common attribute processing part of functions krt_learn_async() and
krt_learn_async() to a separate function to have only one place for such
changes.
2022-09-27 11:33:41 +02:00
Maria Matejka
896dbbfe4a Local page allocation 2022-09-21 11:49:35 +02:00
Maria Matejka
6768e0cf9e Pipe kick-and-drain packed into a neat structure and functions. 2022-09-20 17:17:50 +02:00