aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-04-27 13:21:39 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-04-27 13:21:39 +0800
commit12b63716e2b92d429aa7be7a67f361b1abebd78c (patch)
tree9b74996f306806fd00d9690ee8a6efb96696a58a
parent184961ea3e3004d1e2eec2ad16eb13852e607289 (diff)
nat: Add a command to close a given BSC Connection
This can be used to clear stale connections for a given BSC or to force a reconnect of the BSC.
-rw-r--r--openbsc/include/openbsc/bsc_nat.h1
-rw-r--r--openbsc/src/nat/bsc_nat.c9
-rw-r--r--openbsc/src/nat/bsc_nat_vty.c19
3 files changed, 24 insertions, 5 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 90c263d2..28ed4e80 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -230,6 +230,7 @@ struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat);
void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip);
void sccp_connection_destroy(struct sccp_connections *);
+void bsc_close_connection(struct bsc_connection *);
/**
* parse the given message into the above structure
diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c
index a6258dac..842bb0a2 100644
--- a/openbsc/src/nat/bsc_nat.c
+++ b/openbsc/src/nat/bsc_nat.c
@@ -59,7 +59,6 @@ static const char *msc_ip = NULL;
static struct bsc_nat *nat;
static void bsc_send_data(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length, int);
-static void remove_bsc_connection(struct bsc_connection *connection);
static void msc_send_reset(struct bsc_msc_connection *con);
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num)
@@ -344,7 +343,7 @@ static void msc_connection_was_lost(struct bsc_msc_connection *con)
LOGP(DMSC, LOGL_ERROR, "Closing all connections downstream.\n");
llist_for_each_entry_safe(bsc, tmp, &nat->bsc_connections, list_entry)
- remove_bsc_connection(bsc);
+ bsc_close_connection(bsc);
nat->first_contact = 0;
bsc_mgcp_free_endpoints(nat);
@@ -432,7 +431,7 @@ static int ipaccess_msc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
* remove it from the patching of SCCP header lists
* as well. Maybe in the future even close connection..
*/
-static void remove_bsc_connection(struct bsc_connection *connection)
+void bsc_close_connection(struct bsc_connection *connection)
{
struct sccp_connections *sccp_patch, *tmp;
@@ -470,7 +469,7 @@ static void ipaccess_close_bsc(void *data)
getpeername(conn->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
LOGP(DNAT, LOGL_ERROR, "BSC on %s didn't respond to identity request. Closing.\n",
inet_ntoa(sock.sin_addr));
- remove_bsc_connection(conn);
+ bsc_close_connection(conn);
}
static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc)
@@ -605,7 +604,7 @@ static int ipaccess_bsc_read_cb(struct bsc_fd *bfd)
else
LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error);
- remove_bsc_connection(bsc);
+ bsc_close_connection(bsc);
return -1;
}
diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c
index 6387aaf2..7501767a 100644
--- a/openbsc/src/nat/bsc_nat_vty.c
+++ b/openbsc/src/nat/bsc_nat_vty.c
@@ -170,6 +170,24 @@ DEFUN(show_stats,
return CMD_SUCCESS;
}
+DEFUN(close_bsc,
+ close_bsc_cmd,
+ "close bsc connection BSC_NR",
+ "Close the connection with the BSC identified by the config number.\n")
+{
+ struct bsc_connection *bsc;
+ int bsc_nr = atoi(argv[0]);
+
+ llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
+ if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
+ continue;
+ bsc_close_connection(bsc);
+ break;
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
{
vty->index = _nat;
@@ -349,6 +367,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
install_element(VIEW_NODE, &show_bsc_cmd);
install_element(VIEW_NODE, &show_bsc_cfg_cmd);
install_element(VIEW_NODE, &show_stats_cmd);
+ install_element(VIEW_NODE, &close_bsc_cmd);
openbsc_vty_add_cmds();