Commit graph

59 commits

Author SHA1 Message Date
Quentin Young af4c27286d *: rename zlog_fer -> flog_err
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Quentin Young 43e52561b4 zebra, lib: error references for zebra
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Donald Sharp 174482ef37 bgpd, lib, zebra: Convert LIB_ERR_PRIVILEGES
For all the places we zlog_err about raising/lowering privileges, use
zlog_ferr.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
F. Aragon e940478c02
zebra: socket fd check (Coverity 1472236)
Signed-off-by: F. Aragon <paco@voltanet.io>
2018-08-03 18:16:09 +02:00
Russ White 155d6d4415
Merge pull request #2696 from sworleys/Netlink-Fuzz
zebra: Add code for fuzzing netlink
2018-07-29 08:33:43 -04:00
Stephen Worley e6a0e0d141 zebra: Check for netlink message next fault
NLMSG_NEXT decrements the buffer length (status) by
the header msg length (nlmsg_len) everytime its called.
If nlmsg_len isn't accurate and set to be larger than
what it should represent, it will cause status to
decrement passed 0. This makes NLMSG_NEXT return a
pointer that references an inaccessible address.
When that is passed to NLMSG_OK, it segfaults.

Add a check to verify that there is still something to read
before we try to.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-26 16:46:57 -04:00
Stephen Worley 29bf7b0b67 Style, don't initialize netlink_read flag
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-26 14:34:28 -04:00
Stephen Worley ef593eff00 zebra: Make fuzzer code use default netlink socket
Change the fuzzing code so that it fakes data from
the listening socket rather than using its own pseudo one.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-26 14:32:50 -04:00
Stephen Worley acfa8927f9 Refactor code for new fuzzing netlink flag
Changed the configure flag used by netlink fuzzing
and refactored code accordingly.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-24 13:39:25 -04:00
Stephen Worley bd7891fd70 Style for Add code for fuzzing netlink
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-23 11:25:31 -04:00
Stephen Worley 81a2f870dd zebra: Add code for fuzzing netlink
This code allows you to fuzz the netlink listening socket
in zebra by --enable-fuzzing and passing the -w [FILE]
option when running zebra.

File collection is stored in /var/run/frr/netlink_*
where each number is just a counter to keep the
files distinct.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
2018-07-21 00:06:38 -04:00
Donald Sharp 8c85e8ea92 zebra: Remove need for ACK for netlink messages
Kernel requests via netlink are synchronous.

Therefore we do not need to specify a need for a ACK and
we can make the netlink_cmd NONBLOCKING

1) If the netlink message is going to cause an error
we will still get one.  Since results from the kernel
are synchronous we will get the error message on the
netlink_cmd socket and handle it

2) If the netlink message is going to send more than
one packet we will still get them all.  Since the results
from the kernel are synchronous we will receive all data.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-07-12 22:43:06 -04:00
Donald Sharp 19d5a4fead zebra: Listen to error codes from netlink_socket
When creating a netlink_socket, listen to error
codes and abandon ship if it crashes and burns.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-07-12 22:43:06 -04:00
Mark Stapp 86391e5659 zebra, libs: use const prefix ptrs in apis
Add 'const' to prefix args to several zebra route update,
redistribution, and route owner notification apis.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2018-07-11 09:22:49 -04:00
F. Aragon e36e5b569c
isisd zebra: dead code (Clang scan)
This correction fixes two bugs detected by Clang scan:

Bug Group: Dead store

Bug Type: Dead assignment
File: zebra/kernel_netlink.c
Function: netlink_parse_extended_ack
Line: 548

Bug Type: Dead increment
File: isisd/isis_lsp.c
Function: lsp_bits2string
Line: 625

Signed-off-by: F. Aragon <paco@voltanet.io>
2018-06-29 17:47:05 +02:00
Donald Sharp 6ca7b664b5 zebra: Log how we got to this failure.
When a filter function fails to work correctly, we get an
error message that something has gone wrong.  Unfortunately
we may not have any clues as to where the decode failure
happened.  Add a backtrace to give us a clue.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-06-25 10:02:48 -04:00
Donald Sharp 5d307d5d3a zebra: Add extended Ack error parsing to FRR
Add code to request and read in extended ack information
to provide a bit more context of what went wrong when
a failure is detected in the kernel.

