packet-erf: added dissector table for "erf.types.type" type field.

1- removed unnecessary include <wiretap/erf.h>
2- used fall through in protocol switch case instead of calling same
function with same params.

fixes/changes after review with Evan Huus, changes ETH/IPv4/IPv6/Infiniband/InfinibandLink
to use dissector table instead of direct function calls.
other protocols should be called in the same way, we'll do it when have
the time.

instead of calling subdissector directly from packet-erf.c code it's
easier to declare this and each time we need to register a new
protocol over erf format we sould easily extend it from the protcol module
instead using "dissector_add_uint()" function.

the change is still backward compatible, if no upper protocol is
registered for the specifc type an old fasion direct function call
is performed.

Change-Id: I3ae1ccfdd49ab8f90667185296cc950dc2184475
Reviewed-on: https://code.wireshark.org/review/3670
Petri-Dish: Evan Huus <eapache@gmail.com>
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Wasim Abu Moch 2014-08-17 15:24:14 +03:00 committed by Michael Mann
parent ca5fa539f5
commit 401469880b
5 changed files with 26 additions and 53 deletions

View File

@ -108,6 +108,7 @@ typedef struct sdh_g707_format_s
} sdh_g707_format_t;
static dissector_handle_t erf_handle;
static dissector_table_t erf_dissector_table;
/* Initialize the protocol and registered fields */
static int proto_erf = -1;
@ -284,13 +285,6 @@ static expert_field ei_erf_checksum_error = EI_INIT;
/* Default subdissector, display raw hex data */
static dissector_handle_t data_handle;
/* IPv4 and IPv6 subdissectors */
static dissector_handle_t ipv4_handle;
static dissector_handle_t ipv6_handle;
static dissector_handle_t infiniband_handle;
static dissector_handle_t infiniband_link_handle;
typedef enum {
ERF_HDLC_CHDLC = 0,
ERF_HDLC_PPP = 1,
@ -315,7 +309,6 @@ static gint erf_aal5_type = ERF_AAL5_GUESS;
static dissector_handle_t atm_untruncated_handle;
static gboolean erf_ethfcs = TRUE;
static dissector_handle_t ethwithfcs_handle, ethwithoutfcs_handle;
static dissector_handle_t sdh_handle;
@ -1241,7 +1234,7 @@ dissect_erf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
switch (erf_type) {
case ERF_TYPE_RAW_LINK:
if(sdh_handle){
if(sdh_handle) {
call_dissector(sdh_handle, tvb, pinfo, tree);
}
else{
@ -1249,32 +1242,18 @@ dissect_erf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
break;
case ERF_TYPE_ETH:
case ERF_TYPE_COLOR_ETH:
case ERF_TYPE_DSM_COLOR_ETH:
dissect_eth_header(tvb, pinfo, erf_tree);
/* fall through */
case ERF_TYPE_IPV4:
if (ipv4_handle)
call_dissector(ipv4_handle, tvb, pinfo, tree);
else
call_dissector(data_handle, tvb, pinfo, tree);
break;
case ERF_TYPE_IPV6:
if (ipv6_handle)
call_dissector(ipv6_handle, tvb, pinfo, tree);
else
call_dissector(data_handle, tvb, pinfo, tree);
break;
case ERF_TYPE_INFINIBAND:
if (infiniband_handle)
call_dissector(infiniband_handle, tvb, pinfo, tree);
else
call_dissector(data_handle, tvb, pinfo, tree);
break;
case ERF_TYPE_INFINIBAND_LINK:
if (infiniband_link_handle)
call_dissector(infiniband_link_handle, tvb, pinfo, tree);
else
if (!dissector_try_uint(erf_dissector_table, erf_type, tvb, pinfo, tree)) {
call_dissector(data_handle, tvb, pinfo, tree);
}
break;
case ERF_TYPE_LEGACY:
@ -1445,16 +1424,6 @@ dissect_erf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
call_dissector(atm_untruncated_handle, new_tvb, pinfo, tree);
break;
case ERF_TYPE_ETH:
case ERF_TYPE_COLOR_ETH:
case ERF_TYPE_DSM_COLOR_ETH:
dissect_eth_header(tvb, pinfo, erf_tree);
if (erf_ethfcs)
call_dissector(ethwithfcs_handle, tvb, pinfo, tree);
else
call_dissector(ethwithoutfcs_handle, tvb, pinfo, tree);
break;
case ERF_TYPE_MC_HDLC:
dissect_mc_hdlc_header(tvb, pinfo, erf_tree);
/* continue with type HDLC */
@ -1963,6 +1932,8 @@ proto_register_erf(void)
"Ethernet packets have FCS",
"Whether the FCS is present in Ethernet packets",
&erf_ethfcs);
erf_dissector_table = register_dissector_table("erf.types.type", "Type", FT_UINT8, BASE_DEC);
}
void
@ -1973,14 +1944,6 @@ proto_reg_handoff_erf(void)
/* Dissector called to dump raw data, or unknown protocol */
data_handle = find_dissector("data");
/* Get handle for IP dissectors) */
ipv4_handle = find_dissector("ip");
ipv6_handle = find_dissector("ipv6");
/* Get handle for Infiniband dissector */
infiniband_handle = find_dissector("infiniband");
infiniband_link_handle = find_dissector("infiniband_link");
/* Get handles for serial line protocols */
chdlc_handle = find_dissector("chdlc");
ppp_handle = find_dissector("ppp_hdlc");
@ -1990,9 +1953,5 @@ proto_reg_handoff_erf(void)
/* Get handle for ATM dissector */
atm_untruncated_handle = find_dissector("atm_untruncated");
/* Get handles for Ethernet dissectors */
ethwithfcs_handle = find_dissector("eth_withfcs");
ethwithoutfcs_handle = find_dissector("eth_withoutfcs");
sdh_handle = find_dissector("sdh");
}

View File

@ -41,6 +41,7 @@
#include "packet-usb.h"
#include <epan/crc32-tvb.h>
#include <epan/tap.h>
#include <wiretap/erf.h>
void proto_register_eth(void);
void proto_reg_handoff_eth(void);
@ -1021,6 +1022,7 @@ proto_reg_handoff_eth(void)
eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
dissector_add_uint("ethertype", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);
dissector_add_uint("erf.types.type", ERF_TYPE_ETH, eth_withoutfcs_handle);
dissector_add_uint("chdlc.protocol", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);
dissector_add_uint("gre.proto", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);

View File

@ -38,6 +38,7 @@
#include <epan/etypes.h>
#include <epan/show_exception.h>
#include <epan/to_str.h>
#include <wiretap/erf.h>
#include "packet-infiniband.h"
@ -107,6 +108,7 @@ static gint ett_link = -1;
/* Dissector Declaration */
static dissector_handle_t ib_handle;
static dissector_handle_t ib_link_handle;
/* Subdissectors Declarations */
static dissector_handle_t ipv6_handle;
@ -7366,7 +7368,7 @@ void proto_register_infiniband(void)
&pref_dissect_eoib);
proto_infiniband_link = proto_register_protocol("InfiniBand Link", "InfiniBand Link", "infiniband_link");
register_dissector("infiniband_link", dissect_infiniband_link, proto_infiniband_link);
ib_link_handle = register_dissector("infiniband_link", dissect_infiniband_link, proto_infiniband_link);
proto_register_field_array(proto_infiniband_link, hf_link, array_length(hf_link));
proto_register_subtree_array(ett_link_array, array_length(ett_link_array));
@ -7386,6 +7388,12 @@ void proto_reg_handoff_infiniband(void)
eth_handle = find_dissector("eth");
ethertype_dissector_table = find_dissector_table("ethertype");
/* announce an anonymous Infiniband dissector */
dissector_add_uint("erf.types.type", ERF_TYPE_INFINIBAND, ib_handle);
/* announce an anonymous Infiniband dissector */
dissector_add_uint("erf.types.type", ERF_TYPE_INFINIBAND_LINK, ib_link_handle);
/* create and announce an anonymous RoCE dissector */
roce_handle = create_dissector_handle(dissect_roce, proto_infiniband);
dissector_add_uint("ethertype", ETHERTYPE_ROCE, roce_handle);

