diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2024-09-25 15:27:54 +0300 | 
|---|---|---|
| committer | Donatas Abraitis <donatas@opensourcerouting.org> | 2024-09-27 23:01:06 +0300 | 
| commit | 5d3da70ba379bdfa7310874bcd2ae55930465e14 (patch) | |
| tree | 097369081e2d46558e8849639897f6ac32f1a0e0 /bgpd/bgp_routemap_nb_config.c | |
| parent | 419e024b3f142f26fea0aacf7921af071eb4f334 (diff) | |
bgpd: Implement `match src-peer ...` command
To match source peer on the outgoing direction.
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to 'bgpd/bgp_routemap_nb_config.c')
| -rw-r--r-- | bgpd/bgp_routemap_nb_config.c | 156 | 
1 files changed, 156 insertions, 0 deletions
diff --git a/bgpd/bgp_routemap_nb_config.c b/bgpd/bgp_routemap_nb_config.c index 15c32eaa28..0dca196ed6 100644 --- a/bgpd/bgp_routemap_nb_config.c +++ b/bgpd/bgp_routemap_nb_config.c @@ -809,6 +809,162 @@ lib_route_map_entry_match_condition_rmap_match_condition_peer_local_destroy(  }  /* + * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:src-peer-ipv4-address + */ +int lib_route_map_entry_match_condition_rmap_match_condition_src_peer_ipv4_address_modify( +	struct nb_cb_modify_args *args) +{ +	struct routemap_hook_context *rhc; +	const char *peer; +	enum rmap_compile_rets ret; + +	switch (args->event) { +	case NB_EV_VALIDATE: +	case NB_EV_PREPARE: +	case NB_EV_ABORT: +		break; +	case NB_EV_APPLY: +		/* Add configuration. */ +		rhc = nb_running_get_entry(args->dnode, NULL, true); +		peer = yang_dnode_get_string(args->dnode, NULL); + +		/* Set destroy information. */ +		rhc->rhc_mhook = bgp_route_match_delete; +		rhc->rhc_rule = "src-peer"; +		rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; + +		ret = bgp_route_match_add(rhc->rhc_rmi, "src-peer", peer, RMAP_EVENT_MATCH_ADDED, +					  args->errmsg, args->errmsg_len); + +		if (ret != RMAP_COMPILE_SUCCESS) { +			rhc->rhc_mhook = NULL; +			return NB_ERR_INCONSISTENCY; +		} +	} + +	return NB_OK; +} + +int lib_route_map_entry_match_condition_rmap_match_condition_src_peer_ipv4_address_destroy( +	struct nb_cb_destroy_args *args) +{ +	switch (args->event) { +	case NB_EV_VALIDATE: +	case NB_EV_PREPARE: +	case NB_EV_ABORT: +		break; +	case NB_EV_APPLY: +		return lib_route_map_entry_match_destroy(args); +	} + +	return NB_OK; +} + +/* + * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:src-peer-interface + */ +int lib_route_map_entry_match_condition_rmap_match_condition_src_peer_interface_modify( +	struct nb_cb_modify_args *args) +{ +	struct routemap_hook_context *rhc; +	const char *peer; +	enum rmap_compile_rets ret; + +	switch (args->event) { +	case NB_EV_VALIDATE: +	case NB_EV_PREPARE: +	case NB_EV_ABORT: +		break; +	case NB_EV_APPLY: +		/* Add configuration. */ +		rhc = nb_running_get_entry(args->dnode, NULL, true); +		peer = yang_dnode_get_string(args->dnode, NULL); + +		/* Set destroy information. */ +		rhc->rhc_mhook = bgp_route_match_delete; +		rhc->rhc_rule = "src-peer"; +		rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; + +		ret = bgp_route_match_add(rhc->rhc_rmi, "src-peer", peer, RMAP_EVENT_MATCH_ADDED, +					  args->errmsg, args->errmsg_len); + +		if (ret != RMAP_COMPILE_SUCCESS) { +			rhc->rhc_mhook = NULL; +			return NB_ERR_INCONSISTENCY; +		} +	} + +	return NB_OK; +} + +int lib_route_map_entry_match_condition_rmap_match_condition_src_peer_interface_destroy( +	struct nb_cb_destroy_args *args) +{ +	switch (args->event) { +	case NB_EV_VALIDATE: +	case NB_EV_PREPARE: +	case NB_EV_ABORT: +		break; +	case NB_EV_APPLY: +		return lib_route_map_entry_match_destroy(args); +	} + +	return NB_OK; +} + +/* + * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:src-peer-ipv6-address + */ +int lib_route_map_entry_match_condition_rmap_match_condition_src_peer_ipv6_address_modify( +	struct nb_cb_modify_args *args) +{ +	struct routemap_hook_context *rhc; +	const char *peer; +	enum rmap_compile_rets ret; + +	switch (args->event) { +	case NB_EV_VALIDATE: +	case NB_EV_PREPARE: +	case NB_EV_ABORT: +		break; +	case NB_EV_APPLY: +		/* Add configuration. */ +		rhc = nb_running_get_entry(args->dnode, NULL, true); +		peer = yang_dnode_get_string(args->dnode, NULL); + +		/* Set destroy information. */ +		rhc->rhc_mhook = bgp_route_match_delete; +		rhc->rhc_rule = "src-peer"; +		rhc->rhc_event = RMAP_EVENT_MATCH_DELETED; + +		ret = bgp_route_match_add(rhc->rhc_rmi, "src-peer", peer, RMAP_EVENT_MATCH_ADDED, +					  args->errmsg, args->errmsg_len); + +		if (ret != RMAP_COMPILE_SUCCESS) { +			rhc->rhc_mhook = NULL; +			return NB_ERR_INCONSISTENCY; +		} +	} + +	return NB_OK; +} + +int lib_route_map_entry_match_condition_rmap_match_condition_src_peer_ipv6_address_destroy( +	struct nb_cb_destroy_args *args) +{ +	switch (args->event) { +	case NB_EV_VALIDATE: +	case NB_EV_PREPARE: +	case NB_EV_ABORT: +		break; +	case NB_EV_APPLY: +		return lib_route_map_entry_match_destroy(args); +	} + +	return NB_OK; +} + +/*   * XPath: /frr-route-map:lib/route-map/entry/match-condition/rmap-match-condition/frr-bgp-route-map:list-name   */  int  | 
