Skip to content

Commit

Permalink
bgpd: Show applied route-map attributes for `neighbor X advertised-ro…
Browse files Browse the repository at this point in the history
…utes 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 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 unicast neighbor 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, no best path)
  Advertised to non peer-group peers:
  192.168.1.1 192.168.2.3
  65001
    0.0.0.0 (inaccessible, import-check enabled) from 192.168.2.3 (192.168.2.3)
      Origin IGP, invalid, external
      Community: 65001:65002 <<<<<<<<<<<<<<<<<
      Extended Community: LB:65002:12500000 (100.000 Mbps) <<<<<<<<<<<<<<<<<
      Large Community: 65001:65002:65003 <<<<<<<<<<<<<<<<<
      Last update: Wed Dec 18 04:54:23 2024
```

Without this fix we didn't see Community, Large Community, etc.

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Dec 19, 2024
1 parent b23c6e5 commit fa98a5b
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1912,42 +1912,48 @@ static int bgp_input_modifier(struct peer *peer, const struct prefix *p,
return RMAP_PERMIT;
}

static int bgp_output_modifier(struct peer *peer, const struct prefix *p,
struct attr *attr, afi_t afi, safi_t safi,
const char *rmap_name)
static int bgp_output_modifier(struct bgp_dest *dest, struct peer *peer, const struct prefix *p,
struct attr *attr, afi_t afi, safi_t safi, const char *rmap_name)
{
struct bgp_path_info rmap_path;
route_map_result_t ret;
struct route_map *rmap = NULL;
uint8_t rmap_type;
struct bgp_filter *filter;
struct bgp_path_info *bpi = bgp_dest_get_bgp_path_info(dest);

/*
* So if we get to this point and have no rmap_name
* we want to just show the output as it currently
* exists.
*/
if (!rmap_name)
return RMAP_PERMIT;
filter = &peer->filter[afi][safi];

/* Apply default weight value. */
if (peer->weight[afi][safi])
attr->weight = peer->weight[afi][safi];

rmap = route_map_lookup_by_name(rmap_name);

/*
* If we have a route map name and we do not find
* the routemap that means we have an implicit
* deny.
*/
if (rmap == NULL)
return RMAP_DENY;
if (rmap_name) {
rmap = route_map_lookup_by_name(rmap_name);
if (!rmap)
return RMAP_DENY;
} else {
if (ROUTE_MAP_OUT_NAME(filter)) {
rmap = ROUTE_MAP_OUT(filter);
if (!rmap)
return RMAP_DENY;
} else {
/*
* So if we get to this point and have no route-map
* we want to just show the output as it currently
* exists.
*/
return RMAP_PERMIT;
}
}

memset(&rmap_path, 0, sizeof(rmap_path));
/* Route map apply. */
/* Duplicate current value to new structure for modification. */
rmap_path.peer = peer;
rmap_path.attr = attr;
rmap_path.from = bpi->peer;
rmap_path.flags = bpi->flags;

rmap_type = peer->rmap_type;
SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT);
Expand Down Expand Up @@ -14623,8 +14629,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
}
}

ret = bgp_output_modifier(peer, rn_p, &attr, afi, safi,
rmap_name);
ret = bgp_output_modifier(dest, peer, rn_p, &attr, afi, safi, rmap_name);

if (ret != RMAP_DENY) {
show_adj_route_header(vty, peer, table, header1,
Expand Down Expand Up @@ -14798,18 +14803,25 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,

const struct prefix *rn_p =
bgp_dest_get_prefix(dest);
struct bgp_path_info mbpi;
struct bgp_dest modified_dest = *dest;
struct bgp_dest *mdest;

attr = *adj->attr;
ret = bgp_output_modifier(
peer, rn_p, &attr, afi, safi,
rmap_name);
ret = bgp_output_modifier(dest, peer, rn_p, &attr, afi,
safi, rmap_name);

if (ret == RMAP_DENY) {
(*filtered_count)++;
bgp_attr_flush(&attr);
continue;
}

mbpi.attr = &attr;
mbpi.peer = peer;
modified_dest.info = &mbpi;
mdest = &modified_dest;

if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) ||
(safi == SAFI_EVPN)) {
if (use_json)
Expand All @@ -14824,7 +14836,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
if (detail) {
if (use_json)
json_net = json_object_new_object();
bgp_show_path_info(NULL, dest, vty, bgp, afi, safi,
bgp_show_path_info(NULL, mdest, vty, bgp, afi, safi,
json_net, BGP_PATH_SHOW_ALL,
&display, RPKI_NOT_BEING_USED);
if (use_json)
Expand Down

0 comments on commit fa98a5b

Please sign in to comment.