]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #2231 from ppmathis/fix/clear-bgp-afi
authorRuss White <russ@riw.us>
Fri, 18 May 2018 06:48:59 +0000 (02:48 -0400)
committerGitHub <noreply@github.com>
Fri, 18 May 2018 06:48:59 +0000 (02:48 -0400)
bgpd: Respect AFI/SAFI when hard-clearing a peer

1  2 
bgpd/bgp_vty.c

diff --combined bgpd/bgp_vty.c
index 35477ba164af38ed6b490ad0f6e092ce94630f87,f95499df5dff1e0f2ce47ea0129c2b91eb4ee69a..f4f4e63264e2af2bee7c02c0a809b62f03dd4032
@@@ -553,39 -553,46 +553,46 @@@ static int bgp_clear(struct vty *vty, s
                     const char *arg)
  {
        int ret;
+       bool found = false;
        struct peer *peer;
        struct listnode *node, *nnode;
  
        /* Clear all neighbors. */
        /*
         * Pass along pointer to next node to peer_clear() when walking all
-        * nodes
-        * on the BGP instance as that may get freed if it is a doppelganger
+        * nodes on the BGP instance as that may get freed if it is a
+        * doppelganger
         */
        if (sort == clear_all) {
                for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
+                       if (!peer->afc[afi][safi])
+                               continue;
                        if (stype == BGP_CLEAR_SOFT_NONE)
                                ret = peer_clear(peer, &nnode);
-                       else if (peer->afc[afi][safi])
-                               ret = peer_clear_soft(peer, afi, safi, stype);
                        else
-                               ret = 0;
+                               ret = peer_clear_soft(peer, afi, safi, stype);
  
                        if (ret < 0)
                                bgp_clear_vty_error(vty, peer, afi, safi, ret);
+                       else
+                               found = true;
                }
  
                /* This is to apply read-only mode on this clear. */
                if (stype == BGP_CLEAR_SOFT_NONE)
                        bgp->update_delay_over = 0;
  
+               if (!found)
+                       vty_out(vty, "%%BGP: No %s peer configured",
+                               afi_safi_print(afi, safi));
                return CMD_SUCCESS;
        }
  
-       /* Clear specified neighbors. */
+       /* Clear specified neighbor. */
        if (sort == clear_peer) {
                union sockunion su;
-               int ret;
  
                /* Make sockunion for lookup. */
                ret = str2sockunion(arg, &su);
                        }
                }
  
-               if (stype == BGP_CLEAR_SOFT_NONE)
+               if (!peer->afc[afi][safi])
+                       ret = BGP_ERR_AF_UNCONFIGURED;
+               else if (stype == BGP_CLEAR_SOFT_NONE)
                        ret = peer_clear(peer, NULL);
                else
                        ret = peer_clear_soft(peer, afi, safi, stype);
                return CMD_SUCCESS;
        }
  
-       /* Clear all peer-group members. */
+       /* Clear all neighbors belonging to a specific peer-group. */
        if (sort == clear_group) {
                struct peer_group *group;
  
                }
  
                for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
-                       if (stype == BGP_CLEAR_SOFT_NONE) {
-                               peer_clear(peer, NULL);
-                               continue;
-                       }
                        if (!peer->afc[afi][safi])
                                continue;
  
-                       ret = peer_clear_soft(peer, afi, safi, stype);
+                       if (stype == BGP_CLEAR_SOFT_NONE)
+                               ret = peer_clear(peer, NULL);
+                       else
+                               ret = peer_clear_soft(peer, afi, safi, stype);
  
                        if (ret < 0)
                                bgp_clear_vty_error(vty, peer, afi, safi, ret);
+                       else
+                               found = true;
                }
+               if (!found)
+                       vty_out(vty,
+                               "%%BGP: No %s peer belonging to peer-group %s is configured\n",
+                               afi_safi_print(afi, safi), arg);
                return CMD_SUCCESS;
        }
  
+       /* Clear all external (eBGP) neighbors. */
        if (sort == clear_external) {
                for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
                        if (peer->sort == BGP_PEER_IBGP)
                                continue;
  
+                       if (!peer->afc[afi][safi])
+                               continue;
                        if (stype == BGP_CLEAR_SOFT_NONE)
                                ret = peer_clear(peer, &nnode);
                        else
  
                        if (ret < 0)
                                bgp_clear_vty_error(vty, peer, afi, safi, ret);
+                       else
+                               found = true;
                }
