* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config.h>
#include <glib.h>
-#include <wsutil/wsjsmn.h>
+#include <wsutil/wsjson.h>
#include <wsutil/ws_printf.h>
#include <file.h>
#include <ui/ssl_key_export.h>
+#include <ui/io_graph_item.h>
#include <epan/stats_tree_priv.h>
#include <epan/stat_tap_ui.h>
#include <epan/conversation_table.h>
#include <ui/voip_calls.h>
#include <ui/rtp_stream.h>
#include <ui/tap-rtp-common.h>
+#include <ui/tap-rtp-analysis.h>
#include <epan/to_str.h>
#include <epan/addr_resolv.h>
# include <codecs/speex/speex_resampler.h>
#endif /* HAVE_SPEEXDSP */
-#ifdef HAVE_GEOIP
-# include <GeoIP.h>
-# include <epan/geoip_db.h>
-# include <wsutil/pint.h>
-#endif
+#include <epan/maxmind_db.h>
-#include <wsutil/glib-compat.h>
+#include <wsutil/pint.h>
#include <wsutil/strtoi.h>
+#include "globals.h"
+
#include "sharkd.h"
+struct sharkd_filter_item
+{
+ guint8 *filtered;
+};
+
+static GHashTable *filter_table = NULL;
+
static gboolean
json_unescape_str(char *input)
{
- return wsjsmn_unescape_json_string(input, input);
+ return wsjson_unescape_json_string(input, input);
}
static const char *
putchar('"');
}
-struct filter_item
+static void
+sharkd_session_filter_free(gpointer data)
{
- struct filter_item *next;
-
- char *filter;
- guint8 *filtered;
-};
+ struct sharkd_filter_item *l = (struct sharkd_filter_item *) data;
-static struct filter_item *filter_list = NULL;
+ g_free(l->filtered);
+ g_free(l);
+}
static const guint8 *
sharkd_session_filter_data(const char *filter)
{
- struct filter_item *l;
-
- for (l = filter_list; l; l = l->next)
- {
- if (!strcmp(l->filter, filter))
- return l->filtered;
- }
+ struct sharkd_filter_item *l;
+ l = (struct sharkd_filter_item *) g_hash_table_lookup(filter_table, filter);
+ if (!l)
{
guint8 *filtered = NULL;
if (ret == -1)
return NULL;
- l = (struct filter_item *) g_malloc(sizeof(struct filter_item));
- l->filter = g_strdup(filter);
+ l = (struct sharkd_filter_item *) g_malloc(sizeof(struct sharkd_filter_item));
l->filtered = filtered;
- l->next = filter_list;
- filter_list = l;
-
- return filtered;
+ g_hash_table_insert(filter_table, g_strdup(filter), l);
}
-}
-struct sharkd_rtp_match
-{
- guint32 addr_src, addr_dst;
- address src_addr;
- address dst_addr;
- guint16 src_port;
- guint16 dst_port;
- guint32 ssrc;
-};
+ return l->filtered;
+}
static gboolean
-sharkd_rtp_match_init(struct sharkd_rtp_match *req, const char *init_str)
+sharkd_rtp_match_init(rtpstream_id_t *id, const char *init_str)
{
gboolean ret = FALSE;
char **arr;
+ guint32 tmp_addr_src, tmp_addr_dst;
+ address tmp_src_addr, tmp_dst_addr;
+
+ memset(id, 0, sizeof(*id));
arr = g_strsplit(init_str, "_", 7); /* pass larger value, so we'll catch incorrect input :) */
if (g_strv_length(arr) != 5)
goto fail;
/* TODO, for now only IPv4 */
- if (!get_host_ipaddr(arr[0], &req->addr_src))
+ if (!get_host_ipaddr(arr[0], &tmp_addr_src))
goto fail;
- if (!ws_strtou16(arr[1], NULL, &req->src_port))
+ if (!ws_strtou16(arr[1], NULL, &id->src_port))
goto fail;
- if (!get_host_ipaddr(arr[2], &req->addr_dst))
+ if (!get_host_ipaddr(arr[2], &tmp_addr_dst))
goto fail;
- if (!ws_strtou16(arr[3], NULL, &req->dst_port))
+ if (!ws_strtou16(arr[3], NULL, &id->dst_port))
goto fail;
- if (!ws_hexstrtou32(arr[4], NULL, &req->ssrc))
+ if (!ws_hexstrtou32(arr[4], NULL, &id->ssrc))
goto fail;
- set_address(&req->src_addr, AT_IPv4, 4, &req->addr_src);
- set_address(&req->dst_addr, AT_IPv4, 4, &req->addr_dst);
+ set_address(&tmp_src_addr, AT_IPv4, 4, &tmp_addr_src);
+ copy_address(&id->src_addr, &tmp_src_addr);
+ set_address(&tmp_dst_addr, AT_IPv4, 4, &tmp_addr_dst);
+ copy_address(&id->dst_addr, &tmp_dst_addr);
+
ret = TRUE;
fail:
return ret;
}
-static gboolean
-sharkd_rtp_match_check(const struct sharkd_rtp_match *req, const packet_info *pinfo, const struct _rtp_info *rtp_info)
-{
- if (rtp_info->info_sync_src == req->ssrc &&
- pinfo->srcport == req->src_port &&
- pinfo->destport == req->dst_port &&
- addresses_equal(&pinfo->src, &req->src_addr) &&
- addresses_equal(&pinfo->dst, &req->dst_addr))
- {
- return TRUE;
- }
-
- return FALSE;
-}
-
static gboolean
sharkd_session_process_info_nstat_cb(const void *key, void *value, void *userdata)
{
- stat_tap_table_ui *new_stat_tap = (stat_tap_table_ui *) value;
+ stat_tap_table_ui *stat_tap = (stat_tap_table_ui *) value;
int *pi = (int *) userdata;
printf("%s{", (*pi) ? "," : "");
- printf("\"name\":\"%s\"", new_stat_tap->title);
+ printf("\"name\":\"%s\"", stat_tap->title);
printf(",\"tap\":\"nstat:%s\"", (const char *) key);
printf("}");
printf(",\"nstat\":[");
i = 0;
- new_stat_tap_iterate_tables(sharkd_session_process_info_nstat_cb, &i);
+ stat_tap_iterate_tables(sharkd_session_process_info_nstat_cb, &i);
printf("]");
printf(",\"convs\":[");
g_free(name);
}
- if (cfile.frame_set_info.wth)
+ if (cfile.provider.wth)
{
- gint64 file_size = wtap_file_size(cfile.frame_set_info.wth, NULL);
+ gint64 file_size = wtap_file_size(cfile.provider.wth, NULL);
if (file_size > 0)
printf(",\"filesize\":%" G_GINT64_FORMAT, file_size);
printf(",\"protocols\":[");
for (framenum = 1; framenum <= cfile.count; framenum++)
- sharkd_dissect_request(framenum, &sharkd_session_process_analyse_cb, 0, 0, 0, &analyser);
+ sharkd_dissect_request(framenum, (framenum != 1) ? 1 : 0, framenum - 1, &sharkd_session_process_analyse_cb, 0, 0, 0, &analyser);
printf("]");
if (analyser.first_time)
if (tok_column == NULL)
break;
+ columns_custom[i] = NULL;
+ columns_occur[i] = 0;
+
if ((custom_sepa = strchr(tok_column, ':')))
{
*custom_sepa = '\0'; /* XXX, C abuse: discarding-const */
columns_fmt[i] = COL_CUSTOM;
columns_custom[i] = tok_column;
- columns_occur[i] = 0;
if (!ws_strtoi16(custom_sepa + 1, NULL, &columns_occur[i]))
return NULL;
* (o) filter - filter to be used
* (o) skip=N - skip N frames
* (o) limit=N - show only N frames
+ * (o) refs - list (comma separated) with sorted time reference frame numbers.
*
* Output array of frames with attributes:
* (m) c - array of column data
const char *tok_column = json_find_attr(buf, tokens, count, "column0");
const char *tok_skip = json_find_attr(buf, tokens, count, "skip");
const char *tok_limit = json_find_attr(buf, tokens, count, "limit");
+ const char *tok_refs = json_find_attr(buf, tokens, count, "refs");
const guint8 *filter_data = NULL;
const char *frame_sepa = "";
int col;
- guint32 framenum;
+ guint32 framenum, prev_dis_num = 0;
+ guint32 current_ref_frame = 0, next_ref_frame = G_MAXUINT32;
guint32 skip;
guint32 limit;
return;
}
+ if (tok_refs)
+ {
+ if (!ws_strtou32(tok_refs, &tok_refs, &next_ref_frame))
+ return;
+ }
+
printf("[");
for (framenum = 1; framenum <= cfile.count; framenum++)
{
- frame_data *fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
+ frame_data *fdata;
+ guint32 ref_frame = (framenum != 1) ? 1 : 0;
if (filter_data && !(filter_data[framenum / 8] & (1 << (framenum % 8))))
continue;
if (skip)
{
skip--;
+ prev_dis_num = framenum;
continue;
}
- sharkd_dissect_columns(framenum, cinfo, (fdata->color_filter == NULL));
+ if (tok_refs)
+ {
+ if (framenum >= next_ref_frame)
+ {
+ current_ref_frame = next_ref_frame;
+
+ if (*tok_refs != ',')
+ next_ref_frame = G_MAXUINT32;
+
+ while (*tok_refs == ',' && framenum >= next_ref_frame)
+ {
+ current_ref_frame = next_ref_frame;
+
+ if (!ws_strtou32(tok_refs + 1, &tok_refs, &next_ref_frame))
+ {
+ fprintf(stderr, "sharkd_session_process_frames() wrong format for refs: %s\n", tok_refs);
+ break;
+ }
+ }
+ }
+
+ if (current_ref_frame)
+ ref_frame = current_ref_frame;
+ }
+
+ fdata = sharkd_get_frame(framenum);
+ sharkd_dissect_columns(fdata, ref_frame, prev_dis_num, cinfo, (fdata->color_filter == NULL));
printf("%s{\"c\":[", frame_sepa);
for (col = 0; col < cinfo->num_cols; ++col)
printf("}");
frame_sepa = ",";
+ prev_dis_num = framenum;
if (limit && --limit == 0)
break;
sharkd_session_packet_tap_expert_cb(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pointer)
{
struct sharkd_expert_tap *etd = (struct sharkd_expert_tap *) tapdata;
- expert_info_t *ei = (expert_info_t *) pointer;
+ const expert_info_t *ei = (const expert_info_t *) pointer;
+ expert_info_t *ei_copy;
+
+ if (ei == NULL)
+ return FALSE;
- ei = (expert_info_t *) g_memdup(ei, sizeof(*ei));
- ei->protocol = g_string_chunk_insert_const(etd->text, ei->protocol);
- ei->summary = g_string_chunk_insert_const(etd->text, ei->summary);
+ ei_copy = g_new(expert_info_t, 1);
+ /* Note: this is a shallow copy */
+ *ei_copy = *ei;
- etd->details = g_slist_prepend(etd->details, ei);
+ /* ei->protocol, ei->summary might be allocated in packet scope, make a copy. */
+ ei_copy->protocol = g_string_chunk_insert_const(etd->text, ei_copy->protocol);
+ ei_copy->summary = g_string_chunk_insert_const(etd->text, ei_copy->summary);
+
+ etd->details = g_slist_prepend(etd->details, ei_copy);
return TRUE;
}
gboolean resolve_port;
};
-static int
+static gboolean
sharkd_session_geoip_addr(address *addr, const char *suffix)
{
- int with_geoip = 0;
-
- (void) addr;
- (void) suffix;
+ const mmdb_lookup_t *lookup = NULL;
+ gboolean with_geoip = FALSE;
-#ifdef HAVE_GEOIP
if (addr->type == AT_IPv4)
{
- guint32 ip = pntoh32(addr->data);
-
- guint num_dbs = geoip_db_num_dbs();
- guint dbnum;
-
- for (dbnum = 0; dbnum < num_dbs; dbnum++)
- {
- const char *geoip_key = NULL;
- char *geoip_val;
-
- int db_type = geoip_db_type(dbnum);
-
- switch (db_type)
- {
- case GEOIP_COUNTRY_EDITION:
- geoip_key = "geoip_country";
- break;
-
- case GEOIP_CITY_EDITION_REV0:
- case GEOIP_CITY_EDITION_REV1:
- geoip_key = "geoip_city";
- break;
-
- case GEOIP_ORG_EDITION:
- geoip_key = "geoip_org";
- break;
-
- case GEOIP_ISP_EDITION:
- geoip_key = "geoip_isp";
- break;
-
- case GEOIP_ASNUM_EDITION:
- geoip_key = "geoip_as";
- break;
-
- case WS_LAT_FAKE_EDITION:
- geoip_key = "geoip_lat";
- break;
-
- case WS_LON_FAKE_EDITION:
- geoip_key = "geoip_lon";
- break;
- }
+ guint32 ip;
- if (geoip_key && (geoip_val = geoip_db_lookup_ipv4(dbnum, ip, NULL)))
- {
- printf(",\"%s%s\":", geoip_key, suffix);
- json_puts_string(geoip_val);
- with_geoip = 1;
- }
- }
+ memcpy(&ip, addr->data, 4);
+ lookup = maxmind_db_lookup_ipv4(ip);
}
-#ifdef HAVE_GEOIP_V6
- if (addr->type == AT_IPv6)
+ else if (addr->type == AT_IPv6)
{
const ws_in6_addr *ip6 = (const ws_in6_addr *) addr->data;
- guint num_dbs = geoip_db_num_dbs();
- guint dbnum;
+ lookup = maxmind_db_lookup_ipv6(ip6);
+ }
- for (dbnum = 0; dbnum < num_dbs; dbnum++)
- {
- const char *geoip_key = NULL;
- char *geoip_val;
+ if (!lookup || !lookup->found)
+ return FALSE;
- int db_type = geoip_db_type(dbnum);
+ if (lookup->country)
+ {
+ printf(",\"geoip_country%s\":", suffix);
+ json_puts_string(lookup->country);
+ with_geoip = TRUE;
+ }
- switch (db_type)
- {
- case GEOIP_COUNTRY_EDITION_V6:
- geoip_key = "geoip_country";
- break;
-#if NUM_DB_TYPES > 31
- case GEOIP_CITY_EDITION_REV0_V6:
- case GEOIP_CITY_EDITION_REV1_V6:
- geoip_key = "geoip_city";
- break;
+ if (lookup->country_iso)
+ {
+ printf(",\"geoip_country_iso%s\":", suffix);
+ json_puts_string(lookup->country_iso);
+ with_geoip = TRUE;
+ }
- case GEOIP_ORG_EDITION_V6:
- geoip_key = "geoip_org";
- break;
+ if (lookup->city)
+ {
+ printf(",\"geoip_city%s\":", suffix);
+ json_puts_string(lookup->city);
+ with_geoip = TRUE;
+ }
- case GEOIP_ISP_EDITION_V6:
- geoip_key = "geoip_isp";
- break;
+ if (lookup->as_org)
+ {
+ printf(",\"geoip_as_org%s\":", suffix);
+ json_puts_string(lookup->as_org);
+ with_geoip = TRUE;
+ }
- case GEOIP_ASNUM_EDITION_V6:
- geoip_key = "geoip_as";
- break;
-#endif /* DB_NUM_TYPES */
- case WS_LAT_FAKE_EDITION:
- geoip_key = "geoip_lat";
- break;
+ if (lookup->as_number > 0)
+ {
+ printf(",\"geoip_as%s\":%u", suffix, lookup->as_number);
+ with_geoip = TRUE;
+ }
- case WS_LON_FAKE_EDITION:
- geoip_key = "geoip_lon";
- break;
- }
+ if (lookup->latitude >= -90.0 && lookup->latitude <= 90.0)
+ {
+ printf(",\"geoip_lat%s\":%f", suffix, lookup->latitude);
+ with_geoip = TRUE;
+ }
- if (geoip_key && (geoip_val = geoip_db_lookup_ipv6(dbnum, *ip6, NULL)))
- {
- printf(",\"%s%s\":", geoip_key, suffix);
- json_puts_string(geoip_val);
- with_geoip = 1;
- }
- }
+ if (lookup->longitude >= -180.0 && lookup->longitude <= 180.0)
+ {
+ printf(",\"geoip_lon%s\":%f", suffix, lookup->longitude);
+ with_geoip = TRUE;
}
-#endif /* HAVE_GEOIP_V6 */
-#endif /* HAVE_GEOIP */
return with_geoip;
}
struct sharkd_analyse_rtp
{
const char *tap_name;
- struct sharkd_rtp_match rtp;
+ rtpstream_id_t id;
GSList *packets;
double start_time;
sharkd_session_packet_tap_rtp_analyse_cb(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pointer)
{
struct sharkd_analyse_rtp *rtp_req = (struct sharkd_analyse_rtp *) tapdata;
- const struct _rtp_info *rtpinfo = (const struct _rtp_info *) pointer;
+ const struct _rtp_info *rtp_info = (const struct _rtp_info *) pointer;
- if (sharkd_rtp_match_check(&rtp_req->rtp, pinfo, rtpinfo))
+ if (rtpstream_id_equal_pinfo_rtp_info(&rtp_req->id, pinfo, rtp_info))
{
tap_rtp_stat_t *statinfo = &(rtp_req->statinfo);
struct sharkd_analyse_rtp_items *item;
- rtp_packet_analyse(statinfo, pinfo, rtpinfo);
+ rtppacket_analyse(statinfo, pinfo, rtp_info);
item = (struct sharkd_analyse_rtp_items *) g_malloc(sizeof(struct sharkd_analyse_rtp_items));
rtp_req->start_time = nstime_to_sec(&pinfo->abs_ts);
item->frame_num = pinfo->num;
- item->sequence_num = rtpinfo->info_seq_num;
+ item->sequence_num = rtp_info->info_seq_num;
item->delta = (statinfo->flags & STAT_FLAG_FIRST) ? 0.0 : statinfo->delta;
item->jitter = (statinfo->flags & STAT_FLAG_FIRST) ? 0.0 : statinfo->jitter;
item->skew = (statinfo->flags & STAT_FLAG_FIRST) ? 0.0 : statinfo->skew;
item->bandwidth = statinfo->bandwidth;
- item->marker = rtpinfo->info_marker_set ? TRUE : FALSE;
+ item->marker = rtp_info->info_marker_set ? TRUE : FALSE;
item->arrive_offset= nstime_to_sec(&pinfo->abs_ts) - rtp_req->start_time;
item->flags = statinfo->flags;
printf("{\"tap\":\"%s\",\"type\":\"rtp-analyse\"", rtp_req->tap_name);
- printf(",\"ssrc\":%u", rtp_req->rtp.ssrc);
+ printf(",\"ssrc\":%u", rtp_req->id.ssrc);
printf(",\"max_delta\":%f", statinfo->max_delta);
printf(",\"max_delta_nr\":%u", statinfo->max_nr);
static void
sharkd_session_process_tap_nstat_cb(void *arg)
{
- new_stat_data_t *stat_data = (new_stat_data_t *) arg;
+ stat_data_t *stat_data = (stat_data_t *) arg;
guint i, j, k;
printf("{\"tap\":\"nstat:%s\",\"type\":\"nstat\"", stat_data->stat_tap_data->cli_string);
{
stat_tap_table_item_type *field_data;
- field_data = new_stat_tap_get_field_data(table, j, 0);
+ field_data = stat_tap_get_field_data(table, j, 0);
if (field_data == NULL || field_data->type == TABLE_ITEM_NONE) /* Nothing for us here */
continue;
printf("%s[", sepa);
for (k = 0; k < table->num_fields; k++)
{
- field_data = new_stat_tap_get_field_data(table, j, k);
+ field_data = stat_tap_get_field_data(table, j, k);
if (k)
printf(",");
break;
case TABLE_ITEM_INT:
- printf("%d", field_data->value.uint_value);
+ printf("%d", field_data->value.int_value);
break;
case TABLE_ITEM_STRING:
static void
sharkd_session_free_tap_nstat_cb(void *arg)
{
- new_stat_data_t *stat_data = (new_stat_data_t *) arg;
+ stat_data_t *stat_data = (stat_data_t *) arg;
- free_stat_tables(stat_data->stat_tap_data, NULL, NULL);
+ free_stat_tables(stat_data->stat_tap_data);
}
/**
{
rtd_data_t *rtd_data = (rtd_data_t *) arg;
- free_rtd_table(&rtd_data->stat_table, NULL, NULL);
+ free_rtd_table(&rtd_data->stat_table);
g_free(rtd_data);
}
srt_data_t *srt_data = (srt_data_t *) arg;
register_srt_t *srt = (register_srt_t *) srt_data->user_data;
- free_srt_table(srt, srt_data->srt_array, NULL, NULL);
+ free_srt_table(srt, srt_data->srt_array);
g_array_free(srt_data->srt_array, TRUE);
g_free(srt_data);
}
printf(",\"streams\":[");
for (listx = g_list_first(rtp_tapinfo->strinfo_list); listx; listx = listx->next)
{
- rtp_stream_info_t *streaminfo = (rtp_stream_info_t *) listx->data;
+ rtpstream_info_calc_t calc;
+ rtpstream_info_t *streaminfo = (rtpstream_info_t *) listx->data;
- char *src_addr, *dst_addr;
- char *payload;
- guint32 expected;
+ rtpstream_info_calculate(streaminfo, &calc);
- src_addr = address_to_display(NULL, &(streaminfo->src_addr));
- dst_addr = address_to_display(NULL, &(streaminfo->dest_addr));
+ printf("%s{\"ssrc\":%u", sepa, calc.ssrc);
+ printf(",\"payload\":\"%s\"", calc.all_payload_type_names);
- if (streaminfo->payload_type_name != NULL)
- payload = wmem_strdup(NULL, streaminfo->payload_type_name);
- else
- payload = val_to_str_ext_wmem(NULL, streaminfo->payload_type, &rtp_payload_type_short_vals_ext, "Unknown (%u)");
-
- printf("%s{\"ssrc\":%u", sepa, streaminfo->ssrc);
- printf(",\"payload\":\"%s\"", payload);
+ printf(",\"saddr\":\"%s\"", calc.src_addr_str);
+ printf(",\"sport\":%u", calc.src_port);
- printf(",\"saddr\":\"%s\"", src_addr);
- printf(",\"sport\":%u", streaminfo->src_port);
+ printf(",\"daddr\":\"%s\"", calc.dst_addr_str);
+ printf(",\"dport\":%u", calc.dst_port);
- printf(",\"daddr\":\"%s\"", dst_addr);
- printf(",\"dport\":%u", streaminfo->dest_port);
+ printf(",\"pkts\":%u", calc.packet_count);
- printf(",\"pkts\":%u", streaminfo->packet_count);
+ printf(",\"max_delta\":%f",calc.max_delta);
+ printf(",\"max_jitter\":%f", calc.max_jitter);
+ printf(",\"mean_jitter\":%f", calc.mean_jitter);
- printf(",\"max_delta\":%f", streaminfo->rtp_stats.max_delta);
- printf(",\"max_jitter\":%f", streaminfo->rtp_stats.max_jitter);
- printf(",\"mean_jitter\":%f", streaminfo->rtp_stats.mean_jitter);
+ printf(",\"expectednr\":%u", calc.packet_expected);
+ printf(",\"totalnr\":%u", calc.total_nr);
- expected = (streaminfo->rtp_stats.stop_seq_nr + streaminfo->rtp_stats.cycles * 65536) - streaminfo->rtp_stats.start_seq_nr + 1;
- printf(",\"expectednr\":%u", expected);
- printf(",\"totalnr\":%u", streaminfo->rtp_stats.total_nr);
-
- printf(",\"problem\":%s", streaminfo->problem ? "true" : "false");
+ printf(",\"problem\":%s", calc.problem? "true" : "false");
/* for filter */
- printf(",\"ipver\":%d", (streaminfo->src_addr.type == AT_IPv6) ? 6 : 4);
+ printf(",\"ipver\":%d", (streaminfo->id.src_addr.type == AT_IPv6) ? 6 : 4);
- wmem_free(NULL, src_addr);
- wmem_free(NULL, dst_addr);
- wmem_free(NULL, payload);
+ rtpstream_info_calc_free(&calc);
printf("}");
sepa = ",";
}
else if (!strncmp(tok_tap, "nstat:", 6))
{
- stat_tap_table_ui *stat_tap = new_stat_tap_by_name(tok_tap + 6);
- new_stat_data_t *stat_data;
+ stat_tap_table_ui *stat_tap = stat_tap_by_name(tok_tap + 6);
+ stat_data_t *stat_data;
if (!stat_tap)
{
continue;
}
- stat_tap->stat_tap_init_cb(stat_tap, NULL, NULL);
+ stat_tap->stat_tap_init_cb(stat_tap);
- stat_data = g_new0(new_stat_data_t, 1);
+ stat_data = g_new0(stat_data_t, 1);
stat_data->stat_tap_data = stat_tap;
stat_data->user_data = NULL;
srt_data = g_new0(srt_data_t, 1);
srt_data->srt_array = g_array_new(FALSE, TRUE, sizeof(srt_stat_table *));
srt_data->user_data = srt;
- srt_table_dissector_init(srt, srt_data->srt_array, NULL, NULL);
+ srt_table_dissector_init(srt, srt_data->srt_array);
tap_error = register_tap_listener(get_srt_tap_listener_name(srt), srt_data, tap_filter, 0, NULL, get_srt_packet_func(srt), sharkd_session_process_tap_srt_cb);
}
else if (!strcmp(tok_tap, "rtp-streams"))
{
- tap_error = register_tap_listener("rtp", &rtp_tapinfo, tap_filter, 0, rtpstream_reset_cb, rtpstream_packet, sharkd_session_process_tap_rtp_cb);
+ tap_error = register_tap_listener("rtp", &rtp_tapinfo, tap_filter, 0, rtpstream_reset_cb, rtpstream_packet_cb, sharkd_session_process_tap_rtp_cb);
tap_data = &rtp_tapinfo;
tap_free = rtpstream_reset_cb;
struct sharkd_analyse_rtp *rtp_req;
rtp_req = (struct sharkd_analyse_rtp *) g_malloc0(sizeof(*rtp_req));
- if (!sharkd_rtp_match_init(&rtp_req->rtp, tok_tap + 12))
+ if (!sharkd_rtp_match_init(&rtp_req->id, tok_tap + 12))
{
+ rtpstream_id_free(&rtp_req->id);
g_free(rtp_req);
continue;
}
if (fdata->flags.has_user_comment)
pkt_comment = sharkd_get_user_comment(fdata);
else if (fdata->flags.has_phdr_comment)
- pkt_comment = pi->phdr->opt_comment;
+ pkt_comment = pi->rec->opt_comment;
if (pkt_comment)
{
for (i = 0; i < count; i++)
{
- struct data_source *src = (struct data_source *) g_slist_nth_data((GSList *) data_src, i);
+ const struct data_source *src = (const struct data_source *) g_slist_nth_data((GSList *) data_src, i);
tvbs[i] = get_data_source_tvb(src);
}
printf("}\n");
}
+#define SHARKD_IOGRAPH_MAX_ITEMS 250000 /* 250k limit of items is taken from wireshark-qt, on x86_64 sizeof(io_graph_item_t) is 152, so single graph can take max 36 MB */
+
+struct sharkd_iograph
+{
+ /* config */
+ int hf_index;
+ io_graph_item_unit_t calc_type;
+ guint32 interval;
+
+ /* result */
+ int space_items;
+ int num_items;
+ io_graph_item_t *items;
+ GString *error;
+};
+
+static gboolean
+sharkd_iograph_packet(void *g, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_)
+{
+ struct sharkd_iograph *graph = (struct sharkd_iograph *) g;
+ int idx;
+
+ idx = get_io_graph_index(pinfo, graph->interval);
+ if (idx < 0 || idx >= SHARKD_IOGRAPH_MAX_ITEMS)
+ return FALSE;
+
+ if (idx + 1 > graph->num_items)
+ {
+ if (idx + 1 > graph->space_items)
+ {
+ int new_size = idx + 1024;
+
+ graph->items = (io_graph_item_t *) g_realloc(graph->items, sizeof(io_graph_item_t) * new_size);
+ reset_io_graph_items(&graph->items[graph->space_items], new_size - graph->space_items);
+
+ graph->space_items = new_size;
+ }
+ else if (graph->items == NULL)
+ {
+ graph->items = (io_graph_item_t *) g_malloc(sizeof(io_graph_item_t) * graph->space_items);
+ reset_io_graph_items(graph->items, graph->space_items);
+ }
+
+ graph->num_items = idx + 1;
+ }
+
+ return update_io_graph_item(graph->items, idx, pinfo, edt, graph->hf_index, graph->calc_type, graph->interval);
+}
+
+/**
+ * sharkd_session_process_iograph()
+ *
+ * Process iograph request
+ *
+ * Input:
+ * (o) interval - interval time in ms, if not specified: 1000ms
+ * (m) graph0 - First graph request
+ * (o) graph1...graph9 - Other graph requests
+ * (o) filter0 - First graph filter
+ * (o) filter1...filter9 - Other graph filters
+ *
+ * Graph requests can be one of: "packets", "bytes", "bits", "sum:<field>", "frames:<field>", "max:<field>", "min:<field>", "avg:<field>", "load:<field>",
+ * if you use variant with <field>, you need to pass field name in filter request.
+ *
+ * Output object with attributes:
+ * (m) iograph - array of graph results with attributes:
+ * errmsg - graph cannot be constructed
+ * items - graph values, zeros are skipped, if value is not a number it's next index encoded as hex string
+ */
+static void
+sharkd_session_process_iograph(char *buf, const jsmntok_t *tokens, int count)
+{
+ const char *tok_interval = json_find_attr(buf, tokens, count, "interval");
+ struct sharkd_iograph graphs[10];
+ gboolean is_any_ok = FALSE;
+ int graph_count;
+
+ guint32 interval_ms = 1000; /* default: one per second */
+ int i;
+
+ if (tok_interval)
+ {
+ if (!ws_strtou32(tok_interval, NULL, &interval_ms) || interval_ms == 0)
+ {
+ fprintf(stderr, "Invalid interval parameter: %s.\n", tok_interval);
+ return;
+ }
+ }
+
+ for (i = graph_count = 0; i < (int) G_N_ELEMENTS(graphs); i++)
+ {
+ struct sharkd_iograph *graph = &graphs[graph_count];
+
+ const char *tok_graph;
+ const char *tok_filter;
+ char tok_format_buf[32];
+ const char *field_name;
+
+ snprintf(tok_format_buf, sizeof(tok_format_buf), "graph%d", i);
+ tok_graph = json_find_attr(buf, tokens, count, tok_format_buf);
+ if (!tok_graph)
+ break;
+
+ snprintf(tok_format_buf, sizeof(tok_format_buf), "filter%d", i);
+ tok_filter = json_find_attr(buf, tokens, count, tok_format_buf);
+
+ if (!strcmp(tok_graph, "packets"))
+ graph->calc_type = IOG_ITEM_UNIT_PACKETS;
+ else if (!strcmp(tok_graph, "bytes"))
+ graph->calc_type = IOG_ITEM_UNIT_BYTES;
+ else if (!strcmp(tok_graph, "bits"))
+ graph->calc_type = IOG_ITEM_UNIT_BITS;
+ else if (g_str_has_prefix(tok_graph, "sum:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_SUM;
+ else if (g_str_has_prefix(tok_graph, "frames:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_FRAMES;
+ else if (g_str_has_prefix(tok_graph, "fields:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_FIELDS;
+ else if (g_str_has_prefix(tok_graph, "max:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_MAX;
+ else if (g_str_has_prefix(tok_graph, "min:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_MIN;
+ else if (g_str_has_prefix(tok_graph, "avg:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_AVERAGE;
+ else if (g_str_has_prefix(tok_graph, "load:"))
+ graph->calc_type = IOG_ITEM_UNIT_CALC_LOAD;
+ else
+ break;
+
+ field_name = strchr(tok_graph, ':');
+ if (field_name)
+ field_name = field_name + 1;
+
+ graph->interval = interval_ms;
+
+ graph->hf_index = -1;
+ graph->error = check_field_unit(field_name, &graph->hf_index, graph->calc_type);
+
+ graph->space_items = 0; /* TODO, can avoid realloc()s in sharkd_iograph_packet() by calculating: capture_time / interval */
+ graph->num_items = 0;
+ graph->items = NULL;
+
+ if (!graph->error)
+ graph->error = register_tap_listener("frame", graph, tok_filter, TL_REQUIRES_PROTO_TREE, NULL, sharkd_iograph_packet, NULL);
+
+ graph_count++;
+
+ if (graph->error == NULL)
+ is_any_ok = TRUE;
+ }
+
+ /* retap only if we have at least one ok */
+ if (is_any_ok)
+ sharkd_retap();
+
+ printf("{\"iograph\":[");
+
+ for (i = 0; i < graph_count; i++)
+ {
+ struct sharkd_iograph *graph = &graphs[i];
+
+ if (i)
+ printf(",");
+ printf("{");
+
+ if (graph->error)
+ {
+ printf("\"errmsg\":");
+ json_puts_string(graph->error->str);
+ g_string_free(graph->error, TRUE);
+ }
+ else
+ {
+ int idx;
+ int next_idx = 0;
+ const char *sepa = "";
+
+ printf("\"items\":[");
+ for (idx = 0; idx < graph->num_items; idx++)
+ {
+ double val;
+
+ val = get_io_graph_item(graph->items, graph->calc_type, idx, graph->hf_index, &cfile, graph->interval, graph->num_items);
+
+ /* if it's zero, don't display */
+ if (val == 0.0)
+ continue;
+
+ printf("%s", sepa);
+
+ /* cause zeros are not printed, need to output index */
+ if (next_idx != idx)
+ printf("\"%x\",", idx);
+
+ printf("%f", val);
+ next_idx = idx + 1;
+ sepa = ",";
+ }
+ printf("]");
+ }
+ printf("}");
+
+ remove_tap_listener(graph);
+ g_free(graph->items);
+ }
+
+ printf("]}\n");
+}
+
/**
* sharkd_session_process_intervals()
*
guint64 bytes;
} st, st_total;
- nstime_t *start_ts = NULL;
+ nstime_t *start_ts;
guint32 interval_ms = 1000; /* default: one per second */
printf("{\"intervals\":[");
+ start_ts = (cfile.count >= 1) ? &(sharkd_get_frame(1)->abs_ts) : NULL;
+
for (framenum = 1; framenum <= cfile.count; framenum++)
{
- frame_data *fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
+ frame_data *fdata;
gint64 msec_rel;
gint64 new_idx;
- if (start_ts == NULL)
- start_ts = &fdata->abs_ts;
-
if (filter_data && !(filter_data[framenum / 8] & (1 << (framenum % 8))))
continue;
+ fdata = sharkd_get_frame(framenum);
+
msec_rel = (fdata->abs_ts.secs - start_ts->secs) * (gint64) 1000 + (fdata->abs_ts.nsecs - start_ts->nsecs) / 1000000;
new_idx = msec_rel / interval_ms;
*
* Input:
* (m) frame - requested frame number
+ * (o) ref_frame - time reference frame number
+ * (o) prev_frame - previously displayed frame number
* (o) proto - set if output frame tree
* (o) columns - set if output frame columns
* (o) bytes - set if output frame bytes
sharkd_session_process_frame(char *buf, const jsmntok_t *tokens, int count)
{
const char *tok_frame = json_find_attr(buf, tokens, count, "frame");
+ const char *tok_ref_frame = json_find_attr(buf, tokens, count, "ref_frame");
+ const char *tok_prev_frame = json_find_attr(buf, tokens, count, "prev_frame");
int tok_proto = (json_find_attr(buf, tokens, count, "proto") != NULL);
int tok_bytes = (json_find_attr(buf, tokens, count, "bytes") != NULL);
int tok_columns = (json_find_attr(buf, tokens, count, "columns") != NULL);
- guint32 framenum;
+ guint32 framenum, ref_frame_num, prev_dis_num;
if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0)
return;
- sharkd_dissect_request(framenum, &sharkd_session_process_frame_cb, tok_bytes, tok_columns, tok_proto, NULL);
+ ref_frame_num = (framenum != 1) ? 1 : 0;
+ if (tok_ref_frame && (!ws_strtou32(tok_ref_frame, NULL, &ref_frame_num) || ref_frame_num > framenum))
+ return;
+
+ prev_dis_num = framenum - 1;
+ if (tok_prev_frame && (!ws_strtou32(tok_prev_frame, NULL, &prev_dis_num) || prev_dis_num >= framenum))
+ return;
+
+ sharkd_dissect_request(framenum, ref_frame_num, prev_dis_num, &sharkd_session_process_frame_cb, tok_bytes, tok_columns, tok_proto, NULL);
}
/**
if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0)
return;
- fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
+ fdata = sharkd_get_frame(framenum);
if (!fdata)
return;
struct sharkd_download_rtp
{
- struct sharkd_rtp_match rtp;
+ rtpstream_id_t id;
GSList *packets;
double start_time;
};
if (rtp_info->info_setup_frame_num == 0)
return FALSE;
- if (sharkd_rtp_match_check(&req_rtp->rtp, pinfo, rtp_info))
+ if (rtpstream_id_equal_pinfo_rtp_info(&req_rtp->id, pinfo, rtp_info))
{
rtp_packet_t *rtp_packet;
printf(",\"mime\":");
json_puts_string(mime);
printf(",\"data\":");
- json_print_base64(eo_entry->payload_data, eo_entry->payload_len);
+ json_print_base64(eo_entry->payload_data, (size_t)(eo_entry->payload_len));
printf("}\n");
}
}
GString *tap_error;
memset(&rtp_req, 0, sizeof(rtp_req));
- if (!sharkd_rtp_match_init(&rtp_req.rtp, tok_token + 4))
+ if (!sharkd_rtp_match_init(&rtp_req.id, tok_token + 4))
{
fprintf(stderr, "sharkd_session_process_download() rtp tokenizing error %s\n", tok_token);
return;
sharkd_session_process_tap(buf, tokens, count);
else if (!strcmp(tok_req, "follow"))
sharkd_session_process_follow(buf, tokens, count);
+ else if (!strcmp(tok_req, "iograph"))
+ sharkd_session_process_iograph(buf, tokens, count);
else if (!strcmp(tok_req, "intervals"))
sharkd_session_process_intervals(buf, tokens, count);
else if (!strcmp(tok_req, "frame"))
fprintf(stderr, "Hello in child.\n");
+ filter_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, sharkd_session_filter_free);
+
+#ifdef HAVE_MAXMINDDB
+ /* mmdbresolve was stopped before fork(), force starting it */
+ uat_get_table_by_name("MaxMind Database Paths")->post_update_cb();
+#endif
+
while (fgets(buf, sizeof(buf), stdin))
{
/* every command is line seperated JSON */
int ret;
- ret = wsjsmn_parse(buf, NULL, 0);
+ ret = wsjson_parse(buf, NULL, 0);
if (ret < 0)
{
fprintf(stderr, "invalid JSON -> closing\n");
memset(tokens, 0, ret * sizeof(jsmntok_t));
- ret = wsjsmn_parse(buf, tokens, ret);
+ ret = wsjson_parse(buf, tokens, ret);
if (ret < 0)
{
fprintf(stderr, "invalid JSON(2) -> closing\n");
return 2;
}
+#if defined(HAVE_C_ARES) || defined(HAVE_MAXMINDDB)
+ host_name_lookup_process();
+#endif
+
sharkd_session_process(buf, tokens, ret);
}
+ g_hash_table_destroy(filter_table);
g_free(tokens);
return 0;