Commit Graph

4978 Commits

Author SHA1 Message Date
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
Donald Sharp
0775caa958
Merge pull request #9082 from ton31337/feature/bgp_alias_route-map_match
bgpd: `match alias` for route-map
2021-07-22 08:30:15 -04:00
Donald Sharp
918af5a40b
Merge pull request #9102 from opensourcerouting/autoconf-fix-gcov
build: fix LDFLAGS confusion & gcov
2021-07-21 19:26:15 -04:00
David Lamparter
63116a7008 build: fix AM_LDFLAGS usage (and gcov)
like the other automake variables, setting `xyz_LDFLAGS` causes
`AM_LDFLAGS` to be ignored for `xyz`.  For some reason I had in my mind
that automake doesn't do this for LDFLAGS, but... it does.  (Which is
consistent with `_CFLAGS` and co.)

So, all the libraries and modules have been ignoring `AM_LDFLAGS` (which
includes `SAN_FLAGS` too).  Set up new `LIB_LDFLAGS` and
`MODULE_LDFLAGS` to handle all of this correctly (and move these bits to
a central location.)

Fixes: #9034
Fixes: 0c4285d77e ("build: properly split CFLAGS from AC_CFLAGS")
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-07-21 17:10:08 +02:00
Igor Ryzhov
d9331fc67c lib, zebra: fix exit from link-params node
When exiting from link-params node, we must not decrement xpath_index
because it is not incremented when entering the node.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-07-21 17:23:45 +03:00
Donatas Abraitis
2690f18cc8 bgpd: Add route-map match alias command
Will be handy to filter BGP prefixes by using BGP community alias
instead of numerical community values.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-21 09:26:14 +03:00
Donald Lee
2ce634e2ad lib: formatting
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-19 23:28:01 +08:00
Mark Stapp
0a0875df5b lib: remove quagga from route_types.txt
Remove the q-word.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-07-19 08:43:48 -04:00
Donald Lee
596b44af8a lib: Remove warning about script not found
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
7472871eef lib: Comment functions
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
2b67227e6e lib: Add int encoder/decoder
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
8878080b1b lib: Remove ../ include
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
64d457d7ac lib: Rename frrscript_unload to delete
frrscript_load now loads a function instead of a file, so frrscript_unload
should be renamed since it does not unload a function.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
b664092990 lib: standardize zlog error messages
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
ad6e9b854d test: Use frrscript_unload
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
fae19fa56d lib: frrscript unload deallocates Lua function
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
8a79921ca3 lib: format macro slashes
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
06947ddeac lib: Add frrscript_get_result
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
24ff8520af lib: frrscript_call check name before decode
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
cb5de23140 lib: update frrscript unload
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
a71096fb0a lib: Update Script command example to call function
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
40d038d2a1 lib: Change frrscript_call to call function instead
There is some rather heavy error checking logic in frrscript_call. Normally
I'd put this in the _frrscript_call function, but the error checking needs
to happen before the encoders/decoders in the macro are called.

The error checking looks messy but its really just nested ternary
expressions insite a larger statement expression.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
f0cddf950f lib: create new frrscript_new
frrscript_new now creates a new frrscript
frrscript_load now loads a function (by allocating a new lua stack)

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Donald Lee
105ba9af8f lib: Change frrscript to hold many Lua states
Instead of 1 frrscript : 1 lua state, it is changed to 1 : N.
The states are hashed with their function names.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-07-18 06:32:03 +08:00
Russ White
000df71ccd
Merge pull request #8767 from opensourcerouting/ospfd-gr
ospfd: introduce support for Graceful Restart (restarting mode)
2021-07-13 06:39:53 -04:00
Rafael Zalamena
1fe59b44fc lib,ospfd,ospf6d: remove duplicated function
Move `is_default_prefix` variations to `lib/prefix.h` and make the code
use the library version instead of implementing it again.

NOTE
----

The function was split into per family versions to cover all types.
Using `union prefixconstptr` is not possible due to static analyzer
warnings which cause CI to fail.

The specific cases that would cause this failure were:
 - Caller used `struct prefix_ipv4` and called the generic function.
 - `is_default_prefix` with signature using `const struct prefix *` or
   `union prefixconstptr`.

The compiler would complain about reading bytes outside of the memory
bounds even though it did not take into account the `prefix->family`
part.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-07-09 07:55:25 -03:00
Donald Sharp
b94683f0db lib, zebra: add ip_proto to the filter data structure
Add ip_proto to the filter data structure and also account
for it in the hash when stored.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-08 11:12:47 -04:00
Donald Sharp
8096bd72aa zebra: Add ability to encode/decode netlink FRA_IP_PROTO for rule changes
Encode/Decode the FRA_IP_PROTO but do nothing with it at the moment.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-08 11:12:47 -04:00
Martin Winter
3f8fcd2caa
Merge pull request #8997 from donaldsharp/opaque_length
lib: Allow ZAPI_MESSAGE_OPAQUE_LENGTH length of data
2021-07-08 03:35:42 +02:00
Donald Sharp
3b1849be32 lib: Allow ZAPI_MESSAGE_OPAQUE_LENGTH length of data
We are sending up to ZAPI_MESSAGE_OPAQUE_LENGTH but checking
for one less.  We know the data will fit in it to that size.
Also we have asserts on the write to ensure we don't go over
it

Fixes: #8995
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-07 16:01:32 -04:00
David Lamparter
f49e0be728 lib: fix coverity unused result warning
There's nothing that can be done here with an error.  Try to make
Coverity understand that this is intentional.

(I don't know if the `(void)` will actually fix the coverity warning,
but I don't really have a better way to figure it out beyond just
getting this merged and waiting for a result...)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-07-07 14:58:14 +02:00
Quentin Young
e15106149f
Merge pull request #8508 from opensourcerouting/systemd-no-lib 2021-07-06 14:54:25 +00:00
Donald Sharp
acb4c44ef8
Merge pull request #8942 from ton31337/fix/cleanups_2
Another round of cleanup
2021-07-06 09:47:41 -04:00
David Lamparter
19cf3fc5ab
lib: add command to test prefix-list match
While we do have `show ip prefix-list NAME A.B.C.D/M`, that doesn't
actually run the prefix list matching code.  While the result would
hopefully be the same anyway, let's have a way to call the actual prefix
list match code and get a result.

(As an aside, this might be useful for scripting to do a quick "is this
prefix in that prefix list" check.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-07-06 01:44:35 +02:00
David Lamparter
2b6b16fc21
lib, pimd: add address match mode to prefix lists
... the PIM code is kinda misusing prefix lists to match addresses.
Considering the weird semantics of access-lists, I can't fault it.
However, prefix lists aren't great at matching addresses by default,
since they try to match the prefix length too.  So, here's an "address
match mode" for prefix lists to get that to work more reasonably.

Fixes: #8492
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-07-06 01:44:34 +02:00
Renato Westphal
1051417011 ospfd: introduce support for Graceful Restart (restarting mode)
RFC 3623 specifies the Graceful Restart enhancement to the OSPF
routing protocol. This PR implements support for the restarting mode,
whereas the helper mode was implemented by #6811.

This work is based on #6782, which implemented the pre-restart part
and settled the foundations for the post-restart part (behavioral
changes, GR exit conditions, and on-exit actions).

Here's a quick summary of how the GR restarting mode works:
* GR can be enabled on a per-instance basis using the `graceful-restart
  [grace-period (1-1800)]` command;
* To perform a graceful shutdown, the `graceful-restart prepare ospf`
  EXEC-level command needs to be issued before restarting the ospfd
  daemon (there's no specific requirement on how the daemon should
  be restarted);
* `graceful-restart prepare ospf` will initiate the graceful restart
  for all GR-enabled instances by taking the following actions:
  o Flooding Grace-LSAs over all interfaces
  o Freezing the OSPF routes in the RIB
  o Saving the end of the grace period in non-volatile memory (a JSON
    file stored in `$frr_statedir`)
* Once ospfd is started again, it will follow the procedures
  described in RFC 3623 until it detects it's time to exit the graceful
  restart (either successfully or unsuccessfully).

Testing done:
* New topotest featuring a multi-area OSPF topology (including stub
  and NSSA areas);
* Successful interop tests against IOS-XR routers acting as helpers.

Co-authored-by: GalaxyGorilla <sascha@netdef.org>
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-07-05 11:43:02 -03:00
Quentin Young
71bae95e4a
Merge pull request #8888 from dlqs/lua-call 2021-07-05 04:13:20 +00:00
Donatas Abraitis
8643c2e5f7 *: Replace 4/16 integers to IPV4_MAX_BYTELEN/IPV6_MAX_BYTELEN
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-01 23:54:39 +03:00
Donatas Abraitis
12256b84a5 *: Convert numeric 32 into IPV4_MAX_BITLEN for prefixlen
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-01 23:50:39 +03:00
Donatas Abraitis
13ccce6e7e *: Convert numeric 128 into IPV6_MAX_BITLEN for prefixlen
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-01 17:53:21 +03:00
Donatas Abraitis
936fbaef47 *: Replace IPV4_MAX_PREFIXLEN to IPV4_MAX_BITLEN
Just drop IPV4_MAX_PREFIXLEN at all, no need keeping both.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-01 17:44:09 +03:00
Donatas Abraitis
f4d81e5507 *: Replace IPV6_MAX_PREFIXLEN to IPV6_MAX_BITLEN
Just drop IPV6_MAX_PREFIXLEN at all, no need keeping both.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-07-01 17:41:09 +03:00
Renato Westphal
8b0ab1f8a0
Merge pull request #8780 from idryzhov/fix-zebra-coverity
zebra: fix a couple of coverity warnings
2021-06-30 16:08:35 -03:00
Donatas Abraitis
e702605d80 *: Do not check for XMALLOC/XCALLOC against NULLs
We don't check this pattern anywhere in the code basically, so let's
unify the code.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-29 22:27:50 +03:00
Donatas Abraitis
0e2d70760d lib: Avoid using assignments within checks
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-29 22:27:49 +03:00
David Lamparter
247898d5d2 lib, watchfrr: remove HAVE_SYSTEMD, use own code
This replaces the external libsystemd dependency with... pretty much the
same amount of built-in code.  But with one fewer dependency and build
switch needed.

Also check `JOURNAL_STREAM` for future logging integration.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-29 17:57:04 +02:00
Olivier Dugeon
55a02e1ed4
Merge pull request #8824 from volta-networks/fix_check_for_link_param_change
isisd, ospfd: update interface_link_params callback to check for change
2021-06-29 16:53:54 +02:00
Igor Ryzhov
b08dcc3f3f *: unify prefix copying
There are a few places in the code where we use PREFIX_COPY(_IPV4/IPV6)
macro to copy a prefix. Let's always use prefix_copy function for this.

This should fix CID 1482142 and 1504610.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-29 16:11:47 +03:00
Igor Ryzhov
ba88ced84c
Merge pull request #8835 from ranjanyash54/clear_process
ospf6d: "clear ipv6 ospf6 process" command
2021-06-29 11:54:39 +03:00
Donatas Abraitis
7702d0b720
Merge pull request #8911 from donaldsharp/command_node
lib: Add some hash name differentiation for Command Hash's
2021-06-29 11:47:16 +03:00
Karen Schoener
0b4124c18c isisd, ospfd: update interface_link_params callback to check for change
Adding defensive code to the interface_link_params zebra callback
to check if the link params changed before taking action.

Signed-off-by: Karen Schoener <karen@voltanet.io>
2021-06-28 10:32:52 -04:00
Yash Ranjan
f71ed6df3e ospf6d: "clear ipv6 ospf6 process" command
Adding the "clear ipv6 ospf6 command" . It resets
the ospfv3 datastructures and clears the database
as well as route tables. It resets the neighborship
by restarting the interface state machine.
If the user wants to change the router-id, this
command updates the router-id to the latest static
router-id and starts the neighbor formation with
the new router-id.

Signed-off-by: Yash Ranjan <ranjany@vmware.com>
2021-06-27 20:56:10 -07:00
Donald Lee
19eee398d4 lib: add comments for functions
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-25 17:29:15 +08:00
Donald Sharp
c81d78cf1c lib: Add some hash name differentiation for Command Hash's
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-06-24 10:51:34 -04:00
David Lamparter
13f9aea383 build: add -Werror to xrelfo log format warnings
Adding a `\n' should now produce a warning.  Controlled by `-Werror` so
if you're doing a dev build and it's warning about some `prefix2str`
that should be converted to `%pFX`, you can turn off `-Werror` to fix it
later like with all other warnings.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-24 16:42:59 +02:00
David Lamparter
6418e2d342 lib: try CLOCK_THREAD_CPUTIME_ID
This might be faster if at some point in the future the Linux vDSO
supports CLOCK_THREAD_CPUTIME_ID without making a syscall.  (Same
applies for other OSes.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-24 16:42:59 +02: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
Donald Sharp
2afd15f5c6
Merge pull request #8656 from opensourcerouting/xref-5424-prep-2
lib: preparations for RFC5424 syslog support
2021-06-23 06:08:41 -04:00
Patrick Ruddy
fa855f8fa3
Merge pull request #6695 from adharkar/frr-master-gateway_ip
EVPN route type-5 gateway IP overlay Index
2021-06-23 09:23:54 +01:00
Donald Lee
62510c0948 lib: use in6addr comparator in test
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-23 00:58:04 +08:00
Donald Lee
8192b47173 lib: Pop tables off Lua stack when decoding
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-23 00:58:04 +08:00
Donald Lee
81fde499e5 lib: Use noop decoder for bgp_script values
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 05:08:25 +08:00
Donald Lee
7e058da5bc lib: Add lua noop decoder
Use this noop decoder for const values (since we can't mutate a const
value passed into frrscript_call anyways) or values we don't want to
write a decoder for.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 05:03:12 +08:00
Donald Lee
b7da61c1d1 bgpd: Update bgp_script encoders and decoders
This is an example of creating encoders and decoders for user defined
structs and registering them in the ENCODE_ARGS DECODE_ARGS macro
in frrscript.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 05:03:07 +08:00
Donald Lee
bdc1085d7b lib: Update script SCRIPT command
Can now test out script by modifying a prefix

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 05:02:12 +08:00
Donald Lee
3a3cfe4762 lib: Add decoder functions
Split existing lua_to* functions into two functions:
 - lua_decode_*: unmarshall Lua values into an existing C data structure
 - lua_to*: allocate *and* unmarshall Lua values into C data structure
This allows us to mutate C data structures passed into frrscript_call,
without allocation

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 05:02:03 +08:00
Donald Lee
c2642aab24 lib: Add basic encoders
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 04:55:19 +08:00
Donald Lee
43a5106d42 lib: make frrscript_call encode args based on type
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 04:51:22 +08:00
Donald Lee
249cd5daa7 lib: Add MAP_LIST macro
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-06-22 04:46:16 +08:00
Igor Ryzhov
f5eef2d5a8 lib: remove vrf-interface config when removing the VRF
If we have the following configuration:
```
vrf red
 smth
 exit-vrf
!
interface red vrf red
 smth
```
And we delete the VRF using "no vrf red" command, we end up with:
```
interface red
 smth
```
Interface config is preserved but moved to the default VRF.

This is not an expected behavior. We should remove the interface config
when the VRF is deleted.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-21 18:04:46 +03:00
Renato Westphal
2f0884023a
Merge pull request #8749 from pjdruddy/bitfield_mtype
lib: add an MTYPE for bitfields
2021-06-19 12:16:48 -03:00
Renato Westphal
1e810976e2
Merge pull request #8864 from idryzhov/fix-vtysh-vrf-change
lib: fix interface configuration after vrf change
2021-06-19 12:15:40 -03:00
David Lamparter
ca4849b374
Merge pull request #8876 from idryzhov/remove-pure
lib: remove pure attribute from functions that modify memory
2021-06-19 14:32:43 +02:00
David Lamparter
ca846ff82c lib: fix printf format on NetBSD
*sigh*.  It doesn't accept `%m` otherwise.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
c6610ea98f lib: make a few log symbols accessible
Might've made a few things too many `static` there.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
5c58f5d336 lib: save instance number in zlog
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
78598fd019 lib: cache PID & TID in zlog code
glibc removed its pid cache a while back, and grabbing this from TLS is
faster than repeatedly calling the kernel...

Also use `intmax_t` which is more appropriate for both PID & TID.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
8b94cb4388 lib: include \n in zlog_msg_text()
Since the file targets append one anyway, save them some extra work.
syslog can use `%.*s` since it's "forced" printf by API anyway.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
243ff228a9 lib: add RFC3164 logging timestamps
This is old-style syslog, used among other things for /dev/log.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
f6caaa6524 lib: use fbuf for zlog_msg_ts()
Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 21:05:21 +02:00
David Lamparter
e3daa82c18 lib: record output argument positions in zlog
printfrr() recently acquired the capability to record start/end of
formatting outputs.  Make use of this in the zlog code so logging
targets have access to this information.

(This also records how long the `[XXXXX-XXXXX][EC 9999999]` prefix was
so log targets can choose to skip over it.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 20:56:53 +02:00
David Lamparter
ba9256d2d0 lib: add hook for show logging CLI
... so additional targets can print their state.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 20:56:53 +02:00
David Lamparter
9c2aa91921 lib: de-conflict log-filter CLI command
`log-filter WORD` was giving me a serious headache since it also matches
`log WORD` due to the way the CLI token handling works.  This meant that
a mistyped `log something` command would silently be interpreted as a
filter string, causing me serious headscratching and WTFs until I
figured what was going on.

Remove this UX pitfall so noone else falls into it.  (Since the command
was never saved to config, renaming it shouldn't cause trouble.)

[Also I apparently forgot to update the docs when I transferred this
over to the new zlog bits...]

TODO for a rainy day:  since we collect all the CLI commands anyway, we
should warn somewhere for "2nd level ambiguous" commands like this.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-06-18 20:56:53 +02:00
Igor Ryzhov
4f08c715db lib: remove pure attribute from functions that modify memory
Almost all functions currently marked with pure attribute acquire a
route_node lock. By marking them pure we allow compiler to optimize the
code and not call them when it already knows the return value. This is
completely incorrect.

Only two of eleven functions can be marked as pure. And they still won't
be optimized because they are never called from the same function twice.
Let's remove the ext_pure macro completely to reduce the chance of
repeating this mistake in the future.

Fixes #8866, #8809, #8595, #6992.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-18 19:54:40 +03:00
Donald Sharp
d7193080af
Merge pull request #8478 from mjstapp/fix_nb_grpc_shutdown
lib: stop grpc pthread at shutdown
2021-06-18 08:52:44 -04:00
Pat Ruddy
0e2deb5878 lib: add an MTYPE for bitfields
it is handy to be able to see allocated bitfields in the show
memory output.

Signed-off-by: Pat Ruddy <pat@voltanet.io>
2021-06-18 09:34:43 +01: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
Donatas Abraitis
aa6fe908f3 lib: Do not double-assign freed pointer to NULL
It's already done by XFREE.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-17 10:14:38 +03:00
Mark Stapp
de800c10af lib: cleanup and stop grpc pthread
At shutdown, try to stop the grpc module and its
dedicated pthread cleanly.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-06-15 11:08:19 -04:00
Igor Ryzhov
f9fa6ee74c
Merge pull request #8838 from LabNConsulting/chopps/fix-nb-edit-cli
lib: do not attempt to create default nodes from NULL tree node
2021-06-15 12:18:29 +03:00
Christian Hopps
4da08e016b
lib: do not attempt to create default nodes from NULL tree node
Perform same NULL check for dependent node creation code too.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-12 09:10:18 +00:00
Stephen Worley
ea0d70b1c4 lib: terminate default vrf last
Always terminate default VRF last during FRR shutdown.

On shutdown we were simply looping over the RB tree and terminating
VRFs from the ROOT. This is not guaranteed to be the default last ever.

Instead switch to RB_SAFE and skip the default VRF till the very end.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2021-06-11 11:48:23 -04:00
Donald Sharp
6dbaa012be
Merge pull request #8807 from mjstapp/fix_srv6_delete
lib,zebra: srv6 cleanup
2021-06-09 09:07:53 -04:00
Olivier Dugeon
3898a4522f
Merge pull request #8798 from opensourcerouting/ospfd-fixes
ospfd: assorted fixes
2021-06-09 09:06:42 +02:00
Quentin Young
fdb7f5d54f
Merge pull request #8593 from idryzhov/cmd-ambiguous
vtysh: fix searching commands in parent nodes
2021-06-08 15:41:45 +00:00
Renato Westphal
461d106dae lib, ospfd, ospf6d: fix logging of pointer addresses
The %p printf format specifier does already print the pointer address
with a leading "0x" prefix (indicating a hexadecimal number). There's
no need to add that prefix manually.

While here, replace explicit function names in log messages by
__func__.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-06-08 11:50:44 -03:00
Quentin Young
7b450535c9
Merge pull request #8713 from LabNConsulting/chopps/grpc-unit-test 2021-06-08 14:00:10 +00:00
Ameya Dharkar
d0a4ee6010 bgpd: Add "set evpn gateway-ip" clause for route-map
- Add following set clause for route-maps
  "set evpn gateway-ip <ipv4|ipv6 >A.B.C.D|X:X::X:X"
- When this route-map is applied as outboubd policy in BGP, it will set the
  gateway-ip in BGP attribute For EVPN type-5 routes.

Example configuration:

route-map RMAP-EVPN_GWIP permit 5
 set evpn gateway-ip ipv4 50.0.2.12
 set evpn gateway-ip ipv6 50:0:2::12

router bgp 101
 bgp router-id 10.100.0.1
 neighbor 10.0.1.2 remote-as 102
 !
 address-family l2vpn evpn
  neighbor 10.0.1.2 activate
  neighbor 10.0.1.2 route-map RMAP-EVPN_GWIP out
  advertise-all-vni
 exit-address-family

Signed-off-by: Ameya Dharkar <adharkar@vmware.com>
2021-06-07 17:58:22 -07:00
Rafael Zalamena
77af3a34ba lib: fix address sanitizer crash on find
Fix the following address sanitizer crash when running the command `find`:

  ERROR: AddressSanitizer: dynamic-stack-buffer-overflow
  WRITE of size 1 at 0x7fff4840fc1d thread T0
      0  in print_cmd ../lib/command.c:1541
      1  in cmd_find_cmds ../lib/command.c:2364
      2  in find ../vtysh/vtysh.c:3732
      3  in cmd_execute_command_real ../lib/command.c:995
      4  in cmd_execute_command ../lib/command.c:1055
      5  in cmd_execute ../lib/command.c:1219
      6  in vtysh_execute_func ../vtysh/vtysh.c:486
      7  in vtysh_execute ../vtysh/vtysh.c:671
      8  in main ../vtysh/vtysh_main.c:721
      9  in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
      10 in _start (/usr/bin/vtysh+0x21f64d)

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-06-07 11:14:25 -03:00
Mark Stapp
4b220ad052 lib: add dtor for srv6 locator chunk list
Add a delete function for the chunk list in an srv6
locator.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-06-07 09:52:33 -04:00
Rafael Zalamena
455d14ae31
Merge pull request #8778 from idryzhov/fix-zebra-vrf
zebra: fix config after exit from vrf
2021-06-07 08:59:10 -03:00