2 * Routines for NTP packet dissection
3 * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-tftp.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37 #include <epan/packet.h>
38 #include <epan/addr_resolv.h>
39 #include <epan/emem.h>
41 #include <epan/tvbparse.h>
43 #include "packet-ntp.h"
46 * Dissecting NTP packets version 3 and 4 (RFC2030, RFC1769, RFC1361,
49 * Those packets have simple structure:
51 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * |LI | VN |Mode | Stratum | Poll | Precision |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 * | Reference Identifier |
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 * | Reference Timestamp (64) |
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 * | Originate Timestamp (64) |
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 * | Receive Timestamp (64) |
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * | Transmit Timestamp (64) |
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 * | Key Identifier (optional) (32) |
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 * | Message Digest (optional) (128) |
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 * NTP timestamps are represented as a 64-bit unsigned fixed-point number,
81 * in seconds relative to 0h on 1 January 1900. The integer part is in the
82 * first 32 bits and the fraction part in the last 32 bits.
85 * NTP Control messages as defined in version 2, 3 and 4 (RFC1119, RFC1305) use
86 * the following structure:
88 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
89 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 * |00 | VN | 110 |R E M| OpCode | Sequence |
91 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92 * | Status | Association ID |
93 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
97 * | Data (468 octets max) |
99 * | | Padding (zeros) |
100 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
101 * | Authenticator (optional) (96) |
104 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106 * Not yet implemented: complete dissection of TPCTRL_OP_SETTRAP,
107 * NTPCTRL_OP_ASYNCMSG, NTPCTRL_OP_UNSETTRAPSETTRAP Control-Messages
111 #define UDP_PORT_NTP 123
112 #define TCP_PORT_NTP 123
114 /* Leap indicator, 2bit field is used to warn of a inserted/deleted
115 * second, or to alarm loosed synchronization.
117 #define NTP_LI_MASK 0xC0
119 #define NTP_LI_NONE 0
122 #define NTP_LI_ALARM 3
124 static const value_string li_types[] = {
125 { NTP_LI_NONE, "no warning" },
126 { NTP_LI_61, "last minute has 61 seconds" },
127 { NTP_LI_59, "last minute has 59 seconds" },
128 { NTP_LI_ALARM, "alarm condition (clock not synchronized)" },
132 /* Version info, 3bit field informs about NTP version used in particular
133 * packet. According to rfc2030, version info could be only 3 or 4, but I
134 * have noticed packets with 1 or even 6 as version numbers. They are
135 * produced as a result of ntptrace command. Are those packets mailformed
136 * on purpose? I don't know yet, probably some browsing through ntp sources
137 * would help. My solution is to put them as reserved for now.
139 #define NTP_VN_MASK 0x38
141 static const value_string ver_nums[] = {
143 { 1, "NTP Version 1" },
144 { 2, "NTP Version 2" },
145 { 3, "NTP Version 3" },
146 { 4, "NTP Version 4" },
153 /* Mode, 3bit field representing mode of comunication.
155 #define NTP_MODE_MASK 7
157 #define NTP_MODE_RSV 0
158 #define NTP_MODE_SYMACT 1
159 #define NTP_MODE_SYMPAS 2
160 #define NTP_MODE_CLIENT 3
161 #define NTP_MODE_SERVER 4
162 #define NTP_MODE_BCAST 5
163 #define NTP_MODE_CTRL 6
164 #define NTP_MODE_PRIV 7
166 static const value_string mode_types[] = {
167 { NTP_MODE_RSV, "reserved" },
168 { NTP_MODE_SYMACT, "symmetric active" },
169 { NTP_MODE_SYMPAS, "symmetric passive" },
170 { NTP_MODE_CLIENT, "client" },
171 { NTP_MODE_SERVER, "server" },
172 { NTP_MODE_BCAST, "broadcast" },
173 { NTP_MODE_CTRL, "reserved for NTP control message"},
174 { NTP_MODE_PRIV, "reserved for private use" },
178 static const value_string info_mode_types[] = {
179 { NTP_MODE_RSV, "NTP reserved" },
180 { NTP_MODE_SYMACT, "NTP symmetric active" },
181 { NTP_MODE_SYMPAS, "NTP symmetric passive" },
182 { NTP_MODE_CLIENT, "NTP client" },
183 { NTP_MODE_SERVER, "NTP server" },
184 { NTP_MODE_BCAST, "NTP broadcast" },
185 { NTP_MODE_CTRL, "NTP control"},
186 { NTP_MODE_PRIV, "NTP private" },
190 /* According to rfc, primary (stratum-0 and stratum-1) servers should set
191 * their Reference Clock ID (4bytes field) according to following table:
193 static const struct {
196 } primary_sources[] = {
197 { "LOCL", "uncalibrated local clock" },
198 { "CESM", "calibrated Cesium clock" },
199 { "RBDM", "calibrated Rubidium clock" },
200 { "PPS\0", "calibrated quartz clock or other pulse-per-second source" },
201 { "ACTS", "NIST dialup modem service" },
202 { "USNO", "USNO modem service" },
203 { "PTB\0", "PTB (Germany) modem service" },
204 { "TDF\0", "Allouis (France) Radio 164 kHz" },
205 { "DCF\0", "Mainflingen (Germany) Radio 77.5 kHz" },
206 { "MSF\0", "Anthorn (UK) Radio 60 kHz" },
207 { "WWV\0", "Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz" },
208 { "WWVB", "Boulder (US) Radio 60 kHz" },
209 { "WWVH", "Kauai Hawaii (US) Radio 2.5, 5, 10, 15 MHz" },
210 { "CHU\0", "Ottawa (Canada) Radio 3330, 7335, 14670 kHz" },
211 { "LORC", "LORAN-C radionavigation system" },
212 { "OMEG", "OMEGA radionavigation system" },
213 { "GPS\0", "Global Positioning Service" },
214 { "GOES", "Geostationary Orbit Environment Satellite" },
215 { "DCN\0", "DCN routing protocol" },
216 { "NIST", "NIST public modem" },
217 { "TSP\0", "TSP time protocol" },
218 { "DTS\0", "Digital Time Service" },
219 { "ATOM", "Atomic clock (calibrated)" },
220 { "VLF\0", "VLF radio (OMEGA,, etc.)" },
221 { "IRIG", "IRIG-B timecode" },
222 { "1PPS", "External 1 PPS input" },
223 { "FREE", "(Internal clock)" },
224 { "INIT", "(Initialization)" },
225 { "\0\0\0\0", "NULL" },
229 #define NTP_EXT_R_MASK 0x80
231 static const value_string ext_r_types[] = {
237 #define NTP_EXT_ERROR_MASK 0x40
238 #define NTP_EXT_VN_MASK 0x3f
240 static const value_string ext_op_types[] = {
254 #define NTPCTRL_R_MASK 0x80
256 #define ctrl_r_types ext_r_types
258 #define NTPCTRL_ERROR_MASK 0x40
259 #define NTPCTRL_MORE_MASK 0x20
260 #define NTPCTRL_OP_MASK 0x1f
262 #define NTPCTRL_OP_UNSPEC 0
263 #define NTPCTRL_OP_READSTAT 1
264 #define NTPCTRL_OP_READVAR 2
265 #define NTPCTRL_OP_WRITEVAR 3
266 #define NTPCTRL_OP_READCLOCK 4
267 #define NTPCTRL_OP_WRITECLOCK 5
268 #define NTPCTRL_OP_SETTRAP 6
269 #define NTPCTRL_OP_ASYNCMSG 7
270 #define NTPCTRL_OP_UNSETTRAP 31
272 static const value_string ctrl_op_types[] = {
273 { NTPCTRL_OP_UNSPEC, "UNSPEC" },
274 { NTPCTRL_OP_READSTAT, "READSTAT" },
275 { NTPCTRL_OP_READVAR, "READVAR" },
276 { NTPCTRL_OP_WRITEVAR, "WRITEVAR" },
277 { NTPCTRL_OP_READCLOCK, "READCLOCK" },
278 { NTPCTRL_OP_WRITECLOCK, "WRITECLOCK" },
279 { NTPCTRL_OP_SETTRAP, "SETTRAP" },
280 { NTPCTRL_OP_ASYNCMSG, "ASYNCMSG" },
281 { NTPCTRL_OP_UNSETTRAP, "UNSETTRAP" },
285 #define NTPCTRL_SYSSTATUS_LI_MASK 0xC000
286 #define NTPCTRL_SYSSTATUS_CLK_MASK 0x3F00
287 #define NTPCTRL_SYSSTATUS_COUNT_MASK 0x00F0
288 #define NTPCTRL_SYSSTATUS_CODE_MASK 0x000F
290 static const value_string ctrl_sys_status_clksource_types[] = {
291 { 0, "unspecified or unknown" },
292 { 1, "Calibrated atomic clock (e.g. HP 5061)" },
293 { 2, "VLF (band 4) or LF (band 5) radio (e.g. OMEGA, WWVB)" },
294 { 3, "HF (band 7) radio (e.g. CHU, MSF, WWV/H)" },
295 { 4, "UHF (band 9) satellite (e.g. GOES, GPS)" },
296 { 5, "local net (e.g. DCN, TSP, DTS)" },
299 { 8, "eyeball-and-wristwatch" },
300 { 9, "telephone modem (e.g. NIST)" },
304 static const value_string ctrl_sys_status_event_types[] = {
305 { 0, "unspecified" },
306 { 1, "system restart" },
307 { 2, "system or hardware fault" },
308 { 3, "system new status word (leap bits or synchronization change)" },
309 { 4, "system new synchronization source or stratum (sys.peer or sys.stratum change)" },
310 { 5, "system clock reset (offset correction exceeds CLOCK.MAX)" },
311 { 6, "system invalid time or date (see NTP spec.)" },
312 { 7, "system clock exception (see system clock status word)" },
316 #define NTPCTRL_PEERSTATUS_STATUS_MASK 0xF800
317 #define NTPCTRL_PEERSTATUS_CONFIG_MASK 0x8000
318 #define NTPCTRL_PEERSTATUS_AUTHENABLE_MASK 0x4000
319 #define NTPCTRL_PEERSTATUS_AUTHENTIC_MASK 0x2000
320 #define NTPCTRL_PEERSTATUS_REACH_MASK 0x1000
321 #define NTPCTRL_PEERSTATUS_RESERVED_MASK 0x0800
322 #define NTPCTRL_PEERSTATUS_SEL_MASK 0x0700
323 #define NTPCTRL_PEERSTATUS_COUNT_MASK 0x00F0
324 #define NTPCTRL_PEERSTATUS_CODE_MASK 0x000F
326 static const value_string ctrl_peer_status_config_types[] = {
327 { 0, "not configured (peer.config)" },
328 { 1, "configured (peer.config)" },
332 static const value_string ctrl_peer_status_authenable_types[] = {
333 { 0, "authentication disabled (peer.authenable" },
334 { 1, "authentication enabled (peer.authenable" },
338 static const value_string ctrl_peer_status_authentic_types[] = {
339 { 0, "authentication not okay (peer.authentic)" },
340 { 1, "authentication okay (peer.authentic)" },
344 static const value_string ctrl_peer_status_reach_types[] = {
345 { 0, "reachability not okay (peer.reach != 0)" },
346 { 1, "reachability okay (peer.reach != 0)" },
350 static const value_string ctrl_peer_status_selection_types[] = {
352 { 1, "passed sanity checks (tests 1 trough 8 in Section 3.4.3)" },
353 { 2, "passed correctness checks (intersection algorithm in Section 4.2.1)" },
354 { 3, "passed candidate checks (if limit check implemented)" },
355 { 4, "passed outlyer checks (clustering algorithm in Section 4.2.2)" },
356 { 5, "current synchronization source; max distance exceeded (if limit check implemented)" },
357 { 6, "current synchronization source; max distance okay" },
362 static const value_string ctrl_peer_status_event_types[] = {
363 { 0, "unspecified" },
364 { 1, "peer IP error" },
365 { 2, "peer authentication failure (peer.authentic bit was one now zero)" },
366 { 3, "peer unreachable (peer.reach was nonzero now zero)" },
367 { 4, "peer reachable (peer.reach was zero now nonzero)" },
368 { 5, "peer clock exception (see peer clock status word)" },
372 #define NTPCTRL_CLKSTATUS_STATUS_MASK 0xFF00
373 #define NTPCTRL_CLKSTATUS_CODE_MASK 0x00FF
375 static const value_string ctrl_clk_status_types[] = {
376 { 0, "clock operating within nominals" },
377 { 1, "reply timeout" },
378 { 2, "bad reply format" },
379 { 3, "hardware or software fault" },
380 { 4, "propagation failure" },
381 { 5, "bad date format or value" },
382 { 6, "bad time format or value" },
386 #define NTP_CTRL_ERRSTATUS_CODE_MASK 0xFF00
388 static const value_string ctrl_err_status_types[] = {
389 { 0, "unspecified" },
390 { 1, "authentication failure" },
391 { 2, "invalid message length or format" },
392 { 3, "invalid opcode" },
393 { 4, "unknown association identifier" },
394 { 5, "unknown variable name" },
395 { 6, "invalid variable value" },
396 { 7, "administratively prohibited" },
401 #define NTPPRIV_R_MASK 0x80
403 #define priv_r_types ext_r_types
405 #define NTPPRIV_MORE_MASK 0x40
407 #define NTPPRIV_AUTH_MASK 0x80
408 #define NTPPRIV_SEQ_MASK 0x7f
410 static const value_string priv_impl_types[] = {
412 { 2, "XNTPD_OLD (pre-IPv6)" },
417 static const value_string priv_rc_types[] = {
419 { 1, "PEER_LIST_SUM" },
427 { 9, "TIMER_STATS" },
430 { 12, "SET_SYS_FLAG" },
431 { 13, "CLR_SYS_FLAG" },
432 { 16, "GET_RESTRICT" },
433 { 17, "RESADDFLAGS" },
434 { 18, "RESSUBFLAGS" },
435 { 19, "UNRESTRICT" },
436 { 20, "MON_GETLIST" },
437 { 21, "RESET_STATS" },
438 { 22, "RESET_PEER" },
439 { 23, "REREAD_KEYS" },
441 { 27, "UNTRUSTKEY" },
446 { 32, "REQUEST_KEY" },
447 { 33, "CONTROL_KEY" },
448 { 34, "GET_CTLSTATS" },
449 { 36, "GET_CLOCKINFO" },
450 { 37, "SET_CLKFUDGE" },
451 { 38, "GET_KERNEL" },
452 { 39, "GET_CLKBUGINFO" },
453 { 42, "MON_GETLIST_1" },
454 { 43, "HOSTNAME_ASSOCID" },
459 * Maximum MAC length.
461 #define MAX_MAC_LEN (5 * sizeof (guint32))
463 static int proto_ntp = -1;
465 static int hf_ntp_flags = -1;
466 static int hf_ntp_flags_li = -1;
467 static int hf_ntp_flags_vn = -1;
468 static int hf_ntp_flags_mode = -1;
469 static int hf_ntp_stratum = -1;
470 static int hf_ntp_ppoll = -1;
471 static int hf_ntp_precision = -1;
472 static int hf_ntp_rootdelay = -1;
473 static int hf_ntp_rootdispersion = -1;
474 static int hf_ntp_refid = -1;
475 static int hf_ntp_reftime = -1;
476 static int hf_ntp_org = -1;
477 static int hf_ntp_rec = -1;
478 static int hf_ntp_xmt = -1;
479 static int hf_ntp_keyid = -1;
480 static int hf_ntp_mac = -1;
482 static int hf_ntp_ext = -1;
483 static int hf_ntp_ext_flags = -1;
484 static int hf_ntp_ext_flags_r = -1;
485 static int hf_ntp_ext_flags_error = -1;
486 static int hf_ntp_ext_flags_vn = -1;
487 static int hf_ntp_ext_op = -1;
488 static int hf_ntp_ext_len = -1;
489 static int hf_ntp_ext_associd = -1;
490 static int hf_ntp_ext_tstamp = -1;
491 static int hf_ntp_ext_fstamp = -1;
492 static int hf_ntp_ext_vallen = -1;
493 static int hf_ntp_ext_val = -1;
494 static int hf_ntp_ext_siglen = -1;
495 static int hf_ntp_ext_sig = -1;
497 static int hf_ntpctrl_flags2 = -1;
498 static int hf_ntpctrl_flags2_r = -1;
499 static int hf_ntpctrl_flags2_error = -1;
500 static int hf_ntpctrl_flags2_more = -1;
501 static int hf_ntpctrl_flags2_opcode = -1;
502 static int hf_ntpctrl_sequence = -1;
503 static int hf_ntpctrl_status = -1;
504 static int hf_ntpctrl_error_status_word = -1;
505 static int hf_ntpctrl_sys_status_li = -1;
506 static int hf_ntpctrl_sys_status_clksrc = -1;
507 static int hf_ntpctrl_sys_status_count = -1;
508 static int hf_ntpctrl_sys_status_code = -1;
509 static int hf_ntpctrl_peer_status_b0 = -1;
510 static int hf_ntpctrl_peer_status_b1 = -1;
511 static int hf_ntpctrl_peer_status_b2 = -1;
512 static int hf_ntpctrl_peer_status_b3 = -1;
513 static int hf_ntpctrl_peer_status_b4 = -1;
514 static int hf_ntpctrl_peer_status_selection = -1;
515 static int hf_ntpctrl_peer_status_count = -1;
516 static int hf_ntpctrl_peer_status_code = -1;
517 static int hf_ntpctrl_clk_status = -1;
518 static int hf_ntpctrl_clk_status_code = -1;
519 static int hf_ntpctrl_associd = -1;
520 static int hf_ntpctrl_offset = -1;
521 static int hf_ntpctrl_count = -1;
522 static int hf_ntpctrl_data = -1;
523 static int hf_ntpctrl_item = -1;
524 static int hf_ntpctrl_trapmsg = -1;
526 static int hf_ntppriv_flags_r = -1;
527 static int hf_ntppriv_flags_more = -1;
528 static int hf_ntppriv_auth_seq = -1;
529 static int hf_ntppriv_auth = -1;
530 static int hf_ntppriv_seq = -1;
531 static int hf_ntppriv_impl = -1;
532 static int hf_ntppriv_reqcode = -1;
534 static gint ett_ntp = -1;
535 static gint ett_ntp_flags = -1;
536 static gint ett_ntp_ext = -1;
537 static gint ett_ntp_ext_flags = -1;
538 static gint ett_ntpctrl_flags2 = -1;
539 static gint ett_ntpctrl_status = -1;
540 static gint ett_ntpctrl_data = -1;
541 static gint ett_ntpctrl_item = -1;
542 static gint ett_ntppriv_auth_seq = -1;
544 static void dissect_ntp_std(tvbuff_t *, proto_tree *, guint8);
545 static void dissect_ntp_ctrl(tvbuff_t *, proto_tree *, guint8);
546 static void dissect_ntp_priv(tvbuff_t *, proto_tree *, guint8);
547 static int dissect_ntp_ext(tvbuff_t *, proto_tree *, int);
549 static const char *mon_names[12] = {
565 /* parser definitions */
566 static tvbparse_wanted_t* want;
567 static tvbparse_wanted_t* want_ignore;
570 /* ntp_fmt_ts - converts NTP timestamp to human readable string.
571 * reftime - 64bit timestamp (IN)
572 * returns pointer to filled buffer. This buffer will be freed automatically once
573 * dissection of the next packet occurs.
576 ntp_fmt_ts(const guint8 *reftime)
578 guint32 tempstmp, tempfrac;
584 tempstmp = pntohl(&reftime[0]);
585 tempfrac = pntohl(&reftime[4]);
586 if ((tempstmp == 0) && (tempfrac == 0)) {
590 temptime = tempstmp - (guint32) NTP_BASETIME;
591 bd = gmtime(&temptime);
593 return "Not representable";
596 fractime = bd->tm_sec + tempfrac / 4294967296.0;
597 buff=ep_alloc(NTP_TS_SIZE);
598 g_snprintf(buff, NTP_TS_SIZE,
599 "%s %2d, %d %02d:%02d:%09.6f UTC",
600 mon_names[bd->tm_mon],
609 /* dissect_ntp - dissects NTP packet data
610 * tvb - tvbuff for packet data (IN)
611 * pinfo - packet info
612 * proto_tree - resolved protocol tree
615 dissect_ntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
617 proto_tree *ntp_tree;
620 void (*dissector)(tvbuff_t *, proto_item *, guint8);
622 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NTP");
624 col_clear(pinfo->cinfo, COL_INFO);
626 flags = tvb_get_guint8(tvb, 0);
627 switch (flags & NTP_MODE_MASK) {
629 dissector = dissect_ntp_std;
632 dissector = dissect_ntp_ctrl;
635 dissector = dissect_ntp_priv;
639 col_add_str(pinfo->cinfo, COL_INFO,
640 val_to_str(flags & NTP_MODE_MASK, info_mode_types, "Unknown"));
643 /* Adding NTP item and subtree */
644 ti = proto_tree_add_item(tree, proto_ntp, tvb, 0, -1, FALSE);
645 ntp_tree = proto_item_add_subtree(ti, ett_ntp);
647 (*dissector)(tvb, ntp_tree, flags);
652 dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
654 proto_tree *flags_tree;
660 double rootdispersion;
663 const guint8 *reftime;
673 tf = proto_tree_add_uint(ntp_tree, hf_ntp_flags, tvb, 0, 1, flags);
675 /* Adding flag subtree and items */
676 flags_tree = proto_item_add_subtree(tf, ett_ntp_flags);
677 proto_tree_add_uint(flags_tree, hf_ntp_flags_li, tvb, 0, 1, flags);
678 proto_tree_add_uint(flags_tree, hf_ntp_flags_vn, tvb, 0, 1, flags);
679 proto_tree_add_uint(flags_tree, hf_ntp_flags_mode, tvb, 0, 1, flags);
681 /* Stratum, 1byte field represents distance from primary source
683 stratum = tvb_get_guint8(tvb, 1);
685 buffc="Peer Clock Stratum: unspecified or unavailable (%u)";
686 } else if (stratum == 1) {
687 buffc="Peer Clock Stratum: primary reference (%u)";
688 } else if ((stratum >= 2) && (stratum <= 15)) {
689 buffc="Peer Clock Stratum: secondary reference (%u)";
691 buffc="Peer Clock Stratum: reserved: %u";
693 proto_tree_add_uint_format(ntp_tree, hf_ntp_stratum, tvb, 1, 1,
694 stratum, buffc, stratum);
695 /* Poll interval, 1byte field indicating the maximum interval
696 * between successive messages, in seconds to the nearest
699 ppoll = tvb_get_guint8(tvb, 2);
700 if ((ppoll >= 4) && (ppoll <= 17)) {
701 proto_tree_add_uint_format(ntp_tree, hf_ntp_ppoll, tvb, 2, 1,
703 "Peer Polling Interval: %u (%u sec)",
707 proto_tree_add_uint_format(ntp_tree, hf_ntp_ppoll, tvb, 2, 1,
709 "Peer Polling Interval: invalid (%u)",
713 /* Precision, 1byte field indicating the precision of the
714 * local clock, in seconds to the nearest power of two.
716 precision = tvb_get_guint8(tvb, 3);
717 proto_tree_add_int_format(ntp_tree, hf_ntp_precision, tvb, 3, 1,
719 "Peer Clock Precision: %8.6f sec",
722 /* Root Delay is a 32-bit signed fixed-point number indicating
723 * the total roundtrip delay to the primary reference source,
724 * in seconds with fraction point between bits 15 and 16.
726 rootdelay = ((gint16)tvb_get_ntohs(tvb, 4)) +
727 (tvb_get_ntohs(tvb, 6) / 65536.0);
728 proto_tree_add_double_format(ntp_tree, hf_ntp_rootdelay, tvb, 4, 4,
730 "Root Delay: %9.4f sec",
733 /* Root Dispersion, 32-bit unsigned fixed-point number indicating
734 * the nominal error relative to the primary reference source, in
735 * seconds with fraction point between bits 15 and 16.
737 rootdispersion = ((gint16)tvb_get_ntohs(tvb, 8)) +
738 (tvb_get_ntohs(tvb, 10) / 65536.0);
739 proto_tree_add_double_format(ntp_tree, hf_ntp_rootdispersion, tvb, 8, 4,
741 "Root Dispersion: %9.4f sec",
744 /* Now, there is a problem with secondary servers. Standards
745 * asks from stratum-2 - stratum-15 servers to set this to the
746 * low order 32 bits of the latest transmit timestamp of the
748 * But, all V3 and V4 servers set this to IP adress of their
749 * higher level server. My decision was to resolve this address.
751 refid = tvb_get_ptr(tvb, 12, 4);
752 buff = ep_alloc(NTP_TS_SIZE);
754 g_snprintf (buff, NTP_TS_SIZE, "Unidentified reference source '%.4s'",
756 for (i = 0; primary_sources[i].id; i++) {
757 if (memcmp (refid, primary_sources[i].id, 4) == 0) {
758 g_snprintf(buff, NTP_TS_SIZE, "%s",
759 primary_sources[i].data);
765 refid_addr = tvb_get_ipv4(tvb, 12);
766 buffpos = g_snprintf(buff, NTP_TS_SIZE, "%s", get_hostname (refid_addr));
767 if (buffpos >= NTP_TS_SIZE) {
768 buff[NTP_TS_SIZE-4]='.';
769 buff[NTP_TS_SIZE-3]='.';
770 buff[NTP_TS_SIZE-2]='.';
771 buff[NTP_TS_SIZE-1]=0;
774 proto_tree_add_bytes_format(ntp_tree, hf_ntp_refid, tvb, 12, 4,
776 "Reference Clock ID: %s", buff);
778 /* Reference Timestamp: This is the time at which the local clock was
779 * last set or corrected.
781 reftime = tvb_get_ptr(tvb, 16, 8);
782 proto_tree_add_bytes_format(ntp_tree, hf_ntp_reftime, tvb, 16, 8,
784 "Reference Clock Update Time: %s",
785 ntp_fmt_ts(reftime));
787 /* Originate Timestamp: This is the time at which the request departed
788 * the client for the server.
790 org = tvb_get_ptr(tvb, 24, 8);
791 proto_tree_add_bytes_format(ntp_tree, hf_ntp_org, tvb, 24, 8,
793 "Originate Time Stamp: %s",
796 /* Receive Timestamp: This is the time at which the request arrived at
799 rec = tvb_get_ptr(tvb, 32, 8);
800 proto_tree_add_bytes_format(ntp_tree, hf_ntp_rec, tvb, 32, 8,
802 "Receive Time Stamp: %s",
805 /* Transmit Timestamp: This is the time at which the reply departed the
806 * server for the client.
808 xmt = tvb_get_ptr(tvb, 40, 8);
809 proto_tree_add_bytes_format(ntp_tree, hf_ntp_xmt, tvb, 40, 8,
811 "Transmit Time Stamp: %s",
814 /* MAX_MAC_LEN is the largest message authentication code
815 * (MAC) length. If we have more data left in the packet
816 * after the header than that, the extra data is NTP4
817 * extensions; parse them as such.
820 while (tvb_reported_length_remaining(tvb, macofs) > (gint)MAX_MAC_LEN)
821 macofs = dissect_ntp_ext(tvb, ntp_tree, macofs);
823 /* When the NTP authentication scheme is implemented, the
824 * Key Identifier and Message Digest fields contain the
825 * message authentication code (MAC) information defined in
826 * Appendix C of RFC-1305. Will print this as hex code for now.
828 if (tvb_reported_length_remaining(tvb, macofs) >= 4)
829 proto_tree_add_item(ntp_tree, hf_ntp_keyid, tvb, macofs, 4,
832 maclen = tvb_reported_length_remaining(tvb, macofs);
834 proto_tree_add_item(ntp_tree, hf_ntp_mac, tvb, macofs,
839 dissect_ntp_ext(tvbuff_t *tvb, proto_tree *ntp_tree, int offset)
841 proto_tree *ext_tree, *flags_tree;
846 guint32 vallen, vallen_round, siglen;
848 extlen = tvb_get_ntohs(tvb, offset+2);
850 /* Extension length isn't enough for the extension header.
851 * Report the error, and return an offset that goes to
852 * the end of the tvbuff, so we stop dissecting.
854 proto_tree_add_text(ntp_tree, tvb, offset+2, 2,
855 "Extension length %u < 8", extlen);
856 offset += tvb_length_remaining(tvb, offset);
860 /* Extension length isn't a multiple of 4.
861 * Report the error, and return an offset that goes
862 * to the end of the tvbuff, so we stop dissecting.
864 proto_tree_add_text(ntp_tree, tvb, offset+2, 2,
865 "Extension length %u isn't a multiple of 4",
867 offset += tvb_length_remaining(tvb, offset);
870 endoffset = offset + extlen;
872 tf = proto_tree_add_item(ntp_tree, hf_ntp_ext, tvb, offset, extlen,
874 ext_tree = proto_item_add_subtree(tf, ett_ntp_ext);
876 flags = tvb_get_guint8(tvb, offset);
877 tf = proto_tree_add_uint(ext_tree, hf_ntp_ext_flags, tvb, offset, 1,
879 flags_tree = proto_item_add_subtree(tf, ett_ntp_ext_flags);
880 proto_tree_add_uint(flags_tree, hf_ntp_ext_flags_r, tvb, offset, 1,
882 proto_tree_add_uint(flags_tree, hf_ntp_ext_flags_error, tvb, offset, 1,
884 proto_tree_add_uint(flags_tree, hf_ntp_ext_flags_vn, tvb, offset, 1,
888 proto_tree_add_item(ext_tree, hf_ntp_ext_op, tvb, offset, 1, FALSE);
891 proto_tree_add_uint(ext_tree, hf_ntp_ext_len, tvb, offset, 2, extlen);
894 if ((flags & NTP_EXT_VN_MASK) != 2) {
895 /* don't care about autokey v1 */
899 proto_tree_add_item(ext_tree, hf_ntp_ext_associd, tvb, offset, 4,
903 /* check whether everything up to "vallen" is present */
904 if (extlen < MAX_MAC_LEN) {
905 /* XXX - report as error? */
909 proto_tree_add_item(ext_tree, hf_ntp_ext_tstamp, tvb, offset, 4,
912 proto_tree_add_item(ext_tree, hf_ntp_ext_fstamp, tvb, offset, 4,
915 /* XXX fstamp can be server flags */
917 vallen = tvb_get_ntohl(tvb, offset);
918 proto_tree_add_uint(ext_tree, hf_ntp_ext_vallen, tvb, offset, 4,
921 vallen_round = (vallen + 3) & (-4);
923 if ((guint32)(endoffset - offset) < vallen_round) {
925 * Value goes past the length of the extension
928 proto_tree_add_text(ext_tree, tvb, offset,
930 "Value length makes value go past the end of the extension field");
933 proto_tree_add_item(ext_tree, hf_ntp_ext_val, tvb, offset,
936 offset += vallen_round;
938 siglen = tvb_get_ntohl(tvb, offset);
939 proto_tree_add_uint(ext_tree, hf_ntp_ext_siglen, tvb, offset, 4,
943 if (offset + (int)siglen > endoffset) {
945 * Value goes past the length of the extension
948 proto_tree_add_text(ext_tree, tvb, offset,
950 "Signature length makes value go past the end of the extension field");
953 proto_tree_add_item(ext_tree, hf_ntp_ext_sig, tvb,
954 offset, siglen, FALSE);
960 dissect_ntp_ctrl_peerstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
963 * dissect peer status word:
965 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
966 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
967 * | Status | Sel | Count | Code |
968 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
970 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_b0, tvb, offset, 2, status);
971 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_b1, tvb, offset, 2, status);
972 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_b2, tvb, offset, 2, status);
973 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_b3, tvb, offset, 2, status);
974 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_b4, tvb, offset, 2, status);
975 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_selection, tvb, offset, 2, status);
976 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_count, tvb, offset, 2, status);
977 proto_tree_add_uint(status_tree, hf_ntpctrl_peer_status_code, tvb, offset, 2, status);
981 dissect_ntp_ctrl_systemstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
984 * dissect system status word:
986 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
987 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
988 * |LI | ClkSource | Count | Code |
989 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
991 proto_tree_add_uint(status_tree, hf_ntpctrl_sys_status_li, tvb, offset, 2, status);
992 proto_tree_add_uint(status_tree, hf_ntpctrl_sys_status_clksrc, tvb, offset, 2, status);
993 proto_tree_add_uint(status_tree, hf_ntpctrl_sys_status_count, tvb, offset, 2, status);
994 proto_tree_add_uint(status_tree, hf_ntpctrl_sys_status_code, tvb, offset, 2, status);
998 dissect_ntp_ctrl_errorstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
1001 * if error bit is set: dissect error status word
1003 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
1004 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1005 * | Error Code | reserved |
1006 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1008 proto_tree_add_uint(status_tree, hf_ntpctrl_error_status_word, tvb, offset, 2, status);
1012 dissect_ntp_ctrl_clockstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
1015 * dissect clock status word:
1017 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
1018 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1019 * | Clock Status | Event Code |
1020 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1022 proto_tree_add_uint(status_tree, hf_ntpctrl_clk_status, tvb, offset, 2, status);
1023 proto_tree_add_uint(status_tree, hf_ntpctrl_clk_status_code, tvb, offset, 2, status);
1027 dissect_ntp_ctrl(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
1029 proto_tree *flags_tree;
1033 proto_tree *status_tree, *data_tree, *item_tree;
1034 proto_item *ts, *td, *ti;
1038 guint16 data_offset;
1041 tvbparse_elem_t *element;
1043 tf = proto_tree_add_uint(ntp_tree, hf_ntp_flags, tvb, 0, 1, flags);
1045 /* Adding flag subtree and items */
1046 flags_tree = proto_item_add_subtree(tf, ett_ntp_flags);
1047 proto_tree_add_uint(flags_tree, hf_ntp_flags_li, tvb, 0, 1, flags);
1048 proto_tree_add_uint(flags_tree, hf_ntp_flags_vn, tvb, 0, 1, flags);
1049 proto_tree_add_uint(flags_tree, hf_ntp_flags_mode, tvb, 0, 1, flags);
1051 flags2 = tvb_get_guint8(tvb, 1);
1052 tf = proto_tree_add_uint(ntp_tree, hf_ntpctrl_flags2, tvb, 1, 1, flags2);
1053 flags_tree = proto_item_add_subtree(tf, ett_ntpctrl_flags2);
1054 proto_tree_add_uint(flags_tree, hf_ntpctrl_flags2_r, tvb, 1, 1, flags2);
1055 proto_tree_add_uint(flags_tree, hf_ntpctrl_flags2_error, tvb, 1, 1, flags2);
1056 proto_tree_add_uint(flags_tree, hf_ntpctrl_flags2_more, tvb, 1, 1, flags2);
1057 proto_tree_add_uint(flags_tree, hf_ntpctrl_flags2_opcode, tvb, 1, 1, flags2);
1059 proto_tree_add_uint(ntp_tree, hf_ntpctrl_sequence, tvb, 2, 2, tvb_get_ntohs(tvb, 2));
1061 status = tvb_get_ntohs(tvb, 4);
1062 associd = tvb_get_ntohs(tvb, 6);
1063 ts = proto_tree_add_uint(ntp_tree, hf_ntpctrl_status, tvb, 4, 2, status);
1064 status_tree = proto_item_add_subtree(ts, ett_ntpctrl_status);
1066 * further processing of status is only necessary in server responses
1068 if (flags2 & NTPCTRL_R_MASK) {
1069 if (flags2 & NTPCTRL_ERROR_MASK) {
1070 /* Check if this is an error response... */
1071 dissect_ntp_ctrl_errorstatus(tvb, status_tree, 4, status);
1073 /* ...otherwise status word depends on OpCode */
1074 switch (flags2 & NTPCTRL_OP_MASK) {
1075 case NTPCTRL_OP_READSTAT:
1076 case NTPCTRL_OP_READVAR:
1077 case NTPCTRL_OP_WRITEVAR:
1078 case NTPCTRL_OP_ASYNCMSG:
1080 dissect_ntp_ctrl_peerstatus(tvb, status_tree, 4, status);
1082 dissect_ntp_ctrl_systemstatus(tvb, status_tree, 4, status);
1084 case NTPCTRL_OP_READCLOCK:
1085 case NTPCTRL_OP_WRITECLOCK:
1086 dissect_ntp_ctrl_clockstatus(tvb, status_tree, 4, status);
1088 case NTPCTRL_OP_SETTRAP:
1089 case NTPCTRL_OP_UNSETTRAP:
1094 proto_tree_add_uint(ntp_tree, hf_ntpctrl_associd, tvb, 6, 2, associd);
1095 proto_tree_add_uint(ntp_tree, hf_ntpctrl_offset, tvb, 8, 2, tvb_get_ntohs(tvb, 8));
1096 datalen = tvb_get_ntohs(tvb, 10);
1097 proto_tree_add_uint(ntp_tree, hf_ntpctrl_count, tvb, 10, 2, datalen);
1100 * dissect Data part of the NTP control message
1104 td = proto_tree_add_item(ntp_tree, hf_ntpctrl_data, tvb, data_offset, datalen, TRUE);
1105 data_tree = proto_item_add_subtree(td, ett_ntpctrl_data);
1106 switch(flags2 & NTPCTRL_OP_MASK) {
1107 case NTPCTRL_OP_READSTAT:
1110 * if associd == 0 then data part contains a list of the form
1111 * <association identifier><status word>,
1114 ti = proto_tree_add_item(data_tree, hf_ntpctrl_item, tvb, data_offset, 4, TRUE);
1115 item_tree = proto_item_add_subtree(ti, ett_ntpctrl_item);
1116 proto_tree_add_uint(item_tree, hf_ntpctrl_associd, tvb, data_offset, 2, tvb_get_ntohs(tvb, data_offset));
1118 status = tvb_get_ntohs(tvb, data_offset);
1119 ts = proto_tree_add_uint(item_tree, hf_ntpctrl_status, tvb, data_offset, 2, status);
1120 status_tree = proto_item_add_subtree(ts, ett_ntpctrl_status);
1121 dissect_ntp_ctrl_peerstatus( tvb, status_tree, 4, status );
1128 * but if associd != 0,
1129 * then data part could be the same as if opcode is NTPCTRL_OP_READVAR
1130 * --> so, no "break" here!
1132 case NTPCTRL_OP_READVAR:
1133 case NTPCTRL_OP_WRITEVAR:
1134 case NTPCTRL_OP_READCLOCK:
1135 case NTPCTRL_OP_WRITECLOCK:
1136 tt = tvbparse_init(tvb, data_offset, datalen, NULL, want_ignore);
1137 while( (element = tvbparse_get(tt, want)) != NULL ) {
1138 tvbparse_tree_add_elem(data_tree, element);
1141 case NTPCTRL_OP_ASYNCMSG:
1142 proto_tree_add_item(data_tree, hf_ntpctrl_trapmsg, tvb, data_offset, datalen, TRUE);
1144 /* these opcodes doesn't carry any data: NTPCTRL_OP_SETTRAP, NTPCTRL_OP_UNSETTRAP, NTPCTRL_OP_UNSPEC */
1150 * Initialize tvb-parser, which is used to dissect data part of NTP control
1153 * Here some constants are defined, which describes character groups used for
1154 * various purposes. These groups are then used to configure the two global
1155 * variables "want_ignore" and "want" that we use for dissection
1160 /* specify what counts as character */
1161 tvbparse_wanted_t* want_identifier = tvbparse_chars(-1, 1, 0,
1162 "abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789", NULL, NULL, NULL);
1163 /* this is the equal sign used in assignments */
1164 tvbparse_wanted_t* want_equalsign = tvbparse_chars(-1, 1, 0, "=", NULL, NULL, NULL);
1165 /* possible characters allowed for values */
1166 tvbparse_wanted_t* want_value = tvbparse_set_oneof(0, NULL, NULL, NULL,
1167 tvbparse_quoted(-1, NULL, NULL, tvbparse_shrink_token_cb, '\"', '\\'),
1168 tvbparse_quoted(-1, NULL, NULL, tvbparse_shrink_token_cb, '\'', '\\'),
1169 tvbparse_chars(-1, 1, 0, "abcdefghijklmnopqrstuvwxyz-_ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789 ", NULL, NULL, NULL),
1171 /* the following specifies an assignment of the form identifier=value */
1172 tvbparse_wanted_t* want_assignment = tvbparse_set_seq(-1, NULL, NULL, NULL,
1178 /* we ignore white space characters */
1179 want_ignore = tvbparse_chars(-1, 1, 0, ", \t\r\n", NULL, NULL, NULL);
1180 /* data part of control messages consists of either identifiers or assignments */
1181 want = tvbparse_set_oneof(-1, NULL, NULL, NULL,
1188 dissect_ntp_priv(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
1190 proto_tree *flags_tree;
1192 guint8 auth_seq, impl, reqcode;
1194 tf = proto_tree_add_uint(ntp_tree, hf_ntp_flags, tvb, 0, 1, flags);
1196 /* Adding flag subtree and items */
1197 flags_tree = proto_item_add_subtree(tf, ett_ntp_flags);
1198 proto_tree_add_uint(flags_tree, hf_ntppriv_flags_r, tvb, 0, 1, flags);
1199 proto_tree_add_uint(flags_tree, hf_ntppriv_flags_more, tvb, 0, 1,
1201 proto_tree_add_uint(flags_tree, hf_ntp_flags_vn, tvb, 0, 1, flags);
1202 proto_tree_add_uint(flags_tree, hf_ntp_flags_mode, tvb, 0, 1, flags);
1204 auth_seq = tvb_get_guint8(tvb, 1);
1205 tf = proto_tree_add_uint(ntp_tree, hf_ntppriv_auth_seq, tvb, 1, 1,
1207 flags_tree = proto_item_add_subtree(tf, ett_ntppriv_auth_seq);
1208 proto_tree_add_uint(flags_tree, hf_ntppriv_auth, tvb, 1, 1, auth_seq);
1209 proto_tree_add_uint(flags_tree, hf_ntppriv_seq, tvb, 1, 1, auth_seq);
1211 impl = tvb_get_guint8(tvb, 2);
1212 proto_tree_add_uint(ntp_tree, hf_ntppriv_impl, tvb, 2, 1, impl);
1214 reqcode = tvb_get_guint8(tvb, 3);
1215 proto_tree_add_uint(ntp_tree, hf_ntppriv_reqcode, tvb, 3, 1, reqcode);
1219 proto_register_ntp(void)
1221 static hf_register_info hf[] = {
1223 "Flags", "ntp.flags", FT_UINT8, BASE_HEX,
1224 NULL, 0, "Flags (Leap/Version/Mode)", HFILL }},
1225 { &hf_ntp_flags_li, {
1226 "Leap Indicator", "ntp.flags.li", FT_UINT8, BASE_DEC,
1227 VALS(li_types), NTP_LI_MASK, NULL, HFILL }},
1228 { &hf_ntp_flags_vn, {
1229 "Version number", "ntp.flags.vn", FT_UINT8, BASE_DEC,
1230 VALS(ver_nums), NTP_VN_MASK, NULL, HFILL }},
1231 { &hf_ntp_flags_mode, {
1232 "Mode", "ntp.flags.mode", FT_UINT8, BASE_DEC,
1233 VALS(mode_types), NTP_MODE_MASK, NULL, HFILL }},
1234 { &hf_ntp_stratum, {
1235 "Peer Clock Stratum", "ntp.stratum", FT_UINT8, BASE_DEC,
1236 NULL, 0, NULL, HFILL }},
1238 "Peer Polling Interval", "ntp.ppoll", FT_UINT8, BASE_DEC,
1239 NULL, 0, NULL, HFILL }},
1240 { &hf_ntp_precision, {
1241 "Peer Clock Precision", "ntp.precision", FT_INT8, BASE_DEC,
1242 NULL, 0, NULL, HFILL }},
1243 { &hf_ntp_rootdelay, {
1244 "Root Delay", "ntp.rootdelay", FT_DOUBLE, BASE_NONE,
1245 NULL, 0, NULL, HFILL }},
1246 { &hf_ntp_rootdispersion, {
1247 "Root Dispersion", "ntp.rootdispersion", FT_DOUBLE, BASE_NONE,
1248 NULL, 0, NULL, HFILL }},
1250 "Reference Clock ID", "ntp.refid", FT_BYTES, BASE_NONE,
1251 NULL, 0, NULL, HFILL }},
1252 { &hf_ntp_reftime, {
1253 "Reference Clock Update Time", "ntp.reftime", FT_BYTES, BASE_NONE,
1254 NULL, 0, NULL, HFILL }},
1256 "Originate Time Stamp", "ntp.org", FT_BYTES, BASE_NONE,
1257 NULL, 0, NULL, HFILL }},
1259 "Receive Time Stamp", "ntp.rec", FT_BYTES, BASE_NONE,
1260 NULL, 0, NULL, HFILL }},
1262 "Transmit Time Stamp", "ntp.xmt", FT_BYTES, BASE_NONE,
1263 NULL, 0, NULL, HFILL }},
1265 "Key ID", "ntp.keyid", FT_BYTES, BASE_NONE,
1266 NULL, 0, NULL, HFILL }},
1268 "Message Authentication Code", "ntp.mac", FT_BYTES, BASE_NONE,
1269 NULL, 0, NULL, HFILL }},
1272 "Extension", "ntp.ext", FT_NONE, BASE_NONE,
1273 NULL, 0, NULL, HFILL }},
1274 { &hf_ntp_ext_flags, {
1275 "Flags", "ntp.ext.flags", FT_UINT8, BASE_HEX,
1276 NULL, 0, "Flags (Response/Error/Version)", HFILL }},
1277 { &hf_ntp_ext_flags_r, {
1278 "Response bit", "ntp.ext.flags.r", FT_UINT8, BASE_DEC,
1279 VALS(ext_r_types), NTP_EXT_R_MASK, NULL, HFILL }},
1280 { &hf_ntp_ext_flags_error, {
1281 "Error bit", "ntp.ext.flags.error", FT_UINT8, BASE_DEC,
1282 NULL, NTP_EXT_ERROR_MASK, NULL, HFILL }},
1283 { &hf_ntp_ext_flags_vn, {
1284 "Version", "ntp.ext.flags.vn", FT_UINT8, BASE_DEC,
1285 NULL, NTP_EXT_VN_MASK, NULL, HFILL }},
1287 "Opcode", "ntp.ext.op", FT_UINT8, BASE_DEC,
1288 VALS(ext_op_types), 0, NULL, HFILL }},
1289 { &hf_ntp_ext_len, {
1290 "Extension length", "ntp.ext.len", FT_UINT16, BASE_DEC,
1291 NULL, 0, NULL, HFILL }},
1292 { &hf_ntp_ext_associd, {
1293 "Association ID", "ntp.ext.associd", FT_UINT32, BASE_DEC,
1294 NULL, 0, NULL, HFILL }},
1295 { &hf_ntp_ext_tstamp, {
1296 "Timestamp", "ntp.ext.tstamp", FT_UINT32, BASE_HEX,
1297 NULL, 0, NULL, HFILL }},
1298 { &hf_ntp_ext_fstamp, {
1299 "File Timestamp", "ntp.ext.fstamp", FT_UINT32, BASE_HEX,
1300 NULL, 0, NULL, HFILL }},
1301 { &hf_ntp_ext_vallen, {
1302 "Value length", "ntp.ext.vallen", FT_UINT32, BASE_DEC,
1303 NULL, 0, NULL, HFILL }},
1304 { &hf_ntp_ext_val, {
1305 "Value", "ntp.ext.val", FT_BYTES, BASE_NONE,
1306 NULL, 0, NULL, HFILL }},
1307 { &hf_ntp_ext_siglen, {
1308 "Signature length", "ntp.ext.siglen", FT_UINT32, BASE_DEC,
1309 NULL, 0, NULL, HFILL }},
1310 { &hf_ntp_ext_sig, {
1311 "Signature", "ntp.ext.sig", FT_BYTES, BASE_NONE,
1312 NULL, 0, NULL, HFILL }},
1314 { &hf_ntpctrl_flags2, {
1315 "Flags 2", "ntpctrl.flags2", FT_UINT8, BASE_HEX,
1316 NULL, 0, "Flags (Response/Error/More/Opcode)", HFILL }},
1317 { &hf_ntpctrl_flags2_r, {
1318 "Response bit", "ntpctrl.flags2.r", FT_UINT8, BASE_DEC,
1319 VALS(ctrl_r_types), NTPCTRL_R_MASK, NULL, HFILL }},
1320 { &hf_ntpctrl_flags2_error, {
1321 "Error bit", "ntpctrl.flags2.error", FT_UINT8, BASE_DEC,
1322 NULL, NTPCTRL_ERROR_MASK, NULL, HFILL }},
1323 { &hf_ntpctrl_flags2_more, {
1324 "More bit", "ntpctrl.flags2.more", FT_UINT8, BASE_DEC,
1325 NULL, NTPCTRL_MORE_MASK, NULL, HFILL }},
1326 { &hf_ntpctrl_flags2_opcode, {
1327 "Opcode", "ntpctrl.flags2.opcode", FT_UINT8, BASE_DEC,
1328 VALS(ctrl_op_types), NTPCTRL_OP_MASK, NULL, HFILL }},
1329 { &hf_ntpctrl_sequence, {
1330 "Sequence", "ntpctrl.sequence", FT_UINT16, BASE_DEC,
1331 NULL, 0, NULL, HFILL }},
1332 { &hf_ntpctrl_status, {
1333 "Status", "ntpctrl.status", FT_UINT16, BASE_DEC,
1334 NULL, 0, NULL, HFILL }},
1335 { &hf_ntpctrl_error_status_word, {
1336 "Error Status Word", "ntpctrl.err_status", FT_UINT16, BASE_DEC,
1337 VALS(ctrl_err_status_types), NTP_CTRL_ERRSTATUS_CODE_MASK, NULL, HFILL }},
1338 { &hf_ntpctrl_sys_status_li, {
1339 "Leap Indicator", "ntpctrl.sys_status.li", FT_UINT16, BASE_DEC,
1340 VALS(li_types), NTPCTRL_SYSSTATUS_LI_MASK, NULL, HFILL }},
1341 { &hf_ntpctrl_sys_status_clksrc, {
1342 "Clock Source", "ntpctrl.sys_status.clksrc", FT_UINT16, BASE_DEC,
1343 VALS(ctrl_sys_status_clksource_types), NTPCTRL_SYSSTATUS_CLK_MASK, NULL, HFILL }},
1344 { &hf_ntpctrl_sys_status_count, {
1345 "System Event Counter", "ntpctrl.sys_status.count", FT_UINT16, BASE_DEC,
1346 NULL, NTPCTRL_SYSSTATUS_COUNT_MASK, NULL, HFILL }},
1347 { &hf_ntpctrl_sys_status_code, {
1348 "System Event Code", "ntpctrl.sys_status.code", FT_UINT16, BASE_DEC,
1349 VALS(ctrl_sys_status_event_types), NTPCTRL_SYSSTATUS_CODE_MASK, NULL, HFILL }},
1350 { &hf_ntpctrl_peer_status_b0, {
1351 "Peer Status", "ntpctrl.peer_status.config", FT_UINT16, BASE_DEC,
1352 VALS(ctrl_peer_status_config_types), NTPCTRL_PEERSTATUS_CONFIG_MASK, NULL, HFILL }},
1353 { &hf_ntpctrl_peer_status_b1, {
1354 "Peer Status", "ntpctrl.peer_status.authenable", FT_UINT16, BASE_DEC,
1355 VALS(ctrl_peer_status_authenable_types), NTPCTRL_PEERSTATUS_AUTHENABLE_MASK, NULL, HFILL }},
1356 { &hf_ntpctrl_peer_status_b2, {
1357 "Peer Status", "ntpctrl.peer_status.authentic", FT_UINT16, BASE_DEC,
1358 VALS(ctrl_peer_status_authentic_types), NTPCTRL_PEERSTATUS_AUTHENTIC_MASK, NULL, HFILL }},
1359 { &hf_ntpctrl_peer_status_b3, {
1360 "Peer Status", "ntpctrl.peer_status.reach", FT_UINT16, BASE_DEC,
1361 VALS(ctrl_peer_status_reach_types), NTPCTRL_PEERSTATUS_REACH_MASK, NULL, HFILL }},
1362 { &hf_ntpctrl_peer_status_b4, {
1363 "Peer Status: reserved", "ntpctrl.peer_status.reserved", FT_UINT16, BASE_DEC,
1364 NULL, NTPCTRL_PEERSTATUS_RESERVED_MASK, NULL, HFILL }},
1365 { &hf_ntpctrl_peer_status_selection, {
1366 "Peer Selection", "ntpctrl.peer_status.selection", FT_UINT16, BASE_DEC,
1367 VALS(ctrl_peer_status_selection_types), NTPCTRL_PEERSTATUS_SEL_MASK, NULL, HFILL }},
1368 { &hf_ntpctrl_peer_status_count, {
1369 "Peer Event Counter", "ntpctrl.peer_status.count", FT_UINT16, BASE_DEC,
1370 NULL, NTPCTRL_PEERSTATUS_COUNT_MASK, NULL, HFILL }},
1371 { &hf_ntpctrl_peer_status_code, {
1372 "Peer Event Code", "ntpctrl.peer_status.code", FT_UINT16, BASE_DEC,
1373 VALS(ctrl_peer_status_event_types), NTPCTRL_PEERSTATUS_CODE_MASK, NULL, HFILL }},
1374 { &hf_ntpctrl_clk_status, {
1375 "Clock Status", "ntpctrl.clock_status.status", FT_UINT16, BASE_DEC,
1376 VALS(ctrl_clk_status_types), NTPCTRL_CLKSTATUS_STATUS_MASK, NULL, HFILL }},
1377 { &hf_ntpctrl_clk_status_code, {
1378 "Clock Event Code", "ntpctrl.clock_status.code", FT_UINT16, BASE_DEC,
1379 NULL, NTPCTRL_CLKSTATUS_CODE_MASK, NULL, HFILL }},
1380 { &hf_ntpctrl_data, {
1381 "Data", "ntpctrl.data", FT_NONE, BASE_NONE,
1382 NULL, 0, NULL, HFILL }},
1383 { &hf_ntpctrl_item, {
1384 "Item", "ntpctrl.item", FT_NONE, BASE_NONE,
1385 NULL, 0, NULL, HFILL }},
1386 { &hf_ntpctrl_associd, {
1387 "AssociationID", "ntpctrl.associd", FT_UINT16, BASE_DEC,
1388 NULL, 0, NULL, HFILL }},
1389 { &hf_ntpctrl_offset, {
1390 "Offset", "ntpctrl.offset", FT_UINT16, BASE_DEC,
1391 NULL, 0, NULL, HFILL }},
1392 { &hf_ntpctrl_count, {
1393 "Count", "ntpctrl.count", FT_UINT16, BASE_DEC,
1394 NULL, 0, NULL, HFILL }},
1395 { &hf_ntpctrl_trapmsg, {
1396 "Trap message", "ntpctrl.trapmsg", FT_STRING, BASE_NONE,
1397 NULL, 0, NULL, HFILL }},
1399 { &hf_ntppriv_flags_r, {
1400 "Response bit", "ntppriv.flags.r", FT_UINT8, BASE_DEC,
1401 VALS(priv_r_types), NTPPRIV_R_MASK, NULL, HFILL }},
1402 { &hf_ntppriv_flags_more, {
1403 "More bit", "ntppriv.flags.more", FT_UINT8, BASE_DEC,
1404 NULL, NTPPRIV_MORE_MASK, NULL, HFILL }},
1405 { &hf_ntppriv_auth_seq, {
1406 "Auth, sequence", "ntppriv.auth_seq", FT_UINT8, BASE_DEC,
1407 NULL, 0, "Auth bit, sequence number", HFILL }},
1408 { &hf_ntppriv_auth, {
1409 "Auth bit", "ntppriv.auth", FT_UINT8, BASE_DEC,
1410 NULL, NTPPRIV_AUTH_MASK, NULL, HFILL }},
1411 { &hf_ntppriv_seq, {
1412 "Sequence number", "ntppriv.seq", FT_UINT8, BASE_DEC,
1413 NULL, NTPPRIV_SEQ_MASK, NULL, HFILL }},
1414 { &hf_ntppriv_impl, {
1415 "Implementation", "ntppriv.impl", FT_UINT8, BASE_DEC,
1416 VALS(priv_impl_types), 0, NULL, HFILL }},
1417 { &hf_ntppriv_reqcode, {
1418 "Request code", "ntppriv.reqcode", FT_UINT8, BASE_DEC,
1419 VALS(priv_rc_types), 0, NULL, HFILL }}
1421 static gint *ett[] = {
1426 &ett_ntpctrl_flags2,
1427 &ett_ntpctrl_status,
1430 &ett_ntppriv_auth_seq
1433 proto_ntp = proto_register_protocol("Network Time Protocol", "NTP",
1435 proto_register_field_array(proto_ntp, hf, array_length(hf));
1436 proto_register_subtree_array(ett, array_length(ett));
1442 proto_reg_handoff_ntp(void)
1444 dissector_handle_t ntp_handle;
1446 ntp_handle = create_dissector_handle(dissect_ntp, proto_ntp);
1447 dissector_add_uint("udp.port", UDP_PORT_NTP, ntp_handle);
1448 dissector_add_uint("tcp.port", TCP_PORT_NTP, ntp_handle);