aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-11-08 23:50:10 +0100
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-11-09 01:04:04 +0100
commit0a94e57b72e5d1445b8a92538c8091b474fef445 (patch)
tree6d5ccb8f84e7f4973a355092f2a93c54a057f564 /src
parentd7ab53dc168ff2aac4d0eea8f0ecb3377e03103b (diff)
client: Allow to stop and remove a connection
Diffstat (limited to 'src')
-rw-r--r--src/osmo_client_core.c22
-rw-r--r--src/osmo_client_network.c20
-rw-r--r--src/osmo_client_vty.c30
3 files changed, 64 insertions, 8 deletions
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index 50e6573..5208744 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -346,7 +346,15 @@ void osmo_client_conn_init(struct osmo_pcap_client_conn *conn,
conn->wqueue.bfd.fd = -1;
}
-struct osmo_pcap_client_conn *osmo_client_find_or_create_conn(
+
+void osmo_client_free(struct osmo_pcap_client_conn *conn)
+{
+ osmo_client_disconnect(conn);
+ llist_del(&conn->entry);
+ talloc_free(conn);
+}
+
+struct osmo_pcap_client_conn *osmo_client_find_conn(
struct osmo_pcap_client *client,
const char *name)
{
@@ -356,6 +364,18 @@ struct osmo_pcap_client_conn *osmo_client_find_or_create_conn(
if (strcmp(conn->name, name) == 0)
return conn;
+ return NULL;
+}
+
+struct osmo_pcap_client_conn *osmo_client_find_or_create_conn(
+ struct osmo_pcap_client *client,
+ const char *name)
+{
+ struct osmo_pcap_client_conn *conn = osmo_client_find_conn(client, name);;
+
+ if (conn)
+ return conn;
+
conn = talloc_zero(client, struct osmo_pcap_client_conn);
if (!conn) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate conn for %s\n", name);
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index a588f07..f9303e9 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -46,13 +46,7 @@ static void _osmo_client_connect(void *_data)
static void lost_connection(struct osmo_pcap_client_conn *conn)
{
- if (conn->wqueue.bfd.fd >= 0) {
- osmo_tls_release(&conn->tls_session);
- osmo_fd_unregister(&conn->wqueue.bfd);
- close(conn->wqueue.bfd.fd);
- conn->wqueue.bfd.fd = -1;
- }
-
+ osmo_client_disconnect(conn);
conn->timer.cb = _osmo_client_connect;
conn->timer.data = conn;
@@ -260,3 +254,15 @@ void osmo_client_reconnect(struct osmo_pcap_client_conn *conn)
{
lost_connection(conn);
}
+
+void osmo_client_disconnect(struct osmo_pcap_client_conn *conn)
+{
+ if (conn->wqueue.bfd.fd >= 0) {
+ osmo_tls_release(&conn->tls_session);
+ osmo_fd_unregister(&conn->wqueue.bfd);
+ close(conn->wqueue.bfd.fd);
+ conn->wqueue.bfd.fd = -1;
+ }
+
+ osmo_timer_del(&conn->timer);
+}
diff --git a/src/osmo_client_vty.c b/src/osmo_client_vty.c
index 88b7140..5cf3aa1 100644
--- a/src/osmo_client_vty.c
+++ b/src/osmo_client_vty.c
@@ -411,6 +411,23 @@ DEFUN(cfg_pcap_store,
return CMD_SUCCESS;
}
+DEFUN(cfg_no_pcap_store,
+ cfg_no_pcap_store_cmd,
+ "no pcap-store-connection .NAME",
+ NO_STR "Configure additional PCAP store server\n" "Name of server\n")
+{
+ struct osmo_pcap_client_conn *conn;
+ conn = osmo_client_find_conn(pcap_client, argv[0]);
+ if (!conn) {
+ vty_out(vty, "%%Failed to find connection %s%ss",
+ argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ osmo_client_free(conn);
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_client_connect,
cfg_client_connect_cmd,
"connect",
@@ -422,6 +439,17 @@ DEFUN(cfg_client_connect,
return CMD_SUCCESS;
}
+DEFUN(cfg_client_disconnect,
+ cfg_client_disconnect_cmd,
+ "disconnect",
+ "Disconnect to the storage\n")
+{
+ struct osmo_pcap_client_conn *conn = get_conn(vty);
+
+ osmo_client_disconnect(conn);
+ return CMD_SUCCESS;
+}
+
int vty_client_init(struct osmo_pcap_client *pcap)
{
install_element(CONFIG_NODE, &cfg_client_cmd);
@@ -460,6 +488,7 @@ int vty_client_init(struct osmo_pcap_client *pcap)
/* per server confiug*/
install_element(CLIENT_NODE, &cfg_pcap_store_cmd);
+ install_element(CLIENT_NODE, &cfg_no_pcap_store_cmd);
install_element(CLIENT_SERVER_NODE, &cfg_server_ip_cmd);
install_element(CLIENT_SERVER_NODE, &cfg_server_port_cmd);
install_element(CLIENT_SERVER_NODE, &cfg_enable_tls_cmd);
@@ -478,6 +507,7 @@ int vty_client_init(struct osmo_pcap_client *pcap)
install_element(CLIENT_SERVER_NODE, &cfg_no_tls_priority_cmd);
install_element(CLIENT_SERVER_NODE, &cfg_tls_log_level_cmd);
install_element(CLIENT_SERVER_NODE, &cfg_client_connect_cmd);
+ install_element(CLIENT_SERVER_NODE, &cfg_client_disconnect_cmd);
return 0;
}