diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2015-04-13 10:21:35 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2015-11-03 14:49:39 +0100 |
commit | c7da3d50b38b430494465c1ba0d68244bfd16d56 (patch) | |
tree | 26b658e9503e5786c6156d48c0bfe0411bd822e5 /lib | |
parent | lib: hide internal prefix list structures (diff) | |
download | frr-c7da3d50b38b430494465c1ba0d68244bfd16d56.tar.xz frr-c7da3d50b38b430494465c1ba0d68244bfd16d56.zip |
lib: straighten out ORF prefix list support
BGP ORF prefix lists are in a separate namespace; this was previously
hooked up with a special-purpose AFI value. This is a little kludgy for
extension, hence this splits it off.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/plist.c | 149 | ||||
-rw-r--r-- | lib/plist.h | 5 |
2 files changed, 53 insertions, 101 deletions
diff --git a/lib/plist.c b/lib/plist.c index 0174a53fe..7a356dffb 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -86,7 +86,17 @@ static struct prefix_master prefix_master_ipv6 = #endif /* HAVE_IPV6*/ /* Static structure of BGP ORF prefix_list's master. */ -static struct prefix_master prefix_master_orf = +static struct prefix_master prefix_master_orf_v4 = +{ + {NULL, NULL}, + {NULL, NULL}, + 1, + NULL, + NULL, +}; + +/* Static structure of BGP ORF prefix_list's master. */ +static struct prefix_master prefix_master_orf_v6 = { {NULL, NULL}, {NULL, NULL}, @@ -96,16 +106,12 @@ static struct prefix_master prefix_master_orf = }; static struct prefix_master * -prefix_master_get (afi_t afi) +prefix_master_get (afi_t afi, int orf) { if (afi == AFI_IP) - return &prefix_master_ipv4; -#ifdef HAVE_IPV6 - else if (afi == AFI_IP6) - return &prefix_master_ipv6; -#endif /* HAVE_IPV6 */ - else if (afi == AFI_ORF_PREFIX) - return &prefix_master_orf; + return orf ? &prefix_master_orf_v4 : &prefix_master_ipv4; + if (afi == AFI_IP6) + return orf ? &prefix_master_orf_v6 : &prefix_master_ipv6; return NULL; } @@ -115,8 +121,8 @@ const char *prefix_list_name (struct prefix_list *plist) } /* Lookup prefix_list from list of prefix_list by name. */ -struct prefix_list * -prefix_list_lookup (afi_t afi, const char *name) +static struct prefix_list * +prefix_list_lookup_do (afi_t afi, int orf, const char *name) { struct prefix_list *plist; struct prefix_master *master; @@ -124,7 +130,7 @@ prefix_list_lookup (afi_t afi, const char *name) if (name == NULL) return NULL; - master = prefix_master_get (afi); + master = prefix_master_get (afi, orf); if (master == NULL) return NULL; @@ -139,6 +145,18 @@ prefix_list_lookup (afi_t afi, const char *name) return NULL; } +struct prefix_list * +prefix_list_lookup (afi_t afi, const char *name) +{ + return prefix_list_lookup_do (afi, 0, name); +} + +struct prefix_list * +prefix_bgp_orf_lookup (afi_t afi, const char *name) +{ + return prefix_list_lookup_do (afi, 1, name); +} + static struct prefix_list * prefix_list_new (void) { @@ -172,7 +190,7 @@ prefix_list_entry_free (struct prefix_list_entry *pentry) /* Insert new prefix list to list of prefix_list. Each prefix_list is sorted by the name. */ static struct prefix_list * -prefix_list_insert (afi_t afi, const char *name) +prefix_list_insert (afi_t afi, int orf, const char *name) { unsigned int i; long number; @@ -181,7 +199,7 @@ prefix_list_insert (afi_t afi, const char *name) struct prefix_list_list *list; struct prefix_master *master; - master = prefix_master_get (afi); + master = prefix_master_get (afi, orf); if (master == NULL) return NULL; @@ -262,14 +280,14 @@ prefix_list_insert (afi_t afi, const char *name) } static struct prefix_list * -prefix_list_get (afi_t afi, const char *name) +prefix_list_get (afi_t afi, int orf, const char *name) { struct prefix_list *plist; - plist = prefix_list_lookup (afi, name); + plist = prefix_list_lookup_do (afi, orf, name); if (plist == NULL) - plist = prefix_list_insert (afi, name); + plist = prefix_list_insert (afi, orf, name); return plist; } @@ -740,7 +758,7 @@ vty_prefix_list_install (struct vty *vty, afi_t afi, const char *name, lenum = 0; /* Get prefix_list with name. */ - plist = prefix_list_get (afi, name); + plist = prefix_list_get (afi, 0, name); /* Make prefix entry. */ pentry = prefix_list_entry_make (&p, type, seqnum, lenum, genum, any); @@ -995,7 +1013,7 @@ vty_show_prefix_list (struct vty *vty, afi_t afi, const char *name, struct prefix_master *master; int seqnum = 0; - master = prefix_master_get (afi); + master = prefix_master_get (afi, 0); if (master == NULL) return CMD_WARNING; @@ -1113,7 +1131,7 @@ vty_clear_prefix_list (struct vty *vty, afi_t afi, const char *name, int ret; struct prefix p; - master = prefix_master_get (afi); + master = prefix_master_get (afi, 0); if (master == NULL) return CMD_WARNING; @@ -1568,7 +1586,7 @@ DEFUN (ip_prefix_list_description, { struct prefix_list *plist; - plist = prefix_list_get (AFI_IP, argv[0]); + plist = prefix_list_get (AFI_IP, 0, argv[0]); if (plist->desc) { @@ -2164,7 +2182,7 @@ DEFUN (ipv6_prefix_list_description, { struct prefix_list *plist; - plist = prefix_list_get (AFI_IP6, argv[0]); + plist = prefix_list_get (AFI_IP6, 0, argv[0]); if (plist->desc) { @@ -2359,7 +2377,7 @@ config_write_prefix_afi (afi_t afi, struct vty *vty) struct prefix_master *master; int write = 0; - master = prefix_master_get (afi); + master = prefix_master_get (afi, 0); if (master == NULL) return 0; @@ -2502,7 +2520,7 @@ prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp, if (orfp->ge && orfp->le == (afi == AFI_IP ? 32 : 128)) orfp->le = 0; - plist = prefix_list_get (AFI_ORF_PREFIX, name); + plist = prefix_list_get (afi, 1, name); if (! plist) return CMD_WARNING; @@ -2536,11 +2554,11 @@ prefix_bgp_orf_set (char *name, afi_t afi, struct orf_prefix *orfp, } void -prefix_bgp_orf_remove_all (char *name) +prefix_bgp_orf_remove_all (afi_t afi, char *name) { struct prefix_list *plist; - plist = prefix_list_lookup (AFI_ORF_PREFIX, name); + plist = prefix_bgp_orf_lookup (afi, name); if (plist) prefix_list_delete (plist); } @@ -2555,7 +2573,7 @@ prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name, u_char use_ json_object *json_prefix = NULL; json_object *json_list = NULL; - plist = prefix_list_lookup (AFI_ORF_PREFIX, name); + plist = prefix_bgp_orf_lookup (afi, name); if (! plist) return 0; @@ -2626,13 +2644,13 @@ prefix_bgp_show_prefix_list (struct vty *vty, afi_t afi, char *name, u_char use_ } static void -prefix_list_reset_orf (void) +prefix_list_reset_afi (afi_t afi, int orf) { struct prefix_list *plist; struct prefix_list *next; struct prefix_master *master; - master = prefix_master_get (AFI_ORF_PREFIX); + master = prefix_master_get (afi, orf); if (master == NULL) return; @@ -2673,38 +2691,6 @@ config_write_prefix_ipv4 (struct vty *vty) } static void -prefix_list_reset_ipv4 (void) -{ - struct prefix_list *plist; - struct prefix_list *next; - struct prefix_master *master; - - master = prefix_master_get (AFI_IP); - if (master == NULL) - return; - - for (plist = master->num.head; plist; plist = next) - { - next = plist->next; - prefix_list_delete (plist); - } - for (plist = master->str.head; plist; plist = next) - { - next = plist->next; - prefix_list_delete (plist); - } - - assert (master->num.head == NULL); - assert (master->num.tail == NULL); - - assert (master->str.head == NULL); - assert (master->str.tail == NULL); - - master->seqnum = 1; - master->recent = NULL; -} - -static void prefix_list_init_ipv4 (void) { install_node (&prefix_node, config_write_prefix_ipv4); @@ -2782,38 +2768,6 @@ config_write_prefix_ipv6 (struct vty *vty) } static void -prefix_list_reset_ipv6 (void) -{ - struct prefix_list *plist; - struct prefix_list *next; - struct prefix_master *master; - - master = prefix_master_get (AFI_IP6); - if (master == NULL) - return; - - for (plist = master->num.head; plist; plist = next) - { - next = plist->next; - prefix_list_delete (plist); - } - for (plist = master->str.head; plist; plist = next) - { - next = plist->next; - prefix_list_delete (plist); - } - - assert (master->num.head == NULL); - assert (master->num.tail == NULL); - - assert (master->str.head == NULL); - assert (master->str.tail == NULL); - - master->seqnum = 1; - master->recent = NULL; -} - -static void prefix_list_init_ipv6 (void) { install_node (&prefix_ipv6_node, config_write_prefix_ipv6); @@ -2888,9 +2842,8 @@ prefix_list_init () void prefix_list_reset () { - prefix_list_reset_ipv4 (); -#ifdef HAVE_IPV6 - prefix_list_reset_ipv6 (); -#endif /* HAVE_IPV6 */ - prefix_list_reset_orf (); + prefix_list_reset_afi (AFI_IP, 0); + prefix_list_reset_afi (AFI_IP6, 0); + prefix_list_reset_afi (AFI_IP, 1); + prefix_list_reset_afi (AFI_IP6, 1); } diff --git a/lib/plist.h b/lib/plist.h index cfc43c781..2c6f13a5c 100644 --- a/lib/plist.h +++ b/lib/plist.h @@ -23,8 +23,6 @@ #ifndef _QUAGGA_PLIST_H #define _QUAGGA_PLIST_H -#define AFI_ORF_PREFIX 65535 - enum prefix_list_type { PREFIX_DENY, @@ -51,11 +49,12 @@ extern const char *prefix_list_name (struct prefix_list *); extern struct prefix_list *prefix_list_lookup (afi_t, const char *); extern enum prefix_list_type prefix_list_apply (struct prefix_list *, void *); +extern struct prefix_list *prefix_bgp_orf_lookup (afi_t, const char *); extern struct stream * prefix_bgp_orf_entry (struct stream *, struct prefix_list *, u_char, u_char, u_char); extern int prefix_bgp_orf_set (char *, afi_t, struct orf_prefix *, int, int); -extern void prefix_bgp_orf_remove_all (char *); +extern void prefix_bgp_orf_remove_all (afi_t, char *); extern int prefix_bgp_show_prefix_list (struct vty *, afi_t, char *, u_char); #endif /* _QUAGGA_PLIST_H */ |