blob: 3af4dfcdbcb8f42af39bea3d092ddc09df8b3c00 [file] [log] [blame]
Holger Hans Peter Freyther530ecc02011-05-31 15:47:44 +02001/*
2 * osmo-pcap-client code
3 *
4 * (C) 2011 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2011 by On-Waves
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <osmo-pcap/osmo_pcap_client.h>
Holger Hans Peter Freyther3b9b38c2011-05-31 17:42:13 +020024#include <osmo-pcap/common.h>
25
26#include <osmocom/core/talloc.h>
27
28#include <stdlib.h>
29
30
31#define PCAP_STRING "PCAP related functions\n"
32#define SERVER_STRING "Server string\n"
33
34static struct cmd_node client_node = {
35 CLIENT_NODE,
36 "%s(client)#",
37 1,
38};
39
40DEFUN(cfg_client,
41 cfg_client_cmd,
42 "client",
43 "Enter the client configuration\n")
44{
45 vty->node = CLIENT_NODE;
46 return CMD_SUCCESS;
47}
48
49static int config_write_client(struct vty *vty)
50{
51 vty_out(vty, "client%s", VTY_NEWLINE);
52 vty_out(vty, " pcap device %s%s",
53 pcap_client->device, VTY_NEWLINE);
54 vty_out(vty, " pcap filter %s%s",
55 pcap_client->filter_string, VTY_NEWLINE);
56 vty_out(vty, " pcap detect-loop %d%s",
57 pcap_client->filter_itself, VTY_NEWLINE);
58 vty_out(vty, " server ip %s%s",
59 pcap_client->srv_ip, VTY_NEWLINE);
60 vty_out(vty, " server port %d%s",
61 pcap_client->srv_port, VTY_NEWLINE);
62
63 return CMD_SUCCESS;
64}
65
66DEFUN(cfg_client_device,
67 cfg_client_device_cmd,
68 "pcap device NAME",
69 PCAP_STRING "the device to filter\n" "device name\n")
70{
71 osmo_client_capture(pcap_client, argv[0]);
72 return CMD_SUCCESS;
73}
74
75DEFUN(cfg_client_filter,
76 cfg_client_filter_cmd,
77 "pcap filter NAME",
78 PCAP_STRING "filter string in pcap syntax\n" "filter\n")
79{
80 if (osmo_client_filter(pcap_client, argv[0]) != 0) {
81 vty_out(vty, "Failed to set the device.%s", VTY_NEWLINE);
82 return CMD_WARNING;
83 }
84
85 return CMD_SUCCESS;
86}
87
88DEFUN(cfg_client_loop,
89 cfg_client_loop_cmd,
90 "pcap detect-loop (0|1)",
91 PCAP_STRING "detect loop and drop\n" "No detection\n" "Detection\n")
92{
93 pcap_client->filter_itself = atoi(argv[0]);
94 return CMD_SUCCESS;
95}
96
97DEFUN(cfg_server_ip,
98 cfg_server_ip_cmd,
99 "server ip A.B.C.D",
100 SERVER_STRING "IP Address of the server\n" "IP\n")
101{
102 talloc_free(pcap_client->srv_ip);
103 pcap_client->srv_ip = talloc_strdup(pcap_client, argv[0]);
104 return CMD_SUCCESS;
105}
106
107DEFUN(cfg_server_port,
108 cfg_server_port_cmd,
109 "server port <1-65535>",
110 SERVER_STRING "Port\n" "Number\n")
111{
112 pcap_client->srv_port = atoi(argv[0]);
113 return CMD_SUCCESS;
114}
115
116
117int vty_client_init(struct osmo_pcap_client *pcap)
118{
119 install_element(CONFIG_NODE, &cfg_client_cmd);
120 install_node(&client_node, config_write_client);
121 install_default(CLIENT_NODE);
122
123 install_element(CLIENT_NODE, &cfg_client_device_cmd);
124 install_element(CLIENT_NODE, &cfg_client_filter_cmd);
125 install_element(CLIENT_NODE, &cfg_client_loop_cmd);
126
127 install_element(CLIENT_NODE, &cfg_server_ip_cmd);
128 install_element(CLIENT_NODE, &cfg_server_port_cmd);
129
130 return 0;
131}