Commit Graph

215 Commits

Author SHA1 Message Date
David Lamparter
3efd0893d0 *: un-split strings across lines
Remove mid-string line breaks, cf. workflow doc:

  .. [#tool_style_conflicts] For example, lines over 80 characters are allowed
     for text strings to make it possible to search the code for them: please
     see `Linux kernel style (breaking long lines and strings)
     <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_
     and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.

Scripted commit, idempotent to running:
```
python3 tools/stringmangle.py --unwrap `git ls-files | egrep '\.[ch]$'`
```

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-07-14 10:37:25 +02:00
Igor Ryzhov
cd980d0375 vtysh: return success from "no vrf" when VRF doesn't exist
It is possible that the same VRF exists in one daemon and doesn't exist
in another. In this case, "no vrf NAME" command execution will stop on
the first daemon without the VRF and it won't be possible to delete the
VRF from other daemons.

Such behavior can be reproduced with the following steps:
```
# ip link add test type vrf table 1
# vtysh -c "conf t" -c "vrf test" -c "ip route 1.1.1.1/32 blackhole"
# vtysh -c "show run"
...
vrf test
 ip route 1.1.1.1/32 blackhole
 exit-vrf
!
...
# ip link del test
# vtysh -c "conf t" -c "no vrf test"
% VRF test does not exist
# vtysh -c "show run"
...
vrf test
 ip route 1.1.1.1/32 blackhole
 exit-vrf
!
...
```

This commit fixes the issue by returning success from "no vrf" command
when VRF doesn't exist.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-07-09 19:20:32 +03:00
Renato Westphal
10bdc68f0c *: convert northbound callbacks to new error handling model
The northbound configuration callbacks should now print error
messages to the provided buffer (args->errmsg) instead of logging
them directly.  This will allow the northbound layer to forward the
error messages to the northbound clients in addition to logging them.

NOTE: many callbacks are returning errors without providing any
error message. This needs to be fixed long term.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-05-28 19:22:54 -03:00
Philippe Guibert
9d3555e06c zebra, lib: store relative default ns id in each namespace
to be able to retrieve the network namespace identifier for each
namespace, the ns id is stored in each ns context. For default
namespace, the netns id is the same as that value.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-05-18 14:11:03 +02:00
Renato Westphal
799a81df9d lib: update the CLI xpath index when exiting from the VRF node
All custom "exit-*" commands that exit from a YANG-modeled
CLI node need to use cmd_exit() to ensure the CLI xpath index
(vty->xpath_index) will be updated accordingly.

Fixes #6316.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-04-29 18:49:29 -03:00
Renato Westphal
60ee8be107 *: change the signature of the northbound callbacks to be more flexible
Having a fixed set of parameters for each northbound callback isn't a
good idea since it makes it difficult to add new parameters whenever
that becomes necessary, as several hundreds or thousands of existing
callbacks need to be updated accordingly.

To remediate this issue, this commit changes the signature of all
northbound callbacks to have a single parameter: a pointer to a
'nb_cb_x_args' structure (where x is different for each type
of callback). These structures encapsulate all real parameters
(both input and output) the callbacks need to have access to. And
adding a new parameter to a given callback is as simple as adding
a new field to the corresponding 'nb_cb_x_args' structure, without
needing to update any instance of that callback in any daemon.

This commit includes a .cocci semantic patch that can be used to
update old code to the new format automatically.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-04-23 10:14:32 -03:00
Donald Sharp
a83014ccd6
Merge pull request #6247 from FRRouting/nb_conversions
Merge nb_converions branch to master
2020-04-16 19:39:14 -04:00
Chirag Shah
8b4cb7a64b lib: convert vrf cmd to northbound config callback
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-04-16 08:00:18 -07:00
Chirag Shah
bc867a5d30 lib: vrf northbound callbacks
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-04-16 07:55:56 -07:00
David Lamparter
f4b8291fcb *: move CLI node names to cmd_node->name
And again for the name.  Why on earth would we centralize this, just so
people can forget to update it?

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:59 +02:00
David Lamparter
243895805a *: move CLI parent data to cmd_node->parent_node
Same as before, instead of shoving this into a big central list we can
just put the parent node in cmd_node.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter
612c2c15d8 *: remove second parameter on install_node()
There is really no reason to not put this in the cmd_node.

And while we're add it, rename from pointless ".func" to ".config_write".

[v2: fix forgotten ldpd config_write]

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter
249a771b63 *: remove cmd_node->vtysh
The only nodes that have this as 0 don't have a "->func" anyway, so the
entire thing is really just pointless.

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter
62b346eefa *: clean up cmd_node initializers
... and use named assignments everywhere (so I can change the struct.)

Signed-off-by: David Lamparter <equinox@diac24.net>
2020-04-16 12:53:00 +02:00
David Lamparter
feaabe472d
Merge pull request #5988 from xThaid/zebra_vrf_logs
zebra: Add vrf name and id to debugs
2020-04-14 12:52:31 +02:00
Quentin Young
f7d4592509 lib: work around enum issue in old gcc
I'd like to keep the explicit check here, but since underlying type of
enum is implementation defined, theres some inconsistency using -Wall
-Werror in older compilers here

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-13 17:03:42 -04:00
Quentin Young
6063ede092 lib: improve sanity check on vrf backend value
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-13 13:25:25 -04:00
Quentin Young
7239d3d9e6 lib: handle bogus VRF backend type
And use an enum...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-13 13:25:25 -04: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
Donatas Abraitis
c4efd0f423 *: Do not cast to the same type
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-04-08 17:15:06 +03: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
542e1aeb07
Merge pull request #5268 from qlyoung/vrrp-vrf
VRRP VRF support
2019-12-22 20:16:47 +02:00
Quentin Young
79a80af8b4 lib: document vrf_socket(), vrf_bind()
These two don't really do what you might expect, document them

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-12-18 15:58:08 -05:00
David Lamparter
1b3e9a21dd lib: make some variables static
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-13 06:22:34 +01:00
Igor Ryzhov
e429a2a0cc *: fix missing VRF autocompletions
Current autocompletion works only for simple "vrf NAME" case.

This commit expands it also for the following cases:
- "nexthop-vrf NAME" in staticd
- usage of $varname in many daemons

All daemons are updated to use single varname "$vrf_name".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2019-09-24 19:51:46 +03:00
Russ White
fe8d933c2c
Merge pull request #4564 from pguibert6WIND/misc_vrf_update_name
Misc vrf update name
2019-09-17 07:22:22 -04:00
David Lamparter
0cf6db21ec *: frr_elevate_privs -> frr_with_privs
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-09-03 17:18:35 +02:00
Philippe Guibert
87272aff32 lib: call vrf update hook when default vrf name changes
this is a call done whenever vrf name changes. This is useful on remote
daemons.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-08-27 15:08:50 +02:00
Donald Sharp
a36898e755
Revert "Ospf missing interface handling 2" 2019-06-23 19:46:39 -04:00
Philippe Guibert
a41c4e1b1f *: change interface structure, from vrf_id to vrf
Field vrf_id is replaced by the pointer of the struct vrf *.
For that all other code referencing to (interface)->vrf_id is replaced.
This work should not change the behaviour.
It is just a continuation work toward having an interface API handling
vrf pointer only.

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

a zebra function is also created:
zvrf_info_lookup

an ospf function is also created:
ospf_lookup_by_vrf

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

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

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2019-06-12 08:37:58 +02:00
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
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
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
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
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
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
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
Donald Sharp
c9146c85a0
Merge pull request #3772 from pguibert6WIND/vrf_backend_unknown
Vrf backend unknown
2019-03-25 08:13:16 -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
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
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
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
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
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
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
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
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
74df8d6d9d *: Replace hash_cmp function return value to a bool
The ->hash_cmp and linked list ->cmp functions were sometimes
being used interchangeably and this really is not a good
thing.  So let's modify the hash_cmp function pointer to return
a boolean and convert everything to use the new syntax.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-10-19 13:14:45 -04:00
Quentin Young
1c50c1c0d6 *: style for EC replacements
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13 19:38:57 +00:00
Quentin Young
450971aa99 *: LIB_[ERR|WARN] -> EC_LIB
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13 19:34:28 +00:00
David Lamparter
e991eff5b5 Merge remote-tracking branch 'frr/master' into warnings
Conflicts:
	zebra/if_ioctl_solaris.c
	zebra/rtread_getmsg.c

Signed-off-by: David Lamparter <equinox@diac24.net>
2018-09-12 21:58:39 +02:00
Quentin Young
ade6974def *: style for flog_warn conversions
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-06 20:56:41 +00:00
Donald Sharp
0351a28f2a lib: Convert vrf.c to use new error-code subsystem
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-09-06 20:50:58 +00:00
Thibaut Collet
c3568c4d1a zebra/lib: code cleaning
Remove useless parenthesis and explicit cast.
Remove redundant code.

Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
2018-09-06 07:48:12 +02:00
Thibaut Collet
20c87e98d8 vrf: return vrf implementation for default vrf
To correct potential crash with netns implementation of vrf (see next
commit) it is necessary to allow any daemons to know the vrf
implementation whatever the vrf.
With current implementation the daemons do not know the vrf
implementation for the default vrf. For this vrf the returned vrf
implementation is always vrf-lite.
To solve this issue a netns name is set to the default vrf to just test
is presence to know the used implementation.

For zebra a netns name (if needed) is set in the vrf_init function just
before enabling the vrf. So this information is propagated to the other
daemons thanks the zapi message called when the vrf is enable at zebra
layer and override the default configuration (vrf-lite) of the daemon.

Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
2018-08-30 14:37:55 +02:00
Philippe Guibert
eb6934d5c5 lib: avoid default vrf name memory allocation at startup
If default VRF is used, with standard naming convention,
memory allocation can be avoided.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28 16:23:50 +02:00
Philippe Guibert
dd1147028a lib: protect newly created vrfs against default vrf naming.
Prevent from creating vrf, if the default vrf name is the same as the
vrf to be created.
Also, prevent at startup from creating default vrf with a name already
used in vrf list.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28 16:23:50 +02:00
Philippe Guibert
fdafe17ee9 lib: set default vrf name at startup
For the daemons that do not use vrf_init(), the call to the define
will return a default vrf if no other values has been overriden.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28 16:23:50 +02:00
Philippe Guibert
ecbc5a3781 *: add a vrf update hook to be informed of the vrf name
The Vrf aliases can be known with a specific hook. That hook will then,
from zebra propagate the information to the relevant zapi clients.
The registration hook function is the same for all daemons.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28 16:23:50 +02:00
Philippe Guibert
723001fc13 lib: autocomple vrf list authorises default vrf name
Now it is possible to dump default vrf information by its name.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28 16:23:50 +02:00
Philippe Guibert
c200f5e1e4 lib: offer an API to get and set default vrf name
The get API is used each time the VRF_DEFAULT_NAME macro is used.
The set API is not yet used.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28 16:23:50 +02:00
Donald Sharp
4a8bf85858 lib: Convert vrf bit-map to a hash.
Memory sizes of the vrf bit-map was insane for a system
with a moderate number of data on it:

Zebra:
VRF bit-map                   :        601   65536            39391944

Having a full 32bit integer bit space is problematically large,
switch over to a hash to store bit data.  We do not need to waste
so much space.

VRF bit-map                   :         13       8                 312

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-23 20:17:57 -04:00
Philippe Guibert
3d4c0b49da lib: change vrf_is_mapped_on_netns API
The function handles not a vrf pointer instead of a vrf_id value.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-22 09:19:04 +02:00
David Lamparter
6bb30c2cba *: use frr_elevate_privs() (2/2: manual)
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-08-14 20:02:05 +00:00
Quentin Young
09c866e34d *: rename ferr_zlog -> flog_err_sys
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Quentin Young
af4c27286d *: rename zlog_fer -> flog_err
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
Donald Sharp
481bc15ffc lib: Add LIB_ERR_SYSTEM_CALL and convert VRF_SOCKET to SOCKET
Add a new error code LIB_ERR_SYSTEM_CALL to the ferr subsystem.
Additionally convert LIB_ERR_VRF_SOCKET to a more generic
LIB_ERR_SOCKET.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Donald Sharp
b66d022e8d lib, bgpd: Add code to make lib auto create the ferr infrastructure
Add code to auto-create the ferr infrastructure as well as add
some initial error handling for vrf.c

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-14 20:02:05 +00:00
Renato Westphal
34c4627457 lib, vtysh: fix inconsistent VRF commands in vtysh
* Only zebra and pimd call vrf_cmd_init(), so these are the only daemons
  that should receive VRF commands from vtysh;
* "netns NAME" and "no netns NAME" are available only in zebra, write
  custom DEFSHs in vtysh to make it aware of that;
* Remove the "no vrf NAME" definition from vtysh.c and expose the
  original command to vtysh by converting the DEFUN_NOSH to a simple
  DEFUN. This command doesn't change the vty node so there's no need to
  special case it.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-08-13 18:59:31 -03:00
F. Aragon
2e1cc43679
eigrpd lib pimd zebra: dead code (PVS-Studio)
Signed-off-by: F. Aragon <paco@voltanet.io>
2018-07-06 01:10:15 +02:00
Lou Berger
9dff113290 lib: don't open vrf specific socket when tcp|udp_l3mdev_accept != 0
Signed-off-by: Lou Berger <lberger@labn.net>
2018-06-17 21:10:24 -04:00
Quentin Young
67c0ef6aab
Merge pull request #2345 from pguibert6WIND/issue_2328
lib: make netns command visible under vtysh
2018-06-06 19:21:49 -04:00
Philippe Guibert
4a541e8c23 lib: make netns command visible under vtysh
Make netns command visible under vtysh.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-06-05 17:33:10 +02:00
Lou Berger
c9c70dd164 lib: fix setsockopt arg
Signed-off-by: Lou Berger <lberger@labn.net>
2018-06-04 13:13:15 +02:00
Donald Sharp
98cbbaea91 lib: Handle if up/down and vrf enable/disable events
Properly notice when we get if up/down and vrf enable/disable
events and attempt to properly install nexthops as they
come in.

Ticket: CM20489
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-04-17 18:44:33 -04:00
Philippe Guibert
03aff2d848 zebra: add an indirection table for ns_id
This list "table" is created in the case the netns backend for VRF is
used. This contains the mapping between the NSID value read from the
'ip netns list' and the ns id external used to create the VRF
value from vrf context. This mapping is
necessary in order to reserve default 0 value for vrf_default.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-04-13 16:40:32 +02:00
Philippe Guibert
0c2bac3880 lib: a vrf is searched first by its name, than its vrf id
Because at startup, remote daemons attempt to create default VRF,
the VRF_ID may be set to unknown. In that case, an event will be
triggered later by zebra to inform remote daemon that the vrf id of that
VRF has changed to valid value. In that case, two instances of default
VRF must not be created. By looking first at vrf name, this avoids
having two instances.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-04-13 16:40:32 +02:00
Quentin Young
16d6ea59d3
lib, vtysh: vrf walkup bugfix
Static route commands are now installed inside the VRF nodes. This has
quietly broken top-level static routes in certain scenarios due to
walkup logic resolving a static route configuration command inside
VRF_NODE first if the command is issued while in a CLI node lower than
VRF_NODE. To fix this VRF_NODE needs a special exit command, as has been
done for many other nodes with the same issue, to explicitly change the
vrf context to the default VRF so that when walkup resolves against the
VRF node it will configure against the default VRF as desired.

Of course this is a hack on top of a hack and the CLI walkup
implementation needs to be rewritten.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-30 13:14:34 -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
Philippe Guibert
3bc34908e8 lib: privileges are granted to vty netns command
Vty commands that link netns context to a vrf is requiring some
privileges. The change consists in retrieving the privileges at the
vrf_cmd_init() called by the relevant daemon. Then use it.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-03-13 16:32:58 +01:00
Lou Berger
996c93142d *: conform with COMMUNITY.md formatting rules, via 'make indent'
Signed-off-by: Lou Berger <lberger@labn.net>
2018-03-06 14:04:32 -05:00
Philippe Guibert
0f4977c668 lib: add vrf-lite bind capability to vrf APIs
Because socket creation is tightly linked with socket binding for vrf
lite, the proposal is made to extend socket creation APIs and to create
a new API called vrf_bind that applies to vrf lite. The passed interface
name is the interface that will be bound to the socket passed.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
516d7591d6 lib: add vrf_ioctl API
That API can be used to wrap the ioctl call with various vrf instances.
This permits transparently doing the ioctl() call without taking into
consideration the vrf backend kind.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
e26aedbe0b lib: split logicalrouter and vrf netns feature
This split is introducing logicalrouter.[ch] as the file that contains
the vty commands to configure logical router feature. The split has as
consequence that the backend of logical router is linux_netns.c formerly
called ns.c. The same relationship exists between VRF and its backend
which may be linux_netns.c file.
The split is adapting ns and vrf fiels so as to :
- clarify header
- ensure that the daemon persepctive, the feature VRF or logical router
  is called instead of calling directly ns.
- this implies that VRF will call NS apis, as logical router does.

Also, like it is done for default NS and default VRF, the associated VRF
is enabled first, before NETNS is enabled, so that zvrf->zns pointer is
valid when NETNS discovery applies.

Also, other_netns.c file is a stub handler that will be used for non
linux systems. As NETNS feature is only used by Linux, some BSD systems
may want to use the same backend API to benefit from NETNS. This is what
that file has been done.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
2e0d2b3d9c lib: add two APIs to handle socket operations with VRF NETNS
The vrf_sockunion_socket() wraps sockunion_socket() with vrf_id as
additional parameter. The creation of socket forces the user to
transparently move to new NETNS for doing the operation.
The vrf_getaddr_info() wraps getaddr_info() with vrf_id as additional
parameter. That API relies on the underlying system. Then there may be
need to switch to an other netns in that case too.
Also, the vrf_socket() implementation is simplified.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
ec31f30d28 zebra: upon startup, a NSID is assigned to default netns
when the netns backend is selected for VRF, the default VRF is being
assigned a NSID. This avoids the need to handle the case where if the
incoming NSID was 0 for a non default VRF, then a specific handling had
to be done to keep 0 value for default VRF.
In most cases, as the first NETNS to get a NSID will be the default VRF,
most probably the default VRF will be assigned to 0, while the other
ones will have their value incremented. On some cases, where the NSID is
already assigned for NETNS, including default VRF, then the default VRF
value will be the one derived from the NSID of default VRF, thus keeping
consistency between VRF IDs and NETNS IDs.
Default NS is attempted to be created. Actually, some VMs may have the
netns feature, but the NS initialisation fails because that folder is
not present.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
ce1be3692f lib: provide an API to switch from one netns to an other
Two apis are provided so that the switch from one netns to an other one
is taken care.
Also an other API to know if the VRF has a NETNS backend or a VRF Lite
backend.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
4691b65ae4 lib: add namespace name structure in zebra message
The addition of the name of the netns in the vrf message introduces also
a limitation when the size of the netns is bigger than 15 bytes. Then
the netns are ignored by the library.
In addition to this, some sanity checks have been introduced. some
functions to create the netns from a call not coming from the vty is
being added with traces.
Also, the ns vty function is reentrant, if the context is already
created.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-02-27 11:11:24 +01:00
Philippe Guibert
697d3ec731 lib: externalise vrf and ns creation
In addition to have the possibility to create from vty vrf based on a
netns backend, the API will be made accessible from external, especially
for zebra that will handle the netns discovery part. This commit is
externalising following functions:
- netns_pathname
- ns_handler_create
- vrf_handler_create

Also, the VRF initialisation case when under NETNS backend is changed,
since the NS identifier may not be known at the configuration time,but
may be known later, under discovery process.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01: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
Philippe Guibert
b95c18833a zebra: copy logical-router-command under vrf subnode
a vty command is added:
in addition to this command ( kept for future usage):
- [no] logical-router-id <ID> netns <NETNSNAME>
a new command is being placed under vrf subnode
- vrf <NAME>
   [no] netns <NETNSNAME>
  exit

This command permits to map a VRF with a Netnamespace.
The commit only handles the relationship between vrf and ns structures.
It adds 2 attributes to vrf structure:
- one defines the kind of vrf ( mapped under netns or vrf from kernel)
- the other is the opaque pointer to ns
The show running-config is handled by zebra daemon.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:11:24 +01:00
Philippe Guibert
78dd30b263 zebra: add a runtime flag to enable vrf with netns
The netns backend is chosen by VRF if a runtime flag named vrfwnetns is
selected when running zebra.
In the case the NETNS backend is chosen, in some case the VRFID value is
being assigned the value of the NSID. Within the perimeter of that work,
this is why the vrf_lookup_by_table function is extended with a new
parameter.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-27 11:10:41 +01:00
Donald Sharp
55cd0f612a *: Make assignment from RB_ROOT in while loop work better
Fix up the assignment of the variable = RB_ROOT inside of
while loop patter we were using.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-02-23 07:08:36 -05:00
vivek
22bd3e9497 *: Refine the notion of a configured VRF in FRR
Refine the notion of what FRR considers as "configured" VRF. It is no longer
based on user just typing "vrf FOO" but when something is actually configured
against that VRF. Right now, in zebra, the only configuration against a VRF
are static IP routes and EVPN L3 VNI. Whenever a configuration is removed,
check and clear the "configured" flag if there is no other configuration for
this VRF. When user attempts to configure a static route and the VRF doesn't
exist, a VRF is created; the VRF is only active when also defined in the
kernel.

Updates: 8b73ea7bd479030418ca06eef59d0648d913b620
Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by:   Don Slice <dslice@cumulusnetworks.com>

Ticket: CM-10139, CM-18553
Reviewed By: CCR-7019
Testing Done:
1. Manual testing for L3 VNI and static routes - FRR restart, networking
restart etc.
2. 'vrf' smoke

<DETAILED DESCRIPTION (REPLACE)>
2018-01-23 18:49:40 -08:00
vivek
65c3a7c4e5 lib: Handle configured VRFs at termination
When shutting down, ensure that all VRFs including "configured" ones are
cleaned up properly.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>

Ticket: CM-19069
Reviewed By: CCR-7011
Testing Done: Manual verification of failed scenario
2018-01-23 16:24:39 -08:00
vivek
84915b0a15 *: Handle VRF configuration when VRF gets inactivated and activated
A VRF is active only when the corresponding VRF device is present in the
kernel. However, when the kernel VRF device is removed, the VRF container in
FRR should go away only if there is no user configuration for it. Otherwise,
when the VRF device is created again so that the VRF becomes active, FRR
cannot take the correct actions. Example configuration for the VRF includes
static routes and EVPN L3 VNI.

Note that a VRF is currently considered to be "configured" as soon as the
operator has issued the "vrf <name>" command in FRR. Such a configured VRF
is not deleted upon VRF device removal, it is only made inactive. A VRF that
is "configured" can be deleted only upon operator action and only if the VRF
has been deactivated i.e., the VRF device removed from the kernel. This is
an existing restriction.

To implement this change, the VRF disable and delete actions have been modified.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by:   Mitesh Kanjariya <mkanjariya@cumulusnetworks.com>
Reviewed-by:   Don Slice <dslice@cumulusnetworks.com>

Ticket: CM-18553, CM-18918, CM-10139
Reviewed By: CCR-7022
Testing Done:
1. vrf and pim-vrf automation tests
2. Multiple VRF delete and readd (ifdown, ifup-with-depends)
3. FRR stop, start, restart
4. Networking restart
5. Configuration delete and readd

Some of the above tests run in different sequences (manually).
2018-01-23 16:24:35 -08:00
Philippe Guibert
3bd74754c9 lib: vrf_bitmap_groups increased from 8 to 1024
The number of vrf bitmap groups is increased so as to avoid consuming
too much memory. This fix is related to a fork memory that occured when
running pimd as daemon.
A check on memory consumed shows that the memory consumed goes from
33480ko to 46888ko with that change. This is less compared to if the
value of the bitmap groups is increased to 16 ( 852776ko).

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-01-22 13:52:23 +01:00
Philippe Guibert
a9ff90c41b lib: increase vrf_id from 16 bit to 32 bit identifier
This is a preparatory work for configuring vrf/frr over netns
vrf structure is being changed to 32 bit, and the VRF will have the
possibility to have a backend made up of NETNS.

Let's put some history.
Initially the 32 bit was because one wanted to map on vrf_id both the
VRFLITE and the NSID.
Initially, one would have liked to make zebra configure at the same time
both vrf lite and vrf from netns in a flat way. From the show
running perspective, one would have had both kind of vrfs, thatone
would configure on the same way.
however, it leads to inconsistencies in concepts, because it mixes vrf
vrf with vrf, and vrf is not always mapped with netns.
For instance, logical-router could also be used with netns. In that
case, it would not be possible to map vrf with netns.
There was an other reason why 32 bit is proposed. this is because
some systems handle NSID to 32 bits. As vrf lite exists only on
Linux, there are other systems that would like to use an other vrf
backend than vrf lite. The netns backend for vrf will be used for that
too. for instance, for windows or freebsd, some similar
netns concept exists; so it will be easier to reuse netns
backend for vrf, than reusing vrflite backend for vrf.

This commit is here to extend vrf_id to 32 bits. Following commits in a
second step will help in enable a VRF backend.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-01-22 13:52:17 +01:00