Separate "Ethernet in capture file" and "Ethernet maybe with FCS" dissectors.

Have a dissector that is passed a "struct eth_phdr" pointer, indicating
whether there is an FCS, there is no FCS, or there's maybe an FCS, and
an "eth_maybefcs" dissector, to be called from other dissectors.  The
latter takes no data argument.

That obviates the need for callers of the latter to fill in an
"eth_phdr" structure.

Note in a comment that setting the "assume an FCS" preference overrides
a file format handler in Wiretap saying "we have no FCS".  I seem to
remember that this might be intentional.

Ping-Bug: 9933
Change-Id: I600e1351d468ab31d48369edb96832d6da3e480c
Reviewed-on: https://code.wireshark.org/review/13432
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-01-20 01:46:34 -08:00
parent 47648e0528
commit eeff506f56
5 changed files with 38 additions and 28 deletions

View File

@ -145,7 +145,7 @@ static dissector_handle_t fr_handle;
static dissector_handle_t llc_handle;
static dissector_handle_t sscop_handle;
static dissector_handle_t ppp_handle;
static dissector_handle_t eth_handle;
static dissector_handle_t eth_maybefcs_handle;
static dissector_handle_t ip_handle;
static dissector_handle_t data_handle;
@ -992,12 +992,9 @@ dissect_reassembled_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
* See RFC 2684 section 6.2 "VC Multiplexing of Bridged
* Protocols".
*/
struct eth_phdr eth;
proto_tree_add_item(tree, hf_atm_padding, tvb, 0, 2, ENC_NA);
next_tvb = tvb_new_subset_remaining(tvb, 2);
eth.fcs_len = -1; /* We don't know whether there's an FCS */
call_dissector_with_data(eth_handle, next_tvb, pinfo, tree, &eth);
call_dissector(eth_maybefcs_handle, next_tvb, pinfo, tree);
decoded = TRUE;
}
else if (octet[2] == 0x03 && /* NLPID */
@ -2018,7 +2015,7 @@ proto_reg_handoff_atm(void)
llc_handle = find_dissector("llc");
sscop_handle = find_dissector("sscop");
ppp_handle = find_dissector("ppp");
eth_handle = find_dissector("eth");
eth_maybefcs_handle = find_dissector("eth_maybefcs");
ip_handle = find_dissector("ip");
data_handle = find_dissector("data");

View File

@ -72,7 +72,7 @@ static const true_false_string ooodl_tfs = {
"Deliver in order (If DA) or Learn (If SA)"
};
static dissector_handle_t eth_dissector ;
static dissector_handle_t eth_maybefcs_dissector ;
#define FP_PROTO_COL_NAME "FabricPath"
@ -218,7 +218,6 @@ dissect_fp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
guint16 dlid = 0;
const guint8 *dst_addr = NULL;
gboolean dest_ig = FALSE;
struct eth_phdr eth;
col_set_str( pinfo->cinfo, COL_PROTOCOL, FP_PROTO_COL_NAME ) ;
col_set_str( pinfo->cinfo, COL_INFO, FP_PROTO_COL_INFO ) ;
@ -295,11 +294,9 @@ dissect_fp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
/* call the eth dissector */
next_tvb = tvb_new_subset_remaining( tvb, FP_HEADER_SIZE) ;
/*
* For now, say we don't know whether there's an FCS in the
* captured data.
* For now, we don't know whether there's an FCS in the captured data.
*/
eth.fcs_len = -1;
call_dissector_with_data( eth_dissector, next_tvb, pinfo, tree, &eth ) ;
call_dissector( eth_maybefcs_dissector, next_tvb, pinfo, tree ) ;
return tvb_captured_length( tvb ) ;
}
@ -416,7 +413,7 @@ proto_reg_handoff_fabricpath(void)
* by the Ethernet dissector. This needs more work, so we leave this
* as calling the "eth" dissector as a reminder.
*/
eth_dissector = find_dissector( "eth" );
eth_maybefcs_dissector = find_dissector( "eth_maybefcs" );
prefs_initialized = TRUE;
}
}

View File

