mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-09 11:24:42 +00:00
bgpd: Abstract the header inclusion for show_adj_route
Cut-n-paste code can go away. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
5a45d61308
commit
2f9bc755fd
172
bgpd/bgp_route.c
172
bgpd/bgp_route.c
@ -11971,6 +11971,52 @@ DEFUN (show_bgp_l2vpn_evpn_route_prefix,
|
|||||||
use_json(argc, argv));
|
use_json(argc, argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void show_adj_route_header(struct vty *vty, struct bgp *bgp,
|
||||||
|
struct bgp_table *table, int *header1,
|
||||||
|
int *header2, json_object *json,
|
||||||
|
json_object *json_scode,
|
||||||
|
json_object *json_ocode, bool wide)
|
||||||
|
{
|
||||||
|
uint64_t version = table ? table->version : 0;
|
||||||
|
|
||||||
|
if (*header1) {
|
||||||
|
if (json) {
|
||||||
|
json_object_int_add(json, "bgpTableVersion", version);
|
||||||
|
json_object_string_add(json, "bgpLocalRouterId",
|
||||||
|
inet_ntoa(bgp->router_id));
|
||||||
|
json_object_int_add(json, "defaultLocPrf",
|
||||||
|
bgp->default_local_pref);
|
||||||
|
json_object_int_add(json, "localAS", bgp->as);
|
||||||
|
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, vrf id ",
|
||||||
|
version, inet_ntoa(bgp->router_id));
|
||||||
|
if (bgp->vrf_id == VRF_UNKNOWN)
|
||||||
|
vty_out(vty, "%s", VRFID_NONE_STR);
|
||||||
|
else
|
||||||
|
vty_out(vty, "%u", bgp->vrf_id);
|
||||||
|
vty_out(vty, "\n");
|
||||||
|
vty_out(vty, "Default local pref %u, ",
|
||||||
|
bgp->default_local_pref);
|
||||||
|
vty_out(vty, "local AS %u\n", bgp->as);
|
||||||
|
vty_out(vty, BGP_SHOW_SCODE_HEADER);
|
||||||
|
vty_out(vty, BGP_SHOW_NCODE_HEADER);
|
||||||
|
vty_out(vty, BGP_SHOW_OCODE_HEADER);
|
||||||
|
}
|
||||||
|
*header1 = 0;
|
||||||
|
}
|
||||||
|
if (*header2) {
|
||||||
|
if (!json)
|
||||||
|
vty_out(vty, (wide ? BGP_SHOW_HEADER_WIDE
|
||||||
|
: BGP_SHOW_HEADER));
|
||||||
|
*header2 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
|
static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
|
||||||
safi_t safi, enum bgp_show_adj_route_type type,
|
safi_t safi, enum bgp_show_adj_route_type type,
|
||||||
const char *rmap_name, bool use_json,
|
const char *rmap_name, bool use_json,
|
||||||
@ -12081,60 +12127,9 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
|
|||||||
if (ain->peer != peer)
|
if (ain->peer != peer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (header1) {
|
show_adj_route_header(
|
||||||
if (use_json) {
|
vty, bgp, table, &header1, &header2,
|
||||||
json_object_int_add(
|
json, json_scode, json_ocode, wide);
|
||||||
json, "bgpTableVersion",
|
|
||||||
0);
|
|
||||||
json_object_string_add(
|
|
||||||
json,
|
|
||||||
"bgpLocalRouterId",
|
|
||||||
inet_ntoa(
|
|
||||||
bgp->router_id));
|
|
||||||
json_object_int_add(json,
|
|
||||||
"defaultLocPrf",
|
|
||||||
bgp->default_local_pref);
|
|
||||||
json_object_int_add(json,
|
|
||||||
"localAS", bgp->as);
|
|
||||||
json_object_object_add(
|
|
||||||
json, "bgpStatusCodes",
|
|
||||||
json_scode);
|
|
||||||
json_object_object_add(
|
|
||||||
json, "bgpOriginCodes",
|
|
||||||
json_ocode);
|
|
||||||
} else {
|
|
||||||
vty_out(vty,
|
|
||||||
"BGP table version is 0, local router ID is %s, vrf id ",
|
|
||||||
inet_ntoa(
|
|
||||||
bgp->router_id));
|
|
||||||
if (bgp->vrf_id == VRF_UNKNOWN)
|
|
||||||
vty_out(vty, "%s",
|
|
||||||
VRFID_NONE_STR);
|
|
||||||
else
|
|
||||||
vty_out(vty, "%u",
|
|
||||||
bgp->vrf_id);
|
|
||||||
vty_out(vty, "\n");
|
|
||||||
vty_out(vty,
|
|
||||||
"Default local pref %u, ",
|
|
||||||
bgp->default_local_pref);
|
|
||||||
vty_out(vty, "local AS %u\n",
|
|
||||||
bgp->as);
|
|
||||||
vty_out(vty,
|
|
||||||
BGP_SHOW_SCODE_HEADER);
|
|
||||||
vty_out(vty,
|
|
||||||
BGP_SHOW_NCODE_HEADER);
|
|
||||||
vty_out(vty,
|
|
||||||
BGP_SHOW_OCODE_HEADER);
|
|
||||||
}
|
|
||||||
header1 = 0;
|
|
||||||
}
|
|
||||||
if (header2) {
|
|
||||||
if (!use_json)
|
|
||||||
vty_out(vty,
|
|
||||||
(wide ? BGP_SHOW_HEADER_WIDE
|
|
||||||
: BGP_SHOW_HEADER));
|
|
||||||
header2 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
attr = *ain->attr;
|
attr = *ain->attr;
|
||||||
route_filtered = false;
|
route_filtered = false;
|
||||||
@ -12175,71 +12170,10 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
|
|||||||
if (paf->peer != peer || !adj->attr)
|
if (paf->peer != peer || !adj->attr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (header1) {
|
show_adj_route_header(
|
||||||
if (use_json) {
|
vty, bgp, table, &header1,
|
||||||
json_object_int_add(
|
&header2, json, json_scode,
|
||||||
json,
|
json_ocode, wide);
|
||||||
"bgpTableVersion",
|
|
||||||
table->version);
|
|
||||||
json_object_string_add(
|
|
||||||
json,
|
|
||||||
"bgpLocalRouterId",
|
|
||||||
inet_ntoa(
|
|
||||||
bgp->router_id));
|
|
||||||
json_object_int_add(
|
|
||||||
json, "defaultLocPrf",
|
|
||||||
bgp->default_local_pref
|
|
||||||
);
|
|
||||||
json_object_int_add(
|
|
||||||
json, "localAS",
|
|
||||||
bgp->as);
|
|
||||||
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, vrf id ",
|
|
||||||
table->version,
|
|
||||||
inet_ntoa(
|
|
||||||
bgp->router_id));
|
|
||||||
if (bgp->vrf_id ==
|
|
||||||
VRF_UNKNOWN)
|
|
||||||
vty_out(vty,
|
|
||||||
"%s",
|
|
||||||
VRFID_NONE_STR);
|
|
||||||
else
|
|
||||||
vty_out(vty,
|
|
||||||
"%u",
|
|
||||||
bgp->vrf_id);
|
|
||||||
vty_out(vty, "\n");
|
|
||||||
vty_out(vty,
|
|
||||||
"Default local pref %u, ",
|
|
||||||
bgp->default_local_pref
|
|
||||||
);
|
|
||||||
vty_out(vty,
|
|
||||||
"local AS %u\n",
|
|
||||||
bgp->as);
|
|
||||||
vty_out(vty,
|
|
||||||
BGP_SHOW_SCODE_HEADER);
|
|
||||||
vty_out(vty,
|
|
||||||
BGP_SHOW_NCODE_HEADER);
|
|
||||||
vty_out(vty,
|
|
||||||
BGP_SHOW_OCODE_HEADER);
|
|
||||||
}
|
|
||||||
header1 = 0;
|
|
||||||
}
|
|
||||||
if (header2) {
|
|
||||||
if (!use_json)
|
|
||||||
vty_out(vty,
|
|
||||||
(wide ? BGP_SHOW_HEADER_WIDE
|
|
||||||
: BGP_SHOW_HEADER));
|
|
||||||
header2 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct prefix *rn_p =
|
const struct prefix *rn_p =
|
||||||
bgp_dest_get_prefix(dest);
|
bgp_dest_get_prefix(dest);
|
||||||
|
Loading…
Reference in New Issue
Block a user