diff options
author | Sake Blok <sake@euronet.nl> | 2011-12-06 23:07:55 +0000 |
---|---|---|
committer | Sake Blok <sake@euronet.nl> | 2011-12-06 23:07:55 +0000 |
commit | efd2ce4116f944184e2588fcf382cfb828d4ddda (patch) | |
tree | b3c8f7d7fe22ef5f41d219271b31d935e3630e94 | |
parent | c2f07ae585384952f55c10ad5523345912d337ba (diff) |
- Make a distinction between ethernet padding and an ethernet trailer
- ... and make that distinction configurable for capture files that do not have padding in small frames, but do have trailers
- Add VSS-Monitoring dissector to show by the TAP inserted time- and portstamps
svn path=/trunk/; revision=40108
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | epan/dissectors/Makefile.common | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-eth.c | 63 | ||||
-rw-r--r-- | epan/dissectors/packet-vssmonitoring.c | 216 |
4 files changed, 270 insertions, 11 deletions
@@ -2798,6 +2798,7 @@ Sake Blok <sake [AT] euronet.nl> { Enable printing of all occurrences of fields Follow TCP stream enhancements Export SSL Session Keys + VSS-Monitoring dissector Miscellaneous enhancements and fixes } diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index 4745c25ee4..cf15caca45 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -1009,6 +1009,7 @@ DISSECTOR_SRC = \ packet-vmlab.c \ packet-vnc.c \ packet-vrrp.c \ + packet-vssmonitoring.c \ packet-vtp.c \ packet-vuze-dht.c \ packet-vxi11.c \ diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c index 5e9a377cba..cc98ffa449 100644 --- a/epan/dissectors/packet-eth.c +++ b/epan/dissectors/packet-eth.c @@ -43,6 +43,7 @@ #include <epan/expert.h> /* Assume all packets have an FCS */ +static gboolean eth_assume_padding = TRUE; static gboolean eth_assume_fcs = FALSE; static gboolean eth_check_fcs = TRUE; /* Interpret packets as FW1 monitor file packets if they look as if they are */ @@ -63,6 +64,7 @@ static int hf_eth_invalid_lentype = -1; static int hf_eth_addr = -1; static int hf_eth_lg = -1; static int hf_eth_ig = -1; +static int hf_eth_padding = -1; static int hf_eth_trailer = -1; static int hf_eth_fcs = -1; static int hf_eth_fcs_good = -1; @@ -496,7 +498,12 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, int trailer_id, tvbuff_t *tvb, tvbuff_t *trailer_tvb, int fcs_len) { /* If there're some bytes left over, show those bytes as a trailer. - + the trailer can contain: + - padding to meet the minimum 64 byte frame length + - information inserted by TAPs or other equipment + - an optional FCS (optional, because the FCS is usually stripped before + the frame is seen by us + However, if the Ethernet frame was claimed to have had 64 or more bytes - i.e., it was at least an FCS worth of data longer than the minimum payload size - assume the last 4 bytes of the trailer @@ -506,16 +513,38 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, if (trailer_tvb && fh_tree) { guint trailer_length, trailer_reported_length; + guint padding_length = 0; gboolean has_fcs = FALSE; - - if (dissector_try_heuristic(eth_trailer_subdissector_list, trailer_tvb, - pinfo, tree)) { - return; - } + tvbuff_t *real_trailer_tvb; trailer_length = tvb_length(trailer_tvb); trailer_reported_length = tvb_reported_length(trailer_tvb); + /* There can not have been padding when the length of the frame (including the + trailer) is less than 60 bytes. */ + if (eth_assume_padding && pinfo->fd->pkt_len>=60) { + /* Calculate the amount of padding needed for a minimum sized frame */ + if ( (pinfo->fd->pkt_len - trailer_reported_length) < 60 ) + padding_length = 60 - (pinfo->fd->pkt_len - trailer_reported_length); + + /* Add the padding to the tree, unless it should be treated as + part of the trailer and therefor be handed over to (one of) + the ethernet-trailer dissectors */ + if (padding_length > 0) { + tvb_ensure_bytes_exist(tvb, 0, padding_length); + proto_tree_add_item(fh_tree, hf_eth_padding, trailer_tvb, 0, + padding_length, FALSE); + trailer_length -= padding_length; + trailer_reported_length -= padding_length; + } + } + real_trailer_tvb = tvb_new_subset_remaining(trailer_tvb, padding_length); + + /* Call all ethernet trailer dissectors to dissect the trailer. */ + if ( dissector_try_heuristic(eth_trailer_subdissector_list, + real_trailer_tvb, pinfo, tree) ) + return; + if (fcs_len != 0) { /* If fcs_len is 4, we assume we definitely have an FCS. Otherwise, then, if the frame is big enough that, if we @@ -555,15 +584,15 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, } if (trailer_length != 0) { tvb_ensure_bytes_exist(tvb, 0, trailer_length); - proto_tree_add_item(fh_tree, trailer_id, trailer_tvb, 0, + proto_tree_add_item(fh_tree, trailer_id, real_trailer_tvb, 0, trailer_length, FALSE); } if (has_fcs) { - guint32 sent_fcs = tvb_get_ntohl(trailer_tvb, trailer_length); + guint32 sent_fcs = tvb_get_ntohl(real_trailer_tvb, trailer_length); if(eth_check_fcs){ guint32 fcs = crc32_802_tvb(tvb, tvb_length(tvb) - 4); if (fcs == sent_fcs) { - item = proto_tree_add_uint_format(fh_tree, hf_eth_fcs, trailer_tvb, + item = proto_tree_add_uint_format(fh_tree, hf_eth_fcs, real_trailer_tvb, trailer_length, 4, sent_fcs, "Frame check sequence: 0x%08x [correct]", sent_fcs); checksum_tree = proto_item_add_subtree(item, ett_eth_fcs); @@ -574,7 +603,7 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, trailer_length, 2, FALSE); PROTO_ITEM_SET_GENERATED(item); } else { - item = proto_tree_add_uint_format(fh_tree, hf_eth_fcs, trailer_tvb, + item = proto_tree_add_uint_format(fh_tree, hf_eth_fcs, real_trailer_tvb, trailer_length, 4, sent_fcs, "Frame check sequence: 0x%08x [incorrect, should be 0x%08x]", sent_fcs, fcs); @@ -589,7 +618,7 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree, col_append_str(pinfo->cinfo, COL_INFO, " [ETHERNET FRAME CHECK SEQUENCE INCORRECT]"); } }else{ - item = proto_tree_add_uint_format(fh_tree, hf_eth_fcs, trailer_tvb, + item = proto_tree_add_uint_format(fh_tree, hf_eth_fcs, real_trailer_tvb, trailer_length, 4, sent_fcs, "Frame check sequence: 0x%08x [validiation disabled]", sent_fcs); checksum_tree = proto_item_add_subtree(item, ett_eth_fcs); @@ -661,6 +690,10 @@ proto_register_eth(void) { "Address", "eth.addr", FT_ETHER, BASE_NONE, NULL, 0x0, "Source or Destination Hardware Address", HFILL }}, + { &hf_eth_padding, + { "Padding", "eth.padding", FT_BYTES, BASE_NONE, NULL, 0x0, + "Ethernet Padding", HFILL }}, + { &hf_eth_trailer, { "Trailer", "eth.trailer", FT_BYTES, BASE_NONE, NULL, 0x0, "Ethernet Trailer or Checksum", HFILL }}, @@ -707,6 +740,14 @@ proto_register_eth(void) /* Register configuration preferences */ eth_module = prefs_register_protocol(proto_eth, NULL); + prefs_register_bool_preference(eth_module, "assume_padding", + "Assume short frames which include a trailer contain padding", + "Some devices add trailing data to frames. When this setting is checked " + "the Ethernet dissector will assume there has been added padding to the " + "frame before the trailer was added. Uncheck if a device added a trailer " + "before the frame was padded.", + ð_assume_padding); + prefs_register_bool_preference(eth_module, "assume_fcs", "Assume packets have FCS", "Some Ethernet adapters and drivers include the FCS at the end of a packet, others do not. " diff --git a/epan/dissectors/packet-vssmonitoring.c b/epan/dissectors/packet-vssmonitoring.c new file mode 100644 index 0000000000..1f0ee4c886 --- /dev/null +++ b/epan/dissectors/packet-vssmonitoring.c @@ -0,0 +1,216 @@ +/* packet-vssmonitoring.c + * Routines for dissection of VSS-monitoring timestamp and portstamp + * + * Copyright VSS-Monitoring 2011 + * + * 20111205 - First edition by Sake Blok (sake.blok@SYN-bit.nl) + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdio.h> +#include <epan/packet.h> +#include <epan/prefs.h> + + +#define VSS_NS_MASK 0x3fffffff +#define CLKSRC_SHIFT 30 + +#define CLKSRC_LOCAL 0 +#define CLKSRC_NTP 1 +#define CLKSRC_GPS 2 +#define CLKSRC_PTP 3 + +static const value_string clksrc_vals[] = { + { CLKSRC_LOCAL, "Not Synced" }, + { CLKSRC_NTP, "NTP" }, + { CLKSRC_GPS, "GPS" }, + { CLKSRC_PTP, "PTP" }, + { 0, NULL } +}; + + +static int proto_vssmonitoring = -1; + +static int hf_vssmonitoring_time = -1; +static int hf_vssmonitoring_clksrc = -1; +static int hf_vssmonitoring_srcport = -1; + +static gint ett_vssmonitoring = -1; + +static gboolean vssmonitoring_use_heuristics = TRUE; + +static int +dissect_vssmonitoring(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + proto_tree *ti = NULL, *item = NULL; + proto_tree *vssmonitoring_tree = NULL; + guint offset = 0; + + guint trailer_len; + nstime_t vssmonitoring_time; + guint8 vssmonitoring_clksrc = 0; + guint8 vssmonitoring_srcport = 0; + + struct tm *tmp; + + + /* First get the length of the trailer */ + trailer_len = tvb_reported_length(tvb); + + /* The trailer length is a sum (of any combination) of: + * timestamp (8 bytes) + * port stamp (1 or 2 bytes) + * fcs (4 bytes) + * + * This means a trailer length must not be more than 14 bytes + */ + if ( trailer_len > 14 ) + return 0; + + /* ... and also a 1-byte port stamp can not co-exist with a 2-byte + * portstamp + */ + if ( (trailer_len & 3) == 3 ) + return 0; + + if ( trailer_len & 8 ) { + vssmonitoring_time.secs = tvb_get_ntohl(tvb, offset); + vssmonitoring_time.nsecs = tvb_get_ntohl(tvb, offset + 4); + vssmonitoring_clksrc = (guint8)(((guint32)vssmonitoring_time.nsecs) >> CLKSRC_SHIFT); + vssmonitoring_time.nsecs &= VSS_NS_MASK; + + /* There are only heuristics for timestamps, the port stamp can be any value */ + if ( vssmonitoring_use_heuristics ) { + + /* The timestamp will be based on the uptime untill the TAP is completely booted, + * this takes about 60s, but use 1 hour to be sure + */ + if (vssmonitoring_time.secs > 3600) { + + /* Check whether the timestamp in the PCAP header and the VSS-Monitoring + * differ less than 30 days, otherwise, this might not be a VSS-Monitoring + * timestamp + */ + if ( vssmonitoring_time.secs > pinfo->fd->abs_ts.secs ) { + if ( vssmonitoring_time.secs - pinfo->fd->abs_ts.secs > 2592000 ) /* 30 days */ + return 0; + } else { + if ( pinfo->fd->abs_ts.secs - vssmonitoring_time.secs > 2592000 ) /* 30 days */ + return 0; + } + } + + /* The nanoseconds field should be less than 1000000000 + */ + if ( vssmonitoring_time.nsecs >= 1000000000 ) + return 0; + } + } + + /* All systems are go, lets dissect the VSS-Monitoring trailer */ + if (tree) { + ti = proto_tree_add_item(tree, proto_vssmonitoring, + tvb, 0, (trailer_len & 0xb), ENC_NA); + vssmonitoring_tree = proto_item_add_subtree(ti, ett_vssmonitoring); + } + + /* Do we have a timestamp? */ + if ( trailer_len & 8 ) { + if (tree) { + item = proto_tree_add_time(vssmonitoring_tree, hf_vssmonitoring_time, tvb, offset, 8, &vssmonitoring_time); + item = proto_tree_add_uint(vssmonitoring_tree, hf_vssmonitoring_clksrc, tvb, offset + 4, 1, vssmonitoring_clksrc); + + tmp = localtime(&vssmonitoring_time.secs); + proto_item_append_text(ti, ", Timestamp: %02d:%02d:%02d.%09ld", + tmp->tm_hour, tmp->tm_min, tmp->tm_sec,(long)vssmonitoring_time.nsecs); + } + offset += 8; + } + + /* Do we have a portstamp? */ + if ( trailer_len & 3) { + if ( trailer_len & 1) { + vssmonitoring_srcport = tvb_get_guint8(tvb, offset); + if (tree) + item = proto_tree_add_item(vssmonitoring_tree, hf_vssmonitoring_srcport, tvb, offset, 1, ENC_NA); + offset++; + } else if ( trailer_len & 2) { + vssmonitoring_srcport = tvb_get_ntohs(tvb, offset); + if (tree) + item = proto_tree_add_item(vssmonitoring_tree, hf_vssmonitoring_srcport, tvb, offset, 2, ENC_NA); + offset += 2; + } + if (tree) + proto_item_append_text(ti, ", Source Port: %d", vssmonitoring_srcport); + } + + return offset; +} + +void +proto_register_vssmonitoring(void) +{ + static hf_register_info hf[] = { + { &hf_vssmonitoring_time, { + "Time Stamp", "vssmonitoring.time", + FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, + "VSS-Monitoring Time Stamp", HFILL }}, + + { &hf_vssmonitoring_clksrc, { + "Clock Source", "vssmonitoring.clksrc", + FT_UINT8, BASE_DEC, VALS(clksrc_vals), 0x0, + "VSS-Monitoring Clock Source", HFILL }}, + + { &hf_vssmonitoring_srcport, { + "Src Port", "vssmonitoring.srcport", + FT_UINT8, BASE_DEC, NULL, 0x0, + "VSS-Monitoring Source Port", HFILL }} + }; + + static gint *ett[] = { + &ett_vssmonitoring + }; + + module_t *vssmonitoring_module; + + proto_vssmonitoring = proto_register_protocol("VSS-Monitoring ethernet trailer", "VSS-Monitoring", "vssmonitoring"); + proto_register_field_array(proto_vssmonitoring, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + vssmonitoring_module = prefs_register_protocol(proto_vssmonitoring, NULL); + + prefs_register_bool_preference(vssmonitoring_module, "use_heuristics", + "Use heuristics to verify if trailer contains VSS-Monitoring data", + "When enabled, Wireshark will do a check on the trailer data to verify" + "whether it contains VSS-Monitoring time- and port-stamps.", + &vssmonitoring_use_heuristics); +} + +void +proto_reg_handoff_vssmonitoring(void) +{ + heur_dissector_add("eth.trailer", dissect_vssmonitoring, proto_vssmonitoring); +} |