Skip to content

Commit

Permalink
bgpd: conditional advertisement - other match rules support
Browse files Browse the repository at this point in the history
Sample Configuration with prefix-list and community match rules
---------------------------------------------------------------

R1 ------- R2(DUT) ------- R3

Router2# show running-config
Building configuration...

Current configuration:
!
frr version 7.6-dev-MyOwnFRRVersion
frr defaults traditional
hostname router
log file /var/log/frr/bgpd.log
log syslog informational
hostname Router2
service integrated-vtysh-config
!
debug bgp updates in
debug bgp updates out
!
debug route-map
!
ip route 20.20.0.0/16 blackhole
ipv6 route 2001:db8::200/128 blackhole
!
interface enp0s9
 ip address 10.10.10.2/24
!
interface enp0s10
 ip address 10.10.20.2/24
!
interface lo
 ip address 2.2.2.2/32
!
router bgp 2
 bgp log-neighbor-changes
 no bgp ebgp-requires-policy
 neighbor 10.10.10.1 remote-as 1
 neighbor 10.10.20.3 remote-as 3
 !
 address-family ipv4 unicast
  neighbor 10.10.10.1 soft-reconfiguration inbound
  neighbor 10.10.20.3 soft-reconfiguration inbound
  neighbor 10.10.20.3 advertise-map ADV-MAP non-exist-map EXIST-MAP
 exit-address-family
!
ip prefix-list DEFAULT seq 5 permit 1.1.1.5/32
ip prefix-list DEFAULT seq 10 permit 1.1.1.1/32
ip prefix-list EXIST seq 5 permit 10.10.10.10/32
ip prefix-list DEFAULT-ROUTE seq 5 permit 0.0.0.0/0
ip prefix-list IP1 seq 5 permit 10.139.224.0/20
ip prefix-list T2 seq 5 permit 1.1.1.5/32
!
bgp community-list standard DC-ROUTES seq 5 permit 64952:3008
bgp community-list standard DC-ROUTES seq 10 permit 64671:501
bgp community-list standard DC-ROUTES seq 15 permit 64950:3009
bgp community-list standard DEFAULT-ROUTE seq 5 permit 65013:200
!
route-map ADV-MAP permit 10
 match ip address prefix-list IP1
!
route-map ADV-MAP permit 20
 match community DC-ROUTES
!
route-map EXIST-MAP permit 10
 match community DEFAULT-ROUTE
 match ip address prefix-list DEFAULT-ROUTE
!
line vty
!
end
Router2#

