Commit Graph

342 Commits

Author SHA1 Message Date
Donald Sharp
24a58196dd *: Convert event.h to frrevent.h
We should probably prevent any type of namespace collision
with something else.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -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
e16d030c65 *: Convert THREAD_XXX macros to EVENT_XXX macros
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
5f6eaa9b96 *: Convert a bunch of thread_XX to event_XX
Convert these functions:

thread_getrusage
thread_cmd_init
thread_consumed_time
thread_timer_to_hhmmss
thread_is_scheduled
thread_ignore_late_timer

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
Donald Sharp
cb37cb336a *: Rename thread.[ch] to event.[ch]
This is a first in a series of commits, whose goal is to rename
the thread system in FRR to an event system.  There is a continual
problem where people are confusing `struct thread` with a true
pthread.  In reality, our entire thread.c is an event system.

In this commit rename the thread.[ch] files to event.[ch].

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:16 -04:00
Christian Hopps
39c329bbd1 lib: staticd: vtysh: apply frrbot style requirements
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-03-22 05:22:56 +00:00
Pushpasis Sarkar
1401ee8bf7 lib, mgmtd: Add few fixes for commit-check and rollback
This commit contains fixes for the following issues found
- 'mgmt commit check' issued through 'vtysh -f' was actually commtting the changeset.
- On config validation failure backend, mgmtd was not passing the correct error-reason
  to frontend.
- 'mgmt rollback ...' was reverting the change on backend, but config on mgmtd daemon
  remains intact

Signed-off-by: Pushpasis Sarkar <pushpasis@gmail.com>
2023-03-22 05:22:56 +00:00
Christian Hopps
ef43a6329b mgmtd: Add MGMT Frontend Interface Framework
This commit introduces the Frontend Interface which can be used
by front-end management clients like Netconf server, Restconf
Server and CLI to interact with new FRR Management daemon (MGMTd)
to access and sometimes modify FRR management data.

This commit includes the following functionalities in the changeset:
1. Add new Frontend server for clients connect to.
2. Add a C-based Frontend client library which can be used by Frontend
   clients to communicate with MGMTd via the Frontend interface.
3. Maintain a frontend adapter for each connection from an appropriate
   Frontend client to facilitate client requests and track one or more
   client sessions across it.
4. Define the protobuf message format for messages to be exchanged
   between MGMTd Frontend module and the Frontend client.
5. This changeset also introduces an instance of MGMT Frontend client
   embedded within the lib/vty module that can be leveraged by any FRR
   daemon to connect to MGMTd's Frontend interface. The same has been
   integrated with and initialized within the MGMTd daemon's process
   context to implement a bunch of 'set-config', 'commit-apply',
   'get-config' and 'get-data' commands via VTYSH

Co-authored-by: Pushpasis Sarkar <pushpasis@gmail.com>
Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com>
Co-authored-by: Ujwal P <ujwalp@vmware.com>
Signed-off-by: Yash Ranjan <ranjany@vmware.com>
2023-03-21 22:08:32 -04:00
Donald Sharp
7cedcf270e
Merge pull request #12889 from LabNConsulting/chopps/fix-nb-context-arg
lib: fix init. use of nb_context to be by value not by reference
2023-02-24 07:37:09 -05:00
Donatas Abraitis
ba995a720b
Merge pull request #12751 from Pdoijode/pdoijode/ospf-vrf-neighbor-detail-1
ospfd: Added missing fields and option to query specific neighbor in VRF
2023-02-24 11:56:28 +02: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
Donald Sharp
8383d53e43
Merge pull request #12780 from opensourcerouting/spdx-license-id
*: convert to SPDX License identifiers
2023-02-17 09:43:05 -05:00
Donald Sharp
00b0bb99ae lib: Fix non-use of option
Commit d7c6467ba2 added the
ability to specify non pretty printing but unfortunately
forgot to use the option variable to make the whole
thing work.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-16 08:14:22 -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
Pooja Jagadeesh Doijode
6333c54822 lib: Helper function to print empty JSON
Introduced a helper function to print empty JSON object.

