mirror of https://gerrit.osmocom.org/osmo-pcap
client: Add pcap snaplen VTY cmd
Change-Id: I84fda9f27b725e031c218187ab679392dfa7ec3d
This commit is contained in:
parent
168949e119
commit
f946fa21ee
|
@ -63,4 +63,6 @@ extern int osmopcap_is_config_node(struct vty *vty, int node);
|
|||
#define MAXIMUM_SNAPLEN 262144
|
||||
#endif
|
||||
|
||||
#define DEFAULT_SNAPLEN 9000
|
||||
|
||||
#endif
|
||||
|
|
|
@ -94,6 +94,7 @@ struct osmo_pcap_client {
|
|||
char *filter_string;
|
||||
int filter_itself;
|
||||
int gprs_filtering;
|
||||
int snaplen;
|
||||
struct osmo_fd fd;
|
||||
|
||||
struct osmo_pcap_client_conn conn;
|
||||
|
@ -105,6 +106,7 @@ struct osmo_pcap_client {
|
|||
|
||||
extern struct osmo_pcap_client *pcap_client;
|
||||
|
||||
struct osmo_pcap_client *osmo_pcap_client_alloc(void *tall_ctx);
|
||||
int vty_client_init(struct osmo_pcap_client *);
|
||||
|
||||
int osmo_client_capture(struct osmo_pcap_client *client, const char *device);
|
||||
|
|
|
@ -287,7 +287,9 @@ int osmo_client_capture(struct osmo_pcap_client *client, const char *device)
|
|||
return 1;
|
||||
}
|
||||
|
||||
client->handle = pcap_open_live(client->device, 9000, 0,
|
||||
LOGP(DCLIENT, LOGL_INFO, "Opening device %s for capture with snaplen %zu\n",
|
||||
client->device, (size_t) client->snaplen);
|
||||
client->handle = pcap_open_live(client->device, client->snaplen, 0,
|
||||
1000, client->errbuf);
|
||||
if (!client->handle) {
|
||||
LOGP(DCLIENT, LOGL_ERROR,
|
||||
|
@ -346,6 +348,16 @@ void osmo_client_conn_init(struct osmo_pcap_client_conn *conn,
|
|||
conn->wqueue.bfd.fd = -1;
|
||||
}
|
||||
|
||||
struct osmo_pcap_client *osmo_pcap_client_alloc(void *tall_ctx)
|
||||
{
|
||||
struct osmo_pcap_client *client;
|
||||
client = talloc_zero(tall_ctx, struct osmo_pcap_client);
|
||||
if (!client)
|
||||
return NULL;
|
||||
client->fd.fd = -1;
|
||||
client->snaplen = DEFAULT_SNAPLEN;
|
||||
return client;
|
||||
}
|
||||
|
||||
void osmo_client_free(struct osmo_pcap_client_conn *conn)
|
||||
{
|
||||
|
|
|
@ -212,12 +212,11 @@ int main(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
pcap_client = talloc_zero(tall_cli_ctx, struct osmo_pcap_client);
|
||||
pcap_client = osmo_pcap_client_alloc(tall_cli_ctx);
|
||||
if (!pcap_client) {
|
||||
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate osmo_pcap_client.\n");
|
||||
exit(1);
|
||||
}
|
||||
pcap_client->fd.fd = -1;
|
||||
vty_client_init(pcap_client);
|
||||
|
||||
/* initialize the queue */
|
||||
|
|
|
@ -169,14 +169,14 @@ void osmo_client_send_data(struct osmo_pcap_client_conn *conn,
|
|||
struct msgb *msg;
|
||||
int offset, ip_len;
|
||||
|
||||
if (in_hdr->caplen > 9000) {
|
||||
if (in_hdr->len > in_hdr->caplen) {
|
||||
LOGP(DCLIENT, LOGL_ERROR,
|
||||
"Capture len too big %zu\n", (size_t) in_hdr->caplen);
|
||||
"Recording truncated packet, len %zu > snaplen %zu\n",
|
||||
(size_t) in_hdr->len, (size_t) in_hdr->caplen);
|
||||
rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_2BIG]);
|
||||
return;
|
||||
}
|
||||
|
||||
msg = msgb_alloc(9000 + sizeof(*om_hdr) + sizeof(*hdr), "data-data");
|
||||
msg = msgb_alloc(in_hdr->caplen + sizeof(*om_hdr) + sizeof(*hdr), "data-data");
|
||||
if (!msg) {
|
||||
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate.\n");
|
||||
rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_NOMEM]);
|
||||
|
@ -239,7 +239,7 @@ void osmo_client_send_link(struct osmo_pcap_client_conn *conn)
|
|||
return;
|
||||
}
|
||||
|
||||
msg = msgb_alloc(9000 + sizeof(*om_hdr) + sizeof(*hdr), "link-data");
|
||||
msg = msgb_alloc(conn->client->snaplen + sizeof(*om_hdr) + sizeof(*hdr), "link-data");
|
||||
if (!msg) {
|
||||
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate data.\n");
|
||||
return;
|
||||
|
@ -256,7 +256,7 @@ void osmo_client_send_link(struct osmo_pcap_client_conn *conn)
|
|||
hdr->version_minor = 4;
|
||||
hdr->thiszone = 0;
|
||||
hdr->sigfigs = 0;
|
||||
hdr->snaplen = MAXIMUM_SNAPLEN;
|
||||
hdr->snaplen = conn->client->snaplen;
|
||||
hdr->linktype = pcap_datalink(conn->client->handle);
|
||||
|
||||
write_data(conn, msg);
|
||||
|
|
|
@ -125,7 +125,9 @@ static int config_write_client(struct vty *vty)
|
|||
if (pcap_client->device)
|
||||
vty_out(vty, " pcap device %s%s",
|
||||
pcap_client->device, VTY_NEWLINE);
|
||||
|
||||
if (pcap_client->snaplen != DEFAULT_SNAPLEN)
|
||||
vty_out(vty, " pcap snaplen %d%s",
|
||||
pcap_client->snaplen, VTY_NEWLINE);
|
||||
if (pcap_client->filter_string)
|
||||
vty_out(vty, " pcap filter %s%s",
|
||||
pcap_client->filter_string, VTY_NEWLINE);
|
||||
|
@ -148,6 +150,19 @@ DEFUN(cfg_client_device,
|
|||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_client_snaplen,
|
||||
cfg_client_snaplen_cmd,
|
||||
"pcap snaplen <1-262144>", /* MAXIMUM_SNAPLEN */
|
||||
PCAP_STRING "snapshot length\n" "Bytes\n")
|
||||
{
|
||||
if (pcap_client->handle) {
|
||||
vty_out(vty, "'pcap snaplen' must be set before 'pcap device' to take effect!%s", VTY_NEWLINE);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
pcap_client->snaplen = atoi(argv[0]);
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_client_add_gprs,
|
||||
cfg_client_add_gprs_cmd,
|
||||
"pcap add-filter gprs",
|
||||
|
@ -512,6 +527,7 @@ int vty_client_init(struct osmo_pcap_client *pcap)
|
|||
install_node(&server_node, config_write_server);
|
||||
|
||||
install_element(CLIENT_NODE, &cfg_client_device_cmd);
|
||||
install_element(CLIENT_NODE, &cfg_client_snaplen_cmd);
|
||||
install_element(CLIENT_NODE, &cfg_client_filter_cmd);
|
||||
install_element(CLIENT_NODE, &cfg_client_loop_cmd);
|
||||
|
||||
|
|
Loading…
Reference in New Issue