bgpd: Show applied route-map attributes for neighbor X advertised-routes detail

If we have a route-map that sets some attributes e.g. community or large-community,
and the route-map is applied for outgoing direction, everything is fine, but
we missed the point that `advertised-routes detail` was not using the applied
attributes to display and instead it uses what is received from the peer (original).

Let's fix this, and use what's already applied (advertise attributes), and
we can now see:

```
route-map r3 permit 10
 match ip address prefix-list p1
 set community 65001:65002
 set extcommunity bandwidth 100
 set large-community 65001:65002:65003
exit
!
...
 address-family ipv4 unicast
  neighbor 192.168.2.3 route-map r3 out
 exit-address-family
...
```

The output:

```
r2# show bgp ipv4 neighbors 192.168.2.3 advertised-routes detail
BGP table version is 1, local router ID is 192.168.2.2, vrf id 0
Default local pref 100, local AS 65002
BGP routing table entry for 10.10.10.1/32, version 1
Paths: (1 available, best #1, table default)
  Advertised to non peer-group peers:
  192.168.1.1 192.168.2.3
  65001
    0.0.0.0 from 192.168.1.1 (192.168.1.1)
      Origin IGP, valid, external, best (First path received)
      Community: 65001:65002
      Extended Community: LB:65002:12500000 (100.000 Mbps)
      Large Community: 65001:65002:65003
      Last update: Thu Dec 19 17:00:40 2024
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2024-12-19 16:59:47 +02:00
parent b23c6e522d
commit 708f08cb18
3 changed files with 66 additions and 80 deletions

View File

@ -764,10 +764,9 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi,
json_path = json_object_new_array(); json_path = json_object_new_array();
if (detail) if (detail)
route_vty_out_detail( route_vty_out_detail(vty, bgp, bd, bgp_dest_get_prefix(bd), pi,
vty, bgp, bd, bgp_dest_get_prefix(bd), AFI_L2VPN, SAFI_EVPN, RPKI_NOT_BEING_USED,
pi, AFI_L2VPN, SAFI_EVPN, json_path, NULL);
RPKI_NOT_BEING_USED, json_path);
else else
route_vty_out(vty, &bd->rn->p, pi, 0, SAFI_EVPN, route_vty_out(vty, &bd->rn->p, pi, 0, SAFI_EVPN,
json_path, false); json_path, false);
@ -892,10 +891,9 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn,
json_path = json_object_new_array(); json_path = json_object_new_array();
if (detail) if (detail)
route_vty_out_detail(vty, bgp, dest, &tmp_p, pi, route_vty_out_detail(vty, bgp, dest, &tmp_p, pi, AFI_L2VPN,
AFI_L2VPN, SAFI_EVPN, SAFI_EVPN, RPKI_NOT_BEING_USED, json_path,
RPKI_NOT_BEING_USED, NULL);
json_path);
else else
route_vty_out(vty, &tmp_p, pi, 0, SAFI_EVPN, route_vty_out(vty, &tmp_p, pi, 0, SAFI_EVPN,
@ -2570,9 +2568,8 @@ static void evpn_show_route_vni_multicast(struct vty *vty, struct bgp *bgp,
if (json) if (json)
json_path = json_object_new_array(); json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi, afi, safi,
pi, afi, safi, RPKI_NOT_BEING_USED, RPKI_NOT_BEING_USED, json_path, NULL);
json_path);
if (json) if (json)
json_object_array_add(json_paths, json_path); json_object_array_add(json_paths, json_path);
@ -2699,9 +2696,8 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp,
NULL /* ip */); NULL /* ip */);
} }
route_vty_out_detail(vty, bgp, dest, (struct prefix *)&tmp_p, route_vty_out_detail(vty, bgp, dest, (struct prefix *)&tmp_p, pi, afi, safi,
pi, afi, safi, RPKI_NOT_BEING_USED, RPKI_NOT_BEING_USED, json_path, NULL);
json_path);
if (json) if (json)
json_object_array_add(json_paths, json_path); json_object_array_add(json_paths, json_path);
@ -2810,9 +2806,8 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp,
if (json) if (json)
json_path = json_object_new_array(); json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi, afi, safi,
pi, afi, safi, RPKI_NOT_BEING_USED, RPKI_NOT_BEING_USED, json_path, NULL);
json_path);
if (json) if (json)
json_object_array_add(json_paths, json_path); json_object_array_add(json_paths, json_path);
@ -2923,9 +2918,8 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp,
if (json) if (json)
json_path = json_object_new_array(); json_path = json_object_new_array();
route_vty_out_detail( route_vty_out_detail(vty, bgp, dest, bgp_dest_get_prefix(dest), pi, afi,
vty, bgp, dest, bgp_dest_get_prefix(dest), pi, safi, RPKI_NOT_BEING_USED, json_path, NULL);
afi, safi, RPKI_NOT_BEING_USED, json_path);
if (json) if (json)
json_object_array_add(json_paths, json_path); json_object_array_add(json_paths, json_path);
@ -3060,9 +3054,8 @@ static void evpn_show_route_rd_all_macip(struct vty *vty, struct bgp *bgp,
if (json) if (json)
json_path = json_object_new_array(); json_path = json_object_new_array();
route_vty_out_detail(vty, bgp, dest, p, pi, AFI_L2VPN, route_vty_out_detail(vty, bgp, dest, p, pi, AFI_L2VPN, SAFI_EVPN,
SAFI_EVPN, RPKI_NOT_BEING_USED, RPKI_NOT_BEING_USED, json_path, NULL);
json_path);
if (json) if (json)
json_object_array_add(json_paths, json_path); json_object_array_add(json_paths, json_path);
@ -3223,11 +3216,10 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
json_path = json_object_new_array(); json_path = json_object_new_array();
if (detail) { if (detail) {
route_vty_out_detail( route_vty_out_detail(vty, bgp, dest,
vty, bgp, dest, bgp_dest_get_prefix(dest), pi,
bgp_dest_get_prefix(dest), pi, AFI_L2VPN, SAFI_EVPN,
AFI_L2VPN, SAFI_EVPN, RPKI_NOT_BEING_USED, json_path, NULL);
RPKI_NOT_BEING_USED, json_path);
} else } else
route_vty_out(vty, p, pi, 0, SAFI_EVPN, route_vty_out(vty, p, pi, 0, SAFI_EVPN,
json_path, false); json_path, false);

View File

@ -10552,14 +10552,13 @@ static void route_vty_out_detail_es_info(struct vty *vty,
} }
void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
const struct prefix *p, struct bgp_path_info *path, const struct prefix *p, struct bgp_path_info *path, afi_t afi,
afi_t afi, safi_t safi, safi_t safi, enum rpki_states rpki_curr_state, json_object *json_paths,
enum rpki_states rpki_curr_state, struct attr *pattr)
json_object *json_paths)
{ {
char buf[INET6_ADDRSTRLEN]; char buf[INET6_ADDRSTRLEN];
char vni_buf[30] = {}; char vni_buf[30] = {};
struct attr *attr = path->attr; struct attr *attr = pattr ? pattr : path->attr;
time_t tbuf; time_t tbuf;
char timebuf[32]; char timebuf[32];
json_object *json_bestpath = NULL; json_object *json_bestpath = NULL;
@ -11284,6 +11283,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
json_path, "community", json_path, "community",
bgp_attr_get_community(attr)->json); bgp_attr_get_community(attr)->json);
} else { } else {
if (!bgp_attr_get_community(attr)->str)
community_str(bgp_attr_get_community(attr), true, true);
vty_out(vty, " Community: %s\n", vty_out(vty, " Community: %s\n",
bgp_attr_get_community(attr)->str); bgp_attr_get_community(attr)->str);
} }
@ -11291,6 +11292,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
/* Line 5 display Extended-community */ /* Line 5 display Extended-community */
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) { if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
if (!bgp_attr_get_ecommunity(attr)->str)
ecommunity_str(bgp_attr_get_ecommunity(attr));
if (json_paths) { if (json_paths) {
json_ext_community = json_object_new_object(); json_ext_community = json_object_new_object();
json_object_string_add( json_object_string_add(
@ -11305,6 +11309,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
} }
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES))) { if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES))) {
if (!bgp_attr_get_ipv6_ecommunity(attr)->str)
ecommunity_str(bgp_attr_get_ipv6_ecommunity(attr));
if (json_paths) { if (json_paths) {
json_ext_ipv6_community = json_object_new_object(); json_ext_ipv6_community = json_object_new_object();
json_object_string_add(json_ext_ipv6_community, "string", json_object_string_add(json_ext_ipv6_community, "string",
@ -11330,6 +11337,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
json_path, "largeCommunity", json_path, "largeCommunity",
bgp_attr_get_lcommunity(attr)->json); bgp_attr_get_lcommunity(attr)->json);
} else { } else {
if (!bgp_attr_get_lcommunity(attr)->str)
lcommunity_str(bgp_attr_get_lcommunity(attr), true, true);
vty_out(vty, " Large Community: %s\n", vty_out(vty, " Large Community: %s\n",
bgp_attr_get_lcommunity(attr)->str); bgp_attr_get_lcommunity(attr)->str);
} }
@ -11997,11 +12006,9 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t sa
prd, table->afi, safi, prd, table->afi, safi,
NULL, false, false); NULL, false, false);
route_vty_out_detail( route_vty_out_detail(vty, bgp, dest, dest_p, pi,
vty, bgp, dest, dest_p, pi, family2afi(dest_p->family), safi,
family2afi(dest_p->family), RPKI_NOT_BEING_USED, json_paths, NULL);
safi, RPKI_NOT_BEING_USED,
json_paths);
} else { } else {
route_vty_out(vty, dest_p, pi, display, route_vty_out(vty, dest_p, pi, display,
safi, json_paths, wide); safi, json_paths, wide);
@ -12511,11 +12518,10 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
} }
} }
static void bgp_show_path_info(const struct prefix_rd *pfx_rd, static void bgp_show_path_info(const struct prefix_rd *pfx_rd, struct bgp_dest *bgp_node,
struct bgp_dest *bgp_node, struct vty *vty, struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
struct bgp *bgp, afi_t afi, safi_t safi, json_object *json, enum bgp_path_type pathtype, int *display,
json_object *json, enum bgp_path_type pathtype, enum rpki_states rpki_target_state, struct attr *attr)
int *display, enum rpki_states rpki_target_state)
{ {
struct bgp_path_info *pi; struct bgp_path_info *pi;
int header = 1; int header = 1;
@ -12558,10 +12564,8 @@ static void bgp_show_path_info(const struct prefix_rd *pfx_rd,
|| (pathtype == BGP_PATH_SHOW_MULTIPATH || (pathtype == BGP_PATH_SHOW_MULTIPATH
&& (CHECK_FLAG(pi->flags, BGP_PATH_MULTIPATH) && (CHECK_FLAG(pi->flags, BGP_PATH_MULTIPATH)
|| CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)))) || CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))))
route_vty_out_detail(vty, bgp, bgp_node, route_vty_out_detail(vty, bgp, bgp_node, bgp_dest_get_prefix(bgp_node), pi,
bgp_dest_get_prefix(bgp_node), pi, afi, safi, rpki_curr_state, json_paths, attr);
afi, safi, rpki_curr_state,
json_paths);
} }
if (json && json_paths) { if (json && json_paths) {
@ -12648,9 +12652,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
continue; continue;
} }
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp, afi, safi,
bgp, afi, safi, json, pathtype, json, pathtype, &display, rpki_target_state, NULL);
&display, rpki_target_state);
bgp_dest_unlock_node(rm); bgp_dest_unlock_node(rm);
} }
@ -12709,9 +12712,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
rm = longest_pfx; rm = longest_pfx;
bgp_dest_lock_node(rm); bgp_dest_lock_node(rm);
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty, bgp, afi, safi,
bgp, afi, safi, json, pathtype, json, pathtype, &display, rpki_target_state, NULL);
&display, rpki_target_state);
bgp_dest_unlock_node(rm); bgp_dest_unlock_node(rm);
} }
@ -12737,9 +12739,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
const struct prefix *dest_p = bgp_dest_get_prefix(dest); const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (!prefix_check if (!prefix_check
|| dest_p->prefixlen == match.prefixlen) { || dest_p->prefixlen == match.prefixlen) {
bgp_show_path_info(NULL, dest, vty, bgp, afi, bgp_show_path_info(NULL, dest, vty, bgp, afi, safi, json, pathtype,
safi, json, pathtype, &display, rpki_target_state, NULL);
&display, rpki_target_state);
} }
bgp_dest_unlock_node(dest); bgp_dest_unlock_node(dest);
@ -14633,10 +14634,8 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
if (use_json) if (use_json)
json_net = json_object_new_object(); json_net = json_object_new_object();
bgp_show_path_info(NULL /* prefix_rd */, dest, vty, bgp, bgp_show_path_info(NULL /* prefix_rd */, dest, vty, bgp, afi, safi, json_net,
afi, safi, json_net, BGP_PATH_SHOW_ALL, &display, RPKI_NOT_BEING_USED, NULL);
BGP_PATH_SHOW_ALL, &display,
RPKI_NOT_BEING_USED);
if (use_json) if (use_json)
json_object_object_addf(json_ar, json_net, json_object_object_addf(json_ar, json_net,
"%pFX", rn_p); "%pFX", rn_p);
@ -14770,11 +14769,9 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
pass_in = &buildit; pass_in = &buildit;
} else } else
pass_in = dest; pass_in = dest;
bgp_show_path_info( bgp_show_path_info(NULL, pass_in, vty, bgp, afi, safi,
NULL, pass_in, vty, bgp, afi, json_net, BGP_PATH_SHOW_ALL, &display,
safi, json_net, RPKI_NOT_BEING_USED, NULL);
BGP_PATH_SHOW_ALL, &display,
RPKI_NOT_BEING_USED);
if (use_json) if (use_json)
json_object_object_addf( json_object_object_addf(
json_ar, json_net, json_ar, json_net,
@ -14800,9 +14797,8 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
bgp_dest_get_prefix(dest); bgp_dest_get_prefix(dest);
attr = *adj->attr; attr = *adj->attr;
ret = bgp_output_modifier( ret = bgp_output_modifier(peer, rn_p, &attr, afi, safi,
peer, rn_p, &attr, afi, safi, rmap_name);
rmap_name);
if (ret == RMAP_DENY) { if (ret == RMAP_DENY) {
(*filtered_count)++; (*filtered_count)++;
@ -14826,7 +14822,8 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
json_net = json_object_new_object(); json_net = json_object_new_object();
bgp_show_path_info(NULL, dest, vty, bgp, afi, safi, bgp_show_path_info(NULL, dest, vty, bgp, afi, safi,
json_net, BGP_PATH_SHOW_ALL, json_net, BGP_PATH_SHOW_ALL,
&display, RPKI_NOT_BEING_USED); &display, RPKI_NOT_BEING_USED,
adj->attr);
if (use_json) if (use_json)
json_object_object_addf(json_ar, json_net, json_object_object_addf(json_ar, json_net,
"%pFX", rn_p); "%pFX", rn_p);
@ -14839,7 +14836,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
*/ */
if (use_json) { if (use_json) {
route_vty_out_tmp(vty, bgp, dest, rn_p, route_vty_out_tmp(vty, bgp, dest, rn_p,
&attr, safi, use_json, adj->attr, safi, use_json,
json_ar, wide); json_ar, wide);
} else { } else {
for (bpi = bgp_dest_get_bgp_path_info(dest); for (bpi = bgp_dest_get_bgp_path_info(dest);
@ -14872,11 +14869,9 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
if (use_json) if (use_json)
json_net = json_net =
json_object_new_object(); json_object_new_object();
bgp_show_path_info( bgp_show_path_info(NULL /* prefix_rd */, dest, vty, bgp, afi,
NULL /* prefix_rd */, dest, vty, safi, json_net, BGP_PATH_SHOW_BESTPATH,
bgp, afi, safi, json_net, &display, RPKI_NOT_BEING_USED, NULL);
BGP_PATH_SHOW_BESTPATH,
&display, RPKI_NOT_BEING_USED);
if (use_json) if (use_json)
json_object_object_addf( json_object_object_addf(
json_ar, json_net, json_ar, json_net,

View File

@ -932,11 +932,10 @@ extern void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
safi_t safi, json_object *json, safi_t safi, json_object *json,
bool incremental_print, bool incremental_print,
bool local_table); bool local_table);
extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
struct bgp_dest *bn, const struct prefix *p, const struct prefix *p, struct bgp_path_info *path, afi_t afi,
struct bgp_path_info *path, afi_t afi, safi_t safi, enum rpki_states, json_object *json_paths,
safi_t safi, enum rpki_states, struct attr *attr);
json_object *json_paths);
extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
struct bgp_table *table, struct prefix_rd *prd, struct bgp_table *table, struct prefix_rd *prd,
enum bgp_show_type type, void *output_arg, enum bgp_show_type type, void *output_arg,