@ -54,7 +54,7 @@ static expert_field ei_epon_dpoe_bad = EI_INIT;
static expert_field ei_epon_dpoe_encrypted_data = EI_INIT;
static expert_field ei_epon_checksum_bad = EI_INIT;
static dissector_handle_t eth_handle;
static dissector_handle_t eth_maybefcs_handle;
static gint ett_epon = -1;
static gint ett_epon_sec = -1;
@ -79,7 +79,6 @@ dissect_epon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
guint offset = 0;
guint dpoe_sec_byte;
gboolean dpoe_encrypted = FALSE;
struct eth_phdr eth;
/* Start_of_Packet delimiter (/S/) can either happen in byte 1 or byte 2,
* making the captured preamble either 7 or 6 bytes in length. If the
@ -200,8 +199,7 @@ dissect_epon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
* XXX - is it guaranteed whether the capture will, or won't, have
* an FCS?
*/
eth.fcs_len = -1;
call_dissector_with_data(eth_handle, next_tvb, pinfo, tree, &eth);
call_dissector(eth_maybefcs_handle, next_tvb, pinfo, tree);
}
return tvb_captured_length(tvb);
@ -297,7 +295,7 @@ proto_reg_handoff_epon(void)
epon_handle = create_dissector_handle(dissect_epon, proto_epon);
dissector_add_uint("wtap_encap", WTAP_ENCAP_EPON, epon_handle);
eth_handle = find_dissector("eth");
eth_maybefcs_handle = find_dissector("eth_maybefcs");
}
/*

View File

@ -795,7 +795,7 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
/* Called for the Ethernet Wiretap encapsulation type; pass the FCS length
reported to us, or, if the "assume_fcs" preference is set, pass 4. */
static int
dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
struct eth_phdr *eth = (struct eth_phdr *)data;
proto_tree *fh_tree;
@ -808,6 +808,10 @@ dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
tvbuff_t *next_tvb;
guint total_trailer_length;
/*
* XXX - this overrides Wiretap saying "this packet definitely has
* no FCS".
*/
total_trailer_length = eth_trailer_length + (eth_assume_fcs ? 4 : 0);
/* Dissect the tvb up to, but not including the trailer */
@ -818,9 +822,17 @@ dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
/* Now handle the ethernet trailer and optional FCS */
next_tvb = tvb_new_subset_remaining(tvb, tvb_captured_length(tvb) - total_trailer_length);
/*
* XXX - this overrides Wiretap saying "this packet definitely has
* no FCS".
*/
add_ethernet_trailer(pinfo, tree, fh_tree, hf_eth_trailer, tvb, next_tvb,
eth_assume_fcs ? 4 : eth->fcs_len);
} else {
/*
* XXX - this overrides Wiretap saying "this packet definitely has
* no FCS".
*/
dissect_eth_common(tvb, pinfo, tree, eth_assume_fcs ? 4 : eth->fcs_len);
}
return tvb_captured_length(tvb);
@ -843,6 +855,14 @@ dissect_eth_withfcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* d
return tvb_captured_length(tvb);
}
/* ...and this one's for encapsulated packets that might or might not. */
static int
dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
dissect_eth_common(tvb, pinfo, tree, eth_assume_fcs ? 4 : -1);
return tvb_captured_length(tvb);
}
void
proto_register_eth(void)
{
@ -1008,7 +1028,7 @@ proto_register_eth(void)
register_dissector("eth_withoutfcs", dissect_eth_withoutfcs, proto_eth);
register_dissector("eth_withfcs", dissect_eth_withfcs, proto_eth);
register_dissector("eth", dissect_eth_maybefcs, proto_eth);
register_dissector("eth_maybefcs", dissect_eth_maybefcs, proto_eth);
eth_tap = register_tap("eth");
register_conversation_table(proto_eth, TRUE, eth_conversation_packet, eth_hostlist_packet);
@ -1018,7 +1038,7 @@ proto_register_eth(void)
void
proto_reg_handoff_eth(void)
{
dissector_handle_t eth_maybefcs_handle, eth_withoutfcs_handle;
dissector_handle_t eth_handle, eth_withoutfcs_handle;
/* Get a handle for the Firewall-1 dissector. */
fw1_handle = find_dissector("fw1");
@ -1029,8 +1049,8 @@ proto_reg_handoff_eth(void)
/* Get a handle for the generic data dissector. */
data_handle = find_dissector("data");
eth_maybefcs_handle = find_dissector("eth");
dissector_add_uint("wtap_encap", WTAP_ENCAP_ETHERNET, eth_maybefcs_handle);
eth_handle = create_dissector_handle(dissect_eth, proto_eth);
dissector_add_uint("wtap_encap", WTAP_ENCAP_ETHERNET, eth_handle);
eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
dissector_add_uint("ethertype", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);

View File

@ -101,7 +101,7 @@ static const value_string tzsp_encapsulation[] = {
static gint ett_tzsp = -1;
static gint ett_tag = -1;
static dissector_handle_t eth_handle;
static dissector_handle_t eth_maybefcs_handle;
static dissector_handle_t tr_handle;
static dissector_handle_t ppp_handle;
static dissector_handle_t fddi_handle;
@ -289,7 +289,6 @@ dissect_tzsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
guint16 encapsulation = 0;
const char *info;
guint8 type;
struct eth_phdr eth;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "TZSP");
col_clear(pinfo->cinfo, COL_INFO);
@ -340,8 +339,7 @@ dissect_tzsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
switch (encapsulation) {
case TZSP_ENCAP_ETHERNET:
eth.fcs_len = -1; /* not known */
call_dissector_with_data(eth_handle, next_tvb, pinfo, tree, &eth);
call_dissector(eth_maybefcs_handle, next_tvb, pinfo, tree);
break;
case TZSP_ENCAP_TOKEN_RING:
@ -556,7 +554,7 @@ proto_reg_handoff_tzsp(void)
dissector_add_uint("udp.port", UDP_PORT_TZSP, tzsp_handle);
/* Get the data dissector for handling various encapsulation types. */
eth_handle = find_dissector("eth");
eth_maybefcs_handle = find_dissector("eth_maybefcs");
tr_handle = find_dissector("tr");
ppp_handle = find_dissector("ppp_hdlc");
fddi_handle = find_dissector("fddi");