summaryrefslogtreecommitdiff
path: root/lib/if.c
AgeCommit message (Collapse)Author
2021-10-13lib: Add missing enum values in switch statement for if_link_type_strDonald Sharp
The switch statement over `enum zebra_link_type` had a default and FRR was missing a few of the pre-defined types we cared about. Remove the default statement and add the missing values. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-05lib: fix spelling nits in more lib filesewlumpkin
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-08-23*: explicitly print "exit" at the end of every node configIgor Ryzhov
There is a possibility that the same line can be matched as a command in some node and its parent node. In this case, when reading the config, this line is always executed as a command of the child node. For example, with the following config: ``` router ospf network 193.168.0.0/16 area 0 ! mpls ldp discovery hello interval 111 ! ``` Line `mpls ldp` is processed as command `mpls ldp-sync` inside the `router ospf` node. This leads to a complete loss of `mpls ldp` node configuration. To eliminate this issue and all possible similar issues, let's print an explicit "exit" at the end of every node config. This commit also changes indentation for a couple of existing exit commands so that all existing commands are on the same level as their corresponding node-entering commands. Fixes #9206. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-07-29*: cleanup interface node installationIgor Ryzhov
The only difference in daemons' interface node definition is the config write function. No need to define the node in every daemon, just pass the callback as an argument to a library function and define the node there. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-18lib: fix interface configuration after vrf changeIgor Ryzhov
This commit fixes the following problem: - enter the interface node - move the interface to another VRF - try to continue configuring the interface It is not possible to continue configuration because the XPath stored in the vty doesn't correspond with the actual state of the system anymore. For example: ``` nfware# conf nfware(config)# interface enp2s0 <-- move the enp2s0 to a different VRF --> nfware(config-if)# ip router isis 1 % Failed to get iface dnode in candidate DB ``` To fix the issue, go through all connected vty shells and update the stored XPath. Suggested-by: Renato Westphal <renato@opensourcerouting.org> Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-06-02northbound: KISS always batch yang config (file read), it's fasterChristian Hopps
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>
2021-05-13lib: adapt to version 2 of libyangChristian Hopps
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>
2021-04-12lib: fix interface nb stale pointersIgor Ryzhov
The first change in this commit is the processing of the VRF termination. When we terminate the VRF, we should not delete the underlying interfaces, because there may be pointers to them in the northbound configuration. We should move them to the default VRF instead. Because of the first change, the VRF interface itself is also not deleted when deleting the VRF. It should be handled in netlink_link_change. This is done by the second change. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-03-17*: require semicolon after DEFINE_QOBJ & co.David Lamparter
Again, see previous commits. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17*: require semicolon after DEFINE_HOOK & co.David Lamparter
See previous commit. Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17*: require semicolon after DEFINE_MTYPE & coDavid Lamparter
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>
2021-02-02lib: add utility to get the next index in a vrfPat Ruddy
Add if_vrf_lookup_by_index_next to get the next ifindex in a vrf given the previous ifindex or 0 for the first. Signed-off-by: Pat Ruddy <pat@voltanet.io>
2021-01-28lib: Remove #if 0 codeDonald Sharp
Just some more dead code that has been sitting unused for a very long time. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-10-22lib: Convert inet_ntoa to %pI4Donatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-10-17lib: Convert usage of strings to %pFX and %pRNDonald Sharp
Convert over to using the %pFX and %pRN modifiers to output strings to allow us to consolidate on one standard for printing prefixes. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-09-21*: Remove solaris from FRRDonald Sharp
The Solaris code has gone through a deprecation cycle. No-one has said anything to us and worse of all we don't have any test systems running Solaris to know if we are making changes that are breaking on Solaris. Remove it from the system so we can clean up a bit. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2020-08-28lib: Note old ifindex on shutdownDonald Sharp
If we have an interface configured in a daemon on shutdown store the old ifindex value for retrieval on when it is possibly recreated. This is especially important for nexthop groups as that we had at one point in time the ability to restore the configuration but it was lost when we started deleting all deleted interfaces. We need the nexthop group subsystem to also mark that it has configured an interface. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-08-05evpn-netns: Revert PR5077, has been re-worked post-refactorPat Ruddy
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>
2020-08-03lib: introduce configuration back-off timer for YANG-modeled commandsRenato Westphal
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>
2020-08-03*: introduce DEFPY_YANG & friendsRenato Westphal
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>
2020-07-14*: un-split strings across linesDavid Lamparter
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-06-22zebra: show interfaces from all VRFs in "show interface ..." commandsIgor Ryzhov
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2020-06-10Merge pull request #6414 from opensourcerouting/nb-error-handlingSantosh P K
NB context + enhanced error handling
2020-06-04lib: move all userdata when changing node xpathQuentin Young
All userdata pointers need to be rekeyed to their new xpaths, not just the one associated with the dnode being moved. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-05-28*: convert northbound callbacks to new error handling modelRenato Westphal
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-19Merge pull request #6426 from pguibert6WIND/update_ifname_before_hookStephen Worley
Update ifname before hook
2020-05-19lib: fix bandwidth multiplier for link paramEmanuele Di Pascale
in the CLI we state that the bandwidth of a link is in Megabits per second, but when converting it to Bytes per second for TE purposes we were treating it as Kilobits. Fix the conversion error. Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2020-05-19lib, zebra: update interface name at netlink creationPhilippe Guibert
the interface name was not present in the hook in charge of updating the interface context to the registered hook service. For that, update the name before informing it. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2020-04-30lib: constify a few parameters of helper functionsRenato 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>
2020-04-24Merge pull request #6279 from opensourcerouting/nb-cb-argsDonald Sharp
*: change the signature of the northbound callbacks to be more flexible
2020-04-23*: change the signature of the northbound callbacks to be more flexibleRenato Westphal
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-20*: sprintf -> snprintfQuentin Young
Replace sprintf with snprintf where straightforward to do so. - sprintf's into local scope buffers of known size are replaced with the equivalent snprintf call - snprintf's into local scope buffers of known size that use the buffer size expression now use sizeof(buffer) - sprintf(buf + strlen(buf), ...) replaced with snprintf() into temp buffer followed by strlcat Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-16lib: remove gcc 4.x workaround for nb structureChirag Shah
Remove gcc 4.x workaround for variable size array as gcc check moved to header file. In lib/northbound.h : struct frr_yang_module_info made size 1000 for gcc 4.x, where maximum 1000 nodes can fit. Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-04-16lib: add interface operational northbound callbackChirag Shah
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-04-13lib: handle failure to change ifindexQuentin Young
This fixes a theoretical bug that could occur when trying to change an ifindex on an interface to that of an existing interface. We would remove the interface from the ifindex tree, and change the ifindex, but when we tried to reinsert the interface, the insert would fail. It was impossible to know if this failed due to the insertion / deletion macros capturing the result value of the underlying BSD tree macros. So we would effectively delete the interface. Instead of failing on insert, we just check if the prospective ifindex already exists and return -1 if it does. Macros have been changed to statement expressions so the result can be checked, and bubbled up. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-13lib: remove unnecessary null checksQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-04-03lib: consolidate flexible array hack in a single placeRenato Westphal
Old gcc versions (< 5.x) have a bug that prevents C99 flexible arrays from working properly on shared libraries. We already have a hack in place to work around this problem, but it needs to be replicated in every declaration of a frr_yang_module_info variable within libfrr. This clearly isn't a good solution if we consider that many more libfrr YANG modules are about to come in the future. This commit introduces a different workaround that operates within the northbound layer itself, such that implementers of libfrr YANG modules won't need to worry about this problem anymore. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-03-11*: Remove tests for some XFREE-family functionsDonatas Abraitis
XFREE() covers that. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-14lib: Add vrf name to outputs/debugsDonald Sharp
Add some additional output/debug to code to allow us to see the vrf name instead of just the vrf id. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-02-14lib: Format according to our standardDonald Sharp
A couple of functions needed to be reformated. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-02-03*: don't null after XFREE; XFREE does this itselfQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-01-03lib: fix ifindex comparison overflowQuentin Young
Very small (negative!) ifindexes, when subtracted, can overflow. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-12-13lib: make some variables staticDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-10lib: fixes invalid running_entry when VRF is changedMahdi Varasteh
we just unset the entry from old node and add it to the new one Signed-off-by: Mahdi Varasteh <mahdy.varasteh@gmail.com>
2019-11-30lib: gcc 4.x workaround v2 for frr_interface_infoDavid Lamparter
The previous workaround only works for -O0, at higher optimization levels gcc reorders the statements in the file global scope which breaks the asm statement :(. Fixes: #4563 Fixes: #5074 Signed-off-by: David Lamparter <equinox@diac24.net>
2019-11-26lib: add gcc 4.x workaround for frr_interface_infoDavid Lamparter
gcc 4.x does not properly support structs with variable length array members. Specifically, for global variables, it completely ignores the array, coming up with a size much smaller than what is correct. This is broken for both sizeof() as well as ELF object size. This breaks for frr_interface_info since this variable is in some cases copy relocated by the linker. (The linker does this to make the address of the variable a "constant" for the main program.) This copying uses the ELF object size, thereby copying only the non-array part of the struct. Breakage ensues... (This fix is a bit ugly, but it's limited to very old gcc, and it's better than changing the array to "nodes[1000]" and wasting memory...) Fixes: #4563 Fixes: #5074 Signed-off-by: David Lamparter <equinox@diac24.net>
2019-11-02lib, ospfd, zebra: Convert interface_delete to take double pointerDonald Sharp
When free'ing the interface pointer, set it to NULL. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-11-02*: Convert connected_free to a double pointerDonald Sharp
Set the connected pointer to set the pointer to NULL. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-11-02*: Convert prefix_free to double pointerDonald Sharp
Have the prefix_free code take a double pointer to free the data. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-10-29vrrpd: only count ipv4 addresses on check startGhasem Naddaf
Signed-off-by: Ghasem Naddaf <ghasem.naddaf@gmail.com>