Commit Graph

3440 Commits

Author SHA1 Message Date
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
Donald Sharp
b3cfe1e2da
Merge pull request #3633 from opensourcerouting/send-vrf-backend
Send VRF backend to the client daemons
2019-01-22 09:11:58 -05:00
Russ White
62b6a7e149
Merge pull request #3631 from opensourcerouting/zapi_fixes
Small zapi fixes
2019-01-21 20:25:08 -05:00
Renato Westphal
81bd033cbb lib: remove the vrf_is_mapped_on_netns() function
Now that all daemons receive the VRF backend from zebra, we can get
rid of vrf_is_mapped_on_netns() in favor of using the more convenient
vrf_is_backend_netns() function, which doesn't require any argument.

This commit also fixes the following problem:
  debian(config)# ip route 50.0.0.0/8 blackhole vrf FAKE table 2
  % table param only available when running on netns-based vrfs

Even when zebra was started with the --vrfwnetns, the error
above would be displayed since the VRF FAKE didn't exist, which
would make vrf_is_mapped_on_netns() return 0 incorrectly. Using
vrf_is_backend_netns() this problem doesn't happen anymore.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-19 22:49:11 -02:00
Renato Westphal
bb6b7f79be zebra, lib: send VRF backend to the client daemons
Add a new field in the ZEBRA_CAPABILITIES zapi message specifying
the VRF backend in use.

For simplicity, make the zclient code call vrf_configure_backend()
to apply the received value automatically instead of requiring
the daemons to do that themselves in their zebra_capabilities()
callbacks.

Additionally, call zebra_vrf_update_all() only after sending the
capabilities message to the client, so that it will know which VRF
backend is in use when processing the VRF messages.

This commit fixes a couple of bugs in the "interface" CLI command and
associated northbound callbacks, which behave differently depending
on the VRF backend in use. Before this commit, the vrf_backend
variable would always be set to VRF_BACKEND_NETNS in the client
daemons, even when zebra was started without the --vrfwnetns option.
This could lead to inconsistent behavior and subtle bugs under
specific circumstances.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-19 22:46:37 -02:00
Renato Westphal
cf09d3ca45 lib: simplify detection of when the user is leaving the CLI config mode
We can make use of the vty->config variable to know when the CLI
user is in the configuration mode or not. This is much simpler
than obtaining this information from the vty node, and also a more
robust solution (the three switch statements below, for example,
were out of sync).

Also, fix a bug where vty->config wasn't being unset in the
vty_config_exit() function (bug introduced by commit f344c66ea3).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-19 16:07:30 -02:00
Renato Westphal
41e195d477 lib: reset the vty xpath index when entering the config mode
The CLI code uses the vty->xpath[] array and the vty->xpath_index
variables to keep track of where the user is in the configuration
hierarchy. As such, we were resetting vty->xpath_index to zero
whenever the user exited from the configuration mode in order to
keep the index valid. We weren't doing this in the vty_stop_input()
function however, which is called when the user types ^C in the
terminal. This was leading to bugs like this:

  zebra> en
  zebra# conf t
  zebra(config)# interface eth0
  zebra(config-if)# ^C
  zebra# conf t
  zebra(config)# interface eth0
  % Configuration failed.

  Schema node not found.
  YANG path: /frr-interface:lib/interface[name='eth0'][vrf='default']/frr-interface:lib

