Commit Graph

3440 Commits

Author SHA1 Message Date
David Lamparter
57d898f3eb lib: fix MTYPE alias on clang
This is probably a compiler bug :/

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-21 14:51:50 +02:00
David Lamparter
eaf58ba906 lib: use MTYPE_STATIC
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-21 08:54:25 +02:00
David Lamparter
056830ba69 lib: improve MTYPE definitions
The "static struct mtype * const MTYPE_FOO" doesn't quite make a
"constant" that is usable for initializers.  An 1-element array works
better.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-21 08:54:25 +02:00
Donald Sharp
55858394f2 lib: Order show run route-map order to be alphabetical
When running `show run` of route-maps the order is basically
the order read in some fashion.  Convert the display to
always be the alphabetically sorted order.

Suggested-by: Manuel Schweizer <manuel@cloudscale.ch>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-20 15:03:05 -04:00
Donald Sharp
1fa305095a lib: Add clear route-map counters [WORD] command
This will allow the end-user to clear the counters associated
with the route-map.  Subsuquent `show route-map ..` commands
will display counters since the last clear.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-20 14:10:44 -04:00
Visakha Erina
0277936a2c lib: Keep proper count of prefix-list hit-count when used
When a prefix-list is applied to a BGP neighbor to deny the learning
of specific routes, the hit count is showing 0 for BGP even though
the routes are being filtered correctly due
to the configured prefix-list.

Before fix:

c1# show ip prefix-list nag seq 10
ZEBRA: seq 10 permit any (hit count: 0, refcount: 0)
BGP: seq 10 permit any (hit count: 0, refcount: 0)
c1# show ip prefix-list nag seq 5
ZEBRA: seq 5 deny 1.0.1.0/24 (hit count: 0, refcount: 0)
BGP: seq 5 deny 1.0.1.0/24 (hit count: 0, refcount: 0)

Fix: Increment the prefix-list's hit count whenever a rule match occurs.

After Fix:

c1# show ip prefix-list nag seq 10
ZEBRA: seq 10 permit any (hit count: 0, refcount: 0)
BGP: seq 10 permit any (hit count: 6, refcount: 0)
c1# show ip prefix-list nag seq 5
ZEBRA: seq 5 deny 1.0.1.0/24 (hit count: 0, refcount: 0)
BGP: seq 5 deny 1.0.1.0/24 (hit count: 1, refcount: 0)

Signed-off-by: Visakha Erina visakha.erina@broadcom.com
2019-06-20 01:51:38 -04:00
Donald Sharp
43b8ca995b lib: Do not blindly set the _read and _write pointers to NULL
Adding a read with the address of the thread pointer we want to
use will allow lib/thread.c to properly handle your thread pointers.
Instead we were setting the pointer to NULL before we passed
into the _read and _write thread functions.  Remove the NULL
pointer set and just let thread.c handle everything.

vty_stdio_resume and vty_read would blindly add read and write
which would cause vty_event() to drop the thread pointer.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-19 19:04:53 -04:00
Stephen Worley
8ad7c5c2e7 lib: Remove extraneous spacing/output filter cmds
Use %% style for errors in log commands and switch
tabs to a single space in output. Also, remove un-needed
output for success.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
ec1d97751e lib: Use gotos in filter control functions
Use gotos to reduce return paths in the log filter
add/del/dump functions.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
3b96430b72 lib: Add vrrpd,sharpd to DAEMONS_* strings
Add vrrpd and sharpd to the DAEMONS_* list so they
can be dispatched daemons independent commands
such as `show work-queues` and `log-filter`.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
fc2a67dd25 lib: Filter logs as they come in via macros
As logging functions are called, if filters are stored,
look for the filter substring in the logs. If it is not
found, do not output the log to a file or stdout.

