From 3b9b38ca688b422894470618e8f017ea74dee0e1 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 31 May 2011 17:42:13 +0200 Subject: 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. --- src/osmo_client_vty.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'src/osmo_client_vty.c') 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 +#include + +#include + +#include + + +#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; +} -- cgit v1.2.3