nat: Close all endpoints used by a BSC when the BSC is gone
Cleanup all endpoints that belonged to a given BSC. This is
one part of the cleanup, the other is to bring down the SCCP
link properly.
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c
index 49c4466..6fc5eac 100644
--- a/openbsc/src/nat/bsc_mgcp_utils.c
+++ b/openbsc/src/nat/bsc_mgcp_utils.c
@@ -466,3 +466,21 @@
return 0;
}
+
+void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc)
+{
+ int i;
+ for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
+ struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i];
+
+ if (bsc_endp->bsc != bsc)
+ continue;
+
+ bsc_endp->bsc = NULL;
+ bsc_endp->pending_delete = 0;
+ if (bsc_endp->transaction_id)
+ talloc_free(bsc_endp->transaction_id);
+ bsc_endp->transaction_id = NULL;
+ mgcp_free_endp(&bsc->nat->mgcp_cfg->endpoints[i]);
+ }
+}
diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c
index 9fb4f02..06c130b 100644
--- a/openbsc/src/nat/bsc_nat.c
+++ b/openbsc/src/nat/bsc_nat.c
@@ -354,6 +354,9 @@
sccp_connection_destroy(sccp_patch);
}
+ /* close endpoints allocated by this BSC */
+ bsc_mgcp_clear_endpoints_for(connection);
+
talloc_free(connection);
}