diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2024-02-02 00:57:59 +0200 | 
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2024-02-02 00:57:59 +0200 | 
| commit | cb781f60972aca7e0fdd18884814a9ef0403a67c (patch) | |
| tree | 8ae2c2b8d6701fee31088d86a39588534ecdfca4 /staticd/static_nb_config.c | |
| parent | 5dfa36b6a7bf52041e61ea3bdcf8fd7c92fc61af (diff) | |
staticd: fix NB dependency hack
Currently, staticd configuration is tightly coupled with VRF existence.
Because of that, it has to use a hack in NB infrastructure to create a
VRF configuration when at least one static route is configured for this
VRF. This hack is incompatible with mgmtd, because mgmtd doesn't execute
configuration callbacks. Because of that, the configuration may become
out of sync between mgmtd and staticd. There are two main cases:
1. Create static route in a VRF. The VRF data node will be created
   automatically in staticd by the NB hack, but not in mgmtd.
2. Delete VRF which has some static routes configured. The static route
   configuration will be deleted from staticd by the NB hack, but not
   from mgmtd.
To fix the problem, decouple configuration of static routes from VRF
configuration. Now it is possible to configure static routes even if the
VRF doesn't exist yet. Once the VRF is created, staticd applies all the
preconfigured routes.
This change also fixes the problem with static routes being preserved in
the system when staticd "control-plane-protocol" container is deleted
but the VRF is still configured.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'staticd/static_nb_config.c')
| -rw-r--r-- | staticd/static_nb_config.c | 52 | 
1 files changed, 46 insertions, 6 deletions
diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c index d7605cb347..7de5f0474a 100644 --- a/staticd/static_nb_config.c +++ b/staticd/static_nb_config.c @@ -540,6 +540,48 @@ int routing_control_plane_protocols_name_validate(  	}  	return NB_OK;  } + +/* + * XPath: + * /frr-routing:routing/control-plane-protocols/control-plane-protocol + */ +int routing_control_plane_protocols_staticd_create(struct nb_cb_create_args *args) +{ +	struct static_vrf *svrf; +	const char *vrf; + +	vrf = yang_dnode_get_string(args->dnode, "vrf"); +	svrf = static_vrf_alloc(vrf); +	nb_running_set_entry(args->dnode, svrf); + +	return NB_OK; +} + +int routing_control_plane_protocols_staticd_destroy( +	struct nb_cb_destroy_args *args) +{ +	struct static_vrf *svrf; +	struct route_table *stable; +	struct route_node *rn; +	afi_t afi; +	safi_t safi; + +	svrf = nb_running_unset_entry(args->dnode); + +	FOREACH_AFI_SAFI (afi, safi) { +		stable = svrf->stable[afi][safi]; +		if (!stable) +			continue; + +		for (rn = route_top(stable); rn; rn = route_next(rn)) +			static_del_route(rn); +	} + +	static_vrf_free(svrf); + +	return NB_OK; +} +  /*   * XPath:   * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list @@ -547,8 +589,7 @@ int routing_control_plane_protocols_name_validate(  int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_create(  	struct nb_cb_create_args *args)  { -	struct vrf *vrf; -	struct static_vrf *s_vrf; +	struct static_vrf *svrf;  	struct route_node *rn;  	const struct lyd_node *vrf_dnode;  	struct prefix prefix; @@ -577,15 +618,14 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_cr  	case NB_EV_APPLY:  		vrf_dnode = yang_dnode_get_parent(args->dnode,  						  "control-plane-protocol"); -		vrf = nb_running_get_entry(vrf_dnode, NULL, true); -		s_vrf = vrf->info; +		svrf = nb_running_get_entry(vrf_dnode, NULL, true);  		yang_dnode_get_prefix(&prefix, args->dnode, "prefix");  		afi_safi = yang_dnode_get_string(args->dnode, "afi-safi");  		yang_afi_safi_identity2value(afi_safi, &afi, &safi); -		rn = static_add_route(afi, safi, &prefix, NULL, s_vrf); -		if (vrf->vrf_id == VRF_UNKNOWN) +		rn = static_add_route(afi, safi, &prefix, NULL, svrf); +		if (!svrf->vrf || svrf->vrf->vrf_id == VRF_UNKNOWN)  			snprintf(  				args->errmsg, args->errmsg_len,  				"Static Route to %s not installed currently because dependent config not fully available",  | 
