]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #4377 from ton31337/feature/show_fqdn_in_show_ip_bgp
authorRuss White <russ@riw.us>
Tue, 28 May 2019 11:53:20 +0000 (07:53 -0400)
committerGitHub <noreply@github.com>
Tue, 28 May 2019 11:53:20 +0000 (07:53 -0400)
bgpd: Show FQDN in `show [ip] bgp` output

1  2 
bgpd/bgp_route.c

diff --combined bgpd/bgp_route.c
index d526afd77bfa46e832e2616959e20c0f8680ecea,e554b905f3c9acb82d9520717da63f1208d63305..31243c899dc2219e6709b8998d54d99fd58aa6ac
@@@ -6930,6 -6930,13 +6930,13 @@@ static void route_vty_short_status_out(
                vty_out(vty, " ");
  }
  
+ static char *bgp_nexthop_fqdn(struct peer *peer)
+ {
+       if (peer->hostname && bgp_flag_check(peer->bgp, BGP_FLAG_SHOW_HOSTNAME))
+               return peer->hostname;
+       return NULL;
+ }
  /* called from terminal list command */
  void route_vty_out(struct vty *vty, struct prefix *p,
                   struct bgp_path_info *path, int display, safi_t safi,
        bool nexthop_othervrf = false;
        vrf_id_t nexthop_vrfid = VRF_DEFAULT;
        const char *nexthop_vrfname = VRF_DEFAULT_NAME;
+       char *nexthop_fqdn = bgp_nexthop_fqdn(path->peer);
  
        if (json_paths)
                json_path = json_object_new_object();
                if (json_paths) {
                        json_nexthop_global = json_object_new_object();
  
-                       json_object_string_add(json_nexthop_global, "afi",
-                                              (af == AF_INET) ? "ip" : "ipv6");
-                       json_object_string_add(json_nexthop_global,
-                                              (af == AF_INET) ? "ip" : "ipv6",
-                                              nexthop);
+                       json_object_string_add(
+                               json_nexthop_global, "afi",
+                               nexthop_fqdn ? "fqdn"
+                                            : (af == AF_INET) ? "ip" : "ipv6");
+                       json_object_string_add(
+                               json_nexthop_global,
+                               nexthop_fqdn ? "fqdn"
+                                            : (af == AF_INET) ? "ip" : "ipv6",
+                               nexthop_fqdn ? nexthop_fqdn : nexthop);
                        json_object_boolean_true_add(json_nexthop_global,
                                                     "used");
                } else
-                       vty_out(vty, "%s%s", nexthop, vrf_id_str);
+                       vty_out(vty, "%s%s",
+                               nexthop_fqdn ? nexthop_fqdn : nexthop,
+                               vrf_id_str);
        } else if (safi == SAFI_EVPN) {
                if (json_paths) {
                        json_nexthop_global = json_object_new_object();
  
-                       json_object_string_add(json_nexthop_global, "ip",
-                                              inet_ntoa(attr->nexthop));
+                       json_object_string_add(
+                               json_nexthop_global,
+                               nexthop_fqdn ? "fqdn" : "ip",
+                               nexthop_fqdn ? nexthop_fqdn
+                                            : inet_ntoa(attr->nexthop));
                        json_object_string_add(json_nexthop_global, "afi",
                                               "ipv4");
                        json_object_boolean_true_add(json_nexthop_global,
                                                     "used");
                } else
-                       vty_out(vty, "%-16s%s", inet_ntoa(attr->nexthop),
+                       vty_out(vty, "%-16s%s",
+                               nexthop_fqdn ?: inet_ntoa(attr->nexthop),
                                vrf_id_str);
        } else if (safi == SAFI_FLOWSPEC) {
                if (attr->nexthop.s_addr != 0) {
                        if (json_paths) {
                                json_nexthop_global = json_object_new_object();
                                json_object_string_add(
-                                              json_nexthop_global, "ip",
-                                              inet_ntoa(attr->nexthop));
+                                       json_nexthop_global,
+                                       nexthop_fqdn ? "fqdn" : "ip",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntoa(attr->nexthop));
                                json_object_string_add(json_nexthop_global,
                                                       "afi", "ipv4");
                                json_object_boolean_true_add(
                                                        json_nexthop_global,
                                                             "used");
                        } else {
-                               vty_out(vty, "%-16s", inet_ntoa(attr->nexthop));
+                               vty_out(vty, "%-16s",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntoa(attr->nexthop));
                        }
                }
        } else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
  
                        if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_EVPN))
                                json_object_string_add(
-                                       json_nexthop_global, "ip",
-                                       inet_ntoa(attr->mp_nexthop_global_in));
+                                       json_nexthop_global,
+                                       nexthop_fqdn ? "fqdn" : "ip",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntoa(
+                                                         attr->mp_nexthop_global_in));
                        else
                                json_object_string_add(
-                                       json_nexthop_global, "ip",
-                                       inet_ntoa(attr->nexthop));
+                                       json_nexthop_global,
+                                       nexthop_fqdn ? "fqdn" : "ip",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntoa(attr->nexthop));
  
                        json_object_string_add(json_nexthop_global, "afi",
                                               "ipv4");
                        char buf[BUFSIZ];
  
                        snprintf(buf, sizeof(buf), "%s%s",
-                               inet_ntoa(attr->nexthop), vrf_id_str);
+                                nexthop_fqdn ? nexthop_fqdn
+                                             : inet_ntoa(attr->nexthop),
+                                vrf_id_str);
                        vty_out(vty, "%-16s", buf);
                }
        }
                if (json_paths) {
                        json_nexthop_global = json_object_new_object();
                        json_object_string_add(
-                               json_nexthop_global, "ip",
-                               inet_ntop(AF_INET6, &attr->mp_nexthop_global,
-                                         buf, BUFSIZ));
+                               json_nexthop_global,
+                               nexthop_fqdn ? "fqdn" : "ip",
+                               nexthop_fqdn
+                                       ? nexthop_fqdn
+                                       : inet_ntop(AF_INET6,
+                                                   &attr->mp_nexthop_global,
+                                                   buf, BUFSIZ));
                        json_object_string_add(json_nexthop_global, "afi",
                                               "ipv6");
                        json_object_string_add(json_nexthop_global, "scope",
                            || (path->peer->conf_if)) {
                                json_nexthop_ll = json_object_new_object();
                                json_object_string_add(
-                                       json_nexthop_ll, "ip",
-                                       inet_ntop(AF_INET6,
-                                                 &attr->mp_nexthop_local, buf,
-                                                 BUFSIZ));
+                                       json_nexthop_ll,
+                                       nexthop_fqdn ? "fqdn" : "ip",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntop(
+                                                         AF_INET6,
+                                                         &attr->mp_nexthop_local,
+                                                         buf, BUFSIZ));
                                json_object_string_add(json_nexthop_ll, "afi",
                                                       "ipv6");
                                json_object_string_add(json_nexthop_ll, "scope",
                                } else {
                                        len = vty_out(
                                                vty, "%s%s",
-                                               inet_ntop(
-                                                       AF_INET6,
-                                                       &attr->mp_nexthop_local,
-                                                       buf, BUFSIZ),
+                                               nexthop_fqdn
+                                                       ? nexthop_fqdn
+                                                       : inet_ntop(
+                                                                 AF_INET6,
+                                                                 &attr->mp_nexthop_local,
+                                                                 buf, BUFSIZ),
                                                vrf_id_str);
                                        len = 16 - len;
  
                        } else {
                                len = vty_out(
                                        vty, "%s%s",
-                                       inet_ntop(AF_INET6,
-                                                 &attr->mp_nexthop_global, buf,
-                                                 BUFSIZ),
-                                                 vrf_id_str);
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntop(
+                                                         AF_INET6,
+                                                         &attr->mp_nexthop_global,
+                                                         buf, BUFSIZ),
+                                       vrf_id_str);
                                len = 16 - len;
  
                                if (len < 1)
