[ospfd] Allow ospf_lsa_unlock to NULL out callers' LSA pointers upon free
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.
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 788daba..44dca18 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -2764,7 +2764,7 @@
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;
@@ -2860,7 +2860,7 @@
count++;
list_delete_node (update, node);
- ospf_lsa_unlock (lsa);
+ ospf_lsa_unlock (&lsa); /* oi->ls_upd_queue */
}
/* Now set #LSAs. */
@@ -2874,17 +2874,13 @@
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))
@@ -2893,21 +2889,10 @@
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;
}
@@ -3396,10 +3381,7 @@
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 =