summaryrefslogtreecommitdiffstats
path: root/lib/vrf.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #10183 from idryzhov/rework-vrf-renameRafael Zalamena2022-01-171-31/+2
|\ | | | | *: rework renaming the default VRF
| * *: rework renaming the default VRFIgor Ryzhov2021-12-211-31/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, it is possible to rename the default VRF either by passing `-o` option to zebra or by creating a file in `/var/run/netns` and binding it to `/proc/self/ns/net`. In both cases, only zebra knows about the rename and other daemons learn about it only after they connect to zebra. This is a problem, because daemons may read their config before they connect to zebra. To handle this rename after the config is read, we have some special code in every single daemon, which is not very bad but not desirable in my opinion. But things are getting worse when we need to handle this in northbound layer as we have to manually rewrite the config nodes. This approach is already hacky, but still works as every daemon handles its own NB structures. But it is completely incompatible with the central management daemon architecture we are aiming for, as mgmtd doesn't even have a connection with zebra to learn from it. And it shouldn't have it, because operational state changes should never affect configuration. To solve the problem and simplify the code, I propose to expand the `-o` option to all daemons. By using the startup option, we let daemons know about the rename before they read their configs so we don't need any special code to deal with it. There's an easy way to pass the option to all daemons by using `frr_global_options` variable. Unfortunately, the second way of renaming by creating a file in `/var/run/netns` is incompatible with the new mgmtd architecture. Theoretically, we could force daemons to read their configs only after they connect to zebra, but it means adding even more code to handle a very specific use-case. And anyway this won't work for mgmtd as it doesn't have a connection with zebra. So I had to remove this option. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* | lib: default VRF may not exist on early exitDavid Lamparter2021-12-141-1/+2
|/ | | | | | | If we're exiting before we finished initializing, we can end up trying to shut down a NULL vrf here. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib, yang: remove vrf from the interface list keyIgor Ryzhov2021-11-231-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This is needed for the following two reasons: 1. To be able to remove the northbound HACK in if_update_to_new_vrf. It is totally wrong to rewrite the configuration datastore when some operational state changes. It is a hard blocker for storing a configuration data in a management daemon which knows nothing about the operational state. 2. To allow changing the VRF of the interface using FRR CLI or any other frontend in the future. If the VRF is a part of the key, it can't be changed. If the VRF is a simple leaf, it becomes possible to change it and thus move the interface between VRFs. For now I mark the leaf as a "config false" as it's not yet possible to control it from FRR. But we can't simply remove the VRF from the key, because it is needed to distinguish interfaces when using netns based VRFs, as it is possible to have multiple interfaces with the same name in different namespaces. To handle this, I came up with an idea to store both VRF and an interface name in the "name" leaf using the pattern "vrfname:ifname". For example, if there's an interface "eth0" in VRF "red" then its "name" leaf will be "red:eth0". Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* *: cleanup ifp->vrf_idIgor Ryzhov2021-11-221-7/+0
| | | | | | | Since f60a1188 we store a pointer to the VRF in the interface structure. There's no need anymore to store a separate vrf_id field. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix vrf deletion when the last interface is deletedIgor Ryzhov2021-11-111-4/+1
| | | | | | | | | | | | | | | | Currently, we automatically delete an inactive VRF when its last interface is deleted. This code introduces a couple of crashes because of the following problems: - vrf_delete is called before calling if_del hook, so daemons may try to dereference an ifp->vrf pointer which is freed - in if_terminate, we continue to use the VRF in the loop condition after the last interface is deleted This check is needed only when the interface is deleted by the user, because if the interface is deleted by the system, VRF must still exist in the system. Move the check to appropriate places to fix crashes. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix crash when terminating inactive VRFsIgor Ryzhov2021-11-031-1/+4
| | | | | | | | If the VRF is not enabled, if_terminate deletes the VRF after the last interface is removed from it. Therefore daemons crash on the subsequent call to vrf_delete. We should call vrf_delete only for enabled VRFs. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* zebra: fix stale pointer when netns is deletedIgor Ryzhov2021-11-031-3/+1
| | | | | | | | | | | When the netns is deleted, we should always clear the vrf->ns_ctxt pointer. Currently, it is not cleared when there are interfaces in the netns at the time of deletion. If the netns is re-created, zebra crashes because it tries to use the stale pointer. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* Merge pull request #9846 from idryzhov/lib-zebra-netnsMark Stapp2021-10-261-135/+22
|\ | | | | lib: move zebra-only netns stuff to zebra
| * lib: move zebra-only netns stuff to zebraIgor Ryzhov2021-10-181-135/+22
| | | | | | | | | | | | | | When something is used only from zebra and part of its description is "should be called from zebra only" then it belongs to zebra, not lib. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* | lib: allow to create interfaces in non-existing VRFsIgor Ryzhov2021-10-191-12/+10
|/ | | | | | | | | | | | | | | | | | | | | It allows FRR to read the interface config even when the necessary VRFs are not yet created and interfaces are in "wrong" VRFs. Currently, such config is rejected. For VRF-lite backend, we don't care at all about the VRF of the inactive interface. When the interface is created in the OS and becomes active, we always use its actual VRF instead of the configured one. So there's no need to reject the config. For netns backend, we may have multiple interfaces with the same name in different VRFs. So we care about the VRF of inactive interfaces. And we must allow to preconfigure the interface in a VRF even before it is moved to the corresponding netns. From now on, we allow to create multiple configs for the same interface name in different VRFs and the necessary config is applied once the OS interface is moved to the corresponding netns. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* vrf_name_to_id(): removeG. Paul Ziemba2021-09-071-15/+0
| | | | | | | | | vrf_name_to_id() returned VRF_DEFAULT when the vrf name was unknown, hiding errors. Per community recommendation, vrf_name_to_id() is now removed and the few callers now use vrf_lookup_by_name() directly. Signed-off-by: G. Paul Ziemba <paulz@labn.net>
* lib: Remove unused function vrf_generate_idDonald Sharp2021-09-021-7/+0
| | | | Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* lib: remove unused argument from vrf_cmd_initIgor Ryzhov2021-08-261-2/+1
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib, zebra: move vrf netns commands from lib to zebraIgor Ryzhov2021-08-231-63/+0
| | | | | | | | | | | | "[no] netns NAME" commands are part of the lib, but they are actually zebra-only: - they are using vrf_netns_handler_create and its description clearly says that it "should be called from zebra only" - vtysh sends these commands only to zebra - only zebra outputs the netns related config - zebra notifies other daemons about netns attachment Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib, zebra: Preserve user-configured VRF on netns deletionXiao Liang2021-07-301-0/+1
| | | | | | Don't clear VRF's user-configured flag when netns is deleted. Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
* lib: remove vrf-interface config when removing the VRFIgor Ryzhov2021-06-211-1/+15
| | | | | | | | | | | | | | | | | | | | | | | If we have the following configuration: ``` vrf red smth exit-vrf ! interface red vrf red smth ``` And we delete the VRF using "no vrf red" command, we end up with: ``` interface red smth ``` Interface config is preserved but moved to the default VRF. This is not an expected behavior. We should remove the interface config when the VRF is deleted. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: terminate default vrf lastStephen Worley2021-06-111-11/+20
| | | | | | | | | | | Always terminate default VRF last during FRR shutdown. On shutdown we were simply looping over the RB tree and terminating VRFs from the ROOT. This is not guaranteed to be the default last ever. Instead switch to RB_SAFE and skip the default VRF till the very end. Signed-off-by: Stephen Worley <sworley@nvidia.com>
* zebra: fix config after exit from vrfIgor Ryzhov2021-06-041-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the VRF node is exited using "exit" or "quit", there's still a VRF pointer stored in the vty context. If you try to configure some router related command, it will be applied to the previous VRF instead of the default VRF. For example: ``` (config)# vrf test (config-vrf)# ip router-id 1.1.1.1 (config-vrf)# do show run ... ! vrf test ip router-id 1.1.1.1 exit-vrf ! ... (config-vrf)# exit (config)# ip router-id 2.2.2.2 (config)# do show run ... ! vrf test ip router-id 2.2.2.2 exit-vrf ! ... ``` `vrf-exit` works correctly, because it stores a pointer to the default VRF into the vty context (but weirdly keeping the VRF_NODE instead of changing it to CONFIG_NODE). Instead of relying on the behavior of exit function, always use the default VRF when in CONFIG_NODE. Another problem is missing `VTY_CHECK_CONTEXT`. If someone deletes the VRF in which node the user enters the command, then zebra applies the command to the default VRF instead of throwing an error. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* Merge pull request #8210 from LabNConsulting/chopps/always-batchDonald Sharp2021-06-031-2/+1
|\ | | | | northbound: KISS always batch yang config, it's faster.
| * northbound: KISS always batch yang config (file read), it's fasterChristian Hopps2021-06-021-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The backoff code assumed that yang operations always completed quickly. It checked for > 100 YANG modeled commands happening in under 1 second to enable batching. If 100 yang modeled commands always take longer than 1 second batching is never enabled. This is the exact opposite of what we want to happen since batching speeds the operations up. Here are the results for libyang2 code without and with batching. | action | 1K rts | 2K rts | 1K rts | 2K rts | 20k rts | | | nobatch | nobatch | batch | batch | batch | | Add IPv4 | .881 | 1.28 | .703 | 1.04 | 8.16 | | Add Same IPv4 | 28.7 | 113 | .590 | .860 | 6.09 | | Rem 1/2 IPv4 | .376 | .442 | .379 | .435 | 1.44 | | Add Same IPv4 | 28.7 | 113 | .576 | .841 | 6.02 | | Rem All IPv4 | 17.4 | 71.8 | .559 | .813 | 5.57 | (IPv6 numbers are basically the same as iPv4, a couple percent slower) Clearly we need this. Please note the growth (1K to 2K) w/o batching is non-linear and 100 times slower than batched. Notes on code: The use of the new `nb_cli_apply_changes_clear_pending` is to commit any pending changes (including the current one). This is done when the code would not correctly handle a single diff that included the current changes with possible following changes. For example, a "no" command followed by a new value to replace it would be merged into a change, and the code would not deal well with that. A good example of this is BGP neighbor peer-group changing. The other use is after entering a router level (e.g., "router bgp") where the follow-on command handlers expect that router object to now exists. The code eventually needs to be cleaned up to not fail in these cases, but that is for future NB cleanup. Signed-off-by: Christian Hopps <chopps@labn.net>
* | lib: fix binding to a vrfIgor Ryzhov2021-05-311-13/+38
|/ | | | | | | | | | | | | | | | | | | | | | | | | There are two possible use-cases for the `vrf_bind` function: - bind socket to an interface in a vrf - bind socket to a vrf device For the former case, there's one problem - success is returned when the interface is not found. In that case, the socket is left unbound without throwing an error. For the latter case, there are multiple possible problems: - If the name is not set, then the socket is left unbound (zebra, vrrp). - If the name is "default" and there's an interface with that name in the default VRF, then the socket is bound to that interface. - In most daemons, if the router is configured before the VRF is actually created, we're trying to open and bind the socket right after the daemon receives a VRF registration from zebra. We may not receive the VRF-interface registration from zebra yet at that point. Therefore, `if_lookup_by_name` fails, and the socket is left unbound. This commit fixes all the issues and updates the function description. Suggested-by: Pat Ruddy <pat@voltanet.io> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix missing newlineIgor Ryzhov2021-05-241-1/+1
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: adapt to version 2 of libyangChristian Hopps2021-05-131-1/+2
| | | | | | | | | Compile with v2.0.0 tag of `libyang2` branch of: https://github.com/CESNET/libyang staticd init load time of 10k routes now 6s vs ly1 time of 150s Signed-off-by: Christian Hopps <chopps@labn.net>
* *: modify VRF_CONFIGURED flag only in VRF NB layerIgor Ryzhov2021-03-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is to fix the crash reproduced by the following steps: * ip link add red type vrf table 1 Creates VRF. * vtysh -c "conf" -c "vrf red" Creates VRF NB node and marks VRF as configured. * ip route 1.1.1.0/24 2.2.2.2 vrf red * no ip route 1.1.1.0/24 2.2.2.2 vrf red (or similar l3vni set/unset in zebra) Marks VRF as NOT configured. * ip link del red VRF is deleted, because it is marked as not configured, but NB node stays. Subsequent attempt to configure something in the VRF leads to a crash because of the stale pointer in NB layer. Fixes #8357. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* *: require semicolon after DEFINE_QOBJ & co.David Lamparter2021-03-171-1/+1
| | | | | | Again, see previous commits. Signed-off-by: David Lamparter <equinox@diac24.net>
* *: require semicolon after DEFINE_MTYPE & coDavid Lamparter2021-03-171-2/+2
| | | | | | | | | | | | | | | | | Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: add definitions for vrf xpathsIgor Ryzhov2021-02-221-4/+3
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* *: remove tabs & newlines from log messagesDavid Lamparter2021-02-141-2/+2
| | | | | | | Neither tabs nor newlines are acceptable in syslog messages. They also break line-based parsing of file logs. Signed-off-by: David Lamparter <equinox@diac24.net>
* Merge pull request #7508 from sudhanshukumar22/zebra-vrf-deleteStephen Worley2021-02-101-0/+47
|\ | | | | zebra: treat vrf add for existing vrf as update
| * zebra: treat vrf add for existing vrf as updatesudhanshukumar222021-02-011-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Description: When we get a new vrf add and vrf with same name, but different vrf-id already exists in the database, we should treat vrf add as update. This happens mostly when there are lots of vrf and other configuration being replayed. There may be a stale vrf delete followed by new vrf add. This can cause timing race condition where vrf delete could be missed and further same vrf add would get rejected instead of treating last arrived vrf add as update. Treat vrf add for existing vrf as update. Implicitly disable this VRF to cleanup routes and other functions as part of vrf disable. Update vrf_id for the vrf and update vrf_id tree. Re-enable VRF so that all routes are freshly installed. Above 3 steps are mandatory since it can happen that with config reload stale routes which are installed in vrf-1 table might contain routes from older vrf-0 table which might have got deleted due to missing vrf-0 in new configuration. Signed-off-by: sudhanshukumar22 <sudhanshu.kumar@broadcom.com>
* | vrf: use wrappers to change VRF_CONFIGURED flagIgor Ryzhov2021-02-091-2/+2
| | | | | | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* | vrf: mark vrf as configured when entering vrf nodeIgor Ryzhov2021-02-091-0/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The VRF must be marked as configured when user enters "vrf NAME" command. Otherwise, the following problem occurs: `ip link add red type vrf table 1` VRF structure is allocated. `vtysh -c "conf t" -c "vrf red"` `lib_vrf_create` is called, and pointer to the VRF structure is stored to the nb_config_entry. `ip link del red` VRF structure is freed (because it is not marked as configured), but the pointer is still stored in the nb_config_entry. `vtysh -c "conf t" -c "no vrf red"` Nothing happens, because VRF structure doesn't exist. It means that `lib_vrf_destroy` is not called, and nb_config_entry still exists in the running config with incorrect pointer. `ip link add red type vrf table 1` New VRF structure is allocated. `vtysh -c "conf t" -c "vrf red"` `lib_vrf_create` is NOT called, because the nb_config_entry for that VRF name still exists in the running config. After that all NB commands for this VRF will use incorrect pointer to the freed VRF structure. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* vrf: VRF_DEFAULT must be 0, remove useless codeChristophe Gouault2020-09-211-14/+2
| | | | | | | | | | Code was added in the past to support a value of VRF_DEFAULT different from 0. This option was abandoned, the default vrf id is always 0. Remove this code, this will simplify the code and improve performance (use a constant value instead of a function that performs tests). Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
* lib: optimize vrf_id_to_name(VRF_DEFAULT) caseChristophe Gouault2020-09-211-0/+3
| | | | | | | | | | vrf_id_to_name() looks up in a RB_TREE to find the VRF entry, then reads the name. Avoid it for VRF_DEFAULT, which always exists and for which the translation is straightforward. Signed-off-by: Christophe Gouault <christophe.gouault@6wind.com>
* Merge pull request #7089 from pguibert6WIND/netns-refactorRuss White2020-09-181-2/+6
|\ | | | | Netns refactor
| * zebra, lib: store relative default ns id in each namespacePhilippe Guibert2020-08-181-2/+6
| | | | | | | | | | | | | | | | 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>
* | lib: Remove debug associated with vrf_getDonald Sharp2020-09-181-4/+0
| | | | | | | | | | | | | | | | The vrf_get function is called throughout the code base so much so that when you turn on vrf debugging it eclipses everything else to a degree that is completely unreasonable. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* | lib: Add vrf name to vrf debugsDonald Sharp2020-09-181-3/+5
| | | | | | | | | | | | | | The vrf name was not being printed out in some vrf debugs. Add this data in so people don't have to remember the vrf id. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* | lib: Actually call nexthop_group_disable_vrfDonald Sharp2020-09-181-0/+8
|/ | | | | | | | | | When the nexthop-groups were added to FRR for some reason the call to nexthop_group_disable_vrf was not added although it was written. Add it in. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* evpn-netns: Revert PR5077, has been re-worked post-refactorPat Ruddy2020-08-051-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Revert "zebra: support for macvlan interfaces" This reverts commit bf69e212fd053af3298fc3cba38458b396467849. Revert "doc: add some documentation about bgp evpn netns support" This reverts commit 89b97c33d7a6d9dc427d56fea52fa27334dde81d. Revert "zebra: dynamically detect vxlan link interfaces in other netns" This reverts commit de0ebb25404fe984f084a0d57b7f873618423876. Revert "bgpd: sanity check when updating nexthop from bgp to zebra" This reverts commit ee9633ed87f0ff5da1373a42d6c044f0a682c8d3. Revert "lib, zebra: reuse and adapt ns_list walk functionality" This reverts commit c4d466c830083e8ba58881d7ad03a90f6baf0754. Revert "zebra: local mac entries populated in correct netnamespace" This reverts commit 40424548910887f3bbbf544ce964d3b736048ae5. Revert "zebra: when parsing local entry against dad, retrieve config" This reverts commit 3acc394bc5e5c225e9258fd0d57a6cebea0c0ccd. Revert "bgpd: evpn nexthop can be changed by default" This reverts commit a2342a241253c41b798845cae155b4caab4bcda5. Revert "zebra: zvni_map_to_vlan() adaptation for all namespaces" This reverts commit db81d18647bbd81a2c335620c9a03e32e4a5b2be. Revert "zebra: add ns_id attribute to mac structure" This reverts commit 388d5b438e22cddc6740e362763c0922edbb242a. Revert "zebra: bridge layer2 information records ns_id where bridge is" This reverts commit b5b453a2d6af58692bee0e256fe1dffe99824801. Revert "zebra, lib: new API to get absolute netns val from relative netns val" This reverts commit b6ebab34f664ba1cc9479fc1287f127c12077509. Revert "zebra, lib: store relative default ns id in each namespace" This reverts commit 9d3555e06ccc68fe37e0a00100029ac4bad8dee2. Revert "zebra, lib: add an internal API to get relative default nsid in other ns" This reverts commit 97c9e7533bd22029ac19838c043cfca82d2f6eb3. Revert "zebra: map vxlan interface to bridge interface with correct ns id" This reverts commit 7c990878f20efff335c1211deda3ec50071ae2b5. Revert "zebra: fdb and neighbor table are read for all zns" This reverts commit f8ed2c5420106314a940cb67264494e0110fc4c0. Revert "zebra: zvni_map_to_svi() adaptation for other network namespaces" This reverts commit 2a9dccb6475bfc11af2b855c4c8ff9e500ba21f4. Revert "zebra: display interface slave type" This reverts commit fc3141393ad95651d31fccd144b5c029d00e5f3a. Revert "zebra: zvni_from_svi() adaptation for other network namespaces" This reverts commit 6fe516bd4b85569b3b8b4bcc2910afc5569aa026. Revert "zebra: importation of bgp evpn rt5 from vni with other netns" This reverts commit 28254125d06f65cc4344b6156eec76a37ec6aede. Revert "lib, zebra: update interface name at netlink creation" This reverts commit 1f7a68a2ff0ba1424131f30112e0cc1572f0bee3. Signed-off-by: Pat Ruddy <pat@voltanet.io>
* lib: introduce configuration back-off timer for YANG-modeled commandsRenato Westphal2020-08-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using the default CLI mode, the northbound layer needs to create a separate transaction to process each YANG-modeled command since they are supposed to be applied immediately (there's no candidate configuration nor the "commit" command like in the transactional CLI). The problem is that configuration transactions have an overhead associated to them, in big part because of the use of some heavy libyang functions like `lyd_validate()` and `lyd_diff()`. As of now this overhead is substantial and doesn't scale well when large numbers of transactions need to be performed in sequence. As an example, loading 50k prefix-lists using a single transaction takes about 2 seconds on a modern CPU. Loading the same 50k prefix-lists using 50k transactions can take more than an hour to complete (which is unacceptable by any standard). To fix this problem, some heavy optimization work needs to be done on libyang and on the FRR northbound itself too (e.g. perform partial configuration diffs whenever possible). This, however, should be a long term effort since these optimizations shouldn't be trivial to implement and we're far from having the performance numbers we need. In the meanwhile, this commit introduces a simple but efficient workaround to alleviate the issue. In short, a new back-off timer was introduced in the CLI to monitor and detect when too many YANG-modeled commands are being received at the same time. When a certain threshold is reached (100 YANG-modeled commands within one second), the northbound starts to group all subsequent commands into a single large transaction, which allows them to be processed much faster (e.g. seconds and not hours). It's essentially a protection mechanism that creates dynamically-sized transactions when necessary to prevent performance issues from happening. This mechanism is enabled both when parsing configuration files and when reading commands from a terminal. The downside of this optimization is that, if several YANG-modeled commands are grouped into the same transaction and at least one of them fails, the whole transaction is rejected. This is undesirable since users don't expect transactional behavior when that's not enabled explicitly. To minimize this issue, the CLI will log all commands that were rejected whenever that happens, to make the user aware of what happened and have enough information to fix the problem. Commands that fail due to parsing errors or CLI-level validations in general are rejected separately. Again, this proposed workaround is intended to be temporary. The goal is to provided a quick fix to issues like #6658 while we work on better long-term solutions. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* *: introduce DEFPY_YANG & friendsRenato Westphal2020-08-031-2/+2
| | | | | | | | | | DEFPY_YANG will allow the CLI to identify which commands are YANG-modeled or not before executing them. This is going to be useful for the upcoming configuration back-off timer work that needs to commit pending configuration changes before executing a command that isn't YANG-modeled. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* Merge pull request #6435 from idryzhov/fix-no-vrfQuentin Young2020-07-211-4/+2
|\ | | | | vtysh: return success from "no vrf" when VRF doesn't exist
| * vtysh: return success from "no vrf" when VRF doesn't existIgor Ryzhov2020-07-091-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | *: un-split strings across linesDavid Lamparter2020-07-141-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | *: convert northbound callbacks to new error handling modelRenato Westphal2020-05-291-2/+2
|/ | | | | | | | | | | | 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>
* zebra, lib: store relative default ns id in each namespacePhilippe Guibert2020-05-181-2/+6
| | | | | | | | 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>
* lib: update the CLI xpath index when exiting from the VRF nodeRenato Westphal2020-04-291-1/+1
| | | | | | | | | | 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>
* *: change the signature of the northbound callbacks to be more flexibleRenato Westphal2020-04-231-28/+25
| | | | | | | | | | | | | | | | | | | | | 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>