Commit graph

543 commits

Author SHA1 Message Date
Jakub Urbańczyk a757997cab zebra: more clean-ups in netlink code
* Use nl_attr_add32 instead of nl_attr_add where it is possible.
 * Move common code from build_singlepath() and build_multipath()
   to separate function.

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-06-13 22:56:25 +02:00
Jakub Urbańczyk 0be6e7d75d zebra: check for buffer boundary
* Move code encoding Netlink messages to separate functions
 * Add buffer bounds checking while creating Nelink messages

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-06-13 22:56:25 +02:00
Jakub Urbańczyk 312a6beed6 zebra: clean up netlink api
* Rename netlink utility functions like addattr to be less ambiguous
 * Replace rta_attr_* functions with nl_attr_* since they introduced
   inconsistencies in the code
 * Add helper functions for adding rtnexthop struct to the Netlink
   message

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-06-13 22:53:24 +02:00
Mark Stapp ee70f62979 zebra: convert LSP nhlfe lists to use typesafe lists
Convert the embedded lists of nhlfes and snhlfes in zebra LSPs
and SLSPs to use typesafe dlists.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-06-01 14:46:12 -04:00
Sri Mohana Singamsetty 6e19892fdf
Merge pull request #6419 from vivek-cumulus/zebra_macfdb_fixup
Zebra macfdb fixup
2020-05-19 08:18:37 -07:00
Stephen Worley 22857da1bb
Merge pull request #6351 from opensourcerouting/fpm-nh
fpm: explicit next hop groups control
2020-05-19 11:01:03 -04:00
vivek bbd4285bc7 zebra: Install bridge FDB entries with correct VTEP IP
Fixes: zebra: adapt and export rmac netlink functions

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2020-05-15 14:01:59 -07:00
vivek 4682d1bf81 zebra: Pass correct buffer to MAC FDB netlink message build
Fixes: zebra: adapt and export rmac netlink functions

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2020-05-15 13:58:30 -07:00
Rafael Zalamena a2072e7100 zebra: format files to make polychaeta happy
Use clang-format to make code match what polychaeta wants for
formatting.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-13 13:56:16 -03:00
Rafael Zalamena b55ab92abd fpm: add toggle to enable/disable next hop groups
If you haven't migrated your FPM server to use next hop groups, it is
possible that you want to disable this feature. This commit implements
a toggle to enable/disable next hop groups usage (even if your Linux
kernel is not using it).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-05 16:22:07 -03:00
Stephen Worley 002e5c4357 zebra: abstract 5549 check into a function
Abstract the 5549 ipv4 over ipv6 into a function for easier
code reuse and reading.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-05-05 15:05:30 -04:00
Rafael Zalamena e9a1cd931b fpm: add next hop group support
Add support for the new kernel messages: `RTM_NEWNEXTHOP` and
`RTM_DELNEXTHOP`.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-05-05 10:54:06 -03:00
Mark Stapp 81ad029173
Merge pull request #6330 from sworleys/No-NHG-Install-With-VRFns
zebra: force off kernel NHG install with netns VRFs
2020-05-01 14:23:49 -04:00
Stephen Worley d982012a0e zebra: force off kernel NHG install with netns VRFs
Force off kernel NHG install with netns-based VRFs for
now. There is not really a good solution for allowing
kernel nexthop groups in namespaced based vrfs.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-05-01 12:34:43 -04:00
Donald Sharp 2c77ddee4b zebra: Display ifindex of interface being installed on
When installing a nexthop group, dump out the ifindex of the
nexthop being installed as a bit more data for the developer.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-05-01 11:58:20 -04:00
David Lamparter c334a16ef1
Merge pull request #6262 from qlyoung/remove-sprintf 2020-04-23 20:27:26 +02:00
Donald Sharp 9d866c07c8 zebra: Expose vrf lookup by table id out of rt_netlink.c
The function rt_netlink.c is using to lookup the vrf by
passed in table id.

I'm also going to pretend that this function is not
so awful to run when we have a large number of routes
incoming.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-04-22 10:56:06 -04:00
Quentin Young 772270f3b6 *: sprintf -> snprintf
Replace sprintf with snprintf where straightforward to do so.

- sprintf's into local scope buffers of known size are replaced with the
  equivalent snprintf call
- snprintf's into local scope buffers of known size that use the buffer
  size expression now use sizeof(buffer)