To fix this, do something more clever: instead of resetting the
XPath index whenever the user exits from the configuration mode,
do that when the user enters in the configuration mode. This way
the XPath index needs to be reset in a single place only, not to
mention it's a more robust solution.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-19 15:56:54 -02:00
Renato Westphal
37345802af lib: peform only partial YANG validation when displaying operational data
When lyd_validate() is used with the LYD_OPT_DATA option, full YANG
validation is performed. As a side-effect to this, default nodes are
created, which is not desirable when displaying operational data
since configuration nodes can also be created. Use LYD_OPT_GET
option to resolve this problem.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-18 16:15:41 -02:00
Renato Westphal
fcb7bffdda lib: introduce new YANG helper function
One use case for the new yang_data_list_find() function is to find
input parameters in RPC northbound callbacks easily, without the
need to iterate over the input parameters manually.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-18 16:15:41 -02:00
Renato Westphal
02fe07c7b8 lib: constify a few parameters in the VRF code
Parameters should be const whenever possible to improve code
readability and remove the need to cast away the constness of
const arguments.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-18 16:15:41 -02:00
Renato Westphal
edc127627d lib: use the correct VRF ID when parsing INTERFACE_LINK_PARAMS messages
Bug found during code inspection.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-18 16:06:00 -02:00
Renato Westphal
d763789879 lib: fix checking of clients subscribed to receive default routes
In these two functions, we were using VRF_DEFAULT instead of the
VRF ID passed as a parameter when checking if the given client
subscribed to receive default routes or not. This prevented the
"default-originate" command from ospfd/isisd from working correctly
under specific circumstances.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-18 16:06:00 -02:00
Renato Westphal
d8e331eb0e
Merge pull request #3180 from qlyoung/prefixlen-u8-to-u16
lib: convert prefixlen to 16-bit integer
2019-01-15 00:39:39 -02:00
Donald Sharp
31107203da
Merge pull request #3611 from opensourcerouting/nb-fixes
Minor northbound fixes
2019-01-14 17:28:49 -05:00
Renato Westphal
b44d0de576 lib: update suggestions related to some northbound errors
Since commit 3a11599c, the FRR YANG modules are embedded inside the
binaries and no longer need to be loaded from the file system. This
way, it's impossible for the FRR binaries and YANG modules to be out
of sync anymore. As such, update the suggestions of the northbound
error codes.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 16:33:37 -02:00
Renato Westphal
9f6de29901 lib: don't abort when incomplete xpath is given by the user
Instead of aborting when an incomplete xpath is given to the
nb_oper_data_iterate() function, just return an error so that the
callers have a chance to treat this error. Aborting based on invalid
user input is never the right thing to do.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 16:33:21 -02:00
Renato Westphal
f65fb6b4b4 lib: fix "use of uninitialised value" valgrind warning
When FRR is built without the --enable-config-rollbacks option,
the nb_db_transaction_save() function does nothing and the
"transaction_id" output parameter is left uninitialized. For
this reason, all northbound clients should initialize the
"transaction_id" argument before calling nb_candidate_commit() or
nb_candidate_commit_apply() (except when a NULL pointer is given,
which is the case of the confd and sysrepo plugins).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 16:32:23 -02:00
Renato Westphal
ec348d4344 lib: fix "may be used uninitialized" build warning
We are already handling all possible four cases from the "nb_event"
enumeration, so this problem can't happen in practice. Initialize the
"ref" variable to zero to silence the warning.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 16:30:39 -02:00
Renato Westphal
e4081c0e0b lib: add a few more sanity checks when encoding/decoding routes
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 15:58:26 -02:00
Renato Westphal
49db7a7b05 lib, zebra: add AFI parameter to the ZEBRA_REDISTRIBUTE_DEFAULT_* messages
Some daemons like ospfd and isisd have the ability to advertise a
default route to their peers only if one exists in the RIB. This
is what the "default-information originate" commands do when used
without the "always" parameter.

For that to work, these daemons use the ZEBRA_REDISTRIBUTE_DEFAULT_ADD
message to request default route information to zebra. The problem
is that this message didn't have an AFI parameter, so a default route
from any address-family would satisfy the requests from both daemons
(e.g. ::/0 would trigger ospfd to advertise a default route to its
peers, and 0.0.0.0/0 would trigger isisd to advertise a default route
to its IPv6 peers).

Fix this by adding an AFI parameter to the
ZEBRA_REDISTRIBUTE_DEFAULT_{ADD,DELETE} messages and making the
corresponding code changes.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 11:41:33 -02:00
Donald Sharp
6a923ca462 lib: Add another 32 bit accessor to the prefix data structure
It would be nice to have the ability to access the prefix data structure
address as a block of 4 uint32_t's.  This will allow me to easily/quickly
update the v6 address by 1.  This will be used in subsuquent commits.

Signed-off-by:  Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-10 19:26:31 -05:00
Mark Stapp
a311fb5653
Merge pull request #3589 from donaldsharp/self_vs_thread
lib: Convert RUSAGE_SELF to RUSAGE_THREAD where we can
2019-01-10 08:49:01 -05:00
Donald Sharp
c80bedb83b lib, bgpd: Convert frr_pthread_set_name to only cause it to set os name of the thread
The current invocation of frr_pthread_set_name was causing it reset the os_name.
There is no need for this, we now always create the pthread appropriately
to have both name and os_name.  So convert this function to a simple
call through of the pthread call now.

Before(any of these changes):
sharpd@robot ~/frr1> ps -L -p 16895
  PID   LWP TTY          TIME CMD
16895 16895 ?        00:01:39 bgpd
16895 16896 ?        00:00:54
16895 16897 ?        00:00:07 bgpd_ka

After:
sharpd@donna ~/frr1> ps -L -p 1752
  PID   LWP TTY          TIME CMD
 1752  1752 ?        00:00:00 bgpd
 1752  1753 ?        00:00:00 bgpd_io
 1752  1754 ?        00:00:00 bgpd_ka

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-09 14:59:22 -05:00
Donald Sharp
6d0a40b5b7 lib: Cleanup thread name setting to happen at start
When we start a thread we always call fpt_run and since
the last commit we know os_name is filled with something,
therefore we can just set the name on startup.

This creates this output now for zebra:

sharpd@donna ~/frr2> ps -L -p 25643
  PID   LWP TTY          TIME CMD
25643 25643 ?        00:00:00 zebra
25643 25644 ?        00:00:00 Zebra dplane
25643 25684 ?        00:00:00 zebra_apic
sharpd@donna ~/frr2>