Router2# show ip bgp 0.0.0.0
BGP routing table entry for 0.0.0.0/0
Paths: (1 available, best #1, table default)
  Advertised to non peer-group peers:
  10.10.10.1 10.10.20.3
  1
    10.10.10.1 from 10.10.10.1 (10.139.224.1)
      Origin IGP, metric 0, valid, external, best (First path received)
      Community: 64848:3011 65011:200 65013:200
      Last update: Tue Oct  6 02:39:42 2020
Router2#

Sample output with non-exist-map when default route present in table
--------------------------------------------------------------------
Router2# show ip bgp
BGP table version is 4, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 0.0.0.0/0        10.10.10.1               0             0 1 i
*> 1.1.1.1/32       10.10.10.1               0             0 1 i
*> 1.1.1.5/32       10.10.10.1               0             0 1 i
*> 10.139.224.0/20  10.10.10.1               0             0 1 ?

Displayed  4 routes and 4 total paths

Router2# show ip bgp neighbors 10.10.20.3 advertised-routes
BGP table version is 4, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 0.0.0.0/0        0.0.0.0                                0 1 i
*> 1.1.1.5/32       0.0.0.0                                0 1 i   		<<<<<<<<<  non-exist-map : 0.0.0.0/0 is present so, 10.139.224.0/20 not advertised

Total number of prefixes 2

Sample output with non-exist-map when default route not present in table
------------------------------------------------------------------------
Router2# show ip bgp
BGP table version is 5, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       10.10.10.1               0             0 1 i
*> 1.1.1.5/32       10.10.10.1               0             0 1 i
*> 10.139.224.0/20  10.10.10.1               0             0 1 ?

Displayed  3 routes and 3 total paths
Router2#
Router2#
Router2# show ip bgp neighbors 10.10.20.3 advertised-routes
BGP table version is 5, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       0.0.0.0                                0 1 i
*> 1.1.1.5/32       0.0.0.0                                0 1 i
*> 10.139.224.0/20  0.0.0.0                                0 1 ?                <<<<<<<<<  non-exist-map : 0.0.0.0/0 is not present so, 10.139.224.0/20 advertised

Total number of prefixes 3
Router2#

Sample output with exist-map when default route present in table
--------------------------------------------------------------------
Router2# show ip bgp
BGP table version is 8, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 0.0.0.0/0        10.10.10.1               0             0 1 i
*> 1.1.1.1/32       10.10.10.1               0             0 1 i
*> 1.1.1.5/32       10.10.10.1               0             0 1 i
*> 10.139.224.0/20  10.10.10.1               0             0 1 ?

Displayed  4 routes and 4 total paths
Router2#
Router2#
Router2#
Router2#
Router2# show ip bgp neighbors 10.10.20.3 advertised-routes
BGP table version is 8, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 0.0.0.0/0        0.0.0.0                                0 1 i
*> 1.1.1.1/32       0.0.0.0                                0 1 i
*> 1.1.1.5/32       0.0.0.0                                0 1 i
*> 10.139.224.0/20  0.0.0.0                                0 1 ?		<<<<<<<<<  exist-map : 0.0.0.0/0 is present so, 10.139.224.0/20 advertised

Total number of prefixes 4
Router2#

Sample output with exist-map when default route not present in table
--------------------------------------------------------------------
Router2# show ip bgp
BGP table version is 9, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.1/32       10.10.10.1               0             0 1 i
*> 1.1.1.5/32       10.10.10.1               0             0 1 i
*> 10.139.224.0/20  10.10.10.1               0             0 1 ?

Displayed  3 routes and 3 total paths
Router2#
Router2#
Router2#
Router2# show ip bgp neighbors 10.10.20.3 advertised-routes
BGP table version is 9, local router ID is 2.2.2.2, vrf id 0
Default local pref 100, local AS 2
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.5/32       0.0.0.0                                0 1 i		<<<<<<<<<  exist-map : 0.0.0.0/0 is not present so, 10.139.224.0/20 not advertised

Total number of prefixes 1
Router2#

Signed-off-by: Madhuri Kuruganti <k.madhuri@samsung.com>
  • Loading branch information
Madhuri Kuruganti authored and qlyoung committed Apr 1, 2021
1 parent 43b2b93 commit dd43e59
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 406 deletions.
409 changes: 120 additions & 289 deletions bgpd/bgp_conditional_adv.c

Large diffs are not rendered by default.

95 changes: 0 additions & 95 deletions bgpd/bgp_conditional_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,105 +36,10 @@ extern "C" {
/* Polling time for monitoring condition-map routes in route table */
#define CONDITIONAL_ROUTES_POLL_TIME 60

#define FOREACH_ACCESS_LIST_FILTER(alist, filter) \
for (filter = alist->head; filter; filter = filter->next)

static inline bool is_rmap_valid(struct route_map *rmap)
{
if (!rmap || !rmap->head)
return false;

/* Doesn't make sense to configure advertise
* or condition map in deny/any clause.
*/
if (rmap->head->type != RMAP_PERMIT)
return false;

/* If a match command is not present, all routes match the clause */
if (!rmap->head->match_list.head)
return false;

return true;
}

static inline afi_t get_afi_from_match_rule(const char *str)
{
if (!strcmp(str, "ip address"))
return AFI_IP;
else if (!strcmp(str, "ipv6 address"))
return AFI_IP6;
else
return AFI_MAX;
}

static inline bool advertise_dest_routes(struct update_subgroup *subgrp,
struct bgp_dest *dest,
struct peer *peer, afi_t afi,
safi_t safi, int addpath_capable,
bool advertise)
{
struct attr attr;
struct bgp_path_info *pi = NULL;
const struct prefix *dest_p = NULL;
bool route_advertised = false;

dest_p = (struct prefix *)bgp_dest_get_prefix(dest);
if (!dest_p)
return route_advertised;

for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)
|| (addpath_capable
&& bgp_addpath_tx_path(peer->addpath_type[afi][safi],
pi))) {

/* Skip route-map checks in subgroup_announce_check
* while executing from the conditional advertise
* scanner process. otherwise when route-map is also
* configured on same peer, routes in advertise-map
* may not be advertised as expected.
*/
if (advertise
&& subgroup_announce_check(dest, pi, subgrp, dest_p,
&attr, true)) {
bgp_adj_out_set_subgroup(dest, subgrp, &attr,
pi);
route_advertised = true;
} else {
/* If default originate is enabled for the
* peer, do not send explicit withdraw.
* This will prevent deletion of default route
* advertised through default originate.
*/
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_DEFAULT_ORIGINATE)
&& is_default_prefix(dest_p))
break;

bgp_adj_out_unset_subgroup(
dest, subgrp, 1,
bgp_addpath_id_for_peer(
peer, afi, safi,
&pi->tx_addpath));
route_advertised = true;
}
}
}
return route_advertised;
}

