Rename the routines that handle dissector tables with unsigned integer
[obnox/wireshark/wip.git] / epan / dissectors / packet-ntp.c
1 /* packet-ntp.c
2  * Routines for NTP packet dissection
3  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-tftp.c
12  *
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.
17  *
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.
22  *
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.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <string.h>
33 #include <time.h>
34 #include <math.h>
35 #include <glib.h>
36
37 #include <epan/packet.h>
38 #include <epan/addr_resolv.h>
39 #include <epan/emem.h>
40
41 #include <epan/tvbparse.h>
42
43 #include "packet-ntp.h"
44
45 /*
46  * Dissecting NTP packets version 3 and 4 (RFC2030, RFC1769, RFC1361,
47  * RFC1305).
48  *
49  * Those packets have simple structure:
50  *                      1                   2                   3
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55  * |                          Root Delay                           |
56  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57  * |                       Root Dispersion                         |
58  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59  * |                    Reference Identifier                       |
60  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61  * |                   Reference Timestamp (64)                    |
62  * |                                                               |
63  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64  * |                   Originate Timestamp (64)                    |
65  * |                                                               |
66  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67  * |                    Receive Timestamp (64)                     |
68  * |                                                               |
69  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70  * |                    Transmit Timestamp (64)                    |
71  * |                                                               |
72  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73  * |                 Key Identifier (optional) (32)                |
74  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75  * |                 Message Digest (optional) (128)               |
76  * |                                                               |
77  * |                                                               |
78  * |                                                               |
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.
83  *
84  *
85  * NTP Control messages as defined in version 2, 3 and 4 (RFC1119, RFC1305) use
86  * the following structure:
87  *                      1                   2                   3
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94  * |            Offset             |             Count             |
95  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96  * |                                                               |
97  * |                     Data (468 octets max)                     |
98  * |                                                               |
99  * |                               |        Padding (zeros)        |
100  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
101  * |                 Authenticator (optional) (96)                 |
102  * |                                                               |
103  * |                                                               |
104  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
105  *
106  * Not yet implemented: complete dissection of TPCTRL_OP_SETTRAP,
107  * NTPCTRL_OP_ASYNCMSG, NTPCTRL_OP_UNSETTRAPSETTRAP Control-Messages
108  *
109  */
110
111 #define UDP_PORT_NTP    123
112 #define TCP_PORT_NTP    123
113
114 /* Leap indicator, 2bit field is used to warn of a inserted/deleted
115  * second, or to alarm loosed synchronization.
116  */
117 #define NTP_LI_MASK     0xC0
118
119 #define NTP_LI_NONE     0
120 #define NTP_LI_61       1
121 #define NTP_LI_59       2
122 #define NTP_LI_ALARM    3
123
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)" },
129         { 0,            NULL}
130 };
131
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.
138  */
139 #define NTP_VN_MASK     0x38
140
141 static const value_string ver_nums[] = {
142         { 0,    "reserved" },
143         { 1,    "NTP Version 1" },
144         { 2,    "NTP Version 2" },
145         { 3,    "NTP Version 3" },
146         { 4,    "NTP Version 4" },
147         { 5,    "reserved" },
148         { 6,    "reserved" },
149         { 7,    "reserved" },
150         { 0,    NULL}
151 };
152
153 /* Mode, 3bit field representing mode of comunication.
154  */
155 #define NTP_MODE_MASK   7
156
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
165
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" },
175         { 0,            NULL}
176 };
177
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" },
187         { 0,            NULL}
188 };
189
190 /* According to rfc, primary (stratum-0 and stratum-1) servers should set
191  * their Reference Clock ID (4bytes field) according to following table:
192  */
193 static const struct {
194         const char *id;
195         const char *data;
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" },
226         { NULL,         NULL}
227 };
228
229 #define NTP_EXT_R_MASK 0x80
230
231 static const value_string ext_r_types[] = {
232         { 0,            "Request" },
233         { 1,            "Response" },
234         { 0,            NULL}
235 };
236
237 #define NTP_EXT_ERROR_MASK 0x40
238 #define NTP_EXT_VN_MASK 0x3f
239
240 static const value_string ext_op_types[] = {
241         { 0,            "NULL" },
242         { 1,            "ASSOC" },
243         { 2,            "CERT" },
244         { 3,            "COOK" },
245         { 4,            "AUTO" },
246         { 5,            "TAI" },
247         { 6,            "SIGN" },
248         { 7,            "IFF" },
249         { 8,            "GQ" },
250         { 9,            "MV" },
251         { 0,            NULL}
252 };
253
254 #define NTPCTRL_R_MASK 0x80
255
256 #define ctrl_r_types ext_r_types
257
258 #define NTPCTRL_ERROR_MASK 0x40
259 #define NTPCTRL_MORE_MASK 0x20
260 #define NTPCTRL_OP_MASK 0x1f
261
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
271
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" },
282         { 0,            NULL}
283 };
284
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
289
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)" },
297         { 6,            "UDP/NTP" },
298         { 7,            "UDP/TIME" },
299         { 8,            "eyeball-and-wristwatch" },
300         { 9,            "telephone modem (e.g. NIST)" },
301         { 0,            NULL}
302 };
303
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)" },
313         { 0,            NULL}
314 };
315
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
325
326 static const value_string ctrl_peer_status_config_types[] = {
327         { 0,            "not configured (peer.config)" },
328         { 1,            "configured (peer.config)" },
329         { 0,            NULL}
330 };
331
332 static const value_string ctrl_peer_status_authenable_types[] = {
333         { 0,            "authentication disabled (peer.authenable" },
334         { 1,            "authentication enabled (peer.authenable" },
335         { 0,            NULL}
336 };
337
338 static const value_string ctrl_peer_status_authentic_types[] = {
339         { 0,            "authentication not okay (peer.authentic)" },
340         { 1,            "authentication okay (peer.authentic)" },
341         { 0,            NULL}
342 };
343
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)" },
347         { 0,            NULL}
348 };
349
350 static const value_string ctrl_peer_status_selection_types[] = {
351         { 0,            "rejected" },
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" },
358         { 7,            "reserved" },
359         { 0,            NULL}
360 };
361
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)" },
369         { 0,            NULL}
370 };
371
372 #define NTPCTRL_CLKSTATUS_STATUS_MASK   0xFF00
373 #define NTPCTRL_CLKSTATUS_CODE_MASK             0x00FF
374
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" },
383         { 0,            NULL}
384 };
385
386 #define NTP_CTRL_ERRSTATUS_CODE_MASK    0xFF00
387
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" },
397         { 0,            NULL}
398 };
399
400
401 #define NTPPRIV_R_MASK 0x80
402
403 #define priv_r_types ext_r_types
404
405 #define NTPPRIV_MORE_MASK 0x40
406
407 #define NTPPRIV_AUTH_MASK 0x80
408 #define NTPPRIV_SEQ_MASK 0x7f
409
410 static const value_string priv_impl_types[] = {
411         { 0,            "UNIV" },
412         { 2,            "XNTPD_OLD (pre-IPv6)" },
413         { 3,            "XNTPD" },
414         { 0,            NULL}
415 };
416
417 static const value_string priv_rc_types[] = {
418         { 0,            "PEER_LIST" },
419         { 1,            "PEER_LIST_SUM" },
420         { 2,            "PEER_INFO" },
421         { 3,            "PEER_STATS" },
422         { 4,            "SYS_INFO" },
423         { 5,            "SYS_STATS" },
424         { 6,            "IO_STATS" },
425         { 7,            "MEM_STATS" },
426         { 8,            "LOOP_INFO" },
427         { 9,            "TIMER_STATS" },
428         { 10,           "CONFIG" },
429         { 11,           "UNCONFIG" },
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" },
440         { 26,           "TRUSTKEY" },
441         { 27,           "UNTRUSTKEY" },
442         { 28,           "AUTHINFO" },
443         { 29,           "TRAPS" },
444         { 30,           "ADD_TRAP" },
445         { 31,           "CLR_TRAP" },
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" },
455         { 0,            NULL}
456 };
457
458 /*
459  * Maximum MAC length.
460  */
461 #define MAX_MAC_LEN     (5 * sizeof (guint32))
462
463 static int proto_ntp = -1;
464
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;
481
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;
496
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;
525
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;
533
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;
543
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);
548
549 static const char *mon_names[12] = {
550         "Jan",
551         "Feb",
552         "Mar",
553         "Apr",
554         "May",
555         "Jun",
556         "Jul",
557         "Aug",
558         "Sep",
559         "Oct",
560         "Nov",
561         "Dec"
562 };
563
564
565 /* parser definitions */
566 static tvbparse_wanted_t* want;
567 static tvbparse_wanted_t* want_ignore;
568
569
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.
574  */
575 const char *
576 ntp_fmt_ts(const guint8 *reftime)
577 {
578         guint32 tempstmp, tempfrac;
579         time_t temptime;
580         struct tm *bd;
581         double fractime;
582         char *buff;
583
584         tempstmp = pntohl(&reftime[0]);
585         tempfrac = pntohl(&reftime[4]);
586         if ((tempstmp == 0) && (tempfrac == 0)) {
587                 return "NULL";
588         }
589
590         temptime = tempstmp - (guint32) NTP_BASETIME;
591         bd = gmtime(&temptime);
592         if(!bd){
593                 return "Not representable";
594         }
595
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],
601                  bd->tm_mday,
602                  bd->tm_year + 1900,
603                  bd->tm_hour,
604                  bd->tm_min,
605                  fractime);
606         return buff;
607 }
608
609 /* dissect_ntp - dissects NTP packet data
610  * tvb - tvbuff for packet data (IN)
611  * pinfo - packet info
612  * proto_tree - resolved protocol tree
613  */
614 static void
615 dissect_ntp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
616 {
617         proto_tree      *ntp_tree;
618         proto_item      *ti;
619         guint8          flags;
620         void (*dissector)(tvbuff_t *, proto_item *, guint8);
621
622         col_set_str(pinfo->cinfo, COL_PROTOCOL, "NTP");
623
624         col_clear(pinfo->cinfo, COL_INFO);
625
626         flags = tvb_get_guint8(tvb, 0);
627         switch (flags & NTP_MODE_MASK) {
628         default:
629                 dissector = dissect_ntp_std;
630                 break;
631         case NTP_MODE_CTRL:
632                 dissector = dissect_ntp_ctrl;
633                 break;
634         case NTP_MODE_PRIV:
635                 dissector = dissect_ntp_priv;
636                 break;
637         }
638
639         col_add_str(pinfo->cinfo, COL_INFO,
640                 val_to_str(flags & NTP_MODE_MASK, info_mode_types, "Unknown"));
641
642         if (tree) {
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);
646
647                 (*dissector)(tvb, ntp_tree, flags);
648         }
649 }
650
651 static void
652 dissect_ntp_std(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
653 {
654         proto_tree      *flags_tree;
655         proto_item      *tf;
656         guint8          stratum;
657         guint8          ppoll;
658         gint8           precision;
659         double          rootdelay;
660         double          rootdispersion;
661         const guint8    *refid;
662         guint32         refid_addr;
663         const guint8    *reftime;
664         const guint8    *org;
665         const guint8    *rec;
666         const guint8    *xmt;
667         const gchar     *buffc;
668         gchar           *buff;
669         int             i;
670         int             macofs;
671         gint            maclen;
672
673         tf = proto_tree_add_uint(ntp_tree, hf_ntp_flags, tvb, 0, 1, flags);
674
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);
680
681         /* Stratum, 1byte field represents distance from primary source
682          */
683         stratum = tvb_get_guint8(tvb, 1);
684         if (stratum == 0) {
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)";
690         } else {
691                 buffc="Peer Clock Stratum: reserved: %u";
692         }
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
697          * power of two.
698          */
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,
702                                    ppoll, 
703                                    "Peer Polling Interval: %u (%u sec)",
704                                    ppoll,
705                                    1 << ppoll);
706         } else {
707                 proto_tree_add_uint_format(ntp_tree, hf_ntp_ppoll, tvb, 2, 1,
708                                    ppoll,
709                                    "Peer Polling Interval: invalid (%u)",
710                                    ppoll);
711         }
712         
713         /* Precision, 1byte field indicating the precision of the
714          * local clock, in seconds to the nearest power of two.
715          */
716         precision = tvb_get_guint8(tvb, 3);
717         proto_tree_add_int_format(ntp_tree, hf_ntp_precision, tvb, 3, 1,
718                                    precision,
719                                    "Peer Clock Precision: %8.6f sec",
720                                    pow(2, precision));
721
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.
725          */
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,
729                                    rootdelay,
730                                    "Root Delay: %9.4f sec",
731                                    rootdelay);
732
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.
736          */
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,
740                                    rootdispersion,
741                                    "Root Dispersion: %9.4f sec",
742                                    rootdispersion);
743
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
747          * reference source.
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.
750          */
751         refid = tvb_get_ptr(tvb, 12, 4);
752         buff = ep_alloc(NTP_TS_SIZE);
753         if (stratum <= 1) {
754                 g_snprintf (buff, NTP_TS_SIZE, "Unidentified reference source '%.4s'",
755                         refid);
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);
760                                 break;
761                         }
762                 }
763         } else {
764                 int buffpos;
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;
772                 }
773         }
774         proto_tree_add_bytes_format(ntp_tree, hf_ntp_refid, tvb, 12, 4,
775                                    refid,
776                                    "Reference Clock ID: %s", buff);
777
778         /* Reference Timestamp: This is the time at which the local clock was
779          * last set or corrected.
780          */
781         reftime = tvb_get_ptr(tvb, 16, 8);
782         proto_tree_add_bytes_format(ntp_tree, hf_ntp_reftime, tvb, 16, 8,
783                                    reftime,
784                                    "Reference Clock Update Time: %s",
785                                    ntp_fmt_ts(reftime));
786
787         /* Originate Timestamp: This is the time at which the request departed
788          * the client for the server.
789          */
790         org = tvb_get_ptr(tvb, 24, 8);
791         proto_tree_add_bytes_format(ntp_tree, hf_ntp_org, tvb, 24, 8,
792                                    org,
793                                    "Originate Time Stamp: %s",
794                                    ntp_fmt_ts(org));
795
796         /* Receive Timestamp: This is the time at which the request arrived at
797          * the server.
798          */
799         rec = tvb_get_ptr(tvb, 32, 8);
800         proto_tree_add_bytes_format(ntp_tree, hf_ntp_rec, tvb, 32, 8,
801                                    rec,
802                                    "Receive Time Stamp: %s",
803                                    ntp_fmt_ts(rec));
804
805         /* Transmit Timestamp: This is the time at which the reply departed the
806          * server for the client.
807          */
808         xmt = tvb_get_ptr(tvb, 40, 8);
809         proto_tree_add_bytes_format(ntp_tree, hf_ntp_xmt, tvb, 40, 8,
810                                    xmt,
811                                    "Transmit Time Stamp: %s",
812                                    ntp_fmt_ts(xmt));
813
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.
818          */
819         macofs = 48;
820         while (tvb_reported_length_remaining(tvb, macofs) > (gint)MAX_MAC_LEN)
821                 macofs = dissect_ntp_ext(tvb, ntp_tree, macofs);
822
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.
827          */
828         if (tvb_reported_length_remaining(tvb, macofs) >= 4)
829                 proto_tree_add_item(ntp_tree, hf_ntp_keyid, tvb, macofs, 4,
830                                     FALSE);
831         macofs += 4;
832         maclen = tvb_reported_length_remaining(tvb, macofs);
833         if (maclen > 0)
834                 proto_tree_add_item(ntp_tree, hf_ntp_mac, tvb, macofs,
835                                     maclen, FALSE);
836 }
837
838 static int
839 dissect_ntp_ext(tvbuff_t *tvb, proto_tree *ntp_tree, int offset)
840 {
841         proto_tree      *ext_tree, *flags_tree;
842         proto_item      *tf;
843         guint16         extlen;
844         int             endoffset;
845         guint8          flags;
846         guint32         vallen, vallen_round, siglen;
847
848         extlen = tvb_get_ntohs(tvb, offset+2);
849         if (extlen < 8) {
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.
853                  */
854                 proto_tree_add_text(ntp_tree, tvb, offset+2, 2,
855                                     "Extension length %u < 8", extlen);
856                 offset += tvb_length_remaining(tvb, offset);
857                 return offset;
858         }
859         if (extlen % 4) {
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.
863                  */
864                 proto_tree_add_text(ntp_tree, tvb, offset+2, 2,
865                         "Extension length %u isn't a multiple of 4",
866                                     extlen);
867                 offset += tvb_length_remaining(tvb, offset);
868                 return offset;
869         }
870         endoffset = offset + extlen;
871
872         tf = proto_tree_add_item(ntp_tree, hf_ntp_ext, tvb, offset, extlen,
873             FALSE);
874         ext_tree = proto_item_add_subtree(tf, ett_ntp_ext);
875
876         flags = tvb_get_guint8(tvb, offset);
877         tf = proto_tree_add_uint(ext_tree, hf_ntp_ext_flags, tvb, offset, 1,
878                                  flags);
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,
881                             flags);
882         proto_tree_add_uint(flags_tree, hf_ntp_ext_flags_error, tvb, offset, 1,
883                             flags);
884         proto_tree_add_uint(flags_tree, hf_ntp_ext_flags_vn, tvb, offset, 1,
885                             flags);
886         offset++;
887
888         proto_tree_add_item(ext_tree, hf_ntp_ext_op, tvb, offset, 1, FALSE);
889         offset++;
890
891         proto_tree_add_uint(ext_tree, hf_ntp_ext_len, tvb, offset, 2, extlen);
892         offset += 2;
893
894         if ((flags & NTP_EXT_VN_MASK) != 2) {
895                 /* don't care about autokey v1 */
896                 return endoffset;
897         }
898
899         proto_tree_add_item(ext_tree, hf_ntp_ext_associd, tvb, offset, 4,
900                             FALSE);
901         offset += 4;
902
903         /* check whether everything up to "vallen" is present */
904         if (extlen < MAX_MAC_LEN) {
905                 /* XXX - report as error? */
906                 return endoffset;
907         }
908
909         proto_tree_add_item(ext_tree, hf_ntp_ext_tstamp, tvb, offset, 4,
910                             FALSE);
911         offset += 4;
912         proto_tree_add_item(ext_tree, hf_ntp_ext_fstamp, tvb, offset, 4,
913                             FALSE);
914         offset += 4;
915         /* XXX fstamp can be server flags */
916
917         vallen = tvb_get_ntohl(tvb, offset);
918         proto_tree_add_uint(ext_tree, hf_ntp_ext_vallen, tvb, offset, 4,
919                             vallen);
920         offset += 4;
921         vallen_round = (vallen + 3) & (-4);
922         if (vallen != 0) {
923                 if ((guint32)(endoffset - offset) < vallen_round) {
924                         /*
925                          * Value goes past the length of the extension
926                          * field.
927                          */
928                         proto_tree_add_text(ext_tree, tvb, offset,
929                                             endoffset - offset,
930                                             "Value length makes value go past the end of the extension field");
931                         return endoffset;
932                 }
933                 proto_tree_add_item(ext_tree, hf_ntp_ext_val, tvb, offset,
934                                     vallen, FALSE);
935         }
936         offset += vallen_round;
937
938         siglen = tvb_get_ntohl(tvb, offset);
939         proto_tree_add_uint(ext_tree, hf_ntp_ext_siglen, tvb, offset, 4,
940                             siglen);
941         offset += 4;
942         if (siglen != 0) {
943                 if (offset + (int)siglen > endoffset) {
944                         /*
945                          * Value goes past the length of the extension
946                          * field.
947                          */
948                         proto_tree_add_text(ext_tree, tvb, offset,
949                                             endoffset - offset,
950                                             "Signature length makes value go past the end of the extension field");
951                         return endoffset;
952                 }
953                 proto_tree_add_item(ext_tree, hf_ntp_ext_sig, tvb,
954                         offset, siglen, FALSE);
955         }
956         return endoffset;
957 }
958
959 static void
960 dissect_ntp_ctrl_peerstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
961 {
962         /*
963          * dissect peer status word:
964          *                      1
965          *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
966          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
967          * | Status  | Sel | Count | Code  |
968          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
969          */
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);
978 }
979
980 static void
981 dissect_ntp_ctrl_systemstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
982 {
983         /*
984          * dissect system status word:
985          *                      1
986          *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
987          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
988          * |LI | ClkSource | Count | Code  |
989          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
990          */
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);
995 }
996
997 static void
998 dissect_ntp_ctrl_errorstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
999 {
1000         /*
1001          * if error bit is set: dissect error status word
1002          *                      1
1003          *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
1004          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1005          * |  Error Code   |   reserved    |
1006          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1007          */
1008         proto_tree_add_uint(status_tree, hf_ntpctrl_error_status_word, tvb, offset, 2, status);
1009 }
1010
1011 static void
1012 dissect_ntp_ctrl_clockstatus(tvbuff_t *tvb, proto_tree *status_tree, guint16 offset, guint16 status)
1013 {
1014         /*
1015          * dissect clock status word:
1016          *                      1
1017          *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
1018          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1019          * | Clock Status  |  Event Code   |
1020          * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1021          */
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);
1024 }
1025
1026 static void
1027 dissect_ntp_ctrl(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
1028 {
1029         proto_tree *flags_tree;
1030         proto_item *tf;
1031         guint8 flags2;
1032
1033         proto_tree *status_tree, *data_tree, *item_tree;
1034         proto_item *ts, *td, *ti;
1035         guint16 status;
1036         guint16 associd;
1037         guint16 datalen;
1038         guint16 data_offset;
1039
1040         tvbparse_t *tt;
1041         tvbparse_elem_t *element;
1042
1043         tf = proto_tree_add_uint(ntp_tree, hf_ntp_flags, tvb, 0, 1, flags);
1044
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);
1050
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);
1058
1059         proto_tree_add_uint(ntp_tree, hf_ntpctrl_sequence, tvb, 2, 2, tvb_get_ntohs(tvb, 2));
1060
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);
1065         /*
1066          * further processing of status is only necessary in server responses
1067          */
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);
1072                 } else {
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:
1079                                 if (associd)
1080                                         dissect_ntp_ctrl_peerstatus(tvb, status_tree, 4, status);
1081                                 else
1082                                         dissect_ntp_ctrl_systemstatus(tvb, status_tree, 4, status);
1083                                 break;
1084                         case NTPCTRL_OP_READCLOCK:
1085                         case NTPCTRL_OP_WRITECLOCK:
1086                                 dissect_ntp_ctrl_clockstatus(tvb, status_tree, 4, status);
1087                                 break;
1088                         case NTPCTRL_OP_SETTRAP:
1089                         case NTPCTRL_OP_UNSETTRAP:
1090                                 break;
1091                         }
1092                 }
1093         }
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);
1098
1099         /*
1100          * dissect Data part of the NTP control message
1101          */
1102         if (datalen) {
1103                 data_offset = 12;
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:
1108                         if (!associd) {
1109                                 /*
1110                                  * if associd == 0 then data part contains a list of the form
1111                                  * <association identifier><status word>,
1112                                  */
1113                                 while(datalen) {
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));
1117                                         data_offset += 2;
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 );
1122                                         data_offset += 2;
1123                                         datalen -= 4;
1124                                 }
1125                                 break;
1126                         }
1127                         /*
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!
1131                          */
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);
1139                         }
1140                         break;
1141                 case NTPCTRL_OP_ASYNCMSG:
1142                         proto_tree_add_item(data_tree, hf_ntpctrl_trapmsg, tvb, data_offset, datalen, TRUE);
1143                         break;
1144                 /* these opcodes doesn't carry any data: NTPCTRL_OP_SETTRAP, NTPCTRL_OP_UNSETTRAP, NTPCTRL_OP_UNSPEC */
1145                 }
1146         }
1147 }
1148
1149 /*
1150  * Initialize tvb-parser, which is used to dissect data part of NTP control
1151  * messages
1152  *
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
1156  */
1157 static void
1158 init_parser(void)
1159 {
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),
1170                 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,
1173                 want_identifier,
1174                 want_equalsign,
1175                 want_value,
1176                 NULL);
1177
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,
1182                 want_assignment,
1183                 want_identifier,
1184                 NULL);
1185 }
1186
1187 static void
1188 dissect_ntp_priv(tvbuff_t *tvb, proto_tree *ntp_tree, guint8 flags)
1189 {
1190         proto_tree      *flags_tree;
1191         proto_item      *tf;
1192         guint8          auth_seq, impl, reqcode;
1193
1194         tf = proto_tree_add_uint(ntp_tree, hf_ntp_flags, tvb, 0, 1, flags);
1195
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,
1200                             flags);
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);
1203
1204         auth_seq = tvb_get_guint8(tvb, 1);
1205         tf = proto_tree_add_uint(ntp_tree, hf_ntppriv_auth_seq, tvb, 1, 1,
1206                                  auth_seq);
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);
1210
1211         impl = tvb_get_guint8(tvb, 2);
1212         proto_tree_add_uint(ntp_tree, hf_ntppriv_impl, tvb, 2, 1, impl);
1213
1214         reqcode = tvb_get_guint8(tvb, 3);
1215         proto_tree_add_uint(ntp_tree, hf_ntppriv_reqcode, tvb, 3, 1, reqcode);
1216 }
1217
1218 void
1219 proto_register_ntp(void)
1220 {
1221         static hf_register_info hf[] = {
1222                 { &hf_ntp_flags, {
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 }},
1237                 { &hf_ntp_ppoll, {
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 }},
1249                 { &hf_ntp_refid, {
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 }},
1255                 { &hf_ntp_org, {
1256                         "Originate Time Stamp", "ntp.org", FT_BYTES, BASE_NONE,
1257                         NULL, 0, NULL, HFILL }},
1258                 { &hf_ntp_rec, {
1259                         "Receive Time Stamp", "ntp.rec", FT_BYTES, BASE_NONE,
1260                         NULL, 0, NULL, HFILL }},
1261                 { &hf_ntp_xmt, {
1262                         "Transmit Time Stamp", "ntp.xmt", FT_BYTES, BASE_NONE,
1263                         NULL, 0, NULL, HFILL }},
1264                 { &hf_ntp_keyid, {
1265                         "Key ID", "ntp.keyid", FT_BYTES, BASE_NONE,
1266                         NULL, 0, NULL, HFILL }},
1267                 { &hf_ntp_mac, {
1268                         "Message Authentication Code", "ntp.mac", FT_BYTES, BASE_NONE,
1269                         NULL, 0, NULL, HFILL }},
1270
1271                 { &hf_ntp_ext, {
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 }},
1286                 { &hf_ntp_ext_op, {
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 }},
1313
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 }},
1398
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 }}
1420         };
1421         static gint *ett[] = {
1422                 &ett_ntp,
1423                 &ett_ntp_flags,
1424                 &ett_ntp_ext,
1425                 &ett_ntp_ext_flags,
1426                 &ett_ntpctrl_flags2,
1427                 &ett_ntpctrl_status,
1428                 &ett_ntpctrl_data,
1429                 &ett_ntpctrl_item,
1430                 &ett_ntppriv_auth_seq
1431         };
1432
1433         proto_ntp = proto_register_protocol("Network Time Protocol", "NTP",
1434             "ntp");
1435         proto_register_field_array(proto_ntp, hf, array_length(hf));
1436         proto_register_subtree_array(ett, array_length(ett));
1437
1438         init_parser();
1439 }
1440
1441 void
1442 proto_reg_handoff_ntp(void)
1443 {
1444         dissector_handle_t ntp_handle;
1445
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);
1449 }