Merge pull request #1360 from donaldsharp/show_advertised_routes

Show advertised routes
This commit is contained in:
Renato Westphal 2017-11-27 20:14:15 -02:00 committed by GitHub
commit 633c7abd8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 123 additions and 88 deletions

View File

@ -822,6 +822,32 @@ void bgp_attr_unintern_sub(struct attr *attr)
#endif #endif
} }
/*
* We have some show commands that let you experimentally
* apply a route-map. When we apply the route-map
* we are reseting values but not saving them for
* posterity via intern'ing( because route-maps don't
* do that) but at this point in time we need
* to compare the new attr to the old and if the
* routemap has changed it we need to, as Snoop Dog says,
* Drop it like it's hot
*/
void bgp_attr_undup(struct attr *new, struct attr *old)
{
if (new->aspath != old->aspath)
aspath_free(new->aspath);
if (new->community != old->community)
community_free(new->community);
if (new->ecommunity != old->ecommunity)
ecommunity_free(&new->ecommunity);
if (new->lcommunity != old->lcommunity)
lcommunity_free(&new->lcommunity);
}
/* Free bgp attribute and aspath. */ /* Free bgp attribute and aspath. */
void bgp_attr_unintern(struct attr **pattr) void bgp_attr_unintern(struct attr **pattr)
{ {

View File

@ -239,6 +239,7 @@ extern bgp_attr_parse_ret_t bgp_attr_parse(struct peer *, struct attr *,
bgp_size_t, struct bgp_nlri *, bgp_size_t, struct bgp_nlri *,
struct bgp_nlri *); struct bgp_nlri *);
extern void bgp_attr_dup(struct attr *, struct attr *); extern void bgp_attr_dup(struct attr *, struct attr *);
extern void bgp_attr_undup(struct attr *new, struct attr *old);
extern struct attr *bgp_attr_intern(struct attr *attr); extern struct attr *bgp_attr_intern(struct attr *attr);
extern void bgp_attr_unintern_sub(struct attr *); extern void bgp_attr_unintern_sub(struct attr *);
extern void bgp_attr_unintern(struct attr **); extern void bgp_attr_unintern(struct attr **);

View File

@ -1157,49 +1157,52 @@ static int bgp_output_modifier(struct peer *peer, struct prefix *p,
struct attr *attr, afi_t afi, safi_t safi, struct attr *attr, afi_t afi, safi_t safi,
const char *rmap_name) const char *rmap_name)
{ {
struct bgp_filter *filter;
struct bgp_info info; struct bgp_info info;
route_map_result_t ret; route_map_result_t ret;
struct route_map *rmap = NULL; struct route_map *rmap = NULL;
u_char rmap_type;
filter = &peer->filter[afi][safi]; /*
* 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;
/* Apply default weight value. */ /* Apply default weight value. */
if (peer->weight[afi][safi]) if (peer->weight[afi][safi])
attr->weight = peer->weight[afi][safi]; attr->weight = peer->weight[afi][safi];
if (rmap_name) { rmap = route_map_lookup_by_name(rmap_name);
rmap = route_map_lookup_by_name(rmap_name);
if (rmap == NULL) /*
return RMAP_DENY; * If we have a route map name and we do not find
} else { * the routemap that means we have an implicit
if (ROUTE_MAP_OUT_NAME(filter)) { * deny.
rmap = ROUTE_MAP_OUT(filter); */
if (rmap == NULL)
if (rmap == NULL) return RMAP_DENY;
return RMAP_DENY;
}
}
/* Route map apply. */ /* Route map apply. */
if (rmap) { /* Duplicate current value to new strucutre for modification. */
/* Duplicate current value to new strucutre for modification. */ info.peer = peer;
info.peer = peer; info.attr = attr;
info.attr = attr;
SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT); rmap_type = peer->rmap_type;
SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT);
/* Apply BGP route map to the attribute. */ /* Apply BGP route map to the attribute. */
ret = route_map_apply(rmap, p, RMAP_BGP, &info); ret = route_map_apply(rmap, p, RMAP_BGP, &info);
peer->rmap_type = 0; peer->rmap_type = rmap_type;
if (ret == RMAP_DENYMATCH)
/*
* caller has multiple error paths with bgp_attr_flush()
*/
return RMAP_DENY;
if (ret == RMAP_DENYMATCH)
/* caller has multiple error paths with bgp_attr_flush()
*/
return RMAP_DENY;
}
return RMAP_PERMIT; return RMAP_PERMIT;
} }
@ -10180,70 +10183,75 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
} }
} else { } else {
for (adj = rn->adj_out; adj; adj = adj->next) for (adj = rn->adj_out; adj; adj = adj->next)
SUBGRP_FOREACH_PEER (adj->subgroup, paf) SUBGRP_FOREACH_PEER (adj->subgroup, paf) {
if (paf->peer == peer) { if (paf->peer != peer)
if (header1) { continue;
if (use_json) {
json_object_int_add(
json,
"bgpTableVersion",
table->version);
json_object_string_add(
json,
"bgpLocalRouterId",
inet_ntoa(
bgp->router_id));
json_object_object_add(
json,
"bgpStatusCodes",
json_scode);
json_object_object_add(
json,
"bgpOriginCodes",
json_ocode);
} else {
vty_out(vty,
"BGP table version is %" PRIu64
", local router ID is %s\n",
table->version,
inet_ntoa(
bgp->router_id));
vty_out(vty,
BGP_SHOW_SCODE_HEADER);
vty_out(vty,
BGP_SHOW_OCODE_HEADER);
}
header1 = 0;
}
if (header2) { if (header1) {
if (!use_json) if (use_json) {
vty_out(vty, json_object_int_add(
BGP_SHOW_HEADER); json,
header2 = 0; "bgpTableVersion",
} table->version);
json_object_string_add(
if (adj->attr) { json,
bgp_attr_dup(&attr, "bgpLocalRouterId",
adj->attr); inet_ntoa(
ret = bgp_output_modifier( bgp->router_id));
peer, &rn->p, json_object_object_add(
&attr, afi, json,
safi, "bgpStatusCodes",
rmap_name); json_scode);
if (ret != RMAP_DENY) { json_object_object_add(
route_vty_out_tmp( json,
vty, "bgpOriginCodes",
&rn->p, json_ocode);
&attr, } else {
safi, vty_out(vty,
use_json, "BGP table version is %" PRIu64
json_ar); ", local router ID is %s\n",
output_count++; table->version,
} else inet_ntoa(
filtered_count++; bgp->router_id));
vty_out(vty,
BGP_SHOW_SCODE_HEADER);
vty_out(vty,
BGP_SHOW_OCODE_HEADER);
} }
header1 = 0;
} }
if (header2) {
if (!use_json)
vty_out(vty,
BGP_SHOW_HEADER);
header2 = 0;
}
if (adj->attr) {
bgp_attr_dup(&attr,
adj->attr);
ret = bgp_output_modifier(
peer, &rn->p,
&attr, afi,
safi,
rmap_name);
if (ret != RMAP_DENY) {
route_vty_out_tmp(
vty,
&rn->p,
&attr,
safi,
use_json,
json_ar);
output_count++;
} else
filtered_count++;
bgp_attr_undup(&attr,
adj->attr);
}
}
} }
} }
if (use_json) if (use_json)