blob: 2a40ef3edee4abf0da2c7630c2d96a89fbbe6268 [file] [log] [blame]
Holger Hans Peter Freyther13619dd2011-05-31 22:09:08 +02001/*
2 * osmo-pcap-server 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_server.h>
Holger Hans Peter Freyther9f6127f2011-05-31 22:52:41 +020024#include <osmo-pcap/common.h>
Holger Hans Peter Freyther13619dd2011-05-31 22:09:08 +020025
Holger Hans Peter Freyther9f6127f2011-05-31 22:52:41 +020026#include <osmocom/core/talloc.h>
27
28
29#define SERVER_STR "Server settings\n"
30#define CLIENT_STR "Client\n"
31
32static struct cmd_node server_node = {
33 SERVER_NODE,
34 "%s(server)#",
35 1,
36};
37
38static int config_write_server(struct vty *vty)
39{
40 struct osmo_pcap_conn *conn;
41
42 vty_out(vty, "server%s", VTY_NEWLINE);
43
44 if (pcap_server->base_path)
45 vty_out(vty, " base-path %s%s", pcap_server->base_path, VTY_NEWLINE);
46 if (pcap_server->addr)
47 vty_out(vty, " server ip %s%s", pcap_server->addr, VTY_NEWLINE);
48 if (pcap_server->port > 0)
49 vty_out(vty, "server port %d%s", pcap_server->port, VTY_NEWLINE);
50
51 llist_for_each_entry(conn, &pcap_server->conn, entry) {
52 vty_out(vty, " client %s %s%s",
53 conn->name, conn->remote_host, VTY_NEWLINE);
54 }
55
56 return CMD_SUCCESS;
57}
58
59DEFUN(cfg_server,
60 cfg_server_cmd,
61 "server",
62 "Enter the server configuration\n")
63{
64 vty->node = SERVER_NODE;
65 return CMD_SUCCESS;
66}
67
68DEFUN(cfg_server_base,
69 cfg_server_base_cmd,
70 "base-path PATH",
71 "Base path for log files\n" "Path\n")
72{
73 talloc_free(pcap_server->base_path);
74 pcap_server->base_path = talloc_strdup(pcap_server, argv[0]);
75 return CMD_SUCCESS;
76}
77
78DEFUN(cfg_server_ip,
79 cfg_server_ip_cmd,
80 "server ip A.B.C.D",
81 SERVER_STR "Listen\n" "IP Address\n")
82{
83 talloc_free(pcap_server->addr);
84 pcap_server->addr = talloc_strdup(pcap_server, argv[0]);
85 return CMD_SUCCESS;
86}
87
88DEFUN(cfg_server_port,
89 cfg_server_port_cmd,
90 "server port <1-65535>",
91 SERVER_STR "Port\n" "Port Number\n")
92{
93 pcap_server->port = atoi(argv[0]);
94 return CMD_SUCCESS;
95}
96
97DEFUN(cfg_server_client,
98 cfg_server_client_cmd,
99 "client NAME A.B.C.D",
100 CLIENT_STR "Remote name used in filenames\n" "IP of the remote\n")
101{
102 struct osmo_pcap_conn *conn;
103 conn = osmo_pcap_server_find(pcap_server, argv[0]);
104 if (!conn) {
105 vty_out(vty, "Failed to create a pcap server.\n");
106 return CMD_WARNING;
107 }
108
109 talloc_free(conn->remote_host);
Holger Hans Peter Freyther80b8b602011-05-31 23:42:20 +0200110 conn->remote_host = talloc_strdup(pcap_server, argv[1]);
111 inet_aton(argv[1], &conn->remote_addr);
Holger Hans Peter Freyther9f6127f2011-05-31 22:52:41 +0200112
113 return CMD_SUCCESS;
114}
115
116DEFUN(cfg_server_no_client,
117 cfg_server_no_client_cmd,
118 "no client NAME",
119 NO_STR CLIENT_STR "The name\n")
120{
121 struct osmo_pcap_conn *conn;
122 conn = osmo_pcap_server_find(pcap_server, argv[0]);
123 if (!conn) {
124 vty_out(vty, "Failed to create a pcap server.\n");
125 return CMD_WARNING;
126 }
127
128 osmo_pcap_server_delete(conn);
129 return CMD_SUCCESS;
130}
Holger Hans Peter Freyther13619dd2011-05-31 22:09:08 +0200131
132void vty_server_init(struct osmo_pcap_server *server)
133{
Holger Hans Peter Freyther9f6127f2011-05-31 22:52:41 +0200134 install_element(CONFIG_NODE, &cfg_server_cmd);
135 install_node(&server_node, config_write_server);
136 install_default(SERVER_NODE);
137
138 install_element(SERVER_NODE, &cfg_server_base_cmd);
139 install_element(SERVER_NODE, &cfg_server_ip_cmd);
140 install_element(SERVER_NODE, &cfg_server_port_cmd);
141
142 install_element(SERVER_NODE, &cfg_server_client_cmd);
143 install_element(SERVER_NODE, &cfg_server_no_client_cmd);
Holger Hans Peter Freyther13619dd2011-05-31 22:09:08 +0200144}