- sprintf(buf + strlen(buf), ...) replaced with snprintf() into temp
  buffer followed by strlcat

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-20 19:14:33 -04:00
Donald Sharp fd3f8e52b6 zebra: Modify netlink_request to statisfy coverity
The netlink_request function takes a `struct nlmsghdr *`
pointer from a common pattern that we use:

	struct {
		struct nlmsghdr n;
		struct fib_rule_hdr frh;
		char buf[NL_PKT_BUF_SIZE];
	} req;

We were calling it `netlink_request(Socket, &req.n)`

The problem here is that coverity, rightly so, sees that
we access the data after the nlmsghdr in netlink_request and
tells us we have an read beyond end of the structure.  While
we know we haven't mangled anything up here because of manual
inspection coverity doesn't have this knowledge implicitly.

So let's modify the code call to netlink_request to pass in the
void pointer of the req structure itself, cast to the appropriate
data structure in the function and do the right thing.  Hopefully
the coverity SA will be happy and we can move on with our life.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-04-15 09:01:56 -04:00
Rafael Zalamena a50404aaae zebra: fix some formatting/style issues
* Break lines longer than 80 columns.
* Remove space after '('.
* Use '%pIX' instead of 'inet_ntop'.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 14:05:52 -03:00
Rafael Zalamena f2a0ba3a50 zebra: data plane FPM add support RMAC VNI
Store VNI information in the data plane context so we can use it to
build the FPM netlink update with that information later.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 13:45:39 -03:00
Rafael Zalamena d4d4ec1cc1 zebra: adapt and export rmac netlink functions
Those functions are going to be used by the new data plane plugin for
netlink FPM.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 13:45:39 -03:00
Rafael Zalamena f78fe8f3d6 zebra: export netlink function and change return
Instead of retuning always `0`, lets return the amount of used bytes for
the message. This will be used by the new FPM interface to know how many
bytes we must reserve for the output buffer.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 11:44:39 -03:00
Rafael Zalamena b9c875150b zebra: simplify netlink_route_multipath
*   Remove variable `family`;
*   Remove always false `RTM_DELROUTE` checks;

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 11:44:39 -03:00
Rafael Zalamena 9266b31568 zebra: simplify some netlink debug messages
*   Use `inet_ntop` instead of `inet_ntoa`
*   Replace function name with `__func__`
*   Inline functions

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 11:44:39 -03:00
Rafael Zalamena e57a3fab68 zebra: generalize netlink route talk function
Generalize the netlink route message building function so it can be used
in the future by the netlink Forwarding Plane Manager (FPM) interface.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-04-14 10:40:50 -03:00
Jakub Urbańczyk bd47f3a3b4 zebra: Add vrf name and id to debugs
In some places we log the interface but not the vfr the
interface is in. In others we only output the vrf id, which
can be difficult for human to read. This commit makes zebra
debugs more vrf aware.

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-04-12 21:03:29 +02:00
David Lamparter c0d4a6d852
Merge pull request #5928 from xThaid/rt_link_cleanup
zebra: make common function for RTM_NEWNEIGH calls
2020-04-08 15:38:46 +02:00
Mark Stapp bf1626a6b1 zebra: clean up a debug and an api in netlink code
Simplify the netlink nexthop api; clean up a debug too.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-03-27 09:37:02 -04:00
Stephen Worley 13e0321ac9 zebra: remove unnecessary cmd = check
In the netlink code for determining whether to set
a src on the route, we check if the cmd=NEW_ROUTE
but its not possible for this to ever be anything
but a new route since we do a goto skip further up
if its a DEL_ROUTE cmd.

So remove this unnecessary check.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-03-26 10:39:16 -04:00
Stephen Worley d8bfd8dc9a zebra: determine src when using nexthop objects
Determine src based on nexthop data even when we are using
kernel nexthop objects.

Before, we were entirely skipping this step and just sending the
nexthop ID, ignoring src determination.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-03-26 10:37:51 -04:00
Stephen Worley 762288f50f zebra: abstract route src determiniation into func
Abstraction the route src determination from a nexthop in the
netlink code into a function for both singlepath and mutlipath
to call.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-03-26 10:37:40 -04:00
David Lamparter d6951e5ef9 *: remove tabs from log messages
Some logging systems are, er, "allergic" to tabs in log messages.
(RFC5424: "The syslog application SHOULD avoid octet values below 32")

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2020-03-24 18:47:12 +01:00
Jakub Urbańczyk 340845e2b5 zebra: make common function for RTM_NEWNEIGH calls
We currently have netlink_neigh_update_ctx,
netlink_vxlan_flood_update_ctx and netlink_macfdb_update_ctx
all of which do slightly different RTM_NEWNEIGH calls into
the kernel. After this change, there will be one common
function.

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-03-21 19:38:18 +01:00
Donald Sharp 9a0132a577 zebra: Modify some route install debugs to allow us to understand a bit better
1) When programming a nhg id to the kernel we had no debug of that
is what we are doing.

