Commit graph

49 commits

Author SHA1 Message Date
Donald Sharp 315aa6cde4 *: Remove netlink headers from lib/zebra.h
The headers associated with netlink code
really only belong in those that need it.
Move these headers out of lib/zebra.h and
into more appropriate places.  bgp's usage
of the RT_TABLE_XXX defines are probably not
appropriate and will be cleaned up in future
commits.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-07 06:46:19 -05:00
Mark Stapp 7aabdc677a zebra: ignore iprule requests for unsupported actions
Only attempt to install in netlink iprules that include supported
actions; ignore requests with actions that aren't supported by
netlink.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-09-08 10:23:20 -04:00
G. Paul Ziemba 5572f45d51 pbrd: PBR_FILTER_DSFIELD -> {PBR_FILTER_DSCP,PBR_FILTER_ECN}
DSCP and ECN matching are configured independently. Maintain
    these values in independent fields in pbrd, zapi, and zebra.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2023-08-08 10:18:22 -07:00
Donald Sharp 605df8d44f zebra: Use zebra dplane for RTM link and addr
a) Move the reads of link and address information
into the dplane
b) Move the startup read of data into the dplane
as well.
c) Break up startup reading of the linux kernel data
into multiple phases.  As that we have implied ordering
of data that must be read first and if the dplane has
taken over some data reading then we must delay initial
read-in of other data.

Fixes: #13288
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-07-05 13:03:14 -04:00
Mark Stapp 4112baec9f pbrd, zebra: fix zapi and netlink rule encoding
In pbrd, don't encode a rule without a table. There are cases
where the zapi encoding was incorrect because the 4-octet
table id was missing. In zebra, mask off the ECN bits in the
TOS byte when encoding an iprule to match netlink's
expectation.

Signed-off-by: Mark Stapp <mjs@labn.net>
2023-06-12 16:39:26 -04:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Donald Sharp 1239b60c06 zebra: Add tracepoint for netlink_rule_change
Add a tracepoint for the netlink_rule_change function.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-04-20 09:43:47 -04:00
Donald Sharp 9bfadae860 zebra: Use a bool for startup indications
Let's not pass around an int startup when all we are doing
is true/falsing it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-04 20:26:38 -04:00
Donald Sharp 8ccbc778cf zebra: Add ability for dataplane code to understand rule ip protocols
The zebra dplane needs to be taught about the rule ip_proto that can
be installed.

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

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-07-08 11:12:47 -04:00
Stephen Worley e36ea40d3b zebra: derive rule family from src->dst->ipv4
Derive the rule family from src if available, otherwise
dst if available, otherwise assume ipv4. We only support
ipv4/ipv6 currently so it we cant tell from the src/dst
it must be ipv4 and likely a dsfield match.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
2020-12-18 11:53:18 -05:00
Donatas Abraitis 2dbe669bdf :* Convert prefix2str to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-22 09:07:41 +03:00
Donald Sharp 58a1d24924 bgpd, lib, pbrd, zebra: Pass by ifname
When installing rules pass by the interface name across
zapi.

This is being changed because we have a situation where
if you quickly create/destroy ephermeal interfaces under
linux the upper level protocol may be trying to add
a rule for a interface that does not quite exist
at the moment.  Since ip rules actually want the
interface name ( to handle just this sort of situation )
convert over to passing the interface name and storing
it and using it in zebra.

Ticket: CM-31042
Signed-off-by: Stephen Worley <sworley@nvidia.com>
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-09-11 20:04:45 -04:00
Jakub Urbańczyk 18f60fe999 zebra: remove old kernel one-update-at-a-time api
The old one is replaced by the api that is suitable for the batching.

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-08-10 21:57:04 +02:00
Jakub Urbańczyk 67e3369ed4 zebra: netlink message batching
Integrate existing functions with batching infrastructure.

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-08-10 21:42:43 +02:00
Russ White a90f46738a
Merge pull request #6730 from wesleycoakley/pbrd-dscp-ecn
DSCP / ECN-based PBR Matching
2020-07-23 12:08:38 -04:00
Donald Sharp dfbe3a2bd3 zebra: Silently ignore afi 128/129 for rules
We do not need to know anything about rules in afi 128/129
at this point in time.  Just note it with a zebra kernel
debug and move on.  This is not something that a operator
can do anything with and at this point in time FRR
does not care.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-07-16 20:59:33 -04:00
Wesley Coakley 01f23affdb pbrd, zebra, lib: DSCP / ECN-based PBR Matching
Extend PBR maps to discriminate by Differentiated Services Code Point and / or
Explicit Congestion Notification fields. These fields are used in the IP header
for classifying network traffic.

      0     1     2     3     4     5     6     7
    +-----+-----+-----+-----+-----+-----+-----+-----+
    |          DS FIELD, DSCP           | ECN FIELD |
    +-----+-----+-----+-----+-----+-----+-----+-----+
      DSCP: differentiated services codepoint
      ECN:  Explicit Congestion Notification

Signed-off-by: Wesley Coakley <wcoakley@nvidia.com>
Signed-off-by: Saurav Kumar Paul <saurav@cumulusnetworks.com>
2020-07-15 12:59:36 -04: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
Jakub Urbańczyk 99e387d583 zebra: separate code encoding netlink msg
Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-06-10 16:29:14 +02:00
Jakub Urbańczyk f62e5480ec zebra: convert ip rule installation to use dplane thread
* Implement new dataplane operations
 * Convert existing code to use dataplane context object
 * Modify function preparing netlink message to use dataplane
   context object

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
2020-06-10 16:18:45 +02: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
Stephen Worley ab35be755f zebra: read in and sweep rules on startup
On startup of zebra, read in all ipv4/ipv6 rules from
the kernel and remove any with the zebra proto.

If there are any, this means we failed to remove them
on shutdown due to a crash or something. Without this,
users have to manually remove them with iproute2 or some
such and its really annoying.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-04-10 11:05:06 -04:00
Stephen Worley b6d34c2609 zebra: set family on read in rule prefix
We were not setting the family for the prefix on the src/dst
IP of the rule.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-04-09 19:04:45 -04:00
Stephen Worley 3ae327cb96 zebra: define some explicit rule replace code paths
Define some explicit rule replace code paths into the dataplane
code and improve the handling around it/releasing the the old
rule from the hash table.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2020-04-09 13:37:55 -04: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
Stephen Worley b19d55d048 zebra: Don't bother ref'ing ifp in zebra_pbr_rule
If we only really use the ifp for the name, then
don't bother referencing the ifp. If that ifp is
freed, we don't expect zebra to handle the rules that
use it (that's pbrd's job), so it is going to be
pointing to unintialized memory when we decide to remove
that rule later. Thus, just keep the name in the data
and dont mess with pointer refs.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-15 15:39:49 -04:00
Stephen Worley b77a69bdc6 zebra: Use the rule ifindex as a hash key, not ifp
Use the ifindex value as a primary hash key/identifier, not
the ifp pointer. It is possible for that data to be freed
and then we would not be able to hash and find the rule entry
anymore. Using the ifindex, we can still find the rule even
if the interface is removed.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-10-15 15:03:46 -04:00
Donald Sharp f3dbec60f2 zebra: Send RTPROT_ZEBRA for netlink messages missing this data
Update neighbor entries and rule entries to have the RTPROT_ZEBRA
protocol value.  So we can tell where things come from.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-09-19 16:05:39 -04:00
Stephen Worley cc42104c35 zebra: Fix late memset of pbr rule in rule_netlink
We were memsetting zebra_pbr_rule struct after
we had already put some information in it. Also updated
the init of the struct to use braces instead of a
memset.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2019-04-09 10:35:11 -04:00
Philippe Guibert 15e6eed417 zebra: add fwmark information at netlink level
ip rule configuration is being equipped with extra log information for
fwmark information.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-01-29 14:15:51 +01:00
Mark Stapp ea1c14f680 zebra: Create zebra_dplane.c and .h
Add first sketchy 'dplane' files.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-09-19 18:29:55 -04:00
Quentin Young e914ccbe9c zebra: ZEBRA_[ERR|WARN] -> EC_ZEBRA
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13 19:23:29 +00:00
Quentin Young 9df414feeb zebra: flog_warn conversion
Convert Zebra to user error subsystem.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-06 20:56:38 +00:00
Stephen Worley 8122787440 zebra: Format log for address family check
Switched the address family check to use unsigned format.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-25 14:08:24 -04:00
Stephen Worley 8a1b681cba zebra: Add address family filters
The zebra netlink socket was attempting to read netlink
messages with invalid address families in a couple areas.
Added filters and warn messages.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-23 12:11:02 -04:00
Donald Sharp 9bdf861803 zebra: Add error messages in places where we have a decode problem
When we receive a netlink message from the kernel we have
handler functions for when we send a netlink command, if these
return a failure ( < 0 ) then we output that we had a parse
issue.  But if all we get is:

2018-06-21T23:47:45.298156+00:00 qct-ix1-08 zebra[1484]: netlink-cmd (NS 0) filter function error

Then it is not very useful to figure out *where* the error happened.

Add more error code when in a decode path to hopefully allow us
to figure out where this message is coming from.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-06-25 10:02:48 -04:00
Donald Sharp ebecd64913 zebra: Add knowledge of request success/failure for pbr rules
Add some nascent code to handle success/failure of the rule
installation.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-30 08:05:28 -04:00
Donald Sharp 215181cbf1 zebra: Rename SOUTHBOUND_XXX to DP_XXX
The SOUTHBOUND_XXX enum was named a bit poorly.
Let's use a bit better name for what we are trying to do.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-30 08:00:55 -04:00
Donald Sharp 68542a6da6
Merge pull request #2142 from pguibert6WIND/fs_zebra_complement
Flowspec complement : port support and policy routing per interface and plugin wrapper
2018-05-29 11:33:00 -04:00
Philippe Guibert 2bee7aae60 zebra: add netlink rule support for fwmark option
When a mark is set, incoming traffic having that mark set can be
redirected to a specific table identifier. This work is done through
netlink.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-05-25 15:49:38 +02:00
Donald Sharp 2414abd3b0 zebra: Remove unnecessary function parameter
The snl variable is no longer needed to be passed around, so
remove it from the calling path.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-24 09:14:43 -04:00
Philippe Guibert 5dd0722dcf zebra: adapt zebra_pbr_rule based with pbr_rule
In order to avoid duplicates functions, the zebra_pbr_rule structure
used by zebra to decode the zapi message, and send netlink messages, is
slightly modified. the structure is derived from pbr_rule, but it also
includes sock identifier that is used to send back information to the
daemon that did the request. Also, the ifp pointer is stored in that
structure.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-04-16 14:40:43 +02:00
Don Slice 49027ce856 pbrd: adjust/remove the rule correctly when dst and/or src removed
When the last match criteria was removed (dst-ip or src-ip), we were
not deleting the rule correctly for ipv6. This fix retains the
needed src-ip/dst-ip during the pbr_send_pbr_map process so the
appropriate information is available for the rule delete.

Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2018-04-06 13:22:43 -04:00
Donald Sharp a03219780f zebra: Make the ifp part of the rule structure
Every place we need to pass around the rule structure
we need to pass around the ifp as well.  Move it into
the structure.  This will also allow us to notify up
to higher level protocols that this worked properly
or not better too.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-03-09 11:07:41 -05:00
Donald Sharp 43fe6a2a73 zebra: Keep track of rules written
Keep track of rules written into the kernel.  This will
allow us to delete them on shutdown if we are not cleaned
up properly.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-03-09 11:07:41 -05:00
Donald Sharp fd71d73eb3 zebra: Cleanup a couple of api issues
1) use uint32_t instead of u_int32_t as we are supposed to
2) Consolidate priority into the rule.
3) Cleanup the api from this.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-03-09 11:07:41 -05:00
vivek 942bf97b13 *: PBR - netlink interaction and basic definitions
Implement netlink interactions for Policy Based Routing. This includes
APIs to install and uninstall rules and handle notifications from the
kernel related to rule addition or deletion. Various definitions are
added to facilitate this.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
2018-03-09 11:07:41 -05:00