Example of a failed delete:
Jun 20 21:19:25 robot zebra[11878]: Extended Error: Invalid prefix for given prefix length
Jun 20 21:19:25 robot zebra[11878]: netlink-cmd (NS 0) error: Invalid argument, type=RTM_DELROUTE(25), seq=8, pid=4078403400
Jun 20 21:19:25 robot zebra[11878]: 0:4.3.2.0/24: Route Deletion failure

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-06-21 08:07:30 -04:00
Russ White e73f79ac4c
Merge pull request #2283 from donaldsharp/ignore_some_more
zebra: netlink cleanups
2018-05-27 11:02:15 -04:00
Donald Sharp d4d71f1133 tools, zebra: Use different protocol value for our statics
The re-use of RTPROT_STATIC has caused too many collisions
where other legitimate route sources are causing us to
believe we are the originator of the route.  Modify
the code so that if another protocol inserts RTPROT_STATIC
we will assume it's a Kernel Route.

Fixes: #2293
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-26 08:46:13 +02:00
Donald Sharp 026a316f2c zebra: Fix RULE notification netlink messages
Fix the code so that we would actually start receiving
RULE netlink notifications.

The Kernel expects the long long to be a bit field
value, while the newer netlink message types are
an enum.  So we need to convert the message type
number to a bit position and set that value.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-24 09:14:43 -04: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
Donald Sharp 783827ae61 zebra: Move where we check for non-kernel netlink messages
Move where we check for non-kernel netlink messages to
a slightly earlier spot.  This will allow in subsuquent
commits the removal of an extra parameter that needs to
be passed around.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-24 09:14:43 -04:00
Donald Sharp 3575d9e866 zebra: Ignore most netlink notifications from ourselves
The BPF filter was an exclusion list of netlink messages
we did not want to receive from our self.  The problem
with this is that the exclusion list was and will be
ever growing.  So switch the test around to an inclusion
list since it is shorter and not growing.  Right
now this is RTM_NEWADDR and RTM_DELADDR.

Change some of the debug messages to error messages
so that when something slips through and it is unexpected
during development we will see the problem.

Also try to improve the documentation about what
the filter is doing and leave some breadcrumbs for
future developers to know where to change code
when new functionality is added.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-24 09:13:05 -04:00
vivek 9ed7517b1a zebra: Increase recvmsg buffer size for picking up netlink messages
Netlink messages from the kernel need to be received in a buffer larger
than 8K in order to handle some types of info - for example, the VLAN
information. Define a separate size for receive and set it to 32K, which
is the value used by other netlink receivers like iproute2.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-08 19:24:15 -04:00
Quentin Young d7c0a89a3a
*: use C99 standard fixed-width integer types
The following types are nonstandard:
- u_char
- u_short
- u_int
- u_long
- u_int8_t
- u_int16_t
- u_int32_t

Replace them with the C99 standard types:
- uint8_t
- unsigned short
- unsigned int
- unsigned long
- uint8_t
- uint16_t
- uint32_t

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-27 15:13:34 -04: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
Philippe Guibert fe533c564e zebra: socket operations stick to namespace if necessary
Upon following calls: interface poll, address poll, route poll, and
ICMPv6 handling, each new Namespace is being parsed. For that, the
socket operations need to switch from one NS to one other, to get the
necessary information.

As of now, there is a crash when dumping interfaces, through show
running-config.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Donald Sharp 05f7f5db89 zebra: Make zserv.h the true api for zapi northbound
zserv.c had a grab bag of function declarations that
did not belong in it.  Move those to where they better
belong.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-12-13 07:57:15 -05:00
Donald Sharp cbaca6a144 zebra: Fix valgrind report of unintialized data
When calling the kernel we are not properly initializing
iov and msg on function startup.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-02 10:42:53 -04:00
Jorge Boncompte 109b90f525 zebra: hide netlink warning message
Signed-off-by: Jorge Boncompte <jbonor@gmail.com>
2017-08-04 10:19:36 +02:00
David Lamparter ddfeb48652 build: zebra: remove *_method Makefile hacks
replace with preprocessor checks in source files.  Much simpler...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-31 23:03:30 +02:00
David Lamparter 9d303b37d7 Revert "*: reindent pt. 2"
This reverts commit c14777c6bf.

