pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmo-sigtran/+/40583?usp=email )
Change subject: sccp: Free connections of sccp_user when unbinding it
......................................................................
sccp: Free connections of sccp_user when unbinding it
Implement FIXME in code.
Once we unbind the user, they cannot be used anymore anyway, so we
end up with dangling SCCP conns. By binding again we would be
potentially recieving previous connection stuff, which is not
really what the user expects.
Related: OS#6793
Change-Id: Ide694646e971043b60e232dcdc82b145af03dc91
---
M src/sccp_instance.c
M src/sccp_user.c
M src/sccp_user.h
3 files changed, 29 insertions(+), 14 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/83/40583/1
diff --git a/src/sccp_instance.c b/src/sccp_instance.c
index 10ef570..08274a5 100644
--- a/src/sccp_instance.c
+++ b/src/sccp_instance.c
@@ -284,16 +284,6 @@
return inst;
}
-static void sccp_flush_connections(struct osmo_sccp_instance *inst)
-{
- struct rb_node *node;
- while ((node = rb_first(&inst->connections))) {
- struct sccp_connection *conn = container_of(node, struct sccp_connection, node);
- sccp_conn_free(conn);
- }
-
-}
-
void osmo_sccp_instance_destroy(struct osmo_sccp_instance *inst)
{
struct osmo_sccp_user *scu, *scu2;
@@ -306,7 +296,7 @@
llist_for_each_entry_safe(scu, scu2, &inst->users, list) {
osmo_sccp_user_unbind(scu);
}
- sccp_flush_connections(inst);
+ OSMO_ASSERT(RB_EMPTY_ROOT(&inst->connections)); /* assert is empty */
llist_del(&inst->list);
talloc_free(inst);
}
diff --git a/src/sccp_user.c b/src/sccp_user.c
index 2ec2f28..fac01cb 100644
--- a/src/sccp_user.c
+++ b/src/sccp_user.c
@@ -37,6 +37,7 @@
#include <osmocom/sigtran/sccp_helpers.h>
#include <osmocom/sccp/sccp_types.h>
+#include "sccp_connection.h"
#include "sccp_instance.h"
#include "sccp_internal.h"
#include "sccp_user.h"
@@ -64,15 +65,38 @@
return scu;
}
+static void sccp_user_flush_connections(struct osmo_sccp_user *scu)
+{
+ struct osmo_sccp_instance *inst = scu->inst;
+ struct rb_node *node;
+
+start:
+ for (node = rb_first(&inst->connections); node; node = rb_next(node)) {
+ struct sccp_connection *conn = container_of(node, struct sccp_connection, node);
+ if (conn->user == scu) {
+ sccp_conn_free(conn);
+ /* node has been freed, rbtree has been changed, start again: */
+ goto start;
+ }
+ }
+}
+
+void sccp_user_free(struct osmo_sccp_user *scu)
+{
+ if (!scu)
+ return;
+ sccp_user_flush_connections(scu);
+ llist_del(&scu->list);
+ talloc_free(scu);
+}
+
/*! \brief Unbind a given SCCP user
* \param[in] scu SCCP User which is to be un-bound. Will be destroyed
* at the time this function returns. */
void osmo_sccp_user_unbind(struct osmo_sccp_user *scu)
{
LOGPSCU(scu, LOGL_INFO, "Unbinding user\n");
- /* FIXME: free/release all connections held by this user? */
- llist_del(&scu->list);
- talloc_free(scu);
+ sccp_user_free(scu);
}
void osmo_sccp_user_set_priv(struct osmo_sccp_user *scu, void *priv)
diff --git a/src/sccp_user.h b/src/sccp_user.h
index 95b37ee..47c8aa4 100644
--- a/src/sccp_user.h
+++ b/src/sccp_user.h
@@ -34,6 +34,7 @@
struct osmo_sccp_user *sccp_user_alloc(struct osmo_sccp_instance *inst, const char
*name,
osmo_prim_cb prim_cb, uint16_t ssn, uint32_t pc);
+void sccp_user_free(struct osmo_sccp_user *scu);
int sccp_user_prim_up(struct osmo_sccp_user *scut, struct osmo_scu_prim *prim);
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-sigtran/+/40583?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Ide694646e971043b60e232dcdc82b145af03dc91
Gerrit-Change-Number: 40583
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>