aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo_client_vty.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-05-31 17:42:13 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-05-31 17:42:53 +0200
commit3b9b38ca688b422894470618e8f017ea74dee0e1 (patch)
tree6e26491852ce7981226d2e5883098c8c288336ab /src/osmo_client_vty.c
parent47169baa6edc040cd7f36174a86f565a8f403611 (diff)
osmo-pcap-client: Work on the client code, be able to open the device
Add vty code to allow changing the device, this will just attempt to open and close the device. Nothing else is done.
Diffstat (limited to 'src/osmo_client_vty.c')
-rw-r--r--src/osmo_client_vty.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/osmo_client_vty.c b/src/osmo_client_vty.c
index b262e8d..3af4dfc 100644
--- a/src/osmo_client_vty.c
+++ b/src/osmo_client_vty.c
@@ -21,3 +21,111 @@
*/
#include <osmo-pcap/osmo_pcap_client.h>
+#include <osmo-pcap/common.h>
+
+#include <osmocom/core/talloc.h>
+
+#include <stdlib.h>
+
+
+#define PCAP_STRING "PCAP related functions\n"
+#define SERVER_STRING "Server string\n"
+
+static struct cmd_node client_node = {
+ CLIENT_NODE,
+ "%s(client)#",
+ 1,
+};
+
+DEFUN(cfg_client,
+ cfg_client_cmd,
+ "client",
+ "Enter the client configuration\n")
+{
+ vty->node = CLIENT_NODE;
+ return CMD_SUCCESS;
+}
+
+static int config_write_client(struct vty *vty)
+{
+ vty_out(vty, "client%s", VTY_NEWLINE);
+ vty_out(vty, " pcap device %s%s",
+ pcap_client->device, VTY_NEWLINE);
+ vty_out(vty, " pcap filter %s%s",
+ pcap_client->filter_string, VTY_NEWLINE);
+ vty_out(vty, " pcap detect-loop %d%s",
+ pcap_client->filter_itself, VTY_NEWLINE);
+ vty_out(vty, " server ip %s%s",
+ pcap_client->srv_ip, VTY_NEWLINE);
+ vty_out(vty, " server port %d%s",
+ pcap_client->srv_port, VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_client_device,
+ cfg_client_device_cmd,
+ "pcap device NAME",
+ PCAP_STRING "the device to filter\n" "device name\n")
+{
+ osmo_client_capture(pcap_client, argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_client_filter,
+ cfg_client_filter_cmd,
+ "pcap filter NAME",
+ PCAP_STRING "filter string in pcap syntax\n" "filter\n")
+{
+ if (osmo_client_filter(pcap_client, argv[0]) != 0) {
+ vty_out(vty, "Failed to set the device.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_client_loop,
+ cfg_client_loop_cmd,
+ "pcap detect-loop (0|1)",
+ PCAP_STRING "detect loop and drop\n" "No detection\n" "Detection\n")
+{
+ pcap_client->filter_itself = atoi(argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_server_ip,
+ cfg_server_ip_cmd,
+ "server ip A.B.C.D",
+ SERVER_STRING "IP Address of the server\n" "IP\n")
+{
+ talloc_free(pcap_client->srv_ip);
+ pcap_client->srv_ip = talloc_strdup(pcap_client, argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_server_port,
+ cfg_server_port_cmd,
+ "server port <1-65535>",
+ SERVER_STRING "Port\n" "Number\n")
+{
+ pcap_client->srv_port = atoi(argv[0]);
+ return CMD_SUCCESS;
+}
+
+
+int vty_client_init(struct osmo_pcap_client *pcap)
+{
+ install_element(CONFIG_NODE, &cfg_client_cmd);
+ install_node(&client_node, config_write_client);
+ install_default(CLIENT_NODE);
+
+ install_element(CLIENT_NODE, &cfg_client_device_cmd);
+ install_element(CLIENT_NODE, &cfg_client_filter_cmd);
+ install_element(CLIENT_NODE, &cfg_client_loop_cmd);
+
+ install_element(CLIENT_NODE, &cfg_server_ip_cmd);
+ install_element(CLIENT_NODE, &cfg_server_port_cmd);
+
+ return 0;
+}