I removed the abstraction to frr_pthread_set_name because
it was snprintf'ing into the same buffer which was the
real bug here( the first character of os_name became null).
In the next commit I'll remove that api because
it is unneeded and was a horrible hack to get
this to work for the one place it was wanted.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-09 14:38:07 -05:00
Donald Sharp
b8dccd94f3 lib: On frr_pthread_new save a os_name
On call of frr_pthread_new, save the os_name if given,
if not given use the name passed in( shortening to fit
in available space ) and finally if the name was not
passed in use the default value.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-09 14:30:43 -05:00
Donald Sharp
231db9a6e1 lib: Convert RUSAGE_SELF to RUSAGE_THREAD where we can
When using getrusage, we have multiple choices about what
to call for data gathering about this particular thread of execution.

RUSAGE_SELF -> This means gather all cpu run time for all pthreads associated
with this process.

RUSAGE_THREAD -> This means gather all cpu run time for this particular
pthread.

Clearly with data gathering for slow thread as well as `show thread cpu`
it would be preferable to gather only data about the current running
pthread.  This probably was the original behavior of using RUSAGE_SELF
when we didn't have multiple pthreads.  So it didn't matter so much.

Prior to this change, 10 iterations of 1 million routes install/remove
from zebra would give us this cpu time for the dataplane pthread:

Showing statistics for pthread Zebra dplane thread
--------------------------------------------------
                      CPU (user+system): Real (wall-clock):
Active   Runtime(ms)   Invoked Avg uSec Max uSecs Avg uSec Max uSecs  Type  Thread
    0     280902.149    326541      860   2609982      550   2468910    E  dplane_thread_loop

After this change we are seeing this:

Showing statistics for pthread Zebra dplane thread
--------------------------------------------------
                      CPU (user+system): Real (wall-clock):
Active   Runtime(ms)   Invoked Avg uSec Max uSecs Avg uSec Max uSecs  Type  Thread
    0      58045.560    334944      173    277226      539   2502268    E  dplane_thread_loop

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-09 12:18:21 -05:00
Donald Sharp
6edbb8b2e3 lib: Add mlag_role2str function
Add a generic mlag_role2str function for lib since multiple daemons
will be using this code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-04 12:21:00 -05:00
Donald Sharp
02c0866dbe lib, zebra: On startup send mlag role as part of the capabilities
On startup send the mlag role as part of the capabilities to
the end protocol.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-04 12:21:00 -05:00
Donald Sharp
14beb5484f lib: Add a basic mlag.h file
This is the start of a series of commits that will allow FRR to
be integrated into mlag.

Zebra and Pim will both need mlag state for the router.  As such we will
need to provide a abstract about this state through the zapi.

This is the start of the common header that both Pim and Zebra will
be using.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-04 12:21:00 -05:00
Renato Westphal
3cb4162cfe lib: fix segfault on freebsd when using vsnprintf() incorrectly
FreeBSD's libc segfaults when vsnprintf() is called with a null
format string. Add a null check before calling vsnprintf() to
resolve this problem.

Fixes #3537

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-02 22:32:13 -02:00
Renato Westphal
91d227b7e3 zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
Unlike the other interface zapi messages, ZEBRA_INTERFACE_VRF_UPDATE
identifies interfaces using ifindexes and not interface names. This
is a problem because zebra always sends ZEBRA_INTERFACE_DOWN
and ZEBRA_INTERFACE_DELETE messages before sending
ZEBRA_INTERFACE_VRF_UPDATE, and the ZEBRA_INTERFACE_DELETE callback
from all daemons set the interface index to IFINDEX_INTERNAL. Hence,
when decoding a ZEBRA_INTERFACE_VRF_UPDATE message, the interface
lookup would always fail since the corresponding interface lost
its ifindex. Example (ospfd):

OSPF: Zebra: Interface[rt1-eth2] state change to down.
OSPF: Zebra: interface delete rt1-eth2 vrf default[0] index 8 flags 11143 metric 0 mtu 1500
OSPF: [EC 100663301] INTERFACE_VRF_UPDATE: Cannot find IF 8 in VRF 0

