2019-11-04 09:42:29 +00:00
|
|
|
/* conversation_filter.c
|
2015-10-29 03:57:37 +00:00
|
|
|
* Routines for dissector-generated conversation filters for use as
|
|
|
|
* display and color filters
|
2014-12-09 02:40:24 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2014-12-09 02:40:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include "packet.h"
|
|
|
|
|
2019-11-04 09:42:29 +00:00
|
|
|
#include "conversation_filter.h"
|
2014-12-09 02:40:24 +00:00
|
|
|
|
|
|
|
|
2015-10-29 03:30:55 +00:00
|
|
|
GList *conv_filter_list = NULL;
|
2014-12-09 02:40:24 +00:00
|
|
|
|
|
|
|
|
2022-03-10 20:21:12 +00:00
|
|
|
static void do_register_conversation_filter(const char *proto_name, const char *display_name,
|
2015-10-29 04:21:36 +00:00
|
|
|
is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string) {
|
2015-10-29 03:30:55 +00:00
|
|
|
conversation_filter_t *entry;
|
2014-12-09 02:40:24 +00:00
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
entry = g_new(conversation_filter_t, 1);
|
2014-12-09 02:40:24 +00:00
|
|
|
|
2014-12-18 02:55:52 +00:00
|
|
|
entry->proto_name = proto_name;
|
|
|
|
entry->display_name = display_name;
|
2014-12-09 02:40:24 +00:00
|
|
|
entry->is_filter_valid = is_filter_valid;
|
|
|
|
entry->build_filter_string = build_filter_string;
|
|
|
|
|
2015-10-29 03:30:55 +00:00
|
|
|
conv_filter_list = g_list_append(conv_filter_list, entry);
|
2014-12-09 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 22:39:36 +00:00
|
|
|
void register_conversation_filter(const char *proto_name, const char *display_name,
|
|
|
|
is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string) {
|
2021-06-02 21:45:14 +00:00
|
|
|
do_register_conversation_filter(proto_name,
|
|
|
|
display_name,
|
|
|
|
is_filter_valid,
|
|
|
|
build_filter_string);
|
2021-05-19 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 20:21:12 +00:00
|
|
|
void register_log_conversation_filter(const char *proto_name, const char *display_name,
|
2022-01-28 22:39:36 +00:00
|
|
|
is_filter_valid_func is_filter_valid, build_filter_string_func build_filter_string) {
|
2021-06-02 21:45:14 +00:00
|
|
|
do_register_conversation_filter(proto_name,
|
|
|
|
display_name,
|
|
|
|
is_filter_valid,
|
|
|
|
build_filter_string);
|
2021-05-19 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 03:30:55 +00:00
|
|
|
struct conversation_filter_s* find_conversation_filter(const char *name)
|
2014-12-18 02:55:52 +00:00
|
|
|
{
|
2015-10-29 03:30:55 +00:00
|
|
|
GList *list_entry = conv_filter_list;
|
|
|
|
conversation_filter_t* filter;
|
2014-12-18 02:55:52 +00:00
|
|
|
|
|
|
|
while (list_entry != NULL) {
|
2015-10-29 03:30:55 +00:00
|
|
|
filter = (conversation_filter_t*)list_entry->data;
|
|
|
|
if (!strcmp(filter->proto_name, name))
|
|
|
|
return filter;
|
2014-12-18 02:55:52 +00:00
|
|
|
|
|
|
|
list_entry = g_list_next(list_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-20 11:19:18 +00:00
|
|
|
static void conversation_filter_free(gpointer p, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
g_free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void conversation_filters_cleanup(void)
|
|
|
|
{
|
|
|
|
g_list_foreach(conv_filter_list, conversation_filter_free, NULL);
|
|
|
|
g_list_free(conv_filter_list);
|
|
|
|
}
|
|
|
|
|
2017-06-20 18:08:39 +00:00
|
|
|
gchar *conversation_filter_from_packet(struct _packet_info *pinfo)
|
|
|
|
{
|
|
|
|
const char *layers[] = { "tcp", "udp", "ip", "ipv6", "eth" };
|
|
|
|
conversation_filter_t *conv_filter;
|
|
|
|
gchar *filter;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS(layers); i++) {
|
|
|
|
conv_filter = find_conversation_filter(layers[i]);
|
|
|
|
if (conv_filter && conv_filter->is_filter_valid(pinfo)) {
|
|
|
|
if ((filter = conv_filter->build_filter_string(pinfo)) != NULL)
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-09 02:40:24 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2014-12-09 02:40:24 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|