+               if (!found)
+                       vty_out(vty,
+                               "%%BGP: No external %s peer is configured\n",
+                               afi_safi_print(afi, safi));
                return CMD_SUCCESS;
        }
  
+       /* Clear all neighbors belonging to a specific AS. */
        if (sort == clear_as) {
-               as_t as;
-               int find = 0;
-               as = strtoul(arg, NULL, 10);
+               as_t as = strtoul(arg, NULL, 10);
  
                for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
                        if (peer->as != as)
                                continue;
  
-                       find = 1;
-                       if (stype == BGP_CLEAR_SOFT_NONE)
+                       if (!peer->afc[afi][safi])
+                               ret = BGP_ERR_AF_UNCONFIGURED;
+                       else if (stype == BGP_CLEAR_SOFT_NONE)
                                ret = peer_clear(peer, &nnode);
                        else
                                ret = peer_clear_soft(peer, afi, safi, stype);
  
                        if (ret < 0)
                                bgp_clear_vty_error(vty, peer, afi, safi, ret);
+                       else
+                               found = true;
                }
-               if (!find)
+               if (!found)
                        vty_out(vty,
-                               "%%BGP: No peer is configured with AS %s\n",
-                               arg);
+                               "%%BGP: No %s peer is configured with AS %s\n",
+                               afi_safi_print(afi, safi), arg);
                return CMD_SUCCESS;
        }
  
@@@ -10859,7 -10889,7 +10889,7 @@@ static void lcommunity_show_all_iterato
  
        lcom = (struct lcommunity *)backet->data;
        vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
 -              lcommunity_str(lcom));
 +              lcommunity_str(lcom, false));
  }
  
  /* Show BGP's community internal data. */
@@@ -13606,24 -13636,6 +13636,24 @@@ DEFUN (no_ip_community_list_expanded_al
        return CMD_SUCCESS;
  }
  
 +/* Return configuration string of community-list entry.  */
 +static const char *community_list_config_str(struct community_entry *entry)
 +{
 +      const char *str;
 +
 +      if (entry->any)
 +              str = "";
 +      else {
 +              if (entry->style == COMMUNITY_LIST_STANDARD)
 +                      str = community_str(entry->u.com, false);
 +              else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
 +                      str = lcommunity_str(entry->u.lcom, false);
 +              else
 +                      str = entry->config;
 +      }
 +      return str;
 +}
 +
  static void community_list_show(struct vty *vty, struct community_list *list)
  {
        struct community_entry *entry;
                else
                        vty_out(vty, "    %s %s\n",
                                community_direct_str(entry->direct),
 -                              entry->style == COMMUNITY_LIST_STANDARD
 -                                      ? community_str(entry->u.com, false)
 -                                      : entry->config);
 +                              community_list_config_str(entry));
        }
  }
  
@@@ -14001,7 -14015,9 +14031,7 @@@ static void lcommunity_list_show(struc
                else
                        vty_out(vty, "    %s %s\n",
                                community_direct_str(entry->direct),
 -                              entry->style == EXTCOMMUNITY_LIST_STANDARD
 -                                      ? entry->u.ecom->str
 -                                      : entry->config);
 +                              community_list_config_str(entry));
        }
  }
  
@@@ -14236,7 -14252,9 +14266,7 @@@ static void extcommunity_list_show(stru
                else
                        vty_out(vty, "    %s %s\n",
                                community_direct_str(entry->direct),
 -                              entry->style == EXTCOMMUNITY_LIST_STANDARD
 -                                      ? entry->u.ecom->str
 -                                      : entry->config);
 +                              community_list_config_str(entry));
        }
  }
  
@@@ -14287,6 -14305,22 +14317,6 @@@ DEFUN (show_ip_extcommunity_list_arg
        return CMD_SUCCESS;
  }
  
 -/* Return configuration string of community-list entry.  */
 -static const char *community_list_config_str(struct community_entry *entry)
 -{
 -      const char *str;
 -
 -      if (entry->any)
 -              str = "";
 -      else {
 -              if (entry->style == COMMUNITY_LIST_STANDARD)
 -                      str = community_str(entry->u.com, false);
 -              else
 -                      str = entry->config;
 -      }
 -      return str;
 -}
 -
  /* Display community-list and extcommunity-list configuration.  */
  static int community_list_config_write(struct vty *vty)
  {