clang 5 is not widely available enough for people to indent with.  This
is particularly problematic when rebasing/adjusting branches.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-22 14:52:33 +02:00
whitespace / reindent c14777c6bf
*: reindent pt. 2
w/ clang 5

* reflow comments
* struct members go 1 per line
* binpack algo was adjusted
2017-07-17 15:26:02 -04:00
whitespace / reindent d62a17aede *: reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17 14:04:07 +02:00
vivek 2232a77c2b zebra: MAC and Neighbor (ARP/ND) handling
Implement handling of MACs and Neighbors (ARP/ND entries) in zebra:
- MAC and Neighbor database handlers
- Read MACs and Neighbors from the kernel, when needed and create
entries in zebra's MAC and Neighbor databases.
- Handle add/update/delete notifications from the kernel for MACs and
Neighbors and update zebra's database appropriately
- Inform locally learnt MACs and Neighbors to client
- Handle MACIP add/delete from client and install appriporiate entries
into the kernel
- Since Neighbor entries will be installed on an SVI, implement the
needed mappings

NOTE: kernel interface is only implemented for Linux/netlink

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
2017-07-12 12:29:25 -04:00
David Lamparter 21bb7c8774 Merge commit '3d22338f04d9554fa' into evpn-prep
Conflicts:
	lib/Makefile.am

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-10 22:15:19 +02:00
Quentin Young 56b4067930 *: simplify log message lookup
log.c provides functionality for associating a constant (typically a
protocol constant) with a string and finding the string given the
constant. However this is highly delicate code that is extremely prone
to stack overflows and off-by-one's due to requiring the developer to
always remember to update the array size constant and to do so correctly
which, as shown by example, is never a good idea.b

The original goal of this code was to try to implement lookups in O(1)
time without a linear search through the message array. Since this code
is used 99% of the time for debugs, it's worth the 5-6 additional cmp's
worst case if it means we avoid explitable bugs due to oversights...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-21 15:22:21 +00:00
Donald Sharp 8755598a08 zebra: Store commonly used values instead of regenerating
the ipv4_ll address used for 5549 routes does not need
to be figured out every single time that we attempt
to install/remove a route of that type.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-25 21:11:24 -04:00
vivek 289602d73d zebra: Format netlink requests correctly
When zebra issues read (GET) requests to the kernel using the netlink
interface, it is incorrect to format all of them in a generic manner
using 'struct ifinfomsg' or 'struct rtgenmsg'. Rather, messages for a
particular entity (e.g., routes) should use the corresponding structure
for encoding (e.g., 'struct rtmsg'). Of course, this has to correlate
with what the kernel expects.

In the absence of this, there is the possibility of sending extraneous
information in the request which the kernel wouldn't like.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   David Ahern <dsa@cumulusnetworks.com>
2017-05-25 10:20:03 -07:00
vivek 80e7e4077d zebra: Set nlmsg_pid in netlink_talk()
While it is not essential to set this, it seems a good thing to do.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2017-05-25 10:20:03 -07:00
vivek bbc16902a6 zebra: New API for filling netlink attribute
Define addattr16().

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2017-05-25 10:20:03 -07:00
David Lamparter 896014f4bc *: make consistent & update GPLv2 file headers
The FSF's address changed, and we had a mixture of comment styles for
the GPL file header.  (The style with * at the beginning won out with
580 to 141 in existing files.)

Note: I've intentionally left intact other "variations" of the copyright
header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15 16:37:41 +02:00
Donald Sharp 64a4bd09f0 zebra: Fix kernel netlink hex dump of information
1) Fix the kernel send and recv hex dump of what we
are sending to the kernel

2) When configuring the debugs under 'conf t' display
it too.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-11 11:44:07 -04:00
Quentin Young 66e78ae64b *: update thread_add_* calls
Pass pointer to pointer instead of assigning by return value. See
previous commit message.

To ensure that the behavior stays functionally correct, any assignments
with the result of a thread_add* function have been transformed to set
the pointer to null before passing it. These can be removed wherever the
pointer is known to already be null.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-09 20:44:22 +00:00
Quentin Young ffa2c8986d *: remove THREAD_ON macros, add nullity check
The way thread.c is written, a caller who wishes to be able to cancel a
thread or avoid scheduling it twice must keep a reference to the thread.
Typically this is done with a long lived pointer whose value is checked
for null in order to know if the thread is currently scheduled.  The
check-and-schedule idiom is so common that several wrapper macros in
thread.h existed solely to provide it.

