]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: 'show bgp [ipv4|ipv6] neighbors' displays all af neighbors
authorKiran Kella <kiran.kella@broadcom.com>
Fri, 8 Feb 2019 07:25:25 +0000 (12:55 +0530)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 25 Feb 2019 16:11:03 +0000 (16:11 +0000)
- Display only ipv4 neighbors when 'show bgp ipv4 neighbors' command is
  issued.
- Display only ipv6 neighbors when 'show bgp ipv6 neighbors'
  command is issued.
- Take the address family of the peer address into account, while
  displaying the neighbors.

Signed-off-by: Kiran Kella <kiran.kella@broadcom.com>
bgpd/bgp_vty.c
bgpd/bgpd.h

index f7ec2780ef5f820d398d4913aa894391b180f9e3..67a745047b0ce25b7364035d0b13e68343abee86 100644 (file)
@@ -8296,7 +8296,7 @@ const char *afi_safi_json(afi_t afi, safi_t safi)
 }
 
 /* Show BGP peer's information. */
-enum show_type { show_all, show_peer };
+enum show_type { show_all, show_peer, show_ipv4_all, show_ipv6_all, show_ipv4_peer, show_ipv6_peer };
 
 static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p,
                                      afi_t afi, safi_t safi,
@@ -10690,6 +10690,14 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
        struct listnode *node, *nnode;
        struct peer *peer;
        int find = 0;
+       afi_t afi = AFI_MAX;
+       safi_t safi = SAFI_MAX;
+
+       if (type == show_ipv4_peer || type == show_ipv4_all) {
+               afi = AFI_IP;
+       } else if (type == show_ipv6_peer || type == show_ipv6_all) {
+               afi = AFI_IP6;
+       }
 
        for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
                if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
@@ -10717,10 +10725,45 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp,
                                }
                        }
                        break;
+               case show_ipv4_peer:
+               case show_ipv6_peer:
+                       FOREACH_SAFI (safi) {
+                               if (peer->afc[afi][safi]) {
+                                       if (conf_if) {
+                                               if ((peer->conf_if
+                                                    && !strcmp(peer->conf_if, conf_if))
+                                                   || (peer->hostname
+                                                       && !strcmp(peer->hostname, conf_if))) {
+                                                       find = 1;
+                                                       bgp_show_peer(vty, peer, use_json,
+                                                                     json);
+                                                       break;
+                                               }
+                                       } else {
+                                               if (sockunion_same(&peer->su, su)) {
+                                                       find = 1;
+                                                       bgp_show_peer(vty, peer, use_json,
+                                                                     json);
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+                       break;
+               case show_ipv4_all:
+               case show_ipv6_all:
+                       FOREACH_SAFI (safi) {
+                               if (peer->afc[afi][safi]) {
+                                       bgp_show_peer(vty, peer, use_json, json);
+                                       break;
+                               }
+                       }
+                       break;
                }
        }
 
-       if (type == show_peer && !find) {
+       if ((type == show_peer || type == show_ipv4_peer ||
+            type == show_ipv6_peer) && !find) {
                if (use_json)
                        json_object_boolean_true_add(json, "bgpNoSuchNeighbor");
                else
@@ -10788,7 +10831,8 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
                                        : bgp->name);
                }
 
-               if (type == show_peer) {
+               if (type == show_peer || type == show_ipv4_peer ||
+                   type == show_ipv6_peer) {
                        ret = str2sockunion(ip_str, &su);
                        if (ret < 0)
                                bgp_show_neighbor(vty, bgp, type, NULL, ip_str,
@@ -10797,7 +10841,7 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
                                bgp_show_neighbor(vty, bgp, type, &su, NULL,
                                                  use_json, json);
                } else {
-                       bgp_show_neighbor(vty, bgp, show_all, NULL, NULL,
+                       bgp_show_neighbor(vty, bgp, type, NULL, NULL,
                                          use_json, json);
                }
        }
@@ -10884,6 +10928,7 @@ DEFUN (show_ip_bgp_neighbors,
        char *vrf = NULL;
        char *sh_arg = NULL;
        enum show_type sh_type;
+       afi_t afi = AFI_MAX;
 
        uint8_t uj = use_json(argc, argv);
 
@@ -10894,13 +10939,29 @@ DEFUN (show_ip_bgp_neighbors,
                vrf = argv[idx + 1]->arg;
 
        idx++;
+
+       if (argv_find(argv, argc, "ipv4", &idx)) {
+               sh_type = show_ipv4_all;
+               afi = AFI_IP;
+       } else if (argv_find(argv, argc, "ipv6", &idx)) {
+               sh_type = show_ipv6_all;
+               afi = AFI_IP6;
+       } else {
+               sh_type = show_all;
+       }
+
        if (argv_find(argv, argc, "A.B.C.D", &idx)
            || argv_find(argv, argc, "X:X::X:X", &idx)
            || argv_find(argv, argc, "WORD", &idx)) {
                sh_type = show_peer;
                sh_arg = argv[idx]->arg;
-       } else
-               sh_type = show_all;
+       }
+
+       if (sh_type == show_peer && afi == AFI_IP) {
+               sh_type = show_ipv4_peer;
+       } else if (sh_type == show_peer && afi == AFI_IP6) {
+               sh_type = show_ipv6_peer;
+       }
 
        return bgp_show_neighbor_vty(vty, vrf, sh_type, sh_arg, uj);
 }
index fd2157ab9cb9c02aa4847a5d1b685faca8c841f3..a516e873888c682435868d1444b7b0ce72047c64 100644 (file)
@@ -97,6 +97,9 @@ enum bgp_af_index {
        for (afi = AFI_IP; afi < AFI_MAX; afi++)                               \
                for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
 
+#define FOREACH_SAFI(safi)                                            \
+       for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
+
 /* BGP master for system wide configurations and variables.  */
 struct bgp_master {
        /* BGP instance list.  */