To fix this problem, use interface names instead of ifindexes to
indentify interfaces like the other interface zapi messages do.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-02 13:32:31 -02:00
Philippe Guibert
03a38493f8 lib, rip, ripng, babel, eigrp: add ctx pointer to distribute api
a distribute_ctx context pointer is returned after initialisation to the
calling daemon. this context pointer will be further used to do
discussion with distribute service. Today, there is no specific problem
with old api, since the pointer is the same in all the memory process.
but the pointer will be different if we have multiple instances. Right
now, this is not the case, but if that happens, that work will be used
for that.
distribute-list initialisation is split in two. the vty initialisation
is done at global level, while the context initialisation is done for
each routing daemon instance.
babel daemon is being equipped with a routing returning the main babel
instance.
also, a delete routine is available when the daemon routing instance is
suppressed.
a list of contexts is used inside distribute_list. This will permit
distribute_list utility to handle in the same daemon to handle more than
one context. This will be very useful in the vrf context.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-28 18:18:40 +01:00
Philippe Guibert
2569910bb6 lib: enforce vrf_name_to_id by returning default_vrf when name is null
in order to enforce the vrf_id to return, from a vrf name, a check is
done on the vrf_name_to_id callback.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-12-28 18:18:40 +01:00
Anton Degtyarev
57592a53b5 bgpd, zebra: auto assign labels from label pool to regular prefixes in BGP labeled unicast
This commit is the last missing piece to complete BGP LU support in bgpd. To this moment, bgpd (and zebra) supported auto label assignment only for prefixes leaked from VRFs to vpn and for MPLS SR prefixes. This adds auto label assignment to other routes types in bgpd. The following enhancements have been made:
* bgp_route.c:bgp_process_main_one() now sets implicit-null local_label to all local, aggregate and redistributed routes.
* bgp_route.c:bgp_process_main_one() now will request a label from the label pool for any prefix that loses the label for some reason (for example, when the static label assignment config is removed)
* bgp_label.c:bgp_reg_dereg_for_label() now requests labels from label pool for routes which have no associated label index
* zebra_mpls.c:zebra_mpls_fec_register() now expects both label and label_index from the calling function, one of which must be set to MPLS_INVALID_LABEL or MPLS_INVALID_LABEL_INDEX, based on this it will decide how to register the provided FEC.

Signed-off-by: Anton Degtyarev <anton@cumulusnetworks.com>
2018-12-20 15:28:52 +03:00
Emanuele Di Pascale
96f2c00903 lib: add frr-isisd to the native models
Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2018-12-18 15:25:57 +01:00
Emanuele Di Pascale
bb359ba2f2 lib: fix issue with yang_str2enum
The same issue with derived enum types that was already fixed
for yang_data_new_enum was still present here, so I simply
applied the same fix.

Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2018-12-18 15:15:26 +01:00
Emanuele Di Pascale
8427e0e674 lib: copy xpaths when enqueing changes
Just copying th const char* of the xpath means that if we
are enqueing multiple changes from a buffer, the last xpath
addedd will overwrite all of the previous references.
Copying the xpath to a buffer simplifies the API when
retrofitting the commands.

Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2018-12-18 15:15:26 +01:00
Emanuele Di Pascale
625b70e3da lib: add NB phase-specific error codes
As suggested by Renato, add error codes that are specific
to the various phases of a northbound callback. These can
be used by the daemons when logging an error. The reasoning
is that validation errors typically mean that there is an
inconsistency in the configuration, a prepare error means
that we are running out of resources, and abort/apply errors
are bugs that need to be reported to the devs.

Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2018-12-18 15:15:26 +01:00
David Lamparter
bbfeedb5ef lib: flip to ISC on hook & module code
I accidentally put MIT headers on these; the intent was ISC.  It doesn't
really make a difference, but let's get it consistent.

Signed-off-by: David Lamparter <equinox@diac24.net>
2018-12-14 16:24:06 +01:00
Donald Sharp
85c3d6005e
Merge pull request #3464 from mjstapp/wq_event
libs,zebra: support timeout for workqueue retries, use for rib
2018-12-14 10:00:49 -05:00
Donald Sharp
9c3f61e583
Merge pull request #3399 from opensourcerouting/ripngd-nb-retrofitting
ripngd northbound conversion
2018-12-14 07:45:42 -05:00
Mark Stapp
5418f988cf libs: support timeout for workqueue retries
Support an optional timeout/delay for use when a workqueue
determines that it is blocked, instead of retrying immediately.
Also, schedule as an 'event' instead of a 'timer' when using
a zero timeout value.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2018-12-13 14:08:39 -05:00
Mark Stapp
141e9ae222
Merge pull request #3472 from donaldsharp/flags
zebra.h ZEBRA_FLAG_XXX cleanup
2018-12-13 09:16:20 -05:00
Donald Sharp
07c67e1ec2 lib: Reorder Zebra message flags and document
Reorder the numbering of the Zebra message flags and document
what each flag is supposed to do.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-12-12 15:33:40 -05:00
Donald Sharp
646f779f9d lib: Remove unused ZEBRA_FLAG_SCOPE_LINK
The ZEBRA_FLAG_SCOPE_LINK #define was never used, remove it

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-12-12 15:17:47 -05:00
Donald Sharp
36a11c0f39 lib, zebra: Remove ZEBRA_FLAG_STATIC
We never used this information and it was merely stored.
Additionally this is not something that is a flag, it's
a status.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-12-12 15:03:22 -05:00
Donald Sharp
f999f11e76 lib: Fix string size issue with clang
Newer versions of clang are failing on xpath length
not being sufficiently sized to hold all possible data
that could be thrown at it.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-12-12 12:32:22 -05:00
Renato Westphal
99fb518fef lib, tests: add support for keyless YANG lists
YANG allows lists without keys for operational data, in which case
the list elements are uniquely identified using a positional index
(starting from one).

This commit does the following:
* Remove the need to implement the 'get_keys' and 'lookup_entry'
  callbacks for keyless lists.
* Extend nb_oper_data_iter_list() so that it special-cases keyless
  lists appropriately. Since both the CLI and the sysrepo plugin
  use nb_oper_data_iterate() to fetch operational data, both these
  northbound clients automatically gain the ability to understand
  keyless lists without additional changes.
