]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/distribute.c
isisd: implemented the 'sequence-number-skipped' notification
[mirror_frr.git] / lib / distribute.c
index 9f1272111bff3ac8c67c371cc0e935b6848322b0..96979163323480b3a78a64a04bfb1fe40c357b4b 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -141,15 +140,15 @@ static unsigned int distribute_hash_make(void *arg)
 
 /* If two distribute-list have same value then return 1 else return
    0. This function is used by hash package. */
-static int distribute_cmp(const struct distribute *dist1,
+static bool distribute_cmp(const struct distribute *dist1,
                          const struct distribute *dist2)
 {
        if (dist1->ifname && dist2->ifname)
                if (strcmp(dist1->ifname, dist2->ifname) == 0)
-                       return 1;
+                       return true;
        if (!dist1->ifname && !dist2->ifname)
-               return 1;
-       return 0;
+               return true;
+       return false;
 }
 
 /* Set access-list name to the distribute list. */
@@ -300,16 +299,15 @@ DEFUN (ipv6_distribute_list,
                ifname = argv[argc - 1]->arg;
 
        /* Get interface name corresponding distribute list. */
-       distfn(ifname, type, argv[1 + prefix]->arg);
+       distfn(ifname, type, argv[2 + prefix]->arg);
 
        return CMD_SUCCESS;
 }
 
 DEFUN (no_distribute_list,
        no_distribute_list_cmd,
-       "no [ipv6] distribute-list [prefix] WORD <in|out> [WORD]",
+       "no distribute-list [prefix] WORD <in|out> [WORD]",
        NO_STR
-       "IPv6\n"
        "Filter networks in routing updates\n"
        "Specify a prefix\n"
        "Access-list name\n"
@@ -317,20 +315,53 @@ DEFUN (no_distribute_list,
        "Filter outgoing routing updates\n"
        "Interface name\n")
 {
-       int ipv6 = strmatch(argv[1]->text, "ipv6");
-       int prefix = (argv[2 + ipv6]->type == WORD_TKN) ? 1 : 0;
+       int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0;
 
-       int idx_alname = 2 + ipv6 + prefix;
+       int idx_alname = 2 + prefix;
        int idx_disttype = idx_alname + 1;
+       enum distribute_type type =
+               argv[idx_disttype]->arg[0] == 'i' ?
+               DISTRIBUTE_V4_IN : DISTRIBUTE_V4_OUT;
 
-       /* Check of distribute list type. */
-       enum distribute_type distin =
-               (ipv6) ? DISTRIBUTE_V6_IN : DISTRIBUTE_V4_IN;
-       enum distribute_type distout =
-               (ipv6) ? DISTRIBUTE_V6_OUT : DISTRIBUTE_V4_OUT;
+       /* Set appropriate function call */
+       int (*distfn)(const char *, enum distribute_type,
+                     const char *) =
+               prefix ? &distribute_list_prefix_unset : &distribute_list_unset;
+
+       /* if interface is present, get name */
+       const char *ifname = NULL;
+       if (argv[argc - 1]->type == VARIABLE_TKN)
+               ifname = argv[argc - 1]->arg;
+       /* Get interface name corresponding distribute list. */
+       int ret = distfn(ifname, type, argv[2 + prefix]->arg);
+
+       if (!ret) {
+               vty_out(vty, "distribute list doesn't exist\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+       return CMD_SUCCESS;
+}
+
+DEFUN (no_ipv6_distribute_list,
+       no_ipv6_distribute_list_cmd,
+       "no ipv6 distribute-list [prefix] WORD <in|out> [WORD]",
+       NO_STR
+       "IPv6\n"
+       "Filter networks in routing updates\n"
+       "Specify a prefix\n"
+       "Access-list name\n"
+       "Filter incoming routing updates\n"
+       "Filter outgoing routing updates\n"
+       "Interface name\n")
+{
+       int prefix = (argv[3]->type == WORD_TKN) ? 1 : 0;
+
+       int idx_alname = 3 + prefix;
+       int idx_disttype = idx_alname + 1;
 
        enum distribute_type type =
-               argv[idx_disttype]->arg[0] == 'i' ? distin : distout;
+               argv[idx_disttype]->arg[0] == 'i' ?
+               DISTRIBUTE_V6_IN : DISTRIBUTE_V6_OUT;
 
        /* Set appropriate function call */
        int (*distfn)(const char *, enum distribute_type, const char *) =
@@ -338,14 +369,15 @@ DEFUN (no_distribute_list,
 
        /* if interface is present, get name */
        const char *ifname = NULL;
+
        if (argv[argc - 1]->type == VARIABLE_TKN)
                ifname = argv[argc - 1]->arg;
        /* Get interface name corresponding distribute list. */
-       int ret = distfn(ifname, type, argv[2 + prefix]->arg);
+       int ret = distfn(ifname, type, argv[3 + prefix]->arg);
 
        if (!ret) {
-               vty_out(vty, "distribute list doesn't exist%s", VTY_NEWLINE);
-               return CMD_WARNING;
+               vty_out(vty, "distribute list doesn't exist\n");
+               return CMD_WARNING_CONFIG_FAILED;
        }
        return CMD_SUCCESS;
 }
@@ -383,9 +415,9 @@ int config_show_distribute(struct vty *vty)
                                             DISTRIBUTE_V6_OUT, has_print);
        }
        if (has_print)
-               vty_out(vty, "%s", VTY_NEWLINE);
+               vty_out(vty, "\n");
        else
-               vty_out(vty, " not set%s", VTY_NEWLINE);
+               vty_out(vty, " not set\n");
 
        for (i = 0; i < disthash->size; i++)
                for (mp = disthash->index[i]; mp; mp = mp->next) {
@@ -407,9 +439,9 @@ int config_show_distribute(struct vty *vty)
                                        vty, dist->prefix, 1, DISTRIBUTE_V6_OUT,
                                        has_print);
                                if (has_print)
-                                       vty_out(vty, "%s", VTY_NEWLINE);
+                                       vty_out(vty, "\n");
                                else
-                                       vty_out(vty, " nothing%s", VTY_NEWLINE);
+                                       vty_out(vty, " nothing\n");
                        }
                }
 
@@ -429,9 +461,9 @@ int config_show_distribute(struct vty *vty)
                                             DISTRIBUTE_V6_IN, has_print);
        }
        if (has_print)
