diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2021-10-13 15:06:38 +0300 | 
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-10-19 15:29:51 +0300 | 
| commit | f60a11883cb426f574dbe5abeff8254148e7c371 (patch) | |
| tree | 2b489718f0d61ed4c5b043959bcbe3e18035d874 /lib/vrf.c | |
| parent | e9f7b2b597ad8c6947ce3b7238e89391e4f9f863 (diff) | |
lib: allow to create interfaces in non-existing VRFs
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>
Diffstat (limited to 'lib/vrf.c')
| -rw-r--r-- | lib/vrf.c | 22 | 
1 files changed, 10 insertions, 12 deletions
@@ -272,32 +272,29 @@ void vrf_delete(struct vrf *vrf)  	if (vrf_is_enabled(vrf))  		vrf_disable(vrf); +	if (vrf->vrf_id != VRF_UNKNOWN) { +		RB_REMOVE(vrf_id_head, &vrfs_by_id, vrf); +		vrf->vrf_id = VRF_UNKNOWN; +	} +  	/* If the VRF is user configured, it'll stick around, just remove  	 * the ID mapping. Interfaces assigned to this VRF should've been  	 * removed already as part of the VRF going down.  	 */  	if (vrf_is_user_cfged(vrf)) { -		if (vrf->vrf_id != VRF_UNKNOWN) { -			/* Delete any VRF interfaces - should be only -			 * the VRF itself, other interfaces should've -			 * been moved out of the VRF. -			 */ -			if_terminate(vrf); -			RB_REMOVE(vrf_id_head, &vrfs_by_id, vrf); -			vrf->vrf_id = VRF_UNKNOWN; -		}  		vrf->ns_ctxt = NULL;  		return;  	} +	/* Do not delete the VRF if it has interfaces configured in it. */ +	if (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) +		return; +  	if (vrf_master.vrf_delete_hook)  		(*vrf_master.vrf_delete_hook)(vrf);  	QOBJ_UNREG(vrf); -	if_terminate(vrf); -	if (vrf->vrf_id != VRF_UNKNOWN) -		RB_REMOVE(vrf_id_head, &vrfs_by_id, vrf);  	if (vrf->name[0] != '\0')  		RB_REMOVE(vrf_name_head, &vrfs_by_name, vrf); @@ -571,6 +568,7 @@ static void vrf_terminate_single(struct vrf *vrf)  {  	/* Clear configured flag and invoke delete. */  	UNSET_FLAG(vrf->status, VRF_CONFIGURED); +	if_terminate(vrf);  	vrf_delete(vrf);  }  | 