* Extend the confd plugin to special-case keyless lists as well. This
  was a bit painful to implement given ConfD's clumsy API, but
  keyless lists should work ok now.
* Update the "test_oper_data" unit test to test keyless YANG lists in
  addition to regular lists.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-09 13:58:53 -02:00
Donald Sharp
ca6541963c
Merge pull request #3449 from opensourcerouting/network-wide-transactions
lib: fix NETCONF network-wide transactions for confd and sysrepo
2018-12-09 09:39:37 -05:00
Donald Sharp
64b81b3a64
Merge pull request #3442 from opensourcerouting/confirmed-commits
lib: add support for confirmed commits
2018-12-09 09:35:49 -05:00
Renato Westphal
88a7d121d1 lib: fix NETCONF network-wide transactions for confd and sysrepo
ConfD and Sysrepo implement configuration transactions using a
two-phase commit protocol (prepare + abort/apply). For network-wide
transactions to work, ConfD and Sysrepo move to the second phase of
the commit protocol only after receiving the results of the first
phase from all devices involved in the transaction. If all devices
succeed in the 'prepare' phase, then all of them move to the 'apply'
phase and the transaction is committed. On the other hand, if any
device fails in the 'prepare' phase, all of them move to 'abort'
phase and the transaction is aborted.

The confd and sysrepo plugins were implementing the full
two-phase commit protocol upon receiving a request to validate
the configuration changes and allocate all resources required to
apply them (first phase). The notifications to abort or apply the
changes (second phase) were being ignored since everything was being
done in the first phase for simplicity. This wasn't a problem for
single-device transactions, but it is for transactions involving
multiple devices.  Rework the code a bit to do things properly and
fix this problem.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-07 16:01:34 -02:00
Renato Westphal
18bf258a0d lib: implement the "show" command
The "show" command will be available in the configuration mode and
all configuration subnodes. It's used to display the section of
the candidate configuration being edited, instead of displaying
the entire candidate configuration like when "show configuration
candidate" is used. The goal is to add more convenience when editing
huge configurations.

When the transactional CLI mode is not used, the candidate
configuration and the running configuration are identical, hence in
this case we can say that the "show" command displays the section
of the running configuration being edited.

Example:
ripd(config)# show
Configuration:
!
frr version 6.1-dev
frr defaults traditional
!
interface eth0
 ip rip split-horizon poisoned-reverse
 ip rip authentication mode md5
 ip rip authentication string supersecret
!
interface eth1
 ip rip receive version 1
 ip rip send version 1
!
router rip
 allow-ecmp
 route 10.0.1.0/24
 route 10.0.2.0/24
!
end
ripd(config)#
ripd(config)#
ripd(config)# interface eth0
ripd(config-if)# show
!
interface eth0
 ip rip split-horizon poisoned-reverse
 ip rip authentication mode md5
 ip rip authentication string supersecret
!
ripd(config-if)# exit
ripd(config)#
ripd(config)#
ripd(config)# router rip
ripd(config-router)# show
!
router rip
 allow-ecmp
 route 10.0.1.0/24
 route 10.0.2.0/24
!
ripd(config-router)#

The "show" command only works for daemons converted to the new
northbound model. vtysh support will be implemented at a later
time as it will require some level of coordination between vtysh
and the FRR daemons.

Fixes #3148.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-07 11:29:58 -02:00
Renato Westphal
fbdc1c0a84 lib: add support for confirmed commits
Confirmed commits allow the user to request an automatic rollback to
the previous configuration if the commit operation is not confirmed
within a number of minutes. This is particularly useful when the user
is accessing the CLI through the network (e.g. using SSH) and any
configuration change might cause an unexpected loss of connectivity
between the user and the managed device (e.g. misconfiguration of a
routing protocol). By using a confirmed commit, the user can rest
assured the connectivity will be restored after the given timeout
expires, avoiding the need to access the router physically to fix
the problem.

When "commit confirmed TIMEOUT" is used, a new "commit" command is
expected to confirm the previous commit before the given timeout
expires. If "commit confirmed TIMEOUT" is used while there's already
a confirmed-commit in progress, the confirmed-commit timeout is
reset to the new value.

In the current implementation, if other users perform commits while
there's a confirmed-commit in progress, all commits are rolled back
when the confirmed-commit timeout expires. It's recommended to use
the "configure exclusive" configuration mode to prevent unexpected
outcomes when using confirmed commits.

When an user exits from the configuration mode while there's a
confirmed-commit in progress, the commit is automatically rolled
back and the user is notified about it. In the future we might
want to prompt the user if he or she really wants to exit from the
configuration mode when there's a pending confirmed commit.

