From 3ba8963a1d8a55b19d3fd902dd2c20196afdff5a Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 5 Apr 2010 23:09:27 +0200 Subject: 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. --- openbsc/include/openbsc/bsc_nat.h | 1 + openbsc/src/nat/bsc_mgcp_utils.c | 18 ++++++++++++++++++ openbsc/src/nat/bsc_nat.c | 3 +++ 3 files changed, 22 insertions(+) (limited to 'openbsc') diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 13bdc7184..6de32ebc9 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -205,6 +205,7 @@ struct bsc_connection *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number); struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port); void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg); +void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc); int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]); int bsc_mgcp_extract_ci(const char *resp); int bsc_mgcp_extract_port(const char *resp); diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index 49c44668e..6fc5eaca2 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -466,3 +466,21 @@ int bsc_mgcp_init(struct bsc_nat *nat) 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 fcf732b42..1465be01c 100644 --- a/openbsc/src/nat/bsc_nat.c +++ b/openbsc/src/nat/bsc_nat.c @@ -354,6 +354,9 @@ static void remove_bsc_connection(struct bsc_connection *connection) sccp_connection_destroy(sccp_patch); } + /* close endpoints allocated by this BSC */ + bsc_mgcp_clear_endpoints_for(connection); + talloc_free(connection); } -- cgit v1.2.3