summaryrefslogtreecommitdiff
path: root/lib/if.c
AgeCommit message (Collapse)Author
2018-10-02*: list_delete_and_null() -> list_delete()David Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-09-22lib: Allow useful display of default vrf nameDonald Sharp
When entering a interface name and you fat-finger it actually display some useful information about the vrf we are in. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-09-17Merge pull request #3040 from pacovn/static_analysis__drop_const_1Quentin Young
bgpd isisd ldpd lib: const drop fixes (SA)
2018-09-17bgpd isisd ldpd lib: const drop fixes (SA)F. Aragon
Can be detected with e.g. ./configure CFLAGS=-Wcast-qual CC=clang Signed-off-by: F. Aragon <paco@voltanet.io>
2018-09-13*: LIB_[ERR|WARN] -> EC_LIBQuentin Young
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-09-11Merge pull request #2944 from thbtcllt/masterRuss White
fix zebra crash when a vrf interface changes with netns implementation for vrf
2018-09-08*: fix some solaris warningsDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-08-30lib/if.c: fix CLANG warningThibaut Collet
Fix CLANG warning: Report for if.c | 2 issues =============================================== < WARNING: else is not generally useful after a break or return < #390: FILE: /tmp/f1-28557/if.c:390: Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com>
2018-08-30zebra: fix crash when interface vrf changesThibaut Collet
This crash occurs only with netns implementation. vrf meaning is different regarging its implementation (netns or vrf-lite) - With vrf-lite implementation vrf is a property of the interface that can be changed as the speed or the state (iproute2 command: "ip link set dev IF_NAME master VRF_NAME"). All interfaces of the system are in the same netns and so interface name is unique. - With netns implementation vrf is a characteristic of the interface that CANNOT be changed: it is the id of the netns where the interface is located. To change the vrf of an interface (iproute2 command to move an interface "ip netns exec VRF_NAME1 ip link set dev IF_NAME netns VRF_NAME2") the interface is deleted from the old vrf and created in the new vrf. Interface name is not unique, the same name can be present in the different netns (typically the lo interface) and search of interface must be done by the tuple (interface name, netns id). Current tests on the vrf implementation (vrf-lite or netns) are not sufficient. In some cases (for example when an interface is moved from a vrf X to the default vrf and then move back to VRF X) we can have a corruption message and then a crash of zebra. To avoid this corruption test on the vrf implementation, needed when an interface changes, has been rewritten: - For all interface changes except deletion the if_get_by_name function, that checks if an interface exists and creates or updates it if needed, is changed: * The vrf-lite implementation is unchanged: search of the interface is based only on the name and update the vrf-id if needed. * The netns implementation search of the interface is based on the (name, vrf-id) tuple and interface is created if not found, the vrf-id is never updated. - deletion of an interface (reception of a RTM_DELLINK netlink message): * The vrf-lite implementation is unchanged: the interface information are cleared and the interface is moved to the default vrf if it does not belong to (to allow vrf deletion) * The netns implementation is changed: only the interface information are cleared and the interface stays in its vrf to avoid conflict with interface with the same name in the default vrf. This implementation reverts (partially or totally): commit 393ec5424e35 ("zebra: fix missing node attribute set in ifp") commit e9e9b1150f0c ("lib: create interface even if name is the same") commit 9373219c67e1 ("zebra: improve logs when replacing interface to an other netns") Fixes: b53686c52a59 ("zebra: delete interface that disappeared") Signed-off-by: Thibaut Collet <thibaut.collet@6wind.com> Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-08-23zebra: if multiple connecteds, select loopback or vrf if presentDon Slice
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2018-08-23lib: Convert debug to error situationDonald Sharp
This debug should be moved to an error situation since it's a developmental escape that needs to be fixed. 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-14lib, zebra: Add LIB_ERR_INTERFACEDonald Sharp
Add a error type that allows us to track bad interface states. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-08-13lib, vtysh: fix inconsistent interface commands in vtyshRenato Westphal
The definition of the interface commands in vtysh.c were outdated. Currently, all daemons that call if_cmd_init() will have the "no interface IFNAME" command and the "[no] description" commands as well, so there's no need to define exceptions for these commands anymore. To fix this, make extract.pl parse the if.c file so that vtysh can get the interface commands from there automatically. Only the "interface IFNAME [vrf NAME]" must be kept in vtysh.c because it changes the vty node and thus needs special treatment. Finally, make pimd and pbrd display interface descriptions on "sh run" when they are configured. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-07-27lib,zebra: fix json output when vrf1 when not activeNathan Van Gheem
When I did a show ip route with `json` on a vrf when it didn't exist, frr would output invalid json. Signed-off-by: Nathan Van Gheem <nathan@cumulusnetworks.com>
2018-07-10lib: remove if_lookup_by_index portion of code with unknown vrfPhilippe Guibert
This function should be called with a known vrf_id. All other cases, the other API should be called. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-03-08ospfd: Treat vrf interface as loopback typeChirag Shah
Ticket:CM-19914 Signed-off-by: Chirag Shah <chirag@cumulusnetworks.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: create interface even if name is the samePhilippe Guibert
For supporting vrf based on namespaces, it is possible that an interface with the same index is present. This is the case for loopback interfaces. For that, for each query, if the interface is not found , matching the vrf identifier, then a new interface is created, when the backens for VRF is NETNS. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-02-23*: Make assignment from RB_ROOT in while loop work betterDonald Sharp
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-01-29lib: When we shutdown we would leak interface descriptionDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com.
2018-01-12lib: Allow interface lookup by VRF_UNKNOWNDonald Sharp
Modify if_lookup_by_index to accept a VRF_UNKNOWN as a vrf_id. This will cause it to look in all vrf's for the interface pointer. Subsequently all if_XXXX functions that call this function will also get this behavior. VRF_UNKNOWN *should* not be used for interface creation as that this will break some core assumptions. This work is part of allowing vrf route leaking. Currently it is possible to create a route in the linux kernel that has a nexthop across vrf boundaries. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-01-03lib: Fix no interface cmd vrf parsingChirag Shah
For no interface <ifname> vrf VRFNAME, vrf-name is not parsed properly. Ticket:CM-19274 Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2017-10-24lib: fix coverity warnings introduced by the iface rb-tree conversionRenato Westphal
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-10*: use the FOR_ALL_INTERFACES abstraction from babeldRenato Westphal
This improves code readability and also future-proofs our codebase against new changes in the data structure used to store interfaces. The FOR_ALL_INTERFACES_ADDRESSES macro was also moved to lib/ but for now only babeld is using it. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-10lib: fix bug in if_cmp_name_func()Renato Westphal
If the p1 and p2 arguments pointed to identical strings ending with a non-numeric character (e.g. "lo"), this function would return -1 instead of 0 as one would expect. This inconsistency didn't matter for sorted linked-lists but for red-black trees it's a major source of problems. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-10*: introduce new rb-tree to optimize interface lookup by ifindexRenato Westphal
Performance tests showed that, when running on a system with a large number of interfaces, some daemons would spend a considerable amount of time in the if_lookup_by_index() function. Introduce a new rb-tree to solve this problem. With this change, we need to use the if_set_index() function whenever we want to change the ifindex of an interface. This is necessary to ensure that the 'ifaces_by_index' rb-tree is updated accordingly. The return value of all insert/remove operations in the interface rb-trees is checked to ensure that an error is logged if a corruption is detected. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-10*: use rb-trees to store interfaces instead of sorted linked-listsRenato Westphal
This is an important optimization for users running FRR on systems with a large number of interfaces (e.g. thousands of tunnels). Red-black trees scale much better than sorted linked-lists and also store the elements in an ordered way (contrary to hash tables). This is a big patch but the interesting bits are all in lib/if.[ch]. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-10lib: register 'if_var_handlers' only onceRenato Westphal
There's no need to register 'if_var_handlers' for every VRF, we need to do it only once. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-10lib: nuke the if_*_by_name_len() functionsRenato Westphal
Make use of strnlen() and strlcpy() so we can get rid of these convoluted if_*_by_name_len() functions. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-05*: Convert list_free usage to list_deleteDonald Sharp
list_free is occassionally being used to delete the list and accidently not deleting all the nodes. We keep running across this usage pattern. Let's remove the temptation and only allow list_delete to handle list deletion. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-05*: Convert list_delete(struct list *) to ** to allow nullingDonald Sharp
Convert the list_delete(struct list *) function to use struct list **. This is to allow the list pointer to be nulled. I keep running into uses of this list_delete function where we forget to set the returned pointer to NULL and attempt to use it and then experience a crash, usually after the developer has long since left the building. Let's make the api explicit in it setting the list pointer to null. Cynical Prediction: This code will expose a attempt to use the NULL'ed list pointer in some obscure bit of code. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-09-15*: use clang's 'ForEachMacros' format style optionRenato Westphal
This fixes the broken indentation of several foreach loops throughout the code. From clang's documentation[1]: ForEachMacros: A vector of macros that should be interpreted as foreach loops instead of as function calls. [1] http://clang.llvm.org/docs/ClangFormatStyleOptions.html Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-08-15lib: replace if_add_hook with hook_* logicDavid Lamparter
This allows modules to register their own additional hooks on interface creation/deletion. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17*: reindentreindent-master-afterwhitespace / reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'` Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14Merge remote-tracking branch 'frr/master' into newline-reduxDavid Lamparter
Lots of conflicts from CMD_WARNING_CONFIG_FAILED... Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14*: remove VTYNL, part 4 of 6David Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14*: remove VTYNL, part 3 of 6David Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14*: remove VTYNL, part 2 of 6David Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14*: ditch vty_outln(), part 2 of 2David Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-13vtysh: return non-zero for configuration failuresDaniel Walton
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com> This allows frr-reload.py (or anything else that scripts via vtysh) to know if the vtysh command worked or hit an error.
2017-07-13*: ditch vty_outln(), part 1 of 2David Lamparter
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-06-29Merge pull request #767 from donaldsharp/if_updateJafar Al-Gharaibeh
bgpd, lib, zebra: Fix if_update function to represent what it does
2017-06-29*: s/VTY_NEWLINE/VTYNL/gQuentin Young
Should be able to fit more vty_out onto one line now Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29*: use vty_outlnQuentin Young
Saves 400 lines Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-06-29bgpd, lib, zebra: Fix if_update function to represent what it doesDonald Sharp
The if_update function was taking the interface name as input and reapplying it, using strncpy to reapply the name. This has several issues. strncpy should not be used to copy memory in place. The second issue is that the interface name is not actually changing when we update interface to be in the new vrf. Since every usage of if_update was just reapplying the same name the interface actually had, just remove that part of the function and rename it to if_update_to_new_vrf to represent what it is actually doing. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-15*: make consistent & update GPLv2 file headersDavid Lamparter
The FSF's address changed, and we had a mixture of comment styles for the GPL file header. (The style with * at the beginning won out with 580 to 141 in existing files.) Note: I've intentionally left intact other "variations" of the copyright header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15lib: cli: autocomplete variablesDavid Lamparter
Shows known values in the appropriate naming domain when the user hits <?> or <Tab>. This patch only works in the telnet CLI, the next patch adds vtysh support. Included completions: - interface names - route-map names - prefix-list names Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-03-15bgpd, lib, zebra: Rename if_update_vrf -> if_updateDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-03-15bgpd, lib, zebra: Refactor ifname2ifindex to be VRF awareDonald Sharp
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>