mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-27 08:32:12 +00:00
bgpd: Show the real next-hop address in addition to hostname in show bgp
It's hard to cope with cases when next-hop is changed/unchanged or peers are non-direct. It would be better to show the hostname and nexthop IP address (both) under `show bgp` to quickly identify the source and the real next-hop of the route. If `bgp default show-nexthop-hostname` is toggled the output looks like: ``` spine1-debian-9# show bgp BGP table version is 1, local router ID is 2.2.2.2, vrf id 0 Default local pref 100, local AS 65002 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 * 2a02:4780::/64 fe80::a00:27ff:fe09:f8a3(exit1-debian-9) 0 0 65001 ? spine1-debian-9# 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 65002 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 *> 10.255.255.0/24 192.168.0.1(exit1-debian-9) 0 0 65001 ? ``` Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
parent
c6a5994609
commit
e7cc3d2145
161
bgpd/bgp_route.c
161
bgpd/bgp_route.c
@ -7559,8 +7559,7 @@ static char *bgp_nexthop_hostname(struct peer *peer,
|
|||||||
struct bgp_nexthop_cache *bnc)
|
struct bgp_nexthop_cache *bnc)
|
||||||
{
|
{
|
||||||
if (peer->hostname
|
if (peer->hostname
|
||||||
&& CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_HOSTNAME) && bnc
|
&& CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME))
|
||||||
&& CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED))
|
|
||||||
return peer->hostname;
|
return peer->hostname;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -7570,6 +7569,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
struct bgp_path_info *path, int display, safi_t safi,
|
struct bgp_path_info *path, int display, safi_t safi,
|
||||||
json_object *json_paths)
|
json_object *json_paths)
|
||||||
{
|
{
|
||||||
|
int len;
|
||||||
struct attr *attr = path->attr;
|
struct attr *attr = path->attr;
|
||||||
json_object *json_path = NULL;
|
json_object *json_path = NULL;
|
||||||
json_object *json_nexthops = NULL;
|
json_object *json_nexthops = NULL;
|
||||||
@ -7681,10 +7681,19 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
: "ipv6");
|
: "ipv6");
|
||||||
json_object_boolean_true_add(json_nexthop_global,
|
json_object_boolean_true_add(json_nexthop_global,
|
||||||
"used");
|
"used");
|
||||||
} else
|
} else {
|
||||||
vty_out(vty, "%s%s",
|
if (nexthop_hostname)
|
||||||
nexthop_hostname ? nexthop_hostname : nexthop,
|
len = vty_out(vty, "%s(%s)%s", nexthop,
|
||||||
vrf_id_str);
|
nexthop_hostname, vrf_id_str);
|
||||||
|
else
|
||||||
|
len = vty_out(vty, "%s%s", nexthop, vrf_id_str);
|
||||||
|
|
||||||
|
len = 16 - len;
|
||||||
|
if (len < 1)
|
||||||
|
vty_out(vty, "\n%*s", 36, " ");
|
||||||
|
else
|
||||||
|
vty_out(vty, "%*s", len, " ");
|
||||||
|
}
|
||||||
} else if (safi == SAFI_EVPN) {
|
} else if (safi == SAFI_EVPN) {
|
||||||
if (json_paths) {
|
if (json_paths) {
|
||||||
json_nexthop_global = json_object_new_object();
|
json_nexthop_global = json_object_new_object();
|
||||||
@ -7701,11 +7710,20 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
"ipv4");
|
"ipv4");
|
||||||
json_object_boolean_true_add(json_nexthop_global,
|
json_object_boolean_true_add(json_nexthop_global,
|
||||||
"used");
|
"used");
|
||||||
} else
|
} else {
|
||||||
vty_out(vty, "%-16s%s",
|
if (nexthop_hostname)
|
||||||
nexthop_hostname ? nexthop_hostname
|
len = vty_out(vty, "%pI4(%s)%s", &attr->nexthop,
|
||||||
: inet_ntoa(attr->nexthop),
|
nexthop_hostname, vrf_id_str);
|
||||||
vrf_id_str);
|
else
|
||||||
|
len = vty_out(vty, "%pI4%s", &attr->nexthop,
|
||||||
|
vrf_id_str);
|
||||||
|
|
||||||
|
len = 16 - len;
|
||||||
|
if (len < 1)
|
||||||
|
vty_out(vty, "\n%*s", 36, " ");
|
||||||
|
else
|
||||||
|
vty_out(vty, "%*s", len, " ");
|
||||||
|
}
|
||||||
} else if (safi == SAFI_FLOWSPEC) {
|
} else if (safi == SAFI_FLOWSPEC) {
|
||||||
if (attr->nexthop.s_addr != INADDR_ANY) {
|
if (attr->nexthop.s_addr != INADDR_ANY) {
|
||||||
if (json_paths) {
|
if (json_paths) {
|
||||||
@ -7726,10 +7744,21 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
json_nexthop_global,
|
json_nexthop_global,
|
||||||
"used");
|
"used");
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, "%-16s",
|
if (nexthop_hostname)
|
||||||
nexthop_hostname
|
len = vty_out(vty, "%pI4(%s)%s",
|
||||||
? nexthop_hostname
|
&attr->nexthop,
|
||||||
: inet_ntoa(attr->nexthop));
|
nexthop_hostname,
|
||||||
|
vrf_id_str);
|
||||||
|
else
|
||||||
|
len = vty_out(vty, "%pI4%s",
|
||||||
|
&attr->nexthop,
|
||||||
|
vrf_id_str);
|
||||||
|
|
||||||
|
len = 16 - len;
|
||||||
|
if (len < 1)
|
||||||
|
vty_out(vty, "\n%*s", 36, " ");
|
||||||
|
else
|
||||||
|
vty_out(vty, "%*s", len, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
|
} else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
|
||||||
@ -7749,19 +7778,23 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
json_object_boolean_true_add(json_nexthop_global,
|
json_object_boolean_true_add(json_nexthop_global,
|
||||||
"used");
|
"used");
|
||||||
} else {
|
} else {
|
||||||
char buf[BUFSIZ];
|
if (nexthop_hostname)
|
||||||
|
len = vty_out(vty, "%pI4(%s)%s", &attr->nexthop,
|
||||||
|
nexthop_hostname, vrf_id_str);
|
||||||
|
else
|
||||||
|
len = vty_out(vty, "%pI4%s", &attr->nexthop,
|
||||||
|
vrf_id_str);
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s%s",
|
len = 16 - len;
|
||||||
nexthop_hostname ? nexthop_hostname
|
if (len < 1)
|
||||||
: inet_ntoa(attr->nexthop),
|
vty_out(vty, "\n%*s", 36, " ");
|
||||||
vrf_id_str);
|
else
|
||||||
vty_out(vty, "%-16s", buf);
|
vty_out(vty, "%*s", len, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IPv6 Next Hop */
|
/* IPv6 Next Hop */
|
||||||
else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
|
else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
|
||||||
int len;
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
if (json_paths) {
|
if (json_paths) {
|
||||||
@ -7835,15 +7868,18 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
else
|
else
|
||||||
vty_out(vty, "%*s", len, " ");
|
vty_out(vty, "%*s", len, " ");
|
||||||
} else {
|
} else {
|
||||||
len = vty_out(
|
if (nexthop_hostname)
|
||||||
vty, "%s%s",
|
len = vty_out(
|
||||||
nexthop_hostname
|
vty, "%pI6(%s)%s",
|
||||||
? nexthop_hostname
|
&attr->mp_nexthop_local,
|
||||||
: inet_ntop(
|
nexthop_hostname,
|
||||||
AF_INET6,
|
vrf_id_str);
|
||||||
&attr->mp_nexthop_local,
|
else
|
||||||
buf, BUFSIZ),
|
len = vty_out(
|
||||||
vrf_id_str);
|
vty, "%pI6%s",
|
||||||
|
&attr->mp_nexthop_local,
|
||||||
|
vrf_id_str);
|
||||||
|
|
||||||
len = 16 - len;
|
len = 16 - len;
|
||||||
|
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
@ -7852,15 +7888,16 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
|
|||||||
vty_out(vty, "%*s", len, " ");
|
vty_out(vty, "%*s", len, " ");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
len = vty_out(
|
if (nexthop_hostname)
|
||||||
vty, "%s%s",
|
len = vty_out(vty, "%pI6(%s)%s",
|
||||||
nexthop_hostname
|
&attr->mp_nexthop_global,
|
||||||
? nexthop_hostname
|
nexthop_hostname,
|
||||||
: inet_ntop(
|
vrf_id_str);
|
||||||
AF_INET6,
|
else
|
||||||
&attr->mp_nexthop_global,
|
len = vty_out(vty, "%pI6%s",
|
||||||
buf, BUFSIZ),
|
&attr->mp_nexthop_global,
|
||||||
vrf_id_str);
|
vrf_id_str);
|
||||||
|
|
||||||
len = 16 - len;
|
len = 16 - len;
|
||||||
|
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
@ -7986,6 +8023,7 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
|
|||||||
{
|
{
|
||||||
json_object *json_status = NULL;
|
json_object *json_status = NULL;
|
||||||
json_object *json_net = NULL;
|
json_object *json_net = NULL;
|
||||||
|
int len;
|
||||||
char buff[BUFSIZ];
|
char buff[BUFSIZ];
|
||||||
|
|
||||||
/* Route status display. */
|
/* Route status display. */
|
||||||
@ -8079,7 +8117,6 @@ void route_vty_out_tmp(struct vty *vty, const struct prefix *p,
|
|||||||
inet_ntoa(attr->nexthop));
|
inet_ntoa(attr->nexthop));
|
||||||
} else if (p->family == AF_INET6
|
} else if (p->family == AF_INET6
|
||||||
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
|
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
|
||||||
int len;
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
len = vty_out(
|
len = vty_out(
|
||||||
@ -8823,12 +8860,15 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
|
|||||||
json_object_string_add(
|
json_object_string_add(
|
||||||
json_nexthop_global, "hostname",
|
json_nexthop_global, "hostname",
|
||||||
nexthop_hostname);
|
nexthop_hostname);
|
||||||
} else
|
} else {
|
||||||
vty_out(vty, " %s",
|
if (nexthop_hostname)
|
||||||
nexthop_hostname
|
vty_out(vty, " %pI4(%s)",
|
||||||
? nexthop_hostname
|
&attr->mp_nexthop_global_in,
|
||||||
: inet_ntoa(
|
nexthop_hostname);
|
||||||
attr->mp_nexthop_global_in));
|
else
|
||||||
|
vty_out(vty, " %pI4",
|
||||||
|
&attr->mp_nexthop_global_in);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (json_paths) {
|
if (json_paths) {
|
||||||
json_object_string_add(
|
json_object_string_add(
|
||||||
@ -8839,11 +8879,15 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
|
|||||||
json_object_string_add(
|
json_object_string_add(
|
||||||
json_nexthop_global, "hostname",
|
json_nexthop_global, "hostname",
|
||||||
nexthop_hostname);
|
nexthop_hostname);
|
||||||
} else
|
} else {
|
||||||
vty_out(vty, " %s",
|
if (nexthop_hostname)
|
||||||
nexthop_hostname
|
vty_out(vty, " %pI4(%s)",
|
||||||
? nexthop_hostname
|
&attr->nexthop,
|
||||||
: inet_ntoa(attr->nexthop));
|
nexthop_hostname);
|
||||||
|
else
|
||||||
|
vty_out(vty, " %pI4",
|
||||||
|
&attr->nexthop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_paths)
|
if (json_paths)
|
||||||
@ -8866,12 +8910,13 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
|
|||||||
json_object_string_add(json_nexthop_global, "scope",
|
json_object_string_add(json_nexthop_global, "scope",
|
||||||
"global");
|
"global");
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, " %s",
|
if (nexthop_hostname)
|
||||||
nexthop_hostname
|
vty_out(vty, " %pI6(%s)",
|
||||||
? nexthop_hostname
|
&attr->mp_nexthop_global,
|
||||||
: inet_ntop(AF_INET6,
|
nexthop_hostname);
|
||||||
&attr->mp_nexthop_global,
|
else
|
||||||
buf, INET6_ADDRSTRLEN));
|
vty_out(vty, " %pI6",
|
||||||
|
&attr->mp_nexthop_global);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,10 @@ FRR_CFG_DEFAULT_BOOL(BGP_SHOW_HOSTNAME,
|
|||||||
{ .val_bool = true, .match_profile = "datacenter", },
|
{ .val_bool = true, .match_profile = "datacenter", },
|
||||||
{ .val_bool = false },
|
{ .val_bool = false },
|
||||||
)
|
)
|
||||||
|
FRR_CFG_DEFAULT_BOOL(BGP_SHOW_NEXTHOP_HOSTNAME,
|
||||||
|
{ .val_bool = true, .match_profile = "datacenter", },
|
||||||
|
{ .val_bool = false },
|
||||||
|
)
|
||||||
FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
|
FRR_CFG_DEFAULT_BOOL(BGP_LOG_NEIGHBOR_CHANGES,
|
||||||
{ .val_bool = true, .match_profile = "datacenter", },
|
{ .val_bool = true, .match_profile = "datacenter", },
|
||||||
{ .val_bool = false },
|
{ .val_bool = false },
|
||||||
@ -422,6 +426,8 @@ int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
|
|||||||
SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
|
SET_FLAG((*bgp)->flags, BGP_FLAG_IMPORT_CHECK);
|
||||||
if (DFLT_BGP_SHOW_HOSTNAME)
|
if (DFLT_BGP_SHOW_HOSTNAME)
|
||||||
SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
|
SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_HOSTNAME);
|
||||||
|
if (DFLT_BGP_SHOW_NEXTHOP_HOSTNAME)
|
||||||
|
SET_FLAG((*bgp)->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
|
||||||
if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
|
if (DFLT_BGP_LOG_NEIGHBOR_CHANGES)
|
||||||
SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
|
SET_FLAG((*bgp)->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
|
||||||
if (DFLT_BGP_DETERMINISTIC_MED)
|
if (DFLT_BGP_DETERMINISTIC_MED)
|
||||||
@ -3100,6 +3106,32 @@ DEFUN (no_bgp_default_show_hostname,
|
|||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Display hostname in certain command outputs */
|
||||||
|
DEFUN (bgp_default_show_nexthop_hostname,
|
||||||
|
bgp_default_show_nexthop_hostname_cmd,
|
||||||
|
"bgp default show-nexthop-hostname",
|
||||||
|
"BGP specific commands\n"
|
||||||
|
"Configure BGP defaults\n"
|
||||||
|
"Show hostname for nexthop in certain command outputs\n")
|
||||||
|
{
|
||||||
|
VTY_DECLVAR_CONTEXT(bgp, bgp);
|
||||||
|
SET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFUN (no_bgp_default_show_nexthop_hostname,
|
||||||
|
no_bgp_default_show_nexthop_hostname_cmd,
|
||||||
|
"no bgp default show-nexthop-hostname",
|
||||||
|
NO_STR
|
||||||
|
"BGP specific commands\n"
|
||||||
|
"Configure BGP defaults\n"
|
||||||
|
"Show hostname for nexthop in certain command outputs\n")
|
||||||
|
{
|
||||||
|
VTY_DECLVAR_CONTEXT(bgp, bgp);
|
||||||
|
UNSET_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME);
|
||||||
|
return CMD_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/* "bgp network import-check" configuration. */
|
/* "bgp network import-check" configuration. */
|
||||||
DEFUN (bgp_network_import_check,
|
DEFUN (bgp_network_import_check,
|
||||||
bgp_network_import_check_cmd,
|
bgp_network_import_check_cmd,
|
||||||
@ -15190,6 +15222,15 @@ int bgp_config_write(struct vty *vty)
|
|||||||
? ""
|
? ""
|
||||||
: "no ");
|
: "no ");
|
||||||
|
|
||||||
|
/* BGP default show-nexthop-hostname */
|
||||||
|
if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
|
||||||
|
!= SAVE_BGP_SHOW_HOSTNAME)
|
||||||
|
vty_out(vty, " %sbgp default show-nexthop-hostname\n",
|
||||||
|
CHECK_FLAG(bgp->flags,
|
||||||
|
BGP_FLAG_SHOW_NEXTHOP_HOSTNAME)
|
||||||
|
? ""
|
||||||
|
: "no ");
|
||||||
|
|
||||||
/* BGP default subgroup-pkt-queue-max. */
|
/* BGP default subgroup-pkt-queue-max. */
|
||||||
if (bgp->default_subgroup_pkt_queue_max
|
if (bgp->default_subgroup_pkt_queue_max
|
||||||
!= BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
|
!= BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
|
||||||
@ -15815,6 +15856,10 @@ void bgp_vty_init(void)
|
|||||||
install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
|
install_element(BGP_NODE, &bgp_default_show_hostname_cmd);
|
||||||
install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
|
install_element(BGP_NODE, &no_bgp_default_show_hostname_cmd);
|
||||||
|
|
||||||
|
/* bgp default show-nexthop-hostname */
|
||||||
|
install_element(BGP_NODE, &bgp_default_show_nexthop_hostname_cmd);
|
||||||
|
install_element(BGP_NODE, &no_bgp_default_show_nexthop_hostname_cmd);
|
||||||
|
|
||||||
/* "bgp default subgroup-pkt-queue-max" commands. */
|
/* "bgp default subgroup-pkt-queue-max" commands. */
|
||||||
install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
|
install_element(BGP_NODE, &bgp_default_subgroup_pkt_queue_max_cmd);
|
||||||
install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
|
install_element(BGP_NODE, &no_bgp_default_subgroup_pkt_queue_max_cmd);
|
||||||
|
@ -447,6 +447,7 @@ struct bgp {
|
|||||||
#define BGP_FLAG_SELECT_DEFER_DISABLE (1 << 23)
|
#define BGP_FLAG_SELECT_DEFER_DISABLE (1 << 23)
|
||||||
#define BGP_FLAG_GR_DISABLE_EOR (1 << 24)
|
#define BGP_FLAG_GR_DISABLE_EOR (1 << 24)
|
||||||
#define BGP_FLAG_EBGP_REQUIRES_POLICY (1 << 25)
|
#define BGP_FLAG_EBGP_REQUIRES_POLICY (1 << 25)
|
||||||
|
#define BGP_FLAG_SHOW_NEXTHOP_HOSTNAME (1 << 26)
|
||||||
|
|
||||||
enum global_mode GLOBAL_GR_FSM[BGP_GLOBAL_GR_MODE]
|
enum global_mode GLOBAL_GR_FSM[BGP_GLOBAL_GR_MODE]
|
||||||
[BGP_GLOBAL_GR_EVENT_CMD];
|
[BGP_GLOBAL_GR_EVENT_CMD];
|
||||||
|
Loading…
Reference in New Issue
Block a user