@@@ -7664,7 -7710,7 +7710,7 @@@ void route_vty_out_overlay(struct vty *
                        vty_out(vty, "%s", str);
                else
                        json_object_string_add(json_overlay, "esi", str);
-               
                XFREE(MTYPE_TMP, str);
  
                if (is_evpn_prefix_ipaddr_v4((struct prefix_evpn *)p)) {
@@@ -8005,7 -8051,6 +8051,7 @@@ static const char *bgp_path_selection_r
                return "Nothing left to compare";
                break;
        }
 +      return "Invalid (internal error)";
  }
  
  void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
        bool nexthop_self =
                CHECK_FLAG(path->flags, BGP_PATH_ANNC_NH_SELF) ? true : false;
        int i;
+       char *nexthop_fqdn = bgp_nexthop_fqdn(path->peer);
  
        if (json_paths) {
                json_path = json_object_new_object();
                            || safi == SAFI_EVPN) {
                                if (json_paths)
                                        json_object_string_add(
-                                               json_nexthop_global, "ip",
-                                               inet_ntoa(
-                                                       attr->mp_nexthop_global_in));
+                                               json_nexthop_global,
+                                               nexthop_fqdn ? "fqdn" : "ip",
+                                               nexthop_fqdn
+                                                       ? nexthop_fqdn
+                                                       : inet_ntoa(
+                                                                 attr->mp_nexthop_global_in));
                                else
                                        vty_out(vty, "    %s",
-                                               inet_ntoa(
-                                                       attr->mp_nexthop_global_in));
+                                               nexthop_fqdn
+                                                       ? nexthop_fqdn
+                                                       : inet_ntoa(
+                                                                 attr->mp_nexthop_global_in));
                        } else {
                                if (json_paths)
                                        json_object_string_add(
-                                               json_nexthop_global, "ip",
-                                               inet_ntoa(attr->nexthop));
+                                               json_nexthop_global,
+                                               nexthop_fqdn ? "fqdn" : "ip",
+                                               nexthop_fqdn
+                                                       ? nexthop_fqdn
+                                                       : inet_ntoa(
+                                                                 attr->nexthop));
                                else
                                        vty_out(vty, "    %s",
-                                               inet_ntoa(attr->nexthop));
+                                               nexthop_fqdn
+                                                       ? nexthop_fqdn
+                                                       : inet_ntoa(
+                                                                 attr->nexthop));
                        }
  
                        if (json_paths)
                } else {
                        if (json_paths) {
                                json_object_string_add(
-                                       json_nexthop_global, "ip",
-                                       inet_ntop(AF_INET6,
-                                                 &attr->mp_nexthop_global, buf,
-                                                 INET6_ADDRSTRLEN));
+                                       json_nexthop_global,
+                                       nexthop_fqdn ? "fqdn" : "ip",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntop(
+                                                         AF_INET6,
+                                                         &attr->mp_nexthop_global,
+                                                         buf,
+                                                         INET6_ADDRSTRLEN));
                                json_object_string_add(json_nexthop_global,
                                                       "afi", "ipv6");
                                json_object_string_add(json_nexthop_global,
                                                       "scope", "global");
                        } else {
                                vty_out(vty, "    %s",
-                                       inet_ntop(AF_INET6,
-                                                 &attr->mp_nexthop_global, buf,
-                                                 INET6_ADDRSTRLEN));
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntop(
+                                                         AF_INET6,
+                                                         &attr->mp_nexthop_global,
+                                                         buf,
+                                                         INET6_ADDRSTRLEN));
                        }
                }
  
                        if (json_paths) {
                                json_nexthop_ll = json_object_new_object();
                                json_object_string_add(
-                                       json_nexthop_ll, "ip",
-                                       inet_ntop(AF_INET6,
-                                                 &attr->mp_nexthop_local, buf,
-                                                 INET6_ADDRSTRLEN));
+                                       json_nexthop_ll,
+                                       nexthop_fqdn ? "fqdn" : "ip",
+                                       nexthop_fqdn
+                                               ? nexthop_fqdn
+                                               : inet_ntop(
+                                                         AF_INET6,
+                                                         &attr->mp_nexthop_local,
+                                                         buf,
+                                                         INET6_ADDRSTRLEN));
                                json_object_string_add(json_nexthop_ll, "afi",
                                                       "ipv6");
                                json_object_string_add(json_nexthop_ll, "scope",