2) Add debugs to all nexthop information to allow us to follow
which prefix we are talking about.  This is especially
useful when dealing with a large number of routes and
you want to grep out one or two too see what is going on.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-03-20 18:15:33 -04:00
vivek 8d27e1aaac zebra: Install nexthop's weight for IPv4 routes with IPv6 next hops
Ensure that any weight associated with the next hop is installed for
IPv4 routes with IPv6 next hops too.
Updates: lib, zebra: Allow for installation of a weighted nexthop

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2020-03-17 19:25:13 -07:00
Donald Sharp f61182b931
Merge pull request #5985 from Naveenaidu/5984-cleanup-is_selfroute
zebra/rt_netlink.c: Clean is_selfroute function
2020-03-12 19:19:53 -04:00
Naveen Naidu 6a6d11a33b zebra/rt_netlink.c: Clean is_selfroute function
The return type of is_selfroute function is changed from int to bool.
Also remove the redundant invoking of the is_selfroute function in the
calling function netlink_route_change_read_unicast

Fixes: https://github.com/FRRouting/frr/issues/5984

Signed-off-by: Naveen Naidu <naveennaidu479@gmail.com>
2020-03-12 00:37:21 +05:30
vivek 4b3f26f4c9 zebra: Readd special flood MAC upon del notification
Readd the special MAC that represents the flood (head-end replication) entry
for EVPN-VxLAN upon getting a delete notification for it.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Chirag Shah <chirag@cumulusnetworks.com>

Ticket:  CM-25797
Ticket: CM-26238
Testing Done:
1. evpn-min, evpn-smoke - results summarized in CM-25798
2020-03-10 10:02:43 -04:00
Chirag Shah 7c26c12106 zebra: add debug in specific neigh fetch
add debug trace in specific neigh request send api
to help debug an issue where synchronous response parse
returns with NLMSG_DONE where there is no ipv6 neigh received.
the count value is set to 1 because the request contained
a spcific neigh.

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-03-10 09:59:56 -04:00
Donatas Abraitis 0d6f7fd6fd *: Replace sizeof something to sizeof(something)
Satisfy checkpatch.pl requirements (check for sizeof without parenthesis)

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-08 21:44:53 +02:00
Donatas Abraitis 15569c58f8 *: Replace __PRETTY_FUNCTION__/__FUNCTION__ to __func__
Just keep the code cool.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-03-05 20:23:23 +02:00
Donatas Abraitis 975a328e2e *: Replace s_addr 0 => INADDR_ANY
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-06 09:00:12 +02:00
Russ White 05d0c66d8f
Merge pull request #5737 from mjstapp/zebra_disable_kern_nhs
zebra: add config to disable use of kernel nexthops
2020-02-04 08:12:34 -05:00
Donald Sharp 88cafda739 zebra: nexthop groups vrf's are only a function of namespaces
Nexthop groups as a whole do not make sense to have a vrf'ness
As that you can have a arbitrary number of nexthops that point
to separate vrf's.

Modify the code to make this distinction, by clearly delineating
the line between the nhg and the nexthop a bit better.
Nexthop groups having a vrf_id only make sense if you are using
network namespaces to represent them.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-01-31 08:45:51 -05:00
Mark Stapp 7c99d51beb zebra: add config to disable use of kernel nexthops
Add a config that disables use of kernel-level nexthop ids.
Currently, zebra always uses nexthop ids if the kernel supports
them.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2020-01-28 11:00:42 -05:00
Donald Sharp 946de1b95a bgpd, ospfd, zebra: Do not use 0 as VRF_DEFAULT
Explicitly spell out what we are trying to do.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-01-15 08:29:36 -05:00
Hiroki Shirokura 760f39dc08 zebra: fix kernel-route's deletion on vrf
zebra can catch the kernel's route deletion by netlink.
but current FRR can't delete kernel-route on vrf(l3mdev)
when kernel operator delete the route on out-side of FRR.
It looks problem about kernel-route deletion.

This problem is caused around _nexthop_cmp_no_labels(nh1,nh2)
that checks the each nexthop's member 'vrf_id'.
And _nexthop_cmp_no_labels's caller doesn't set the vrf_id
of nexthop structure. This commit fix that case.

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
2019-12-23 15:25:12 +09:00
Stephen Worley 62d2ecb2f2 zebra: set RTNH_F_ONLINK in nexthop creation
We were not setting the RTNH_F_ONLINK flag where appropriate
when creating nexthop objects in the kernel.

Set it on the nhmsg.nh_flags netlink message.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-12-17 14:24:22 -05:00
Donald Sharp df7fb5800b lib, zebra: Allow for installation of a weighted nexthop
Linux has the idea of allowing a weight to be sent
down as part of a nexthop group to allow the kernel
to weight particular nexthop paths a bit more or less
than others.

See:
http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html

Allow for installation into the kernel using the weight attribute
associated with the nexthop.

This code is foundational in that it just sets up the ability
to do this, we do not use it yet.  Further commits will
allow for the pass through of this data from upper level protocols.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-12-09 13:37:37 -05:00
Donald Sharp e302caaa81
Merge pull request #5416 from mjstapp/re_nhe_pointer
lib,zebra: use shared nexthop-group in route_entry
2019-12-04 14:11:04 -05:00
Mark Stapp 0eb97b860d lib,zebra: use nhg_hash_entry pointer in route_entry
Replace the existing list of nexthops (via a nexthop_group
struct) in the route_entry with a direct pointer to zebra's
new shared group (from zebra_nhg.h). This allows more
direct access to that shared group and the info it carries.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-12-04 08:13:52 -05:00
David Lamparter 2b64873d24 *: generously apply const
const const const your boat, merrily down the stream...

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-02 15:01:29 +01:00
Donald Sharp 207c668368 zebra: Allow zebra to install nexthop groups into linux kernel
This reverts commit 7d5bb02b1a.

Allow zebra to actually maintain the nexthop group in the
linux kernel.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-11-11 09:49:00 -05:00
Donald Sharp 7134ba7060 zebra: Fix some nhg SA issues found in latest Coverity
Fix 2 Coverity issues:
1) zebra_nhg.c -> all paths in nhg_ctx_process_finish have
already deref'ed the ctx pointer no need for a test of it

2) the **ifp pointer passed in may be NULL.  Prevent an accidental
deref if calling function does not pass in a ifp pointer.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-10-28 20:30:06 -04:00
Stephen Worley f3354e1612 zebra: rt_netlink nexthop handling checkpatch
Checkpatch was complaining because this code was extending
beyond 80 characters on a couple lines. Adjusted a conditional
tree to fix that.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:44 -04:00
Stephen Worley 5a935f79d5 zebra: Guard nexthop group overflow read
Guard against an overflow read when processing
nexthop groups from netlink. Add a check to ensure
we don't try to write passed the array size.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:44 -04:00
Stephen Worley 40a2a6cdd3 zebra: Add DPLANE_NEIGH and DPLANE_VTEP to nhg cases
Add DPLANE_OP_NEIGH and DPLANE_OP_VTEP to nhg dplane
handler's switch statements.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:43 -04:00
Stephen Worley fec211ad95 zebra: Zebra nexthop group re-work checkpatch fixes
Checkpatch fixes for the zebra nexthop group re-work.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:43 -04:00
Stephen Worley 7d5bb02b1a zebra: Force off kernel nexthop group API for now
Force off kernel nexthop group API for now. Will re-enable
after suffient testing.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:43 -04:00
Stephen Worley 8d03bc501b zebra: Handle nhg_hash_entry encaps/more debugging
Add code for handling nexthop group hash entry encaps
and sending them to the kernel. Add some more debugging
information for the encaps and groups in general.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:42 -04:00
Stephen Worley b7537db639 zebra: Add common netlink mpls stack building path
There was some code copypasta for mpls stack building in the
netlink install path. Reduced that to a common function.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:42 -04:00
Stephen Worley 6e72876478 zebra: TODO for hanlding blackhole attr exclusive
Add a TODO statement for handling the exclusiveness
of blackhole attributes.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:42 -04:00
Stephen Worley bc541126e4 zebra: Use nexthop object id on route delete
When we receive a route delete from the kernel and it
contains a nexthop object id, use that to match against
route gateways with instead of explicit nexthops.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:42 -04:00
Stephen Worley 815059466c zebra: Move the supports_nh bool to a better place
Move the supports_nh bool indicating whether the kernel we are
using supports nexthop objects into the netlink kernel interface
itself. Since only linux and netlink support nexthop object APIs
for now this is fine.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:41 -04:00
Stephen Worley 9a1588c4ce zebra: Add handling for kernel del/update nexthop
Add handling for delete/update nexthop object messages from the
kernel.

If someone deletes a nexthop object we are still using, send it back
down. If the someone updates a nexthop we are using, replace that nexthop
with ours. Routes are referencing this nexthop object ID and we resolved
it ourselves, so we should force the other `someone` to submit to our
will.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:41 -04:00
Stephen Worley 38e40db1c9 zebra: Sweep our nexthop objects out on restart
On restart, if we failed to remove any nexthop objects due
to a kill -9 or such event, sweep them if we aren't using them.
Add a proto field to handle this and remove the is_kernel bool.

Add a dupicate flag that indicates this nexthop group is only
present in our ID hashtable. It is a dupicate nexthop we received
from the kernel, therefore we cannot hash on it.

Make the idcounter globally accessible so that kernel updates
increment it as soon as we receive them, not when we handle them.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:41 -04:00
Stephen Worley 428b4c0a5d zebra: Give installed nhe's the zebra proto
Give all nhg_hash_entrys we install into the kernel
as nexthop objects a defined proto matching the zebra
rib table one. This makes sense since nhe's are proto-independent
and determined exclusively in zebra.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:41 -04:00
Stephen Worley 98cda54a95 zebra: Add recursive functionality to NHE's
Add the ability to recursively resolve nexthop group hash entries
and resolve them when sending to the kernel.

When copying over nexthops into an NHE, copy resolved info as well.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:40 -04:00
Stephen Worley de3f548819 zebra: Use NHE id on kernel route sends
If the kernel supports nexthop objects, send the route
using an nhg_hash_entry ID instead.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:40 -04:00
Stephen Worley a6e6a6d825 zebra: Fix nhg ifindex setting and checking
We were only setting and checking the ifindex if
the nexthop had an *_IFINDEX type. However, when nexthop
active checking is done, the non-*_IFINDEX types can also
obtain a nexthop with an ifindex and are thus valid too.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:40 -04:00
Stephen Worley e22e80010e zebra: Use a nhe context dataplane and rib metaq
We will use a nhe context for dataplane interaction with
nextho group hash entries.

New nhe's from the kernel will be put into a group array
if they are a group and queued on the rib metaq to be processed
later.

New nhe's sent to the kernel will be set on the dataplane context
with approprate ID's in the group array if needed.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:40 -04:00
Stephen Worley ddaee0c7d3 zebra: Remove uneeded freeing helper function
Removing this function since the new paradigm
of everything just being nhg_connected structs
makes it not make a lot of sense.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley 7b683a96e4 zebra: Put nhe ifp setting inside alloc
Put the setting of the ifp on a nexthop group hash
entry into the zebra_nhg_alloc() function. It should
only be added if its not a group/recursive (it doesn't
have any depends) and its nexthop type has an ifindex.

This also provides functionality for proto-side ifp
setting.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley bbb3940ed1 zebra: VRF ID should be null if a nexthop group
A nexthop group should not have a VRF ID. Only individual
nexthops need to be using a VRF. Fixed this both kernel and
proto side.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley fe593b781d zebra: Re-organize/expose nhg_connected
Re-organize and expose the nhg_connected functions so that
it can be used outside zebra_nhg.c. And then abstract those
into zebra_nhg_depends_* and zebra_nhg_depenents_* functons.

Switch the ifp struct to use an RB tree for its dependents,
making use of the nhg_connected functions.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley a15d4c0089 zebra: Abstract the RB nodes/add dependents tree
Create a nhg_depenents tree that will function as a way
to get back pointers for NHE's depending on it.

Abstract the RB nodes into nhg_connected for both depends and
dependents. This same struct is used for both.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley 0c8215cbab zebra,lib: Refactor depends to RB tree
Refactor the depends to use an RB tree instead of a list.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley 20822f9d2e zebra: Add equivalence function for nhg_depends
Add a helper function to allow us to check if two
nhg_hash_entry's dependency lists are equal.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:39 -04:00
Stephen Worley fdee485ad0 zebra: Make kernel debug nexthop standardized
Make the the kernel debug zlog for nexthop messages from the
kernel more aligned with the route message kernel debug zlog.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley 2d6cd1f007 zebra: Always copy nhg and depends on nhe alloc
Changed our alloc function to just copy the nhg and
nhg_depends. This makes the zebra_nhg_find code a
little bit cleaner, hopefully preventing bugs.

