summaryrefslogtreecommitdiff
path: root/lib/if.c
AgeCommit message (Collapse)Author
2024-05-29Merge pull request #15082 from louis-6wind/fix-iff-lower-upIgor Ryzhov
lib: take into account the Linux IFF_LOWER_UP flag
2024-05-06if: fix same connected addressLoïc Sang
Using the same address with a different prefix length is not supported. If we configure two identical addresses with different netmasks 192.168.1.1/30 and then 192.168.1.1/29. Zebra sends '192.168.1.1' with a prefix length of 29. However, the function 'zebra_interface_address_read()' reads '192.168.1.1/30' because the prefix length is not checked. Using 'same_prefix()' is more convenient. Signed-off-by: Loïc Sang <loic.sang@6wind.com>
2024-04-26lib: take into account the iff_lower_up flagLouis Scalbert
In Linux, a network driver can set the interface flags IFF_UP and IFF_RUNNING although the IFF_LOWER_UP flag is down, which means the interface is ready but the carrier is down: > These values contain interface state: > > ifinfomsg::if_flags & IFF_UP: > Interface is admin up > ifinfomsg::if_flags & IFF_RUNNING: > Interface is in RFC2863 operational state UP or UNKNOWN. This is for > backward compatibility, routing daemons, dhcp clients can use this > flag to determine whether they should use the interface. > ifinfomsg::if_flags & IFF_LOWER_UP: > Driver has signaled netif_carrier_on() However, FRR considers an interface is operational as soon it is up (IFF_UP) and running (IFF_RUNNING), disregarding the IFF_LOWER_UP flag. This can lead to a scenario where FRR starts adding routes through an interface that is technically down at the carrier level, resulting in kernel errors. > Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=243, pid=3112881162 > Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (318[if 164]) into the kernel > Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Carrier for nexthop device is down > Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=245, pid=3112881162 > Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Nexthop id does not exist > Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Invalid argument, type=RTM_NEWROUTE(24), seq=246, pid=3112881162 > Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (320[10.125.0.2 if 164]) into the kernel > Jan 02 18:07:18 dut-vm zebra[283731]: [VYKYC-709DP] default(0:254):0.0.0.0/0: Route install failed Consider an interface is operational when it has the IFF_UP, IFF_RUNNING and IFF_LOWER_UP flags. Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/operstates.rst?h=v6.7-rc8#n29 Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/nexthop.c?h=v6.7-rc8#n2886 Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/netdevice.h?h=v6.7-rc8#n4198 Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-04-26build: include our own copy of if.h and dependenciesLouis Scalbert
Import our a copy of Linux if.h and its dependencies (compiler_types.h and libc-compat.h) from the above links. In "if.h", "#include <linux/compiler.h>" has been replaced by "#include <linux/compiler_types.h>". libc-compat.h is needed to avoid conflicts with glibc. Include "linux/if.h" in "zebra.h" when compiling on Linux. De-reference "net/if.h" in C files. Note that "net/if.h" is still needed. It is even included in many Linux kernel files. "linux/if.h" provides additional definitions. Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/if.h?h=v5.5 Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/libc-compat.h?h=v5.5 Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/linux/compiler_types.h?h=v5.5 Link: https://patchwork.ozlabs.org/project/glibc/patch/1461512707-23058-1-git-send-email-mikko.rapeli@iki.fi/ Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-03-06lib: fix order of interfaces in the configIgor Ryzhov
Add missing cli_cmp callback. Without it, interfaces are not sorted and printed in order they were created. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04lib, mgmtd: don't register NB config callbacks in mgmtdIgor Ryzhov
mgmtd is supposed to only register CLI callbacks. If configuration callbacks are registered, they are getting called on startup when mgmtd reads config files, and they can use infrastructure that is not initialized on mgmtd, or allocate some memory that is never freed. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-28lib: don't set LP_EXTEND_ADM_GRP by defaultIgor Ryzhov
It shouldn't be set unless some affinity is configured. NB callbacks set this flag correctly when necessary. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-19zebra: fix default value for affinity-modeIgor Ryzhov
- initialize the necessary bit when creating if_link_params - fix CLI description to mark extended as the default mode - correctly set mode to extended when using the "no" form of the command - handle the "show_defaults" parameter correctly in cli_show callback Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-14yang: lib: interface MTUs can be larger than uint16Christian Hopps
Technically changing a leaf from uint16 to uint32 is a NBC change; however, increasing this to uint32 should not break anyone in reality. Signed-off-by: Christian Hopps <chopps@labn.net>
2023-11-29lib: all: remove './' from xpath 22% speedupChristian Hopps
fixes #8299 Signed-off-by: Christian Hopps <chopps@labn.net>
2023-11-22*: convert `struct interface->connected` to DLISTDavid Lamparter
Replace `struct list *` with `DLIST(if_connected, ...)`. NB: while converting this, I found multiple places using connected prefixes assuming they were IPv4 without checking: - vrrpd/vrrp.c: vrrp_socket() - zebra/irdp_interface.c: irdp_get_prefix(), irdp_if_start(), irdp_advert_off() (these fixes are really hard to split off into separate commits as that would require going back and reapplying the change but with the old list handling) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-11-21*: Let's use the native IFNAMSIZ instead of INTERFACE_NAMSIZDonald Sharp
INTERFACE_NAMSIZ is just a redefine of IFNAMSIZ and IFNAMSIZ is the standard for interface name length on all platforms that FRR currently compiles on. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-11-02lib: convert if_zapi_callbacks into actual hooksDavid Lamparter
...so that multiple functions can be subscribed. The create/destroy hooks are renamed to real/unreal because that's what they *actually* signal. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-09-29*: Do not cast to the same type as the destination isDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-05-28lib, zebra: Ensure that the ifp->node existsDonald Sharp
On removal, ensure that the ifp->node is set to a null pointer so that FRR does not use data after freed. In addition ensure that the ifp->node exists before attempting to free it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-02-17Merge pull request #12780 from opensourcerouting/spdx-license-idDonald Sharp
*: convert to SPDX License identifiers
2023-02-10lib,yang,zebra: add extended admin-group supportLouis Scalbert
Add the support of Extended Admin-Group (RFC7308) to the zebra interface link-params Traffic-Engineering context. Extended admin-groups can be configured with the affinity-map: > affinity-map blue bit-position 221 > int eth-rt1 > link-params > affinity blue > exit-link-params Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2023-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27*: fix non-const northbound XPath format stringsDavid Lamparter
Passing a pre-formatted buffer in these places needs a `"%s"` in front so it doesn't get formatted twice. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-15lib: add a function to get the VRF or loopback interfaceLouis Scalbert
Add a function to find the VRF or the loopback interface: the loopback interface for the default VRF and the VRF master interface otherwise. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2023-01-13Revert "Merge pull request #11127 from louis-6wind/bgp-leak"Donald Sharp
This reverts commit 16aa1809e7c8caad37e8edd4e5aaac4f344bc7d3, reversing changes made to f616e716089b16d9a678846282a6ac5c55e31a56.
2022-12-16lib: fix clang warningLouis Scalbert
Fix a CLANG warning Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-16lib: add a function to get the VRF or loopback interfaceLouis Scalbert
Add a function to find the VRF or the loopback interface: the loopback interface for the default VRF and the VRF master interface otherwise. Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-12-02lib: use specific MTYPE for interface descriptionsMark Stapp
Don't use MTYPE_TMP, use a real mem type. Signed-off-by: Mark Stapp <mjs@labn.net>
2022-11-03Merge pull request #12196 from opensourcerouting/xref-vtyshDonald Sharp
*: rewrite `extract.pl` using `xref` infra
2022-10-26build, vtysh: extract vtysh commands from .xrefDavid Lamparter
Rather than running selected source files through the preprocessor and a bunch of perl regex'ing to get the list of all DEFUNs, use the data collected in frr.xref. This not only eliminates issues we've been having with preprocessor failures due to nonexistent header files, but is also much faster. Where extract.pl would take 5s, this now finishes in 0.2s. And since this is a non-parallelizable build step towards the end of the build (dependent on a lot of other things being done already), the speedup is actually noticeable. Also files containing CLI no longer need to be listed in `vtysh_scan` since the .xref data covers everything. `#ifndef VTYSH_EXTRACT_PL` checks are equally obsolete. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-10-17lib,zebra: do not enable link-params when a link-params command failsLouis Scalbert
A given interface has no enabled link-params context. If a link-params configuration command fails, the link-params is wrongly enabled: > r4(config-link-params)# no enable > r4(config-link-params)# delay > (0-16777215) Average delay in micro-second as decimal (0...16777215) > r4(config-link-params)# delay 50 min 300 max 500 > Average delay should be comprise between Min (300) and Max (500) delay > r4(config-link-params)# do sh run zebra > (...) > interface eth-rt1 > link-params > enable > exit-link-params link-params are enabled if and only if the interface structure has a valid link_params pointer. Before checking the command validity, if_link_params_get() is called to retrieve the link-params pointer. However, this function initializes the pointer if it is NULL. Only use if_link_params_get() to retrieve the pointer to avoid confusion. In command setting functions, initialize the link_params pointer if needed only after the validation of the command. Fixes: 16f1b9e ("Update Traffic Engineering Support for OSPFD") Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2022-06-20Merge pull request #11146 from NicolasDichtel/masterIgor Ryzhov
lib/if: fix interface name comparison
2022-06-16lib: correct two commentsanlan_cs
Signed-off-by: anlan_cs <vic.lan@pica8.com>
2022-05-30lib/if: fix interface name comparisonNicolas Dichtel
Using strtol() to compare two strings is a bad idea. Before the patch, if_cmp_name_func() may confuse foo001 and foo1. PR=79407 Fixes: 106d2fd572c1 ("2003-08-01 Cougar <cougar@random.ee>") Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Tested-by: Aurélien Degeorges <aurelien.degeorges@6wind.com> Acked-by: Philippe Guibert <philippe.guibert@6wind.com>
2022-02-22lib: Fix possible usage of uninited dataDonald Sharp
assert when if_lookup_address is passed with a family that is not AF_INET or AF_INET6 as that we are dead in the water and this is a dev escape Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-02lib: Correct bug for TE metric wrong assignementOlivier Dugeon
When link-param is enabled for a given interface, TE metric is automatically assigned to the metric of the interface. However, the metric of the interface could be unassigned and keep the default value equal to 0. Thus, if the TE metric is not explicitely modified within the `link-param metric` statement, TE metric remains set to 0 which is not a valid value especially when computing constrainted path. This patch changes the assignement of the default value of the TE metric. It is set to the metric of the interface only if the latter is not equal to 0. TE topotests for OSPF and IS-IS have been adjusted accordingly. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2022-01-24*: do not print vrf name for interface config when using vrf-liteIgor Ryzhov
VRF name should not be printed in the config since 574445ec. The update was done for NB config output but I missed it for regular vty output. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-23lib, yang: remove vrf from the interface list keyIgor Ryzhov
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>
2021-11-22*: cleanup ifp->vrf_idIgor Ryzhov
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>
2021-11-22Merge pull request #10076 from idryzhov/if-is-loopback-or-vrfDonald Sharp
*: unify if_is_loopback/if_is_loopback_or_vrf
2021-11-17*: clean up ifp-by-local-address function(s)David Lamparter
Most users of if_lookup_address_exact only cared about whether the address is any local address. Split that off into a separate function. For the users that actually need the ifp - which I'm about to add a few of - change it to prefer returning interfaces that are UP. (Function name changed due to slight change in behavior re. UP state, to avoid possible bugs from this change.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16*: unify if_is_loopback/if_is_loopback_or_vrfIgor Ryzhov
We should always treat the VRF interface as a loopback. Currently, this is not the case, because in some old pre-VRF code we use if_is_loopback instead of if_is_loopback_or_vrf. To avoid any future problems, the proposal is to rename if_is_loopback_or_vrf to if_is_loopback and use it everywhere. if_is_loopback is renamed to if_is_loopback_exact in case it's ever needed, but currently it's not used anywhere. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11lib: fix vrf deletion when the last interface is deletedIgor Ryzhov
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>
2021-11-05Merge pull request #9833 from idryzhov/cleanup-if-by-index-all-vrfRuss White
*: fix usage of if_lookup_by_index_all_vrf
2021-10-28lib: make if_lookup_by_index_all_vrf internalIgor Ryzhov
This function doesn't work correctly with netns VRF backend as the same index may be used in multiple netns simultaneously. So let's hide it from the public API to reduce temptation to use it instead of writing the correct code. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-27Merge pull request #9837 from idryzhov/cleanup-if-by-name-vrf-allRuss White
*: fix usage of if_lookup_by_name_all_vrf
2021-10-25*: fix interface config write in NB-converted daemonsIgor Ryzhov
When writing the config from the NB-converted daemon, we must not rely on the operational data. This commit changes the output of the interface configuration to use only config data. As the code is the same for all daemons, move it to the lib and remove all the duplicated code. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-25Merge pull request #9824 from idryzhov/nb-cli-const-lyd-nodeDonald Sharp
lib: northbound cli show/cmd functions must not modify data nodes
2021-10-19lib: allow to create interfaces in non-existing VRFsIgor Ryzhov
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>
2021-10-16Merge pull request #9828 from idryzhov/if-lookup-optimizeDonatas Abraitis
lib: optimize if_lookup_by_name_all_vrf
2021-10-15lib: make if_lookup_by_name_all_vrf internalIgor Ryzhov
This function doesn't work correctly with netns VRF backend as the same ifname may be used in multiple netns simultaneously. So let's hide it from the public API to reduce temptation to use it instead of writing the correct code. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-14Merge pull request #9817 from donaldsharp/link_type_orderingDonatas Abraitis
lib: Add missing enum values in switch statement for if_link_type_str
2021-10-13lib: optimize if_lookup_by_name_all_vrfIgor Ryzhov
We already have a VRF pointer, no need to search for it again. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-13lib: northbound cli show/cmd functions must not modify data nodesIgor Ryzhov
To ensure this, add a const modifier to functions' arguments. Would be great do this initially and avoid this large code change, but better late than never. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>