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
|
||||
pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh,
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
pcapng_debug("pcapng_read_section_header_block: unknown option %u - ignoring %u bytes",
|
||||
oh.option_code, oh.option_length);
|
||||
if (!pcap_process_unhandled_option(wblock, BT_INDEX_SHB, section_info, &oh, option_content, err, err_info))
|
||||
return PCAPNG_BLOCK_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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
|
||||
*/
|
||||
default:
|
||||
pcapng_debug("pcapng_read_if_descr_block: unknown option %u - ignoring %u bytes",
|
||||
oh.option_code, oh.option_length);
|
||||
if (!pcap_process_unhandled_option(wblock, BT_INDEX_IDB, section_info, &oh, option_content, err, err_info))
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1183,9 +1223,6 @@ pcapng_read_packet_block(FILE_T fh, pcapng_block_header_t *bh,
|
|||
gpointer option_content_copy;
|
||||
int pseudo_header_len;
|
||||
int fcslen;
|
||||
#ifdef HAVE_PLUGINS
|
||||
option_handler *handler;
|
||||
#endif
|
||||
|
||||
/* "(Enhanced) Packet Block" read fixed part */
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
#ifdef HAVE_PLUGINS
|
||||
/*
|
||||
* Do we have a handler for this packet block option code?
|
||||
*/
|
||||
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);
|
||||
}
|
||||
pcapng_debug("pcapng_read_packet_block: unknown option %u - ignoring %u bytes",
|
||||
oh->option_code, oh->option_length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1834,9 +1855,6 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh,
|
|||
int bytes_read;
|
||||
pcapng_option_header_t oh;
|
||||
guint8 *option_content;
|
||||
#ifdef HAVE_PLUGINS
|
||||
option_handler *handler;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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);
|
||||
break;
|
||||
default:
|
||||
#ifdef HAVE_PLUGINS
|
||||
/*
|
||||
* Do we have a handler for this network resolution block option code?
|
||||
*/
|
||||
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);
|
||||
}
|
||||
if (!pcap_process_unhandled_option(wblock, BT_INDEX_NRB, section_info, &oh, option_content, err, err_info))
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
break;
|
||||
default:
|
||||
pcapng_debug("pcapng_read_interface_statistics_block: unknown option %u - ignoring %u bytes",
|
||||
oh.option_code, oh.option_length);
|
||||
if (!pcap_process_unhandled_option(wblock, BT_INDEX_ISB, section_info, &oh, option_content, err, err_info))
|
||||
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.
|
||||
*/
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue