1 /* packet-vssmonitoring.c
2 * Routines for dissection of VSS-monitoring timestamp and portstamp
4 * Copyright VSS-Monitoring 2011
6 * 20111205 - First edition by Sake Blok (sake.blok@SYN-bit.nl)
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
35 #define VSS_NS_MASK 0x3fffffff
36 #define CLKSRC_SHIFT 30
38 #define CLKSRC_LOCAL 0
43 static const value_string clksrc_vals
[] = {
44 { CLKSRC_LOCAL
, "Not Synced" },
45 { CLKSRC_NTP
, "NTP" },
46 { CLKSRC_GPS
, "GPS" },
47 { CLKSRC_PTP
, "PTP" },
52 static int proto_vssmonitoring
= -1;
54 static int hf_vssmonitoring_time
= -1;
55 static int hf_vssmonitoring_clksrc
= -1;
56 static int hf_vssmonitoring_srcport
= -1;
58 static gint ett_vssmonitoring
= -1;
60 static gboolean vssmonitoring_use_heuristics
= TRUE
;
63 dissect_vssmonitoring(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
65 proto_tree
*ti
= NULL
;
66 proto_tree
*vssmonitoring_tree
= NULL
;
70 nstime_t vssmonitoring_time
;
71 guint8 vssmonitoring_clksrc
= 0;
72 guint16 vssmonitoring_srcport
= 0;
77 /* First get the length of the trailer */
78 trailer_len
= tvb_reported_length(tvb
);
80 /* The trailer length is a sum (of any combination) of:
82 * port stamp (1 or 2 bytes)
85 * The FCS is dissected by our caller, so we check for a trailer
86 * with a length that includes one or more of a time stamp and
87 * a 1-byte or 2-byte port stamp.
91 * http://www.vssmonitoring.com/portals/application_note/Port%20and%20Time%20Stamping.pdf
93 * (although that speaks of 2-byte port stamps as being for a "future
96 * This means a trailer length must not be more than 14 bytes,
99 * must not be 3 modulo 3 (as it can't have both a 1-byte
100 * and a 2-byte port stamp);
102 * if it's less than 8 bytes, must not be 0 modulo 3 (as
103 * it must have a 1-byte or 2-byte port stamp, given that
104 * it has no timestamp).
106 if ( trailer_len
> 14 )
109 /* ... and also a 1-byte port stamp can not co-exist with a 2-byte
112 if ( (trailer_len
& 3) == 3 )
115 /* ... and if you have neither a time stamp nor a port stamp,
116 * you don't have a trailer
118 if ( (trailer_len
& 3) == 0 && trailer_len
< 8 )
121 if ( trailer_len
>= 8 ) {
122 vssmonitoring_time
.secs
= tvb_get_ntohl(tvb
, offset
);
123 vssmonitoring_time
.nsecs
= tvb_get_ntohl(tvb
, offset
+ 4);
124 vssmonitoring_clksrc
= (guint8
)(((guint32
)vssmonitoring_time
.nsecs
) >> CLKSRC_SHIFT
);
125 vssmonitoring_time
.nsecs
&= VSS_NS_MASK
;
127 /* There are only heuristics for timestamps, the port stamp can be any value */
128 if ( vssmonitoring_use_heuristics
) {
130 /* The timestamp will be based on the uptime until the TAP is completely booted,
131 * this takes about 60s, but use 1 hour to be sure
134 /* Probably just null data to fill up a short frame.
135 * FIXME: Should be made even stricter.
137 if (vssmonitoring_time
.secs
== 0)
139 if (vssmonitoring_time
.secs
> 3600) {
141 /* Check whether the timestamp in the PCAP header and the VSS-Monitoring
142 * differ less than 30 days, otherwise, this might not be a VSS-Monitoring
145 if ( vssmonitoring_time
.secs
> pinfo
->fd
->abs_ts
.secs
) {
146 if ( vssmonitoring_time
.secs
- pinfo
->fd
->abs_ts
.secs
> 2592000 ) /* 30 days */
149 if ( pinfo
->fd
->abs_ts
.secs
- vssmonitoring_time
.secs
> 2592000 ) /* 30 days */
154 /* The nanoseconds field should be less than 1000000000
156 if ( vssmonitoring_time
.nsecs
>= 1000000000 )
161 /* All systems are go, lets dissect the VSS-Monitoring trailer */
163 ti
= proto_tree_add_item(tree
, proto_vssmonitoring
,
164 tvb
, 0, (trailer_len
& 0xb), ENC_NA
);
165 vssmonitoring_tree
= proto_item_add_subtree(ti
, ett_vssmonitoring
);
168 /* Do we have a timestamp? */
169 if ( trailer_len
>= 8 ) {
171 proto_tree_add_time(vssmonitoring_tree
, hf_vssmonitoring_time
, tvb
, offset
, 8, &vssmonitoring_time
);
172 proto_tree_add_uint(vssmonitoring_tree
, hf_vssmonitoring_clksrc
, tvb
, offset
+ 4, 1, vssmonitoring_clksrc
);
174 tmp
= localtime(&vssmonitoring_time
.secs
);
175 proto_item_append_text(ti
, ", Timestamp: %02d:%02d:%02d.%09ld",
176 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
,(long)vssmonitoring_time
.nsecs
);
181 /* Do we have a portstamp? */
182 if ( trailer_len
& 3) {
183 if ( trailer_len
& 1) {
184 vssmonitoring_srcport
= (guint16
)tvb_get_guint8(tvb
, offset
);
186 proto_tree_add_item(vssmonitoring_tree
, hf_vssmonitoring_srcport
, tvb
, offset
, 1, ENC_NA
);
188 } else if ( trailer_len
& 2) {
189 vssmonitoring_srcport
= tvb_get_ntohs(tvb
, offset
);
191 proto_tree_add_item(vssmonitoring_tree
, hf_vssmonitoring_srcport
, tvb
, offset
, 2, ENC_NA
);
195 proto_item_append_text(ti
, ", Source Port: %d", vssmonitoring_srcport
);
202 proto_register_vssmonitoring(void)
204 static hf_register_info hf
[] = {
205 { &hf_vssmonitoring_time
, {
206 "Time Stamp", "vssmonitoring.time",
207 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
208 "VSS-Monitoring Time Stamp", HFILL
}},
210 { &hf_vssmonitoring_clksrc
, {
211 "Clock Source", "vssmonitoring.clksrc",
212 FT_UINT8
, BASE_DEC
, VALS(clksrc_vals
), 0x0,
213 "VSS-Monitoring Clock Source", HFILL
}},
215 { &hf_vssmonitoring_srcport
, {
216 "Src Port", "vssmonitoring.srcport",
217 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
218 "VSS-Monitoring Source Port", HFILL
}}
221 static gint
*ett
[] = {
225 module_t
*vssmonitoring_module
;
227 proto_vssmonitoring
= proto_register_protocol("VSS-Monitoring ethernet trailer", "VSS-Monitoring", "vssmonitoring");
228 proto_register_field_array(proto_vssmonitoring
, hf
, array_length(hf
));
229 proto_register_subtree_array(ett
, array_length(ett
));
231 vssmonitoring_module
= prefs_register_protocol(proto_vssmonitoring
, NULL
);
233 prefs_register_bool_preference(vssmonitoring_module
, "use_heuristics",
234 "Use heuristics to verify if trailer contains VSS-Monitoring data",
235 "When enabled, Wireshark will do a check on the trailer data to verify"
236 "whether it contains VSS-Monitoring time- and port-stamps.",
237 &vssmonitoring_use_heuristics
);
241 proto_reg_handoff_vssmonitoring(void)
243 heur_dissector_add("eth.trailer", dissect_vssmonitoring
, proto_vssmonitoring
);