summaryrefslogtreecommitdiff
path: root/lib/libfrr.c
AgeCommit message (Collapse)Author
2024-10-22Revert "lib: Attach stdout to child only if --log=stdout and stdout FD is a tty"Donald Sharp
This reverts commit 0e3c5e8e5907321b35201f0985c1d3f4a1b0e639. (cherry picked from commit 6a36b9ef49bfce59a7e674df233265da6d275257)
2024-10-07lib: add flag to have libyang load internal ietf-yang-library moduleChristian Hopps
Mgmtd makes use of libyang's internal ietf-yang-library module to add support for said module to FRR management. Previously, mgmtd was loading this module explicitly; however, that required that libyang's `ietf-yang-library.yang` module definition file be co-located with FRR's yang files so that it (and ietf-datastore.yang) would be found when searched for by libyang using FRRs search path. This isn't always the case depending on how the user compiles and installs libyang so mgmtd was failing to run in some cases. Instead of doing it the above way we simply tell libyang to load it's internal version of ietf-yang-library when we initialize the libyang context. This required adding a boolean to a couple of the init functions which is why so many files are touched (although all the changes are minimal). Signed-off-by: Christian Hopps <chopps@labn.net>
2024-09-10lib: Attach stdout to child only if --log=stdout and stdout FD is a ttyVladislav Odintsov
Prior to this commit stdout of a process started in a daemon mode was attached to a calling process. As a result a calling process hung for infinity. Signed-off-by: Vladislav Odintsov <vlodintsov@k2.cloud>
2024-08-29Merge pull request #16664 from mjstapp/igor_debug_simplifyJafar Al-Gharaibeh
*: simplify frrlib debug
2024-08-27lib: rework debug initIgor Ryzhov
The debug library allows to register a `debug_set_all` callback which should enable all debugs in a daemon. This callback is implemented exactly the same in each daemon. Instead of duplicating the code, rework the lib to allow registration of each debug type, and implement the common code only once in the lib. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-08-22config: fix missing case when reporting version 'configured with'Jafar Al-Gharaibeh
Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
2024-08-11Merge pull request #16542 from donaldsharp/vtysh_stupidly_largeDonatas Abraitis
lib: Don't print warning if not a daemon
2024-08-08lib: Don't print warning if not a daemonDonald Sharp
vtysh will print out the `stupidly large FD limit` upon every run of the program if the ulimit is set stupidly large. Prevent this from being displayed for vtysh. Fixes: #16516 Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-08-08lib: Cleanup memory associated with modules on shutdownDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-07-23lib: mgmtd: fix too early daemon detach of mgmtdChristian Hopps
Correct FRR startup counts on a daemon's vty socket to be open when the parent process exits. The parent process waits for `frr_check_detach()` to be called by the child before exiting. The problem is when the `FRR_MANUAL_VTY_START` flag is set the vty socket was not opened but `frr_check_detach()` was called anyway. Instead add a bool option for `frr_check_detach()` to be called when the socket is opened with `frr_vty_serv_start()`, and do so when "manually" calling said function (i.e., when FRR_MANUAL_VTY_START is set). The `FRR_MANUAL_VTY_START` flag is only set by mgmtd. The reason we wait to open the vty socket is so that mgmtd can parse the various daemon specific config files it has taken over, after the event loop has started, but before we receive any possible new config from `vtysh`. fixes #16362 Signed-off-by: Christian Hopps <chopps@labn.net>
2024-07-01*: Add and use option for graceful (re)startvivek
Add a new start option "-K" to libfrr to denote a graceful start, and use it in zebra and bgpd. zebra will use this option to denote a planned FRR graceful restart (supporting only bgpd currently) to wait for a route sync completion from bgpd before cleaning up old stale routes from the FIB. An optional timer provides an upper-bounds for this cleanup. bgpd will use this option to denote either a planned FRR graceful restart or a bgpd-only graceful restart, and this will drive the BGP GR restarting router procedures. Signed-off-by: Vivek Venkatraman <vivek@nvidia.com>
2024-04-26Merge pull request #15588 from opensourcerouting/sqlite-filename-sizeDonald Sharp
lib: fix SQLite dbfile path length
2024-04-09lib: add simple generic version helpersMark Stapp
Add some simple helpers for generic major+minor+sub version values. Signed-off-by: Mark Stapp <mjs@cisco.com>
2024-03-21lib: fix SQLite dbfile path lengthDavid Lamparter
I can't see them but apparently this causes compiler warnings. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-03-19Merge pull request #15565 from LabNConsulting/chopps/code-coverRuss White
tests: enable code coverage reporting with topotests
2024-03-17lib: remove nb/yang memory cleanup when daemonizingIgor Ryzhov
We're not calling any other termination functions to free allocated memory when daemonizing except these two. There's no reason for such an exception, and because of these calls we have the following libyang warnings every time FRR is started: ``` MGMTD: libyang: String "15" not freed from the dictionary, refcount 2 MGMTD: libyang: String "200" not freed from the dictionary, refcount 2 MGMTD: libyang: String "mrib-then-urib" not freed from the dictionary, refcount 2 MGMTD: libyang: String "1000" not freed from the dictionary, refcount 2 MGMTD: libyang: String "10" not freed from the dictionary, refcount 2 MGMTD: libyang: String "5" not freed from the dictionary, refcount 2 ``` Remove these calls to get rid of the unnecessary warnings. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-17tests: enable code coverage reporting with topotestsChristian Hopps
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-02-01*: create a single registry of daemons' default port valuesMark Stapp
Create a single registry of default port values that daemons are using. Most of these are vty ports, but there are some others for features like ospfapi and zebra FPM. Signed-off-by: Mark Stapp <mjs@labn.net>
2024-01-27build: homologize path handlingDavid Lamparter
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-27lib, mgmtd: fix commit history locationDavid Lamparter
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-27lib: create `frr_daemon_state_{load,save}`David Lamparter
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-27lib: set up `frr_libstatedir`David Lamparter
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-27build: nuke `ZEBRA_SERV_PATH`David Lamparter
This just unnecessarily complicates things by involving autoconf. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27*: rename `frr_vtydir` to `frr_runstatedir`David Lamparter
Also remove frr_init_vtydir(), just initialize to default. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-09lib: zebra.h is not using signal.hDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09*: zebra.h should not have fcntl.hDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-01-09*: remove sys/stat.h from zebra.hDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-10-12build: add -Wimplicit-fallthroughIgor Ryzhov
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-05-30lib: mgmtd: add manual vty server start option and use itChristian Hopps
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-11lib: when running as a daemon, only redirect sdtin, stdout, sdterr to null ↵Lou Berger
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-03-24*: Convert `struct event_master` to `struct event_loop`Donald Sharp
Let's find a better name for it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_master_XXX functions to event_master_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert struct thread_master to struct event_master and it's ilkDonald Sharp
Convert the `struct thread_master` to `struct event_master` across the code base. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_fetch and thread_call to event_fetch and event_callDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_add_XXX functions to event_add_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename `struct thread` to `struct event`Donald Sharp
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-02-23lib: fix init. use of nb_context to be by value not by referenceChristian Hopps
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-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-01lib: fix one more b0rked format stringDavid Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-12lib: Free some memory in scripting subsystem at shutdownDonald Sharp
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-06-17lib: cleanup red-herring memleaks in parent of daemonizing forkChristian Hopps
- 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-03-07lib: support multiple `--log` optionsDavid Lamparter
Allow simultaneously enabling syslog, stdout and/or file logs. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-02-23*: Change thread->func to return void instead of intDonald Sharp
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-08Merge pull request #8458 from opensourcerouting/xref-5424Donald Sharp
lib: RFC5424 syslog support
2022-01-17Merge pull request #10183 from idryzhov/rework-vrf-renameRafael Zalamena
*: rework renaming the default VRF
2022-01-17lib: add frr_early_init hookDavid Lamparter
To bring up bits that use thread_master before other init happens. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-12-21*: rework renaming the default VRFIgor Ryzhov
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-14lib: shuffle around command line optionsDavid Lamparter
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-09-14lib/module.c and callers of frrmod_load(): fix error messagesG. Paul Ziemba
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-08-25*: Drop `break` after using frr_help_exit() in switch/caseDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>