Commit Graph

4978 Commits

Author SHA1 Message Date
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
Rafael Zalamena
a36dd4c930
Merge pull request #8758 from idryzhov/bfd-fixes
BFD fixes
2021-06-07 08:34:06 -03:00
Rafael Zalamena
4548fb256c
Merge pull request #8781 from idryzhov/fix-list-find
lib: fix output of "list" and "find" commands
2021-06-07 08:32:31 -03:00
Christian Hopps
deca28a33b tests: add grpc unit test
Test uses staticd which required some C++ header protections.
Additionally, the test also runs in the ubuntu20 docker container as
grpc is supported there by the packaging system.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-06 18:03:17 +00:00
Quentin Young
6198bc98be
Merge pull request #8706 from LabNConsulting/chopps/fix-grpc-threading 2021-06-04 20:31:34 +00:00
Mark Stapp
e4768d32b8
Merge pull request #5865 from slankdev/slankdev-zebra-srv6-manager
zebra: srv6 manager
2021-06-04 13:41:55 -04:00
Igor Ryzhov
58929633fb zebra: fix config after exit from vrf
When the VRF node is exited using "exit" or "quit", there's still a VRF
pointer stored in the vty context. If you try to configure some router
related command, it will be applied to the previous VRF instead of the
default VRF. For example:

```
(config)# vrf test
(config-vrf)# ip router-id 1.1.1.1
(config-vrf)# do show run
...
!
vrf test
 ip router-id 1.1.1.1
 exit-vrf
!
...
(config-vrf)# exit
(config)# ip router-id 2.2.2.2
(config)# do show run
...
!
vrf test
 ip router-id 2.2.2.2
 exit-vrf
!
...
```

`vrf-exit` works correctly, because it stores a pointer to the default
VRF into the vty context (but weirdly keeping the VRF_NODE instead of
changing it to CONFIG_NODE).

Instead of relying on the behavior of exit function, always use the
default VRF when in CONFIG_NODE.

Another problem is missing `VTY_CHECK_CONTEXT`. If someone deletes the
VRF in which node the user enters the command, then zebra applies the
command to the default VRF instead of throwing an error.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-04 19:02:32 +03:00
Igor Ryzhov
5b96d81c86 lib: fix output of "list" and "find" commands
Currently, we output the command exactly how it is defined in DEFUN.
We shouldn't output varnames and excessive whitespace.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-03 02:03:20 +03:00
Igor Ryzhov
c22789620d lib, vtysh: reduce code duplication
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-03 02:03:15 +03:00
Donald Sharp
d64162ce84
Merge pull request #8210 from LabNConsulting/chopps/always-batch
northbound: KISS always batch yang config, it's faster.
2021-06-02 18:13:42 -04:00
Hiroki Shirokura
c60c1ade86 *: delete ZEBRA_FLAG_SEG6*_ROUTE and add ZAPI_NEXTHOP_FLAG_SEG6*
https://github.com/FRRouting/frr/pull/5865#discussion_r597670225

As this comment says. ZEBRA_FLAG_XXX should not have been used.
To communicate SRv6 Route Information. A simple Nexthop Flag would
have been sufficient for SRv6 information. And I fixed the whole
thing that way.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
eab0f8f0a2 lib,sharpd,zebra: update nexthop object with nh_srv6
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
0548592691 *: eliminate redundant info from srv6 locator zapi
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
7b778857f8 zebra: drop un-needed info in locator-zapi
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
a9510347aa zebra: delete unneeded zebra_srv6_manager_connect
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
4c6a567d72 lib: erase wrong comments by copy-paste
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
8dcb27e6d9 lib: eliminate odd line-break
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
fbaa42f744 lib: integrate srv6-nexthop-cmp functions
I agree with the PR review from mstap and merged
the following two functions into one.

- zapi_nexthop_seg6_cmp
- zapi_nexthop_seg6local_cmp

[note]
If both of them have more complex extensions in the future,
I think it will be less confusing to remove the integration
of these functions and make them as separate functions as
before.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
1bda3e627d *: use one line init instead of memset and format it
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
326591dcdb lib: fix json style to camel-case instead of underscores
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
ac6a9479af zebra: add zapi_srv6_locator_chunk_{en,de}code
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
618538f8ab lib: add usual func to install SRv6 localsid (step4)
This commit add usuful function to configure SRv6 localsid
which is represented with seg6local lwt route.
Now, it can support only NEXTHOP_TYPE_IFINDEX route.
Actual configurationof SRv6 localsid is performed with
ZEBRA_ROUTE_ADD. So this is just a wrapper function
for route-install.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
bfaab44d1e *: new cli-nodes for BGP SRv6 VPNv4 (step4)
This commit add just CLI-nodes for MP-BGP VPN configuration
with SRv6 backend rather than MPLS. Actual configuration cli
will be implemented after this commit.

Example Configuration follow.
This cli design is based on Cisco IOS-XR but actual cli
tree design is defferent between FRR and Cisco.
It's just based on cisco.

ref:
https://www.cisco.com/c/en/us/td/docs/routers/asr9000/software/asr9k-r6-6/segment-routing/configuration/guide/b-segment-routing-cg-asr9000-66x/b-segment-routing-cg-asr9000-66x_chapter_011.html#concept_hwj_trf_dlb

router bgp 1
 bgp router-id 1.1.1.1
 !
 segment-routing srv6 ! new cli-node
  locator LOC1 ! this cli will be added after this commit.
 !
!

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
4df9d8592b *: fix code format accourding to checkpatch
Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:48 -04:00
Hiroki Shirokura
2aa01034f3 lib: add new nexthop's attributes seg6 (step3)
This commit add new nexthop's addional object for SRv6
routing about seg6 route. Before this commit,
we can add MPLS info as additional object on nexthop.
This commit make it add more support about seg6 routes.

seg6 routes are ones of the LWT routing mechanism,
so configuration of seg6local routes is performed by
ZEBRA_ROUTE_SEND, it's same as MPLS configuration.

Real configuration implementation isn't implemented at
this commit. later commit add that. This commit add
only nexthop additional object and some misc functions.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:47 -04:00
Hiroki Shirokura
f2867068e6 lib: add new structures for srv6-locator (step2)
This commit is a part of #5853 works that add new structures for
SRv6-locator. This structure will be used by zebra and another
routing daemon and its ZAPI messaging to manage SRv6-locator.
Encoder/decoder for ZAPI stream is also added by this commit.

Real configuration mechanism isn't implemented at this commit.
later commit add real configure implementation. This commit add only
SRv6-locator's structures and misc functions.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:47 -04:00
Hiroki Shirokura
6c0a7c0941 *: new cli-nodes for SRv6 manager (step2)
This commit is a part of #5853 that add new cmd-node for SRv6 configuration.
This commit just add cmd-node and moving node cli only, acutual SRv6 config
command isn't added. (that is added later commit. of this branch)

new cli nodes:
* SRv6
* SRv6-locators
* SRv6-locator

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:47 -04:00
Hiroki Shirokura
cb7775a974 lib: add new nexthop's attributes seg6local (step1)
This commit is a part of #5853 works that add new nexthop's addional
object for SRv6 routing about seg6local route. Before this commit,
we can add MPLS info as additional object on nexthop.
This commit make it add more support about seg6local routes.

seg6local routes are ones of the LWT routing mechanism,
so configuration of seg6local routes is performed by
ZEBRA_ROUTE_SEND, it's same as MPLS configuration.

Real configuration implementation isn't implemented at this commit.
later commit add that. This commit add only nexthop additional object
and some misc functions.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:47 -04:00
Hiroki Shirokura
7a4b49bdd1 lib: refactor func prototype seg6local_context2str (step1)
Make seg6local_context2str function's prototype better.
This function is added on commit e496b4203, and function
interface's considering wasn't enough.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2021-06-02 10:24:47 -04:00
Christian Hopps
fd396924d6 northbound: KISS always batch yang config (file read), it's faster
The backoff code assumed that yang operations always completed quickly.
It checked for > 100 YANG modeled commands happening in under 1 second
to enable batching. If 100 yang modeled commands always take longer than
1 second batching is never enabled. This is the exact opposite of what
we want to happen since batching speeds the operations up.

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

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

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

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

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

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-02 14:05:26 +00:00
Rafael Zalamena
d532d1092e
Merge pull request #8644 from idryzhov/fix-vrf-bind
lib: fix binding to a vrf
2021-06-02 10:47:10 -03:00
Quentin Young
c99313762a
Merge pull request #8353 from opensourcerouting/llvm-20210327 2021-06-01 19:08:32 +00:00
Donald Sharp
465d4a6c5b
Merge pull request #8304 from mjstapp/fix_zmq_xref
lib: fix use of xrefs in zmq wrapper
2021-06-01 13:59:51 -04:00
Christian Hopps
b680134e11 lib: fix threading bug in GRPC code
The code that actually calls FRR northbound functions needs to be running in the
master thread. The previous code was running on a GRPC pthread. While fixing
moved to more functional vs OOP to make this easier to see.

Also fix ly merge to merge siblings not throw the originals away.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-01 15:27:54 +00:00
Igor Ryzhov
7bb5c50c83 lib: fix default ttl for single-hop bfd sessions
The TTL field is actually the number of hops, not a TTL.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:08:29 +03:00
Igor Ryzhov
b6c87c3576 lib: fix bfd multihop
Never send an interface name/index for multihop sessions. It breaks
"neighbor A.B.C.D update-source" config in BGP.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-01 18:07:54 +03:00
Donatas Abraitis
ef3b48cfe1 lib: Time to remove CONFDATE block
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-06-01 12:33:43 +03:00
Igor Ryzhov
36eef8586d lib: fix binding to a vrf
There are two possible use-cases for the `vrf_bind` function:
- bind socket to an interface in a vrf
- bind socket to a vrf device

For the former case, there's one problem - success is returned when the
interface is not found. In that case, the socket is left unbound without
throwing an error.

For the latter case, there are multiple possible problems:
- If the name is not set, then the socket is left unbound (zebra, vrrp).
- If the name is "default" and there's an interface with that name in the
  default VRF, then the socket is bound to that interface.
- In most daemons, if the router is configured before the VRF is actually
  created, we're trying to open and bind the socket right after the
  daemon receives a VRF registration from zebra. We may not receive the
  VRF-interface registration from zebra yet at that point. Therefore,
  `if_lookup_by_name` fails, and the socket is left unbound.

This commit fixes all the issues and updates the function description.

Suggested-by: Pat Ruddy <pat@voltanet.io>
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-31 22:12:55 +03:00
Rafael Zalamena
72b9e0cf84
Merge pull request #8718 from taspelund/fix_pfx-tree_default
lib: fix handling of rmap prefix-tree default node
2021-05-25 12:31:03 -03:00
Mark Stapp
9f6b060f63
Merge pull request #8720 from idryzhov/fix-vrf-newline
lib: fix missing newline
2021-05-24 11:40:24 -04:00
Mark Stapp
2d3eb91699
Merge pull request #8498 from ton31337/feature/opaque_data_void_zebra
Zebra OPAQUE data from other daemons stuff
2021-05-24 07:48:02 -04:00
Igor Ryzhov
d9f1279475 lib: fix missing newline
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-24 13:27:23 +03:00
Trey Aspelund
4718791c8f lib: fix handling of rmap prefix-tree default node
Prior to this commit, updating a prefix-list that is referenced by a
route-map clause will unconditionally delete the root node of that
route-map's prefix-tree (used with route-map optimization).
This is problematic because routes not matching a more specific node
in the tree (i.e. other prefix-list sequences) will not fall-back to
the default node, thus they will not hit any route-map sequences.
This commit ensures that an update to a prefix-list will only delete
the default node while adding the first/only seq to the list.

Example config:
========
ip prefix-list peer475-out-pfxlist seq 45 permit 2.138.0.0/16
ip prefix-list peer475-out-pfxlist seq 50 permit 0.0.0.0/0
!
route-map peer475-out permit 5
 match ip address prefix-list peer475-out-pfxlist

Before:
========
ub20# do show route-map peer475-out prefix-table
ZEBRA:

IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    0.0.0.0/0 (2)
(P)
                                                      peer475-out seq 5

    2.138.0.0/16 (2)
(P) 0.0.0.0/0

                                                      peer475-out seq 5
IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________
BGP:
IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    0.0.0.0/0 (2)
(P)
                                                      peer475-out seq 5
    2.138.0.0/16 (2)
(P) 0.0.0.0/0
                                                      peer475-out seq 5
IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________
ub20# conf t
ub20(config)# ip prefix-list peer475-out-pfxlist seq 45 permit 2.138.0.0/16 le 32
ub20(config)# do show route-map peer475-out prefix-table
ZEBRA:
IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    2.138.0.0/16 (2)
(P)
                                                      peer475-out seq 5
IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________
BGP:
IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    2.138.0.0/16 (2)
(P)
                                                      peer475-out seq 5
IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________
ub20(config)#

After:
========
ub20(config)# do show route-map peer475-out prefix-table
ZEBRA:

IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    0.0.0.0/0 (2)
(P)
                                                      peer475-out seq 5

    2.138.0.0/16 (2)
(P) 0.0.0.0/0

                                                      peer475-out seq 5

IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________

BGP:

IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    0.0.0.0/0 (2)
(P)
                                                      peer475-out seq 5

    2.138.0.0/16 (2)
(P) 0.0.0.0/0

                                                      peer475-out seq 5

IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________

ub20(config)# ip prefix-list peer475-out-pfxlist seq 45 permit 2.138.0.0/16 le 32
ub20(config)# do show route-map peer475-out prefix-table
ZEBRA:

IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    0.0.0.0/0 (2)
(P)
                                                      peer475-out seq 5

    2.138.0.0/16 (2)
(P) 0.0.0.0/0

                                                      peer475-out seq 5

IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________

BGP:

IPv4 Prefix                                           Route-map Index List
_______________                                       ____________________
    0.0.0.0/0 (2)
(P)
                                                      peer475-out seq 5

    2.138.0.0/16 (2)
(P) 0.0.0.0/0

                                                      peer475-out seq 5

IPv6 Prefix                                           Route-map Index List
_______________                                       ____________________

ub20(config)#

Fixes: 8410
Signed-off-by: Trey Aspelund <taspelund@nvidia.com>
2021-05-21 22:25:24 +00:00
Christian Hopps
44cd2b2c2a lib: fix northbound merge code (libyang)
lyd_merge_tree replaces dest siblings with source siblings, not what we
want. Instead lyd_merge_siblings to keep both. Instead lyd_merge_siblings
to keep both.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-20 07:38:09 +00:00
Igor Ryzhov
f96c2b6dc2 lib: fix coverity warnings
CID 1504894

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-19 16:22:24 +03:00
Christian Hopps
af1b88e990 lib: libyang2 add missed conversion
Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-17 22:13:59 -04:00
Donatas Abraitis
94effaf032 zebra: Send more OPAQUE data from BGP
This includes community and large-community data.

```
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:23 ago
  * 192.168.0.2, via eth1, weight 1
    AS-Path          : 65030
    Communities      : 65001:1 65001:2 65001:3 65001:4 65001:5 65001:6
    Large-Communities: 65001:123:1 65001:123:2
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-05-14 22:12:33 +03:00
Martin Winter
d8baf3db2d
Merge pull request #8144 from LabNConsulting/chopps/ly2
libyang2
2021-05-14 01:12:06 +02:00
Christian Hopps
3bb513c399 lib: adapt to version 2 of libyang
Compile with v2.0.0 tag of `libyang2` branch of:
https://github.com/CESNET/libyang

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

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-13 16:24:48 -04:00
Donald Sharp
e524fc1e2c
Merge pull request #8659 from mjstapp/fix_connected_multi
lib,zebra: Use a flag to track down status for connected addrs
2021-05-13 07:23:42 -04:00
Mark Stapp
e3d901f863 lib,zebra: Use a flag to track down status for connected addrs
Track 'down' state of connected addresses with a new flag. We
may have multiple addresses on an interface that share a prefix;
in those cases, we need to determine when the first address
is valid, to install a connected route, and similarly detect
when the last address goes 'down', to remove the connected
route.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-05-12 09:37:00 -04:00
Donald Sharp
575a25974b lib: Add ZCAP_IPC_LOCK
We'll need ZCAP_IPC_LOCK for future work coming down the pike
related to dataplane work being done.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-05-11 19:54:40 -04:00
Rafael Zalamena
34723b2fad
Merge pull request #8639 from idryzhov/isis-new-bfd-lib
isisd: rework BFD integration
2021-05-09 17:10:42 -03:00
David Lamparter
de10458d6e
Merge pull request #8380 from mjstapp/nexthop_cmp_basic 2021-05-09 19:29:45 +02:00
Igor Ryzhov
d0bb3c542c
Merge pull request #8632 from wesleycoakley/le-32-128-fix
lib: ip prefix-list "le" and "ge" bug squish
2021-05-07 12:05:59 +03:00
Igor Ryzhov
c97b34cf1a lib: remove old bfd library
This commit also adds missing `bfd_protocol_integration_set_shutdown` to
ospf6d and pimd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-07 12:03:57 +03:00
Wesley Coakley
6907bb6bbf
lib: ip prefix-list enforce expected ge le behavior
When specifying only an "le" for an existing ip prefix-list qualified with
both an "le" and "ge" make sure to remove the "ge" property so it does
not stay in the tree.

E.g. Saying these two things in order:

ip prefix-list test seq 1 permit 1.1.0.0/16 ge 18 le 24
ip prefix-list test seq 1 permit 1.1.0.0/16 ge 18

... should result in the second statement "overwriting" the first like
this:

vxdev-arch# do show ip prefix-list
ZEBRA: ip prefix-list foobar: 3 entries
   seq 1 permit 15.0.0.0/16 ge 18

Previously this did not happen and "le" would stick around since it was
never given NB_OP_DESTROY and purged from the data tree.

Signed-off-by: Wesley Coakley <wcoakley@nvidia.com>
2021-05-06 14:07:06 -04:00
Donatas Abraitis
ed0e57e3f0 bgpd: Create BGP alias names for community/large-community
Show alias name instead of numerical value in `show bgp <prefix>. E.g.:

```
root@exit1-debian-9:~/frr# vtysh -c 'sh run' | grep 'bgp community alias'
bgp community alias 65001:123 community-1
bgp community alias 65001:123:1 lcommunity-1
root@exit1-debian-9:~/frr#
```

```
exit1-debian-9# sh ip bgp 172.16.16.1/32
BGP routing table entry for 172.16.16.1/32, version 21
Paths: (2 available, best #2, table default)
  Advertised to non peer-group peers:
  65030
    192.168.0.2 from home-spine1.donatas.net(192.168.0.2) (172.16.16.1)
      Origin incomplete, metric 0, valid, external, best (Neighbor IP)
      Community: 65001:12 65001:13 community-1 65001:65534
      Large Community: lcommunity-1 65001:123:2
      Last update: Fri Apr 16 12:51:27 2021
exit1-debian-9#
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-05-05 16:37:00 +03:00
Mark Stapp
3d4b999fab
Merge pull request #8237 from pguibert6WIND/nhrp_use_zebra_2
Nhrp use zebra 2
2021-05-05 07:57:04 -04:00
Donatas Abraitis
48c2039199
Merge pull request #8564 from rameshabhinay/bgp_tcp_mss
bgpd: Support tcp-mss for bgp neighbors
2021-05-05 13:45:39 +03:00
Donald Sharp
eda0ea2949 lib: Remove dead code
The distribute_list_init command is not used and is setup
code that will never be used because it makes assumptions about
how distribute-lists work that are fundamentally incorrect.

Remove the code.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-05-04 16:23:37 -04:00
Donald Sharp
458133dbc5 lib, ripd, ripngd, vtysh: Move distribute list to correct spot
Allow the `distribute-list...` command in ripd and ripngd to
work correctly.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-05-04 16:23:37 -04:00
Donald Sharp
df19c76a53 lib: Abstract parsing of distribute lists
Abstract the parsing of distribute lists so that we
don't have as much cut-n-paste code.

This is a setup commit for future work.  In effect
current distribute-list handling is all kinds of messed up

a) eigrp and babel both attempt to use distribute-lists, they just plain
don't work.
b) `distribute-list` is only sent to rip.  `ipv6 distribute-list`
is sent to ripngd.  If you use `distribute-list` under `router ripng`
it sends the command to rip but ripd is in the wrong mode and it
never works.
c) Should ripngd care about v4 and v6 specific distribute-lists?
This dichotomy was added for babel but babel has been broke
about this since day 1( see a ).

All in all we need to unwind this whole mess.  Make distribute-list
commands specific to the daemons( so that we can be in the right
sub-mode ).  But the parsing is going to be the same across all
daemons.  So let's provide that functionality in `lib/distribute.c`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-05-04 16:23:37 -04:00
Mark Stapp
338ec3b867 lib: add basic nexthop comparison api
Add a simpler, more limited nexthop comparison function. This
compares a few key attributes, such as vrf, gateway, labels.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-05-04 15:51:01 -04:00
Mark Stapp
26dddc01a8 lib: Fix label-stack comparison for nexthops
Use the correct number of octets in the comparison of
nexthops' label stacks.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-05-04 11:18:08 -04:00
Abhinay Ramesh
4ab467017e bgpd: Support tcp-mss for bgp neighbors
Problem Statement:
=================
In scale setup BGP sessions start flapping.

RCA:
====
In virtualized environment there are multiple places where
MTU need to be set. If there are some places were MTU is not set
properly then there is chances that BGP packets get fragmented,
in scale setup this will lead to BGP session flap.

Fix:
====
A new tcp option is provided as part of this implementation,
which can be configured per neighbor and helps to set the TCP
max segment size. User need to derive the path MTU between the BGP
neighbors and set that value as part of tcp-mss setting.

1. CLI Configuration:
	[no] neighbor <A.B.C.D|X:X::X:X|WORD> tcp-mss (1-65535)

2. Running config
    frr# show running-config
    router bgp 100
     neighbor 198.51.100.2 tcp-mss 150       => new entry
     neighbor 2001:DB8::2 tcp-mss 400        => new entry

3. Show command
    frr# show bgp neighbors 198.51.100.2
    BGP neighbor is 198.51.100.2, remote AS 100, local AS 100, internal link
    Hostname: frr
      Configured tcp-mss is 150, synced tcp-mss is 138     => new display

4. Show command json output

    frr# show bgp neighbors 2001:DB8::2 json
    {
      "2001:DB8::2":{
        "remoteAs":100,
        "bgpTimerKeepAliveIntervalMsecs":60000,
        "bgpTcpMssConfigured":400,                               => new entry
        "bgpTcpMssSynced":388,                                  => new entry

Risk:
=====
Low - This is a config driven feature and it sets the max segment
size for the TCP session between BGP peers.

Tests Executed:
===============
Have done manual testing with three router topology.
1. Executed basic config and un config scenarios
2. Verified if the config is updated in running config
   during config and no config operation
3. Verified the show command output in both CLI format and
   JSON format.
4. Verified if TCP SYN messages carry the max segment size
   in their initial packets.
5. Verified the behaviour during clear bgp session.
6. done packet capture to see if the new segment size
   takes effect.

Signed-off-by: Abhinay Ramesh <rabhinay@vmware.com>
2021-05-04 06:21:24 +00:00
David Lamparter
02fb02de37 lib: kill unused list_filter_out_nodes()
pimd was the only user of this function, and that has gone away now.
So just kill the function.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-05-03 20:56:55 +02:00
David Lamparter
507e0e5d66 lib: add *_swap_all to typesafe containers
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-05-03 20:55:04 +02:00
Mark Stapp
f71e1ff6a9
Merge pull request #8545 from opensourcerouting/assert-our-own
*: make our own assert() actually work
2021-05-03 11:17:36 -04:00
David Lamparter
9cd090488c
Merge pull request #8479 from mjstapp/zlog_immediate 2021-05-03 10:40:54 +02:00
David Lamparter
4f1a6d98da lib: fix random C++ compat problem w/ printfrr
These hoops to get warnings for mis-printing `uint64_t` are apparently
breaking some C++ bits...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-05-02 16:27:17 +02:00
David Lamparter
64dd77361f lib: rework how we "override" assert()
The previous method, using zassert.h and hoping nothing includes
assert.h (which, on glibc at least, just does "#undef assert" and puts
its own definition in...) was fragile - and actually broke undetected.

Just provide our own assert.h and control overriding by putting it in a
separate directory to add to the include path (or not.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-05-02 16:27:17 +02:00
Donald Sharp
188acbb9a3 lib: Provide some better error handling for operator
When an operator encounters a situation where the number
of FD's open is greater than what we have been configured
to legitimately handle via uname or the `--limit-fds` command
line, abort with a message that they should be able to
debug and figure out what is going on.

Fixes: #8596
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-05-02 07:41:11 -04:00
Philippe Guibert
aea6c49e01 nhrpd: cleaning netlink gre information
flush netlink related dependencies with gre information.
Add some linux headers required to compile with it.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Philippe Guibert
d17af8dd04 lib, zebra: get gre information
the get gre information code is obtained by nhrp, via zebra.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Philippe Guibert
632d83067c zebra: add 3 new gre commands, and enforce synchro mecanism
3 new gre commands are available:
- GRE_GET to permit a daemon to retrieve gre information.
- GRE_UPDATe is the reply message from zebra to the daemon. as it is a
  syncronous request, the GRE_GET expected will have to match the vrf id
  where the gre information is wished. this has an impact on label
  manager with change in APIs.
- SET_GRE_SOURCE. this command will be stubbed for now, assuming that
  the gre interface is set accordingly by external script.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-04-30 10:33:18 +02:00
Rafael Zalamena
c962ab93a8
Merge pull request #8570 from qlyoung/revert-ringbuf-readv
Revert "bgpd: improve socket read performance"
2021-04-29 18:32:52 -03:00
Rafael Zalamena
5418880923
Merge pull request #7165 from qlyoung/fix-zapi-codec-badness
Fix zapi codec badness
2021-04-29 13:50:16 -03:00
Quentin Young
6c55ee964e Revert "lib: add ringbuf socket read function"
This reverts commit d9d7af1a52.
2021-04-29 12:12:32 -04:00
Pavel Ivashchenko
4bb7f7c2dd vtysh: fix searching commands in parent nodes
Do not check parent command nodes in case of ambiguous and incomplete commands

Signed-off-by: Pavel Ivashchenko <pivashchenko@nfware.com>
2021-04-29 18:35:07 +03:00
Igor Ryzhov
55ea3f2ec5
Merge pull request #8110 from rgirada/rmap_nb
lib: Routemap is not getting applied upon changing the routemap action
2021-04-29 17:29:55 +03:00
rgirada
4fc5dafd1c lib: Routemap is not getting applied upon changing the routemap action
Description:
	This looks broken after NB changes in routemap. When routemap
	action modified from permit to deny, it is expected to apply
	the new action on the filtered routes before the action in the
	routemap data structure has been changed. But currently this is
	not handled by the corresponding northbound API.

Signed-off-by: Rajesh Girada <rgirada@vmware.com>
2021-04-29 17:23:37 +03:00
Mark Stapp
ca4681d151
Merge pull request #8559 from idryzhov/fix-printfrr-test-build
tests: fix build warning
2021-04-29 10:12:44 -04:00
Igor Ryzhov
faaa943137 tests: fix build warning
FMT_NSTD_BEGIN should be before the first use of "expr".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-29 03:28:04 +03:00
Quentin Young
bbad027684 lib, bgpd, zebra: RA interval is unsigned
Use unsigned value for all RA requests to Zebra

- encoding signed int as unsigned is bad practice
- RA interval is never, and should never be, negative

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2021-04-28 11:43:50 -04:00
Donatas Abraitis
a1fc0cb01e
Merge pull request #8471 from idryzhov/cleanup-num-named-lists
*: cleanup number-named access-lists and prefix-lists
2021-04-28 08:33:24 +03:00
Russ White
0a9fdfee67
Merge pull request #8527 from opensourcerouting/fixes-20210421
lib: fix zlog assert() & CLI node_exit
2021-04-27 15:14:12 -04:00
Stephen Worley
829c939a88
Merge pull request #8488 from mjstapp/more_workqueue
lib, zebra: use zebra workqueue for NHG updates
2021-04-27 11:59:33 -04:00
Mark Stapp
8123bf2bd6
Merge pull request #8534 from opensourcerouting/threads-vs-fork
lib, pathd PCEP: creating threads before forking does _not_ work
2021-04-26 07:57:15 -04:00
Igor Ryzhov
2ccc493333
Merge pull request #8495 from opensourcerouting/ospfv3-bfd-rework
ospf6d: rework BFD integration and add BFD profiles support
2021-04-24 00:47:31 +03:00
David Lamparter
642ac49da4 *: remaining zassert => assert
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:25:51 +02:00
David Lamparter
6a0eb6885b *: drop zassert.h
It's not actually working properly...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:06:35 +02:00
David Lamparter
1f8031f79a *: make sure config.h or zebra.h is first
`config.h` has all the defines from autoconf, which may include things
that switch behavior of other included headers (e.g. _GNU_SOURCE
enabling prototypes for additional functions.)

So, the first include in any `.c` file must be either `config.h` (with
the appropriate guard) or `zebra.h` (which includes `config.h` first
thing.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-23 12:06:35 +02:00
Rafael Zalamena
ac506cb20e lib: BFD session handling improvement
Don't uninstall sessions if the address, interface, VRF or TTL didn't change.

Update the library documentation to make it clear to other developers.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-04-22 16:10:04 -03:00
Rafael Zalamena
464e6541b1 lib: fix possible crash on BFD notification
Allow sessions to remove themselves from the notifications without
risking crashes.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-04-22 15:12:18 -03:00
Rafael Zalamena
b38f1fd03d
Merge pull request #8536 from idryzhov/bfd-enabled
lib: remove enabled flag for bfd sessions
2021-04-22 15:06:48 -03:00
Igor Ryzhov
e82acdce22 lib: remove enabled flag for bfd sessions
Currently this flag is only helpful in an extremely rare situation when
the BFD session registration was unsuccessful and after that zebra is
restarted. Let's remove this flag to simplify the API. If we ever want
to solve the problem of unsuccessful registration/deregistration, this
can be done using internal flags, without API modification.

Also add the error log to help user understand why the BFD session is
not working.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-04-22 16:39:29 +03:00
David Lamparter
38554d3ae6 lib: hard-fail creating threads before fork()
Creating any threads before we fork() into the background (if `-d` is
given) is an extremely dangerous footgun;  the threads are created in
the parent and terminated when that exits.

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

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

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

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-22 13:16:20 +02:00
David Lamparter
e3476061fe lib: correctly exit CLI nodes on file config load
The (legacy) code for reading split configs tries to execute config
commands in parent nodes, but doesn't call the node_exit function when
it goes up to a parent node.  This breaks BGP RPKI setup (and extended
syslog, which is in the next commit.)

Doing this correctly is a slight bit involved since the node_exit
callbacks should only be called if the command is actually executed on a
parent node.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-04-21 16:25:38 +02:00