123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020 |
- /* Distribute list functions
- * Copyright (C) 1998, 1999 Kunihiro Ishiguro
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * 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.
- */
- #include <zebra.h>
- #include "hash.h"
- #include "if.h"
- #include "filter.h"
- #include "command.h"
- #include "distribute.h"
- #include "memory.h"
- /* Hash of distribute list. */
- struct hash *disthash;
- /* Hook functions. */
- void (*distribute_add_hook) (struct distribute *);
- void (*distribute_delete_hook) (struct distribute *);
- static struct distribute *
- distribute_new (void)
- {
- return XCALLOC (MTYPE_DISTRIBUTE, sizeof (struct distribute));
- }
- /* Free distribute object. */
- static void
- distribute_free (struct distribute *dist)
- {
- int i = 0;
- if (dist->ifname)
- XFREE (MTYPE_DISTRIBUTE_IFNAME, dist->ifname);
- for (i=0; i < DISTRIBUTE_MAX; i++)
- if (dist->list[i])
- free(dist->list[i]);
- for (i=0; i < DISTRIBUTE_MAX; i++)
- if (dist->prefix[i])
- free(dist->prefix[i]);
- XFREE (MTYPE_DISTRIBUTE, dist);
- }
- static void
- distribute_free_if_empty(struct distribute *dist)
- {
- int i;
- for (i=0; i < DISTRIBUTE_MAX; i++)
- if (dist->list[i] != NULL || dist->prefix[i] != NULL)
- return;
- hash_release (disthash, dist);
- distribute_free (dist);
- }
- /* Lookup interface's distribute list. */
- struct distribute *
- distribute_lookup (const char *ifname)
- {
- struct distribute key;
- struct distribute *dist;
- /* temporary reference */
- key.ifname = (char *)ifname;
- dist = hash_lookup (disthash, &key);
-
- return dist;
- }
- void
- distribute_list_add_hook (void (*func) (struct distribute *))
- {
- distribute_add_hook = func;
- }
- void
- distribute_list_delete_hook (void (*func) (struct distribute *))
- {
- distribute_delete_hook = func;
- }
- static void *
- distribute_hash_alloc (struct distribute *arg)
- {
- struct distribute *dist;
- dist = distribute_new ();
- if (arg->ifname)
- dist->ifname = XSTRDUP (MTYPE_DISTRIBUTE_IFNAME, arg->ifname);
- else
- dist->ifname = NULL;
- return dist;
- }
- /* Make new distribute list and push into hash. */
- static struct distribute *
- distribute_get (const char *ifname)
- {
- struct distribute key;
- /* temporary reference */
- key.ifname = (char *)ifname;
-
- return hash_get (disthash, &key, (void * (*) (void *))distribute_hash_alloc);
- }
- static unsigned int
- distribute_hash_make (void *arg)
- {
- const struct distribute *dist = arg;
- return dist->ifname ? string_hash_make (dist->ifname) : 0;
- }
- /* 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, const struct distribute *dist2)
- {
- if (dist1->ifname && dist2->ifname)
- if (strcmp (dist1->ifname, dist2->ifname) == 0)
- return 1;
- if (! dist1->ifname && ! dist2->ifname)
- return 1;
- return 0;
- }
- /* Set access-list name to the distribute list. */
- static struct distribute *
- distribute_list_set (const char *ifname, enum distribute_type type,
- const char *alist_name)
- {
- struct distribute *dist;
- dist = distribute_get (ifname);
- if (dist->list[type])
- free (dist->list[type]);
- dist->list[type] = strdup (alist_name);
- /* Apply this distribute-list to the interface. */
- (*distribute_add_hook) (dist);
- return dist;
- }
- /* Unset distribute-list. If matched distribute-list exist then
- return 1. */
- static int
- distribute_list_unset (const char *ifname, enum distribute_type type,
- const char *alist_name)
- {
- struct distribute *dist;
- dist = distribute_lookup (ifname);
- if (!dist)
- return 0;
- if (!dist->list[type])
- return 0;
- if (strcmp (dist->list[type], alist_name) != 0)
- return 0;
- free (dist->list[type]);
- dist->list[type] = NULL;
- /* Apply this distribute-list to the interface. */
- (*distribute_delete_hook) (dist);
- /* If all dist are NULL, then free distribute list. */
- distribute_free_if_empty(dist);
- return 1;
- }
- /* Set access-list name to the distribute list. */
- static struct distribute *
- distribute_list_prefix_set (const char *ifname, enum distribute_type type,
- const char *plist_name)
- {
- struct distribute *dist;
- dist = distribute_get (ifname);
- if (dist->prefix[type])
- free (dist->prefix[type]);
- dist->prefix[type] = strdup (plist_name);
- /* Apply this distribute-list to the interface. */
- (*distribute_add_hook) (dist);
-
- return dist;
- }
- /* Unset distribute-list. If matched distribute-list exist then
- return 1. */
- static int
- distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
- const char *plist_name)
- {
- struct distribute *dist;
- dist = distribute_lookup (ifname);
- if (!dist)
- return 0;
- if (!dist->prefix[type])
- return 0;
- if (strcmp (dist->prefix[type], plist_name) != 0)
- return 0;
- free (dist->prefix[type]);
- dist->prefix[type] = NULL;
- /* Apply this distribute-list to the interface. */
- (*distribute_delete_hook) (dist);
- /* If all dist are NULL, then free distribute list. */
- distribute_free_if_empty(dist);
- return 1;
- }
- DEFUN (distribute_list_all,
- distribute_list_all_cmd,
- "distribute-list WORD (in|out)",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_set (NULL, type, argv[0]);
- return CMD_SUCCESS;
- }
- DEFUN (ipv6_distribute_list_all,
- ipv6_distribute_list_all_cmd,
- "ipv6 distribute-list WORD (in|out)",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_set (NULL, type, argv[0]);
- return CMD_SUCCESS;
- }
- ALIAS (ipv6_distribute_list_all,
- ipv6_as_v4_distribute_list_all_cmd,
- "distribute-list WORD (in|out)",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- DEFUN (no_distribute_list_all,
- no_distribute_list_all_cmd,
- "no distribute-list WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- DEFUN (no_ipv6_distribute_list_all,
- no_ipv6_distribute_list_all_cmd,
- "no ipv6 distribute-list WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- ALIAS (no_ipv6_distribute_list_all,
- no_ipv6_as_v4_distribute_list_all_cmd,
- "no distribute-list WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- DEFUN (distribute_list,
- distribute_list_cmd,
- "distribute-list WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_set (argv[2], type, argv[0]);
- return CMD_SUCCESS;
- }
- DEFUN (ipv6_distribute_list,
- ipv6_distribute_list_cmd,
- "ipv6 distribute-list WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_set (argv[2], type, argv[0]);
- return CMD_SUCCESS;
- }
- ALIAS (ipv6_distribute_list,
- ipv6_as_v4_distribute_list_cmd,
- "distribute-list WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- DEFUN (no_distribute_list, no_distribute_list_cmd,
- "no distribute-list WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- DEFUN (no_ipv6_distribute_list,
- no_ipv6_distribute_list_cmd,
- "no ipv6 distribute-list WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- ALIAS (no_ipv6_distribute_list,
- no_ipv6_as_v4_distribute_list_cmd,
- "no distribute-list WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Access-list name\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- DEFUN (distribute_list_prefix_all,
- distribute_list_prefix_all_cmd,
- "distribute-list prefix WORD (in|out)",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (NULL, type, argv[0]);
- return CMD_SUCCESS;
- }
- DEFUN (ipv6_distribute_list_prefix_all,
- ipv6_distribute_list_prefix_all_cmd,
- "ipv6 distribute-list prefix WORD (in|out)",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (NULL, type, argv[0]);
- return CMD_SUCCESS;
- }
- ALIAS (ipv6_distribute_list_prefix_all,
- ipv6_as_v4_distribute_list_prefix_all_cmd,
- "distribute-list prefix WORD (in|out)",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- DEFUN (no_distribute_list_prefix_all,
- no_distribute_list_prefix_all_cmd,
- "no distribute-list prefix WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_prefix_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- DEFUN (no_ipv6_distribute_list_prefix_all,
- no_ipv6_distribute_list_prefix_all_cmd,
- "no ipv6 distribute-list prefix WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_prefix_unset (NULL, type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- ALIAS (no_ipv6_distribute_list_prefix_all,
- no_ipv6_as_v4_distribute_list_prefix_all_cmd,
- "no distribute-list prefix WORD (in|out)",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n")
- DEFUN (distribute_list_prefix, distribute_list_prefix_cmd,
- "distribute-list prefix WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (argv[2], type, argv[0]);
- return CMD_SUCCESS;
- }
- DEFUN (ipv6_distribute_list_prefix,
- ipv6_distribute_list_prefix_cmd,
- "ipv6 distribute-list prefix WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- /* Get interface name corresponding distribute list. */
- distribute_list_prefix_set (argv[2], type, argv[0]);
- return CMD_SUCCESS;
- }
- ALIAS (ipv6_distribute_list_prefix,
- ipv6_as_v4_distribute_list_prefix_cmd,
- "distribute-list prefix WORD (in|out) WORD",
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- DEFUN (no_distribute_list_prefix, no_distribute_list_prefix_cmd,
- "no distribute-list prefix WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V4_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V4_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- DEFUN (no_ipv6_distribute_list_prefix,
- no_ipv6_distribute_list_prefix_cmd,
- "no ipv6 distribute-list prefix WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- {
- int ret;
- enum distribute_type type;
- /* Check of distribute list type. */
- if (strncmp (argv[1], "i", 1) == 0)
- type = DISTRIBUTE_V6_IN;
- else if (strncmp (argv[1], "o", 1) == 0)
- type = DISTRIBUTE_V6_OUT;
- else
- {
- vty_out (vty, "distribute list direction must be [in|out]%s",
- VTY_NEWLINE);
- return CMD_WARNING;
- }
- ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
- if (! ret)
- {
- vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
- return CMD_SUCCESS;
- }
- ALIAS (no_ipv6_distribute_list_prefix,
- no_ipv6_as_v4_distribute_list_prefix_cmd,
- "no distribute-list prefix WORD (in|out) WORD",
- NO_STR
- "Filter networks in routing updates\n"
- "Filter prefixes in routing updates\n"
- "Name of an IP prefix-list\n"
- "Filter incoming routing updates\n"
- "Filter outgoing routing updates\n"
- "Interface name\n")
- static int
- distribute_print (struct vty *vty, char *tab[], int is_prefix,
- enum distribute_type type, int has_print)
- {
- if (tab[type]) {
- vty_out (vty, "%s %s%s",
- has_print ? "," : "",
- is_prefix ? "(prefix-list) " : "",
- tab[type]);
- return 1;
- }
- return has_print;
- }
- int
- config_show_distribute (struct vty *vty)
- {
- unsigned int i;
- int has_print = 0;
- struct hash_backet *mp;
- struct distribute *dist;
- /* Output filter configuration. */
- dist = distribute_lookup (NULL);
- vty_out(vty, " Outgoing update filter list for all interface is");
- has_print = 0;
- if (dist)
- {
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V4_OUT, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V4_OUT, has_print);
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V6_OUT, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V6_OUT, has_print);
- }
- if (has_print)
- vty_out (vty, "%s", VTY_NEWLINE);
- else
- vty_out (vty, " not set%s", VTY_NEWLINE);
- for (i = 0; i < disthash->size; i++)
- for (mp = disthash->index[i]; mp; mp = mp->next)
- {
- dist = mp->data;
- if (dist->ifname)
- {
- vty_out (vty, " %s filtered by", dist->ifname);
- has_print = 0;
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V4_OUT, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V4_OUT, has_print);
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V6_OUT, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V6_OUT, has_print);
- if (has_print)
- vty_out (vty, "%s", VTY_NEWLINE);
- else
- vty_out(vty, " nothing%s", VTY_NEWLINE);
- }
- }
- /* Input filter configuration. */
- dist = distribute_lookup (NULL);
- vty_out(vty, " Incoming update filter list for all interface is");
- has_print = 0;
- if (dist)
- {
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V4_IN, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V4_IN, has_print);
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V6_IN, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V6_IN, has_print);
- }
- if (has_print)
- vty_out (vty, "%s", VTY_NEWLINE);
- else
- vty_out (vty, " not set%s", VTY_NEWLINE);
- for (i = 0; i < disthash->size; i++)
- for (mp = disthash->index[i]; mp; mp = mp->next)
- {
- dist = mp->data;
- if (dist->ifname)
- {
- vty_out (vty, " %s filtered by", dist->ifname);
- has_print = 0;
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V4_IN, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V4_IN, has_print);
- has_print = distribute_print(vty, dist->list, 0,
- DISTRIBUTE_V6_IN, has_print);
- has_print = distribute_print(vty, dist->prefix, 1,
- DISTRIBUTE_V6_IN, has_print);
- if (has_print)
- vty_out (vty, "%s", VTY_NEWLINE);
- else
- vty_out(vty, " nothing%s", VTY_NEWLINE);
- }
- }
- return 0;
- }
- /* Configuration write function. */
- int
- config_write_distribute (struct vty *vty)
- {
- unsigned int i;
- int j;
- int output, v6;
- struct hash_backet *mp;
- int write = 0;
- for (i = 0; i < disthash->size; i++)
- for (mp = disthash->index[i]; mp; mp = mp->next)
- {
- struct distribute *dist;
- dist = mp->data;
- for (j=0; j < DISTRIBUTE_MAX; j++)
- if (dist->list[j]) {
- output = j == DISTRIBUTE_V4_OUT || j == DISTRIBUTE_V6_OUT;
- v6 = j == DISTRIBUTE_V6_IN || j == DISTRIBUTE_V6_OUT;
- vty_out (vty, " %sdistribute-list %s %s %s%s",
- v6 ? "ipv6 " : "",
- dist->list[j],
- output ? "out" : "in",
- dist->ifname ? dist->ifname : "",
- VTY_NEWLINE);
- write++;
- }
- for (j=0; j < DISTRIBUTE_MAX; j++)
- if (dist->prefix[j]) {
- output = j == DISTRIBUTE_V4_OUT || j == DISTRIBUTE_V6_OUT;
- v6 = j == DISTRIBUTE_V6_IN || j == DISTRIBUTE_V6_OUT;
- vty_out (vty, " %sdistribute-list prefix %s %s %s%s",
- v6 ? "ipv6 " : "",
- dist->prefix[j],
- output ? "out" : "in",
- dist->ifname ? dist->ifname : "",
- VTY_NEWLINE);
- write++;
- }
- }
- return write;
- }
- /* Clear all distribute list. */
- void
- distribute_list_reset ()
- {
- hash_clean (disthash, (void (*) (void *)) distribute_free);
- }
- /* Initialize distribute list related hash. */
- void
- distribute_list_init (int node)
- {
- disthash = hash_create (distribute_hash_make,
- (int (*) (const void *, const void *)) distribute_cmp);
- /* install v4 */
- if (node == RIP_NODE || node == BABEL_NODE) {
- install_element (node, &distribute_list_all_cmd);
- install_element (node, &no_distribute_list_all_cmd);
- install_element (node, &distribute_list_cmd);
- install_element (node, &no_distribute_list_cmd);
- install_element (node, &distribute_list_prefix_all_cmd);
- install_element (node, &no_distribute_list_prefix_all_cmd);
- install_element (node, &distribute_list_prefix_cmd);
- install_element (node, &no_distribute_list_prefix_cmd);
- }
- /* install v6 */
- if (node == RIPNG_NODE || node == BABEL_NODE) {
- install_element (node, &ipv6_distribute_list_all_cmd);
- install_element (node, &no_ipv6_distribute_list_all_cmd);
- install_element (node, &ipv6_distribute_list_cmd);
- install_element (node, &no_ipv6_distribute_list_cmd);
- install_element (node, &ipv6_distribute_list_prefix_all_cmd);
- install_element (node, &no_ipv6_distribute_list_prefix_all_cmd);
- install_element (node, &ipv6_distribute_list_prefix_cmd);
- install_element (node, &no_ipv6_distribute_list_prefix_cmd);
- }
- /* install v4 syntax command for v6 only protocols. */
- if (node == RIPNG_NODE) {
- install_element (node, &ipv6_as_v4_distribute_list_all_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_all_cmd);
- install_element (node, &ipv6_as_v4_distribute_list_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_cmd);
- install_element (node, &ipv6_as_v4_distribute_list_prefix_all_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_prefix_all_cmd);
- install_element (node, &ipv6_as_v4_distribute_list_prefix_cmd);
- install_element (node, &no_ipv6_as_v4_distribute_list_prefix_cmd);
- }
- }
|