View File

@ -50,6 +50,7 @@
#include <epan/tap.h>
#include <epan/wmem/wmem.h>
#include <epan/decode_as.h>
#include <wiretap/erf.h>
#include "packet-ip.h"
@ -3104,6 +3105,7 @@ proto_reg_handoff_ip(void)
data_handle = find_dissector("data");
dissector_add_uint("ethertype", ETHERTYPE_IP, ip_handle);
dissector_add_uint("erf.types.type", ERF_TYPE_IPV4, ip_handle);
dissector_add_uint("ppp.protocol", PPP_IP, ip_handle);
dissector_add_uint("ppp.protocol", ETHERTYPE_IP, ip_handle);
dissector_add_uint("gre.proto", ETHERTYPE_IP, ip_handle);

View File

@ -47,6 +47,7 @@
#include <epan/wmem/wmem.h>
#include <epan/decode_as.h>
#include <epan/tap.h>
#include <wiretap/erf.h>
#include "packet-ipv6.h"
#include "packet-ip.h"
@ -2985,6 +2986,7 @@ proto_reg_handoff_ipv6(void)
data_handle = find_dissector("data");
ipv6_handle = find_dissector("ipv6");
dissector_add_uint("ethertype", ETHERTYPE_IPv6, ipv6_handle);
dissector_add_uint("erf.types.type", ERF_TYPE_IPV6, ipv6_handle);
dissector_add_uint("ppp.protocol", PPP_IPV6, ipv6_handle);
dissector_add_uint("ppp.protocol", ETHERTYPE_IPv6, ipv6_handle);
dissector_add_uint("gre.proto", ETHERTYPE_IPv6, ipv6_handle);