aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-08-04 16:14:38 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-08-04 16:14:38 +0200
commit2899428be2aac2fb1e5edd6e8c90174bb1dd0a36 (patch)
tree6b5570f9d3940a6f5a5f36a3151ec0931b16dc76
parent9646754e1f82d3b846304dc5803d520641064ba4 (diff)
server: Add a config knob to not store the pcap stream
We might only want to centralize the data streams but handle the data differently. This will be combined with an upcoming ZeroMQ publisher feature to broadcast all events out. Change-Id: I12c6bf16310820d882fa28c6930931650475e0bb
-rw-r--r--include/osmo-pcap/osmo_pcap_server.h1
-rw-r--r--src/osmo_server_network.c13
-rw-r--r--src/osmo_server_vty.c24
3 files changed, 32 insertions, 6 deletions
diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h
index edb29d3..37628ab 100644
--- a/include/osmo-pcap/osmo_pcap_server.h
+++ b/include/osmo-pcap/osmo_pcap_server.h
@@ -52,6 +52,7 @@ struct osmo_pcap_conn {
/* name */
char *name;
char *remote_host;
+ int no_store;
struct in_addr remote_addr;
/* Remote connection */
diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c
index 7127401..d530ef7 100644
--- a/src/osmo_server_network.c
+++ b/src/osmo_server_network.c
@@ -62,6 +62,12 @@ static void restart_pcap(struct osmo_pcap_conn *conn)
conn->local_fd = -1;
}
+ /* omit any storing/creation of the file */
+ if (conn->no_store) {
+ conn->last_write = *tm;
+ return;
+ }
+
filename = talloc_asprintf(conn, "%s/trace-%s-%d%.2d%.2d_%.2d%.2d%.2d.pcap",
conn->server->base_path, conn->name,
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
@@ -103,7 +109,7 @@ static void link_data(struct osmo_pcap_conn *conn, struct osmo_pcap_data *data)
}
hdr = (struct pcap_file_header *) &data->data[0];
- if (conn->local_fd < 0) {
+ if (!conn->no_store && conn->local_fd < 0) {
conn->file_hdr = *hdr;
restart_pcap(conn);
} else if (memcmp(&conn->file_hdr, hdr, sizeof(*hdr)) != 0) {
@@ -121,6 +127,11 @@ static void write_data(struct osmo_pcap_conn *conn, struct osmo_pcap_data *data)
struct tm *tm = localtime(&now);
int rc;
+ if (conn->no_store) {
+ conn->last_write = *tm;
+ return;
+ }
+
if (conn->local_fd < -1) {
LOGP(DSERVER, LOGL_ERROR, "No file is open. close connection.\n");
close_connection(conn);
diff --git a/src/osmo_server_vty.c b/src/osmo_server_vty.c
index 2829620..8822bac 100644
--- a/src/osmo_server_vty.c
+++ b/src/osmo_server_vty.c
@@ -1,7 +1,7 @@
/*
* osmo-pcap-server code
*
- * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2011-2016 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2011 by On-Waves
* All Rights Reserved
*
@@ -25,6 +25,8 @@
#include <osmocom/core/talloc.h>
+#include <unistd.h>
+
#define SERVER_STR "Server settings\n"
#define CLIENT_STR "Client\n"
@@ -51,8 +53,10 @@ static int config_write_server(struct vty *vty)
(unsigned long long) pcap_server->max_size, VTY_NEWLINE);
llist_for_each_entry(conn, &pcap_server->conn, entry) {
- vty_out(vty, " client %s %s%s",
- conn->name, conn->remote_host, VTY_NEWLINE);
+ vty_out(vty, " client %s %s%s%s",
+ conn->name, conn->remote_host,
+ conn->no_store ? " no-store" : "",
+ VTY_NEWLINE);
}
return CMD_SUCCESS;
@@ -107,8 +111,8 @@ DEFUN(cfg_server_max_size,
DEFUN(cfg_server_client,
cfg_server_client_cmd,
- "client NAME A.B.C.D",
- CLIENT_STR "Remote name used in filenames\n" "IP of the remote\n")
+ "client NAME A.B.C.D [no-store]",
+ CLIENT_STR "Remote name used in filenames\n" "IP of the remote\n" "Do not store traffic\n")
{
struct osmo_pcap_conn *conn;
conn = osmo_pcap_server_find(pcap_server, argv[0]);
@@ -121,6 +125,16 @@ DEFUN(cfg_server_client,
conn->remote_host = talloc_strdup(pcap_server, argv[1]);
inet_aton(argv[1], &conn->remote_addr);
+ /* Checking no-store and maybe closing a pcap file */
+ if (argc >= 3) {
+ if (conn->local_fd >= 0) {
+ close(conn->local_fd);
+ conn->local_fd = -1;
+ }
+ conn->no_store = 1;
+ } else
+ conn->no_store = 0;
+
return CMD_SUCCESS;
}