From f65b8886cc94cce3afef3e199b538a4263947f09 Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Sun, 29 Nov 2009 11:08:38 +0000 Subject: ospfd: replace route_nodes with a list It is wasteful to use route nodes for something as simple as a neighbor list. Replace with a list. --- ospfd/ospf_ism.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'ospfd/ospf_ism.c') diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index 18402836..e7bdbf2c 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -163,38 +163,36 @@ ospf_ism_state (struct ospf_interface *oi) } static void -ospf_dr_eligible_routers (struct route_table *nbrs, struct list *el_list) +ospf_dr_eligible_routers (struct list *nbrs, struct list *el_list) { - struct route_node *rn; + struct listnode *node; struct ospf_neighbor *nbr; - for (rn = route_top (nbrs); rn; rn = route_next (rn)) - if ((nbr = rn->info) != NULL) - /* Ignore 0.0.0.0 node*/ - if (nbr->router_id.s_addr != 0) - /* Is neighbor eligible? */ - if (nbr->priority > 0) - /* Is neighbor upper 2-Way? */ - if (nbr->state >= NSM_TwoWay) - listnode_add (el_list, nbr); + for (ALL_LIST_ELEMENTS_RO (nbrs, node, nbr)) + /* Ignore 0.0.0.0 node*/ + if (nbr->router_id.s_addr != 0) + /* Is neighbor eligible? */ + if (nbr->priority > 0) + /* Is neighbor upper 2-Way? */ + if (nbr->state >= NSM_TwoWay) + listnode_add (el_list, nbr); } /* Generate AdjOK? NSM event. */ static void -ospf_dr_change (struct ospf *ospf, struct route_table *nbrs) +ospf_dr_change (struct ospf *ospf, struct list *nbrs) { - struct route_node *rn; + struct listnode *node; struct ospf_neighbor *nbr; - for (rn = route_top (nbrs); rn; rn = route_next (rn)) - if ((nbr = rn->info) != NULL) - /* Ignore 0.0.0.0 node*/ - if (nbr->router_id.s_addr != 0) - /* Is neighbor upper 2-Way? */ - if (nbr->state >= NSM_TwoWay) - /* Ignore myself. */ - if (!IPV4_ADDR_SAME (&nbr->router_id, &ospf->router_id)) - OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_AdjOK); + for (ALL_LIST_ELEMENTS_RO (nbrs, node, nbr)) + /* Ignore 0.0.0.0 node*/ + if (nbr->router_id.s_addr != 0) + /* Is neighbor upper 2-Way? */ + if (nbr->state >= NSM_TwoWay) + /* Ignore myself. */ + if (!IPV4_ADDR_SAME (&nbr->router_id, &ospf->router_id)) + OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_AdjOK); } static int -- cgit v1.2.3 From 950867369b038a2d71394314ce4193c5c1c063b6 Mon Sep 17 00:00:00 2001 From: Joakim Tjernlund Date: Sun, 29 Nov 2009 11:08:39 +0000 Subject: ospfd: delete address in struct ospf_neighbor address is the same as src so it is redundant. This will save both memory and CPU when processing Hellos. --- ospfd/ospf_ism.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ospfd/ospf_ism.c') diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index e7bdbf2c..2186e894 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -88,7 +88,7 @@ ospf_elect_dr (struct ospf_interface *oi, struct list *el_list) listnode_add (dr_list, nbr); /* Preserve neighbor BDR. */ - if (IPV4_ADDR_SAME (&BDR (oi), &nbr->address.u.prefix4)) + if (IPV4_ADDR_SAME (&BDR (oi), &nbr->src)) bdr = nbr; } @@ -100,7 +100,7 @@ ospf_elect_dr (struct ospf_interface *oi, struct list *el_list) /* Set DR to interface. */ if (dr) - DR (oi) = dr->address.u.prefix4; + DR (oi) = dr->src; else DR (oi).s_addr = 0; @@ -141,7 +141,7 @@ ospf_elect_bdr (struct ospf_interface *oi, struct list *el_list) /* Set BDR to interface. */ if (bdr) - BDR (oi) = bdr->address.u.prefix4; + BDR (oi) = bdr->src; else BDR (oi).s_addr = 0; -- cgit v1.2.3