static void add_dix_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, int trailer_id, tvbuff_t *tvb, tvbuff_t *next_tvb, int offset_after_etype, guint length_before, gint fcs_len) { guint length; tvbuff_t *trailer_tvb; /* OK, how much is there in that tvbuff now? */ length = tvb_reported_length(next_tvb); /* If there's less than there was before, what's left is a trailer. */ if (length < length_before) { /* * Is any of the padding present in the tvbuff? */ if (tvb_offset_exists(tvb, offset_after_etype + length)) { /* * Yes - create a tvbuff for the padding. */ trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_etype + length); } else { /* * No - don't bother showing the trailer. * XXX - show a Short Frame indication? */ trailer_tvb = NULL; } } else trailer_tvb = NULL; /* no trailer */ add_ethernet_trailer(pinfo, tree, fh_tree, trailer_id, tvb, trailer_tvb, fcs_len); }
/* 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 void dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *fh_tree; /* Some devices slice the packet and add their own trailer before putting the frame on the network. Make sure these packets get a proper trailer (even though the sliced frame might not properly dissect. */ if ( (eth_trailer_length > 0) && (eth_trailer_length < tvb_length(tvb)) ) { tvbuff_t *next_tvb; guint total_trailer_length; total_trailer_length = eth_trailer_length + (eth_assume_fcs ? 4 : 0); /* Dissect the tvb up to, but not including the trailer */ next_tvb = tvb_new_subset(tvb, 0, tvb_length(tvb) - total_trailer_length, tvb_reported_length(tvb) - total_trailer_length); fh_tree = dissect_eth_common(next_tvb, pinfo, tree, 0); /* Now handle the ethernet trailer and optional FCS */ next_tvb = tvb_new_subset_remaining(tvb, tvb_length(tvb) - total_trailer_length); add_ethernet_trailer(pinfo, tree, fh_tree, hf_eth_trailer, tvb, next_tvb, eth_assume_fcs ? 4 : pinfo->pseudo_header->eth.fcs_len); } else { dissect_eth_common(tvb, pinfo, tree, eth_assume_fcs ? 4 : pinfo->pseudo_header->eth.fcs_len); } }
void dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb, int offset_after_length, packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, int length_id, int trailer_id, expert_field* ei_len, int fcs_len) { proto_item *length_it; tvbuff_t *volatile next_tvb = NULL; tvbuff_t *trailer_tvb = NULL; const char *saved_proto; gint captured_length, reported_length; void *pd_save; length_it = proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2, length); /* Get the length of the payload. If the FCS length is positive, remove the FCS. (If it's zero, there's no FCS; if it's negative, we don't know whether there's an FCS, so we'll guess based on the length of the trailer.) */ reported_length = tvb_reported_length_remaining(tvb, offset_after_length); if (fcs_len > 0) { if (reported_length >= fcs_len) reported_length -= fcs_len; } /* Make sure the length in the 802.3 header doesn't go past the end of the payload. */ if (length > reported_length) { length = reported_length; expert_add_info(pinfo, length_it, ei_len); } /* Give the next dissector only 'length' number of bytes. */ captured_length = tvb_captured_length_remaining(tvb, offset_after_length); if (captured_length > length) captured_length = length; next_tvb = tvb_new_subset(tvb, offset_after_length, captured_length, length); /* Dissect the payload either as IPX or as an LLC frame. Catch non-fatal exceptions, so that if the reported length of "next_tvb" was reduced by some dissector before an exception was thrown, we can still put in an item for the trailer. */ saved_proto = pinfo->current_proto; pd_save = pinfo->private_data; TRY { if (is_802_2) call_dissector(llc_handle, next_tvb, pinfo, tree); else { /* Check if first three bits of payload are 0x7. If so, then payload is IPX. If not, then it's CCSDS. Refer to packet-eth.c for setting of is_802_2 variable. */ if (tvb_get_bits8(next_tvb, 0, 3) == 7) call_dissector(ipx_handle, next_tvb, pinfo, tree); else call_dissector(ccsds_handle, next_tvb, pinfo, tree); } } CATCH_NONFATAL_ERRORS { /* Somebody threw an exception that means that there was a problem dissecting the payload; that means that a dissector was found, so we don't need to dissect the payload as data or update the protocol or info columns. Just show the exception and then drive on to show the trailer, after noting that a dissector was found and restoring the protocol value that was in effect before we called the subdissector. */ pinfo->private_data = pd_save; show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; /* Restore the protocol value, so that any exception thrown by tvb_new_subset_remaining() refers to the protocol for which this is a trailer, and restore the private_data structure in case one of the called dissectors modified it. */ pinfo->private_data = pd_save; pinfo->current_proto = saved_proto; /* Construct a tvbuff for the trailer; if the trailer is past the end of the captured data, this will throw a BoundsError, which is what we want, as it'll report that the packet was cut short. */ trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_length + length); add_ethernet_trailer(pinfo, tree, fh_tree, trailer_id, tvb, trailer_tvb, fcs_len); }
void dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb, int offset_after_length, packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, int length_id, int trailer_id, int fcs_len) { proto_item *length_it; tvbuff_t *volatile next_tvb = NULL; tvbuff_t *volatile trailer_tvb = NULL; const char *saved_proto; gint captured_length, reported_length; length_it = proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2, length); /* Get the length of the payload. If the FCS length is positive, remove the FCS. (If it's zero, there's no FCS; if it's negative, we don't know whether there's an FCS, so we'll guess based on the length of the trailer.) */ reported_length = tvb_reported_length_remaining(tvb, offset_after_length); if (fcs_len > 0) { if (reported_length >= fcs_len) reported_length -= fcs_len; } /* Make sure the length in the 802.3 header doesn't go past the end of the payload. */ if (length > reported_length) { length = reported_length; expert_add_info_format(pinfo, length_it, PI_MALFORMED, PI_ERROR, "Length field value goes past the end of the payload"); } /* Give the next dissector only 'length' number of bytes. */ captured_length = tvb_length_remaining(tvb, offset_after_length); if (captured_length > length) captured_length = length; next_tvb = tvb_new_subset(tvb, offset_after_length, captured_length, length); TRY { trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_length + length); } CATCH2(BoundsError, ReportedBoundsError) { /* The packet has exactly "length" bytes worth of captured data left in it, so the "tvb_new_subset()" creating "trailer_tvb" threw an exception. This means that all the data in the frame is within the length value (assuming our offset isn't past the end of the tvb), so we give all the data to the next protocol and have no trailer. */ trailer_tvb = NULL; } ENDTRY; /* Dissect the payload either as IPX or as an LLC frame. Catch BoundsError and ReportedBoundsError, so that if the reported length of "next_tvb" was reduced by some dissector before an exception was thrown, we can still put in an item for the trailer. */ saved_proto = pinfo->current_proto; TRY { if (is_802_2) call_dissector(llc_handle, next_tvb, pinfo, tree); else { /* Check if first three bits of payload are 0x7. If so, then payload is IPX. If not, then it's CCSDS. Refer to packet-eth.c for setting of is_802_2 variable. */ if (tvb_get_bits8(next_tvb, 0, 3) == 7) call_dissector(ipx_handle, next_tvb, pinfo, tree); else call_dissector(ccsds_handle, next_tvb, pinfo, tree); } } CATCH(BoundsError) { /* Somebody threw BoundsError, which means that dissecting the payload found that the packet was cut off by a snapshot length before the end of the payload. The trailer comes after the payload, so *all* of the trailer is cut off - don't bother adding the trailer, just rethrow the exception so it gets reported. */ RETHROW; } CATCH_ALL { /* Well, somebody threw an exception other than BoundsError. Show the exception, and then drive on to show the trailer, restoring the protocol value that was in effect before we called the subdissector. */ show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); pinfo->current_proto = saved_proto; } ENDTRY; add_ethernet_trailer(pinfo, fh_tree, trailer_id, tvb, trailer_tvb, fcs_len); }