pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcap/+/39269?usp=email )
Change subject: server: Simplify (store|no-store) feature ......................................................................
server: Simplify (store|no-store) feature
Having a bool variable with a negation in its name just makes everything more complex for no good reason.
Change-Id: If0b76e7a922c26859d04d339bcc3bdccd66a6922 --- M include/osmo-pcap/osmo_pcap_server.h M src/osmo_server_network.c M src/osmo_server_vty.c 3 files changed, 21 insertions(+), 27 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-pcap refs/changes/69/39269/1
diff --git a/include/osmo-pcap/osmo_pcap_server.h b/include/osmo-pcap/osmo_pcap_server.h index bed1cb5..dad81d3 100644 --- a/include/osmo-pcap/osmo_pcap_server.h +++ b/include/osmo-pcap/osmo_pcap_server.h @@ -79,7 +79,7 @@ /* name */ char *name; char *remote_host; - int no_store; + bool store; struct in_addr remote_addr;
/* Remote connection */ diff --git a/src/osmo_server_network.c b/src/osmo_server_network.c index a784af2..d55b30d 100644 --- a/src/osmo_server_network.c +++ b/src/osmo_server_network.c @@ -254,7 +254,7 @@ osmo_pcap_server_close_trace(conn);
/* omit any storing/creation of the file */ - if (conn->no_store) { + if (!conn->store) { update_last_write(conn, now); talloc_free(conn->curr_filename); conn->curr_filename = NULL; @@ -309,10 +309,12 @@ return -1; }
- if (!conn->no_store && conn->local_fd < 0) { + if (conn->store && conn->local_fd < 0) { + /* First received link hdr in conn */ conn->file_hdr = *hdr; restart_pcap(conn); } else if (memcmp(&conn->file_hdr, hdr, sizeof(*hdr)) != 0) { + /* Client changed the link hdr in conn */ conn->file_hdr = *hdr; restart_pcap(conn); } @@ -467,7 +469,7 @@
client_data(conn, data);
- if (conn->no_store) { + if (!conn->store) { update_last_write(conn, now); return 1; } diff --git a/src/osmo_server_vty.c b/src/osmo_server_vty.c index 1e8e05c..b976857 100644 --- a/src/osmo_server_vty.c +++ b/src/osmo_server_vty.c @@ -128,7 +128,7 @@ llist_for_each_entry(conn, &pcap_server->conn, entry) { vty_out(vty, " client %s %s%s%s%s", conn->name, conn->remote_host, - conn->no_store ? " no-store" : " store", + conn->store ? " store" : " no-store", conn->tls_use ? " tls" : "", VTY_NEWLINE); } @@ -351,7 +351,7 @@ static int manage_client(struct osmo_pcap_server *pcap_server, struct vty *vty, const char *name, const char *remote_host, - bool no_store, bool use_tls) + bool store, bool use_tls) { struct osmo_pcap_conn *conn; conn = osmo_pcap_server_find(pcap_server, name); @@ -364,12 +364,10 @@ conn->remote_host = talloc_strdup(pcap_server, remote_host); inet_aton(remote_host, &conn->remote_addr);
- /* Checking no-store and maybe closing a pcap file */ - if (no_store) { + /* Checking store and maybe closing a pcap file */ + if (!store) osmo_pcap_server_close_trace(conn); - conn->no_store = 1; - } else - conn->no_store = 0; + conn->store = store;
if (use_tls) { /* force moving to TLS */ @@ -383,25 +381,20 @@ return CMD_SUCCESS; }
- DEFUN(cfg_server_client, cfg_server_client_cmd, - "client NAME A.B.C.D [no-store] [tls]", - CLIENT_STR "Remote name used in filenames\n" - "IP of the remote\n" "Do not store traffic\n" + "client NAME A.B.C.D [(store|no-store)] [tls]", + CLIENT_STR + "Remote name used in filenames\n" + "IP of the remote\n" + "Store traffic\n" "Do not store traffic\n" "Use Transport Level Security\n") { - return manage_client(pcap_server, vty, argv[0], argv[1], argc >= 3, argc >= 4); -} - -DEFUN(cfg_server_client_store_tls, - cfg_server_client_store_tls_cmd, - "client NAME A.B.C.D store [tls]", - CLIENT_STR "Remote name used in filenames\n" - "IP of the remote\n" "Do not store traffic\n" - "Use Transport Level Security\n") -{ - return manage_client(pcap_server, vty, argv[0], argv[1], false, argc >= 3); + bool store = true; + if (argc >= 3 && strcmp(argv[2], "no-store") == 0) + store = false; + bool tls = argc >= 4; + return manage_client(pcap_server, vty, argv[0], argv[1], store, tls); }
DEFUN(cfg_server_no_client, @@ -734,6 +727,5 @@ install_element(SERVER_NODE, &cfg_tls_dh_pkcs3_cmd);
install_element(SERVER_NODE, &cfg_server_client_cmd); - install_element(SERVER_NODE, &cfg_server_client_store_tls_cmd); install_element(SERVER_NODE, &cfg_server_no_client_cmd); }