forked from osmocom/wireshark
pcapng: have common code to handle otherwise-unhandled options.
That code looks for a plugin handler if there's no built-in handler. Change the handler signature so that it can add an option.
This commit is contained in:
parent
66d84fc567
commit
712490f214
106
wiretap/pcapng.c
106
wiretap/pcapng.c
|
@ -605,6 +605,44 @@ pcapng_process_uint64_option(wtapng_block_t *wblock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_PLUGINS
|
||||||
|
static gboolean
|
||||||
|
pcap_process_unhandled_option(wtapng_block_t *wblock,
|
||||||
|
guint bt_index,
|
||||||
|
const section_info_t *section_info,
|
||||||
|
pcapng_option_header_t *ohp,
|
||||||
|
guint8 *option_content,
|
||||||
|
int *err, gchar **err_info)
|
||||||
|
{
|
||||||
|
option_handler *handler;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do we have a handler for this packet block option code?
|
||||||
|
*/
|
||||||
|
if (option_handlers[bt_index] != NULL &&
|
||||||
|
(handler = (option_handler *)g_hash_table_lookup(option_handlers[bt_index],
|
||||||
|
GUINT_TO_POINTER((guint)ohp->option_code))) != NULL) {
|
||||||
|
/* Yes - call the handler. */
|
||||||
|
if (!handler->hfunc(wblock->block, section_info->byte_swapped,
|
||||||
|
ohp->option_length, option_content, err, err_info))
|
||||||
|
/* XXX - free anything? */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static gboolean
|
||||||
|
pcap_process_unhandled_option(wtapng_block_t *wblock _U_,
|
||||||
|
guint bt_index _U_,
|
||||||
|
const section_info_t *section_info _U_,
|
||||||
|
pcapng_option_header_t *ohp _U_,
|
||||||
|
guint8 *option_content _U_,
|
||||||
|
int *err _U_, gchar **err_info _U_)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static block_return_val
|
static block_return_val
|
||||||
pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh,
|
pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||||
section_info_t *section_info,
|
section_info_t *section_info,
|
||||||
|
@ -771,8 +809,9 @@ pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||||
pcapng_process_string_option(wblock, &oh, option_content, opt_cont_buf_len);
|
pcapng_process_string_option(wblock, &oh, option_content, opt_cont_buf_len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pcapng_debug("pcapng_read_section_header_block: unknown option %u - ignoring %u bytes",
|
if (!pcap_process_unhandled_option(wblock, BT_INDEX_SHB, section_info, &oh, option_content, err, err_info))
|
||||||
oh.option_code, oh.option_length);
|
return PCAPNG_BLOCK_ERROR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free(option_content);
|
g_free(option_content);
|
||||||
|
@ -1064,8 +1103,9 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh,
|
||||||
* be useful for highly synchronized capture systems? 1234
|
* be useful for highly synchronized capture systems? 1234
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
pcapng_debug("pcapng_read_if_descr_block: unknown option %u - ignoring %u bytes",
|
if (!pcap_process_unhandled_option(wblock, BT_INDEX_IDB, section_info, &oh, option_content, err, err_info))
|
||||||
oh.option_code, oh.option_length);
|
return FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1183,9 +1223,6 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||||
gpointer option_content_copy;
|
gpointer option_content_copy;
|
||||||
int pseudo_header_len;
|
int pseudo_header_len;
|
||||||
int fcslen;
|
int fcslen;
|
||||||
#ifdef HAVE_PLUGINS
|
|
||||||
option_handler *handler;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* "(Enhanced) Packet Block" read fixed part */
|
/* "(Enhanced) Packet Block" read fixed part */
|
||||||
if (enhanced) {
|
if (enhanced) {
|
||||||
|
@ -1577,25 +1614,9 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||||
option_content[0], oh->option_length - 1);
|
option_content[0], oh->option_length - 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_PLUGINS
|
pcapng_debug("pcapng_read_packet_block: unknown option %u - ignoring %u bytes",
|
||||||
/*
|
oh->option_code, oh->option_length);
|
||||||
* Do we have a handler for this packet block option code?
|
break;
|
||||||
*/
|
|
||||||
if (option_handlers[BT_INDEX_PBS] != NULL &&
|
|
||||||
(handler = (option_handler *)g_hash_table_lookup(option_handlers[BT_INDEX_PBS],
|
|
||||||
GUINT_TO_POINTER((guint)oh->option_code))) != NULL) {
|
|
||||||
/* Yes - call the handler. */
|
|
||||||
if (!handler->hfunc(section_info->byte_swapped,
|
|
||||||
oh->option_length, option_content,
|
|
||||||
err, err_info))
|
|
||||||
/* XXX - free anything? */
|
|
||||||
return FALSE;
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
pcapng_debug("pcapng_read_packet_block: unknown option %u - ignoring %u bytes",
|
|
||||||
oh->option_code, oh->option_length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1834,9 +1855,6 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
pcapng_option_header_t oh;
|
pcapng_option_header_t oh;
|
||||||
guint8 *option_content;
|
guint8 *option_content;
|
||||||
#ifdef HAVE_PLUGINS
|
|
||||||
option_handler *handler;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is this block long enough to be an NRB?
|
* Is this block long enough to be an NRB?
|
||||||
|
@ -2084,28 +2102,9 @@ read_options:
|
||||||
pcapng_process_string_option(wblock, &oh, option_content, opt_cont_buf_len);
|
pcapng_process_string_option(wblock, &oh, option_content, opt_cont_buf_len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_PLUGINS
|
if (!pcap_process_unhandled_option(wblock, BT_INDEX_NRB, section_info, &oh, option_content, err, err_info))
|
||||||
/*
|
return FALSE;
|
||||||
* Do we have a handler for this network resolution block option code?
|
break;
|
||||||
*/
|
|
||||||
if (option_handlers[BT_INDEX_NRB] != NULL &&
|
|
||||||
(handler = (option_handler *)g_hash_table_lookup(option_handlers[BT_INDEX_NRB],
|
|
||||||
GUINT_TO_POINTER((guint)oh.option_code))) != NULL) {
|
|
||||||
/* Yes - call the handler. */
|
|
||||||
if (!handler->hfunc(section_info->byte_swapped,
|
|
||||||
oh.option_length, option_content,
|
|
||||||
err, err_info)) {
|
|
||||||
|
|
||||||
g_free(option_content);
|
|
||||||
ws_buffer_free(&nrb_rec);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
pcapng_debug("pcapng_read_name_resolution_block: unknown option %u - ignoring %u bytes",
|
|
||||||
oh.option_code, oh.option_length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2221,8 +2220,9 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||||
pcapng_process_uint64_option(wblock, section_info, &oh, option_content, opt_cont_buf_len);
|
pcapng_process_uint64_option(wblock, section_info, &oh, option_content, opt_cont_buf_len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pcapng_debug("pcapng_read_interface_statistics_block: unknown option %u - ignoring %u bytes",
|
if (!pcap_process_unhandled_option(wblock, BT_INDEX_ISB, section_info, &oh, option_content, err, err_info))
|
||||||
oh.option_code, oh.option_length);
|
return FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,11 @@ void register_pcapng_block_type_handler(guint block_type, block_reader reader,
|
||||||
/*
|
/*
|
||||||
* Handler routine for pcapng option type.
|
* Handler routine for pcapng option type.
|
||||||
*/
|
*/
|
||||||
typedef gboolean (*option_handler_fn)(gboolean, guint, guint8 *, int *, gchar **);
|
typedef gboolean (*option_handler_fn)(wtap_block_t wblock,
|
||||||
|
gboolean byte_swapped,
|
||||||
|
guint option_length,
|
||||||
|
guint8 *option_content,
|
||||||
|
int *err, gchar **err_info);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register a handler for a pcapng option code for a particular block
|
* Register a handler for a pcapng option code for a particular block
|
||||||
|
|
Loading…
Reference in New Issue