-               vty_out(vty, "%s", VTY_NEWLINE);
+               vty_out(vty, "\n");
        else
-               vty_out(vty, " not set%s", VTY_NEWLINE);
+               vty_out(vty, " not set\n");
 
        for (i = 0; i < disthash->size; i++)
                for (mp = disthash->index[i]; mp; mp = mp->next) {
@@ -453,9 +485,9 @@ int config_show_distribute(struct vty *vty)
                                        vty, dist->prefix, 1, DISTRIBUTE_V6_IN,
                                        has_print);
                                if (has_print)
-                                       vty_out(vty, "%s", VTY_NEWLINE);
+                                       vty_out(vty, "\n");
                                else
-                                       vty_out(vty, " nothing%s", VTY_NEWLINE);
+                                       vty_out(vty, " nothing\n");
                        }
                }
        return 0;
@@ -483,13 +515,12 @@ int config_write_distribute(struct vty *vty)
                                        v6 = j == DISTRIBUTE_V6_IN
                                             || j == DISTRIBUTE_V6_OUT;
                                        vty_out(vty,
-                                               " %sdistribute-list %s %s %s%s",
+                                               " %sdistribute-list %s %s %s\n",
                                                v6 ? "ipv6 " : "",
                                                dist->list[j],
                                                output ? "out" : "in",
                                                dist->ifname ? dist->ifname
-                                                            : "",
-                                               VTY_NEWLINE);
+                                                            : "");
                                        write++;
                                }
 
@@ -500,13 +531,12 @@ int config_write_distribute(struct vty *vty)
                                        v6 = j == DISTRIBUTE_V6_IN
                                             || j == DISTRIBUTE_V6_OUT;
                                        vty_out(vty,
-                                               " %sdistribute-list prefix %s %s %s%s",
+                                               " %sdistribute-list prefix %s %s %s\n",
                                                v6 ? "ipv6 " : "",
                                                dist->prefix[j],
                                                output ? "out" : "in",
                                                dist->ifname ? dist->ifname
-                                                            : "",
-                                               VTY_NEWLINE);
+                                                            : "");
                                        write++;
                                }
                }
@@ -524,7 +554,7 @@ void distribute_list_init(int node)
 {
        disthash = hash_create(
                distribute_hash_make,
-               (int (*)(const void *, const void *))distribute_cmp);
+               (bool (*)(const void *, const void *))distribute_cmp, NULL);
 
        /* vtysh command-extraction doesn't grok install_element(node, ) */
        if (node == RIP_NODE) {
@@ -538,6 +568,7 @@ void distribute_list_init(int node)
        /* install v6 */
        if (node == RIPNG_NODE) {
                install_element(RIPNG_NODE, &ipv6_distribute_list_cmd);
+               install_element(RIPNG_NODE, &no_ipv6_distribute_list_cmd);
        }
 
        /* TODO: install v4 syntax command for v6 only protocols. */