summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-netsync.c
blob: 25c8eaa90baf1a8d37a495bb47f118afedfc7337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/* packet-netsync.c
 * Routines for Monotone Netsync packet disassembly
 *
 * Copyright (c) 2005 by Erwin Rol <erwin@erwinrol.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1999 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

/* Include files */

#include "config.h"

#include <epan/packet.h>
#include <epan/prefs.h>
#include "packet-tcp.h"

void proto_register_netsync(void);
void proto_reg_handoff_netsync(void);

static dissector_handle_t netsync_handle;

/*
 * See
 *
 *	http://www.monotone.ca
 */

/* Define TCP ports for Monotone netsync */

#define TCP_PORT_NETSYNC 5253

#define NETSYNC_ROLE_SOURCE	1
#define NETSYNC_ROLE_SINK	2
#define NETSYNC_ROLE_BOTH	3

static const value_string netsync_role_vals[] = {
	{ NETSYNC_ROLE_SOURCE,	"Source" },
	{ NETSYNC_ROLE_SINK,	"Sink" },
	{ NETSYNC_ROLE_BOTH,	"Both" },
	{ 0,			NULL }
};


#define NETSYNC_CMD_ERROR	0
#define NETSYNC_CMD_BYE		1
#define NETSYNC_CMD_HELLO	2
#define NETSYNC_CMD_ANONYMOUS	3
#define NETSYNC_CMD_AUTH	4
#define NETSYNC_CMD_CONFIRM	5
#define NETSYNC_CMD_REFINE	6
#define NETSYNC_CMD_DONE	7
#define NETSYNC_CMD_SEND_DATA	8
#define NETSYNC_CMD_SEND_DELTA	9
#define NETSYNC_CMD_DATA	10
#define NETSYNC_CMD_DELTA	11
#define NETSYNC_CMD_NONEXISTENT	12

static const value_string netsync_cmd_vals[] = {
	{ NETSYNC_CMD_ERROR,		"Error" },
	{ NETSYNC_CMD_BYE, 		"Bye" },
	{ NETSYNC_CMD_HELLO,		"Hello" },
	{ NETSYNC_CMD_ANONYMOUS, 	"Anonymous" },
	{ NETSYNC_CMD_AUTH, 		"Auth" },
	{ NETSYNC_CMD_CONFIRM, 		"Confirm" },
	{ NETSYNC_CMD_REFINE, 		"Refine" },
	{ NETSYNC_CMD_DONE, 		"Done" },
	{ NETSYNC_CMD_SEND_DATA,	"Send Data" },
	{ NETSYNC_CMD_SEND_DELTA, 	"Send Delta" },
	{ NETSYNC_CMD_DATA,		"Data" },
	{ NETSYNC_CMD_DELTA,		"Delta" },
	{ NETSYNC_CMD_NONEXISTENT, 	"Nonexistent" },
	{ 0,				NULL }
};

#define NETSNYC_MERKLE_HASH_LENGTH 20

/* Define the monotone netsync proto */
static int proto_netsync;

static int hf_netsync_version;
static int hf_netsync_command;
static int hf_netsync_size;
static int hf_netsync_data;
static int hf_netsync_checksum;

static int hf_netsync_cmd_done_level;
static int hf_netsync_cmd_done_type;

static int hf_netsync_cmd_hello_keyname;
static int hf_netsync_cmd_hello_key;
static int hf_netsync_cmd_nonce;

static int hf_netsync_cmd_anonymous_role;
static int hf_netsync_cmd_anonymous_collection;

static int hf_netsync_cmd_send_data_type;
static int hf_netsync_cmd_send_data_id;

static int hf_netsync_cmd_error_msg;


static int hf_netsync_cmd_confirm_sig;

static int hf_netsync_cmd_auth_role;
static int hf_netsync_cmd_auth_collection;
static int hf_netsync_cmd_auth_id;
static int hf_netsync_cmd_auth_nonce1;
static int hf_netsync_cmd_auth_nonce2;
static int hf_netsync_cmd_auth_sig;

static int hf_netsync_cmd_data_type;
static int hf_netsync_cmd_data_id;
static int hf_netsync_cmd_data_compressed;
static int hf_netsync_cmd_data_payload;

static int hf_netsync_cmd_delta_type;
static int hf_netsync_cmd_delta_base_id;
static int hf_netsync_cmd_delta_ident_id;
static int hf_netsync_cmd_delta_compressed;
static int hf_netsync_cmd_delta_payload;

static int hf_netsync_cmd_refine_tree_node;