If the filter is matched, handle the log call per usual.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
f73126c31a lib,vtysh: Add vtysh commands for log-filter
Add vtysh commands to add/del/clear/show filters across
all daemons and independently on each one. Add automake and
clippy boilerplate for those commands as well.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
bd1058c0af lib: Use memmove to adjust filters after del
Simplify the code in deleting a filter by using memmove rather
than iterating. Memmove handles overlapping strings safely so
this is fine here.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
c0dc23460b lib: Add log filter manipulation code
Add code for manipulation/creation of log filters
and their table. Specifically, add lookup,clear,add,del,dump
functionality.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Stephen Worley
db9a7cf7c0 lib: Add some all daemon command strings
Add some strings for defining vty commands that target
all daemons.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-06-19 17:20:24 -04:00
Donald Sharp
2e4c561bf8
Merge pull request #4300 from adharkar/frr-master-rmap_debug
Lib: Debugs for route-map code in FRR
2019-06-18 11:24:10 -04:00
Donald Sharp
7ec5e2bf70
Merge pull request #4514 from opensourcerouting/warnings-20190612
*: kill more warnings
2019-06-17 15:19:42 -04:00
David Lamparter
ce746edebb
lib: Prevent infinite loop in fd handling (#4516)
lib: Prevent infinite loop in fd handling
2019-06-14 23:48:36 +02:00
David Lamparter
277aee6fc9
eliminate snprintf from AF_INET/AF_INET6 prefix2str, add prefix2str test (#4521)
eliminate snprintf from AF_INET/AF_INET6 prefix2str, add prefix2str test
2019-06-14 21:48:34 +02:00
David Lamparter
0688fd81d0
bgpd, lib: Add iana_afi2str and iana_safi2str for eye pleasing strings (#4439)
bgpd, lib: Add iana_afi2str and iana_safi2str for eye pleasing strings
2019-06-13 22:06:49 +02:00
Donald Sharp
a0b36ae673 lib: Add function name to show thread poll
When displaying `show thread poll` data add the
function we are supposed to call when the poll
event happens.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-13 15:14:04 -04:00
Donald Sharp
1ef14bee7a lib: Add check for non-preexisting thread
When adding a read/write poll event and we are using a developmental
build add a bit of code to ensure that we do not already have an read
or write event scheduled.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-13 15:14:04 -04:00
Donald Sharp
45f3d59084 lib: Prevent infinite loop in fd handling
If we have a case where have created a fd for i/o and we have
removed the handling thread but still have the fd in the poll
data structure, there existed a case where we would get
the handle this fd return from poll but we would immediately
do nothing with it because we didn't have a thread to hand
the event to.

This leads to an infinite loop.  Prevent the infinite loop
from happening and log the problem.

We still need to find the cause of this happening.  But
let's prevent the system from melting down in the mean time.

Fixes: #2796
Signed-off-by: David Lamparter <equinox@diac24.net>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-13 15:14:04 -04:00
Quentin Young
42aac9b2ab
Merge pull request #4500 from opensourcerouting/clippy-improve
clippy: batch of improvements
2019-06-13 15:06:24 -04:00
Quentin Young
096873bd46
Merge pull request #4509 from opensourcerouting/spanish-intquisition
lib: make printfrr int64_t usable
2019-06-13 14:00:50 -04:00
Quentin Young
ec466f6546 lib: remove snprintf from prefix2str
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-06-13 17:08:05 +00:00
Mark Stapp
a8baba69ae
Merge pull request #4448 from opensourcerouting/cxx-container-of
lib: const-unaware container_of for C++
2019-06-13 08:38:05 -04:00
David Lamparter
2618a52ed3 *: config.h or zebra.h is the first #include
This is mostly relevant for Solaris, where config.h sets up some #define
that affect overall header behaviour, so it needs to be before anything
else.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-13 13:35:33 +02:00
David Lamparter
f54dd468ec lib/clippy: ignore -Wstrict-aliasing
This warning is both meaningless and unfixable, just ignore it.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-13 00:05:03 +02:00
David Lamparter
866f6e4008 lib: drop DSO_SELF on inet_ntop
NetBSD doesn't seem to like this.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-13 00:05:03 +02:00
David Lamparter
53280f9327 *: fix northbound initializer warning on OpenBSD
For some reason, the compiler on OpenBSD on our CI boxes doesn't like
struct initializers with ".a.b = x, .a.c = y", generating a warning
about overwritten initializers...

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-13 00:05:03 +02:00
David Lamparter
afb35622ef lib: make "%Ld" work for int64_t
... without compiler plugins.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-12 19:35:43 +02:00
David Lamparter
c7179009cf lib: use snprintfrr() in "hidden" printfs
We need to be calling snprintfrr() instead of snprintf() in places that
wrap snprintf in some user-exposed way; otherwise the extensions won't
be available for those functions.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-12 19:35:43 +02:00
David Lamparter
3779776a39 lib/clippy: error out on unsupported bits
clippy can't process #ifdef or similar bits inside of an argument list
(e.g. within the braces of a DEFUN or DEFPY statement.)  Improve error
reporting to catch these cases instead of generating broken C code.

Fixes: #3840
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-12 19:22:59 +02:00
David Lamparter
a71c5039ad build: improve clippy options
* adds a `--with-clippy=...` option to use a prebuilt clippy binary
* limits the autoconf tests done for `--enable-clippy-only`
  (e.g. no libyang)

Fixes: #3921
Fixes: #4006
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-12 19:22:59 +02:00
David Lamparter
2655e41fa2 build: slim down configure.ac
Quite a few tests are deprecated/unnecessary at this point.  Remove
everything that is pointless.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-12 19:22:55 +02:00
Renato Westphal
eaf6705d7a lib: fix outdated candidate configuration issue
Even when using the classic CLI mode (i.e. when --tcli is not
used), the northbound code still uses vty->candidate_config
to perform configuration changes. From the perspective of the
user, the running configuration is being edited directly, but
under the hood the northbound layer does a full configuration
transaction for each command.  When the running configuration is
edited by a northbound client other than the CLI (e.g. kernel,
gRPC), vty->candidate_config might become outdated, and this can
lead to lots of weird problems. To fix this, always regenerate
vty->candidate_config before each configuration command when
using the classic CLI mode. When using the transactional CLI,
the user needs to update the candidate manually using the "update"
command, otherwise the "commit" command will fail with this error:
"% Candidate configuration needs to be updated before commit".

Fixes some problems reported by Don after moving an interface from
one VRF to another one while zebra is running.

Reported-by: Don Slice <dslice@cumulusnetworks.com>
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-06-12 11:17:03 -03:00
Philippe Guibert
a41c4e1b1f *: change interface structure, from vrf_id to vrf
Field vrf_id is replaced by the pointer of the struct vrf *.
For that all other code referencing to (interface)->vrf_id is replaced.
This work should not change the behaviour.
It is just a continuation work toward having an interface API handling
vrf pointer only.

some new generic functions are created in vrf:
vrf_to_id, vrf_to_name,

a zebra function is also created:
zvrf_info_lookup

an ospf function is also created:
ospf_lookup_by_vrf

it is to be noted that now that interface has a vrf pointer, some more
optimisations could be thought through all the rest of the code. as
example, many structure store the vrf_id. those structures could get
the exact vrf structure if inherited from an interface vrf context.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 14:10:28 +02:00
Philippe Guibert
da85f5e038 lib, bgpd, ospfd, pimd, zebra, rip, ripng, bfd: change if_update_to_new_vrf() api
vrf_id parameter is replaced with struct vrf * parameter. It is
needed to create vrf structure before entering in the fuction.
an error is generated in case the vrf parameter is missing.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:58 +02:00
Philippe Guibert
921a85ba8c zebra, ifp: on netlink discovery, anticipate the vrf creation
there may be cases where the vrf is yet allocated from the vty, and the
discovery process did not make the relationship between the vrf_id and
the name of the vrf. For instance, by parsing an interface belonging to
vrf-id X, it is not sure that vrf-id X and vrfname XX are talking about
the same vrf. For that, lets allocate the vrf, and lets try to detect
there is a duplicate case in vrf, so that the merge can be done without
any impact for the user.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:58 +02:00
Philippe Guibert
8205b1b455 zebra, lib: upon entering interface, create vrf context
the interface search is based on vrfs. As at startup, some interfaces
may be configured, there is need to have vrfs contexts present. A macro
is being appended with an extra parameter that permits create a vrf and
return the context. This macro is also used by some show routines, but
will not create vrfs, because that extra parameter will be set to false,
on that case.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:58 +02:00
Philippe Guibert
ac6c2a11a6 lib: create interface upon accessing interface NB API.
Upon accessing interface NB API, the interface is created, if the vrf
is available. the commit does not change the behaviour, since at this
commit, this is not yet possible to have vrf contexts, while zebra did
not connect to daemons. However, that commit adds some work, so that it
will be possible to work on a vrf context, without having the vrf_id
completely resolved. for instance, if we suppose a vrf is created by
command 'vrf TOTO' in the starting configuration of a daemon, then 'interface
TITI vrf TOTO' will permit to create interface TITI within vrf TOTO.

the macro VRF_GET_INSTANCE will return the vrf context, if available or
not.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:58 +02:00
Philippe Guibert
f11e98eca3 *: change if_lookup_by_name() api with vrf
the vrf_id parameter is replaced by struct vrf * parameter.
this impacts most of the daemons that look for an interface based on the
name and the vrf identifier.
Also, it fixes 2 lookup calls in zebra and sharpd, where the vrf_id was
ignored until now.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:54 +02:00
Ameya Dharkar
e3ab8170bd Lib: Debugs for route-map code in FRR
Added a CLI "debug route-map" to enble route-map debugs

Added debugs for following triggers
1. Add/delete a route-map
2. Add/delete a sequence in route-map
3. Add/delete a match statement(dependency)
4. Update a dependency
5. Apply a route-map

Signed-off-by: Ameya Dharkar <adharkar@vmware.com>
2019-06-11 16:17:15 -07:00
David Lamparter
a7f20d4328 lib: const-unaware container_of for C++
This version of container_of() should work on C++, by ditching the
unavailable builtins (at the cost of no longer checking for "const"
violations.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-11 18:45:38 +02:00
Philippe Guibert
e9c199a6c1 lib, ospfd, pimd, zebra: change if_create() api with vrf
if_create() takes as input a vrf poiter instead of the vrf_id parameter.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-11 17:10:47 +02:00
Philippe Guibert
4c634658a6 ospf, ospf6d, zebra, lib: change if_get_by_name prototype with vrf
vrf pointer is used as reference when calling if_get_by_name() function.
this will permit to create interfaces with an unknown vrf_id, since it
is only necessary to get the vrf structure to store the interfaces.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-11 17:10:47 +02:00
David Lamparter
051a0be4b2 *: fix some dumb printf format warnings
Some types like `time_t` vary across platforms and always need to be
cast when printed.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-11 13:34:57 +02:00
David Lamparter
e787685f86
More compiler cleanup (#4487)
More compiler cleanup
2019-06-11 13:31:52 +02:00
David Lamparter
0afc154435
Zebra.h header cleanup (#4444)
Zebra.h header cleanup
2019-06-11 11:36:17 +02:00
Renato Westphal
9fd5497f30
Merge pull request #4484 from donaldsharp/pbr_tab_complete
Pbr tab complete
2019-06-07 21:48:53 -03:00
Quentin Young
9f9307c953
Merge pull request #4480 from opensourcerouting/inet_ntop
inet_ntop but faster
2019-06-07 11:23:16 -04:00
Donald Sharp
adc109b5a2 lib: On some platforms function did not return anything
On some compiler platforms the md5 setup function was
not returning anything.  Place failure case on the bottom
to properly handle this situation.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-07 09:29:45 -04:00
Donald Sharp
3711fdb77c lib: Include proper header
bcopy is being used in the new printf code.  Let's actually
include the proper header for it.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-07 09:29:45 -04:00
Donald Sharp
9a8a7b0ed1 lib, pimd, sharpd: Various output string cleanups
Various compilers in our CI system were complaining about various
auto-conversions.  Let's get these cleaned up a bit more.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-07 09:29:45 -04:00
David Lamparter
874035be4e tests: exercise frr_inet_ntop()
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-06 20:59:54 +02:00
David Lamparter
e128c00226 lib: add optimized inet_ntop()
This commit is brought to you by: "Manuel - Gas Gas Gas" (Initial D)

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-06 20:59:50 +02:00
David Lamparter
111a04f740 lib: add OPTIMIZE + assume() to compiler.h
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-06 20:58:20 +02:00
Mark Stapp
fa3bf3a21b lib,bgpd,babeld,ripngd,nhrpd,bfdd: clean up SA warnings
Clean up several SA warnings.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-06-06 13:13:15 -04:00
Donald Sharp
695a52fd5e
Merge pull request #4333 from opensourcerouting/printfrr
printfrr() world domination tour
2019-06-05 13:30:42 -04:00
Donald Sharp
868ee86cec lib, pbrd, sharpd, vtysh: Add autocompletion for 'nexthop-group'
Add some auto-completion for the nexthop-group command

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-05 06:33:00 -04:00
Donald Sharp
43e587c1d1 *: Convert over to all -N namespace to change DAEMON_VTY_DIR
When the user specifies -N namespace allow it to influence the
frr_vtydir(DAEMON_VTY_DIR) to have namespace in it's path
like so: $frrstate_dir/<namespace>

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-04 19:52:46 -04:00
Donald Sharp
4e99f30932 lib: Allow -N to modify the zapi domain socket
When using -z, allow that to override the zapi domain socket
path.  If using -N add the namespace name to the path to
$frr_statedir/<namespace>/zserv.api.  If you don't specify
the -N or -z option then it is $frr_statedir/zserv.api

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-04 10:37:19 -04:00
Lakshman Krishnamoorthy
2789041a46 Revert of PR 4078 and PR 4315
Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
2019-06-03 15:43:02 -07:00
David Lamparter
c22f6d8cde lib: simplify SEGV handler
printfrr is AS-Safe, let's simplify the SEGV handler quite a bit by
relying on that.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 18:57:31 +02:00
David Lamparter
3cd9490d0b lib/printf: ditch reallocarray
reallocarray() is walled behind stupid feature macros on various
platforms and doesn't quite gain us much in that particular use case.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 18:57:31 +02:00
David Lamparter
d52ec5720f lib: add some printfrr specifiers
More to come - these are just the most obvious and easy.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 18:57:31 +02:00
David Lamparter
807f5b9842 lib: use printfrr for log & vty
This makes printfrr extensions available in most of our format strings.
snprintf() is the obvious exception.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 18:57:28 +02:00
David Lamparter
bf4d3d8021 lib/printf: add extension support
Inspired by the Linux kernel, this allows us to do %pI4 and similar
things.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:45:01 +02:00
David Lamparter
60f1101d29 lib/printf: fix some random warnings
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:58 +02:00
David Lamparter
5c25bd87b5 lib/printf: integrate
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:51 +02:00
David Lamparter
8be3678a23 lib/printf: rename & private __find_arguments
These are internal to printf(), and symbols starting with __ are
reserved for the compiler/libc.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:32 +02:00
David Lamparter
e8c672ea81 lib/printf: disable wchar_t support
... we just don't use wchar_t in FRR, no point in having this enabled.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:29 +02:00
David Lamparter
32b67a0aeb lib/printf: add %Ld/%Lu for int64_t/uint64_t
[u]int64_t is the only type in the intX_t family that needs
special-casing for printf since the calling convention may differ
between 32-bit and 64-bit systems.

Adding the L specifier allows us to eschew the gnarly-looking PRIu64.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:24 +02:00
Donald Sharp
f232dd29c1 lib: Cleanup recent commit warn->werror issues in lib/routemap.c
The get_route_map_delete_event function should return a value
even if we never get to that part of the function.  Make sure
we know why we are here so it can be fixed appropriately in
the future.

Signed-off-by: Donald Sharp <sharpd@cumulusnetwork.com>
2019-06-03 10:44:23 -04:00
David Lamparter
7fa480984e lib/printf: use system printf for floats
We're not libc, we can just fall back to snprintf() to avoid all this
low-level float mangling.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:18 +02:00
David Lamparter
86bfbddf6e lib/printf: cut down to size
remove various FreeBSD specific bits, as well as the entirety of locale
support.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:05 +02:00
David Lamparter
ea0b6afe2b lib: import FreeBSD's printf
... from current SVN HEAD (not that it has been touched in the past 2
years ...)

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:43:11 +02:00
David Lamparter
5a4ac9df0f
No log commands (#3581)
No log commands
2019-06-03 15:52:32 +02:00
Donald Sharp
b2eea7a00e
Merge pull request #4345 from NaveenThanikachalam/route_map_dep
lib: Changes made to dependencies of a route-map do not take effect dynamically.
2019-06-03 09:19:59 -04:00
Donald Sharp
03edc41d51 lib: Move zebra_size_t to zclient.h who should own it
The zebra_size_t type needs to be owned by zclient.h since
it is part of the zapi protocol.  Move it to where the
structure belongs.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 16:07:48 -04:00
Donald Sharp
64cbb7c5b7 lib: Remove unused zebra_command_t type
The zebra_command_t type was never being used, remove from
the system.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 16:07:48 -04:00
Donald Sharp
26ee1525e6 lib: Remove unused INT8_MAX and UINT8_MAX values
We are not using these in the system, remove.

Signed-off-by: Donald Sharp <sharpd2cumulusnetworks.com>
2019-06-02 16:07:48 -04:00
Donald Sharp
8ee06b2c46 lib: Move ZEBRA_HEADER_MARKER to header it belongs in
The ZEBRA_HEADER_MARKER is part of the zapi protocol
Move it to the zclient.h header.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 16:07:48 -04:00
Donald Sharp
da01a37a1b lib: Move zclient flags to zclient.h
zebra.h had some defined flags that were being used
as part of the route encode/decode functionality.  These
belong in the zclient.h code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 16:07:48 -04:00
Donald Sharp
7708357131 lib: Move some log.c functions declarations to log.h
We have some functions that are owned by log.c, so
move their declarations from zebra.h to log.h

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 16:07:48 -04:00
Donald Sharp
17136bf23e lib, bgpd: Create iana_afi.h for storing iana_afi/safi enums
The iana_afi_t and iana_safi_t were being created in zebra.h
and zebra.h is a bit of a dumping ground.  When the iana_afi2str and
iana_safi2str functions were created, it was correctly pointed out
that we should just use the internal afi_t and safi_t 2str functions
but to do that we would need to include prefix.h in zebra.h.  Which
really is not the right thing to do.  This tells us that we need
to break out this code into it's own header.

Move to iana_afi.h the enums and specific functions and remove
from zebra.  Convert to using the afi2str and safi2str functions.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 15:02:07 -04:00
Donald Sharp
748a041f09 bgpd, lib: Add iana_afi2str and iana_safi2str for eye pleasing strings
Modify the code such that we can auto turn the iana values of afi
and safi to pleasant to read strings.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 14:51:52 -04:00
Donald Sharp
d92050a607 lib: Remove some iana_afi_t values that are not really afi's
The IPMR and IP6MR values have no actual legal representation
and we do not sue them at all.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-06-02 14:48:19 -04:00
Mark Stapp
32e4ce5fd5
Merge pull request #4435 from donaldsharp/zclient_buffer_sizing
lib, zebra: Ensure route encoding has enough space
2019-05-31 16:20:38 -04:00
Donald Sharp
ce231fbc87
Merge pull request #4430 from lkrishnamoor/hostname_crash
lib: crash when FRR hostname length > 80 chars
2019-05-31 15:02:10 -04:00
Lakshman Krishnamoorthy
63e653a21f lib: crash when FRR hostname length > 80 chars
Although the RFC states hostname length should be < 255 chars,
FRR allows infinite length technically. However, when you try
to set a hostname > 80 chars, you would immediately notice a crash.

RCA: Crash due to buffer overflow. Large buffer sprintf'd into smaller
buffer. Usage of sprintf function instead of snprintf which is safer.

Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
2019-05-31 10:52:33 -07:00
Naveen Thanikachalam
e2c8d6ce90 lib: Changes made to dependencies of a r-map do not take effect.
Say, more than one sequence of a route-map uses the same named entity
in its match clause. After that entity is removed from any one of the
route-map sequences, any further changes made to that entity doesn't
dynamically take effect.
A reference counter, that allows the named entity to keep a count of
the route-maps dependent on it,  has been introduced to address this issue.

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
2019-05-31 10:05:19 -07:00
Donald Sharp
f3f4562612 lib, zebra: Ensure route encoding has enough space
When you have compiled FRR with a large multipath number
then encoding large ecmp routes between zebra and the
routing daemons.  There exists a theoritical size
of multipath that will cause the encoding to be larger
than the ZEBRA_MAX_PACKET_SIZ.  In the cases where
we have allocated streams that will encode routes
then let's ensure that whatever size we have will
auto-fit what we say we can send.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-31 10:25:18 -04:00
Donald Sharp
2950f5da55 lib: Add '--command-log-always` to all daemons startup
Add 'no log commands' cli and at the same time add a
--command-log-always to the daemon startup cli.

If --command-log-always is specified then all commands are
auto-logged and the 'no log commands' form of the command
is now ignored.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-31 10:06:42 -04:00
Donald Sharp
1b3f6ff1f6 lib: Fix gcc 9 warning -> error issue
gcc is complaing about this with --enable-dev and --enable-werror:

In function 'nb_log_callback',
    inlined from 'nb_transaction_apply_finish' at lib/northbound.c:1106:4:
lib/northbound.c:777:2: error: '%s' directive argument is null [-Werror=format-overflow=]
  777 |  zlog_debug(
      |  ^~~~~~~~~~~
  778 |   "northbound callback: event [%s] op [%s] xpath [%s] value [%s]",
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  779 |   nb_event_name(event), nb_operation_name(operation), xpath,
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  780 |   value);
      |   ~~~~~~
  CC       lib/ringbuf.lo

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-31 08:37:34 -04:00
Donald Sharp
918537e240 lib: vtypath_default could be overwritten
The vtypath_default variable had a possibility of being overwritten
due to size constraints.  This fixes this issue.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-31 08:18:55 -04:00
Donald Sharp
9c61cec7e3
Merge pull request #4315 from lkrishnamoor/route_map_3rd_state
lib: Introducing a 3rd state for route-map match cmd: RMAP_NOOP
2019-05-30 21:25:18 -04:00
Mark Stapp
85a6806dce lib, vtysh: make debug memstats work in vtysh
Allow vtysh to send the 'debug memstats-on-exit' command
to the running daemons.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-05-30 16:14:25 -04:00
Lakshman Krishnamoorthy
eadd168781 lib: Introducing a 3rd state for route-map match cmd: RMAP_NOOP
Introducing a 3rd state for route_map_apply library function: RMAP_NOOP

Traditionally route map MATCH rule apis  were designed to return
a binary response, consisting of either RMAP_MATCH or RMAP_NOMATCH.
(Route-map SET rule apis return RMAP_OKAY or RMAP_ERROR).
Depending on this response, the following statemachine decided the
course of action:

Action: Apply route-map match and return the result (RMAP_MATCH/RMAP_NOMATCH)
State1: Receveived RMAP_MATCH
THEN: If Routemap type is PERMIT, execute other rules if applicable,
otherwise we PERMIT!
Else: If Routemap type is DENY, we DENYMATCH right away

State2: Received RMAP_NOMATCH, continue on to next route-map, otherwise,
return DENYMATCH by default if nothing matched.

With reference to PR 4078 (https://github.com/FRRouting/frr/pull/4078),
we require a 3rd state because of the following situation:

The issue - what if, the rule api needs to abort or ignore a rule?:
"match evpn vni xx" route-map filter can be applied to incoming routes
regardless of whether the tunnel type is vxlan or mpls.
This rule should be N/A for mpls based evpn route, but applicable to only
vxlan based evpn route.

Today, the filter produces either a match or nomatch response regardless of
whether it is mpls/vxlan, resulting in either permitting or denying the
route.. So an mpls evpn route may get filtered out incorrectly.
Eg: "route-map RM1 permit 10 ; match evpn vni 20" or
"route-map RM2 deny 20 ; match vni 20"

With the introduction of the 3rd state, we can abort this rule check safely.
How? The rules api can now return RMAP_NOOP (or another enum) to indicate
that it encountered an invalid check, and needs to abort just that rule,
but continue with other rules.

Question: Do we repurpose an existing enum RMAP_OKAY or RMAP_ERROR
as the 3rd state (or create a new enum like RMAP_NOOP)?
RMAP_OKAY and RMAP_ERROR are used to return the result of set cmd.

We chose to go with RMAP_NOOP (but open to ideas),
as a way to bypass the rmap filter

As a result we have a 3rd state:
State3: Received RMAP_NOOP
Then, proceed to other route-map, otherwise return RMAP_PERMITMATCH by default.

Signed-off-by:Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
2019-05-30 11:21:28 -07:00
Renato Westphal
4eb4afa3b6
Merge pull request #4393 from donaldsharp/debug_all
Debug all
2019-05-29 23:55:50 -03:00
Quentin Young
67c726a10d lib: fix helpstring truncation
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:03:26 +00:00
Quentin Young
daeb97e980 lib: use static storage for vty_cwd
Why are we allocating this

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:03:26 +00:00
Quentin Young
fcb072cdbf lib, zebra: remove uses of strncpy
This removes the last removable uses of strncpy in FRR.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:03:26 +00:00
Quentin Young
9f73d2c9b6 lib: remove some strcpy, strcat
Replace with strlcpy, strlcat

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:02:57 +00:00
Quentin Young
53a394720e lib: fix false compiler warning
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:02:57 +00:00
Quentin Young
aa0e96ed1c lib: fix uninitialized variable in backtrace output
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-29 18:02:57 +00:00
Mark Stapp
5c6188221f
Merge pull request #4404 from qlyoung/const-linklist
lib: const a couple linklist apis
2019-05-29 11:28:08 -04:00
Donald Sharp
ae0994f6eb lib: Separate out the debug_init api
Separate out the debug_init api to have 2 functions:

1) Function to register a callback
2) Function to initiate the cli.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-28 17:16:16 -04:00
Donald Sharp
f756a869ae lib: Make the debug callbacks a list of callbacks
Allow multiple callers to initialize themselves to receive
callbacks for debug on/off operations.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-28 17:07:04 -04:00
Quentin Young
396cd6366d lib: const a couple linklist apis
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-28 20:23:04 +00:00
Donald Sharp
dcdc27095a
Merge pull request #4391 from ton31337/feature/delete_prefix_list_by_sequence_number
plist: Delete prefix-list by sequence number
2019-05-28 16:14:52 -04:00
Jafar Al-Gharaibeh
bda0241599
Merge pull request #4239 from sarav511/rp
pimd: PIM Bootstrap Message Processing
2019-05-28 10:26:28 -05:00
Renato Westphal
f6fd430e44
Merge pull request #4322 from sworleys/Nexthop-Cmp
lib: Add nexthop_cmp
2019-05-28 11:32:44 -03:00
Renato Westphal
a26bd54e86
Merge pull request #4390 from qlyoung/frrstr-beginswith-endswith
lib: rename begins_with, add frrstr_endswith
2019-05-27 20:55:14 -03:00
Donatas Abraitis
7e200e8645 plist: Delete prefix-list by sequence number
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2019-05-25 13:02:38 +03:00
Donald Sharp
51da389626 bgpd, lib: Remove SO_MARK
The SO_MARK socket option was being used pre vrf to allow for the
separation of the front panel -vs- the management port.  This
was facilitated by a ip rule.  Since this is undocumented anywhere
in our system( other than old commits see
ed40466af8 ).  We should remove this
because this will cause interference with people using rules
and are not aware of this offshoot of functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-24 08:35:35 -04:00
Donald Sharp
6c19478a3b lib: Display to end user the MAX_FDS allowed
Upon startup FRR reads in the MAX_FDS variable from
it's control files via the getrlimit call.  We then
setup code to limit the poll data structure size to
that value.  The OS also limits our FD's to that value
because that is what is set.  Provide a methodology
that a interested end user can figure this data out.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-24 08:24:18 -04:00
Donald Sharp
61fa0b976a lib: 'show thread cpu' help strings referenced a weird option
The 'show thread cpu' command referenced a 'b' option.  Which
is not parsed at all in the parse_filter function.  As such
I do not know what this was referencing as that it has been
removed.  Update the help strings to reflect this reality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-24 08:24:18 -04:00
Quentin Young
90cf59eccf lib: replace begins_with, add frrstr_endswith
* Change 'begins_with' to 'frrstr_startswith' for consistency
* Add suffix checker, frrstr_endswith()
* Update vtysh to use the new function

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-23 20:52:01 +00:00
Stephen Worley
a5a2d802d7 lib,zebra,bgpd,pbrd: Compare nexthops without labels
Allow label ignoring when comparing nexthops. Specifically,
add another functon nexthop_same_no_labels() that shares
a path with nexthop_same() but doesn't check labels.

rib_delete() needs to ignore labels in this case.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
24cfec8418 lib: Explicitly cmp gateway and source based on AF
Refactor the gatway and source nexthop comparision into a
common code path that compares them explicitly based on
their address family.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
78fba41bd8 lib,zebra,bgpd: Remove nexthop_same_no_recurse()
The functions nexthop_same() does not check the resolved
nexthops so I don't think this function is even needed
anymore.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
2ed74b933d lib: Update nexthop_same to use nexthop_cmp
Simplify the code a bit by making nexthop_same()
just use nexthop_cmp() internally.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
ff0e16daf9 lib: Add labels_cmp to nexthop_cmp
Add labels comparison to nexthop_cmp() as well.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
f932ce865f lib: nexthop-cmp return if gateways don't match
Fix the cmp check the so that it returns the result
if the gateways don't match.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
89dc316029 lib: Make labels_match function use labels_cmp
Update the nexthop_labels_match() function to use
nexthop_labels_cmp().

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Stephen Worley
ebc403dda5 lib: Add nexthop labels cmp functions
Add a function to compare nexthop labels.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Donald Sharp
776c3e90c1 lib: Add nexthop_cmp
Add function to allow us to have a sorted order
of nexthops.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-23 12:21:15 -04:00
Renato Westphal
81fddbe7ae *: rename new ForEach macros from the typesafe API
This is necessary to avoid a name collision with std::for_each
from C++.

Fixes the compilation of the gRPC northbound module.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-05-21 15:59:08 -03:00
Renato Westphal
eea3c899cd lib: add missing extern "C" {} blocks to new headers
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-05-21 15:56:18 -03:00
David Lamparter
791ac7c7e7 Revert "lib: Make _find functions treat the head as const"
This reverts commit 98d28ef55d.

No longer needed with previous commit.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:42:13 +02:00
David Lamparter
3b18b6c03d lib/table: remove nonsensical const, add pure
Passing the struct route_table *ptr as const doesn't really help; if
anything it semantically would imply that the returned route_node is
const too since constness should propagate (but it doesn't in C.)

The right thing to do here - which actually helps the compiler optimize
the code too - is to tag functions with __attribute__((pure)).  The
compiler does this automatically if it has the function body (and the
body of all called functions) available.  That should cover most "static
inline" functions in headers, as well as functions in the same file.

However, this doesn't work (at least without LTO) for extern functions.
Hence, add "ext_pure" for this case.  (Built-in "extern" to make lines
shorter.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:42:13 +02:00
David Lamparter
0734f93b8e lib/table: remove odd casts
Working with a proper struct route_node gets us around a bunch of weird
casts here and makes the code slightly more robust.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:42:13 +02:00
David Lamparter
9680a2af1c lib: add missing atomlist_init/fini
Only noticed this when trying to add atomlists to the typesafe
datastructure tests...  the atomic-specific test_atomlist doesn't use
init/fini :/

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:42:13 +02:00
David Lamparter
5cb4277dfe lib: add DECLARE_HEAP datastructure
This is an 8-ary heap (cacheline optimized.)  It works as a semi-sorted
kind of middle ground between unsorted and sorted datastructures;  pop()
always returns the lowest item but ordering is only loosely enforced.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:42:13 +02:00
David Lamparter
fdad523b54 lib: add DECLARE_DLIST (double-linked list)
Turns out we need one of these.  Same API as DECLARE_LIST, but deleting
random items is much faster.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:18:16 +02:00
David Lamparter
01734da376 lib: add dedicated pop() to DECLARE_SKIPLIST
The skiplist code was previously falling back to the del() code path for
a pop() on a skiplist.  This is unneeded complexity, a pop() can be done
more efficiently.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-05-21 05:18:16 +02:00
Quentin Young
303b93cdee zebra: update zebra_rib for vrrp
VRRP doesn't install any routes, but should still have an array entry.
Also add a help string for VRRP to route_types.txt

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
4f576e7575 lib, vrrpd: define & use ZEBRA_ROUTE_VRRP
Allow Zebra to know our protocol name.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
2fff50ec01 vrrpd, lib: style fixes
Fixup:
* Blank lines after declarations
* Trailing whitespace
* Braces and parentheses

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
e91c9247eb lib: add more convenient boolean adder for json
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
f828842a69 vrrpd: add support for configuration writing
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
53e60e5c58 vrrpd: autoconfig support
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
c3bd894e4d vrrpd: protodown macvlan in backup state
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
4f838de420 lib: add sizing macro to ipaddr.h
Useful for getting the size of the relevant data in the `ip` field of
struct ipaddr.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
667179cae4 lib: add function to get iface link-local
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
17b48d7d11 lib: add internet checksum with pseudoheaders
Add convenience functions to compute the Internet checksum of a data
block, including a pseudoheader.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
dad18a2fd7 vrrpd: add initial macvlan support
* Search for macvlan interfaces with the appropriate name and MAC
  address when starting up a new VRRP instance
* Split VRRP socket into two; one for Tx, one for Rx
* Bind Tx socket to the macvlan subinterface so our VRRP advertisements
  go out with the correct MAC address
* Send ARP requests from this macvlan subinterface
* Improve error messaging

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
862f2f374f vrrpd: ipv6 support
Add initial support for IPv6.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Quentin Young
4440e3cdf7 lib: add list_to_array
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-17 00:27:08 +00:00
Mark Stapp
4ce7e912ce
Merge pull request #4352 from donaldsharp/routemap_fix_replace
lib: Fix gcc 9.1 and --enable-werror issues found
2019-05-16 11:01:20 -04:00
Russ White
ace430f0db
Merge pull request #4144 from pguibert6WIND/bfd_cbit
BFD CBIT
2019-05-16 10:13:26 -04:00
Russ White
6f33cbff18
Merge pull request #4340 from qlyoung/hash-key-const
lib: hashing functions should take const arguments
2019-05-16 10:00:55 -04:00
Donald Sharp
4255dbe9bb lib: Fix gcc 9.1 and --enable-werror issues found
Compiling FRR w/ gcc 9.1 and --enable-werror generates some
issues that need to be cleaned up.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-16 09:20:12 -04:00
saravanank
9b68e49604 lib: implement utility function API which does the following
1. listnode_add_sort_nodup - This API adds to list only if no duplicate
    element available in the list. returns true/false
2. list_filter_out_nodes - This API deletes the nodes which satisfy the given
    condition. condition is passed as a func ptr in
    API. This function takes in node data(void ptr).

Signed-off-by: Saravanan K <saravanank@vmware.com>
2019-05-14 21:40:50 -07:00
Quentin Young
d8b87afe7c lib: hashing functions should take const arguments
It doesn't make much sense for a hash function to modify its argument,
so const the hash input.

BGP does it in a couple places, those cast away the const. Not great but
not any worse than it was.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-14 21:23:08 +00:00
Stephen Worley
b26f891dca lib,bgpd,pbrd: Add AFI_UNSPEC to AFI enum
Add an upspecified option to the AFI enum and update
switch statements using it in bgpd and pbrd.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-14 12:19:12 -07:00
Philippe Guibert
dcffea6912 bgpd: add vty command to enable bfd control-plane-check-failure
new vty command is added:
neighbor XXX bfd check-control-plane-failure

this command will enforce the check of bgp controlplane, when bfd
detects changes in the dataplane.
- at configuration, the cbit will be set if that command is executed
- at flapping time, if the command is configured and remote cbit is set
  accordingly, then the bfd event will be ignored.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-14 16:49:49 +02:00
Philippe Guibert
9beff0bda9 bfdd, lib, bgpd: add bfd cbit usage
bfd cbit is a value carried out in bfd messages, that permit to keep or
not, the independence between control plane and dataplane. In other
words, while most of the cases plan to flush entries, when bfd goes
down, there are some cases where that bfd event should be ignored. this
is the case with non stop forwarding mechanisms where entries may be
kept. this is the case for BGP, when graceful restart capability is
used. If BFD event down happens, and bgp is in graceful restart mode, it
is wished to ignore the BFD event while waiting for the remote router to
restart.
The changes take into account the following:
- add a config flag across zebra layer so that daemon can set or not the
  cbit capability.
- ability for daemons to read the remote bfd capability associated to a bfd
  notification.
- in bfdd, according to the value, the cbit value is set
- in bfdd, the received value is retrived and stored in the bfd session
  context.
- by default, the local cbit announced to remote is set to 1 while
  preservation of the local path is not set.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-14 16:49:49 +02:00
David Lamparter
0396d40631
Merge pull request #4304 from donaldsharp/route_map_switch
Route map switch
2019-05-14 15:29:58 +02:00
Rafael Zalamena
5fd270a114
Merge pull request #4112 from pguibert6WIND/bfd_vrf
support for BFD VRF
2019-05-14 10:24:56 -03:00
Stephen Worley
5208931b32 lib: Add const to openbsd-tree functions
A few of the functions in openbsd's RB tree implementation
needed to have const in their parameters.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-05-13 17:21:22 -07:00
Renato Westphal
8d0d863754 lib: fix crash in the CLI grammar sandbox
The CLI grammer sandbox needs to initialize the northbound subsystem
otherwise the running_config global variable won't be set, which
leads to crashes.

Fixes #4319.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-05-13 15:18:57 -03:00
Donald Sharp
097b5973d3 bgpd, lib, ospf6d, ospfd, pimd, zebra: Rework routemap event callback
The route_map_event_hook callback was passing the `route_map_event_t`
to each individual interested party.  No-one is ever using this data
so let's cut to the chase a bit and remove the pass through of data.
This is considered ok in that the routemap.c code came this way
originally and after 15+ years no-one is using this functionality.
Nor do I see any `easy` way to do anything useful with this data.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-10 18:43:21 -04:00
Donald Sharp
ba1707ca54 lib: in routemap.c if using a switch for an enum get rid of enum
From looking at a current PR: #4297, we see that routemap.c code
was not properly updating dependency information for some
route_map_event_t enum types.  This has lead to dependancy
information not being updated properly.  While at this time
I do not know whether or not we need to update the switch
for the missing types, I do know that if we add something in
the future we should make the person adding the code consider
this.  So let's remove all `default:` switch statement handlers
from routemap.c when switching on an enum.  Future time will
need to be spent to figure out what is needed to be done here.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-10 18:33:22 -04:00
Quentin Young
5dbb0a7b2a build: fix Lua build
Each of Lua's major versions are incompatible with each other. Ubuntu,
at least, does not provide a single liblua.so or /usr/include/lua; all
SOs and headers are versioned, e.g. liblua5.3.so and
/usr/include/lua5.3. There's already an m4 macro in the GNU collection
to handle this situation, so let's use that.

This allows building with Lua enabled to work on platforms other than
Fedora.

* Move lib/lua.[ch] -> lib/frrlua.[ch] to prevent path conflicts
* Fix configure.ac search for proper CPP and linker flags
* Add Lua include path to AM_CPPFLAGS
* Update vtysh/extract.pl.in

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-10 16:08:32 +00:00
Donald Sharp
c85711a8c9
Merge pull request #4297 from vishaldhingra/rmap
lib : Child rmap not sending an update to parent rmap,if there is an update in child rmap.
2019-05-10 09:04:59 -04:00
Renato Westphal
773fc72b1f
Merge pull request #4242 from donaldsharp/zebra_diet
Zebra diet
2019-05-10 08:29:59 -03:00
Donald Sharp
900193b022
Merge pull request #4287 from NaveenThanikachalam/dup_config_processing
lib, bgpd: Disallow processing of duplicate config.
2019-05-09 18:36:50 -04:00
Naveen Thanikachalam
6c3247bd2a lib, bgpd: Disallow processing of duplicate config.
This fix aims to reduce the load on BGPD when certain
exisiting configurations are replayed.
Specifically, the fix prevents BGPD from processing
routes when the following already existing configurations
are replayed:
1) A match criteria is configured within a route-map.
2) When "call" is invoked within a route-map.
3) When a route-map is tied to a BGP neighbor.

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
2019-05-08 21:22:23 -07:00
vishaldhingra
5ed2e47bbd lib : Child rmap not sending an update to parent rmap,if there is an update in child rmap.
Route map library creates a hash table to save the dependency binding.
route-map LRM permit 1
call rLRM
Whenever there is change in child routemap(rLRM), it tries to
find the dependency mapping with the child route map MATCH event
and it fails.The handing of match add and match delete was missing
to get the correct dependency,here it's LRM.
This fix would correct the flow to get the correct dependency.

Signed-off-by: vishaldhingra <vdhingra@vmware.com>
2019-05-08 20:59:15 -07:00
Dinesh Dutt
dc1c13c019 lib, vtysh: Make archaic "terminal" optional in configure command
The 'configure terminal' command is a bit redundant, so make
the terminal portion optional.

Signed-off-by: Dinesh Dutt <dd.ps4u@gmail.com>
2019-05-07 21:06:00 -04:00
Renato Westphal
51844abda2
Merge pull request #4280 from qlyoung/remove-yang-strreplace-func
lib: remove str_replace function
2019-05-07 18:52:16 -03:00
Quentin Young
6915af74fd
Merge pull request #4082 from opensourcerouting/grpc-nb-plugin
gRPC northbound plugin
2019-05-07 16:53:17 -04:00
Quentin Young
f9ce1142c3 lib: remove str_replace function
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-07 18:15:28 +00:00
Lou Berger
9dc90e2565
Merge pull request #4270 from opensourcerouting/libyang-compat
lib, yang: disable libyang custom user types temporarily
2019-05-07 11:07:39 -04:00
Philippe Guibert
0945d5ed01 bgp, ospfd, ospf6d, pimd, lib, isisd: add bfd_client_sendmsg vrf_id
vrf_id parameter is added to the api of bfd_client_sendmsg().
this permits being registered to bfd from a separate vrf.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:53:07 +02:00
Philippe Guibert
91f854f62a lib: perform a bind inside vrf_socket() call
This is an extension to previous behavior, where the bind() operation
was performed only when vrf was not a netns backend kind. This was done
like that because usually the bind parameter is the vrf name itself, and
having an interface name with vrf name is an expectation so that the
bind operation works.
the bind() operation can be performed on whatever device provided that
that name is not null and there is an interface in the vrf that has the
same name as the parameter.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-05-07 15:49:39 +02:00
Renato Westphal
d2dad0ef49
Merge pull request #4268 from qlyoung/frrstr-replace
lib: add string replace function
2019-05-06 23:14:38 -03:00
Renato Westphal
1b8de275c8 lib, yang: disable libyang custom user types temporarily
libyang 1.0 introduced a few changes in the user types API, and
these changes made FRR incompatible with libyang 1.x. In order to
ease our migration from libyang 0.x to libyang 1.x, let's disable
our libyang custom user types temporarily so that FRR can work
with both libyang 0.x and libyang 1.x. This should be especially
helpful to the CI systems during the transition. Once the migration
to libyang 1.x is complete, this commit will be reverted.

Disabling our libyang custom user types should have only
minimal performance implications when processing configuration
transactions. The user types infrastructure should be more important
in the future to perform canonization of YANG data values when
necessary.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-05-06 22:07:18 -03:00
Quentin Young
ed1809c925 lib: add string replace function
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-06 22:38:10 +00:00
Renato Westphal
61bb5ca6e0
Merge pull request #4253 from qlyoung/zapi-handler-args-macro
ZAPI callback args macro
2019-05-06 17:50:41 -03:00
Quentin Young
121f9dee7c *: use ZAPI_CALLBACK_ARGS macro for zapi handlers
This macro:
- Marks ZAPI callbacks for readability
- Standardizes argument names
- Makes it simple to add ZAPI arguments in the future
- Ensures proper types
- Looks better
- Shortens function declarations

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-03 20:57:35 +00:00
Quentin Young
6c33ca975a lib: define ZAPI_CALLBACK_ARGS macro
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-03 19:47:31 +00:00
Donald Sharp
48e5512c01 lib: Remove functionally dead code.
The vrf_with_default_name vrf variable is set to NULL
and then tested to see if it is valid.  Removing the
dead code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-03 05:05:19 -04:00
Donald Sharp
66355cf9eb lib: Convert table code to use new hash type
This converts the new table code to use the new hash
type provided by David.

The following test is 1 million routes installed and how
much memory we are using:

Old mem usage:
Memory statistics for zebra:
System allocator statistics:
  Total heap allocated:  574 MiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  536 MiB
  Free small blocks:     33 MiB
  Free ordinary blocks:  4600 KiB
  Ordinary blocks:       0
  Small blocks:          0
  Holding blocks:        0

New Memory usage:
Memory statistics for zebra:
System allocator statistics:
  Total heap allocated:  542 MiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  506 MiB
  Free small blocks:     3374 KiB
  Free ordinary blocks:  33 MiB
  Ordinary blocks:       0
  Small blocks:          0
  Holding blocks:        0

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-02 16:21:38 -04:00
Donald Sharp
62b4b3b68d lib: Make prefix_hash_key accept a const
We should not be modifying the pointer for the prefix_hash_key
function, make it a const so that we can use it elsewhere.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-02 16:21:38 -04:00
Donald Sharp
98d28ef55d lib: Make _find functions treat the head as const
The head of a list should not change for find functions.  Probably
are others that should be considered but these changes can come
in as needed I believe.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-02 16:21:38 -04:00
Donald Sharp
5e76ce5069
Revert "bgpd: Prevent IPv6 routes received via a ibgp session with own ip as nexthop " 2019-05-02 07:15:39 -04:00
Lou Berger
e8b9ad5cdd
Revert "Zebra diet" 2019-05-02 06:54:59 -04:00
Donald Sharp
0103534f9c lib: Convert table code to use new hash type
This converts the new table code to use the new hash
type provided by David.

The following test is 1 million routes installed and how
much memory we are using:

Old mem usage:
Memory statistics for zebra:
System allocator statistics:
  Total heap allocated:  574 MiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  536 MiB
  Free small blocks:     33 MiB
  Free ordinary blocks:  4600 KiB
  Ordinary blocks:       0
  Small blocks:          0
  Holding blocks:        0

New Memory usage:
Memory statistics for zebra:
System allocator statistics:
  Total heap allocated:  542 MiB
  Holding block headers: 0 bytes
  Used small blocks:     0 bytes
  Used ordinary blocks:  506 MiB
  Free small blocks:     3374 KiB
  Free ordinary blocks:  33 MiB
  Ordinary blocks:       0
  Small blocks:          0
  Holding blocks:        0

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-01 20:44:23 -04:00
Donald Sharp
6701b1b7e7 lib: Make prefix_hash_key accept a const
We should not be modifying the pointer for the prefix_hash_key
function, make it a const so that we can use it elsewhere.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-01 20:28:57 -04:00
Donald Sharp
a07f484614 lib: Make _find functions treat the head as const
The head of a list should not change for find functions.  Probably
are others that should be considered but these changes can come
in as needed I believe.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-01 20:28:57 -04:00
Russ White
f4b4d16123
Merge pull request #4192 from bisdhdh/biswajitfrr_4
bgpd: Prevent IPv6 routes received via a ibgp session with own ip as nexthop
2019-05-01 18:12:07 -04:00
Lou Berger
31e944a8a7
Merge pull request #3045 from opensourcerouting/atoms
READY: lists/skiplists/rb-trees new API & sequence lock & atomic lists
2019-04-30 10:26:35 -04:00
David Lamparter
8390828dac Revert "lib: use DECLARE_SKIPLIST for timers instead of pqueue"
This reverts commit 7c198e4e1a.
2019-04-29 21:18:55 +02:00
David Lamparter
7629b6b79c Revert "lib: remove pqueue_*"
This reverts commit 798ac49d06.
2019-04-29 21:18:48 +02:00
David Lamparter
9f9e9ef825
Merge pull request #4159 from sworleys/WQ-ErrFunc-Fix
lib: Fix workqueue error function callback
2019-04-28 16:19:55 +02:00
David Lamparter
a297301e89 lib: remove fifo implementation 2019-04-27 19:33:45 +02:00
David Lamparter
798ac49d06 lib: remove pqueue_*
All users of the pqueue_* implementations have been migrated to use
TYPEDSKIP_* skiplists.  Remove.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-27 19:33:45 +02:00
David Lamparter
7c198e4e1a lib: use DECLARE_SKIPLIST for timers instead of pqueue
Replaces the use of pqueue_* for the thread_master's timer list with an
instance of DECLARE_SKIPLIST_*.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-27 19:33:45 +02:00
David Lamparter
c284542b66 lib: use DECLARE_LIST for thread_list
Replaces the open-coded thread_list with a DECLARE_LIST instantiation.
Some function prototypes are actually identical to what was previously
open-coded.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-27 19:33:45 +02:00
David Lamparter
679b1649cb lib: use DECLARE_HASH for qobj hash
This changes the qobj node ID hash to use the new typed hash instead of
the old hash_* code.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-27 19:33:45 +02:00
David Lamparter
bcea0c0fde lib: atomlist & atomsort
These two are lock-free linked list implementations, the plain one is
primarily intended for queues while the sorted one is for general data
storage.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-27 19:33:39 +02:00
David Lamparter
80911bc26a lib: typesafe rb-tree
Typesafe red-black tree, built out of the OpenBSD implementation and the
macro soup layered on top.  API compatible with skiplists & simple
lists.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-04-27 18:22:38 +02:00
David Lamparter
abd71baa2e lib: typesafe lists, skiplist & hash
By the power of the C preprocessor, these macros provide type-safe
warppers for simple lists, skiplists and hash tables.  Also, by changing
the instantiation macro, it is easily possible to switch between
algorithms;  the code itself does not need to be changed since the API
is identical across all algorithms.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-04-27 18:20:35 +02:00
Renato Westphal
ec2ac5f28a lib: add new gRPC-based northbound plugin
This is an experimental plugin for now. Full documentation will
come later.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-26 18:15:32 -03:00
Renato Westphal
83981138fe lib: introduce a read-write lock for northbound configurations
The upcoming gRPC-based northbound plugin will run on a separate
pthread, and it will need to have access to the running configuration
global variable.  Introduce a rw-lock to control concurrent access
to the running configuration. Add the lock inside the "nb_config"
structure so that it can be used to protect candidate configurations
as well (this might be necessary depending on the threading scheme
of future northbound plugins).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-26 18:04:22 -03:00
Renato Westphal
364ad673c8 lib: add API to allow northbound clients to lock/unlock the running configuration
The ability to lock the running configuration to prevent other users
from changing it is a very important one. We already supported
the "configure exclusive" command but the lock was applied to
the CLI users only (other clients like ConfD could still commit
configuration transactions, ignoring the CLI lock). This commit
introduces a global lock for the running configuration that is
shared by all northbound clients, and provides a public API to
manipulate it. This way other northbound clients will also be able
to lock/unlock the running configuration if required (the upcoming
gRPC northbound plugin will have RPCs for that).

NOTE: this is a management-level lock for the running configuration,
not to be confused with low-level locks used to avoid data races.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-26 18:04:22 -03:00
Biswajit Sadhu
2f6197b044 bgpd: Prevent IPv6 routes received via a ibgp session with own ip as nexthop
Prevent IPv6 routes received via a ibgp session with one of its own interface
ip as nexthop from getting installed in the BGP table.

Implemented IPV6 HASH table, where we need to add any ipv6 address as they
gets configured and delete them from the HASH table as the ipv6 addresses
get unconfigured. The above hash table is used to verify if any route learned
via BGP has nexthop which is equal to one of its its connected ipv6 interface.

Signed-off-by: Biswajit Sadhu sadhub@vmware.com
2019-04-24 00:40:01 -07:00
Donald Sharp
c1f0465a3d
Merge pull request #4162 from opensourcerouting/rip-issues
ripd, ripngd: fix cleaning up of offset lists
2019-04-23 08:34:47 -04:00
Mark Stapp
75839aabb8 lib: fix warning in linklist api
Add return value and comment to new/recent linklist api
to clean up compile warning.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-04-22 15:49:16 -04:00
Donald Sharp
8f19bc1c69
Merge pull request #3786 from mjstapp/dplane_intf
zebra: async interface address programming
2019-04-22 15:29:02 -04:00
Quentin Young
0b4f815088
Merge pull request #4161 from opensourcerouting/nb-performance
lib: rework management of user pointers in the northbound layer
2019-04-22 15:10:34 -04:00
Mark Stapp
6339042cb9 libs: use const in some interface flag accessors
Use const in several interface struct flag accessors (that just
test flags.)

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-04-22 13:49:27 -04:00
Jafar Al-Gharaibeh
c6f637132f
Merge pull request #4025 from AnuradhaKaruppiah/pim-evpn
pim-evpn: Forwarding overlay BUM traffic via multicast VxLAN tunnels in the underlay
2019-04-22 11:44:52 -05:00
Mark Stapp
8875d0515e libs: control privs changes with refcount
Use a refcount to control privs changes. Support process-wide
privs apis, as well as per-pthread apis.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-04-22 09:32:41 -04:00
Anuradha Karuppiah
fef327404f lib: two extra bytes were being allocated for the SG string
Fixup in response to Jafar's review comments.

This is actually old code moved in from pimd to lib. But the fixup does
make sense.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-21 07:24:20 -07:00
Anuradha Karuppiah
4ab3321f29 lib, zebra: changes to propagate vxlan mcast SG entries to pimd
These updates act as triggers to pimd to -
1. join the MDT for rxing VxLAN encapsulated BUM traffic
2. register the local-vtep-ip as a source for the MDT

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-20 08:33:20 -07:00
Anuradha Karuppiah
315999e9b4 lib: return listnode on add for subsequent efficent del
Having to lookup the DLL node to delete it defeats one purpose of using
DLLs.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-20 08:33:20 -07:00
Anuradha Karuppiah
c6b6b53b29 lib: move SG prefix2str APIs from pimd to lib
This is to allow zebra to use these APIs instead of re-defining.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-20 08:33:20 -07:00
Anuradha Karuppiah
833b8a504a bgpd: suppress IMET route generation if flood mode is PIM-SM
IMET route is optional if the flood mode is PIM-SM and serves
no functional purpose. So this change limits type-3 route generation
to flood-mode=head-end-replication.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-20 08:33:20 -07:00
Renato Westphal
cbcbac4578 ripd: unlink if-rmap container from global list before removing it
This solves a crash that happens if the "route-map" command is used
after "router rip" + "no router rip" + "router rip".

Once interface route-maps are converted to the new northbound model,
we'll be able to remove the if_rmap_ctx_list global list (which is
an ugly hack to make things work right now).

Bug found by the CLI fuzzer.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-19 16:54:29 -03:00
Don Slice
e47c4d3cfe zebra: stop sending invalid nexthops to clients
Found that zebra_rnh_apply_nht_rmap would set the
NEXTHOP_FLAG_ACTIVE if not blocked by the route-map, even
if the flag was not active prior to the check.  This fix
changes the flag used to denote the nexthop is filtered so
that proper active state can be retained. Additionally,
found two cases where we would send invalid nexthops via
send_client, which would also cause this crash.  All three
fixed in this commit.

Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2019-04-19 16:56:07 +00:00
Donald Sharp
dd50eeb115 lib, zebra: Remove unused flag
The NEXTHOP_FLAG_FILTERED went away when we started treating
static routes like every other route in the system.  This was
a special case for handling static route code that just didn't
get finished cleaning up.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-04-18 14:57:54 -04:00
Donald Sharp
454192f46f lib: Add a counter for number of nexthops
Add a ability to count the number of nexthops in a nexthop_group.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-04-18 14:17:44 -04:00
Renato Westphal
ec3ee0ebb8 lib: make nb_candidate_edit() more flexible
Certain operations, like removing non-presence containers or
modifying list keys, are not considered to be valid from the
perspective of the northbound layer. This is because we want to
implement a minimum set of northbound configuration callbacks and
use them to process all possible configuration changes.

The removal of a np-container [1], for example, can be processed by
calling the "delete" callback of all of its child nodes (recursion
is used for np-container child nodes). Similarly, the modification
of a list key can be processed as if the corresponding list entry
was removed and readded with updated key values. This strategy saves
us the burden of implementing lots of extra configuration callbacks.

That said, the nb_operation_is_valid() function shouldn't be used
for anything other than checking which callbacks are valid for
which YANG nodes. Using it in the nb_candidate_edit() function
is inappropriate as we want as much flexibility as possible when
editing a candidate configuration. We should allow CLI commands,
for example, to remove np-containers (the northbound layer will then
figure out which callbacks need to be called when this candidate
is committed). Remove the check.

[1] We can't do the same for presence containers since they have a
"create" callback associated with them.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18 13:15:13 -03:00
Renato Westphal
c650e48c54 lib: introduce flog() to simplify the northbound code a little bit
flog() is a small wrapper around zlog() that can be useful in a
few places to reduce code duplication.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18 13:17:54 -03:00
Renato Westphal
e412d3b8d9 lib: move zlog() prototype back to the public logging API
zlog() should be part of the public logging API as it's useful in
the cases where the logging priority isn't known at compile time
(i.e. it depends on a variable).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18 13:15:13 -03:00
Renato Westphal
1ae9686cdf lib: don't initialize the northbound database in the unit tests
Move call to nb_db_init() from nb_init() to frr_init() so that only
the FRR daemons will initialize the northbound database. This should
fix a few warnings when running some unit tests.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18 13:06:14 -03:00
Renato Westphal
de4eaa3c55 lib: sync sysrepo module with latest API changes
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18 13:06:14 -03:00
Renato Westphal
ccd43ada17 lib: rework management of user pointers in the northbound layer
Introduce a hash table to keep track of user pointers associated
to configuration entries. The previous strategy was to embed
the user pointers inside libyang data nodes, but this solution
incurred a substantial performance overhead. The user pointers
embedded in candidate configurations could be lost while the
configuration was being edited, so they needed to be regenerated
before the candidate could be committed.  This was done by the
nb_candidate_restore_priv_pointers() function, which was extremely
expensive for large configurations. The new hash table solves this
performance problem.

The yang_dnode_[gs]et_entry() functions were renamed and moved from
yang.[ch] to northbound.[ch], which is a more appropriate place
for them. This patch also introduces the nb_running_unset_entry()
function, the counterpart of nb_running_set_entry() (unsetting
user pointers was done automatically before, now it needs to be
done manually).

As a consequence of these changes, we shouldn't need support for
libyang private pointers anymore (-DENABLE_LYD_PRIV=ON). But it's
probably a good idea to keep requiring this feature as we might
need it in the future for other things (e.g. disable configuration
settings without removing them).

Fixes #4136.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18 11:56:45 -03:00
David Lamparter
7e3a1ec742 lib: ZEBRA_NUM_OF -> array_size
The latter is widely used, e.g. in the Linux kernel.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-18 12:44:29 +02:00
David Lamparter
0d019561bd lib: move/redo some macros
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-18 12:44:29 +02:00
David Lamparter
440d5faa3a lib: add "seqlock" wait/broadcast primitive
Manually tested rather extensively in addition to included unit tests,
should work as intended.

NB: The OpenBSD futex() code is "future"; it's not actually in OpenBSD
(yet?) and thus untested.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-04-18 12:44:29 +02:00
David Lamparter
4cab68a20d lib: add cmpxchg_strong to frratomic.h
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-04-18 12:44:29 +02:00
Stephen Worley
095e181928 lib: Fix workqueue error function callback
After exceeding the max retry number for a thread,
we were passing the data rather than the work_queue_item
struct.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-04-17 19:29:05 -04:00
Russ White
fe586c647b Merge pull request #4084 from qlyoung/bgp-prefix-md5-auth
Support TCP MD5 auth on prefixes & enable MD5 auth for BGP listen ranges
2019-04-16 19:25:43 -04:00
Mark Stapp
ce3c7c2f78
Merge pull request #4132 from opensourcerouting/northbound-debug
lib: add fine-grained debugging in the northbound
2019-04-16 12:01:09 -04:00
Quentin Young
b33e46666d lib: add support for extended TCP MD5 auth
MD5 auth on TCP is supported for prefixes in recent versions of Linux;
add complementary support for FRR.

This is a reworked version of Donald's commit to keep library
compatibility and obviate the need for changes in daemons that don't
need to support this themselves.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-04-16 15:26:20 +00:00
Renato Westphal
4a86cac885
Merge pull request #3720 from donaldsharp/bgp_vrf_peering
lib: Allow bgp to always create a listen socket for the vrf
2019-04-16 12:25:26 -03:00
Lou Berger
817489896f
Merge pull request #3762 from pguibert6WIND/do_not_alloc_lists_fs_by_def
bgpd: do not allocate lists on fs entries of bgp entries.
2019-04-16 11:24:48 -04:00
Renato Westphal
9eb2c0a1dc lib: add fine-grained debugging in the northbound
Split the "debug northbound" command into the following commands:
* debug northbound callbacks configuration
* debug northbound callbacks state
* debug northbound callbacks rpc
* debug northbound notifications
* debug northbound events
* debug northbound client confd
* debug northbound client sysrepo

If "debug northbound" is entered alone, all of its suboptions
are enabled.

This commit also adds code to debug state/rpc callbacks and
notifications (only configuration callbacks were logged before).

Use the debugging infrastructure from "lib/debug.h" in order to
benefit from its facilities (e.g. MT-safe debugging) and avoid
code duplication.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-15 15:59:38 -03:00
Renato Westphal
e0cade1bbc lib: fix inverted logic in the "debug all" command
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-15 12:53:54 -03:00
Quentin Young
e3659a9a72
Merge pull request #4102 from opensourcerouting/sendbuf_recvbuf_privs
*: setting the socket send/recv buffer sizes doesn't need elevated privs
2019-04-09 10:59:00 -04:00
Renato Westphal
338b8e914a *: setting the socket send/recv buffer sizes doesn't need elevated privs
The less code running under elevated privileges the better.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-08 13:11:28 -03:00
Donald Sharp
3393df5cf1 lib: Fixup IFF_OUT_LOG macro to make SA happy
The IFF_OUT_LOG macro is using BUFSIZE, which is the sizeof(logbuf)
but for some reason 8.0 clang SA is not happy with it.  Just
make it happy.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-04-06 20:10:52 -04:00
Stephen Worley
1b1fe1c409 lib: Add hash function for nexthop groups
Add a hash function to turn a nexthop group into a
32 bit unsigned hash key with jhash. We do not care to
hash any recursively resolved nexthops, just the group.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-04-05 14:19:44 -04:00
Donald Sharp
f61f266a0e
Merge pull request #3548 from opensourcerouting/rip-vrf
rip(ng)d: add VRF support
2019-04-04 19:24:14 -04:00
Quentin Young
0080f1f558
Merge pull request #4065 from mjstapp/fix_nexthop_compare
libs: nexthop comparison includes labels if present
2019-04-04 14:08:22 -04:00
Quentin Young
ab9bcaf4f8
Merge pull request #4080 from mjstapp/fix_nh_copy_const
libs: use const in copy_nexthops api
2019-04-04 13:52:01 -04:00
Renato Westphal
467c39ab04
Merge pull request #4074 from qlyoung/remove-event-counter
lib: remove event_counter.[ch]
2019-04-04 12:03:12 -03:00
Mark Stapp
deff170e8b libs: use const in copy_nexthops api
Use const for the source arg to copy_nexthops().

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-04-04 10:54:10 -04:00
Lou Berger
9ffa0d2404
Merge pull request #4072 from chiragshah6/evpn_dev2
lib,bgpd: do not register nexthop 0.0.0.0 to nht
2019-04-04 10:20:43 -04:00
Lou Berger
e9890df15d
Merge pull request #4073 from donaldsharp/undebug_me_or_not
some cleanup across multiple daemons
2019-04-04 10:08:34 -04:00
Donald Sharp
fa0069c647 lib, pbrd, zebra: Fix size_t type printf warnings on obscure platforms
Use the correct printf formater for those obscure platforms that
we build against.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-04-03 16:39:50 -04:00
Quentin Young
c17faa4b10 lib: reduce exported var symbols
Don't need these in our DSO tables

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-04-03 20:34:18 +00:00
Quentin Young
fe7f26ce76 lib: remove event_counter.[ch]
goodbye spooky code

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-04-03 20:18:08 +00:00
Chirag Shah
1eb6c3eae6 *: do not register nexthop 0.0.0.0 to nht
Avoid tracking 0.0.0.0/32 nexthop with RIB.

When routes are aggregated,
the originate of the route becomes self.
Do not track nexthop self (0.0.0.0) with rib.

Ticket: CM-24248
Testing Done:

Before fix-

tor-11# show ip nht vrf all

VRF blue:
0.0.0.0
 unresolved
 Client list: bgp(fd 16)

VRF default:

VRF green:

VRF magenta:
0.0.0.0
 unresolved
 Client list: bgp(fd 16)

After fix-

tor-11# show ip nht vrf all

VRF blue:

VRF default:

VRF green:

VRF magenta:

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2019-04-03 11:17:57 -07:00
Mark Stapp
55f93d4b0d libs: nexthop comparison includes labels if present
Adjust the nexthop comparison api so that it calls the label-
comparison api. Adjust the label-comp api so that "no labels"
is "equal".

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-04-03 04:25:21 -04:00
Renato Westphal
6a3fdeecf1 lib, ripd, ripngd: rename remaining delete northbound callbacks
PR #3622 renamed the "delete" northbound callback to "destroy" in
order to make the libfrr headers compatible with C++. This commit
renames a few functions that still use "delete" instead of "destroy"
in their names.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-03-29 11:32:33 -03:00
Renato Westphal
8f88441d71 Merge remote-tracking branch 'frr/master' into rip-vrf
Merge commit to solve a bunch of conflicts with other PRs that were
merged in the previous weeks.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-03-29 11:32:21 -03:00
Philippe Guibert
33bca8a151 lib: add listnode_add_force utility routine
that routine does the same as listnode_add; in addition it creates the
linked list if needed.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-03-29 15:04:49 +01:00
Philippe Guibert
2fe55afeec lib: add lookup utility routine that accepts null list values
lists passed as parameter that are null, are accepted by the function.
I would even propose to silently return NULL in official
listnode_lookup() routine.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-03-29 15:04:17 +01:00
Renato Westphal
add682b39b
Merge pull request #4014 from dslicenc/zclient-interface-add
lib: zclient provide interface info during reg_requests
2019-03-29 10:04:30 -03:00
Don Slice
eeb2dfa3af lib: zclient provide interface info during reg_requests
Problem found in bgpd where it wasn't learning interface address
information at startup due to the interface information becoming
available before the bgp instance was created. This issue was
caused by an earlier change that tried to make the interface
information discovery process more efficient but left this hole
for bgpd. For now, putting back in the previous method of
gathering interface info via the zclient_send_reg_requests call
and will revisit a more efficient way to get the info in the future.

Ticket: CM-23932
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2019-03-25 16:18:07 +00:00
Donald Sharp
cdc6ed9016 lib: Improve debugs in zclient.c
Fixup a couple of places to improve debugging of what is
going on in zclient.c.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-03-25 09:09:35 -04:00
Donald Sharp
4cf8bb327c lib: Fixup missing log entries
Add a few missing log entries to the macro to allow us to print
out the zapi message type, since they were missing.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-03-25 09:04:28 -04:00
Donald Sharp
c9146c85a0
Merge pull request #3772 from pguibert6WIND/vrf_backend_unknown
Vrf backend unknown
2019-03-25 08:13:16 -04:00
Donald Sharp
8d39ebf675
Merge pull request #3776 from opensourcerouting/pbrd-interface-nexthops
pbrd: add support for interface nexthops
2019-03-22 03:45:48 -04:00
Donald Sharp
6e0d7d0dbb
Merge pull request #3972 from mjstapp/fix_privs_race
libs: fix race in privs changes
2019-03-22 02:32:17 -04:00
Mark Stapp
064e2f3280 libs: fix race in privs changes
Use the privs struct mutex more strictly, to ensure that the
privs are at the level the caller expects when the apis
return.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-03-17 13:25:16 -04:00
Sri Mohana Singamsetty
61be0e35f2
Merge pull request #3949 from qlyoung/remove-zlog-newlines
*: remove trailing newlines from zlog messages
2019-03-15 10:27:54 -07:00
Donald Sharp
6e65fa2b6d
Merge pull request #3902 from opensourcerouting/fix-removal-np-containers
lib: fix removal of yang non-presence containers
2019-03-15 08:37:12 -04:00
Quentin Young
9165c5f5ff *: remove trailing newlines from zlog messages
Zlog puts its own newlines on, and doing this makes logs look nasty.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-03-14 18:41:15 +00:00
David Lamparter
cd92ac05f8
Merge pull request #3911 from mjstapp/fix_privs_deadlock
libs: make privilege elevation thread-safe
2019-03-06 15:58:20 +01:00
David Lamparter
d3b05897ed
Merge pull request #3869 from qlyoung/cocci-fixes
Assorted Coccinelle fixes
2019-03-06 15:54:44 +01:00
Mark Stapp
c5c44d4b41 libs: make privilege escalation thread-safe
Privs escalation is process-wide, and a multi-threaded process
can deadlock. This adds a mutex and a counter to the privs
object, preventing multiple threads from making the privs
escalation system call.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-03-05 11:08:31 -05:00
Renato Westphal
1912caa2ca lib: fix removal of yang non-presence containers
Non-presence containers don't have "destroy" callbacks. So, once
a np-container is deleted, we need to call the "destroy" callbacks
of its child nodes instead.

This commit doesn't fix any real problem as of now since all
np-containers from the FRR YANG modules contain or one more mandatory
child nodes, so they can't be deleted (libyang will add missing
np-containers when validating data). Nevertheless, upcoming YANG
modules should benefit from this change.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-03-02 20:01:49 -03:00
Renato Westphal
cacbffafc9 lib: simplify code that calculates configuration diffs
This is just a small refactoring to reduce code duplication. No
behavior changes intended.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-03-02 19:22:51 -03:00
Renato Westphal
fe39eb421e
Merge pull request #3877 from qlyoung/remove-strncpy
Remove strncpy
2019-03-01 17:06:29 -03:00
Sri Mohana Singamsetty
29da198289
Merge pull request #3882 from vivek-cumulus/refine_evpn_route_add
Refine install of EVPN-based routes to remove some special handling
2019-03-01 09:15:26 -08:00
Donald Sharp
1c62852030
Merge pull request #3606 from pguibert6WIND/if_rmap_container
lib, rip, ripng, eigrp: rework if_rmap context
2019-03-01 09:46:22 -05:00
vivek
2b83602b24 *: Explicitly mark nexthop of EVPN-sourced routes as onlink
In the case of EVPN symmetric routing, the tenant VRF is associated with
a VNI that is used for routing and commonly referred to as the L3 VNI or
VRF VNI. Corresponding to this VNI is a VLAN and its associated L3 (IP)
interface (SVI). Overlay next hops (i.e., next hops for routes in the
tenant VRF) are reachable over this interface. Howver, in the model that
is supported in the implementation and commonly deployed, there is no
explicit Overlay IP address associated with the next hop in the tenant
VRF; the underlay IP is used if (since) the forwarding plane requires
a next hop IP. Therefore, the next hop has to be explicit flagged as
onlink to cause any next hop reachability checks in the forwarding plane
to be skipped.

https://tools.ietf.org/html/draft-ietf-bess-evpn-prefix-advertisement
section 4.4 provides additional description of the above constructs.

Use existing mechanism to specify the nexthops as onlink when installing
these routes from bgpd to zebra and get rid of a special flag that was
introduced for EVPN-sourced routes. Also, use the onlink flag during next
hop validation in zebra and eliminate other special checks.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
2019-02-27 12:54:24 +00:00
Quentin Young
aab9a0a0cb lib: strncpy -> strlcpy | memcpy
strncpy is a byte copy function not a string copy function

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-26 20:50:17 +00:00
Quentin Young
9f5dc3192e *: remove casts of XMALLOC / XCALLOC
No cast necessary for void *

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:46 +00:00
Quentin Young
0a22ddfbb1 *: remove null check before XFREE
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:46 +00:00
Quentin Young
1383ff9c51 lib: STAILQ_FOREACH_SAFE never gives a null elem
So don't check it

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:46 +00:00
Quentin Young
76f0146890 *: do not check XMALLOC / XCALLOC for null ret
They never return NULL

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:44 +00:00
Quentin Young
97b5d752d7 *: use array_size instead of raw division
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:16 +00:00
Quentin Young
5b94ec5024 *: remove unnecessary semicolon from switches
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:16 +00:00
Quentin Young
b08047f82d *: return bool from boolean functions
Not 1 or 0.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:16 +00:00
Quentin Young
d8729f8cb5 *: use proper bool initializers & fix comparisons
- bools should be initialized with true/false
- bools do not need to be compared

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:16 +00:00
Quentin Young
0026ac15ab lib: add compatibility #define for hash_backet
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 17:08:45 +00:00
Tim Bray
e3b78da875 *: Rename backet to bucket
Presume typo from original author

Signed-off-by: Tim Bray <tim@kooky.org>
2019-02-25 16:22:36 +00:00
Donald Sharp
5fa3430885
Merge pull request #3836 from opensourcerouting/debian/master-kill-backports
[master] debian packaging
2019-02-23 18:23:21 -05:00
Donald Sharp
7f9adc7c67 lib: Allow DEFPY_HIDDEN to exist in vtysh
The DEFPY_HIDDEN commands were not being picked up
into vtysh.  Fix this issue.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-02-20 19:26:15 -05:00
David Lamparter
591f57cff3 lib: yang: use common yang_ctx_new_setup()
After creating a libyang context, we need to hook up our callback to use
embedded built-in modules.  I hadn't added this to the yang translator
code.

Also, ly_ctx_new fails if the search directory doesn't exist.  Since
that's not a hard error for us, work around that and ignore inaccessible
YANG_MODELS_DIR.  (This is needed for snap packages.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-19 21:41:39 +01:00
Philippe Guibert
aec0d75667 eigrp, rip, ripng, lib: unlink if_rmap from vrf
an interface rmap context can be created from a custom name string,
instead of a vrf. This ability permits to handle several instances of
interface route map in the same vrf. The naming convention will be
transparent on what the name is for in the daemon code.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-02-19 21:11:37 +01:00
Philippe Guibert
4b23867cad lib, rip, ripng, eigrp: rework if_rmap context
so as to handle ri/ripng/eigrp multiple instances, the need is to
encapsulate if_rmap hash table into a container context self to each
instance. This work then reviews the if_rmap api, mainly by adding a
if_rmap_ctx context, that is passed for each exchange between library
and the daemon.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-02-19 21:11:13 +01:00
Quentin Young
72de5f4b5d lib: fix garbage array size in zprivs_init
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-15 16:27:55 +00:00
Renato Westphal
7dce96f0e4 lib, pbrd: fix indentation of a few commands
When displaying the running configuration, we should use a single
space to indent commands when necessary (and not two spaces).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-14 22:57:39 -02:00
Renato Westphal
1c869b6418 lib: add support for interface nexthops on nexthop groups
This patch adds support to nexthops of type NEXTHOP_TYPE_IFINDEX to
nexthop-groups. This should be especially useful when dealing with
p2p interfaces like tunnels that don't have IP addresses assigned
to them.

NOTE: nh->addr can be NULL now, so we should always perform a null
check before dereferencing this pointer.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-14 22:57:39 -02:00
Renato Westphal
b43bb64f82 lib: change how nexthop groups store nexthop addresses
Use a pointer to a sockunion instead of a full sockunion in the
nexthop_hold structure. This prepares the ground for the next commit,
which will make nexthop addresses optional (in this commit we assume
nh->addr will never be NULL, but this will change).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-14 20:01:30 -02:00
Renato Westphal
e5a501c2ed lib: consolidate nexthop-group deletion in a single place
Reuse the nhgl_delete() function to avoid code duplication.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-14 20:00:14 -02:00
Quentin Young
1c77d034e5 lib: fix uninitialized value use in privs.c
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-14 19:01:33 +00:00
Renato Westphal
7f04943d6b lib: a few more trivial changes for C++ compatibility
* command_graph.h: stop using "new" as a parameter name as that's a
  reserved C++ keyword.

* module.h: avoid using C99 designated initializers since C++ doesn't
  support them. This change hurts code readability quite considerably,
  so we should try to find a better solution later.

* pw.h: remove unneeded empty structure to silence a C++ warning.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11 22:34:12 -02:00
Renato Westphal
343cd13e17 lib: add macro that performs explicit static casts when using a C++ compiler
C++ doesn't support implicit casts from void pointers like C
does. And the libfrr headers have some bits of code that rely on
implicit casts in order to work. To solve this problem, add a new
"static_cast" macro that performs explicit static casts when a C++
compiler is being used, or do nothing otherwise.

NOTE: since macros are only evaluated when they are used, there
might be other macros from libfrr that will need to use "static_cast"
as well. If a header is successfully compiled using a C++ compiler,
there's no guarantee that its macros are compatible with C++. We'll
only know about such macros when they are used by C++ code, then
we'll need to adapt them one by one in the future.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11 22:34:12 -02:00
Renato Westphal
c139972c0f lib: rename enum to avoid conflict
Two different definitions of "enum filter_type" exist in libfrr:
one in lib/filter.h and other in lib/command_match.h. Rename one
of them to resolve a conflict that happens when both headers are
included by the same file.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11 22:34:12 -02:00
Renato Westphal
5e2444690b lib: add extern "C" {} blocks to all libfrr headers
These are necessary to use functions defined in these headers from C++.

Signed-off-by: David Lamparter <equinox@diac24.net>
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11 22:34:12 -02:00
David Lamparter
f8cd615bc4 lib: remove unnamed struct in qobj for C++
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11 15:49:49 -02:00
David Lamparter
f3dd45d108 lib: remove extra top-level ;
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11 15:49:49 -02:00
David Lamparter
c8a65463b2 lib: make atomic ops C++ compatible
C++ doesn't have ISO C11 stdatomic.h or "_Atomic inttype", so use
std::atomic instead to get the headers compatible.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11 15:49:49 -02:00
David Lamparter
be566e4e45 lib: make union prefixptr C++-compatible
Add a no-op conversion constructor to tell C++ that union prefixptr
accepts any of its member types.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11 15:49:49 -02:00
David Lamparter
cd2d58525e lib: revert table.h change for C++
This reverts the lib/table.h change from commit
049b31f7d810fd70069e3edbbd3fea6b5c7af98f.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11 15:49:49 -02:00
Mark Stapp
95ce849b58 libs, rip, isis: change northbound operation enum to DESTROY
Change the northbound lib operation from DELETE to DESTROY;
make the required changes in the users of the northbound, in
the cli, rip, ripng, and isis.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-02-11 15:49:49 -02:00
Mark Stapp
d01b92fd75 libs, daemons: changes to permit c++ compilation
Some misc changes to resolve some c++ compilation errors.
The goal is only to permit an external module - a plugin,
for example - to see frr headers, not to support or encourage
contributions in c++. The changes include: avoiding use
of keywords like 'new', 'delete'; cleaning up implicit
type-casting from 'void *' in several places.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-02-11 15:49:49 -02:00
Philippe Guibert
b0b97a7f61 lib: handling vrf backend unknown case
on interface search algorithm, at initialisation, when reading config
file, the vrf backend may not be yet known ( because zebra did not sync
yet with daemon). For that, avoid searching interface name in a separate
vrf. This change of behaviour is induced because the assumption is done
that at config startup, the user is not wrong with the interface
configuration to use. Every usage of vrf_get_backend() should then be
wisely adapted in order to handle that init state.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-02-11 13:48:12 +01:00
Philippe Guibert
72261ecd22 lib: interface handling where zebra not yet ready
other daemons need to sync with zebra to get to know which vrf backend
is available. in that time, there may be interface configuration
available. in that specific case, the vrf backend returned is not known.
A specific return value is sent back. This will be useful to know which
specific algorithm to apply.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-02-11 13:47:04 +01:00
Donald Sharp
aef69c4fea
Merge pull request #3752 from mjstapp/fix_wq_static_func
libs: remove useless static work_queue_free helper
2019-02-07 17:24:06 -05:00
Russ White
1632290b3f
Merge pull request #3745 from chiragshah6/evpn_dev1
EVPN advertise svi ip as macip route changes via config command
2019-02-07 14:36:46 -05:00
Mark Stapp
6b097e3379 libs: remove useless static work_queue_free helper
Collapse the old static free function into the actual public
function that was using it (and the only user of it.)

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-02-07 13:54:50 -05:00
David Lamparter
e7f0060c12
Merge pull request #3744 from mjstapp/wq_deprecated_api
libs: remove deprecated workqueue api
2019-02-07 18:52:27 +01:00
Donald Sharp
ecc4d697cd lib: MTYPE_PREFIX_FLOWSPEC should not be exposed by memory.h
This MTYPE should be owned by prefix.c as a STATIC for the file.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-02-07 09:35:49 -05:00
Chirag Shah
fc08a52fee lib: advertise svi ip as macip opcode
This change is used to send configue changes for
advertise svi address as macip (type-2) route.

Ticket:CM-23782

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2019-02-06 19:57:00 -08:00
Mark Stapp
49f36252d6 libs: remove deprecated workqueue api
Remove deprecated api from workqueue module.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-02-06 14:13:21 -05:00
Emanuele Di Pascale
77d9c92609 lib: add hooks for external logging function
Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2019-02-05 20:55:04 +01:00
Donald Sharp
9f3a86d3e6
Merge pull request #3518 from rgirada/routemap_3090
libd: Implemented a cli "show route-map-unused" to track all unused rou…
2019-02-05 11:13:22 -05:00
Donald Sharp
22761baa25 lib: Send interface request after initial hello
Ask for all interface information after we have connected
to zebra and sent the initial hello.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-02-05 09:13:30 -05:00
Renato Westphal
3524352154
Merge pull request #3698 from donaldsharp/netlink_is_serious_business
Netlink is serious business
2019-02-05 11:52:33 -02:00
rgirada
4a2a09d03d lib: Implemented a cli "show route-map-unsed" to track all unsed routemaps.
Made the following changes.
1.Defined two apis in routemap-lib, one for increment and another for
  decrement the applied counter.
2.Added a  new configuration “show route-map-unused” to track all unused
  routemaps.
3.called the corresponding route map update api when a route map attached
  or detached from any redistribution list.

Signed-off-by: RajeshGirada <rgirada@vmware.com>
2019-02-04 05:04:23 -08:00
Donald Sharp
0556fc33c7 lib: Allow bgp to always create a listen socket for the vrf
If tcp_l3mdev_accept = 0, then creating a socket for a vrf
for communication is allowed.  On the other hand if it is =1
then the vrf_socket() code assumes that we have created
a listen socket in the default vrf.  This is a bad assumption
in that it is perfectly valid to create a bgp instance like this:

router bgp 99 vrf BLUE
   <configuration>
!

But not to create a default bgp instance.  As such when BGP
would call the vrf_socket to create the listener for that vrf
the code was dissallowing it.

This code is incorrect behavior.  If we are passing in a interface
to bind the socket to, it is not the correct behavior to just not
bind, especially if the interface passed in is not a vrf name.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-02-01 11:54:59 -05:00
Donald Sharp
e77cc2a97f lib: snprintf to strlcpy in frr_pthread.c
Convert to using strlcpy to erase those pesky little
gcc warnings->errors

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-31 07:52:23 -05:00
David Lamparter
fdbd8086b1 build: fix a whole bunch of *FLAGS
- some target_CFLAGS that needed to include AM_CFLAGS didn't do so
- libyang/sysrepo/sqlite3/confd CFLAGS + LIBS weren't used at all
- consistently use $(FOO_CFLAGS) instead of @FOO_CFLAGS@
- 2 dependencies were missing for clippy

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-01-30 19:13:51 +01:00
Donald Sharp
b0538fc8b7 lib, zebra: Fix 'show ip route' char collision
Apparently 'f' means both OpenFabric and a Failed kernel
route installation.

Let's switch the 'f' for the failed kernel route installation
to 'r - rejected route'.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-29 20:41:36 -05:00
Russ White
2538f1dad7
Merge pull request #3681 from donaldsharp/onlink
*: The onlink attribute should be owned by the nexthop not the route.
2019-01-29 10:09:44 -05:00
Russ White
6a7c546fca
Merge pull request #3616 from donaldsharp/route_notification
Route notification
2019-01-29 09:55:41 -05:00
Quentin Young
0ade23e575 lib: protect termtable from bad fmt string
Termtable can write out-of-bounds if given a format string with too many
column separators.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-01-28 20:44:20 +00:00
Donald Sharp
b539a22f5a
Merge pull request #3664 from opensourcerouting/yang-embed-extensions
yang: embed extensions
2019-01-28 10:38:56 -05:00
Donald Sharp
fe85601c96 *: The onlink attribute should be owned by the nexthop not the route.
The onlink attribute was being passed from upper level protocols
as an attribute of the route *not* the individual nexthop.  When
we pass this data to the kernel, we treat the onlink as a attribute
of the nexthop.  This commit modifies the code base to allow
us to pass the ONLINK attribute as an attribute of the nexthop.

This commit also fixes static routes that have multiple nexthops
some onlink and some not.

ip route 4.5.6.7/32 192.168.41.1 eveth1 onlink
ip route 4.5.6.7/32 192.168.42.2

S>* 4.5.6.7/32 [1/0] via 192.168.41.1, eveth1 onlink, 00:03:04
  *                  via 192.168.42.2, eveth2, 00:03:04

sharpd@robot ~/frr2> sudo ip netns exec EVA ip route show
4.5.6.7 proto 196 metric 20
	nexthop via 192.168.41.1 dev eveth1 weight 1 onlink
	nexthop via 192.168.42.2 dev eveth2 weight 1

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-26 21:02:26 -05:00
Donald Sharp
4a2f796f2e lib, zebra: Abstract character selection for nexthop display
When we are selecting nexthops for disply, abstract the notion
of what character we display to the end user about the status
of the nexthop.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-25 20:14:38 -05:00
Anuradha Karuppiah
cde1af847e zebra: set connected route metric based on the devaddr metric
MACVLAN devices are typically used for applications such as VRR/VRRP that
require a second MAC address (virtual). These devices have a corresponding
SVI/VLAN device -
root@TORC11:~# ip addr show vlan1002
39: vlan1002@bridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9152 qdisc noqueue master vrf1 state UP group default
    link/ether 00:02:00:00:00:2e brd ff:ff:ff:ff:ff:ff
    inet6 2001:aa:1::2/64 scope global
       valid_lft forever preferred_lft forever
root@TORC11:~# ip addr show vlan1002-v0
40: vlan1002-v0@vlan1002: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9152 qdisc noqueue master vrf1 state UP group default
    link/ether 00:00:5e:00:01:01 brd ff:ff:ff:ff:ff:ff
    inet6 2001:aa:1::a/64 metric 1024 scope global
       valid_lft forever preferred_lft forever
root@TORC11:~#

The macvlan device is used primarily for RX (VR-IP/VR-MAC). And TX is via
the SVI. To acheive that functionality the macvlan network's metric
is set to a higher value.

Zebra currently ignores the devaddr metric sent by the kernel and hardcodes
it to 0. This commit eliminates that hardcoding. If the devaddr metric
is available (METRIC_MAX) it is used for setting up the connected route
otherwise we fallback to the dev/interface metric.

Setting the macvlan metric to a higher value ensures that zebra will always
select the connected route on the SVI (and subsequently use it for next hop
resolution etc.) -
root@TORC11:~# vtysh -c "show ip route vrf vrf1 2001:aa:1::/64"
Routing entry for 2001:aa:1::/64
  Known via "connected", distance 0, metric 1024, vrf vrf1
  Last update 11:30:56 ago
  * directly connected, vlan1002-v0

Routing entry for 2001:aa:1::/64
  Known via "connected", distance 0, metric 0, vrf vrf1, best
  Last update 11:30:56 ago
  * directly connected, vlan1002

root@TORC11:~#

Ticket: CM-23511
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-01-25 14:19:26 -05:00
Anuradha Karuppiah
2c476b72a0 zebra: propagate inactive neigh deletes to bgpd
When a local neigh is added with a MAC that is remote or absent the
neigh is kept in zebra as local/in-active. But not propagated to bgpd.
Similarly when an inactive neigh is deleted the del-msg is not propagated
to bgpd.

Without this change bgp and zebra would fall out of sync as that
bgp would not know to rerun bestpath and for it to reinstall a
known remote path for the mac-ip in question.  To fix this we
now propagate inactive neigh deletes to bgpd.

Ticket: CM-23018
Testing Done:
1. evpn-min
2. manually triggered the out-of-sync state and verified the fix

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-01-25 14:19:26 -05:00
David Lamparter
d4160947d9 lib: don't disable "log file" on "log syslog"
FRR log targets are independent, so "log syslog" must not disable
"log file" output.

Fixes: #3551
Fixes: 0204baa876
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-01-24 19:06:00 +01:00
David Lamparter
02a0df1f22 build, lib/yang: bake in extensions if possible
Starting with libyang 0.16.74, we can load internally embedded yang
extensions instead of going through the file system/dlopen.  Detect
support for this at build time and use if available.

NB: the fallback mechanism will go away in a short while.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-01-24 17:44:41 +01:00
David Lamparter
a28436ca47
Merge pull request #3655 from rubenk/macos-fixes
A few small build fixes for Mac OS
2019-01-24 13:51:37 +01:00
Ruben Kerkhof
4d762f2607 Treewide: use ANSI function definitions
Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
2019-01-24 11:21:59 +01:00
Quentin Young
b9c25a2a90
Merge pull request #3559 from opensourcerouting/zapi-sanity-checks
add a few moar sanity checks when encoding/decoding zapi routes
2019-01-22 13:53:08 -05:00
Ruben Kerkhof
a64c953a90 Fix compile error on Mac OS
CC       lib/frr_pthread.lo
lib/frr_pthread.c:128:40: error: too many arguments to function call, expected 1, have 3
        ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL);
              ~~~~~~~~~~~~~~~~~~              ^~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/pthread.h:512:1: note: 'pthread_setname_np' declared here
__API_AVAILABLE(macos(10.6), ios(3.2))

Mac OS does have pthread_setname_np, but we can't use it here since it
only accepts a single argument, the thread name, and thus only works for
the current thread.

Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
2019-01-22 17:55:31 +01:00