ospf6d: Convert ospf6_lsa_unlock to a better api

Make the ospf6_lsa_unlock take the same parameters
that the ospf_lsa_unlock does to make it consistent
and to also ensure that no-one can make the mistake
of getting the pointer cleared up.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2023-07-05 09:28:50 -04:00
parent c362e274b2
commit 0cbd5855a9
10 changed files with 37 additions and 36 deletions

View file

@ -389,7 +389,7 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa,
if (req == on->last_ls_req) { if (req == on->last_ls_req) {
/* sanity check refcount */ /* sanity check refcount */
assert(req->lock >= 2); assert(req->lock >= 2);
req = ospf6_lsa_unlock(req); ospf6_lsa_unlock(&req);
on->last_ls_req = NULL; on->last_ls_req = NULL;
} }
if (req) if (req)
@ -406,7 +406,7 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa,
zlog_debug( zlog_debug(
"Received is newer, remove requesting"); "Received is newer, remove requesting");
if (req == on->last_ls_req) { if (req == on->last_ls_req) {
req = ospf6_lsa_unlock(req); ospf6_lsa_unlock(&req);
on->last_ls_req = NULL; on->last_ls_req = NULL;
} }
if (req) if (req)

View file

@ -294,7 +294,7 @@ static int ospf6_router_lsa_contains_adj(struct ospf6_area *area,
continue; continue;
if (lsdesc->neighbor_router_id == neighbor_router_id) { if (lsdesc->neighbor_router_id == neighbor_router_id) {
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
return RTR_LSA_ADJ_FOUND; return RTR_LSA_ADJ_FOUND;
} }
} }
@ -514,7 +514,7 @@ static bool ospf6_gr_check_adjs(struct ospf6 *ospf6)
lsa_self)) { lsa_self)) {
found = true; found = true;
if (!ospf6_gr_check_adjs_lsa(area, lsa_self)) { if (!ospf6_gr_check_adjs_lsa(area, lsa_self)) {
ospf6_lsa_unlock(lsa_self); ospf6_lsa_unlock(&lsa_self);
return false; return false;
} }
} }

View file

@ -228,9 +228,9 @@ static bool ospf6_check_chg_in_rxmt_list(struct ospf6_neighbor *nbr)
lsa->header->adv_router, lsa->lsdb); lsa->header->adv_router, lsa->lsdb);
if (lsa_in_db && lsa_in_db->tobe_acknowledged) { if (lsa_in_db && lsa_in_db->tobe_acknowledged) {
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
if (lsanext) if (lsanext)
ospf6_lsa_unlock(lsanext); ospf6_lsa_unlock(&lsanext);
return OSPF6_TRUE; return OSPF6_TRUE;
} }

View file

@ -797,17 +797,17 @@ struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa)
} }
/* decrement reference counter of struct ospf6_lsa */ /* decrement reference counter of struct ospf6_lsa */
struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa) void ospf6_lsa_unlock(struct ospf6_lsa **lsa)
{ {
/* decrement reference counter */ /* decrement reference counter */
assert(lsa->lock > 0); assert((*lsa)->lock > 0);
lsa->lock--; (*lsa)->lock--;
if (lsa->lock != 0) if ((*lsa)->lock != 0)
return lsa; return;
ospf6_lsa_delete(lsa); ospf6_lsa_delete(*lsa);
return NULL; *lsa = NULL;
} }

View file

@ -239,7 +239,7 @@ extern void ospf6_lsa_delete(struct ospf6_lsa *lsa);
extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *lsa); extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *lsa);
extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa); extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa);
extern struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa); extern void ospf6_lsa_unlock(struct ospf6_lsa **lsa);
extern void ospf6_lsa_expire(struct event *thread); extern void ospf6_lsa_expire(struct event *thread);
extern void ospf6_lsa_refresh(struct event *thread); extern void ospf6_lsa_refresh(struct event *thread);

View file