Needless to say, confirmed commit only work for configuration
commands converted to the new northbound model. vtysh support will
be implemented at a later time.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-07 11:11:33 -02:00
Christian Franke
78ca034252 lib: add thread_timer_remain_msec function
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2018-12-04 12:49:25 +01:00
Renato Westphal
a1f0a9ac23
Merge pull request #3370 from pguibert6WIND/default_vrf_initialization
Default vrf initialization
2018-12-03 21:30:00 -02:00
Renato Westphal
b0f59f90ff
Merge pull request #3404 from donaldsharp/nexthop_cleanup
lib: Cleanup nexthop2str code to be consistent
2018-12-03 18:20:27 -02:00
Renato Westphal
e9ce224b85 yang, ripngd: add 'frr-ripngd.yang' and associated stub callbacks
Introduce frr-ripngd.yang, which defines a model for managing the
FRR ripngd daemon.

Update the 'frr_yang_module_info' array of ripngd with the new
'frr-ripngd' module.

Add two new files (ripng_cli.[ch]) which should contain all ripngd
commands converted to the new northbound model. Centralizing all
commands in a single place will facilitate the process of moving
the CLI to a separate program in the future.

Add automatically generated stub callbacks in
ripng_northbound.c. These callbacks will be implemented gradually
in the following commits.

Add the confd.frr-ripngd.yang YANG module with annotations specific
to the ConfD daemon.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-03 13:47:58 -02:00
David Lamparter
3e30070331 Revert "isisd lib ospfd pbrd python: fix empty init"
This reverts commit 48944eb65e.

We're using GNU C, not ISO C - and this commit triggers new (real)
warnings about {0} instead of bogus ones about {}.

Signed-off-by: David Lamparter <equinox@diac24.net>
2018-12-01 16:49:45 +01:00
Donald Sharp
0ee78eafbd
Merge pull request #3378 from opensourcerouting/remove-config-lock
*: remove the configuration lock from all daemons
2018-11-30 18:50:49 -05:00
Donald Sharp
1d74ea6ea0 lib: Cleanup nexthop2str code to be consistent
We sometimes store ifindex information in the NEXTHOP_TYPE_IPV[4|6]
so let's let us display that information as well when dumping
a nexthop.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-11-30 16:07:34 -05:00
Russ White
9f7b49e105
Merge pull request #3342 from opensourcerouting/nb-operational-data
Northbound: improved support for YANG-modeled operational data
2018-11-29 15:19:38 -05:00
Donald Sharp
c4affc7bc0
Merge pull request #3397 from mjstapp/fix_stream_macros
libs,bgpd: remove deprecated stream lib macros
2018-11-29 13:10:02 -05:00
Mark Stapp
26c08e954d lib,bgpd: remove deprecated stream lib macros
A couple of deprecated lib/stream macros have aged out; remove
them, and replace the one remaining use.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2018-11-29 11:13:15 -05:00
Renato Westphal
2a48af2b26
Merge pull request #3389 from pguibert6WIND/ip_prefixes_do_not_look_integer
lib: do not convert ip prefixes without '.' or ':'
2018-11-28 15:49:50 -02:00
Philippe Guibert
8d92004979 lib: do not convert ip prefixes without '.'
There are cases where the passed parameter for a vty command is either
an interface name or an ip address. Because the interface name can be a
number, and because the user may want to use a number to define an IP (
for instance 'ping 0' is valid from shell purpose), there is a choice
that needs to be done at frr level. either from the application point of
view, the interface name will be priorized, or each number will be
considered as an ip address. In that commit, the inet_aton procedure is
replaced with the inet_pton procedure that ignores ips with just a
number.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-11-28 17:37:24 +01:00
Renato Westphal
1a4bc045de lib, tests: major rework in the operational-data callbacks
The northbound infrastructure for operational data was subpar compared
to the infrastructure for configuration data. This commit addresses most
of the existing problems, making it possible to write operational-data
callbacks for more complex YANG models.

Summary of the changes:
* Add support for nested YANG lists.
* Add support for leaf-lists.
* Add support for leafs of type "empty".
* Introduce the "show yang operational-data XPATH" command, and write an
  unit test for it. The main purpose of this command is to make it
  easier to test the operational-data northbound callbacks.
* Introduce the nb_oper_data_iterate() function, that can be used
  to iterate over operational data. Make the CLI and sysrepo use this
  function.
* Since ConfD has a very peculiar API, it can't reuse the
  nb_oper_data_iterate() like the other northbound clients. In this
  case, adapt the existing ConfD callbacks to support the new features
  (and make some performance improvements in the process).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 18:28:53 -02:00
Renato Westphal
85cd3326fd lib: do not subscribe to config changes on a state data tree (confd plugin)
Prevent the confd plugin from subscribing to configuration changes on a
data tree that contains only state data.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:38:08 -02:00
Renato Westphal
544ca69a5c lib: add support for YANG lists with mixed config and state data
A YANG list that contains both configuration and state data must have
the following callbacks: create(), delete(), get_next(), get_keys()
and lookup_entry().

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:38:08 -02:00
Renato Westphal
e0ccfad220 lib: rework the yang schema node iteration functions
* Rename yang_snodes_iterate() to yang_snodes_iterate_subtree() and
  expose it in the public API.