struct bgp_dest *bgp_dest_matches_filter_prefix(struct bgp_table *table,
struct filter *filter);
extern enum route_map_cmd_result_t
bgp_check_rmap_prefixes_in_bgp_table(struct bgp_table *table,
struct route_map *rmap);
extern void bgp_conditional_adv_enable(struct peer *peer, afi_t afi,
safi_t safi);
extern void bgp_conditional_adv_disable(struct peer *peer, afi_t afi,
safi_t safi);
extern bool bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
safi_t safi, struct bgp_table *table,
struct route_map *rmap, bool advertise);
#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,9 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
BGP_TIMER_OFF(peer->t_holdtime);
bgp_timer_set(peer);

/* Notify BGP Conditional advertisement scanner process */
peer->advmap_table_change = true;

return Receive_UPDATE_message;
}

Expand Down
23 changes: 22 additions & 1 deletion bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,27 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
peer->host, prefix2str(p, buf, sizeof(buf)));

bgp_attr_flush(attr);

/* TBD : Not sure if this is the correct way to fetch
* peer from group.
* Notify BGP Conditional advertisement scanner process.
*/
if (ADVERTISE_MAP_NAME(filter)
|| CONDITION_MAP_NAME(filter)) {
struct peer *temp_peer;
struct listnode *temp_node, *temp_nnode = NULL;
for (ALL_LIST_ELEMENTS(bgp->peer, temp_node,
temp_nnode, temp_peer)) {
if (!CHECK_FLAG(peer->flags,
PEER_FLAG_CONFIG_NODE))
continue;
if (strcmp(peer->host, temp_peer->host)
!= 0)
continue;
temp_peer->advmap_table_change = true;
break;
}
}
return false;
}
}
Expand Down Expand Up @@ -4347,7 +4368,7 @@ static int bgp_announce_route_timer_expired(struct thread *t)
peer_af_announce_route(paf, 1);

/* Notify BGP conditional advertisement scanner percess */
peer->advmap_info[paf->afi][paf->safi].config_change = true;
peer->advmap_config_change[paf->afi][paf->safi] = true;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3684,7 +3684,7 @@ static void bgp_route_map_process_peer(const char *rmap_name,
peer->default_rmap[afi][safi].map = map;

/* Notify BGP conditional advertisement scanner percess */
peer->advmap_info[afi][safi].config_change = true;
peer->advmap_config_change[afi][safi] = true;
}

