mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 20:22:36 +00:00
bgpd: conditional advertisement - comments addressed and few checks
Signed-off-by: Madhuri Kuruganti <k.madhuri@samsung.com>
This commit is contained in:
parent
cf2ad4d8a6
commit
52b8406259
@ -26,25 +26,31 @@ static route_map_result_t
|
|||||||
bgp_check_rmap_prefixes_in_bgp_table(struct bgp_table *table,
|
bgp_check_rmap_prefixes_in_bgp_table(struct bgp_table *table,
|
||||||
struct route_map *rmap)
|
struct route_map *rmap)
|
||||||
{
|
{
|
||||||
|
struct attr dummy_attr = {0};
|
||||||
struct bgp_dest *dest;
|
struct bgp_dest *dest;
|
||||||
struct attr dummy_attr;
|
|
||||||
struct bgp_path_info path;
|
|
||||||
const struct prefix *dest_p;
|
|
||||||
struct bgp_path_info *pi;
|
struct bgp_path_info *pi;
|
||||||
route_map_result_t ret = RMAP_PERMITMATCH;
|
struct bgp_path_info path = {0};
|
||||||
|
struct bgp_path_info_extra path_extra = {0};
|
||||||
|
const struct prefix *dest_p;
|
||||||
|
route_map_result_t ret = RMAP_DENYMATCH;
|
||||||
|
|
||||||
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
|
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
|
||||||
dest_p = bgp_dest_get_prefix(dest);
|
dest_p = bgp_dest_get_prefix(dest);
|
||||||
if (!dest_p)
|
assert(dest_p);
|
||||||
continue;
|
|
||||||
|
|
||||||
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
|
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
|
||||||
dummy_attr = *pi->attr;
|
dummy_attr = *pi->attr;
|
||||||
path.peer = pi->peer;
|
|
||||||
path.attr = &dummy_attr;
|
/* Fill temp path_info */
|
||||||
|
prep_for_rmap_apply(&path, &path_extra, dest, pi,
|
||||||
|
pi->peer, &dummy_attr);
|
||||||
|
|
||||||
|
RESET_FLAG(dummy_attr.rmap_change_flags);
|
||||||
|
|
||||||
ret = route_map_apply(rmap, dest_p, RMAP_BGP, &path);
|
ret = route_map_apply(rmap, dest_p, RMAP_BGP, &path);
|
||||||
if (ret == RMAP_PERMITMATCH)
|
if (ret != RMAP_PERMITMATCH)
|
||||||
|
bgp_attr_flush(&dummy_attr);
|
||||||
|
else
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,13 +63,14 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
|
|||||||
enum update_type advertise)
|
enum update_type advertise)
|
||||||
{
|
{
|
||||||
int addpath_capable;
|
int addpath_capable;
|
||||||
const struct prefix *dest_p;
|
struct bgp_dest *dest;
|
||||||
struct attr dummy_attr, attr;
|
|
||||||
struct bgp_path_info path;
|
|
||||||
struct bgp_path_info *pi;
|
struct bgp_path_info *pi;
|
||||||
struct peer_af *paf = NULL;
|
struct bgp_path_info path;
|
||||||
struct bgp_dest *dest = NULL;
|
struct peer_af *paf;
|
||||||
struct update_subgroup *subgrp = NULL;
|
const struct prefix *dest_p;
|
||||||
|
struct update_subgroup *subgrp;
|
||||||
|
struct attr dummy_attr = {0}, attr = {0};
|
||||||
|
struct bgp_path_info_extra path_extra = {0};
|
||||||
|
|
||||||
paf = peer_af_find(peer, afi, safi);
|
paf = peer_af_find(peer, afi, safi);
|
||||||
if (!paf)
|
if (!paf)
|
||||||
@ -78,17 +85,22 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
|
|||||||
|
|
||||||
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
|
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
|
||||||
dest_p = bgp_dest_get_prefix(dest);
|
dest_p = bgp_dest_get_prefix(dest);
|
||||||
if (!dest_p)
|
assert(dest_p);
|
||||||
continue;
|
|
||||||
|
|
||||||
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
|
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
|
||||||
dummy_attr = *pi->attr;
|
dummy_attr = *pi->attr;
|
||||||
path.peer = pi->peer;
|
|
||||||
path.attr = &dummy_attr;
|
/* Fill temp path_info */
|
||||||
|
prep_for_rmap_apply(&path, &path_extra, dest, pi,
|
||||||
|
pi->peer, &dummy_attr);
|
||||||
|
|
||||||
|
RESET_FLAG(dummy_attr.rmap_change_flags);
|
||||||
|
|
||||||
if (route_map_apply(rmap, dest_p, RMAP_BGP, &path)
|
if (route_map_apply(rmap, dest_p, RMAP_BGP, &path)
|
||||||
!= RMAP_PERMITMATCH)
|
!= RMAP_PERMITMATCH) {
|
||||||
|
bgp_attr_flush(&dummy_attr);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)
|
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)
|
||||||
|| (addpath_capable
|
|| (addpath_capable
|
||||||
@ -166,12 +178,15 @@ static int bgp_conditional_adv_timer(struct thread *t)
|
|||||||
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
|
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (peer->status != Established)
|
||||||
|
continue;
|
||||||
|
|
||||||
FOREACH_AFI_SAFI (afi, safi) {
|
FOREACH_AFI_SAFI (afi, safi) {
|
||||||
if (strmatch(get_afi_safi_str(afi, safi, true),
|
if (strmatch(get_afi_safi_str(afi, safi, true),
|
||||||
"Unknown"))
|
"Unknown"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!peer->afc[afi][safi])
|
if (!peer->afc_nego[afi][safi])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* labeled-unicast routes are installed in the unicast
|
/* labeled-unicast routes are installed in the unicast
|
||||||
|
@ -7076,47 +7076,34 @@ static int peer_advertise_map_set_vty(struct vty *vty, const char *ip_str,
|
|||||||
|
|
||||||
DEFPY (neighbor_advertise_map,
|
DEFPY (neighbor_advertise_map,
|
||||||
neighbor_advertise_map_cmd,
|
neighbor_advertise_map_cmd,
|
||||||
"[no$no] neighbor <A.B.C.D|X:X::X:X|WORD> advertise-map WORD <exist-map WORD|non-exist-map WORD>",
|
"[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
|
||||||
NO_STR
|
NO_STR
|
||||||
NEIGHBOR_STR
|
NEIGHBOR_STR
|
||||||
NEIGHBOR_ADDR_STR2
|
NEIGHBOR_ADDR_STR2
|
||||||
"Route-map to conditionally advertise routes\n"
|
"Route-map to conditionally advertise routes\n"
|
||||||
"Name of advertise map\n"
|
"Name of advertise map\n"
|
||||||
"Advertise routes only if prefixes in exist-map are installed in BGP table\n"
|
"Advertise routes only if prefixes in exist-map are installed in BGP table\n"
|
||||||
"Name of the exist map\n"
|
|
||||||
"Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
|
"Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
|
||||||
"Name of the non exist map\n")
|
"Name of the exist or non exist map\n")
|
||||||
{
|
{
|
||||||
int idx = 0;
|
|
||||||
int idx_peer = 1;
|
|
||||||
int idx_advertise_word = 3;
|
|
||||||
int idx_condition_word = 5;
|
|
||||||
bool condition = CONDITION_EXIST;
|
bool condition = CONDITION_EXIST;
|
||||||
|
|
||||||
if (no) {
|
if (!strcmp(exist, "non-exist-map"))
|
||||||
idx_peer++;
|
|
||||||
idx_advertise_word++;
|
|
||||||
idx_condition_word++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argv_find(argv, argc, "non-exist-map", &idx))
|
|
||||||
condition = CONDITION_NON_EXIST;
|
condition = CONDITION_NON_EXIST;
|
||||||
|
|
||||||
return peer_advertise_map_set_vty(
|
return peer_advertise_map_set_vty(vty, neighbor, bgp_node_afi(vty),
|
||||||
vty, argv[idx_peer]->arg, bgp_node_afi(vty), bgp_node_safi(vty),
|
bgp_node_safi(vty), advertise_str,
|
||||||
argv[idx_advertise_word]->arg, argv[idx_condition_word]->arg,
|
condition_str, condition, !no);
|
||||||
condition, !no);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
|
ALIAS_HIDDEN(neighbor_advertise_map, neighbor_advertise_map_hidden_cmd,
|
||||||
"[no$no] neighbor <A.B.C.D|X:X::X:X|WORD> advertise-map WORD <exist-map WORD|non-exist-map WORD>",
|
"[no$no] neighbor <A.B.C.D|X:X::X:X|WORD>$neighbor advertise-map WORD$advertise_str <exist-map|non-exist-map>$exist WORD$condition_str",
|
||||||
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
|
NO_STR NEIGHBOR_STR NEIGHBOR_ADDR_STR2
|
||||||
"Route-map to conditionally advertise routes\n"
|
"Route-map to conditionally advertise routes\n"
|
||||||
"Name of advertise map\n"
|
"Name of advertise map\n"
|
||||||
"Advertise routes only if prefixes in exist-map are installed in BGP table\n"
|
"Advertise routes only if prefixes in exist-map are installed in BGP table\n"
|
||||||
"Name of the exist map\n"
|
|
||||||
"Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
|
"Advertise routes only if prefixes in non-exist-map are not installed in BGP table\n"
|
||||||
"Name of the non exist map\n")
|
"Name of the exist or non exist map\n")
|
||||||
|
|
||||||
/* Set route-map to the peer. */
|
/* Set route-map to the peer. */
|
||||||
static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
|
static int peer_route_map_set_vty(struct vty *vty, const char *ip_str,
|
||||||
|
@ -6611,8 +6611,9 @@ static void peer_update_rmap_filter_data(struct peer *peer, afi_t afi,
|
|||||||
if (!CHECK_FLAG(config_flags, BGP_PEER_RMAP_SET)) {
|
if (!CHECK_FLAG(config_flags, BGP_PEER_RMAP_SET)) {
|
||||||
memset(filter, 0, sizeof(struct bgp_filter));
|
memset(filter, 0, sizeof(struct bgp_filter));
|
||||||
|
|
||||||
/* decrement condition_filter_count delete timer if last
|
/* decrement condition_filter_count delete timer if
|
||||||
* one */
|
* this is the last advertise-map to be removed.
|
||||||
|
*/
|
||||||
if (filter_exists)
|
if (filter_exists)
|
||||||
bgp_conditional_adv_disable(peer, afi, safi);
|
bgp_conditional_adv_disable(peer, afi, safi);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user