summaryrefslogtreecommitdiff
path: root/lib/vrf.c
AgeCommit message (Collapse)Author
2019-03-29Merge remote-tracking branch 'frr/master' into rip-vrfRenato Westphal
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-25Merge pull request #3772 from pguibert6WIND/vrf_backend_unknownDonald Sharp
Vrf backend unknown
2019-03-14*: remove trailing newlines from zlog messagesQuentin Young
Zlog puts its own newlines on, and doing this makes logs look nasty. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-11libs, daemons: changes to permit c++ compilationMark Stapp
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-11lib: interface handling where zebra not yet readyPhilippe Guibert
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-01lib: Allow bgp to always create a listen socket for the vrfDonald Sharp
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-01-19lib: remove the vrf_is_mapped_on_netns() functionRenato Westphal
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-18lib: constify a few parameters in the VRF codeRenato Westphal
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>
2018-12-28lib: enforce vrf_name_to_id by returning default_vrf when name is nullPhilippe Guibert
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-11-21lib, zebra: default vrf configured will not be overwritten by discoveryPhilippe Guibert
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-13bgpd: allow vrf validity and bgp vrf import/export, when zebra is offPhilippe Guibert
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-10-19*: Replace hash_cmp function return value to a boolDonald Sharp
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-09-13*: style for EC replacementsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-13*: LIB_[ERR|WARN] -> EC_LIBQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-12Merge remote-tracking branch 'frr/master' into warningsDavid Lamparter
Conflicts: zebra/if_ioctl_solaris.c zebra/rtread_getmsg.c Signed-off-by: David Lamparter <equinox@diac24.net>
2018-09-06*: style for flog_warn conversionsQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-06lib: Convert vrf.c to use new error-code subsystemDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-09-06zebra/lib: code cleaningThibaut Collet
Remove useless parenthesis and explicit cast. Remove redundant code. Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
2018-08-30vrf: return vrf implementation for default vrfThibaut Collet
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-28lib: avoid default vrf name memory allocation at startupPhilippe Guibert
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-28lib: protect newly created vrfs against default vrf naming.Philippe Guibert
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-28lib: set default vrf name at startupPhilippe Guibert
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*: add a vrf update hook to be informed of the vrf namePhilippe Guibert
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-28lib: autocomple vrf list authorises default vrf namePhilippe Guibert
Now it is possible to dump default vrf information by its name. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-28lib: offer an API to get and set default vrf namePhilippe Guibert
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-23lib: Convert vrf bit-map to a hash.Donald Sharp
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-22lib: change vrf_is_mapped_on_netns APIPhilippe Guibert
The function handles not a vrf pointer instead of a vrf_id value. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-14*: use frr_elevate_privs() (2/2: manual)David Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-08-14*: rename ferr_zlog -> flog_err_sysQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14*: rename zlog_fer -> flog_errQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-08-14bgpd, lib, zebra: Convert LIB_ERR_PRIVILEGESDonald Sharp
For all the places we zlog_err about raising/lowering privileges, use zlog_ferr. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-14lib: Add LIB_ERR_SYSTEM_CALL and convert VRF_SOCKET to SOCKETDonald Sharp
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-14lib, bgpd: Add code to make lib auto create the ferr infrastructureDonald Sharp
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-13lib, vtysh: fix inconsistent VRF commands in vtyshRenato Westphal
* 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-07-06eigrpd lib pimd zebra: dead code (PVS-Studio)F. Aragon
Signed-off-by: F. Aragon <paco@voltanet.io>
2018-06-17lib: don't open vrf specific socket when tcp|udp_l3mdev_accept != 0Lou Berger
Signed-off-by: Lou Berger <lberger@labn.net>
2018-06-06Merge pull request #2345 from pguibert6WIND/issue_2328Quentin Young
lib: make netns command visible under vtysh
2018-06-05lib: make netns command visible under vtyshPhilippe Guibert
Make netns command visible under vtysh. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-06-04lib: fix setsockopt argLou Berger
Signed-off-by: Lou Berger <lberger@labn.net>
2018-04-17lib: Handle if up/down and vrf enable/disable eventsDonald Sharp
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-13zebra: add an indirection table for ns_idPhilippe Guibert
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-13lib: a vrf is searched first by its name, than its vrf idPhilippe Guibert
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-03-30lib, vtysh: vrf walkup bugfixQuentin Young
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-27*: use C99 standard fixed-width integer typesQuentin Young
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-13lib: privileges are granted to vty netns commandPhilippe Guibert
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-06*: conform with COMMUNITY.md formatting rules, via 'make indent'Lou Berger
Signed-off-by: Lou Berger <lberger@labn.net>
2018-02-27lib: add vrf-lite bind capability to vrf APIsPhilippe Guibert
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-27lib: add vrf_ioctl APIPhilippe Guibert
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-27lib: split logicalrouter and vrf netns featurePhilippe Guibert
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-27lib: add two APIs to handle socket operations with VRF NETNSPhilippe Guibert
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>