The only issue with this is that it makes us have to loop
over the nexthops in a group an extra time for the copies.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley 565ce0d3c7 zebra: Add functionality to send groups to kernel
Add functionality to allow us to send nexthop groups
to the kernel. It creates a nexthop_grp array based on
the dependency list in the nhg_hash_entry and then shoves
that into the netlink message.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley 55eeb2ae7f zebra: Make nexthop group vrf VRF_DEFAULT
Nexthop groups can have nexthops in different vrf's. So,
let's make the group vrf_id just be VRF_DEFAULT for hash
lookup purposes.

Set vrf_id to be VRF_DEFAULT for every message. If its a new
nextop, set the vrf to be the appropriate thing, otherwise
its a group and can just be left as default.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley 8e401b251f zebra: Refactor nexthop group creation code to use allocated memory
Simplify the code for nexthop hash entry creation. I made nexthop
hash entry creation expect the nexthop group and depends to always
be allocated before lookup. Before, it was only allocated if it had
dependencies. I think it makes the code a bit more readable to go
ahead an allocate even for single nexthops as well.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley 85f5e76175 zebra: Read in nexthop dependencies from the kernel
Add functionality to read in a group from the kernel,
create a hash entry for it, and add its nexthops to
its dependency list.

Further, we create its nhg struct separtely from this,
copying over any nexthops it should reference directly
into it.

Thus, we have two types for representation of the nexthop group:
	nhe->nhg_depends->[nhe, nhe, nhe]

	nhe->nhg->nexthop->nexthop->nexthop

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley a3267f8b6e zebra: Check if a nexthop was added to the nhg
Before doing anything with our tables, less make sure
we even added anything to the group.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley e8b0e4201e zebra: Add afi value for all nexthops sent/received
Since nexthops are always going to need to be address family
specific unless they are only a group, we have to address
this when we receive and send them.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley c4239c05c0 zebra: Make bad address family log message more clear
The message for an invalid address family on a nexthop gateway did
not specify that is what for the gateway specifically.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:38 -04:00
Stephen Worley f44088c33e zebra: Fix where the flags are set for new nexthop entries
We were setting the flags in a couple different places for
nexthop entries.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 2614bf8764 zebra: Add ifp to zebra-side rib_add
Add an interface pointer for an nexthop group hash entry
when we are getting a rib_add for a new route.

Also, add the interface index to the `show nexthop-group` command.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 8c0a24c14e zebra: Add new nexthops to the interface nexthop hash entry list
When we get a new nexthop and find the interface associated
with it, add this nexthop to the interface's zebra interface
info nexthop hash entry list.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley bbb322f292 zebra: Make route entry nexthop groups point to our hash entry
Make our route entry struct's re->ng nexthop group pointer
just point to the nhe->nhg nexthop hash entry nexthop group.
This will allow updates to the nexthop itself to propogate
to our routes immediately.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 8032b71737 zebra: Update rib_add to take a nexthop ID
Add a parameter to the rib_add function so that it takes
a nexthop ID from the kernel if one is passed along
with the route.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 77a44d94f8 zebra: Put unicast nexthop parsing into its own function
Move the nexthop unicast parsing into its own function
to improve code readability. It was getting a bit too
indented.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley fcc89a9cfc zebra: Parse in nexthop ID information from new routes
Add parsing code for nexthop object ID's when we get a
route. When we get a new route with the new kernel, it
will come with a nexthop ID and the nexthop full info.
We should just reference by ID if it exists and point
to the nexthop hash entry that matches it.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 044e54d1eb zebra: Set the INSTALLED flags on nexthop entries we receive
Add SETs to the flags on nexthop entries to mark
 installed/uninstalled from the kernel.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 75f8505d2e zebra: Force re-install nexthop if still referenced
Added functionality so that when we receive a RTM_DELNEXTHOP
for a nhg_hash_entry that is still being referenced by
a route, we immediately push it back to the kernel.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 60e0eaee23 zebra: Return proper status result
We were ignoring the status result interger from
the netlink request and message parsing and just
returning 0. Fixed this to return the result of the last one.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley 4f096395c1 zebra: Use the dest prefix for determining nexthop family
Device only nexthops still need an address family associated
with them. Decided to get this from the destination prefix on it.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00
Stephen Worley e1536fce85 zebra: Add debug statement for nexthop netlink messages
Add the zebra kernel debug statement for nexthop messages
so we can see them via vtysh.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-25 11:13:37 -04:00