static void bgp_route_map_update_peer_group(const char *rmap_name,
Expand Down
5 changes: 3 additions & 2 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -11259,8 +11259,9 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi,
filter->advmap.cname,
filter->advmap.amap ? "*" : "",
filter->advmap.aname,
filter->advmap.status ? "Advertise"
: "Withdraw");
filter->advmap.advertise == ADVERTISE
? "Advertise"
: "Withdraw");

/* Receive prefix count */
vty_out(vty, " %u accepted prefixes\n",
Expand Down
18 changes: 9 additions & 9 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6643,19 +6643,19 @@ int peer_advertise_map_set(struct peer *peer, afi_t afi, safi_t safi,
filter->advmap.cmap = condition_map;
filter->advmap.condition = condition;
route_map_counter_increment(advertise_map);
peer->advmap_info[afi][safi].config_change = true;
peer->advmap_config_change[afi][safi] = true;

/* Check if handling a regular peer. */
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
/* Set override-flag and process peer route updates. */
SET_FLAG(peer->filter_override[afi][safi][RMAP_OUT],
PEER_FT_ADVERTISE_MAP);

/* Hold peer_on_policy_change() until timer thread is called */

/* To increment condition_filter_count and/or create timer */
/* Hold peer_on_policy_change() until timer thread is called.
* Increment condition_filter_count and/or create timer.
*/
if (!filter_exists) {
filter->advmap.status = true;
filter->advmap.advertise = ADVERTISE;
bgp_conditional_adv_enable(peer, afi, safi);
}
/* Skip peer-group mechanics for regular peers. */
Expand Down Expand Up @@ -6691,11 +6691,11 @@ int peer_advertise_map_set(struct peer *peer, afi_t afi, safi_t safi,
filter->advmap.condition = condition;
route_map_counter_increment(advertise_map);

/* Hold peer_on_policy_change() until timer thread is called */

/* increment condition_filter_count, create timer if 1st one */
/* Hold peer_on_policy_change() until timer thread is called.
* Increment condition_filter_count, create timer if 1st one
*/
if (!filter_exists) {
filter->advmap.status = true;
filter->advmap.advertise = ADVERTISE;
bgp_conditional_adv_enable(member, afi, safi);
}
}
Expand Down
17 changes: 8 additions & 9 deletions bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ struct bgp {
enum bgp_link_bw_handling lb_handling;

/* BGP Conditional advertisement */
int condition_filter_count;
uint32_t condition_filter_count;
struct thread *t_condition_check;

QOBJ_FIELDS
Expand Down Expand Up @@ -798,8 +798,10 @@ struct bgp_nexthop {
#define BGP_GTSM_HOPS_CONNECTED 1

/* Advertise map */
#define CONDITION_NON_EXIST 0
#define CONDITION_EXIST 1
#define CONDITION_NON_EXIST false
#define CONDITION_EXIST true

enum advertise { WITHDRAW, ADVERTISE };

#include "filter.h"

Expand Down Expand Up @@ -845,7 +847,7 @@ struct bgp_filter {
char *cname;
struct route_map *cmap;

bool status;
enum advertise advertise;
} advmap;
};

Expand Down Expand Up @@ -1504,11 +1506,8 @@ struct peer {
bool as_path_loop_detection;

/* Conditional advertisement */
struct {
bool config_change;
enum route_map_cmd_result_t amap_prev_status;
enum route_map_cmd_result_t cmap_prev_status;
} advmap_info[AFI_MAX][SAFI_MAX];
bool advmap_config_change[AFI_MAX][SAFI_MAX];
bool advmap_table_change;

QOBJ_FIELDS
};
Expand Down

0 comments on commit dd43e59

Please sign in to comment.