Add infrastructure for section-initializing protocol hfis (without array).

configure implementation later.

svn path=/trunk/; revision=53146
This commit is contained in:
Jakub Zawadzki 2013-11-07 20:14:18 +00:00
parent 3f385b31ab
commit ce6ca9a05d
26 changed files with 109 additions and 29 deletions

View File

@ -295,6 +295,7 @@ void proto_register_2dparityfec(void)
{
module_t *module_2dparityfec;
#ifndef HAVE_HFI_SECTION_INIT
/* Payload type definitions */
static header_field_info *hfi[] = {
&hfi_2dparityfec_snbase_low,
@ -312,6 +313,7 @@ void proto_register_2dparityfec(void)
&hfi_2dparityfec_snbase_ext,
&hfi_2dparityfec_payload,
};
#endif
/* Setup protocol subtree array */
static gint *ett[] = {

View File

@ -174,10 +174,12 @@ dissect_acap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_acap(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_acap_response,
&hfi_acap_request,
};
#endif
static gint *ett[] = {
&ett_acap,

View File

@ -1120,6 +1120,7 @@ dissect_bitcoin_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
void
proto_register_bitcoin(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_bitcoin_magic,
&hfi_bitcoin_command,
@ -1248,6 +1249,7 @@ proto_register_bitcoin(void)
&hfi_string_varint_count32,
&hfi_string_varint_count64,
};
#endif
static gint *ett[] = {
&ett_bitcoin,

View File

@ -119,12 +119,14 @@ dissect_data(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree)
void
proto_register_data(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_data_data,
&hfi_data_text,
&hfi_data_md5_hash,
&hfi_data_len,
};
#endif
static gint *ett[] = {
&ett_data

View File

@ -77,9 +77,11 @@ dissect_daytime(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_daytime(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_daytime_string,
};
#endif
static gint *ett[] = {
&ett_daytime,

View File

@ -629,6 +629,7 @@ dissect_dbus_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
void
proto_register_dbus(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
/* Header */
&hfi_dbus_hdr,
@ -651,6 +652,7 @@ proto_register_dbus(void)
&hfi_dbus_value_str,
&hfi_dbus_value_double,
};
#endif
static gint *ett[] = {
&ett_dbus,

View File

@ -1860,7 +1860,7 @@ dissect_fcdns (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_fcdns (void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
/* &hfi_fcdns_gssubtype */
&hfi_fcdns_opcode,
@ -1927,6 +1927,7 @@ proto_register_fcdns (void)
&hfi_fcdns_fc4features_i,
&hfi_fcdns_fc4features_t,
};
#endif
static gint *ett[] = {
&ett_fcdns,

View File

@ -2038,6 +2038,7 @@ dissect_gadu_gadu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat
void
proto_register_gadu_gadu(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
/* Header */
&hfi_gadu_gadu_header_type_recv,
@ -2114,6 +2115,7 @@ proto_register_gadu_gadu(void)
/* Not dissected data */
&hfi_gadu_gadu_data,
};
#endif /* HAVE_HFI_SECTION_INIT */
static gint *ett[] = {
&ett_gadu_gadu,

View File

@ -104,10 +104,12 @@ dissect_hpext(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_hpext(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_hpext_dxsap,
&hfi_hpext_sxsap,
};
#endif
static gint *ett[] = {
&ett_hpext

View File

@ -203,11 +203,13 @@ dissect_form_urlencoded(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi
void
proto_register_http_urlencoded(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_form_keyvalue,
&hfi_form_key,
&hfi_form_value,
};
#endif
static gint *ett[] = {
&ett_form_urlencoded,

View File

@ -610,6 +610,7 @@ dissect_gif_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
void
proto_register_gif(void)
{
#ifndef HAVE_HFI_SECTION_INIT
/*
* Setup list of header fields.
*/
@ -661,6 +662,7 @@ proto_register_gif(void)
*/
&hfi_trailer,
};
#endif
/* Setup protocol subtree array */
static gint *ett[] = {

View File

@ -406,6 +406,7 @@ dissect_png(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *da
void
proto_register_png(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] =
{
&hfi_png_signature,
@ -440,6 +441,7 @@ proto_register_png(void)
&hfi_png_bkgd_green,
&hfi_png_bkgd_blue,
};
#endif
static gint *ett[] =
{

View File

@ -259,7 +259,7 @@ dissect_jpeg( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
void
proto_register_jpeg(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] =
{
&hfi_rtp_jpeg_main_hdr,
@ -281,6 +281,7 @@ proto_register_jpeg(void)
&hfi_rtp_jpeg_qtable_hdr_data,
&hfi_rtp_jpeg_payload,
};
#endif
static gint *ett[] =
{

View File

@ -566,6 +566,7 @@ proto_register_json(void) {
&ett_json_member
};
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_json_array,
&hfi_json_object,
@ -577,6 +578,7 @@ proto_register_json(void) {
&hfi_json_value_null,
&hfi_json_value_true,
};
#endif
int proto_json;

View File

@ -674,6 +674,7 @@ dissect_mint_ethshim_static(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
void
proto_register_mint(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
/* MiNT Eth Shim */
@ -722,6 +723,8 @@ proto_register_mint(void)
&hfi_mint_control_0x22_length,
&hfi_mint_control_0x22_value,
};
#endif
static gint *ett[] = {
&ett_mint_ethshim,
&ett_mint,

View File

@ -354,6 +354,7 @@ dissect_nflog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_nflog(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
/* Header */
&hfi_nflog_family,
@ -371,6 +372,7 @@ proto_register_nflog(void)
&hfi_nflog_tlv_timestamp,
&hfi_nflog_tlv_unknown,
};
#endif
static gint *ett[] = {
&ett_nflog,

View File

@ -186,6 +186,7 @@ dissect_redback(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
void
proto_register_redback(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_redback_context,
&hfi_redback_flags,
@ -197,6 +198,7 @@ proto_register_redback(void)
&hfi_redback_padding,
&hfi_redback_unknown,
};
#endif
static gint *ett[] = {
&ett_redback

View File

@ -308,6 +308,7 @@ void proto_reg_handoff_rsync(void);
void
proto_register_rsync(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_rsync_hdr_magic,
&hfi_rsync_hdr_version,
@ -318,6 +319,7 @@ proto_register_rsync(void)
&hfi_rsync_command_string,
&hfi_rsync_data,
};
#endif
static gint *ett[] = {
&ett_rsync,

View File

@ -63,10 +63,12 @@ static const vsff rwall1_proc[] = {
void
proto_register_rwall(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_rwall_procedure_v1,
&hfi_rwall_message,
};
#endif
static gint *ett[] = {
&ett_rwall,

View File

@ -326,6 +326,7 @@ static const vsff stat1_proc[] = {
void
proto_register_stat(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_stat_procedure_v1,
&hfi_stat_mon_name,
@ -343,6 +344,7 @@ proto_register_stat(void)
&hfi_stat_state,
&hfi_stat_stat_chge,
};
#endif
static gint *ett[] = {
&ett_stat,

View File

@ -180,11 +180,13 @@ dissect_tali_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat
void
proto_register_tali(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_tali_sync_indicator,
&hfi_tali_opcode_indicator,
&hfi_tali_length_indicator
};
#endif
/* Setup protocol subtree array */
static gint *ett[] = {

View File

@ -716,6 +716,7 @@ proto_register_udp(void)
module_t *udplite_module;
expert_module_t* expert_udp;
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_udp_srcport,
&hfi_udp_dstport,
@ -738,6 +739,7 @@ proto_register_udp(void)
&hfi_udplite_checksum_coverage_bad,
&hfi_udplite_checksum_coverage,
};
#endif
static gint *ett[] = {
&ett_udp,

View File

@ -323,7 +323,7 @@ static gboolean dissect_xcsl_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_t
/* register the various xcsl protocol filters */
void proto_register_xcsl(void) {
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
&hfi_xcsl_protocol_version,
&hfi_xcsl_transaction_id,
@ -332,6 +332,7 @@ void proto_register_xcsl(void) {
&hfi_xcsl_parameter,
&hfi_xcsl_information,
};
#endif
/* Setup protocol subtree array */
static gint *ett[] = {

View File

@ -547,6 +547,7 @@ dissect_yami(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
void
proto_register_yami(void)
{
#ifndef HAVE_HFI_SECTION_INIT
static header_field_info *hfi[] = {
/* Header */
&hfi_yami_message_id,
@ -568,6 +569,7 @@ proto_register_yami(void)
&hfi_yami_params_count,
&hfi_yami_items_count,
};
#endif
static gint *ett[] = {
&ett_yami,

View File

@ -4580,14 +4580,30 @@ proto_set_cant_toggle(const int proto_id)
protocol->can_toggle = FALSE;
}
static int
proto_register_field_common(protocol_t *proto, header_field_info *hfi, const int parent)
{
if (proto != NULL) {
if (proto->fields == NULL) {
proto->fields = g_slist_append(NULL, hfi);
proto->last_field = proto->fields;
} else {
proto->last_field =
g_slist_append(proto->last_field, hfi)->next;
}
}
return proto_register_field_init(hfi, parent);
}
/* for use with static arrays only, since we don't allocate our own copies
of the header_field_info struct contained within the hf_register_info struct */
void
proto_register_field_array(const int parent, hf_register_info *hf, const int num_records)
{
int field_id, i;
hf_register_info *ptr = hf;
protocol_t *proto;
int i;
proto = find_protocol_by_id(parent);
for (i = 0; i < num_records; i++, ptr++) {
@ -4606,22 +4622,34 @@ proto_register_field_array(const int parent, hf_register_info *hf, const int num
return;
}
if (proto != NULL) {
if (proto->fields == NULL) {
proto->fields = g_slist_append(NULL, &ptr->hfinfo);
proto->last_field = proto->fields;
} else {
proto->last_field =
g_slist_append(proto->last_field, &ptr->hfinfo)->next;
}
}
field_id = proto_register_field_init(&ptr->hfinfo, parent);
*ptr->p_id = field_id;
*ptr->p_id = proto_register_field_common(proto, &ptr->hfinfo, parent);
}
}
void
proto_register_fields(const int parent, header_field_info **hfi, const int num_records)
proto_register_fields_section(const int parent, header_field_info *hfi, const int num_records)
{
int i;
protocol_t *proto;
proto = find_protocol_by_id(parent);
for (i = 0; i < num_records; i++) {
/*
* Make sure we haven't registered this yet.
*/
if (hfi[i].id != -1) {
fprintf(stderr,
"Duplicate field detected in call to proto_register_fields: %s is already registered\n",
hfi[i].abbrev);
return;
}
proto_register_field_common(proto, &hfi[i], parent);
}
}
void
proto_register_fields_manual(const int parent, header_field_info **hfi, const int num_records)
{
int i;
protocol_t *proto;
@ -4633,21 +4661,12 @@ proto_register_fields(const int parent, header_field_info **hfi, const int num_r
*/
if (hfi[i]->id != -1) {
fprintf(stderr,
"Duplicate field detected in call to proto_register_field_array: %s is already registered\n",
"Duplicate field detected in call to proto_register_fields: %s is already registered\n",
hfi[i]->abbrev);
return;
}
if (proto != NULL) {
if (proto->fields == NULL) {
proto->fields = g_slist_append(NULL, hfi[i]);
proto->last_field = proto->fields;
} else {
proto->last_field =
g_slist_append(proto->last_field, hfi[i])->next;
}
}
proto_register_field_init(hfi[i], parent);
proto_register_field_common(proto, hfi[i], parent);
}
}

View File

@ -1675,7 +1675,8 @@ proto_register_prefix(const char *prefix, prefix_initializer_t initializer);
/** Initialize every remaining uninitialized prefix. */
WS_DLL_PUBLIC void proto_initialize_all_prefixes(void);
WS_DLL_PUBLIC void proto_register_fields(const int parent, header_field_info **hfi, const int num_records);
WS_DLL_PUBLIC void proto_register_fields_manual(const int parent, header_field_info **hfi, const int num_records);
WS_DLL_PUBLIC void proto_register_fields_section(const int parent, header_field_info *hfi, const int num_records);
/** Register a header_field array.
@param parent the protocol handle from proto_register_protocol()
@ -2118,7 +2119,21 @@ proto_custom_set(proto_tree* tree, const int field_id,
gchar *result,
gchar *expr, const int size );
#define HFI_INIT(proto)
/* #define HAVE_HFI_SECTION_INIT */
#ifdef HAVE_HFI_SECTION_INIT
#define HFI_INIT(proto) __attribute__((section( "_data_" G_STRINGIFY(proto) )))
#define proto_register_fields(proto, hfi, count) \
extern header_field_info __start__data_ ##proto[]; \
extern header_field_info __stop__data_ ##proto[]; \
\
proto_register_fields_section(proto, __start__data_ ##proto, (int) (__stop__data_ ##proto - __start__data_ ##proto))
#else
#define HFI_INIT(proto)
#define proto_register_fields(proto, hfi, count) \
proto_register_fields_manual(proto, hfi, count)
#endif
#ifdef NEW_PROTO_TREE_API
#define proto_tree_add_item(tree, hfinfo, tvb, start, length, encoding) \