summaryrefslogtreecommitdiff
path: root/lib/vrf.c
AgeCommit message (Collapse)Author
2016-10-07lib: qobj: register ifaces, routemaps & keychainsDavid Lamparter
This places the appropriate calls so library objects can be used with qobj "pointers", especially in the CLI. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-09-19*: split & distribute memtypes and stop (re|ab)using lib/ MTYPEsDavid Lamparter
This is a rather large mechanical commit that splits up the memory types defined in lib/memtypes.c and distributes them into *_memory.[ch] files in the individual daemons. The zebra change is slightly annoying because there is no nice place to put the #include "zebra_memory.h" statement. bgpd, ospf6d, isisd and some tests were reusing MTYPEs defined in the library for its own use. This is bad practice and would break when the memtype are made static. Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Acked-by: Donald Sharp <sharpd@cumulusnetworks.com> [CF: rebased for cmaster-next] Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-06-28zebra/ospf/ospf6: Fix several memory leaks on if up/downDon Slice
Resolved several memory leaks caused by ifdown/ifup the vrf device or a swp port. For bgp/zebra/ospf/ospf6, bouncing the vrf device would cause a linked list, Interface, and route-table to get leaked. For ospf6, bouncing the swp device also caused leaks of Connected and Prefix entries. Ticket: CM-10841 Signed-off-by: Don Slice Reviewed-By: Donald Sharp Testing Done: Manual testing, bgp and ospf mins passed, smokes had fewer failures than base
2016-05-06lib: Vrf disable hook was never being runDonald Sharp
The check for the fact a vrf was enabled was immediately after we disabled it in vrf_disable() Ticket: CM-10139 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
2016-05-04lib: Fix unprotected debugDonald Sharp
"Vrf found: %p" was not protected by a debug check and as such we were seeing allot of extraneous output. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2016-05-03lib: Rework vrf_getDonald Sharp
vrf_get has these possible lookup/creation ways of being called. name = NULL, vrf_id = VRF_UNKNOWN Nothing to do here. name = NULL, vrf_id != VRF_UNKNOWN Look up the vrf_id in the table. Return that created vrf. If not found create a struct vrf to hold it properly. name = <something>, vrf_id = VRF_UNKNOWN Look up the name in the vrf list, if found return that vrf. If not found create the vrf and zvrf name = <something>, vrf_id != VRF_UNKNOWN Look up the name in the vrf list, if found check to see if the vrf->vrf_id is VRF_UNKNOWN, if so match up and return If not found, create the vrf and table entry and return Ticket: CM-10139 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Signed-off-by: Don Slice <dslice@cumulusnetworks.com> Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2016-04-21zebra: Only create vrf route-node if in the kernelDon Slice
Changed vrf_get to only create a route-node if the kernel has enabled the vrf, supplying a table-id. If the quagga configuration contains vrfs that have not yet been enabled by the kernel, the vrf is created with a vrf_id of VRF_UNKNOWN. These vrfs are added to the vrf_list so they contain a zvrf and configuration, but the route-node is not created until the kernel has signalled that the vrf has been defined and enabled. Ticket: CM-10481 Signed-off-by: Don Slice Reviewed-by: Donald Sharp
2016-04-14lib, zebra: Rework vrf_add_updateDonald Sharp
The vrf_add_update function does not need to exist. Move it's constituent parts into the appropriate vrf_create/vrf_enable functionality as well as move the zebra_vrf_add_update() function call into zebra_vrf_enable() Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com> Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2016-04-14lib, zebra: Rearrange vrf_delete_updateDonald Sharp
vrf_delete_update really belongs in vrf.c broken up into it's appropriate places. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com> Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2016-04-12lib, zebra: Refactor vrf creation a bit moreDonald Sharp
Create the idea of a VRF_UNKNOWN, this is for a vrf where we don't yet have the vrf_id for it yet. Refactor the vrf_create code out of existence. We had two code paths vrf_create and vrf_get. We should use vrf_get to create the new vrf since XXX_get() creates the data structures now. Signed-off-by: Donald Sharp Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2016-04-12lib: passing in vrf string length is not neededDonald Sharp
vrf_create does not need the string length of the vrf. Remove it. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2016-04-08quagga: Remove iflist global variableDonald Sharp
The file if.c has a iflist that had the list of interfaces in the default vrf. Remove this variable and replace with a vrf_iflist lookup on the default vrf where it was used. Additionally, modify ptm code to iterate over all vrf's when enabling ptm. Ticket: CM-10338 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com> Reviewed-by: Radhika Mahankali <radhika@cumulusnetworks.com>
2016-04-08lib, zebra: Rename ZEBRA_VRF_ACTIVEDonald Sharp
ZEBRA_VRF_ACTIVE is a poor name for when a vrf is actually active. Rename VRF_ACTIVE. Ticket: CM-10338 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com> Reviewed-by: Radhika Mahankali <radhika@cumulusnetworks.com>
2016-04-08lib: Refactor XX_name_len awayDonald Sharp
We had two functions XXX_name and XXX_name_len that both did the same thing. Remove the XXX_rename_len functions. Ticket: CM-10338 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com> Reviewed-by: Radhika Mahankali <radhika@cumulusnetworks.com>
2016-04-05lib: Initialize variablevivek
Initialize a variable to prevent warnings. Updates: 8087b296b4750eda2d34e4f48731f81415bdccd2 Ticket: CM-10258 Reviewed By: Trivial Testing Done: None
2016-04-05lib: Ensure VRF is created with correct idvivek
In function vrf_get(), an early call to vrf_get_by_name() may end up creating the Zebra VRF structure prior to the VRF id being set, resulting in various other misbehavior. Fix this with appropriate changes. Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Ticket: CM-10258 Reviewed By: CCR-4418 Testing Done: Manual
2016-04-01lib, zebra: Fix vrf new hook callback.Donald Sharp
This commit fixes two issues: 1) The creation of a new vrf from the cli was not calling the vrf_create hook. This is fixed. 2) The zebra_vrf_delete callback was deleting interface information that belonged to vrf not zvrf. Remove the code as that it was not it's job to do so. Ticket: CM-10100 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-03-31lib: Combine name comparison functionDonald Sharp
The vrf name comparison function was the same as the interface comparison function. Combine the forces for the goodness of mankind. Ticket: CM-10184 Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
2016-03-25Quagga: Fix VRF lookup by namevivek
Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Ticket: CM-10098 Reviewed By: CCR-4368 Testing Done: Verified on failed node
2016-02-24BGP: Fix interface list upon instance creation/deletionvivek
The BGP instance cleanup was deleting interfaces in that instance after prior fixes, but this ended up deleting the interface list header which was not being re-created. Added code to re-create this at the time an instance is created. Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Ticket: CM-9466 Reviewed By: CCR-4164 Testing Done: Manual and verified failed test
2016-02-22BGP: Cleanup interfaces properly on instance delete or exitvivek
Perform interface cleanup as an instance is deleted. This takes care of the scenario when BGP exits (or is stopped/restarted) too as instances undergo deletion and the interface cleanup is done as the last step in that. Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Fixes: 46abd3e3e6eb1f723ea7905c9919b65f1a76f385 Ticket: CM-9410 Reviewed By: CCR-4143 Testing Done: Reran failed test
2016-02-03lib, vtysh, zebra: Better VRF debug handlingDonald Sharp
Fixup the debug handling of vrf's to be a bit more explicit how we create a vrf internally. Add code to turn on/off debugging of vrf's. Ticket: CM-9063 Testing: Manual Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2016-02-01lib, zebra: Abstract vrf.c to handle both vrf_id_t and char *nameDonald Sharp
Abstract vrf.c code to allow pass in a vrf name as well as to start the coding of how namespaces and vrf's will interact. Signed-off-by: Vipin Kumar <vipin@cumulusnetworks.com> Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2015-11-03*: add VRF ID in the API message headerFeng Lu
The API messages are used by zebra to exchange the interfaces, addresses, routes and router-id information with its clients. To distinguish which VRF the information belongs to, a new field "VRF ID" is added in the message header. And hence the message version is increased to 3. * The new field "VRF ID" in the message header: Length (2 bytes) Marker (1 byte) Version (1 byte) VRF ID (2 bytes, newly added) Command (2 bytes) - Client side: - zclient_create_header() adds the VRF ID in the message header. - zclient_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the callback functions registered to the API messages. - All relative functions are appended with a new parameter "vrf_id", including all the callback functions. - "vrf_id" is also added to "struct zapi_ipv4" and "struct zapi_ipv6". Clients need to correctly set the VRF ID when using the API functions zapi_ipv4_route() and zapi_ipv6_route(). - Till now all messages sent from a client have the default VRF ID "0" in the header. - The HELLO message is special, which is used as the heart-beat of a client, and has no relation with VRF. The VRF ID in the HELLO message header will always be 0 and ignored by zebra. - Zebra side: - zserv_create_header() adds the VRF ID in the message header. - zebra_client_read() extracts and validates the VRF ID from the header, and passes the VRF ID to the functions which process the received messages. - All relative functions are appended with a new parameter "vrf_id". * Suppress the messages in a VRF which a client does not care: Some clients may not care about the information in the VRF X, and zebra should not send the messages in the VRF X to those clients. Extra flags are used to indicate which VRF is registered by a client, and a new message ZEBRA_VRF_UNREGISTER is introduced to let a client can unregister a VRF when it does not need any information in that VRF. A client sends any message other than ZEBRA_VRF_UNREGISTER in a VRF will automatically register to that VRF. - lib/vrf: A new utility "VRF bit-map" is provided to manage the flags for VRFs, one bit per VRF ID. - Use vrf_bitmap_init()/vrf_bitmap_free() to initialize/free a bit-map; - Use vrf_bitmap_set()/vrf_bitmap_unset() to set/unset a flag in the given bit-map, corresponding to the given VRF ID; - Use vrf_bitmap_check() to test whether the flag, in the given bit-map and for the given VRF ID, is set. - Client side: - In "struct zclient", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] default_information These flags are extended for each VRF, and controlled by the clients themselves (or with the help of zclient_redistribute() and zclient_redistribute_default()). - Zebra side: - In "struct zserv", the following flags are changed from "u_char" to "vrf_bitmap_t": redist[ZEBRA_ROUTE_MAX] redist_default ifinfo ridinfo These flags are extended for each VRF, as the VRF registration flags. They are maintained on receiving a ZEBRA_XXX_ADD or ZEBRA_XXX_DELETE message. When sending an interface/address/route/router-id message in a VRF to a client, if the corresponding VRF registration flag is not set, this message will not be dropped by zebra. - A new function zread_vrf_unregister() is introduced to process the new command ZEBRA_VRF_UNREGISTER. All the VRF registration flags are cleared for the requested VRF. Those clients, who support only the default VRF, will never receive a message in a non-default VRF, thanks to the filter in zebra. * New callback for the event of successful connection to zebra: - zclient_start() is splitted, keeping only the code of connecting to zebra. - Now zclient_init()=>zclient_connect()=>zclient_start() operations are purely dealing with the connection to zbera. - Once zebra is successfully connected, at the end of zclient_start(), a new callback is used to inform the client about connection. - Till now, in the callback of connect-to-zebra event, all clients send messages to zebra to request the router-id/interface/routes information in the default VRF. Of corse in future the client can do anything it wants in this callback. For example, it may send requests for both default VRF and some non-default VRFs. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Donald Sharp <sharpd@cumulusnetworks.com> Conflicts: lib/zclient.h lib/zebra.h zebra/zserv.c zebra/zserv.h Conflicts: bgpd/bgp_nexthop.c bgpd/bgp_nht.c bgpd/bgp_zebra.c isisd/isis_zebra.c lib/zclient.c lib/zclient.h lib/zebra.h nhrpd/nhrp_interface.c nhrpd/nhrp_route.c nhrpd/nhrpd.h ospf6d/ospf6_zebra.c ospf6d/ospf6_zebra.h ospfd/ospf_vty.c ospfd/ospf_zebra.c pimd/pim_zebra.c pimd/pim_zlookup.c ripd/rip_zebra.c ripngd/ripng_zebra.c zebra/redistribute.c zebra/rt_netlink.c zebra/zebra_rnh.c zebra/zebra_rnh.h zebra/zserv.c zebra/zserv.h
2015-10-30lib/vrf: enable / disable a VRFFeng Lu
A new API vrf_is_enabled() is defined to check whether a VRF is ready to use, that is, to allocate resources in that VRF. Currently there's only one type of resource: socket. Two new hooks VRF_ENABLE_HOOK/VRF_DISABLE_HOOK are introduced to tell the user when a VRF gets ready or to be unavailable. The VRF_ENABLE_HOOK callback is called in the new function vrf_enable(), which is used to let the VRF be ready to use. Till now, only the default VRF can be enabled, and we need do nothing to enable the default, except calling the hook. The VRF_DISABLE_HOOK callback is called in the new function vrf_disable(), which is used to let the VRF be unusable. Till now, it is called only when the VRF is to be deleted. A new utility vrf_socket() is defined to provide a socket in a given VRF to the user. Till now before introducing a way of VRF realization, only the default VRF is enabled since its birth, and vrf_socket() creates socket for only the default VRF. This patch defines the framework of the VRF APIs. The way they serve the users is: - vrf_is_enabled() is used to tell the user whether a VRF is usable; - users are informed by the VRF_ENABLE_HOOK that a VRF gets usable; they can allocate resources after that; - users are informed by the VRF_DISABLE_HOOK that a VRF is to be unavailable, and they must release the resources instantly; - vrf_socket() is used to provide a socket in a given VRF. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2015-10-29lib: move the interface list into "struct vrf"Feng Lu
An interface belongs to a specific VRF. So move the interface list into the "struct vrf". * vrf.c/vrf.h: - add a new member "struct list *iflist" to the the "struct vrf"; - call if_init() in vrf_new(); - call if_terminate() in vrf_delete(); - add utilities to access the interface list and VRF ID in the specified VRF. * if.c/if.h: - the global "iflist" now only exists for the default VRF; - the global "if_master" is initialized on the definition; - in if_create(), the interface is added into the list in the specified VRF; if the VRF does not exist, create one; - add parameters to if_init()/if_terminate() so that the interface list in the VRF can be initialized/destroyed; - in if_dump_all() scan the interfaces in all the VRFs; - add a command "show address vrf N" to show addresses in a specified VRF; - add a command "show address vrf all" to show addresses in all VRFs; - new APIs ifxxx_vrf() are added to access an interface in a specified VRF. The old interface APIs (the global variable "iflist" and the API functions) are not changed to keep the backward compatibility. The new APIs are used in the daemons which support multiple VRFs (till now only zebra). Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Conflicts: lib/if.c
2015-10-29*: call if_init()/if_terminate() from vrf_init()/vrf_terminate()Feng Lu
Later, an interface will belong to a specific VRF, and the interface initialization will be a part of the VRF initialization. So now call if_init() from vrf_init(), and if_terminate() from vrf_terminate(). Daemons have the according changes: - if if_init() was called or "iflist" was initialized, now call vrf_init() instead; - if if_terminate() was called or "iflist" was destroyed, now call vrf_terminate() instead. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Conflicts: bgpd/bgp_main.c pimd/pim_iface.c pimd/pim_iface.h pimd/pim_main.c pimd/pimd.c
2015-10-29lib, zebra: move "struct vrf" to be a lib moduleFeng Lu
Previously "struct vrf" is defined locally in zebra. Now it is moved to be a lib module. This is the first step to support multi-VRF in quagga. The implementation is splitted into small patches for the purpose of easy review. * lib: "struct vrf" with basic members is defined in vrf.c. The member "void *info" is for user data. Some basic functions are defined in vrf.c for adding/deleting/ looking up a VRF, scanning the VRF table and initializing the VRF module. The type "vrf_id_t" is defined specificly for VRF ID. * zebra: The previous "struct vrf" is re-defined as "struct zebra_vrf"; and previous "vrf" variables are renamed to "zvrf". The previous "struct vrf" related functions are removed from zbera_rib.c. New functions are defined to maintain the new "struct zebra_vrf". The names vrf_xxx are reserved for the functions in VRF module. So: - the previous vrf_table() are renamed to zebra_vrf_table(); - the previous vrf_static_table() are renamed to zebra_vrf_static_table(). The main logic is not changed. BTW: Add a statement to zebra_snmp.c telling that the SNMP is running only for the MIBs in the default VRF. Signed-off-by: Feng Lu <lu.feng@6wind.com> Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Vincent JARDIN <vincent.jardin@6wind.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Conflicts: lib/Makefile.am zebra/zebra_rib.c zebra/zebra_vty.c Conflicts: lib/Makefile.am lib/memtypes.c zebra/rib.h zebra/zebra_rib.c zebra/zebra_rnh.c zebra/zebra_rnh.h zebra/zebra_vty.c