+2006-07-26 Paul Jakma <paul.jakma@sun.com>
+
+ * ospf_lsa.{c,h}: (ospf_lsa_unlock) Change to take a double pointer
+ to the LSA to be 'unlocked', so that, if the LSA is freed, the
+ callers pointer to the LSA can be NULLed out, allowing any further
+ use of that pointer to provoke a crash sooner rather than later.
+ * ospf_*.c: (general) Adjust callers of ospf_lsa_unlock to match
+ previous. Try annotate 'locking' somewhat to show which 'locks'
+ are protecting what LSA reference, if not obvious.
+ * ospf_opaque.c: (ospf_opaque_lsa_install) Trivial: remove useless
+ goto, replace with return.
+ * ospf_packet.c: (ospf_make_ls_ack) Trivial: merge two list loops,
+ the dual-loop predated the delete-safe list-loop macro.
+
2006-07-25 Paul Jakma <paul.jakma@sun.com>
* ospf_neigbor.h: (struct ospf_neighbor) Add some additional
if ((new->data = ospf_lsa_data_new (length)) == NULL)
{
zlog_warn ("ospf_apiserver_opaque_lsa_new: ospf_lsa_data_new() ?");
- ospf_lsa_unlock (new);
+ ospf_lsa_unlock (&new);
stream_free (s);
return NULL;
}
if (ospf_lsa_install (ospf, new->oi, new) == NULL)
{
zlog_warn ("ospf_apiserver_lsa_refresher: ospf_lsa_install failed");
- ospf_lsa_unlock (new);
+ ospf_lsa_unlock (&new);
goto out;
}
/* We assume that if LSA is deleted from DB
is is also deleted from this RT */
- listnode_add (lst, ospf_lsa_lock (lsa));
+ listnode_add (lst, ospf_lsa_lock (lsa)); /* external_lsas lst */
}
void
rn = route_node_get (top->external_lsas, (struct prefix *) &p);
lst = rn->info;
-#ifdef ORIGINAL_CODING
- assert (lst);
- listnode_delete (lst, lsa);
- ospf_lsa_unlock (lsa);
-#else /* ORIGINAL_CODING */
/* XXX lst can be NULL */
if (lst) {
listnode_delete (lst, lsa);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* external_lsas list */
}
-#endif /* ORIGINAL_CODING */
}
void
if ((lst = rn->info) != NULL)
{
for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa))
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* external_lsas lst */
list_delete (lst);
}
return;
/* Schedule a delayed LSA Ack to be sent */
- listnode_add (inbr->oi->ls_ack, ospf_lsa_lock (lsa));
+ listnode_add (inbr->oi->ls_ack, ospf_lsa_lock (lsa)); /* delayed LSA Ack */
}
/* Check LSA is related to external info. */
case OSPF_ROUTER_LSA:
/* Originate a new instance and schedule flooding */
/* It shouldn't be necessary, but anyway */
- ospf_lsa_unlock (area->router_lsa_self);
+ ospf_lsa_unlock (&area->router_lsa_self);
area->router_lsa_self = ospf_lsa_lock (new);
ospf_router_lsa_timer_add (area);
}
#endif /* HAVE_OPAQUE_LSA */
- ospf_lsa_unlock (oi->network_lsa_self);
+ ospf_lsa_unlock (&oi->network_lsa_self);
oi->network_lsa_self = ospf_lsa_lock (new);
/* Schedule network-LSA origination. */
{
if (nbr->ls_req_last == lsa)
{
- ospf_lsa_unlock (nbr->ls_req_last);
+ ospf_lsa_unlock (&nbr->ls_req_last);
nbr->ls_req_last = NULL;
}
void
ospf_ls_request_delete_all (struct ospf_neighbor *nbr)
{
- ospf_lsa_unlock (nbr->ls_req_last);
+ ospf_lsa_unlock (&nbr->ls_req_last);
nbr->ls_req_last = NULL;
ospf_lsdb_delete_all (&nbr->ls_req);
}
ospf_ls_retransmit_delete (nbr, lsa);
}
- ospf_lsa_unlock (nbr->ls_req_last);
+ ospf_lsa_unlock (&nbr->ls_req_last);
nbr->ls_req_last = NULL;
}
/* Cleanup Link State Acknowlegdment list. */
for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* oi->ls_ack */
list_delete_all_node (oi->ls_ack);
oi->crypt_seqnum = 0;
oi->nbr_self = ospf_nbr_new (oi);
ospf_nbr_add_self (oi);
- ospf_lsa_unlock (oi->network_lsa_self);
+ ospf_lsa_unlock (&oi->network_lsa_self);
oi->network_lsa_self = NULL;
OSPF_TIMER_OFF (oi->t_network_lsa_self);
}
OSPF_TIMER_OFF (oi->t_network_lsa_self);
}
- ospf_lsa_unlock (oi->network_lsa_self);
+ ospf_lsa_unlock (&oi->network_lsa_self);
oi->network_lsa_self = NULL;
}
/* Unlock LSA. */
void
-ospf_lsa_unlock (struct ospf_lsa *lsa)
+ospf_lsa_unlock (struct ospf_lsa **lsa)
{
/* This is sanity check. */
- if (!lsa)
+ if (!lsa || !*lsa)
return;
- lsa->lock--;
+ (*lsa)->lock--;
- assert (lsa->lock >= 0);
+ assert ((*lsa)->lock >= 0);
- if (lsa->lock == 0)
+ if ((*lsa)->lock == 0)
{
- assert (CHECK_FLAG (lsa->flags, OSPF_LSA_DISCARD));
- ospf_lsa_free (lsa);
+ assert (CHECK_FLAG ((*lsa)->flags, OSPF_LSA_DISCARD));
+ ospf_lsa_free (*lsa);
+ *lsa = NULL;
}
}
if (!CHECK_FLAG (lsa->flags, OSPF_LSA_DISCARD))
{
SET_FLAG (lsa->flags, OSPF_LSA_DISCARD);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa);
}
}
zlog_debug("LSA[Type%d:%s]: Refresh router-LSA for Area %s",
lsa->data->type, inet_ntoa (lsa->data->id), area_str);
ospf_lsa_flush_area (lsa, area);
- ospf_lsa_unlock (area->router_lsa_self);
+ ospf_lsa_unlock (&area->router_lsa_self);
area->router_lsa_self = NULL;
/* Refresh router-LSA, (not install) and flood through area. */
{
if (IS_DEBUG_OSPF_NSSA)
zlog_debug ("LSA[Type-7]: Could not build FWD-ADDR");
- ospf_lsa_discard(new);
+ ospf_lsa_discard (new);
return;
}
}
ospf_router_lsa_timer, OSPF_LS_REFRESH_TIME);
/* Set self-originated router-LSA. */
- ospf_lsa_unlock (area->router_lsa_self);
+ ospf_lsa_unlock (&area->router_lsa_self);
area->router_lsa_self = ospf_lsa_lock (new);
if (IS_DEBUG_OSPF (lsa, LSA_INSTALL))
ospf_network_lsa_refresh_timer,
OSPF_LS_REFRESH_TIME);
- ospf_lsa_unlock (oi->network_lsa_self);
+ ospf_lsa_unlock (&oi->network_lsa_self);
oi->network_lsa_self = ospf_lsa_lock (new);
}
if ((n = listnode_lookup (ospf->maxage_lsa, lsa)))
{
list_delete_node (ospf->maxage_lsa, n);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* maxage_lsa */
}
}
zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id));
ospf_lsa_flush_area (lsa, area);
- ospf_lsa_unlock (area->router_lsa_self);
+ ospf_lsa_unlock (&area->router_lsa_self);
area->router_lsa_self = NULL;
OSPF_TIMER_OFF (area->t_router_lsa_self);
}
zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id));
ospf_lsa_flush_area (oi->network_lsa_self, area);
- ospf_lsa_unlock (oi->network_lsa_self);
+ ospf_lsa_unlock (&oi->network_lsa_self);
oi->network_lsa_self = NULL;
OSPF_TIMER_OFF (oi->t_network_lsa_self);
}
break;
}
- ospf_lsa_unlock (data->lsa);
+ ospf_lsa_unlock (&data->lsa); /* Message */
XFREE (MTYPE_OSPF_MESSAGE, data);
return 0;
}
data->action = LSA_ACTION_FLOOD_AREA;
data->area = area;
- data->lsa = ospf_lsa_lock (lsa);
+ data->lsa = ospf_lsa_lock (lsa); /* Message / Flood area */
thread_add_event (master, ospf_lsa_action, data, 0);
}
data->action = LSA_ACTION_FLUSH_AREA;
data->area = area;
- data->lsa = ospf_lsa_lock (lsa);
+ data->lsa = ospf_lsa_lock (lsa); /* Message / Flush area */
thread_add_event (master, ospf_lsa_action, data, 0);
}
inet_ntoa (lsa->data->id), LS_AGE (lsa), index);
if (!ospf->lsa_refresh_queue.qs[index])
ospf->lsa_refresh_queue.qs[index] = list_new ();
- listnode_add (ospf->lsa_refresh_queue.qs[index], ospf_lsa_lock (lsa));
+ listnode_add (ospf->lsa_refresh_queue.qs[index],
+ ospf_lsa_lock (lsa)); /* lsa_refresh_queue */
lsa->refresh_list = index;
if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
zlog_debug ("LSA[Refresh:%s]: ospf_refresher_register_lsa(): "
list_free (refresh_list);
ospf->lsa_refresh_queue.qs[lsa->refresh_list] = NULL;
}
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* lsa_refresh_queue */
lsa->refresh_list = -1;
}
}
inet_ntoa (lsa->data->id), lsa, i);
list_delete_node (refresh_list, node);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* lsa_refresh_queue */
lsa->refresh_list = -1;
listnode_add (lsa_to_refresh, lsa);
}
extern struct ospf_lsa *ospf_lsa_dup (struct ospf_lsa *);
extern void ospf_lsa_free (struct ospf_lsa *);
extern struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
-extern void ospf_lsa_unlock (struct ospf_lsa *);
+extern void ospf_lsa_unlock (struct ospf_lsa **);
extern void ospf_lsa_discard (struct ospf_lsa *);
extern struct lsa_header *ospf_lsa_data_new (size_t);
old = rn->info;
lsdb->type[old->data->type].checksum -= ntohs(old->data->checksum);
- ospf_lsa_unlock (rn->info);
+ ospf_lsa_unlock (&rn->info);
route_unlock_node (rn);
}
if (lsdb->del_lsa_hook != NULL)
(* lsdb->del_lsa_hook)(lsa);
#endif /* MONITOR_LSDB_CHANGE */
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa);
return;
}
}
if (lsdb->del_lsa_hook != NULL)
(* lsdb->del_lsa_hook)(lsa);
#endif /* MONITOR_LSDB_CHANGE */
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa);
}
}
}
if (oi->network_lsa_self && oi->full_nbrs == 0)
{
ospf_lsa_flush_area (oi->network_lsa_self, oi->area);
- ospf_lsa_unlock (oi->network_lsa_self);
+ ospf_lsa_unlock (&oi->network_lsa_self);
oi->network_lsa_self = NULL;
OSPF_TIMER_OFF (oi->t_network_lsa_self);
}
OSPF_TIMER_OFF (oipi->t_opaque_lsa_self);
if (oipi->lsa != NULL)
- ospf_lsa_unlock (oipi->lsa);
+ ospf_lsa_unlock (&oipi->lsa);
XFREE (MTYPE_OPAQUE_INFO_PER_ID, oipi);
return;
}
if ((oipt = lookup_opaque_info_by_type (lsa)) != NULL
&& (oipi = lookup_opaque_info_by_id (oipt, lsa)) != NULL)
{
- ospf_lsa_unlock (oipi->lsa);
+ ospf_lsa_unlock (&oipi->lsa);
oipi->lsa = ospf_lsa_lock (lsa);
}
/* Register the new lsa entry and get its control info. */
u_char before;
if ((top = oi_to_top (nbr->oi)) == NULL)
- goto out;
+ return;
before = IS_OPAQUE_LSA_ORIGINATION_BLOCKED (top->opaque);
break;
default:
zlog_warn ("ospf_opaque_self_originated_lsa_received: Unexpected LSA-type(%u)", lsa->data->type);
- goto out;
+ return;
}
ospf_lsa_discard (lsa); /* List "lsas" will be deleted by caller. */
if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("Block Opaque-LSA origination: OFF -> ON");
}
-
-out:
- return;
}
void
stream_put_ipv4 (s, lsa->data->id.s_addr);
stream_put_ipv4 (s, lsa->data->adv_router.s_addr);
- ospf_lsa_unlock (nbr->ls_req_last);
+ ospf_lsa_unlock (&nbr->ls_req_last);
nbr->ls_req_last = ospf_lsa_lock (lsa);
*length += 12;
count++;
list_delete_node (update, node);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* oi->ls_upd_queue */
}
/* Now set #LSAs. */
static int
ospf_make_ls_ack (struct ospf_interface *oi, struct list *ack, struct stream *s)
{
- struct list *rm_list;
- struct listnode *node;
+ struct listnode *node, *nnode;
u_int16_t length = OSPF_LS_ACK_MIN_SIZE;
unsigned long delta = stream_get_endp(s) + 24;
struct ospf_lsa *lsa;
- rm_list = list_new ();
-
- for (ALL_LIST_ELEMENTS_RO (ack, node, lsa))
+ for (ALL_LIST_ELEMENTS (ack, node, nnode, lsa))
{
- lsa = listgetdata (node);
assert (lsa);
if (length + delta > ospf_packet_max (oi))
stream_put (s, lsa->data, OSPF_LSA_HEADER_SIZE);
length += OSPF_LSA_HEADER_SIZE;
- listnode_add (rm_list, lsa);
- }
-
- /* Remove LSA from LS-Ack list. */
- /* XXX: this loop should be removed and the list move done in previous
- * loop
- */
- for (ALL_LIST_ELEMENTS_RO (rm_list, node, lsa))
- {
listnode_delete (ack, lsa);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* oi->ls_ack_direct.ls_ack */
}
- list_delete (rm_list);
-
return length;
}
rn->info = list_new ();
for (ALL_LIST_ELEMENTS_RO (update, node, lsa))
- {
- ospf_lsa_lock (lsa);
- listnode_add (rn->info, lsa);
- }
+ listnode_add (rn->info, ospf_lsa_lock (lsa)); /* oi->ls_upd_queue */
if (oi->t_ls_upd_event == NULL)
oi->t_ls_upd_event =
if ((new->data = ospf_lsa_data_new (length)) == NULL)
{
zlog_warn ("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?");
- ospf_lsa_unlock (new);
+ ospf_lsa_unlock (&new);
new = NULL;
stream_free (s);
goto out;
if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
{
zlog_warn ("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?");
- ospf_lsa_unlock (new);
+ ospf_lsa_unlock (&new);
goto out;
}
if (ospf_lsa_install (area->ospf, NULL/*oi*/, new) == NULL)
{
zlog_warn ("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
- ospf_lsa_unlock (new);
+ ospf_lsa_unlock (&new);
goto out;
}
ospf_lsdb_free (ospf->lsdb);
for (ALL_LIST_ELEMENTS (ospf->maxage_lsa, node, nnode, lsa))
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* maxage_lsa */
list_delete (ospf->maxage_lsa);
ospf_lsdb_delete_all (area->lsdb);
ospf_lsdb_free (area->lsdb);
- ospf_lsa_unlock (area->router_lsa_self);
+ ospf_lsa_unlock (&area->router_lsa_self);
route_table_finish (area->ranges);
list_delete (area->oiflist);
if ((lst = (struct list *) rn->info))
{
for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa))
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* oi->ls_upd_queue */
list_free (lst);
rn->info = NULL;
}