* Rename yang_module_snodes_iterate() to yang_snodes_iterate_module().
* Rename yang_all_snodes_iterate() to yang_snodes_iterate_all().
* Make it possible to stop the iteration at any time by returning
  YANG_ITER_STOP in the iteration callbacks.
* Make the iteration callbacks accept only one user argument and not
  two.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:38:08 -02:00
Renato Westphal
a1b5f469e7 lib: introduce function that loads all FRR native YANG modules
In some cases it will be necessary to load all FRR native modules.
Examples:
* vtysh needs to load all YANG modules so that it can manipulate data
  from all daemons.
* The gen_northbound_callbacks tool will need to load all YANG modules
  since augmentations from one module can have an effect in the required
  northbound callbacks of other modules.

The new yang_module_load_all() function provides this functionality.

As a side note, the "frr_native_modules" will need to be updated every
time we add a new YANG module to FRR.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:36:34 -02:00
Renato Westphal
e5dc8a44ee lib: remove entire data tree on yang_dnode_free()
For convenience, make yang_dnode_free() remove the entire data tree and
not only the data node given as a parameter.

Also, add a null-pointer check on nb_config_replace() before calling
yang_dnode_free().

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:35:58 -02:00
Renato Westphal
db452508bf lib, tools: use CHECK_FLAG/SET_FLAG more often in the northbound code
Cosmetic change to improve code readability a bit. No binary changes.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:35:58 -02:00
Renato Westphal
5e02643a64 lib: make it possible to create YANG data nodes containing state data
By default the data nodes created by yang_dnode_new() could contain
only configuration data (LYD_OPT_CONFIG). Add a 'config_only' option
to yang_dnode_new() so that it can create data nodes containing both
configuration and state data.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:35:58 -02:00
Renato Westphal
80243aef05 lib: don't fetch schema information when creating yang_data structures
Prefetching the schema node when creating yang_data structures is
expensive, and in most cases we don't need that information. In that case,
fetch the schema information only when necessary to improve performance
when fetching operational data.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:35:58 -02:00
Renato Westphal
70065793bb lib: use prefixconstptr instead of const prefixptr
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:35:58 -02:00
Renato Westphal
f344c66ea3 *: remove the configuration lock from all daemons
A while ago all FRR configuration commands were converted to use the
QOBJ infrastructure to keep track of configuration objects. This
means the configuration lock isn't necessary anymore because the
QOBJ code detects when someones tries to edit a configuration object
that was deleted and react accordingly (log an error and abort the
command).  The possibility of accessing dangling pointers doesn't
exist anymore since vty->index was removed.

Summary of the changes:
* remove the configuration lock and the vty_config_lockless() function.
* rename vty_config_unlock() to vty_config_exit() since we need to
  clean up a few things when exiting from the configuration mode.
* rename vty_config_lock() to vty_config_enter() to remove code
  duplication that existed between the three different "configuration"
  commands (terminal, private and exclusive).

Configuration commands converted to the new northbound model don't
need the configuration lock either since the northbound API also
detects when someone tries to edit a configuration object that
doesn't exist anymore.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 16:47:35 -02:00
Renato Westphal
a6233bfcb3 lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure
that either all changes made by a command are accepted or none are.
This is done to prevent inconsistent states where only parts of a
command are applied in the event any error happens.

The previous API for converted commands, the nb_cli_cfg_change()
function, required callers to pass an array containing all changes
that needed to be applied in the candidate configuration. The
problem with this API is that it was very inconvenient for complex
commands, which change different configuration options depending
on several factors.  This required users to manipulate the array
of configuration changes using low-level primitives, making it
complicated to implement some commands.

To solve this problem, introduce a new API based on the two following
functions:
- nb_cli_enqueue_change()
- nb_cli_apply_changes()

The first function is used to enqueue configuration changes, one
at time. Then the nb_cli_apply_changes() function is used to apply
all the enqueued configuration changes.

To implement this, a static-sized array was allocated in the "vty"
structure, along with a counter of enqueued changes. This eliminates
the need to declare an array of configuration changes in every
converted CLI command, simplifying things quite considerably.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 15:57:23 -02:00
Renato Westphal
25c780a32a lib: make yang_dnode_get_entry() more flexible
Add the "abort_if_not_found" parameter to the yang_dnode_get_entry()
function instead of always aborting when an user pointer is not
found.  This will make it possible, for example, to use this function
during the validation phase of a configuration transaction. Callers
will only need to check if the function returned NULL or not,
since new configuration objects (if any) won't be created until
the NB_EV_APPLY phase of the transaction.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 15:53:15 -02:00
Renato Westphal
3f66207896 lib: introduce function to retrieve the schema name of a data node
In some cases it might be desirable to obtain the schema name of
a libyang data node. Introduce the yang_dnode_get_schema_name()
function for this purpose.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 15:52:12 -02:00
Renato Westphal
a7d055e4ff lib: improve error handling when connection to confd is lost
This fixes an infinite loop that happened every time the connection
to the confd daemon was lost. Deactivate the confd module when
that happens to fix the infinite loop. This is only a temporary
workaround, in the long term we need to add a connection retry timer
to reestablish the connection to the confd daemon once it's back.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 15:51:57 -02:00
Renato Westphal
f3e5b71cc1 lib: set YANG search directory when creating libyang context
Minor code simplification.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 13:07:40 -02:00
Russ White
0c9503eb4e
Merge pull request #3361 from opensourcerouting/yang-embed-models
yang: embed models into binaries
2018-11-26 08:04:03 -05:00
Russ White
55cdfc769c
Merge pull request #3374 from opensourcerouting/bugfix/vty-shadow
lib/vty: Fix warning about shadowed variable
2018-11-26 07:56:31 -05:00
Russ White
19e5a46591
Merge pull request #3176 from chiragshah6/evpn_dev
zebra: duplicate address detection and dampening
2018-11-25 22:17:33 -05:00
Christian Franke
d0dec58747 lib/vty: Fix warning about shadowed variable
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2018-11-23 17:52:46 +01:00
Philippe Guibert
4fe52e7622 lib, zebra: default vrf configured will not be overwritten by discovery
the netns discovery process executed when vrf backend is netns, allows
the zebra daemon to dynamically change the default vrf name value. This
option is disabled, when the zebra is forced to a default vrf value with
option -o.

