2016-01-25 01:10:20 +00:00
|
|
|
/* proto_data.c
|
|
|
|
* Protocol-specific data
|
|
|
|
*
|
|
|
|
* 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
|
2016-01-25 01:10:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2021-07-26 00:31:17 +00:00
|
|
|
#include <epan/wmem_scopes.h>
|
2016-01-25 01:10:20 +00:00
|
|
|
#include <epan/packet_info.h>
|
|
|
|
#include <epan/proto_data.h>
|
|
|
|
#include <epan/proto.h>
|
|
|
|
|
|
|
|
/* Protocol-specific data attached to a frame_data structure - protocol
|
2021-04-02 01:52:52 +00:00
|
|
|
index, key for multiple items with the same protocol index,
|
|
|
|
and opaque pointer. */
|
2016-01-25 01:10:20 +00:00
|
|
|
typedef struct _proto_data {
|
|
|
|
int proto;
|
|
|
|
guint32 key;
|
|
|
|
void *proto_data;
|
|
|
|
} proto_data_t;
|
|
|
|
|
|
|
|
static gint
|
|
|
|
p_compare(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const proto_data_t *ap = (const proto_data_t *)a;
|
|
|
|
const proto_data_t *bp = (const proto_data_t *)b;
|
|
|
|
|
|
|
|
if (ap -> proto > bp -> proto) {
|
|
|
|
return 1;
|
|
|
|
} else if (ap -> proto == bp -> proto) {
|
|
|
|
if (ap->key > bp->key){
|
|
|
|
return 1;
|
|
|
|
} else if (ap -> key == bp -> key) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
p_add_proto_data(wmem_allocator_t *tmp_scope, struct _packet_info* pinfo, int proto, guint32 key, void *proto_data)
|
|
|
|
{
|
|
|
|
proto_data_t *p1;
|
|
|
|
GSList **proto_list;
|
|
|
|
wmem_allocator_t *scope;
|
|
|
|
|
|
|
|
if (tmp_scope == pinfo->pool) {
|
|
|
|
scope = tmp_scope;
|
|
|
|
proto_list = &pinfo->proto_data;
|
2016-09-16 20:15:57 +00:00
|
|
|
} else if (tmp_scope == wmem_file_scope()) {
|
2016-01-25 01:10:20 +00:00
|
|
|
scope = wmem_file_scope();
|
|
|
|
proto_list = &pinfo->fd->pfd;
|
2016-09-16 20:15:57 +00:00
|
|
|
} else {
|
|
|
|
DISSECTOR_ASSERT(!"invalid wmem scope");
|
2016-01-25 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 02:30:28 +00:00
|
|
|
p1 = wmem_new(scope, proto_data_t);
|
2016-01-25 01:10:20 +00:00
|
|
|
|
|
|
|
p1->proto = proto;
|
|
|
|
p1->key = key;
|
|
|
|
p1->proto_data = proto_data;
|
|
|
|
|
|
|
|
/* Add it to the GSLIST */
|
2016-01-26 02:19:21 +00:00
|
|
|
*proto_list = g_slist_prepend(*proto_list, p1);
|
2016-01-25 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-29 02:52:30 +00:00
|
|
|
void
|
|
|
|
p_set_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key, void *proto_data)
|
|
|
|
{
|
|
|
|
proto_data_t temp;
|
|
|
|
GSList *item;
|
|
|
|
|
|
|
|
temp.proto = proto;
|
|
|
|
temp.key = key;
|
|
|
|
temp.proto_data = NULL;
|
|
|
|
|
|
|
|
if (scope == pinfo->pool) {
|
|
|
|
item = g_slist_find_custom(pinfo->proto_data, &temp, p_compare);
|
|
|
|
} else if (scope == wmem_file_scope()) {
|
|
|
|
item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
|
|
|
|
} else {
|
|
|
|
DISSECTOR_ASSERT(!"invalid wmem scope");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
proto_data_t *pd = (proto_data_t *)item->data;
|
|
|
|
pd->proto_data = proto_data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_add_proto_data(scope, pinfo, proto, key, proto_data);
|
|
|
|
}
|
|
|
|
|
2016-01-25 01:10:20 +00:00
|
|
|
void *
|
|
|
|
p_get_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key)
|
|
|
|
{
|
|
|
|
proto_data_t temp, *p1;
|
|
|
|
GSList *item;
|
|
|
|
|
|
|
|
temp.proto = proto;
|
|
|
|
temp.key = key;
|
|
|
|
temp.proto_data = NULL;
|
|
|
|
|
|
|
|
if (scope == pinfo->pool) {
|
2016-01-26 02:19:21 +00:00
|
|
|
item = g_slist_find_custom(pinfo->proto_data, &temp, p_compare);
|
2016-09-16 20:15:57 +00:00
|
|
|
} else if (scope == wmem_file_scope()) {
|
2016-01-26 02:19:21 +00:00
|
|
|
item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
|
2016-09-16 20:15:57 +00:00
|
|
|
} else {
|
|
|
|
DISSECTOR_ASSERT(!"invalid wmem scope");
|
2016-01-25 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
p1 = (proto_data_t *)item->data;
|
|
|
|
return p1->proto_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
p_remove_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key)
|
|
|
|
{
|
|
|
|
proto_data_t temp;
|
|
|
|
GSList *item;
|
|
|
|
GSList **proto_list;
|
|
|
|
|
|
|
|
temp.proto = proto;
|
|
|
|
temp.key = key;
|
|
|
|
temp.proto_data = NULL;
|
|
|
|
|
|
|
|
if (scope == pinfo->pool) {
|
2017-12-29 13:26:42 +00:00
|
|
|
item = g_slist_find_custom(pinfo->proto_data, &temp, p_compare);
|
2016-01-25 01:10:20 +00:00
|
|
|
proto_list = &pinfo->proto_data;
|
2016-09-16 20:15:57 +00:00
|
|
|
} else if (scope == wmem_file_scope()) {
|
2016-01-26 02:19:21 +00:00
|
|
|
item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
|
2016-01-25 01:10:20 +00:00
|
|
|
proto_list = &pinfo->fd->pfd;
|
2016-09-16 20:15:57 +00:00
|
|
|
} else {
|
|
|
|
DISSECTOR_ASSERT(!"invalid wmem scope");
|
2016-01-25 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
*proto_list = g_slist_remove(*proto_list, item->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
p_get_proto_name_and_key(wmem_allocator_t *scope, struct _packet_info* pinfo, guint pfd_index){
|
|
|
|
proto_data_t *temp;
|
|
|
|
|
|
|
|
if (scope == pinfo->pool) {
|
|
|
|
temp = (proto_data_t *)g_slist_nth_data(pinfo->proto_data, pfd_index);
|
2016-09-16 20:15:57 +00:00
|
|
|
} else if (scope == wmem_file_scope()) {
|
2016-01-25 01:10:20 +00:00
|
|
|
temp = (proto_data_t *)g_slist_nth_data(pinfo->fd->pfd, pfd_index);
|
2016-09-16 20:15:57 +00:00
|
|
|
} else {
|
|
|
|
DISSECTOR_ASSERT(!"invalid wmem scope");
|
2016-01-25 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 20:08:32 +00:00
|
|
|
return wmem_strdup_printf(pinfo->pool, "[%s, key %u]",proto_get_protocol_name(temp->proto), temp->key);
|
2016-01-25 01:10:20 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 23:04:09 +00:00
|
|
|
#define PROTO_DEPTH_KEY 0x3c233fb5 // printf "0x%02x%02x\n" ${RANDOM} ${RANDOM}
|
|
|
|
|
|
|
|
void p_set_proto_depth(struct _packet_info *pinfo, int proto, unsigned depth) {
|
2021-12-29 02:52:30 +00:00
|
|
|
p_set_proto_data(pinfo->pool, pinfo, proto, PROTO_DEPTH_KEY, GUINT_TO_POINTER(depth));
|
2020-04-14 23:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned p_get_proto_depth(struct _packet_info *pinfo, int proto) {
|
|
|
|
return GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto, PROTO_DEPTH_KEY));
|
|
|
|
}
|
|
|
|
|
2016-01-25 01:10:20 +00:00
|
|
|
/*
|
2019-07-26 18:43:17 +00:00
|
|
|
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
2016-01-25 01:10:20 +00:00
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|