Commit Graph

4978 Commits

Author SHA1 Message Date
anlan_cs
10f02a2ac9 lib: fix the right value is returned for fail cases
Currently `bfd_get_peer_info` should return invalid sp->family
and dp->family during fail cases.

Before this fix, in those fail cases `bfd_get_peer_info` maybe
return valid sp->family and dp->family.

This fix ensures all fail cases return invalid sp->family and
dp->family for outside callers.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-12 08:08:29 -05:00
David Schweizer
0b11b56abd
ospf6d: add LSA stats to show area json output
Signed-off-by: David Schweizer <dschweizer@opensourcerouting.org>
2022-01-12 12:32:33 +01:00
anlan_cs
03ff0db15d lib: rename one bfd parameter name to reflect real meaning
As to "struct bfd_session_arg", just rename parameter "ttl" to "hops", in order
to  reflect real meaning.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-10 08:15:08 -05:00
anlan_cs
8b3fd12cda lib: small debug adjustment for bfd
Just use `__func__` to display function name.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-08 06:01:08 -05: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
b8984d4e90 lib: default VRF may not exist on early exit
If we're exiting before we finished initializing, we can end up trying
to shut down a NULL vrf here.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-12-14 18:12:25 +01: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
Martin Winter
e574b842a1
bgpd: fix BGP ORF Prefix-length matching
BGP ORF Prefix list incorrectly rejected list with a GE or LE to match the actual
prefix.

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
2021-12-14 14:53:53 +01:00
Donatas Abraitis
e69ae079b7
Merge pull request #9899 from Drumato/zebra-srv6-locator-detail-json-support
zebra: Add support for json output in srv6 locator detail command
2021-12-14 09:11:36 +02:00
Igor Ryzhov
fb2e99ef9c lib: routemap config output cleanup
Just a small cleanup to unify the code and remove duplication.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 21:00:01 +03:00
Russ White
90f88bbc94
Merge pull request #10110 from idryzhov/if-yang-remove-vrf
lib, yang: remove vrf from the interface list key
2021-12-02 08:33:05 -05:00
Donatas Abraitis
e2144103f8
Merge pull request #9878 from pguibert6WIND/resolver_vrf
lib: resolver per vrf support
2021-12-01 08:12:33 +02:00
Olivier Dugeon
8693b4d66e lib: Update Link State functions to handle IPv6
In order to add Link State Traffic Engineering to IS-IS, Link State library
should have been updated:

- Correct Node and Edge RB Tree comparison functions to support key > 32 bits
- Change Subnet RB Tree comparison function to take into account host part of
  the prefix i.e. 10.0.0.1/24 and 10.0.0.2/24 are considered as different
- Add new function to convert IS-IS ISO system ID into Vertex or Edge key that
  take into account Endianness architecture
- Correct Vertex and Edge creation and search function accordingly
- Add extra Adjacency entries in Link State Attributes for IPv6 Segment Routing
- Update send/received and show TED functions accordingly

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2021-11-30 15:22:28 +01:00
Quentin Young
23b2f11a47
Merge pull request #9798 from abuibrahim/master
fix broken northbound confd
2021-11-30 00:17:28 -05:00
Yamato Sugawara
559f4b2f2a zebra: Add support for json output in srv6 locator detail command
Signed-off-by: Yamato Sugawara <yamato.sugawara@linecorp.com>
2021-11-28 23:53:41 +00:00
Igor Ryzhov
cb3fa0a612
Merge pull request #10124 from ton31337/feature/vty_json 2021-11-29 02:11:29 +03:00
Donatas Abraitis
382dcab318 lib: Convert vty_out to vty_json for JSON
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:50:47 +02:00
Donatas Abraitis
746a6eda2f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:35:55 +02:00
Donatas Abraitis
a6c8642429 lib: Replace prefix2str for JSON to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:31:08 +02:00
Donatas Abraitis
82f191a213 bgpd: Add an ability to match ipv6 next-hop by prefix-list
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-24 16:28:31 +02:00
Renato Westphal
959331a339 lib: do not include bgpd headers in route_opaque.h
Duplicate a couple of definitions in order to remove the bgpd
includes from this libfrr header. This is necessary to fix some
name collisions like PREFIX_LIST_IN being defined differently on
multiple daemons (as soon as other daemons start including
route_opaque.h).

Including daemon headers on libfrr headers is a bad practice and
should be avoided whenever possible.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 14:24:07 -03:00
Donatas Abraitis
8f241168b7 lib: Use autocomplete for route-map <name> <action> <seq>
```
exit1-debian-11(config)# route-map ?
  RMAP_NAME  Route map tag
     belekas testas
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-23 16:10:10 +02:00
Igor Ryzhov
4ac61f7a2a
Merge pull request #10024 from ton31337/feature/match_ipv6_next-hop_access-list
bgpd: match ipv6 next-hop
2021-11-23 16:45:25 +03:00
Donatas Abraitis
bc63ba980f bgpd: Add an ability to match ipv6 next-hop by access-list
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-23 13:47:26 +02:00
Igor Ryzhov
574445ecaf lib, yang: remove vrf from the interface list key
This is needed for the following two reasons:

1. To be able to remove the northbound HACK in if_update_to_new_vrf. It
   is totally wrong to rewrite the configuration datastore when some
   operational state changes. It is a hard blocker for storing a
   configuration data in a management daemon which knows nothing about
   the operational state.
2. To allow changing the VRF of the interface using FRR CLI or any other
   frontend in the future. If the VRF is a part of the key, it can't be
   changed. If the VRF is a simple leaf, it becomes possible to change
   it and thus move the interface between VRFs. For now I mark the leaf
   as a "config false" as it's not yet possible to control it from FRR.

But we can't simply remove the VRF from the key, because it is needed to
distinguish interfaces when using netns based VRFs, as it is possible to
have multiple interfaces with the same name in different namespaces. To
handle this, I came up with an idea to store both VRF and an interface
name in the "name" leaf using the pattern "vrfname:ifname". For example,
if there's an interface "eth0" in VRF "red" then its "name" leaf will be
"red:eth0".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-23 12:57:52 +03:00
Philippe Guibert
c742573b67 lib: resolver per vrf support
add a parameter to resolver api that is the vrf identifier. this permits
to make resolution self to each vrf. in case vrf netns backend is used,
this is very practical, since resolution can happen on one netns, while
it is not the case in an other one.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-11-23 09:02:23 +01:00
Igor Ryzhov
096f7609f9 *: cleanup ifp->vrf_id
Since f60a1188 we store a pointer to the VRF in the interface structure.
There's no need anymore to store a separate vrf_id field.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-22 20:47:23 +03:00
Donald Sharp
9d5a61264a
Merge pull request #10076 from idryzhov/if-is-loopback-or-vrf
*: unify if_is_loopback/if_is_loopback_or_vrf
2021-11-22 12:02:21 -05:00
Donatas Abraitis
039fb41165
Merge pull request #10096 from mjstapp/fix_ted_free
lib: use _safe iteration during link_state/ted cleanup
2021-11-22 15:38:05 +02:00
Igor Ryzhov
03030106ce bgpd, lib: fix inconsistency of match ip/ipv6 next-hop commands
For IPv4 matching, we have "match ip next-hop address A.B.C.D".
For IPv6 matching, we have "match ipv6 next-hop X:X::X:X".

To have consistency, let's add "address" keyword to IPv6 commands.
Old commands are preserved as hidden for backward compatibility.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-19 21:11:52 +03:00
Igor Ryzhov
0609190219
Merge pull request #10074 from opensourcerouting/assorted-20211116
lib/vtysh/ospf6d: assorted small bits
2021-11-19 15:43:10 +03:00
Igor Ryzhov
3c52293809
Merge pull request #10092 from ton31337/feature/replace_json_object_string_add_to_json_object_string_addf_for_inet_ntop
*: inet_ntop for JSON output
2021-11-18 22:19:40 +03:00
Donatas Abraitis
4e9a98636f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-18 18:45:41 +02:00
Mark Stapp
bb0e68802d lib: use _safe iteration during link_state/ted cleanup
Use the _safe iterators when cleaning up the link-state module's
vertices, edges, and subnets.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-11-18 11:23:39 -05:00
zyxwvu Shi
1c1c6c3f2a lib: Do not use sizeof() on size_t errmsg_len.
This prevents caller from getting complete
validation message.

Signed-off-by: zyxwvu Shi <i@shiyc.cn>
2021-11-18 22:44:00 +08:00
Donatas Abraitis
e46a4ac958 lib: Replace inet_ntop to %pI4/6 for JSON outputs
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-18 11:35:31 +02: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
b5bb6c6764 lib: use json-printf in filter code
(This is mostly just to exercise the code, the actual replacement needs
to be a cocci script.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
David Lamparter
ad9df66ce2 lib: use vty_json()
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
David Lamparter
2c4dfddb01 lib: add printfrr to json string helpers
... these should probably have been added ages ago.
`json_object_string_addf(json, "key", "%pFX", prefix)` is super useful.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01: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
Donald Sharp
41e69bb32f
Merge pull request #9852 from opensourcerouting/pim-nht-rework
pimd: make PIM NHT less weird
2021-11-17 09:34:51 -05:00
David Lamparter
4be297235e
Merge pull request #10075 from myloft/fix-chdir-judge 2021-11-17 12:26:23 +01:00
David Lamparter
30f0195d0a lib: fix style misalignment
Just a line that sticks out like a sore thumb.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 11:33:37 +01:00
David Lamparter
1e9044be8d *: clean up ifp-by-local-address function(s)
Most users of if_lookup_address_exact only cared about whether the
address is any local address.  Split that off into a separate function.

For the users that actually need the ifp - which I'm about to add a few
of - change it to prefer returning interfaces that are UP.

(Function name changed due to slight change in behavior re. UP state, to
avoid possible bugs from this change.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 11:17:44 +01:00
David Lamparter
0beb61abc2 vtysh: dispatch unique-id backtrace cmd properly
i.e. to whoever cares, since some unique IDs (from libfrr) are valid
everywhere but some others (from the daemons) only apply to specific
daemons.

(Default handling aborts on first error, so configuring any unique IDs
that don't exist on the first daemon vtysh connects to just failed
before this.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
David Lamparter
dd2c81b8c0 lib: rework vty_check_node_for_xpath_decrement
...by having a flag in struct cmd_node rather than hardcoding it in
`lib/command.c`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
David Lamparter
88711d8a91 lib: use hash for route-map set/match commands
Why would this be in a vector to loop over with strcmp()'ing each
item...  that just makes no sense.  Use a hash instead.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
Igor Ryzhov
608c887069 *: unify if_is_loopback/if_is_loopback_or_vrf
We should always treat the VRF interface as a loopback. Currently, this
is not the case, because in some old pre-VRF code we use if_is_loopback
instead of if_is_loopback_or_vrf. To avoid any future problems, the
proposal is to rename if_is_loopback_or_vrf to if_is_loopback and use it
everywhere. if_is_loopback is renamed to if_is_loopback_exact in case
it's ever needed, but currently it's not used anywhere.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-16 18:07:11 +03: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
Igor Ryzhov
3e51a84a22 lib: rename bfd function to reflect real functionality
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-15 18:16:30 +03:00
Russ White
47af849f95
Merge pull request #9956 from idryzhov/bfd-remove-ttl
lib: remove confusing bfd TTL API
2021-11-14 12:24:28 -05:00
Donald Sharp
045e023549
Merge pull request #10032 from opensourcerouting/build-fix-20211111
build: assorted build system improvements, 2021-11 edition
2021-11-13 10:10:59 -05:00
Jafar Al-Gharaibeh
3357afaa74
Merge pull request #10036 from donaldsharp/finally_frr
Finally frr
2021-11-12 21:35:27 -06:00
Ruslan Babayev
fc3ebe1235 lib: confd: fix format-truncation warnings
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
2021-11-11 23:05:46 -08:00
Ruslan Babayev
7f88892d96 lib: confd: fix non-void return-type warning
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
2021-11-11 23:05:46 -08:00
Ruslan Babayev
722e430fd5 lib: confd: fix compilation broken with libyang2
Fixes the following compilation errors:

In file included from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/tree_data.h:30,
                 from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/context.h:22,
                 from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/libyang.h:24,
                 from ../../src/frr/lib/yang.h:25,
                 from ../../src/frr/lib/northbound.h:27,
                 from ../../src/frr/lib/vty.h:36,
                 from ../../src/frr/lib/ferr.h:28,
                 from ../../src/frr/lib/lib_errors.h:24,
                 from ../../src/frr/lib/northbound_confd.c:23:
../../src/frr/lib/northbound_confd.c: In function 'frr_confd_init_cdb':
../../src/frr/lib/northbound_confd.c:533:28: error: 'const struct lys_module' has no member named 'data'
  533 |   LY_LIST_FOR (module->info->data, snode) {
      |                            ^~
../../src/frr/lib/northbound_confd.c: In function 'frr_confd_data_get_next_object':
../../src/frr/lib/northbound_confd.c:921:3: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  921 |   LY_LIST_FOR (lysc_node_child(nb_node->snode), child) {
      |   ^~~~~~~~~~~

Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
2021-11-11 23:05:46 -08:00
Donald Sharp
13576f45f8
Merge pull request #9981 from idryzhov/fix-vrf-delete
lib: fix vrf deletion when the last interface is deleted
2021-11-11 18:41:02 -05:00
Donald Sharp
b72aae2e04 *: Cleanup some documentation from quagga->frr
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05: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
Donald Sharp
7cc91e67a3 *: Convert quagga_signal_X to frr_signal_X
Naming functions/data structures more appropriately for
the project we are actually in.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
David Lamparter
f642358837 build: fix duplicate yang.c file inclusions
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-11 15:49:40 +01:00
Donald Sharp
7a8ce9d56d *: use compiler.h MIN/MAX macros instead of everyone having one
We had various forms of min/max macros across multiple daemons
all of which duplicated what we have in compiler.h.  Convert
everyone to use the `correct` ones

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 09:39:52 -05:00
David Lamparter
3bd7df45a2 build: link libcrypt & libdl to libfrr only
They're not needed elsewhere.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-11 15:29:48 +01:00
Russ White
eda02ab9da
Merge pull request #10025 from opensourcerouting/xref-backtrace
lib: backtraces for specific log messages
2021-11-11 08:08:19 -05:00
Russ White
b761cb131a
Merge pull request #9864 from ton31337/feature/access_list_autocomplete
lib: Add autocomplete for access-lists
2021-11-11 08:03:33 -05:00
Igor Ryzhov
ce27a13e90 lib: fix vrf deletion when the last interface is deleted
Currently, we automatically delete an inactive VRF when its last
interface is deleted. This code introduces a couple of crashes because
of the following problems:
- vrf_delete is called before calling if_del hook, so daemons may try to
  dereference an ifp->vrf pointer which is freed
- in if_terminate, we continue to use the VRF in the loop condition
  after the last interface is deleted

This check is needed only when the interface is deleted by the user,
because if the interface is deleted by the system, VRF must still exist
in the system. Move the check to appropriate places to fix crashes.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11 14:57:59 +03:00
Igor Ryzhov
92f85e656b lib: remove confusing bfd TTL API
There are two APIs to control the expected number of hops for a BFD
session – `bfd_sess_set_mininum_ttl` and `bfd_sess_set_hop_count`.
The former is very confusing, as it takes an expected TTL in the
BFD packet which is actually a protocol internal value. The latter is
simple and straightforward – it takes an expected number of hops, which
is always 1 for single-hop and >1 for multi-hop.

As the former API is not used anywhere, just remove it to avoid any
confusion.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11 14:56:04 +03:00
David Lamparter
3942ee1f7b lib: fix elf_py TLS section handling
... need to ignore TLS sections, their address is effectively
meaningless but can overlap other sections we actually need to access.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 15:30:56 +01:00
David Lamparter
8d4e934b08 lib: avoid include loop with assert.h
`assert.h` -> `xref.h` -> `typesafe.h` -> `assert.h`

Might be possible to do this more cleanly some way, but that way is not
obvious, so here's the "simple & dumb" approach.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 12:36:50 +01:00
David Lamparter
ef990bd94b lib: add debug uid XXXXX-XXXXX backtrace
Looks much prettier if `libunwind` is available, but works with glibc or
libexecinfo's `backtrace()` too.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 12:36:50 +01:00
David Lamparter
4894e9c12a lib: stuff xrefs into a tree for lookup
... so we can actually access by UID without searching the entire list.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-11-10 10:39:17 +01:00
David Lamparter
b0993fb201 lib: add missing include in typerb.h
The RB-tree macros use memset(), so we need to #include <string.h>

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-11-10 10:39:17 +01:00
David Lamparter
14ae4f17a8 lib: remove vector_get_index()
... its only purpose was to serve as a footgun, and all such uses have
been eliminated now.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-08 14:07:30 +01:00
David Lamparter
faf079ff7e lib: fix c-ares thread misuse
The `struct thread **ref` that the thread code takes is written to and
needs to stay valid over the lifetime of a thread.  This does not hold
up if thread pointers are directly put in a `vector` since adding items
to a `vector` may reallocate the entire array.  The thread code would
then write to a now-invalid `ref`, potentially corrupting entirely
unrelated data.

This should be extremely rare to trigger in practice since we only use
one c-ares channel, which will likely only ever use one fd, so the
vector is never resized.  That said, c-ares using only one fd is just
plain fragile luck.

Either way, fix this by creating a resolver_fd tracking struct, and
clean up the code while we're at it.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-08 14:06:21 +01: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
Russ White
208a07a8b8
Merge pull request #9972 from opensourcerouting/bfd-bgp-fixes
bfdd,bgpd: fix some integration bugs
2021-11-05 17:31:29 -04:00
Russ White
ed79d896b2
Merge pull request #9833 from idryzhov/cleanup-if-by-index-all-vrf
*: fix usage of if_lookup_by_index_all_vrf
2021-11-05 15:17:31 -04:00
Rafael Zalamena
ca30ac7fc3 lib: constify read only parameters
Constify some BFD library function parameters to signalize they are
not going to get modified.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-11-04 08:01:28 -03:00
Renato Westphal
ae09457333 lib: fix BFD IPv6 session address change
Pass the correct family type and remove unneeded casts.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-04 08:00:30 -03:00
Igor Ryzhov
d2dbaf3b5e lib: fix crash when terminating inactive VRFs
If the VRF is not enabled, if_terminate deletes the VRF after the last
interface is removed from it. Therefore daemons crash on the subsequent
call to vrf_delete. We should call vrf_delete only for enabled VRFs.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-03 12:53:02 +03:00
Igor Ryzhov
9acc98c865 zebra: fix stale pointer when netns is deleted
When the netns is deleted, we should always clear the vrf->ns_ctxt
pointer. Currently, it is not cleared when there are interfaces in the
netns at the time of deletion.

If the netns is re-created, zebra crashes because it tries to use the
stale pointer.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-03 11:11:15 +03:00
Donald Sharp
821a877fd7 lib: Return Null when we have an empty string for script name
The script entries were being stored in a hash lookup with
the script name a pre-defined array of characters.  The hash
lookup is succeeding since it is auto-installed at script
start time irrelevant if there is a handler function.

Modify the code so that if the scriptname is an empty
string "\0" just return a NULL so that zebra does
not attempt to actually load up the script

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-01 07:29:10 -04:00
Donatas Abraitis
c60dec369a lib: Add autocomplete for access-lists
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-31 20:26:06 +02:00
Igor Ryzhov
0373909a5f
Merge pull request #9863 from ton31337/feature/prefix-list_autocomplete
lib: Add autocomplete for prefix-list under route-maps
2021-10-29 13:30:04 +03:00
Igor Ryzhov
35a8ebb5db
Merge pull request #9879 from Orange-OpenSource/link_state
lib: Fix comparison function in link_state.c
2021-10-29 13:26:23 +03:00
Olivier Dugeon
f4157b4f6e lib: Fix comparison function in link_state.c
ls_node_same, ls_attributes_same and ls_prefix_same are not producing expected
result due to a wrong usage of memcmp. In addition, if respective structures
are not initialized with 0, there is a risk that the comparison failed.

This patch correct usage of memcmp and expand comparison to each invidual
parameters of the respective structure for safer result.

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2021-10-29 10:16:12 +02:00
Igor Ryzhov
35367f0350 lib: make if_lookup_by_index_all_vrf internal
This function doesn't work correctly with netns VRF backend as the same
index may be used in multiple netns simultaneously. So let's hide it
from the public API to reduce temptation to use it instead of writing
the correct code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-28 18:54:46 +03:00
Igor Ryzhov
8d62b34195 lib: remove wrong setting of interface configured flag
The fact that the interface name is used in some nexthop config doesn't
mean that the interface is configured.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-28 18:54:46 +03:00
Donatas Abraitis
943224a13a lib: Add autocomplete for prefix-list under route-maps
```
exit1-debian-9(config-route-map)# match ip route-source prefix-list ?
  <cr>
  PREFIXLIST_NAME  IP prefix-list name
     p1 p2
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-28 14:01:13 +03:00
Russ White
f727c6ae8a
Merge pull request #9837 from idryzhov/cleanup-if-by-name-vrf-all
*: fix usage of if_lookup_by_name_all_vrf
2021-10-27 15:29:39 -04:00
Quentin Young
0c124f75db
Merge pull request #9440 from dlqs/dplanehook2 2021-10-26 15:26:32 -04:00
Mark Stapp
d127998785
Merge pull request #9846 from idryzhov/lib-zebra-netns
lib: move zebra-only netns stuff to zebra
2021-10-26 12:50:26 -04:00
Mark Stapp
697257179d
Merge pull request #9820 from idryzhov/if-nb-config
*: fix interface config write in NB-converted daemons
2021-10-26 11:50:05 -04:00
Russ White
a2b52cbeb4
Merge pull request #9854 from opensourcerouting/zapi-call-table
*: convert zclient callbacks to table
2021-10-26 11:33:44 -04:00
Hiroki Shirokura
8563b9722a lib: fix srv6 route hardcode with BGP
zclient_send_localsid is called by various routing protocol daemons. To set the
srv6 endpoint function. Fix a hard-coded error in the initial implementation.
Before this PR, the srv6 function will be registered to zebra as a BGP route
even if isisd executes zclient_send_localsid.

Signed-off-by: Hiroki Shirokura <hiroki.shirokura@linecorp.com>
2021-10-25 23:38:42 +00:00
Donald Sharp
d9654571f9
Merge pull request #9316 from ton31337/fix/send_best_path_reason_for_zebra
bgpd: Send BGP best path reason to Zebra
2021-10-25 11:09:20 -04:00
Igor Ryzhov
104fd76738 *: fix interface config write in NB-converted daemons
When writing the config from the NB-converted daemon, we must not rely
on the operational data. This commit changes the output of the interface
configuration to use only config data. As the code is the same for all
daemons, move it to the lib and remove all the duplicated code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-25 15:31:07 +03:00
Donald Sharp
6f354338f9
Merge pull request #9824 from idryzhov/nb-cli-const-lyd-node
lib: northbound cli show/cmd functions must not modify data nodes
2021-10-25 07:55:39 -04:00
Jafar Al-Gharaibeh
63da89db77
Merge pull request #9742 from elimbaum/add-vlan-actions
pbrd: add vlan actions to vty
2021-10-23 00:06:16 -05: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
Donald Sharp
3c8161eaa8
Merge pull request #9843 from opensourcerouting/vtysh-startup-cost
vtysh: improve startup time by ca. ×6
2021-10-20 18:52:00 -04: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
Donald Sharp
a505383d6a lib: Add a thread_is_scheduled function
The function thread_is_scheduled allows us to know if
the particular thread is scheduled for execution or not.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-20 08:28:52 -04:00
Mark Stapp
52e458d922
Merge pull request #9766 from opensourcerouting/typesafe-member-nhrp-zap
lib: add typesafe membership-test functions
2021-10-20 08:13:17 -04:00
David Lamparter
a243d1db93 *: convert zclient callbacks to table
This removes a giant `switch { }` block from lib/zclient.c and
harmonizes all zclient callback function types to be the same (some had
a subset of the args, some had a void return, now they all have
ZAPI_CALLBACK_ARGS and int return.)

Apart from getting rid of the giant switch, this is a minor security
benefit since the function pointers are now in a `const` array, so they
can't be overwritten by e.g. heap overflows for code execution anymore.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-20 13:28:46 +02:00
Donald Lee
1247efcce4 zebra: Add dplane hook point
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
a3ef7ae835 lib: Add frrscript names hash
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
263951c1be lib: Register encoders/decoders for dplane hook
These are for encoding the dplane ctx object. The decoders are noops.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
9b851b74b0 lib: Add encoder/decoder for nexthop/nexthop group
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
e6f42b94c6 lib: Add encoders/decoders for ipaddr/ethaddr
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
David Lamparter
40ee228da9 lib: add unsorted typesafe_anywhere()
*_anywhere(item) returns whether an item is on _any_ container.  Only
available for unsorted containers for now.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
David Lamparter
d259ca0989 lib: use sentinel for single-linked lists
Using a non-NULL sentinel allows distinguishing between "end of list"
and "item not on any list".  It's a compare either way, just the value
is different.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
David Lamparter
f45897e45c lib: typesafe *_member()
This provides a "is this item on this list" check, which may or may not
be faster than using *_find() for the same purpose.  (If the container
has no faster way of doing it, it falls back to using *_find().)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
David Lamparter
4a1b3289c7 lib: null out deleted pointers in typesafe containers
Some of the typesafe containers didn't null out their innards of items
after an item was deleted or popped off the container.  This is both a
bit unsafe as well as hinders the upcoming _member() from working
efficiently.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
Igor Ryzhov
f60a11883c lib: allow to create interfaces in non-existing VRFs
It allows FRR to read the interface config even when the necessary VRFs
are not yet created and interfaces are in "wrong" VRFs. Currently, such
config is rejected.

For VRF-lite backend, we don't care at all about the VRF of the inactive
interface. When the interface is created in the OS and becomes active,
we always use its actual VRF instead of the configured one. So there's
no need to reject the config.

For netns backend, we may have multiple interfaces with the same name in
different VRFs. So we care about the VRF of inactive interfaces. And we
must allow to preconfigure the interface in a VRF even before it is
moved to the corresponding netns. From now on, we allow to create
multiple configs for the same interface name in different VRFs and
the necessary config is applied once the OS interface is moved to the
corresponding netns.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-19 15:29:51 +03:00
Igor Ryzhov
62d89c648b lib: move zebra-only netns stuff to zebra
When something is used only from zebra and part of its description is
"should be called from zebra only" then it belongs to zebra, not lib.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-19 00:16:10 +03:00
David Lamparter
14c39974bb lib: keep element count in vector code
... to speed up vector_empty_slot() among other things.

Behavior should be 100% identical to previous.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
David Lamparter
0e06eb8b2e vtysh: defer CLI tree building
We don't need the CLI tree until we actually enter the node.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
David Lamparter
8005767b2e lib: assign CLI varnames while parsing
... rather than running a costly extra pass across the finished tree.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
Donatas Abraitis
840b90f501
Merge pull request #9828 from idryzhov/if-lookup-optimize
lib: optimize if_lookup_by_name_all_vrf
2021-10-16 11:17:57 +03:00
Igor Ryzhov
0df2e1888b lib: make if_lookup_by_name_all_vrf internal
This function doesn't work correctly with netns VRF backend as the same
ifname may be used in multiple netns simultaneously. So let's hide it
from the public API to reduce temptation to use it instead of writing
the correct code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-15 03:44:42 +03:00
Igor Ryzhov
5d8694aee7 lib: remove wrong setting of interface configured flag
The fact that the interface name is used in some nexthop config doesn't
mean that the interface is configured.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-15 03:42:52 +03:00
Donatas Abraitis
1d7260a1b5 bgpd: Send BGP best path reason to Zebra
```
exit1-debian-9# show ip route 172.16.16.1/32
Routing entry for 172.16.16.1/32
  Known via "bgp", distance 20, metric 0, best
  Last update 00:00:28 ago
  * 192.168.0.2, via eth1, weight 1
    AS-Path          : 65003
    Communities      : first 65001:2 65001:3
    Large-Communities: 65001:1:1 65001:1:2 65001:1:3
    Selection reason : First path received
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-14 16:52:47 +03:00
Donatas Abraitis
7b3e821076
Merge pull request #9817 from donaldsharp/link_type_ordering
lib: Add missing enum values in switch statement for if_link_type_str
2021-10-14 16:25:02 +03:00
Donald Sharp
c6c39c05b5
Merge pull request #9684 from opensourcerouting/printfrr-false-positive
*: `frr-format` with unmodified GCC
2021-10-14 07:34:20 -04:00
Igor Ryzhov
d555177021
Merge pull request #9751 from ewlumpkin/comment_spelling_fixes
lib: fix spelling nits in more lib files' comments
2021-10-14 02:05:44 +03:00
David Lamparter
c5726f0314
Merge pull request #9676 from donaldsharp/import_register 2021-10-13 22:28:03 +02:00
Igor Ryzhov
5393f4db3f lib: optimize if_lookup_by_name_all_vrf
We already have a VRF pointer, no need to search for it again.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-13 23:23:41 +03:00
Igor Ryzhov
2560505196 lib: northbound cli show/cmd functions must not modify data nodes
To ensure this, add a const modifier to functions' arguments. Would be
great do this initially and avoid this large code change, but better
late than never.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-13 20:12:35 +03:00
Donald Sharp
ba62a5c522 lib: Add missing enum values in switch statement for if_link_type_str
The switch statement over `enum zebra_link_type` had a default
and FRR was missing a few of the pre-defined types we cared about.
Remove the default statement and add the missing values.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-13 07:58:37 -04:00
Donatas Abraitis
314479e114
Merge pull request #9715 from idryzhov/cleanup-number-named-acl
*: cleanup number-named access-lists in CLI
2021-10-13 10:00:43 +03:00
Russ White
8274736a0d
Merge pull request #9764 from idryzhov/thread-add-local
*: don't pass pointers to a local variables to thread_add_*
2021-10-08 13:54:23 -04:00
Igor Ryzhov
7e86999140 *: cleanup number-named access-lists in CLI
There's no more difference between number-named and word-named access-lists.
This commit removes separate arguments for number-named ACLs from CLI.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-08 19:25:41 +03:00
David Lamparter
1c50c7243f
Merge pull request #9345 from mjstapp/fix_lib_zmq_free 2021-10-07 15:20:19 +02:00
Eli Baum
d70a31a3ef pbrd: add vlan actions to vty
Signed-off-by: Eli Baum <ebaum@mitre.org>
2021-10-07 09:14:59 -04:00
Igor Ryzhov
7640e3c60b *: don't pass pointers to a local variables to thread_add_*
We should never pass pointers to local variables to thread_add_* family.
When an event is executed, the library writes into this pointer, which
means it writes into some random memory on a stack.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-07 16:01:03 +03:00
Igor Ryzhov
72618ba82a lib: fix incorrect thread management
The current code passes an address of a local variable to `thread_add_read`
which stores it into `thread->ref` by the lib. The next time the thread
callback is executed, the lib stores NULL into the `thread->ref` which
means it writes into some random memory on the stack.

To fix this, we should pass a pointer to the vector entry to the lib.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-06 19:13:12 +03:00
Russ White
a3232e63e6
Merge pull request #9733 from opensourcerouting/grpc-fix-missing
lib: fix gRPC crash on missing YANG node
2021-10-05 19:24:34 -04:00
ewlumpkin
214d8a60e1 lib: fix spelling nits in more lib files
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-05 21:42:57 +00:00
Rafael Zalamena
0f538858c2 lib: prevent gRPC assert on missing YANG node
`yang_dnode_get` will `assert` if no YANG node/model exist, so lets test for
its existence first before trying to access it.

This `assert` is only acceptable for internal FRR usage otherwise we
might miss typos or unmatching YANG models nodes/leaves. For gRPC usage
we should let users attempt to use non existing models without
`assert`ing.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-10-05 10:22:27 -03:00
ewlumpkin
81eb8fc749 lib: fix spelling nits in command.h
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-05 03:21:50 +00:00
David Lamparter
a89bae26f7
Merge pull request #9560 from LabNConsulting/ziemba/frrmod_load-error-messages
frrmod_load(): fix error messages
2021-09-29 14:35:35 +02:00
David Lamparter
f62de63c6a *: frr-format with unmodified GCC
Since there's very few locations where the `frr-format` actually prints
false positive warnings, consensus seems to be to just work around the
false positives even if the code is correct.

In fact, there is only one pattern of false positives currently, in
`bfdd/dplane.c` which does `vty_out("%"PRIu64, (uint64_t)be64toh(...))`.
The workaround/fix for this is a replacement `be64toh` whose type is
always `uint64_t` regardless of what OS we're on, making the cast
unnecessary.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-28 11:20:32 +02:00
Donald Sharp
027db46917 lib, zebra: Send safi for rnh resolution
Pass down the safi for when we need address
resolution.  At this point in time we are
hard coding the safi to SAFI_UNICAST.
Future commits will take advantage of this.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-27 15:26:05 -04:00
Donald Sharp
6cd9a93ddd zebra: Attempt to clarify variable names as they are used
Cleanup the poorly implemented variable names so that we can
understand what is going on a bit better.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-27 12:38:08 -04:00
Donald Sharp
3d174ce08d *: Remove the ZEBRA_IMPORT_ROUTE_XXX zapi messages
These are no longer really needed.  The client just needs
to call nexthop resolution instead.

So let's remove the zapi types.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-27 12:38:08 -04:00
Donald Sharp
ed6cec97d7 *: Add resolve via default flag 2021-09-27 12:38:08 -04:00
Igor Ryzhov
a8a5b21514
Merge pull request #9429 from yar-fed/vtysh-err-not-running
vtysh: Add error code if daemon is not running
2021-09-22 22:52:52 +03:00
Donald Sharp
86b2043033
Merge pull request #9646 from LabNConsulting/ziemba/skiplist-level-counters-int
lib: skiplist: clean up level counter implementation
2021-09-22 07:21:14 -04:00
G. Paul Ziemba
c324b10f28 lib: skiplist: clean up level counter implementation
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2021-09-21 17:03:53 -07:00
Donald Sharp
5b311cf18d
Merge pull request #9052 from mjstapp/dplane_incoming_dev
zebra: Move incoming netlink interface address change events to the dplane pthread
2021-09-21 10:51:37 -04:00
Yaroslav Fedoriachenko
a32f6a107f vtysh: Add error code if daemon is not running
After `<daemon_name> is not running` message vtysh does not return
error. For example if you disable ospf in `/etc/frr/daemons` and run
`vtysh -c configure -c "router ospf"` it prints the message to stderr,
but returns 0.

This commit will make vtysh return error when not in interractive mode.

But if you run commands from vtysh, you will still be able to enter
views and exit them if daemon is not running.

Signed-off-by: Yaroslav Fedoriachenko <yar.fed99@gmail.com>
2021-09-21 17:51:04 +03:00
Igor Ryzhov
0de76236b1 lib: significantly improve nb cli command sorting
Instead of sorting each command one-by-one using listnode_add_sort, add
them to the list without sorting and then sort the list only once.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-09-17 12:00:58 +03:00
Donald Sharp
827ddd5a1d
Merge pull request #9596 from LabNConsulting/ziemba/printfrr-nexthop
printfrr %pNHcg, %pNHci
2021-09-15 20:23:30 -04:00
Stephen Worley
bc4477ecbd
Merge pull request #9608 from idryzhov/vtysh-segfault
lib: fix segfault on question mark on empty line
2021-09-15 11:43:37 -04:00
Donald Sharp
21ecdb1f34 lib: Fix usage of default
case default has snuck into our code base for switches
over enumerated types.  Remove.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-14 13:27:19 -04:00
G. Paul Ziemba
016cfe701e lib,doc,tests: printfrr %pNHcg, %pNHci
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2021-09-14 10:06:57 -07: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
Igor Ryzhov
b8c01bba53
Merge pull request #9486 from slankdev/slankdev-srv6-no-cli-1
CLI to delete SRv6 locator
2021-09-14 19:04:03 +03:00
Mark Stapp
9c86ee1e02 lib,zebra: use more const
Use const in ipX_martian apis, and in some zebra apis.

Signed-off-by: Mark Stapp <mjs.ietf@gmail.com>
2021-09-14 10:31:45 -04:00
Igor Ryzhov
6ccb661c08 lib: fix segfault on question mark on empty line
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-09-14 15:12:23 +03:00
Igor Ryzhov
f17030115f
Merge pull request #9364 from LabNConsulting/ziemba/vrf_name_to_id-unknown
vrf_name_to_id(): remove and change callers to use vrf_lookup_by_name()
2021-09-14 13:16:24 +03:00
Donatas Abraitis
7d18da9671
Merge pull request #9586 from idryzhov/bgp-default-originate-rmap-fixes
BGP default-originate with route-map fixes
2021-09-12 20:50:36 +03:00
Donatas Abraitis
0f64a435db
Merge pull request #9475 from iqras23/change1
bgpd: VRF-Lite fix nexthop type
2021-09-12 20:47:18 +03:00
Quentin Young
32acb4a7ad
Merge pull request #9497 from opensourcerouting/cli-better-no 2021-09-09 12:22:53 -04:00
Igor Ryzhov
c212584717 lib: add ability to supply separate match/set objects to routemaps
Sometimes it's needed to match by fields of one object but set fields of
another object. The following commit is an example.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-09-08 23:37:50 +03:00
G. Paul Ziemba
a383d4d201 vrf_name_to_id(): remove
vrf_name_to_id() returned VRF_DEFAULT when the vrf name was
    unknown, hiding errors. Per community recommendation, vrf_name_to_id()
    is now removed and the few callers now use vrf_lookup_by_name()
    directly.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2021-09-07 09:47:24 -07:00
Hiroki Shirokura
15588d7b63 lib: add zapi encode/decode func for srv6 locator
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-09-07 12:54:01 +00:00
Kantesh Mundaragi
0789eb69e5 bgpd: VRF-Lite fix nexthop type
Description:
Change is intended for fixing the following issues related to vrf route leaking:

Routes with special nexthops i.e. blackhole/sink routes when imported,
are not programmed into the FIB and corresponding nexthop is set as 'inactive',
nexthop interface as 'unknown'.

While importing/leaking routes between VRFs, in case of special nexthop(ipv4/ipv6)
once bgp announces route(s) to zebra, nexthop type is incorrectly set as
NEXTHOP_TYPE_IPV6_IFINDEX/NEXTHOP_TYPE_IFINDEX
i.e. directly connected even though we are not able to resolve through an interface.
This leads to nexthop_active_check marking nexthop !NEXTHOP_FLAG_ACTIVE.
Unable to find the active nexthop(s), route is not programmed into the FIB.

Whenever BGP leaks routes, set the correct nexthop type, so that route gets resolved
and correctly programmed into the FIB, in the imported vrf.

Co-authored-by: Kantesh Mundaragi <kmundaragi@vmware.com>
Signed-off-by: Iqra Siddiqui <imujeebsiddi@vmware.com>
2021-09-07 01:50:06 -07:00
Donald Sharp
3702e8577f
Merge pull request #9563 from opensourcerouting/build-strict-prototypes
build: `-Wstrict-prototypes` (+ BSD `sed`)
2021-09-06 12:28:33 -04:00
Donald Sharp
0e099318c8 lib: Remove unused function vrf_generate_id
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-02 09:19:48 -04:00
Donald Sharp
c2ad0a0d40
Merge pull request #9106 from opensourcerouting/clippy-elf-bsd-cond
lib/clippy: fix forgotten conditional
2021-09-02 07:31:10 -04:00
David Lamparter
9fb83ab17d *: fix for -Wstrict-prototypes
Just some "void" missing between empty braces.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-02 13:00:35 +02:00
David Lamparter
14040553bc lib: fix hook defs for -Wstrict-prototypes
Without this, the hook code creates functions with empty parameter lists
like "void hook_something()", which is not a proper C prototype.  It
needs to be "void hook_something(void)".  Add some macro shenanigans to
handle that.

... and make the plumbing functions "inline" too.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-02 13:00:35 +02:00
Russ White
ce4f3813f0
Merge pull request #9439 from ton31337/feature/set_ext_community_to_none
bgpd: Route-map `set extcommunity none`
2021-09-01 12:55:45 -04:00
Russ White
3c65c73ffa
Merge pull request #9502 from idryzhov/cmd-vtysh-cleanup
lib, vtysh: make node-processing code more generic
2021-08-30 15:58:06 -04:00
David Lamparter
3816ea6bb6 lib/clippy: fix forgotten conditional
This fixes some spurious warnings on *BSD, where `elffile_add_dynreloc`
isn't used since `elf_getdata_rawchunk` is not available.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-08-28 14:27:17 +02:00
Russ White
648c73647d
Merge pull request #9488 from pguibert6WIND/fix_nhrp_neigh_state
Fix nhrp neigh state
2021-08-27 19:00:45 -04:00
Donald Sharp
4cc6d2cef6 lib: Send c-bit when not using bfdd as daemon of choice
Commit: 4b983eef2c

Modified the zapi send receive of the c-bit to only
be under the HAVE_BFDD.  If you are using ptm-bfd
then the decoder function still expects this to be
sent down.  This commit puts this behavior back

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-08-27 09:32:27 -04:00
David Lamparter
8268be3d16
Merge pull request #9496 from idryzhov/vrf-cmd-init-unused-arg
lib: remove unused argument from vrf_cmd_init
2021-08-27 10:39:45 +02:00
David Lamparter
3be280bb8c lib: fix indentation trainwreck in command_py
Hooooo boooooyyyy... that `default` sure was in an "interesting" place.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-08-26 21:08:51 +02:00
David Lamparter
90c8406c20 lib: add ![...] syntax for easy "no" forms
This allows defining a CLI command like this:
  `[no] some setting ![VALUE]`
with VALUE being optional for the "no" form, but required for the
positive form.  It's just a `[...]` where the empty branch can only be
taken for commands starting with `no`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-08-26 21:03:44 +02:00
Igor Ryzhov
c1e7a5e45e lib: make node_parent more generic
Instead of adding a separate case clause for every node, just find the
node structure in the global list and get its parent node from there.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-26 19:43:23 +03:00
Christian Hopps
d448e2c5f9
Merge pull request #9331 from idryzhov/explicit-exit
*: explicitly print "exit" at the end of every node config
2021-08-26 11:57:33 -04:00
Igor Ryzhov
cfc369c43a lib: remove unused argument from vrf_cmd_init
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-26 12:01:22 +03:00
Philippe Guibert
80f6b5faeb lib, zebra: complete the ndm flags on zclient api
Insist on the fact that zclient neighbor state flags are
mapped over netlink state flags. List all the defines
currently known on kernel, and create a netlink API to
convert netlink values to zclient values. The function is
simplified as it is a 1-1 match.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-08-26 09:19:42 +02:00
Philippe Guibert
c4e1fd52a1 nhrp, zebra, lib: pass exact received neighbor state value to nhrp
As NHRP expects some notification of neighboring entries on GRE
interface, when a new interface notification is encountered, the
exact neighbor state flag is found. Previously, the flag passed
to the upper layer was forced to NDM_STATE which is REACHABLE,
as can be seen on below trace:

2021/08/25 10:58:39 NHRP: [QQ0NK-1H449] Netlink: new-neigh 102.1.1.1 dev gre1 lladdr 10.125.0.2 nud 0x2 cache used 1 type 5

When passing the real value, NHRP received an other value like STALE.

2021/08/25 11:28:44 NHRP: [QQ0NK-1H449] Netlink: new-neigh 102.1.1.1 dev gre1 lladdr 10.125.0.2 nud 0x4 cache used 0 type 5

This flag is important for NHRP, as it permits to monitor the link
layer of NHRP entries.

Fixes: d603c0774e ("nhrp, zebra, lib: enforce usage of zapi_neigh_ip structure")

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-08-26 09:19:42 +02:00
Donatas Abraitis
3e324ff419
Merge pull request #9466 from idryzhov/vrf-netns
lib, zebra: move vrf netns commands from lib to zebra
2021-08-26 07:46:19 +03: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
Igor Ryzhov
14b066917b lib: remove the dependency on bgpd code
The library code should not depend on a specific daemon's code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-24 17:42:37 +03:00
Igor Ryzhov
37cb0475e1 lib, zebra: move vrf netns commands from lib to zebra
"[no] netns NAME" commands are part of the lib, but they are actually
zebra-only:
- they are using vrf_netns_handler_create and its description clearly
  says that it "should be called from zebra only"
- vtysh sends these commands only to zebra
- only zebra outputs the netns related config
- zebra notifies other daemons about netns attachment

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-23 23:54:12 +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
Stephen Worley
95b4a691dd
Merge pull request #9337 from dlqs/lua2
lib: check return on str2sockunion
2021-08-23 08:20:33 -06:00
Mark Stapp
8fd5502b0c lib: avoid double-free in zmq wrapper callbacks
There were paths where the zmq wrapper lib could call user
callbacks that would free the internal context struct, but the
context was then used in the lib code. Use a boolean to avoid
freeing the context within an application callback.

Restore logic that frees the context within the 'cancel' api.

Signed-off-by: Mark Stapp <mjs.ietf@gmail.com>
2021-08-19 13:31:33 -04:00
Mark Stapp
cf2182c013 lib: clear caller's pointer when freeing context struct
The zeromq lib wrapper uses an internal context struct to help
interact with the libfrr event mechanism. When freeing that
context struct, ensure the caller's pointer is also cleared.

Signed-off-by: Mark Stapp <mjs.ietf@gmail.com>
2021-08-19 13:31:33 -04:00
Christian Hopps
11ca35875c pimd: change ranges to 1..max, type align with IETF YANG.
While defaults are good picks for "reasonable" guesses, min and max
range values really aren't. Operators and experimenters often like to
configure "unreasonable" values to stress test, tests boundary
conditions and explore innovations.

With that in mind, change all ranges to 1..max (of type).

While we're here add optional ignored values in the "no" CLI forms.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-08-18 22:08:33 -04:00
Donatas Abraitis
bb4dcdd13e bgpd: Add an ability to set extcommunity to none in route-maps
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-08-18 14:14:52 +03:00
Russ White
e709f411e9
Merge pull request #9365 from idryzhov/fix-plist-dup-check
lib: fix prefix-list duplication check
2021-08-17 09:55:34 -04:00
Russ White
55a3d3cef2
Merge pull request #9385 from idryzhov/bgpd-match-evpn-default-route-crash
bgpd: fix segfault when re-adding "match evpn default-route" rule
2021-08-17 09:54:25 -04:00
Igor Ryzhov
40d9855588
Merge pull request #9404 from neirbowj/notcares
Scan lib/resolver.c only when c-ares is installed
2021-08-17 11:28:22 +03:00
Igor Ryzhov
5838d3b452
Merge pull request #9265 from ton31337/fix/extcommunity_lb_route-map_persistent
bgpd: Extended community bandwidth fixes
2021-08-16 12:26:25 +03:00
John W. O'Brien
433d9af2a6 lib: Scan lib/resolver.c only when c-ares is installed
Scan lib/resolver.c only when c-ares is installed

Signed-off-by: John W. O'Brien <john@saltant.com>
2021-08-15 12:54:37 -04:00
Quentin Young
0c0830c599 lib: add frrstr_hex to hexdump buffers
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2021-08-12 16:25:57 -04:00
Igor Ryzhov
30475121ad bgpd: fix segfault when re-adding "match evpn default-route" rule
When using "match evpn default-route" rule, match_arg is NULL and strcmp
is not happy with that. There's already a special function named rulecmp
that handles such situations.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-12 19:08:46 +03:00
Igor Ryzhov
667dcc277c lib: fix prefix-list duplication check
Currently, when we check the new prefix-list entry for duplication, we
only take filled in fields into account and ignore optional fields.
For example, if we already have `ip prefix-list A 0.0.0.0/0 le 32` and
we try to add `ip prefix-list A 0.0.0.0/0`, it is treated as duplicate.
We should always compare all prefix-list fields when doing the check.

Fixes #9355.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-10 22:31:42 +03:00
Donald Lee
0db2bfc5ac lib: Remove extraneous braces
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-08-10 15:37:30 +08:00
Donald Lee
2ed598ba6b lib: Enable consecutive frrscript_call
Previous:
 - frrscript_load: push Lua function onto stack
 - frrscript_call: calls Lua function

Now:
 - frrscript_load: checks Lua function
 - frrscript_call: pushes and calls Lua function (first clear the stack)

So now we just need one frrscript_load for consecutive frrscript_call.
frrscript_call does not recompile or reload the script file, it just
keys it from the global Lua table (where it should already be).

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-08-10 07:35:32 +08:00
Mark Stapp
c123e9df54
Merge pull request #9299 from donaldsharp/zebra_should_continue
Zebra should continue
2021-08-09 13:16:10 -04:00
Quentin Young
edc6ea2ec5
Merge pull request #9273 from dlqs/luadofilefix
lib: Fix dead code from lua_dofile
2021-08-09 09:55:35 -04:00
Donald Lee
a852e5a62d lib: check return on str2sockunion
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-08-09 17:19:28 +08:00
Donatas Abraitis
e885e97d87
Merge pull request #9325 from anlancs/fix-lib-warning
lib: Fix coverity warning of return value
2021-08-09 10:34:38 +03:00
anlan_cs
4b0d126794 lib: Fix coverity warning of return value
Suppress coverity warning on unchecked str2sockunion's return value.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2021-08-07 21:57:55 -04:00
Donald Sharp
f932b4eef3
Merge pull request #9313 from idryzhov/bgp-zebra-opaque
BGP opaque data improvements
2021-08-07 15:12:02 -04:00
Igor Ryzhov
b5bb70e377 bgpd: add protection against too large opaque data structure
BGP opaque data shouldn't be larger than zebra's buffer.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-06 17:09:46 +03:00
Igor Ryzhov
a9bf0ff268 bgpd: use longer aspath string in opaque data
32 bytes are not enough to carry relatively long AS paths so let's make
the buffer larger.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-08-06 17:06:39 +03:00
Donatas Abraitis
639caccfeb bgpd: Fix misleading comments for some parts
Mostly just retrun => return and misleading comments at all.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-08-05 16:29:52 +03:00
Donald Sharp
b7457b40cd lib: Blackhole nexthops cannot be used as part of label generation
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-08-04 13:34:03 -04:00
Donald Sharp
1ae0e1b315 lib: Convert assert to error and record it instead of aborting
When we get a bad value for the opaque data length, instead
of stopping the program, discard the data and move on.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-08-04 11:13:26 -04:00
Donald Lee
868b41d97b lib: Fix dead code from lua_dofile
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-08-03 13:36:24 -04:00
Russ White
1358f9d10a
Merge pull request #9259 from opensourcerouting/moar-json
*: can't get enough JSON
2021-08-03 09:13:12 -04:00
Donatas Abraitis
71bdae66b2 bgpd: Keep extcommunity bandwidth commands persistent in route-maps
~/frr# vtysh -c 'conf' -c 'route-map testas permit 10' -c 'set extcommunity bandwidth 321'
~/frr# vtysh -c 'show route-map testas' | grep 321
    extcommunity bandwidth 321 non-transitive
~/frr# vtysh -c 'sh run' | grep 321
~/frr#

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-08-03 14:38:53 +03:00
Renato Westphal
488599bfa2
Merge pull request #9232 from idryzhov/interface-node-cleanup
*: cleanup interface node installation
2021-08-02 21:13:29 -03:00
Renato Westphal
58e2857d23 lib: add "json" option to "show ip[v6] prefix-list"
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-08-02 17:19:45 -03:00
Renato Westphal
856ed18ae9 lib: add "json" option to "show route-map"
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-08-02 16:05:44 -03:00
Renato Westphal
068ab9018b lib: add "json" option to "show ip[v6] access-list"
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-08-02 16:05:44 -03:00
Igor Ryzhov
72928fa1aa
Merge pull request #9238 from leonshaw/fix/netns-delete
lib, zebra: Preserve user-configured VRF on netns deletion
2021-08-02 18:12:19 +03:00
Quentin Young
41d3d77496
Merge pull request #8982 from dlqs/lua-func-stack 2021-08-02 13:51:35 +00:00
Xiao Liang
6910315f6f lib, zebra: Preserve user-configured VRF on netns deletion
Don't clear VRF's user-configured flag when netns is deleted.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
2021-07-30 14:53:45 +08:00
Igor Ryzhov
9da01b0b7b *: cleanup interface node installation
The only difference in daemons' interface node definition is the config
write function. No need to define the node in every daemon, just pass
the callback as an argument to a library function and define the node
there.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-07-29 21:35:25 +03:00
Donald Lee
b5e790ee4d lib: Add parens around macro args
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-29 05:52:22 +08:00
Donald Lee
9e3a277b04 lib: Fix condition for snprintf
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-29 05:52:22 +08:00
Donald Sharp
fb1df4cd13 lib: prevent crash in make check in some situations
When running `make check` against a build that zeromq enabled
the test_zmq unit test was crashing.  The commit:

e08165def1

Introduced this crash.  Removing the part of the commit
that was causing the crash in the test.  This is mainly
to get `make check` working again for those people using
zeromq in their builds.

Fixes: #9176
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-28 14:41:46 -04:00
Jafar Al-Gharaibeh
213d980ff9
Merge pull request #9007 from donaldsharp/pbr_stuff
add ability to match on proto to pbr
2021-07-27 15:09:29 -05:00
Donald Lee
84c92002d2 lib: formatting
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-26 23:48:23 +08:00
Donald Lee
78f1ac2574 lib: Add new MTYPE for script results
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-26 23:27:56 +08:00
Donald Lee
6ffeb9f79f bgpd: Comment for included
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-26 22:47:50 +08:00
Donatas Abraitis
66aa87d03e
Merge pull request #8637 from opensourcerouting/pim-vrf-acl-fixes
Pim vrf acl fixes
2021-07-26 12:20:54 +03:00
Donald Lee
36cf58c785 lib: Rename decode_int
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 03:41:40 +08:00
Donald Lee
4093300ee8 lib: zlog err in error cases during lua loading
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 03:40:57 +08:00
Donald Lee
6d28552d2d lib: comment typo
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 03:35:09 +08:00
Donald Lee
8be973f5c2 lib: Add function name to script command
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 00:45:22 +08:00
Donald Lee
1da9c4bdbb lib: Use negative indices and add comments
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 00:45:22 +08:00
Donald Lee
1763ed2655 lib: Cap script_name length
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-24 00:45:22 +08:00
Donald Lee
67b64027b2 lib: parens around macro args
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-23 20:48:16 +08:00
Donald Lee
08bf2b41b8 lib: formatting
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-23 20:43:24 +08:00
Donald Lee
70d995abd4 lib: Comment on how macro works
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-23 20:43:24 +08:00