This patch removes those macros and adds a new parameter to all
thread_add_* functions which is a pointer to the struct thread * to
store the result of a scheduling call. If the value passed is non-null,
the thread will only be scheduled if the value is null. This helps with
consistency.

A Coccinelle spatch has been used to transform code of the form:

  if (t == NULL)
    t = thread_add_* (...)

to the form

  thread_add_* (..., &t)

The THREAD_ON macros have also been transformed to the underlying
thread.c calls.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-05-09 20:44:19 +00:00
Dinesh G Dutt 23b1f33451 Add source of route as protocol string in ip route pushed into kernel
Ticket: CM-14313
Reviewed By:
Testing Done: bgpmin, ospfmin, bgp_kitchen_sink_test

'ip route show' displays all routes as belonging to protocol zebra.
The user has to run an additional command (in vtysh) to get the actual
source of a route (bgp/ospf/static etc.). This patch addresses that by
pushing the appropriate protocol string into the protocol field of the
netlink route update message. Now you can see routes with the correct
origin as well as filter on them (ip route show proto ospf).

'ospf' is used for both IPv4 and IPv6 routes, even though the OSPF
version is different in both cases.

Sample output (old):
9.9.12.13 via 69.254.2.38 dev swp3.2  proto zebra  metric 20
9.9.13.3  proto zebra  metric 20
        nexthop via 69.254.2.30  dev swp1.2 weight 1
        nexthop via 69.254.2.34  dev swp2.2 weight 1
        nexthop via 69.254.2.38  dev swp3.2 weight 1

Sample output (new):
9.9.12.13 via 69.254.2.38 dev swp3.2  proto bgp  metric 20
9.9.13.3  proto bgp  metric 20
        nexthop via 69.254.2.30  dev swp1.2 weight 1
        nexthop via 69.254.2.34  dev swp2.2 weight 1
        nexthop via 69.254.2.38  dev swp3.2 weight 1
2017-04-20 21:24:31 -04:00
David Lamparter 4525281af1 *: get rid of zlog(*, LOG_LEVEL, ...)
Result of running the following Coccinelle patch + fixups:
<<EOF
/* long-forms: zlog(NULL, <level>, ...)
 *    =>       zlog_level(...)
 */

@@
expression list args;
@@
- zlog(NULL, LOG_DEBUG, args)
+ zlog_debug(args)

@@
expression list args;
@@
- zlog(NULL, LOG_NOTICE, args)
+ zlog_notice(args)

@@
expression list args;
@@
- zlog(NULL, LOG_INFO, args)
+ zlog_info(args)

@@
expression list args;
@@
- zlog(NULL, LOG_WARNING, args)
+ zlog_warn(args)

@@
expression list args;
@@
- zlog(NULL, LOG_ERR, args)
+ zlog_err(args)

/* long-forms: zlog(base->log, <level>, ...)
 *    =>       zlog_level(...)
 */

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_DEBUG, args)
+ zlog_debug(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_NOTICE, args)
+ zlog_notice(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_INFO, args)
+ zlog_info(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_WARNING, args)
+ zlog_warn(args)

@@
expression base;
expression list args;
@@
- zlog(base->log, LOG_ERR, args)
+ zlog_err(args)

EOF

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-03-08 00:15:39 +01:00
Donald Sharp 936ebf0a2d zebra: Add knowledge of whether or not we are acting under startup conditions
The reading if unicast routes from the kernel acts subtly differently
between reading in the routes from the kernel on startup and
reading a new route or getting a response for a route.

Add startup flag(currently ignored) so that we can start
consolidating the functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-03-01 08:08:05 -05:00
Renato Westphal e2a534d557 zebra: fix wrong asserts in netlink code
These new asserts were causing zebra to abort when trying to install
MPLS labeled routes.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-02-01 12:48:02 -02:00
Donald Sharp f909c67393 zebra: Fix compiles for non-linux based systems
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-01-17 21:39:05 -05:00