lib: a vrf is searched first by its name, than its vrf id

Because at startup, remote daemons attempt to create default VRF,
the VRF_ID may be set to unknown. In that case, an event will be
triggered later by zebra to inform remote daemon that the vrf id of that
VRF has changed to valid value. In that case, two instances of default
VRF must not be created. By looking first at vrf name, this avoids
having two instances.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2018-03-20 10:59:48 +01:00
parent a6528075a8
commit 0c2bac3880

View File

@ -159,11 +159,13 @@ struct vrf *vrf_get(vrf_id_t vrf_id, const char *name)
if (!name && vrf_id == VRF_UNKNOWN)
return NULL;
/* Try to find VRF both by ID and name */
if (vrf_id != VRF_UNKNOWN)
vrf = vrf_lookup_by_id(vrf_id);
if (!vrf && name)
/* attempt to find already available VRF
*/
if (name)
vrf = vrf_lookup_by_name(name);
/* Try to find VRF both by ID and name */
if (!vrf && vrf_id != VRF_UNKNOWN)
vrf = vrf_lookup_by_id(vrf_id);
if (vrf == NULL) {
vrf = XCALLOC(MTYPE_VRF, sizeof(struct vrf));