pespin has uploaded this change for review.

View Change

ran_peer: Add specific API to free object

Add a specific ran_peer_free() API so it becomes clear where the object
is freed and hence the entire lifecycle of the object.
Swap the talloc tree parentship to have the fi be a child of the object,
which simplifies tear down triggered by FSM cleanup.

Apparently the object is not being freed anywhere, so they are so far
only being added to the list through .ran_peer_up_l2() -> ran_peer_find_or_create().

Change-Id: I721de21a68a4e336ae508a995e3cfcca05d57efe
---
M include/osmocom/msc/ran_peer.h
M src/libmsc/ran_peer.c
2 files changed, 27 insertions(+), 24 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/32/40632/1
diff --git a/include/osmocom/msc/ran_peer.h b/include/osmocom/msc/ran_peer.h
index 211dd44..0ef490d 100644
--- a/include/osmocom/msc/ran_peer.h
+++ b/include/osmocom/msc/ran_peer.h
@@ -106,6 +106,7 @@

void ran_peer_reset(struct ran_peer *rp);
void ran_peer_becomes_unreachable(struct ran_peer *rp);
+void ran_peer_discard_all_conns(struct ran_peer *rp);

struct ran_peer *ran_peer_find_by_cell_id(struct sccp_ran_inst *sri, const struct gsm0808_cell_id *cid,
bool expecting_single_match);
diff --git a/src/libmsc/ran_peer.c b/src/libmsc/ran_peer.c
index 07e4328..d87a279 100644
--- a/src/libmsc/ran_peer.c
+++ b/src/libmsc/ran_peer.c
@@ -1,5 +1,5 @@
/*
- * (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ * (C) 2019-2025 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
* All Rights Reserved
*
* SPDX-License-Identifier: AGPL-3.0+
@@ -42,16 +42,23 @@
OSMO_ASSERT( osmo_fsm_register(&ran_peer_fsm) == 0);
}

-/* Allocate a RAN peer with FSM instance. To deallocate, call osmo_fsm_inst_term(ran_peer->fi). */
+/* Allocate a RAN peer with FSM instance. To deallocate, call ran_peer_free(). */
static struct ran_peer *ran_peer_alloc(struct sccp_ran_inst *sri, const struct osmo_sccp_addr *peer_addr)
{
struct ran_peer *rp;
- struct osmo_fsm_inst *fi;
char *sccp_addr;
char *pos;

- fi = osmo_fsm_inst_alloc(&ran_peer_fsm, sri, NULL, LOGL_DEBUG, NULL);
- OSMO_ASSERT(fi);
+ rp = talloc(sri, struct ran_peer);
+ OSMO_ASSERT(rp);
+ *rp = (struct ran_peer){
+ .sri = sri,
+ .peer_addr = *peer_addr,
+ };
+ INIT_LLIST_HEAD(&rp->cells_seen);
+
+ rp->fi = osmo_fsm_inst_alloc(&ran_peer_fsm, rp, rp, LOGL_DEBUG, NULL);
+ OSMO_ASSERT(rp->fi);

/* Unfortunately, osmo_sccp_inst_addr_name() returns "RI=SSN_PC,PC=0.24.1,SSN=BSSAP" but neither commas nor
* full-stops are allowed as FSM inst id. Make it "RI=SSN_PC:PC-0-24-1:SSN-BSSAP". */
@@ -62,23 +69,26 @@
else if (*pos == '.' || *pos == '=')
*pos = '-';
}
- osmo_fsm_inst_update_id_f(fi, "%s:%s", osmo_rat_type_name(sri->ran->type), sccp_addr);
-
- rp = talloc_zero(fi, struct ran_peer);
- OSMO_ASSERT(rp);
- *rp = (struct ran_peer){
- .sri = sri,
- .peer_addr = *peer_addr,
- .fi = fi,
- };
- INIT_LLIST_HEAD(&rp->cells_seen);
- fi->priv = rp;
+ osmo_fsm_inst_update_id_f(rp->fi, "%s:%s", osmo_rat_type_name(sri->ran->type), sccp_addr);

llist_add(&rp->entry, &sri->ran_peers);

return rp;
}

+void ran_peer_free(struct ran_peer *rp)
+{
+ if (!rp)
+ return;
+
+ ran_peer_discard_all_conns(rp);
+
+ osmo_fsm_inst_free(rp->fi);
+ rp->fi = NULL;
+ llist_del(&rp->entry);
+ talloc_free(rp);
+}
+
struct ran_peer *ran_peer_find_or_create(struct sccp_ran_inst *sri, const struct osmo_sccp_addr *peer_addr)
{
struct ran_peer *rp = ran_peer_find_by_addr(sri, peer_addr);
@@ -461,13 +471,6 @@
return 0;
}

-void ran_peer_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
-{
- struct ran_peer *rp = fi->priv;
- ran_peer_discard_all_conns(rp);
- llist_del(&rp->entry);
-}
-
static const struct value_string ran_peer_fsm_event_names[] = {
OSMO_VALUE_STRING(RAN_PEER_EV_MSG_UP_CL),
OSMO_VALUE_STRING(RAN_PEER_EV_MSG_UP_CO_INITIAL),
@@ -548,7 +551,6 @@
.log_subsys = DRR,
.event_names = ran_peer_fsm_event_names,
.timer_cb = ran_peer_fsm_timer_cb,
- .cleanup = ran_peer_fsm_cleanup,
.allstate_action = ran_peer_allstate_action,
.allstate_event_mask = 0
| S(RAN_PEER_EV_MSG_UP_CL)

To view, visit change 40632. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Change-Id: I721de21a68a4e336ae508a995e3cfcca05d57efe
Gerrit-Change-Number: 40632
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>