PR=61513
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
2018-11-21 17:21:19 +01:00
Renato Westphal
f37bb166a6
Merge pull request #3363 from pacovn/static_analysis__ISO_C_return_compliance
bgpd isisd lib: fix return on void functions
2018-11-21 14:19:09 -02:00
Renato Westphal
e3ae78a829
Merge pull request #3368 from pacovn/static_analysis__ISO_C_empty_initializer
isisd lib ospfd pbrd python: fix empty init
2018-11-21 14:14:45 -02:00
F. Aragon
48944eb65e
isisd lib ospfd pbrd python: fix empty init
ISO C forbids empty initializer braces. Empty initializers have been
replaced with {0}

Signed-off-by: F. Aragon <paco@voltanet.io>
2018-11-21 14:45:42 +01:00
Mark Stapp
fb88590c77
Merge pull request #3359 from qlyoung/true-atomics
Restrict atomics to 32-bits only
2018-11-20 11:43:10 -05:00
F. Aragon
d90b788e38
bgpd isisd lib: fix return on void functions
ISO C forbids ‘return’ with expression, in function returning void.

Signed-off-by: F. Aragon <paco@voltanet.io>
2018-11-20 16:32:25 +01:00
David Lamparter
3a11599cdc yang: embed models into binaries
This bakes our YANG models straight into the library/daemons, so they
don't need to be loaded from /usr/share/yang.  This makes the
installation quite a bit more robust, as well as gets us halfway to
running uninstalled.  (The other half is baking in the extension type
module.)

The /usr/share/yang directory is still searched as a fallback, as well
as for the experimental YANG model translator.  This is likely to stay
as is for the time being.

Signed-off-by: David Lamparter <equinox@diac24.net>
2018-11-19 23:45:24 +01:00
Quentin Young
0545c37384 *: only use 32-bit atomics
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-11-19 18:44:35 +00:00
David Lamparter
b156e69c6c
Merge pull request #3294 from pguibert6WIND/distribute_list_ipv6
lib: distribute-list ipv6 can be (un)configured
2018-11-19 17:01:24 +01:00
Chirag Shah
87454e6bd1 lib, zebra: dup addr detect display detection fields
Display following Per MAC and Neigh's output:
If duplicate address detection is under process,
display detection start time and detection count.
If duplicate address detection detected an address
as duplicate, display detection time and duplicate
status.

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2018-11-17 19:22:17 -08:00
Chirag Shah
3950b52c54 zebra: dup addr detect zapi changes
EVPN Duplicate Address Detection (DAD)
zapi information

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2018-11-17 19:22:16 -08:00
Chirag Shah
0b9d9cd013 bgpd: dup addr detect config cli
Duplicate address detection configuration clis
under bgp l2vpn evpn config mode.
- Enabled/Disable (global knob) for feature.
- Configure cli for duplicate detection action
freeze and freze until time (auto-recovery).

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2018-11-17 19:22:16 -08:00
David Lamparter
f335a0a602
Merge pull request #3331 from mjstapp/fix_lib_id_warning
libs: rename two id_alloc macros to resolve bsd conflict
2018-11-15 13:59:52 +01:00
Mark Stapp
4a600b08f7 libs: rename two id_alloc macros to resolve bsd conflict
Two of the macros in lib/id_alloc had conflicts on some platforms;
rename them to be unique.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2018-11-14 14:04:55 -05:00
Philippe Guibert
0b014ea675 bgpd: allow vrf validity and bgp vrf import/export, when zebra is off
if zebra is not started, then vrf identifiers are not available. This
prevents import/exportation to be available. This commit permits having
import/export available, even when zebra is not started.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-11-13 15:29:11 +01:00
Donald Sharp
bddea5fdf8
Merge pull request #3051 from mitch-skiba/addpath_change_V1
Addpath - Reuse IDs
2018-11-13 09:20:22 -05:00