quagga: Remove iflist global variable

The file if.c has a iflist that had the list of interfaces
in the default vrf.  Remove this variable and replace
with a vrf_iflist lookup on the default vrf where it
was used.

Additionally, modify ptm code to iterate over all vrf's
when enabling ptm.

Ticket: CM-10338
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: Radhika Mahankali <radhika@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2016-04-08 09:16:14 -04:00
parent 79694123fd
commit b2d7c082a2
17 changed files with 98 additions and 95 deletions

View File

@ -32,6 +32,7 @@
#include "log.h"
#include "memory.h"
#include "vrf.h"
#include "if.h"
#include "linklist.h"
#include "command.h"
@ -1024,7 +1025,7 @@ isis_interface_config_write (struct vty *vty)
struct isis_circuit *circuit;
int i;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
if (ifp->ifindex == IFINDEX_DELETED)
continue;

View File

@ -38,7 +38,6 @@
#include "log.h"
/* List of interfaces in only the default VRF */
struct list *iflist;
int ptm_enable = 0;
/* One for each program. This structure is needed to store hooks. */
@ -1261,7 +1260,7 @@ ifaddr_ipv4_lookup (struct in_addr *addr, unsigned int ifindex)
/* Initialize interface list. */
void
if_init (vrf_id_t vrf_id, struct list **intf_list)
if_init (struct list **intf_list)
{
*intf_list = list_new ();
#if 0
@ -1269,13 +1268,10 @@ if_init (vrf_id_t vrf_id, struct list **intf_list)
#endif /* ifaddr_ipv4_table */
(*intf_list)->cmp = (int (*)(void *, void *))if_cmp_func;
if (vrf_id == VRF_DEFAULT)
iflist = *intf_list;
}
void
if_terminate (vrf_id_t vrf_id, struct list **intf_list)
if_terminate (struct list **intf_list)
{
for (;;)
{
@ -1290,7 +1286,4 @@ if_terminate (vrf_id_t vrf_id, struct list **intf_list)
list_delete (*intf_list);
*intf_list = NULL;
if (vrf_id == VRF_DEFAULT)
iflist = NULL;
}

View File

@ -324,8 +324,8 @@ extern int if_is_broadcast (struct interface *);
extern int if_is_pointopoint (struct interface *);
extern int if_is_multicast (struct interface *);
extern void if_add_hook (int, int (*)(struct interface *));
extern void if_init (vrf_id_t, struct list **);
extern void if_terminate (vrf_id_t, struct list **);
extern void if_init (struct list **);
extern void if_terminate (struct list **);
extern void if_dump_all (void);
extern const char *if_flag_dump(unsigned long);
@ -364,7 +364,6 @@ extern char *if_indextoname (unsigned int, char *);
#endif
/* Exported variables. */
extern struct list *iflist;
extern struct cmd_element interface_desc_cmd;
extern struct cmd_element no_interface_desc_cmd;
extern struct cmd_element interface_cmd;

View File

@ -70,7 +70,7 @@ vrf_list_lookup_by_name (const char *name)
return NULL;
}
/* Create new interface structure. */
/* Create new vrf structure. */
struct vrf *
vrf_create (const char *name, size_t namelen)
{
@ -184,7 +184,7 @@ vrf_get (vrf_id_t vrf_id, const char *name)
vrf->node = rn;
/* Initialize interfaces. */
if_init (vrf_id, &vrf->iflist);
if_init (&vrf->iflist);
}
if (vrf_master.vrf_new_hook && name) {
@ -210,7 +210,7 @@ vrf_delete (struct vrf *vrf)
(*vrf_master.vrf_delete_hook) (vrf->vrf_id, vrf->name, &vrf->info);
if (CHECK_FLAG (vrf->status, VRF_ACTIVE))
if_terminate (vrf->vrf_id, &vrf->iflist);
if_terminate (&vrf->iflist);
if (vrf->node)
{
@ -491,7 +491,7 @@ vrf_iflist_create (vrf_id_t vrf_id)
{
struct vrf * vrf = vrf_lookup (vrf_id);
if (vrf && !vrf->iflist)
if_init (vrf_id, &vrf->iflist);
if_init (&vrf->iflist);
}
/* Free the interface list of the specified VRF. */
@ -500,7 +500,7 @@ vrf_iflist_terminate (vrf_id_t vrf_id)
{
struct vrf * vrf = vrf_lookup (vrf_id);
if (vrf && vrf->iflist)
if_terminate (vrf->vrf_id, &vrf->iflist);
if_terminate (&vrf->iflist);
}
/*

View File

@ -161,7 +161,7 @@ ospf6_bfd_nbr_replay (int command, struct zclient *zclient, zebra_size_t length,
bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER);
/* Replay the neighbor, if BFD is enabled on the interface*/
for (ALL_LIST_ELEMENTS_RO (iflist, inode, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), inode, ifp))
{
oi = (struct ospf6_interface *) ifp->info;

View File

@ -1009,7 +1009,7 @@ DEFUN (show_ipv6_ospf6_interface,
}
else
{
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, ifp))
ospf6_interface_show (vty, ifp);
}
@ -1102,7 +1102,7 @@ DEFUN (show_ipv6_ospf6_interface_prefix,
struct ospf6_interface *oi;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, ifp))
{
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
@ -1816,7 +1816,7 @@ config_write_ospf6_interface (struct vty *vty)
struct ospf6_interface *oi;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, ifp))
{
oi = (struct ospf6_interface *) ifp->info;
if (oi == NULL)
@ -1984,7 +1984,7 @@ DEFUN (clear_ipv6_ospf6_interface,
if (argc == 0) /* Clear all the ospfv3 interfaces. */
{
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ospf6_interface_clear (vty, ifp);
}
else /* Interface name is specified. */

View File

@ -145,7 +145,7 @@ ospf6_exit (int status)
if (ospf6)
ospf6_delete (ospf6);
for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
if (ifp->info != NULL)
ospf6_interface_delete(ifp->info);

View File

@ -1269,7 +1269,7 @@ void
ospf_if_init ()
{
/* Initialize Zebra interface data structure. */
om->iflist = iflist;
om->iflist = vrf_iflist (VRF_DEFAULT);
if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
}

View File

@ -33,6 +33,7 @@
#include "linklist.h"
#include "prefix.h"
#include "vrf.h"
#include "if.h"
#include "table.h"
#include "memory.h"
@ -1890,7 +1891,7 @@ DEFUN (show_mpls_te_link,
/* Show All Interfaces. */
if (argc == 0)
{
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
show_mpls_te_link_sub (vty, ifp);
}
/* Interface name is specified. */

View File

@ -3927,7 +3927,7 @@ show_ip_ospf_interface_common (struct vty *vty, struct ospf *ospf, int argc,
if (argc == (iface_argv + 1))
{
/* Show All Interfaces.*/
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
if (ospf_oi_count(ifp))
{
@ -3938,7 +3938,7 @@ show_ip_ospf_interface_common (struct vty *vty, struct ospf *ospf, int argc,
else if (argv[iface_argv] && strcmp(argv[iface_argv], "json") == 0)
{
/* Show All Interfaces. */
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
if (ospf_oi_count(ifp))
{
@ -9280,7 +9280,7 @@ config_write_interface (struct vty *vty)
struct ospf_if_params *params;
struct ospf *ospf = ospf_lookup();
for (ALL_LIST_ELEMENTS_RO (iflist, n1, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), n1, ifp))
{
if (memcmp (ifp->name, "VLINK", 5) == 0)
continue;
@ -10284,7 +10284,7 @@ DEFUN (clear_ip_ospf_interface,
if (argc == 0) /* Clear all the ospfv2 interfaces. */
{
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ospf_interface_clear(ifp);
}
else /* Interface name is specified. */

View File

@ -539,7 +539,7 @@ ospf_finish_final (struct ospf *ospf)
list_delete (ospf->vlinks);
/* Remove any ospf interface config params */
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
struct ospf_if_params *params;

View File

@ -357,7 +357,7 @@ if_check_address (struct in_addr addr)
struct listnode *node;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
struct listnode *cnode;
struct connected *connected;
@ -504,7 +504,7 @@ rip_interface_clean (void)
struct interface *ifp;
struct rip_interface *ri;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -527,7 +527,7 @@ rip_interface_reset (void)
struct interface *ifp;
struct rip_interface *ri;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -634,7 +634,7 @@ rip_if_down_all ()
struct interface *ifp;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
rip_if_down (ifp);
}
@ -1059,7 +1059,7 @@ rip_enable_apply_all ()
struct listnode *node, *nnode;
/* Check each interface. */
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
rip_enable_apply (ifp);
}
@ -1180,7 +1180,7 @@ rip_passive_interface_apply_all (void)
struct interface *ifp;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
rip_passive_interface_apply (ifp);
}
@ -1924,7 +1924,7 @@ rip_interface_config_write (struct vty *vty)
struct listnode *node;
struct interface *ifp;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
struct rip_interface *ri;

View File

@ -22,6 +22,7 @@
#include <zebra.h>
#include "vrf.h"
#include "if.h"
#include "command.h"
#include "prefix.h"
@ -343,7 +344,8 @@ rip_nexthop_check (struct in_addr *addr)
/* If nexthop address matches local configured address then it is
invalid nexthop. */
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, ifc))
{
@ -2477,7 +2479,7 @@ rip_update_process (int route_type)
struct prefix_ipv4 *p;
/* Send RIP update to each interface. */
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
if (if_is_loopback (ifp))
continue;
@ -3535,7 +3537,7 @@ DEFUN (show_ip_rip_status,
vty_out (vty, " Interface Send Recv Key-chain%s", VTY_NEWLINE);
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -3567,7 +3569,7 @@ DEFUN (show_ip_rip_status,
{
int found_passive = 0;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -3766,7 +3768,7 @@ rip_distribute_update_all (struct prefix_list *notused)
struct interface *ifp;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
rip_distribute_update_interface (ifp);
}
/* ARGSUSED */
@ -3957,7 +3959,7 @@ rip_routemap_update (const char *notused)
struct interface *ifp;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
rip_if_rmap_update_interface (ifp);
rip_routemap_update_redistribute ();

View File

@ -332,7 +332,7 @@ ripng_interface_clean (void)
struct interface *ifp;
struct ripng_interface *ri;
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp))
{
ri = ifp->info;
@ -355,7 +355,7 @@ ripng_interface_reset (void)
struct interface *ifp;
struct ripng_interface *ri;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -812,7 +812,7 @@ ripng_enable_apply_all (void)
struct interface *ifp;
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ripng_enable_apply (ifp);
}
@ -877,7 +877,7 @@ ripng_passive_interface_apply_all (void)
struct interface *ifp;
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ripng_passive_interface_apply (ifp);
}
@ -1148,7 +1148,7 @@ interface_config_write (struct vty *vty)
struct ripng_interface *ri;
int write = 0;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;

View File

@ -1449,7 +1449,7 @@ ripng_update (struct thread *t)
zlog_debug ("RIPng update timer expired!");
/* Supply routes to each interface. */
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -1532,7 +1532,7 @@ ripng_triggered_update (struct thread *t)
/* Split Horizon processing is done when generating triggered
updates as well as normal updates (see section 2.6). */
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
ri = ifp->info;
@ -2143,7 +2143,7 @@ DEFUN (show_ipv6_ripng_status,
vty_out (vty, " Interface Send Recv%s", VTY_NEWLINE);
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
{
struct ripng_interface *ri;
@ -2760,7 +2760,7 @@ ripng_distribute_update_all (struct prefix_list *notused)
struct interface *ifp;
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ripng_distribute_update_interface (ifp);
}
@ -2935,7 +2935,7 @@ ripng_routemap_update (const char *unused)
struct interface *ifp;
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
ripng_if_rmap_update_interface (ifp);
ripng_routemap_update_redistribute ();

View File

@ -310,25 +310,27 @@ void irdp_finish()
struct interface *ifp;
struct zebra_if *zi;
struct irdp_interface *irdp;
vrf_iter_t iter;
zlog_info("IRDP: Received shutdown notification.");
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
{
zi = ifp->info;
if (!zi)
continue;
irdp = &zi->irdp;
if (!irdp)
continue;
for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
for (ALL_LIST_ELEMENTS (vrf_iter2iflist (iter), node, nnode, ifp))
{
zi = ifp->info;
if (irdp->flags & IF_ACTIVE )
{
irdp->flags |= IF_SHUTDOWN;
irdp_advert_off(ifp);
}
}
if (!zi)
continue;
irdp = &zi->irdp;
if (!irdp)
continue;
if (irdp->flags & IF_ACTIVE )
{
irdp->flags |= IF_SHUTDOWN;
irdp_advert_off(ifp);
}
}
}
#endif /* HAVE_IRDP */

View File

@ -246,16 +246,18 @@ DEFUN (zebra_ptm_enable,
{
struct listnode *i;
struct interface *ifp;
vrf_iter_t iter;
ptm_cb.ptm_enable = 1;
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
if (!ifp->ptm_enable)
{
ifp->ptm_enable = 1;
/* Assign a default unknown status */
ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
}
for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), i, ifp))
if (!ifp->ptm_enable)
{
ifp->ptm_enable = 1;
/* Assign a default unknown status */
ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
}
zebra_ptm_connect(NULL);
@ -984,25 +986,28 @@ zebra_ptm_reset_status(int ptm_disable)
struct listnode *i;
struct interface *ifp;
int send_linkup;
vrf_iter_t iter;
for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
{
send_linkup = 0;
if (ifp->ptm_enable)
{
if (!if_is_operative(ifp))
send_linkup = 1;
for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), i, ifp))
{
send_linkup = 0;
if (ifp->ptm_enable)
{
if (!if_is_operative(ifp))
send_linkup = 1;
if (ptm_disable)
ifp->ptm_enable = 0;
ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
if (ptm_disable)
ifp->ptm_enable = 0;
ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
if (if_is_operative (ifp) && send_linkup) {
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug ("%s: Bringing up interface %s", __func__,
ifp->name);
if_up (ifp);
}
}
}
if (if_is_operative (ifp) && send_linkup)
{
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug ("%s: Bringing up interface %s", __func__,
ifp->name);
if_up (ifp);
}
}
}
}