@ -139,7 +139,7 @@ void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
} }
/* to free the lookup lock in node get*/ /* to free the lookup lock in node get*/
route_unlock_node(current); route_unlock_node(current);
ospf6_lsa_unlock(old); ospf6_lsa_unlock(&old);
} }
ospf6_lsdb_count_assert(lsdb); ospf6_lsdb_count_assert(lsdb);
@ -168,7 +168,7 @@ void ospf6_lsdb_remove(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
route_unlock_node(node); /* to free the lookup lock */ route_unlock_node(node); /* to free the lookup lock */
route_unlock_node(node); /* to free the original lock */ route_unlock_node(node); /* to free the original lock */
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
ospf6_lsdb_count_assert(lsdb); ospf6_lsdb_count_assert(lsdb);
} }
@ -237,7 +237,7 @@ struct ospf6_lsa *ospf6_find_inter_prefix_lsa(struct ospf6 *ospf6,
ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa, ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa,
&prefix_lsa->prefix); &prefix_lsa->prefix);
if (prefix_same(p, &prefix)) { if (prefix_same(p, &prefix)) {
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
return lsa; return lsa;
} }
} }
@ -328,7 +328,7 @@ struct ospf6_lsa *ospf6_lsdb_next(const struct route_node *iterend,
{ {
struct route_node *node = lsa->rn; struct route_node *node = lsa->rn;
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
do do
node = route_next_until(node, iterend); node = route_next_until(node, iterend);
@ -361,7 +361,7 @@ void ospf6_lsdb_lsa_unlock(struct ospf6_lsa *lsa)
if (lsa != NULL) { if (lsa != NULL) {
if (lsa->rn != NULL) if (lsa->rn != NULL)
route_unlock_node(lsa->rn); route_unlock_node(lsa->rn);
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
} }
} }

View file

@ -63,11 +63,11 @@ extern struct ospf6_lsa *ospf6_lsdb_next(const struct route_node *iterend,
* it really early. * it really early.
*/ */
#define ALL_LSDB(lsdb, lsa, lsanext) \ #define ALL_LSDB(lsdb, lsa, lsanext) \
const struct route_node *iterend = \ const struct route_node *iterend = ospf6_lsdb_head(lsdb, 0, 0, 0, \
ospf6_lsdb_head(lsdb, 0, 0, 0, &lsa); \ &lsa); \
(lsa) != NULL && ospf6_lsa_lock(lsa) \ (lsa) != NULL && ospf6_lsa_lock(lsa) && \
&& ((lsanext) = ospf6_lsdb_next(iterend, (lsa)), 1); \ ((lsanext) = ospf6_lsdb_next(iterend, (lsa)), 1); \
ospf6_lsa_unlock(lsa), (lsa) = (lsanext) ospf6_lsa_unlock(&lsa), (lsa) = (lsanext)
extern void ospf6_lsdb_remove_all(struct ospf6_lsdb *lsdb); extern void ospf6_lsdb_remove_all(struct ospf6_lsdb *lsdb);
extern void ospf6_lsdb_lsa_unlock(struct ospf6_lsa *lsa); extern void ospf6_lsdb_lsa_unlock(struct ospf6_lsa *lsa);

View file

@ -2335,9 +2335,9 @@ static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s)
if ((length + sizeof(struct ospf6_lsa_header) if ((length + sizeof(struct ospf6_lsa_header)
+ OSPF6_HEADER_SIZE) + OSPF6_HEADER_SIZE)
> ospf6_packet_max(on->ospf6_if)) { > ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
if (lsanext) if (lsanext)
ospf6_lsa_unlock(lsanext); ospf6_lsa_unlock(&lsanext);
break; break;
} }
stream_put(s, lsa->header, stream_put(s, lsa->header,
@ -2415,9 +2415,9 @@ void ospf6_dbdesc_send_newone(struct event *thread)
if (size + sizeof(struct ospf6_lsa_header) if (size + sizeof(struct ospf6_lsa_header)
> ospf6_packet_max(on->ospf6_if)) { > ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
if (lsanext) if (lsanext)
ospf6_lsa_unlock(lsanext); ospf6_lsa_unlock(&lsanext);
break; break;
} }
@ -2447,9 +2447,9 @@ static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s)
for (ALL_LSDB(on->request_list, lsa, lsanext)) { for (ALL_LSDB(on->request_list, lsa, lsanext)) {
if ((length + OSPF6_HEADER_SIZE) if ((length + OSPF6_HEADER_SIZE)
> ospf6_packet_max(on->ospf6_if)) { > ospf6_packet_max(on->ospf6_if)) {
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
if (lsanext) if (lsanext)
ospf6_lsa_unlock(lsanext); ospf6_lsa_unlock(&lsanext);
break; break;
} }
stream_putw(s, 0); /* reserved */ stream_putw(s, 0); /* reserved */
@ -2462,7 +2462,7 @@ static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s)
if (last_req != NULL) { if (last_req != NULL) {
if (on->last_ls_req != NULL) if (on->last_ls_req != NULL)
on->last_ls_req = ospf6_lsa_unlock(on->last_ls_req); ospf6_lsa_unlock(&on->last_ls_req);
ospf6_lsa_lock(last_req); ospf6_lsa_lock(last_req);
on->last_ls_req = last_req; on->last_ls_req = last_req;
@ -2944,9 +2944,9 @@ static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi,
event_add_event(master, ospf6_lsack_send_interface, oi, event_add_event(master, ospf6_lsack_send_interface, oi,
0, &oi->thread_send_lsack); 0, &oi->thread_send_lsack);
ospf6_lsa_unlock(lsa); ospf6_lsa_unlock(&lsa);
if (lsanext) if (lsanext)
ospf6_lsa_unlock(lsanext); ospf6_lsa_unlock(&lsanext);
break; break;
} }
ospf6_lsa_age_update_to_send(lsa, oi->transdelay); ospf6_lsa_age_update_to_send(lsa, oi->transdelay);

View file

@ -98,9 +98,10 @@ static void ospf6_neighbor_clear_ls_lists(struct ospf6_neighbor *on)
ospf6_lsdb_remove_all(on->summary_list); ospf6_lsdb_remove_all(on->summary_list);
if (on->last_ls_req) { if (on->last_ls_req) {
ospf6_lsa_unlock(on->last_ls_req); ospf6_lsa_unlock(&on->last_ls_req);
on->last_ls_req = NULL; on->last_ls_req = NULL;
} }
ospf6_lsdb_remove_all(on->request_list); ospf6_lsdb_remove_all(on->request_list);
for (ALL_LSDB(on->retrans_list, lsa, lsanext)) { for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
ospf6_decrement_retrans_count(lsa); ospf6_decrement_retrans_count(lsa);

View file

@ -59,7 +59,7 @@ DEFPY(lsa_set, lsa_set_cmd,
lsa_check_resize(idx + 1); lsa_check_resize(idx + 1);
if (lsas[idx]) if (lsas[idx])
ospf6_lsa_unlock(lsas[idx]); ospf6_lsa_unlock(&lsas[idx]);
lsas[idx] = ospf6_lsa_create_headeronly(&hdr); lsas[idx] = ospf6_lsa_create_headeronly(&hdr);
ospf6_lsa_lock(lsas[idx]); ospf6_lsa_lock(lsas[idx]);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -75,7 +75,7 @@ DEFPY(lsa_drop, lsa_drop_cmd,
return CMD_SUCCESS; return CMD_SUCCESS;
if (lsas[idx]->lock != 1) if (lsas[idx]->lock != 1)
vty_out(vty, "refcount at %u\n", lsas[idx]->lock); vty_out(vty, "refcount at %u\n", lsas[idx]->lock);
ospf6_lsa_unlock(lsas[idx]); ospf6_lsa_unlock(&lsas[idx]);
lsas[idx] = NULL; lsas[idx] = NULL;
return CMD_SUCCESS; return CMD_SUCCESS;
} }