Commit graph

140 commits

Author SHA1 Message Date
David Lamparter bbd858935f build: homologize path handling
Use consistent `e_somepath` names for expanded versions of `somepath`.
Also remove all paths from `config.h` and put them into
`lib/config_paths.h` - this is to make more obvious when someone is
doing something probably not quite properly structured.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:02:52 +01:00
David Lamparter bfd6d8ee19 lib, mgmtd: fix commit history location
Both of these belong in `/var/lib`, not `/var/run`.

Rather hilariously, the history read in
`mgmt_history_read_cmt_record_index` was always failing, because it was
doing a `file_exists(MGMTD_COMMIT_FILE_PATH)` check.  Which is the wrong
macro - it's `.../commit-%s.json`, including the unprocessed `%s`, which
would never exist.

I guess noone ever tried if this actually works.  Cool.

On the plus side, this means I don't have to implement legacy
compatibility for this, since it never worked to begin with.

(SQLite3 DB location is also changed in this commit since it also uses
`DAEMON_DB_DIR`.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:02:52 +01:00
David Lamparter cd35ecc575 lib: create frr_daemon_state_{load,save}
These functions load daemon-specific persistent state from
`/var/lib/frr` and supersede open-coded variants of similar calls in
ospfd, ospf6d and isisd to save GR state and/or sequence numbers.

Unlike the open-coded variants, the save call correctly `fsync()`s the
saved data to ensure disk contents are consistent.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:01:19 +01:00
David Lamparter a97d0c5875 lib: set up frr_libstatedir
This needs to be used for persistent state, which currently is misplaced
into `/var/run` / `/run` where it gets deleted across reboots.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:01:19 +01:00
David Lamparter 72783ecca2 build: nuke ZEBRA_SERV_PATH
This just unnecessarily complicates things by involving autoconf.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:01:19 +01:00
David Lamparter 42eeea090e *: rename frr_vtydir to frr_runstatedir
Also remove frr_init_vtydir(), just initialize to default.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:01:19 +01:00
Donald Sharp 8049f74fc6 lib: zebra.h is not using signal.h
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 12:50:40 -05:00
Donald Sharp c6d94a7056 *: zebra.h should not have fcntl.h
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 12:50:40 -05:00
Donald Sharp 848dcf3d03 *: remove sys/stat.h from zebra.h
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09 12:39:23 -05:00
Igor Ryzhov 7d67b9ff28 build: add -Wimplicit-fallthrough
Also:
- replace all /* fallthrough */ comments with portable fallthrough;
pseudo keyword to accomodate both gcc and clang
- add missing break; statements as required by older versions of gcc
- cleanup some code to remove unnecessary fallthrough

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-10-12 21:23:18 +03:00
Christian Hopps 5ba5613077 lib: mgmtd: add manual vty server start option and use it
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-30 02:10:20 -04:00
Lou Berger 4d28aea958 lib: when running as a daemon, only redirect sdtin, stdout, sdterr to null when a tty.
Also write memstat to stderr when stderr is not a tty
     and allow for --log stdout

Signed-off-by: Lou Berger <lberger@labn.net>
2023-05-11 07:38:25 -04:00
Donald Sharp cd9d053741 *: Convert struct event_master to struct event_loop
Let's find a better name for it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp ce50d11c4d *: Convert thread_master_XXX functions to event_master_XXX
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 2453d15dbf *: Convert struct thread_master to struct event_master and it's ilk
Convert the `struct thread_master` to `struct event_master`
across the code base.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp de2754be3a *: Convert thread_fetch and thread_call to event_fetch and event_call
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 907a2395f4 *: Convert thread_add_XXX functions to event_add_XXX
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e6685141aa *: Rename struct thread to struct event
Effectively a massive search and replace of
`struct thread` to `struct event`.  Using the
term `thread` gives people the thought that
this event system is a pthread when it is not

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Christian Hopps 41ef7327e3 lib: fix init. use of nb_context to be by value not by reference
Pass context argument by value on initialization to be clear that the
value is used/saved but not a pointer to the value. Previously the
northbound code was incorrectly holding a pointer to stack allocated
context structs.

However, the structure definition also had some musings (ifdef'd out
code) and a comment that might be taken to imply that user data could
follow the structure and thus be maintained by the code; it won't; so it
can't; so get rid of the disabled misleading code/text from the
structure definition.

The common use case worked b/c the transaction which cached the pointer
was created and freed inside a single function
call (`nb_condidate_commit`) that executed below the stack allocation.

All other use cases (grpc, confd, sysrepo, and -- coming soon -- mgmtd)
were bugs.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-02-23 20:59:17 -05:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
David Lamparter bd90faea56 lib: fix one more b0rked format string
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-01 03:00:22 +01:00
Donald Sharp ca28a0f6fa lib: Free some memory in scripting subsystem at shutdown
Pre:
staticd: showing active allocations in memory group libfrr
staticd: memstats:  Scripting                     :     16 * (variably sized)
staticd: memstats:  Hash                          :      2 * (variably sized)
staticd: memstats:  Hash Bucket                   :      8 *         32
staticd: memstats:  Hash Index                    :      1 * (variably sized)
staticd: memstats:  Link List                     :      1 *         40
staticd: memstats:  Link Node                     :      1 *         24
staticd: showing active allocations in memory group logging subsystem
staticd: memstats:  log file target               :      1 *         88
staticd: showing active allocations in memory group staticd

Post:
staticd: showing active allocations in memory group libfrr
staticd: showing active allocations in memory group logging subsystem
staticd: memstats:  log file target               :      1 *         88
staticd: showing active allocations in memory group staticd

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-10-12 07:39:23 -04:00
Christian Hopps 1213e46bfd
lib: cleanup red-herring memleaks in parent of daemonizing fork
- The parent of the daemonizing fork reports memleaks for the early
northbound allocations (libyang). If these were real memleaks these
would show up in the child as well; however, ignoring all memleaks in
the parent of the fork is too hard a sale. Instead, spend some CPU
cycles cleaning up the allocations in the parent after the fork and
immeidatley prior to exiting the parent after the daemonizing fork.

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-06-17 02:14:30 -04:00
David Lamparter da2fc19187 lib: support multiple --log options
Allow simultaneously enabling syslog, stdout and/or file logs.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-03-07 18:03:15 +01:00
Donald Sharp cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
Donald Sharp b564209367
Merge pull request #8458 from opensourcerouting/xref-5424
lib: RFC5424 syslog support
2022-02-08 15:56:20 -05:00
Rafael Zalamena 4e4c027803
Merge pull request #10183 from idryzhov/rework-vrf-rename
*: rework renaming the default VRF
2022-01-17 08:45:12 -03:00
David Lamparter 603c61656f lib: add frr_early_init hook
To bring up bits that use thread_master before other init happens.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 00:39:00 +01:00
Igor Ryzhov ac2cb9bf94 *: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.

In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.

To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.

Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-21 22:09:29 +03:00
David Lamparter b1dc60f4ab lib: shuffle around command line options
New `FRR_NO_SPLIT_CONFIG` flag for newly added daemons where we're just
rolling without split config and always expect configs to be loaded via
vtysh/integrated config.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-12-14 18:12:20 +01:00
G. Paul Ziemba 52fad8f656 lib/module.c and callers of frrmod_load(): fix error messages
frrmod_load() attempts to dlopen() several possible paths
    (constructed from its basename argument) until one succeeds.

    Each dlopen() attempt may fail for a different reason, and
    the important one might not be the last one. Example:

	dlopen(a/foo): file not found
	dlopen(b/foo): symbol "bar" missing
	dlopen(c/foo): file not found

    Previous code reported only the most recent error. Now frrmod_load()
    describes each dlopen() failure.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2021-09-14 09:51:49 -07:00
Donatas Abraitis d10bda270e *: Drop break after using frr_help_exit() in switch/case
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-08-25 10:49:05 +03:00
David Lamparter 247898d5d2 lib, watchfrr: remove HAVE_SYSTEMD, use own code
This replaces the external libsystemd dependency with... pretty much the
same amount of built-in code.  But with one fewer dependency and build
switch needed.

Also check `JOURNAL_STREAM` for future logging integration.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-29 17:57:04 +02:00
Christian Hopps 3bb513c399 lib: adapt to version 2 of libyang
Compile with v2.0.0 tag of `libyang2` branch of:
https://github.com/CESNET/libyang

staticd init load time of 10k routes now 6s vs ly1 time of 150s

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-13 16:24:48 -04:00
David Lamparter 38554d3ae6 lib: hard-fail creating threads before fork()
Creating any threads before we fork() into the background (if `-d` is
given) is an extremely dangerous footgun;  the threads are created in
the parent and terminated when that exits.

This is extra dangerous because while testing, you'd often run the
daemon in foreground without `-d`, and everything works as expected.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-22 13:25:38 +02:00
David Lamparter bf645e31f6 lib: add frr_config_pre hook
... for any initialization that needs to run after forking, but that
would be racy if it were just scheduled on the thread_master (since the
config load is also just a thread callback, ordering would be undefined
for another scheduled thread callback.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-22 13:20:34 +02:00
David Lamparter 2bafda27a6 lib: rename very_late_init hook to config_post
very_late_init doesn't really say what this does, config_post is much
more descriptive.  (A config_pre is coming in a jiffy.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-22 13:16:20 +02:00
David Lamparter 09781197b6 build: make builddir include path consistent
... by referencing all autogenerated headers relative to the root
directory.  (90% of the changes here is `version.h`.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-21 15:42:33 +02:00
David Lamparter 8451921b70 *: require semicolon after DEFINE_HOOK & co.
See previous commit.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
David Lamparter 6e3253b979 lib: memorize what fds were open at startup
... in case the user does something like `zebra 3>logfile`.  Also useful
for some module purposes, maybe even feeding config at some point in the
future.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-12 19:28:22 +01:00
Quentin Young e4e0229aba lib: add support for scripts directory
Specify default via --with-scriptdir at compile time, override default
with --scriptdir at runtime. If unspecified, it's {sysconfdir}/scripts
(usually /etc/frr/scripts)

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-12-01 18:37:14 -05:00
Quentin Young fa22080d22 build: HAVE_LUA -> HAVE_SCRIPTING
And also guard all scripting-related stuff with HAVE_SCRIPTING.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-12-01 18:37:14 -05:00
Quentin Young e613a6f73c lib: initialize scripting system in libfrr
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-12-01 18:37:14 -05:00
Mark Stapp 1a9f340b6b lib: add startup option to limit fds
Add a startup-time option to limit the number of fds used
by the thread/event infrastructure. If nothing is configured,
the system ulimit is used.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-11-18 15:34:35 -05:00
Renato Westphal 88e635ee63 lib: postpone the sysrepo plugin initialization
From Sysrepo's documentation:
"Note: do not use fork() after creating a connection. Sysrepo
internally stores PID of every created connection and this way a
mismatch of PID and connection is created".

Introduce a new "frr_very_late_init" hook in libfrr that is only
called after the daemon is forked (when the '-d' option is used)
and after the configuration is read. This way we can initialize
the sysrepo plugin correctly even when the daemon is daemonized,
and after the Sysrepo CLI commands are processed (only "debug
northbound client sysrepo" for now).

Fixes #7062

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-09-15 15:55:55 -03:00
Chirag Shah 390a886277 *: record transaction based on control flag
In case of config rollback is enabled,
record northbound transaction based on a control flag.
The actual frr daemons would set the flag to true via
nb_init from frr_init.
This will allow test daemon to bypass recording
transacation to db.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2020-08-20 14:12:04 -07:00
David Lamparter 33606a1547 watchfrr: add (network) namespace support
This adds -N and --netns options to watchfrr, allowing it to start
daemons with -N and switching network namespaces respectively.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-07-22 12:56:04 +02:00
Donald Sharp 70cf5c6b04
Merge pull request #6557 from opensourcerouting/zlogbuf-litter
lib: set up TLS log buffer after forking
2020-06-10 18:59:25 -04:00
David Lamparter e2be26436a lib: set up TLS log buffer after forking
... it contains our pid, so doing it before fork leads to littering
buffers since we try to clean up with the forked pid...

Fixes: #6541
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-06-10 20:30:02 +02:00
Renato Westphal df5eda3d87 lib: return human-readable error messages to the northbound clients
Instead of returning only error codes (e.g. NB_ERR_VALIDATION)
to the northbound clients, do better than that and also return
a human-readable error message. This should make FRR more
automation-friendly since operators won't need to dig into system
logs to find out what went wrong in the case of an error.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-05-28 19:22:54 -03:00