ea3c1ef26641af696401fa56ff30fb96b8f37186
[obnox/wireshark/wip.git] / epan / dissectors / packet-netsync.c
1 /* packet-netsync.c
2  * Routines for Monotone Netsync packet disassembly
3  *
4  * $Id$
5  *
6  * Copyright (c) 2005 by Erwin Rol <erwin@erwinrol.com>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1999 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /* Include files */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <stdlib.h>
34 #include <ctype.h>
35 #include <time.h>
36 #include <epan/packet.h>
37 #include <epan/addr_resolv.h>
38 #include <epan/prefs.h>
39 #include <epan/strutil.h>
40 #include "packet-tcp.h"
41
42 /*
43  * See
44  *
45  *      http://www.venge.net/monotone/
46  */
47
48 /* Define TCP ports for Monotone netsync */
49
50 #define TCP_PORT_NETSYNC 5253
51
52 #define NETSYNC_ROLE_SOURCE     1
53 #define NETSYNC_ROLE_SINK       2
54 #define NETSYNC_ROLE_BOTH       3
55
56 static const value_string netsync_role_vals[] = {
57         { NETSYNC_ROLE_SOURCE,  "Source" },
58         { NETSYNC_ROLE_SINK,    "Sink" },
59         { NETSYNC_ROLE_BOTH,    "Both" },
60         { 0,                    NULL }
61 };
62
63
64 #define NETSYNC_CMD_ERROR       0
65 #define NETSYNC_CMD_BYE         1
66 #define NETSYNC_CMD_HELLO       2
67 #define NETSYNC_CMD_ANONYMOUS   3
68 #define NETSYNC_CMD_AUTH        4
69 #define NETSYNC_CMD_CONFIRM     5
70 #define NETSYNC_CMD_REFINE      6
71 #define NETSYNC_CMD_DONE        7
72 #define NETSYNC_CMD_SEND_DATA   8
73 #define NETSYNC_CMD_SEND_DELTA  9
74 #define NETSYNC_CMD_DATA        10
75 #define NETSYNC_CMD_DELTA       11
76 #define NETSYNC_CMD_NONEXISTENT 12
77
78 static const value_string netsync_cmd_vals[] = {
79         { NETSYNC_CMD_ERROR,            "Error" },
80         { NETSYNC_CMD_BYE,              "Bye" },
81         { NETSYNC_CMD_HELLO,            "Hello" },
82         { NETSYNC_CMD_ANONYMOUS,        "Anonymous" },
83         { NETSYNC_CMD_AUTH,             "Auth" },
84         { NETSYNC_CMD_CONFIRM,          "Confirm" },
85         { NETSYNC_CMD_REFINE,           "Refine" },
86         { NETSYNC_CMD_DONE,             "Done" },
87         { NETSYNC_CMD_SEND_DATA,        "Send Data" },
88         { NETSYNC_CMD_SEND_DELTA,       "Send Delta" },
89         { NETSYNC_CMD_DATA,             "Data" },
90         { NETSYNC_CMD_DELTA,            "Delta" },
91         { NETSYNC_CMD_NONEXISTENT,      "Nonexistent" },
92         { 0,                            NULL }
93 };
94
95 #define NETSNYC_MERKLE_HASH_LENGTH 20
96
97 void proto_reg_handoff_netsync(void);
98
99 /* Define the monotone netsync proto */
100 static int proto_netsync = -1;
101
102 static int hf_netsync_version = -1;
103 static int hf_netsync_command = -1;
104 static int hf_netsync_size = -1;
105 static int hf_netsync_data = -1;
106 static int hf_netsync_checksum = -1;
107
108 static int hf_netsync_cmd_done_level = -1;
109 static int hf_netsync_cmd_done_type = -1;
110
111 static int hf_netsync_cmd_hello_keyname = -1;
112 static int hf_netsync_cmd_hello_key = -1;
113 static int hf_netsync_cmd_nonce = -1;
114
115 static int hf_netsync_cmd_anonymous_role = -1;
116 static int hf_netsync_cmd_anonymous_collection = -1;
117
118 static int hf_netsync_cmd_send_data_type = -1;
119 static int hf_netsync_cmd_send_data_id = -1;
120
121 static int hf_netsync_cmd_error_msg = -1;
122
123
124 static int hf_netsync_cmd_confirm_sig = -1;
125
126 static int hf_netsync_cmd_auth_role = -1;
127 static int hf_netsync_cmd_auth_collection = -1;
128 static int hf_netsync_cmd_auth_id = -1;
129 static int hf_netsync_cmd_auth_nonce1 = -1;
130 static int hf_netsync_cmd_auth_nonce2 = -1;
131 static int hf_netsync_cmd_auth_sig = -1;
132
133 static int hf_netsync_cmd_data_type = -1;
134 static int hf_netsync_cmd_data_id = -1;
135 static int hf_netsync_cmd_data_compressed = -1;
136 static int hf_netsync_cmd_data_payload = -1;
137
138 static int hf_netsync_cmd_delta_type = -1;
139 static int hf_netsync_cmd_delta_base_id = -1;
140 static int hf_netsync_cmd_delta_ident_id = -1;
141 static int hf_netsync_cmd_delta_compressed = -1;
142 static int hf_netsync_cmd_delta_payload = -1;
143
144 static int hf_netsync_cmd_refine_tree_node = -1;
145
146 static int hf_netsync_cmd_send_delta_type = -1;
147 static int hf_netsync_cmd_send_delta_base_id = -1;
148 static int hf_netsync_cmd_send_delta_ident_id = -1;
149
150 static int hf_netsync_cmd_nonexistent_type = -1;
151 static int hf_netsync_cmd_nonexistent_id = -1;
152
153 /* Define the tree for netsync */
154 static int ett_netsync = -1;
155
156
157 /*
158  * Here are the global variables associated with the preferences
159  * for monotone netsync
160  */
161
162 static guint global_tcp_port_netsync = TCP_PORT_NETSYNC;
163 static gboolean netsync_desegment = TRUE;
164
165 static gint dissect_uleb128( tvbuff_t *tvb, gint offset, guint* size)
166 {
167         guint shift = 0;
168         guint8 tmp;
169         guint start_offset = offset;
170
171         *size = 0;
172
173         /* get size */
174         do {
175                 tmp = tvb_get_guint8(tvb, offset);
176                 offset += 1;
177
178                 *size |= (tmp & 0x7F) << shift;
179                 shift += 7;
180         } while (tmp & 0x80);
181
182
183         return offset - start_offset;
184 }
185
186 static gint dissect_netsync_cmd_error( tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
187 {
188         guint len = 0;
189
190         offset += dissect_uleb128( tvb, offset, &len );
191
192         proto_tree_add_item(tree, hf_netsync_cmd_error_msg, tvb,
193                                 offset, len, ENC_ASCII|ENC_NA );
194         offset += len;
195
196         return offset;
197 }
198
199 static gint dissect_netsync_cmd_bye(tvbuff_t *tvb _U_,  gint offset, proto_tree *tree _U_, guint size _U_)
200 {
201         return offset;
202 }
203
204
205 static gint dissect_netsync_cmd_hello(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
206 {
207         guint len = 0;
208
209         offset += dissect_uleb128( tvb, offset, &len );
210
211         proto_tree_add_item(tree, hf_netsync_cmd_hello_keyname, tvb,
212                                 offset, len, ENC_ASCII|ENC_NA );
213         offset += len;
214
215
216         offset += dissect_uleb128( tvb, offset, &len );
217
218         proto_tree_add_item(tree, hf_netsync_cmd_hello_key, tvb,
219                                 offset, len, ENC_NA );
220         offset += len;
221
222         proto_tree_add_item(tree, hf_netsync_cmd_nonce, tvb,
223                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
224         offset += NETSNYC_MERKLE_HASH_LENGTH;
225
226         return offset;
227 }
228
229
230 static gint dissect_netsync_cmd_anonymous(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
231 {
232         guint len = 0;
233
234         proto_tree_add_item(tree, hf_netsync_cmd_anonymous_role, tvb,
235                                 offset, 1, ENC_BIG_ENDIAN );
236         offset += 1;
237
238         offset += dissect_uleb128( tvb, offset, &len );
239
240         proto_tree_add_item(tree, hf_netsync_cmd_anonymous_collection, tvb,
241                                 offset, len, ENC_ASCII|ENC_NA );
242         offset += len;
243
244         proto_tree_add_item(tree, hf_netsync_cmd_nonce, tvb,
245                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
246         offset += NETSNYC_MERKLE_HASH_LENGTH;
247
248         return offset;
249 }
250
251
252 static gint dissect_netsync_cmd_auth(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
253 {
254         guint len = 0;
255
256         proto_tree_add_item(tree, hf_netsync_cmd_auth_role, tvb,
257                                 offset, 1, ENC_BIG_ENDIAN );
258         offset += 1;
259
260
261         offset += dissect_uleb128( tvb, offset, &len );
262
263         proto_tree_add_item(tree, hf_netsync_cmd_auth_collection, tvb,
264                                 offset, len, ENC_ASCII|ENC_NA );
265         offset += len;
266
267         proto_tree_add_item(tree, hf_netsync_cmd_auth_id, tvb,
268                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
269         offset += NETSNYC_MERKLE_HASH_LENGTH;
270
271         offset += len;
272
273         proto_tree_add_item(tree, hf_netsync_cmd_auth_nonce1, tvb,
274                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
275         offset += NETSNYC_MERKLE_HASH_LENGTH;
276
277         offset += len;
278
279         proto_tree_add_item(tree, hf_netsync_cmd_auth_nonce2, tvb,
280                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
281         offset += NETSNYC_MERKLE_HASH_LENGTH;
282
283         offset += dissect_uleb128( tvb, offset, &len );
284
285         proto_tree_add_item(tree, hf_netsync_cmd_auth_sig, tvb,
286                                 offset, len, ENC_NA );
287         offset += len;
288
289         return offset;
290 }
291
292
293 static gint dissect_netsync_cmd_confirm(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
294 {
295         guint len = 0;
296
297         offset += dissect_uleb128( tvb, offset, &len );
298
299         proto_tree_add_item(tree, hf_netsync_cmd_confirm_sig, tvb,
300                                 offset, len, ENC_NA );
301         offset += len;
302
303
304         return offset;
305 }
306
307
308 static gint dissect_netsync_cmd_refine(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size)
309 {
310         proto_tree_add_item(tree, hf_netsync_cmd_refine_tree_node, tvb,
311                                 offset, size, ENC_NA );
312         offset += size;
313
314         return offset;
315 }
316
317
318 static gint dissect_netsync_cmd_done(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
319 {
320         guint len = 0;
321         guint bytes = 0;
322
323         bytes = dissect_uleb128( tvb, offset, &len );
324
325         proto_tree_add_uint(tree, hf_netsync_cmd_done_level, tvb,
326                                         offset, bytes, len );
327         offset += bytes;
328
329         proto_tree_add_item(tree, hf_netsync_cmd_done_type, tvb,
330                                 offset, 1, ENC_BIG_ENDIAN );
331         offset += 1;
332
333         return offset;
334 }
335
336
337 static gint dissect_netsync_cmd_send_data(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
338 {
339         proto_tree_add_item(tree, hf_netsync_cmd_send_data_type, tvb,
340                                         offset, 1, ENC_BIG_ENDIAN );
341         offset += 1;
342
343         proto_tree_add_item(tree, hf_netsync_cmd_send_data_id, tvb,
344                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
345         offset += NETSNYC_MERKLE_HASH_LENGTH;
346
347         return offset;
348 }
349
350
351 static gint dissect_netsync_cmd_send_delta(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
352 {
353         proto_tree_add_item(tree, hf_netsync_cmd_send_delta_type, tvb,
354                                         offset, 1, ENC_BIG_ENDIAN );
355         offset += 1;
356
357         proto_tree_add_item(tree, hf_netsync_cmd_send_delta_base_id, tvb,
358                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
359         offset += NETSNYC_MERKLE_HASH_LENGTH;
360
361
362         proto_tree_add_item(tree, hf_netsync_cmd_send_delta_ident_id, tvb,
363                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
364         offset += NETSNYC_MERKLE_HASH_LENGTH;
365
366         return offset;
367 }
368
369
370 static gint dissect_netsync_cmd_data(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
371 {
372         guint len = 0;
373
374         proto_tree_add_item(tree, hf_netsync_cmd_data_type, tvb,
375                                 offset, 1, ENC_BIG_ENDIAN );
376         offset += 1;
377
378         proto_tree_add_item(tree, hf_netsync_cmd_data_id, tvb,
379                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
380         offset += NETSNYC_MERKLE_HASH_LENGTH;
381
382         proto_tree_add_item(tree, hf_netsync_cmd_data_compressed, tvb,
383                                 offset, 1, ENC_BIG_ENDIAN );
384         offset += 1;
385
386         offset += dissect_uleb128( tvb, offset, &len );
387
388         proto_tree_add_item(tree, hf_netsync_cmd_data_payload, tvb,
389                                 offset, len, ENC_NA );
390         offset += len;
391
392         return offset;
393 }
394
395
396 static gint dissect_netsync_cmd_delta(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
397 {
398         guint len = 0;
399
400         proto_tree_add_item(tree, hf_netsync_cmd_delta_type, tvb,
401                                 offset, 1, ENC_BIG_ENDIAN );
402         offset += 1;
403
404         proto_tree_add_item(tree, hf_netsync_cmd_delta_base_id, tvb,
405                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
406         offset += NETSNYC_MERKLE_HASH_LENGTH;
407
408         proto_tree_add_item(tree, hf_netsync_cmd_delta_ident_id, tvb,
409                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
410         offset += NETSNYC_MERKLE_HASH_LENGTH;
411
412         proto_tree_add_item(tree, hf_netsync_cmd_delta_compressed, tvb,
413                                 offset, 1, ENC_BIG_ENDIAN );
414         offset += 1;
415
416         offset += dissect_uleb128( tvb, offset, &len );
417
418         proto_tree_add_item(tree, hf_netsync_cmd_delta_payload, tvb,
419                                 offset, len, ENC_NA );
420         offset += len;
421
422         return offset;
423 }
424
425
426 static gint dissect_netsync_cmd_nonexistent(tvbuff_t *tvb,  gint offset, proto_tree *tree, guint size _U_)
427 {
428         proto_tree_add_item(tree, hf_netsync_cmd_nonexistent_type, tvb,
429                                 offset, 1, ENC_BIG_ENDIAN );
430         offset += 1;
431
432         proto_tree_add_item(tree, hf_netsync_cmd_nonexistent_id, tvb,
433                                 offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
434         offset += NETSNYC_MERKLE_HASH_LENGTH;
435
436         return offset;
437 }
438
439 static guint
440 get_netsync_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
441 {
442         guint size = 0, size_bytes;
443
444         /* skip version and command */
445         offset += 2;
446
447         size_bytes = dissect_uleb128( tvb, offset, &size );
448
449         /* the calculated size if for the data only, this doesn't
450          * include the version (1 byte), command (1 byte),
451          * length (size_bytes bytes) and checksum (4 bytes)
452          */
453
454         return 1 + 1 + size_bytes + size + 4;
455 }
456
457 static void
458 dissect_netsync_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
459 {
460         gint offset = 0;
461         guint8 tmp;
462         guint8 cmd, version;
463         guint32 size, size_bytes, shift;
464         proto_tree *ti,*netsync_tree=NULL;
465
466         /* Set the protocol column */
467         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Netsync");
468
469
470         if (tree == NULL)
471                 return;
472
473         while (tvb_reported_length_remaining(tvb, offset)  > 0) {
474                 ti = proto_tree_add_item(tree, proto_netsync, tvb, offset, -1, FALSE);
475                 netsync_tree = proto_item_add_subtree(ti, ett_netsync);
476
477                 version = tvb_get_guint8(tvb, offset);
478                 proto_tree_add_item(netsync_tree, hf_netsync_version, tvb,
479                                         offset, 1, ENC_BIG_ENDIAN );
480                 offset += 1;
481
482                 cmd = tvb_get_guint8(tvb, offset);
483                 proto_tree_add_item(netsync_tree, hf_netsync_command, tvb,
484                                         offset, 1, ENC_BIG_ENDIAN );
485                 offset += 1;
486
487
488                 /* get size */
489                 size = 0;
490                 size_bytes = 0;
491                 shift = 0;
492                 do {
493                         tmp = tvb_get_guint8(tvb, offset + size_bytes);
494                         size_bytes += 1;
495
496                         size |= (tmp & 0x7F) << shift;
497                         shift += 7;
498                 } while (tmp & 0x80);
499
500
501                 proto_tree_add_uint(netsync_tree, hf_netsync_size, tvb,
502                                         offset, size_bytes, size );
503                 offset += size_bytes;
504
505                 switch (cmd) {
506                         case NETSYNC_CMD_DONE:
507                                 dissect_netsync_cmd_done( tvb, offset, netsync_tree, size );
508                                 break;
509
510                         case NETSYNC_CMD_ERROR:
511                                 dissect_netsync_cmd_error( tvb, offset, netsync_tree, size );
512                                 break;
513
514                         case NETSYNC_CMD_BYE:
515                                 dissect_netsync_cmd_bye( tvb, offset, netsync_tree, size );
516                                 break;
517
518                         case NETSYNC_CMD_HELLO:
519                                 dissect_netsync_cmd_hello( tvb, offset, netsync_tree, size );
520                                 break;
521
522                         case NETSYNC_CMD_ANONYMOUS:
523                                 dissect_netsync_cmd_anonymous( tvb, offset, netsync_tree, size );
524                                 break;
525
526                         case NETSYNC_CMD_AUTH:
527                                 dissect_netsync_cmd_auth( tvb, offset, netsync_tree, size );
528                                 break;
529
530                         case NETSYNC_CMD_CONFIRM:
531                                 dissect_netsync_cmd_confirm( tvb, offset, netsync_tree, size );
532                                 break;
533
534                         case NETSYNC_CMD_REFINE:
535                                 dissect_netsync_cmd_refine( tvb, offset, netsync_tree, size );
536                                 break;
537
538                         case NETSYNC_CMD_SEND_DATA:
539                                 dissect_netsync_cmd_send_data( tvb, offset, netsync_tree, size );
540                                 break;
541
542                         case NETSYNC_CMD_SEND_DELTA:
543                                 dissect_netsync_cmd_send_delta( tvb, offset, netsync_tree, size );
544                                 break;
545
546                         case NETSYNC_CMD_DATA:
547                                 dissect_netsync_cmd_data( tvb, offset, netsync_tree, size );
548                                 break;
549
550                         case NETSYNC_CMD_DELTA:
551                                 dissect_netsync_cmd_delta( tvb, offset, netsync_tree, size );
552                                 break;
553
554                         case NETSYNC_CMD_NONEXISTENT:
555                                 dissect_netsync_cmd_nonexistent( tvb, offset, netsync_tree, size );
556                                 break;
557
558                         default:
559                                 proto_tree_add_item(netsync_tree, hf_netsync_data, tvb,
560                                         offset, size, ENC_NA );
561                                 break;
562                 }
563
564                 offset += size;
565
566                 proto_tree_add_item(netsync_tree, hf_netsync_checksum, tvb,
567                                         offset, 4, ENC_BIG_ENDIAN );
568                 offset += 4;
569
570
571                 proto_item_append_text(netsync_tree, " V%d, Cmd: %s (%d), Size: %d",
572                                         version, val_to_str(cmd, netsync_cmd_vals, "(0x%x)"), cmd, size );
573
574                 proto_item_set_len(netsync_tree, 1+1+size_bytes+size+4);
575         }
576 }
577
578 static void
579 dissect_netsync(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
580 {
581         tcp_dissect_pdus(tvb, pinfo, tree, netsync_desegment, 7, get_netsync_pdu_len,
582                                         dissect_netsync_pdu);
583 }
584
585 void
586 proto_register_netsync(void)
587 {
588         static hf_register_info hf[] = {
589                 /* General */
590                 { &hf_netsync_version,
591                         { "Version", "netsync.version",
592                           FT_UINT8, BASE_DEC, NULL, 0x0,
593                           NULL, HFILL } },
594                 { &hf_netsync_command,
595                         { "Command", "netsync.command",
596                           FT_UINT8, BASE_HEX, VALS(netsync_cmd_vals), 0x0,
597                           NULL, HFILL } },
598                 { &hf_netsync_size,
599                         { "Size", "netsync.size",
600                           FT_UINT32, BASE_DEC, NULL, 0x0,
601                           NULL, HFILL } },
602                 { &hf_netsync_data,
603                         { "Data", "netsync.data",
604                           FT_BYTES, BASE_NONE, NULL, 0x0,
605                           NULL, HFILL } },
606                 { &hf_netsync_checksum,
607                         { "Checksum", "netsync.checksum",
608                           FT_UINT32, BASE_HEX, NULL, 0x0,
609                           NULL, HFILL } },
610                 { &hf_netsync_cmd_hello_keyname,
611                         { "Key Name", "netsync.cmd.hello.keyname",
612                           FT_STRING, BASE_NONE, NULL, 0x0,
613                           NULL, HFILL } },
614                 { &hf_netsync_cmd_hello_key,
615                         { "Key", "netsync.cmd.hello.key",
616                           FT_BYTES, BASE_NONE, NULL, 0x0,
617                           NULL, HFILL } },
618                 { &hf_netsync_cmd_nonce,
619                         { "Nonce", "netsync.cmd.nonce",
620                           FT_BYTES, BASE_NONE, NULL, 0x0,
621                           NULL, HFILL } },
622                 { &hf_netsync_cmd_anonymous_role,
623                         { "Role", "netsync.cmd.anonymous.role",
624                           FT_UINT8, BASE_DEC, VALS(netsync_role_vals), 0x0,
625                           NULL, HFILL } },
626                 { &hf_netsync_cmd_anonymous_collection,
627                         { "Collection", "netsync.cmd.anonymous.collection",
628                           FT_STRING, BASE_NONE, NULL, 0x0,
629                           NULL, HFILL } },
630                 { &hf_netsync_cmd_confirm_sig,
631                         { "Signature", "netsync.cmd.confirm.signature",
632                           FT_BYTES, BASE_NONE, NULL, 0x0,
633                           NULL, HFILL } },
634                 { &hf_netsync_cmd_send_data_type,
635                         { "Type", "netsync.cmd.send_data.type",
636                           FT_UINT8, BASE_DEC, NULL, 0x0,
637                           NULL, HFILL } },
638                 { &hf_netsync_cmd_send_data_id,
639                         { "ID", "netsync.cmd.send_data.id",
640                           FT_BYTES, BASE_NONE, NULL, 0x0,
641                           NULL, HFILL } },
642                 { &hf_netsync_cmd_error_msg,
643                         { "Message", "netsync.cmd.error.msg",
644                           FT_STRING, BASE_NONE, NULL, 0x0,
645                           NULL, HFILL } },
646
647                 { &hf_netsync_cmd_done_level,
648                         { "Level", "netsync.cmd.done.level",
649                           FT_UINT32, BASE_DEC, NULL, 0x0,
650                           NULL, HFILL } },
651                 { &hf_netsync_cmd_auth_role,
652                         { "Role", "netsync.cmd.auth.role",
653                           FT_UINT8, BASE_DEC, VALS(netsync_role_vals), 0x0,
654                           NULL, HFILL } },
655                 { &hf_netsync_cmd_auth_collection,
656                         { "Collection", "netsync.cmd.auth.collection",
657                           FT_STRING, BASE_NONE, NULL, 0x0,
658                           NULL, HFILL } },
659                 { &hf_netsync_cmd_auth_id,
660                         { "ID", "netsync.cmd.auth.id",
661                           FT_BYTES, BASE_NONE, NULL, 0x0,
662                           NULL, HFILL } },
663                 { &hf_netsync_cmd_auth_nonce1,
664                         { "Nonce 1", "netsync.cmd.auth.nonce1",
665                           FT_BYTES, BASE_NONE, NULL, 0x0,
666                           NULL, HFILL } },
667                 { &hf_netsync_cmd_auth_nonce2,
668                         { "Nonce 2", "netsync.cmd.auth.nonce2",
669                           FT_BYTES, BASE_NONE, NULL, 0x0,
670                           NULL, HFILL } },
671                 { &hf_netsync_cmd_auth_sig,
672                         { "Signature", "netsync.cmd.auth.sig",
673                           FT_BYTES, BASE_NONE, NULL, 0x0,
674                           NULL, HFILL } },
675                 { &hf_netsync_cmd_data_type,
676                         { "Type", "netsync.cmd.data.type",
677                           FT_UINT8, BASE_DEC, NULL, 0x0,
678                           NULL, HFILL } },
679                 { &hf_netsync_cmd_data_id,
680                         { "ID", "netsync.cmd.data.id",
681                           FT_BYTES, BASE_NONE, NULL, 0x0,
682                           NULL, HFILL } },
683                 { &hf_netsync_cmd_data_compressed,
684                         { "Compressed", "netsync.cmd.data.compressed",
685                           FT_UINT8, BASE_DEC, NULL, 0x0,
686                           NULL, HFILL } },
687                 { &hf_netsync_cmd_data_payload,
688                         { "Payload", "netsync.cmd.data.payload",
689                           FT_BYTES, BASE_NONE, NULL, 0x0,
690                           NULL, HFILL } },
691                 { &hf_netsync_cmd_delta_type,
692                         { "Type", "netsync.cmd.delta.type",
693                           FT_UINT8, BASE_DEC, NULL, 0x0,
694                           NULL, HFILL } },
695                 { &hf_netsync_cmd_delta_base_id,
696                         { "Base ID", "netsync.cmd.delta.base_id",
697                           FT_BYTES, BASE_NONE, NULL, 0x0,
698                           NULL, HFILL } },
699                 { &hf_netsync_cmd_delta_ident_id,
700                         { "Ident ID", "netsync.cmd.delta.ident_id",
701                           FT_BYTES, BASE_NONE, NULL, 0x0,
702                           NULL, HFILL } },
703                 { &hf_netsync_cmd_delta_compressed,
704                         { "Compressed", "netsync.cmd.delta.compressed",
705                           FT_UINT8, BASE_DEC, NULL, 0x0,
706                           NULL, HFILL } },
707                 { &hf_netsync_cmd_delta_payload,
708                         { "Payload", "netsync.cmd.delta.payload",
709                           FT_BYTES, BASE_NONE, NULL, 0x0,
710                           NULL, HFILL } },
711                 { &hf_netsync_cmd_refine_tree_node,
712                         { "Tree Node", "netsync.cmd.refine.tree_node",
713                           FT_BYTES, BASE_NONE, NULL, 0x0,
714                           NULL, HFILL } },
715                 { &hf_netsync_cmd_send_delta_type,
716                         { "Type", "netsync.cmd.send_delta.type",
717                           FT_UINT8, BASE_DEC, NULL, 0x0,
718                           NULL, HFILL } },
719                 { &hf_netsync_cmd_send_delta_base_id,
720                         { "Base ID", "netsync.cmd.send_delta.base_id",
721                           FT_BYTES, BASE_NONE, NULL, 0x0,
722                           NULL, HFILL } },
723                 { &hf_netsync_cmd_send_delta_ident_id,
724                         { "Ident ID", "netsync.cmd.send_delta.ident_id",
725                           FT_BYTES, BASE_NONE, NULL, 0x0,
726                           NULL, HFILL } },
727                 { &hf_netsync_cmd_nonexistent_id,
728                         { "ID", "netsync.cmd.nonexistent.id",
729                           FT_BYTES, BASE_NONE, NULL, 0x0,
730                           NULL, HFILL } },
731                 { &hf_netsync_cmd_nonexistent_type,
732                         { "Type", "netsync.cmd.nonexistent.type",
733                           FT_UINT8, BASE_DEC, NULL, 0x0,
734                           NULL, HFILL } },
735                 { &hf_netsync_cmd_done_type,
736                         { "Type", "netsync.cmd.done.type",
737                           FT_UINT8, BASE_DEC, NULL, 0x0,
738                           NULL, HFILL } }
739
740
741         };
742
743         static gint *ett[] = {
744                 &ett_netsync,
745         };
746
747         module_t *netsync_module;
748
749         proto_netsync = proto_register_protocol("Monotone Netsync", "Netsync", "netsync");
750         proto_register_field_array(proto_netsync, hf, array_length(hf));
751         proto_register_subtree_array(ett, array_length(ett));
752
753         netsync_module = prefs_register_protocol(proto_netsync,
754                                                 proto_reg_handoff_netsync);
755
756         prefs_register_uint_preference(netsync_module, "tcp_port",
757                                         "Monotone Netsync TCP Port",
758                                         "The TCP port on which Monotone Netsync packets will be sent",
759                                         10, &global_tcp_port_netsync);
760
761
762         prefs_register_bool_preference(netsync_module, "desegment_netsync_messages",
763                 "Reassemble Netsync messages spanning multiple TCP segments",
764                 "Whether the Netsync dissector should reassemble messages spanning multiple TCP segments."
765                 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
766                 &netsync_desegment);
767
768 }
769
770 void
771 proto_reg_handoff_netsync(void)
772 {
773         static dissector_handle_t netsync_handle;
774         static guint tcp_port_netsync;
775         static gboolean initialized = FALSE;
776
777         if (!initialized) {
778                 netsync_handle = create_dissector_handle(dissect_netsync, proto_netsync);
779                 initialized = TRUE;
780         } else {
781                 dissector_delete_uint("tcp.port", tcp_port_netsync, netsync_handle);
782         }
783
784         tcp_port_netsync = global_tcp_port_netsync;
785         dissector_add_uint("tcp.port", global_tcp_port_netsync, netsync_handle);
786 }
787