Signed-off-by: Pooja Jagadeesh Doijode <pdoijode@nvidia.com>
2023-02-07 14:29:54 -08:00
Donatas Abraitis
96475dfde9
Merge pull request #12707 from donaldsharp/missed_enums
Missed enums
2023-02-07 22:22:27 +02:00
Donald Sharp
d7c6467ba2 lib, bgpd: Add ability to specify that some json output should not be pretty
Initial commit: 23b2a7ef52
changed the json output of `show bgp <afi> <safi> json` to
not have pretty print because when under a situation where
there are a bunch of routes with a large scale ecmp show
output was taking forever and this commit cut 2 minutes out
of vtysh run time.

Subusequent commit: f4ec52f7cc
changed this back.

When upgrading to latest version the long run time was noticed
due to testing.  Let's add back this functionality such that
FRR can have reduced run times with vtysh when it's really
needed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-02 10:28:19 -05:00
Donald Sharp
bde30e78cb lib: Add missing enum's to switch statement
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-01-31 15:15:42 -05:00
David Lamparter
c84e518709 *: no-warn pragmas for non-const format strings
We do use non-constant/literal format strings in a few places for more
or less valid reasons;  put `ignored "-Wformat-nonliteral"` around those
so we can have the warning enabled for everywhere else.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27 12:01:20 +01:00
Donald Sharp
a8a0f80b63 lib: Do not log echo PING commands from watchfrr
Since the `echo PING` commands are from watchfrr and are sent
a whole bunch when an operator has `log commands` on the amount
of logging done is quite significant.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-11-26 09:30:48 -05:00
Donatas Abraitis
061f5d1cb4 lib: Add PCRE2 support
Some results:

```
====
PCRE
====
% ./a.out "^65001" "65001"
comparing: ^65001 / 65001

ret status: 0
[14:31] donatas-pc donatas /home/donatas
% ./a.out "^65001_" "65001"
comparing: ^65001_ / 65001

ret status: 0

=====
PCRE2
=====
% ./a.out "^65001" "65001"
comparing: ^65001 / 65001

ret status: 0
[14:30] donatas-pc donatas /home/donatas
% ./a.out "^65001_" "65001"
comparing: ^65001_ / 65001

ret status: 1
```

Seems that if using PCRE2, we need to escape outer `()` chars and `|`. Sounds
like a bug.
But this is only with some older PCRE2 versions. With >= 10.36, I wasn't able
to reproduce this, everything is fine and working as expected.

Adding _FRR_PCRE2_POSIX definition because pcre2posix.h does not have
include's guard.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-11-07 21:23:53 +02:00
David Lamparter
89cb86aeb0 build, vtysh: extract vtysh commands from .xref
Rather than running selected source files through the preprocessor and a
bunch of perl regex'ing to get the list of all DEFUNs, use the data
collected in frr.xref.

This not only eliminates issues we've been having with preprocessor
failures due to nonexistent header files, but is also much faster.
Where extract.pl would take 5s, this now finishes in 0.2s.  And since
this is a non-parallelizable build step towards the end of the build
(dependent on a lot of other things being done already), the speedup is
actually noticeable.

Also files containing CLI no longer need to be listed in `vtysh_scan`
since the .xref data covers everything.  `#ifndef VTYSH_EXTRACT_PL`
checks are equally obsolete.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-26 17:12:34 +01:00
Donald Sharp
00c89a3673 lib: Function crypt does not need to be declared mid function
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-06-16 16:31:35 -04:00
Donatas Abraitis
6006b807b1 *: Properly use memset() when zeroing
Wrong: memset(&a, 0, sizeof(struct ...));
    Good:  memset(&a, 0, sizeof(a));

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-05-11 14:08:47 +03:00
Donald Sharp
b4c94f8c4d lib: Fix terminal monitor uninited memory usage on freebsd
When `terminal monitor` is issued I am seeing this for valgrind on freebsd:

2022/03/24 18:07:45 ZEBRA: [RHJDG-5FNSK][EC 100663304] can't open configuration file [/usr/local/etc/frr/zebra.conf]
==52993== Syscall param sendmsg(sendmsg.msg_control) points to uninitialised byte(s)
==52993==    at 0x4CE268A: _sendmsg (in /lib/libc.so.7)
==52993==    by 0x4B96245: ??? (in /lib/libthr.so.3)
==52993==    by 0x4CDF329: sendmsg (in /lib/libc.so.7)
==52993==    by 0x49A9994: vtysh_do_pass_fd (vty.c:2041)
==52993==    by 0x49A9994: vtysh_flush (vty.c:2070)
==52993==    by 0x499F4CE: thread_call (thread.c:2002)
==52993==    by 0x495D317: frr_run (libfrr.c:1196)
==52993==    by 0x2B4068: main (main.c:471)
==52993==  Address 0x7fc000864 is on thread 1's stack
==52993==  in frame #3, created by vtysh_flush (vty.c:2065)

Fix by initializing the memory to `0`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-03-24 18:08:29 -04:00
Donald Sharp
55a70ffb78 lib: Rename enum event to enum vty_event
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-03-02 09:17:47 -05:00
David Lamparter
0798d2760d lib: implement terminal monitor for vtysh
Adds a new logging target that sends log messages to vtysh.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-02-28 13:28:43 +01:00
David Lamparter
b2dde56b2c lib: allow returning a file descriptor over vtysh
This adds the plumbing necessary to yield back a file descriptor to
vtysh.  The fd is passed on the command status code bytes through
AF_UNIX SCM_RIGHTS.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-02-28 13:28:40 +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
Donatas Abraitis
d86cf7aa65
Merge pull request #10084 from opensourcerouting/json-sugar
lib: make JSON output less painful/boilerplate-y
2021-11-18 10:33:52 +02:00
David Lamparter
a8dfd147a0 lib: add vty_json() helper
... this is copypasted all over the codebase & should've been a helper
to begin with really.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
Solyn
46cba0d450
zebra: fix chdir judgment to avoid starting failed in a non-existent directory
Signed-off-by: Solyn <admin@iloft.xyz>
2021-11-16 20:46:14 +08:00
Donald Sharp
e36f61b507 *: Rename quagga_timestamp with frr_timestamp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
David Lamparter
26ae7cc219 lib: keep vty listeners in a proper struct & list
Makes a bit more sense than the odd vector stuff.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-06 21:11:40 +01:00
David Lamparter
43dd8cafa3 lib: replace vtyvec/vtyshvec with lists
These are just used to iterate over active vty sessions, a vector is a
weird choice there.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-06 21:11:40 +01:00
David Lamparter
69b089fbfd lib: remove unused vty_log() functions
These had no remaining users for a while now.  The logging backend has
its own list of receivers.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-06 21:11:40 +01:00
Mark Stapp
036b746570
Merge pull request #9765 from idryzhov/lib-bool-thread-add
lib: change thread_add_* API
2021-10-22 09:59:54 -04:00
ewlumpkin
03bad95aa4 lib: finish fixing spelling in lib files
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-22 03:06:16 +00:00
Igor Ryzhov
ee1455dd98 lib: change thread_add_* API
Do not return pointer to the newly created thread from various thread_add
functions. This should prevent developers from storing a thread pointer
into some variable without letting the lib know that the pointer is
stored. When the lib doesn't know that the pointer is stored, it doesn't
prevent rescheduling and it can lead to hard to find bugs. If someone
wants to store the pointer, they should pass a double pointer as the last
argument.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-20 20:07:15 +03:00
Igor Ryzhov
07679ad98a *: explicitly print "exit" at the end of every node config
There is a possibility that the same line can be matched as a command in
some node and its parent node. In this case, when reading the config,
this line is always executed as a command of the child node.

For example, with the following config:
```
router ospf
 network 193.168.0.0/16 area 0
!
mpls ldp
 discovery hello interval 111
!
```
Line `mpls ldp` is processed as command `mpls ldp-sync` inside the
`router ospf` node. This leads to a complete loss of `mpls ldp` node
configuration.

To eliminate this issue and all possible similar issues, let's print an
explicit "exit" at the end of every node config.

This commit also changes indentation for a couple of existing exit
commands so that all existing commands are on the same level as their
corresponding node-entering commands.

Fixes #9206.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-23 22:08:20 +03:00
David Lamparter
45f0118832 lib: make cputime checks runtime options (v2)
...really no reason to force this into a compile time decision.  The
only point is avoiding the getrusage() syscall, which can easily be a
runtime decision.

[v2: also split cputime & walltime limits]

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-24 16:42:59 +02:00
Igor Ryzhov
763725cd5e lib: fix interface configuration after vrf change
This commit fixes the following problem:

- enter the interface node
- move the interface to another VRF
- try to continue configuring the interface

It is not possible to continue configuration because the XPath stored in
the vty doesn't correspond with the actual state of the system anymore.

For example:
```
nfware# conf
nfware(config)# interface enp2s0

<-- move the enp2s0 to a different VRF -->

nfware(config-if)# ip router isis 1
% Failed to get iface dnode in candidate DB
```

To fix the issue, go through all connected vty shells and update the
stored XPath.

Suggested-by: Renato Westphal <renato@opensourcerouting.org>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-18 03:27:46 +03:00
Christian Hopps
fd396924d6 northbound: KISS always batch yang config (file read), it's faster
The backoff code assumed that yang operations always completed quickly.
It checked for > 100 YANG modeled commands happening in under 1 second
to enable batching. If 100 yang modeled commands always take longer than
1 second batching is never enabled. This is the exact opposite of what
we want to happen since batching speeds the operations up.

Here are the results for libyang2 code without and with batching.

| action        |  1K rts |  2K rts | 1K rts | 2K rts | 20k rts |
|               | nobatch | nobatch |  batch |  batch |   batch |
| Add IPv4      |    .881 |    1.28 |   .703 |   1.04 |    8.16 |
| Add Same IPv4 |    28.7 |     113 |   .590 |   .860 |    6.09 |
| Rem 1/2 IPv4  |    .376 |    .442 |   .379 |   .435 |    1.44 |
| Add Same IPv4 |    28.7 |     113 |   .576 |   .841 |    6.02 |
| Rem All IPv4  |    17.4 |    71.8 |   .559 |   .813 |    5.57 |

(IPv6 numbers are basically the same as iPv4, a couple percent slower)

Clearly we need this. Please note the growth (1K to 2K) w/o batching is
non-linear and 100 times slower than batched.

Notes on code: The use of the new `nb_cli_apply_changes_clear_pending`
is to commit any pending changes (including the current one). This is
done when the code would not correctly handle a single diff that
included the current changes with possible following changes. For
example, a "no" command followed by a new value to replace it would be
merged into a change, and the code would not deal well with that. A good
example of this is BGP neighbor peer-group changing. The other use is
after entering a router level (e.g., "router bgp") where the follow-on
command handlers expect that router object to now exists. The code
eventually needs to be cleaned up to not fail in these cases, but that
is for future NB cleanup.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-02 14:05:26 +00:00
Patrick Ruddy
5bb91468c5
Merge pull request #8003 from donaldsharp/timings
lib: Differentiate between real and cpu bound processes
2021-04-14 18:33:18 +01:00
David Lamparter
2c12c904ea lib: save errno in vty_out()
... so `%m` works correctly, without us trampling over `errno` before we
get to formatting it.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:34:56 +02:00
Donald Sharp
9b8e01cae4 lib: Incorporate Wall and Cpu warning into show thread cpu
Incorporate into the `show thread cpu` the number of times
we have issued warnings about a particular thread being
too slow.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-03-26 13:27:45 -04:00
Donald Sharp
039d547f6f lib: Differentiate between real and cpu bound processes
When generating SLOW_THREAD warnings let's differentiate between
a cpu bound process and a wall bound process.  Effectively
a slow thread can now be a process in FRR doing lots of work( cpu bound )
or wall bound ( the cpu is heavy load and a FRR process may be pre-empted
and never scheduled ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-03-26 11:41:57 -04:00