static int hf_netsync_cmd_send_delta_type;
static int hf_netsync_cmd_send_delta_base_id;
static int hf_netsync_cmd_send_delta_ident_id;

static int hf_netsync_cmd_nonexistent_type;
static int hf_netsync_cmd_nonexistent_id;

/* Define the tree for netsync */
static int ett_netsync;


/*
 * Here are the global variables associated with the preferences
 * for monotone netsync
 */

static bool netsync_desegment = true;

static int dissect_netsync_cmd_error( tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );

	proto_tree_add_item(tree, hf_netsync_cmd_error_msg, tvb,
				offset, (int)len, ENC_ASCII );
	offset += (int)len;

	return offset;
}

static int dissect_netsync_cmd_bye(tvbuff_t *tvb _U_,  int offset, proto_tree *tree _U_, unsigned size _U_)
{
	return offset;
}


static int dissect_netsync_cmd_hello(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_hello_keyname, tvb,
				offset, (int)len, ENC_ASCII );
	offset += (int)len;


	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_hello_key, tvb,
				offset, (int)len, ENC_NA );
	offset += (int)len;

	proto_tree_add_item(tree, hf_netsync_cmd_nonce, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	return offset;
}


static int dissect_netsync_cmd_anonymous(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	proto_tree_add_item(tree, hf_netsync_cmd_anonymous_role, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_anonymous_collection, tvb,
				offset, (int)len, ENC_ASCII );
	offset += (int)len;

	proto_tree_add_item(tree, hf_netsync_cmd_nonce, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	return offset;
}


static int dissect_netsync_cmd_auth(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	proto_tree_add_item(tree, hf_netsync_cmd_auth_role, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;


	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_auth_collection, tvb,
				offset, (int)len, ENC_ASCII );
	offset += (int)len;

	proto_tree_add_item(tree, hf_netsync_cmd_auth_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	offset += (int)len;

	proto_tree_add_item(tree, hf_netsync_cmd_auth_nonce1, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	offset += (int)len;

	proto_tree_add_item(tree, hf_netsync_cmd_auth_nonce2, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_auth_sig, tvb,
				offset, (int)len, ENC_NA );
	offset += (int)len;

	return offset;
}


static int dissect_netsync_cmd_confirm(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_confirm_sig, tvb,
				offset, (int)len, ENC_NA );
	offset += (int)len;


	return offset;
}


static int dissect_netsync_cmd_refine(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size)
{
	proto_tree_add_item(tree, hf_netsync_cmd_refine_tree_node, tvb,
				offset, size, ENC_NA );
	offset += size;

	return offset;
}


static int dissect_netsync_cmd_done(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	int bytes = 0;

	proto_tree_add_item_ret_length(tree, hf_netsync_cmd_done_level, tvb,
					offset, -1, ENC_LITTLE_ENDIAN|ENC_VARINT_PROTOBUF, &bytes);
	offset += bytes;

	proto_tree_add_item(tree, hf_netsync_cmd_done_type, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	return offset;
}


static int dissect_netsync_cmd_send_data(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	proto_tree_add_item(tree, hf_netsync_cmd_send_data_type, tvb,
					offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	proto_tree_add_item(tree, hf_netsync_cmd_send_data_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	return offset;
}


static int dissect_netsync_cmd_send_delta(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	proto_tree_add_item(tree, hf_netsync_cmd_send_delta_type, tvb,
					offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	proto_tree_add_item(tree, hf_netsync_cmd_send_delta_base_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;


	proto_tree_add_item(tree, hf_netsync_cmd_send_delta_ident_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	return offset;
}


static int dissect_netsync_cmd_data(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	proto_tree_add_item(tree, hf_netsync_cmd_data_type, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	proto_tree_add_item(tree, hf_netsync_cmd_data_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	proto_tree_add_item(tree, hf_netsync_cmd_data_compressed, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_data_payload, tvb,
				offset, (int)len, ENC_NA );
	offset += (int)len;

	return offset;
}


static int dissect_netsync_cmd_delta(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	uint64_t len = 0;

	proto_tree_add_item(tree, hf_netsync_cmd_delta_type, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	proto_tree_add_item(tree, hf_netsync_cmd_delta_base_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	proto_tree_add_item(tree, hf_netsync_cmd_delta_ident_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	proto_tree_add_item(tree, hf_netsync_cmd_delta_compressed, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	offset += tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &len, ENC_VARINT_PROTOBUF );
	proto_tree_add_item(tree, hf_netsync_cmd_delta_payload, tvb,
				offset, (int)len, ENC_NA );
	offset += (int)len;

	return offset;
}


static int dissect_netsync_cmd_nonexistent(tvbuff_t *tvb,  int offset, proto_tree *tree, unsigned size _U_)
{
	proto_tree_add_item(tree, hf_netsync_cmd_nonexistent_type, tvb,
				offset, 1, ENC_BIG_ENDIAN );
	offset += 1;

	proto_tree_add_item(tree, hf_netsync_cmd_nonexistent_id, tvb,
				offset, NETSNYC_MERKLE_HASH_LENGTH, ENC_NA );
	offset += NETSNYC_MERKLE_HASH_LENGTH;

	return offset;
}

static unsigned
get_netsync_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
{
	uint64_t size = 0;
	unsigned   size_bytes;

	/* skip version and command */
	offset += 2;

	size_bytes = tvb_get_varint( tvb, offset, FT_VARINT_MAX_LEN, &size, ENC_VARINT_PROTOBUF );

	/* the calculated size if for the data only, this doesn't
	 * include the version (1 byte), command (1 byte),
	 * length (size_bytes bytes) and checksum (4 bytes)
	 */

	return 1 + 1 + size_bytes + (unsigned)size + 4;
}

static int
dissect_netsync_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
	int offset = 0;
	uint8_t tmp;
	uint8_t cmd, version;
	uint32_t size, size_bytes, shift;
	proto_tree *ti,*netsync_tree=NULL;

	/* Set the protocol column */
	col_set_str(pinfo->cinfo, COL_PROTOCOL, "Netsync");

	if (tree == NULL)
		return tvb_captured_length(tvb);

	while (tvb_reported_length_remaining(tvb, offset)  > 0) {
		ti = proto_tree_add_item(tree, proto_netsync, tvb, offset, -1, ENC_NA);
		netsync_tree = proto_item_add_subtree(ti, ett_netsync);

		version = tvb_get_uint8(tvb, offset);
		proto_tree_add_item(netsync_tree, hf_netsync_version, tvb,
					offset, 1, ENC_BIG_ENDIAN );
		offset += 1;

		cmd = tvb_get_uint8(tvb, offset);
		proto_tree_add_item(netsync_tree, hf_netsync_command, tvb,
					offset, 1, ENC_BIG_ENDIAN );
		offset += 1;


		/* get size */
		size = 0;
		size_bytes = 0;
		shift = 0;
		do {
			tmp = tvb_get_uint8(tvb, offset + size_bytes);
			size_bytes += 1;

			size |= (tmp & 0x7F) << shift;
			shift += 7;
		} while ((tmp & 0x80) && (shift < 32));


		proto_tree_add_uint(netsync_tree, hf_netsync_size, tvb,
				    offset, size_bytes, size );
		offset += size_bytes;

		switch (cmd) {
			case NETSYNC_CMD_DONE:
				dissect_netsync_cmd_done( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_ERROR:
				dissect_netsync_cmd_error( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_BYE:
				dissect_netsync_cmd_bye( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_HELLO:
				dissect_netsync_cmd_hello( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_ANONYMOUS:
				dissect_netsync_cmd_anonymous( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_AUTH:
				dissect_netsync_cmd_auth( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_CONFIRM:
				dissect_netsync_cmd_confirm( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_REFINE:
				dissect_netsync_cmd_refine( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_SEND_DATA:
				dissect_netsync_cmd_send_data( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_SEND_DELTA:
				dissect_netsync_cmd_send_delta( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_DATA:
				dissect_netsync_cmd_data( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_DELTA:
				dissect_netsync_cmd_delta( tvb, offset, netsync_tree, size );
				break;

			case NETSYNC_CMD_NONEXISTENT:
				dissect_netsync_cmd_nonexistent( tvb, offset, netsync_tree, size );
				break;

			default:
				proto_tree_add_item(netsync_tree, hf_netsync_data, tvb,
					offset, size, ENC_NA );
				break;
		}

		offset += size;

		proto_tree_add_checksum(netsync_tree, tvb, offset, hf_netsync_checksum,
					-1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS );
		offset += 4;


		proto_item_append_text(netsync_tree, " V%d, Cmd: %s (%d), Size: %d",
					version, val_to_str(cmd, netsync_cmd_vals, "(0x%x)"), cmd, size );

		proto_item_set_len(netsync_tree, 1+1+size_bytes+size+4);
	}

	return tvb_captured_length(tvb);
}

static int
dissect_netsync(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
	tcp_dissect_pdus(tvb, pinfo, tree, netsync_desegment, 7, get_netsync_pdu_len,
					dissect_netsync_pdu, data);
	return tvb_captured_length(tvb);
}

void
proto_register_netsync(void)
{
	static hf_register_info hf[] = {
		/* General */
		{ &hf_netsync_version,
			{ "Version", "netsync.version",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_command,
			{ "Command", "netsync.command",
			  FT_UINT8, BASE_HEX, VALS(netsync_cmd_vals), 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_size,
			{ "Size", "netsync.size",
			  FT_UINT32, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_data,
			{ "Data", "netsync.data",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_checksum,
			{ "Checksum", "netsync.checksum",
			  FT_UINT32, BASE_HEX, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_hello_keyname,
			{ "Key Name", "netsync.cmd.hello.keyname",
			  FT_STRING, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_hello_key,
			{ "Key", "netsync.cmd.hello.key",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_nonce,
			{ "Nonce", "netsync.cmd.nonce",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_anonymous_role,
			{ "Role", "netsync.cmd.anonymous.role",
			  FT_UINT8, BASE_DEC, VALS(netsync_role_vals), 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_anonymous_collection,
			{ "Collection", "netsync.cmd.anonymous.collection",
			  FT_STRING, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_confirm_sig,
			{ "Signature", "netsync.cmd.confirm.signature",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_send_data_type,
			{ "Type", "netsync.cmd.send_data.type",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_send_data_id,
			{ "ID", "netsync.cmd.send_data.id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_error_msg,
			{ "Message", "netsync.cmd.error.msg",
			  FT_STRING, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },

		{ &hf_netsync_cmd_done_level,
			{ "Level", "netsync.cmd.done.level",
			  FT_UINT32, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_auth_role,
			{ "Role", "netsync.cmd.auth.role",
			  FT_UINT8, BASE_DEC, VALS(netsync_role_vals), 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_auth_collection,
			{ "Collection", "netsync.cmd.auth.collection",
			  FT_STRING, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_auth_id,
			{ "ID", "netsync.cmd.auth.id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_auth_nonce1,
			{ "Nonce 1", "netsync.cmd.auth.nonce1",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_auth_nonce2,
			{ "Nonce 2", "netsync.cmd.auth.nonce2",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_auth_sig,
			{ "Signature", "netsync.cmd.auth.sig",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_data_type,
			{ "Type", "netsync.cmd.data.type",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_data_id,
			{ "ID", "netsync.cmd.data.id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_data_compressed,
			{ "Compressed", "netsync.cmd.data.compressed",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_data_payload,
			{ "Payload", "netsync.cmd.data.payload",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_delta_type,
			{ "Type", "netsync.cmd.delta.type",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_delta_base_id,
			{ "Base ID", "netsync.cmd.delta.base_id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_delta_ident_id,
			{ "Ident ID", "netsync.cmd.delta.ident_id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_delta_compressed,
			{ "Compressed", "netsync.cmd.delta.compressed",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_delta_payload,
			{ "Payload", "netsync.cmd.delta.payload",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_refine_tree_node,
			{ "Tree Node", "netsync.cmd.refine.tree_node",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_send_delta_type,
			{ "Type", "netsync.cmd.send_delta.type",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_send_delta_base_id,
			{ "Base ID", "netsync.cmd.send_delta.base_id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_send_delta_ident_id,
			{ "Ident ID", "netsync.cmd.send_delta.ident_id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_nonexistent_id,
			{ "ID", "netsync.cmd.nonexistent.id",
			  FT_BYTES, BASE_NONE, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_nonexistent_type,
			{ "Type", "netsync.cmd.nonexistent.type",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } },
		{ &hf_netsync_cmd_done_type,
			{ "Type", "netsync.cmd.done.type",
			  FT_UINT8, BASE_DEC, NULL, 0x0,
			  NULL, HFILL } }


	};

	static int *ett[] = {
		&ett_netsync,
	};

	module_t *netsync_module;

	proto_netsync = proto_register_protocol("Monotone Netsync", "Netsync", "netsync");
	proto_register_field_array(proto_netsync, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	netsync_module = prefs_register_protocol(proto_netsync, NULL);

	prefs_register_bool_preference(netsync_module, "desegment_netsync_messages",
		"Reassemble Netsync messages spanning multiple TCP segments",
		"Whether the Netsync dissector should reassemble messages spanning multiple TCP segments."
		" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
		&netsync_desegment);

	netsync_handle = register_dissector("netsync", dissect_netsync, proto_netsync);
}

void
proto_reg_handoff_netsync(void)
{
	dissector_add_uint_with_preference("tcp.port", TCP_PORT_NETSYNC, netsync_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */