-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzab.lua
More file actions
2011 lines (1743 loc) · 61.5 KB
/
zab.lua
File metadata and controls
2011 lines (1743 loc) · 61.5 KB
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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------------------------------------------------------------------------------
-- zab.lua
--
-- Works as of Wireshark v2.0.2
-- This is a Lua dissector for ZAB 1.0 validation.
-- Only the messages exchanged between the client and the server are supported.
--
-- Notice:
-- The default port is set to 2181, but keep in mind that clients can connect to
-- the Zookeeper server using any port configured in the configuration file.
--
-- Setup
-- Windows:
-- 1. Copy 'zab.lua' to somewhere in your wireshark directory. For example, C:\Program Files\Wireshark.
-- 2. Open 'init.lua' in your wireshark root directory. Comment the line 'disable_lua = true' or change it to 'disable_lua = false'.
-- Linux/MacOS
-- 1. Open/Create 'init.lua' in your Wireshark config directory, '~/.config/wireshark', with the line 'disable_lua = false'
-- 2. Copy 'zab.lua' to your plugins directory '~/.config/wireshark/plugins' (you may have to create it)
--
--------------------------------------------------------------------------------
-- TODOs:
-- SASL packets
-- Logging config and functions, and replace all prints
local DEFAULT_ZAB_PORT = 2181
local MAX_REQUEST_SIZE = 100 * 1024 * 1024
local FOUR_LETTER_WORDS = {
["conf"] = true,
["cons"] = true,
["crst"] = true,
["dump"] = true,
["envi"] = true,
["ruok"] = true,
["srst"] = true,
["srvr"] = true,
["stat"] = true,
["wchs"] = true,
["wchc"] = true,
["wchp"] = true,
["mntr"] = true
}
local FIXED_XIDS = {
[0] = "CONNECT_XID",
[-1] = "WATCH_XID",
[-2] = "PING_XID",
[-4] = "AUTH_XID",
[-8] = "SET_WATCHES_XID"
}
local opCodes = {
-- [0] = "CONNECT", unused?
[1] = "CREATE",
[2] = "DELETE",
[3] = "EXISTS",
[4] = "GETDATA",
[5] = "SETDATA",
[6] = "GETACL",
[7] = "SETACL",
[8] = "GETCHILDREN",
[9] = "SYNC",
[11] = "PING",
[12] = "GETCHILDREN2",
[13] = "CHECK",
[14] = "MULTI",
[15] = "CREATE2",
[16] = "RECONFIG",
[19] = "CREATE_CONTAINER",
[21] = "CREATE_TTL",
[-10] = "CREATESESSION",
[-11] = "CLOSE",
[100] = "SETAUTH",
[101] = "SETWATCHES"
}
local watchEventTypes = {
[-1] = "None",
[1] = "NodeCreated",
[2] = "NodeDeleted",
[3] = "NodeDataChanged",
[4] = "NodeChildrenChanged"
}
local errorCodes = {
[0] = "Success",
[-1] = "SystemZookeeperError",
[-2] = "RuntimeInconsistencyError",
[-3] = "DataInconsistencyError",
[-4] = "ConnectionLossError",
[-5] = "MarshallingError",
[-6] = "UnimplementedError",
[-7] = "OperationTimeoutError",
[-8] = "BadArgumentsError",
[-13] = "NewConfigNoQuorumError",
[-14] = "ReconfigInProcessError",
[-100] = "APIError",
[-101] = "NoNodeError",
[-102] = "NoAuthError",
[-103] = "BadVersionError",
[-108] = "NoChildrenForEphemeralsError",
[-110] = "NodeExistsError",
[-111] = "NotEmptyError",
[-112] = "SessionExpiredError",
[-113] = "InvalidCallbackError",
[-114] = "InvalidACLError",
[-115] = "AuthFailedError",
[-118] = "NotReadOnlyCallError",
[-119] = "ConnectionClosedError",
}
local f_pkt = ProtoField.none("zab.pkt", "Packet")
local f_op = ProtoField.none("zab.op", "Operation")
local f_4lw = ProtoField.string("zab.4lw", "4LW message")
local f_protoversion = ProtoField.uint64("zab.protocolversion", "Protocol Version")
local f_zxid = ProtoField.uint64("zab.zxid", "ZxID", base.HEX)
local f_zxid_epoch = ProtoField.uint32("zab.zxid.epoch", "Epoch")
local f_zxid_count = ProtoField.uint32("zab.zxid.count", "Count")
local f_czxid = ProtoField.uint64("zab.czxid", "Created ZxID", base.HEX)
local f_czxid_epoch = ProtoField.uint32("zab.czxid.epoch", "Epoch")
local f_czxid_count = ProtoField.uint32("zab.czxid.count", "Count")
local f_mzxid = ProtoField.uint64("zab.mzxid", "Last Modified ZxID", base.HEX)
local f_mzxid_epoch = ProtoField.uint32("zab.mzxid.epoch", "Epoch")
local f_mzxid_count = ProtoField.uint32("zab.mzxid.count", "Count")
local f_pzxid = ProtoField.uint64("zab.pzxid", "Last Modified Children ZxID", base.HEX)
local f_pzxid_epoch = ProtoField.uint32("zab.pzxid.epoch", "Epoch")
local f_pzxid_count = ProtoField.uint32("zab.pzxid.count", "Count")
local f_timeout = ProtoField.uint32("zab.timeout", "Timeout")
local f_session = ProtoField.uint64("zab.session", "Session ID", base.HEX)
local f_len = ProtoField.uint32("zab.length", "Length", base.INT)
local f_passwd = ProtoField.bytes("zab.passwd", "Password")
local f_xid = ProtoField.int32("zab.xid", "Transaction ID", base.INT)
local f_opCode = ProtoField.int32("zab.opcode", "OpCode", base.INT, opCodes)
local f_data = ProtoField.bytes("zab.data", "Data")
local f_path = ProtoField.string("zab.path", "Path")
local f_watch = ProtoField.bool("zab.watch", "Watch")
local f_ctime = ProtoField.uint64("zab.ctime", "Created", base.RELATIVE_TIME)
local f_mtime = ProtoField.uint64("zab.mtime", "Last Modified", base.RELATIVE_TIME)
local f_ephemeralowner = ProtoField.uint64("zab.ephemeralowner", "Ephemeral Owner", base.HEX)
local f_numchildren = ProtoField.uint64("zab.numchildren", "Number of Children")
local f_datalength = ProtoField.uint64("zab.datalength", "Data Length")
local f_done = ProtoField.bool("zab.done", "Done")
local f_err = ProtoField.int64("zab.err", "Error", base.INT, errorCodes)
local f_perms = ProtoField.int64("zab.permissions", "Permissions")
local f_authtype = ProtoField.int32("zab.authtype", "Authentication Type")
local f_scheme = ProtoField.string("zab.scheme", "Scheme")
local f_credential = ProtoField.string("zab.credential", "Credentials")
local f_flags = ProtoField.uint32("zab.flags", "Flags", base.HEX)
local f_ephemeral = ProtoField.bool("zab.ephemeral", "Ephemeral")
local f_sequence = ProtoField.bool("zab.sequence", "Sequence")
local f_container = ProtoField.bool("zab.container", "Container")
local f_ttl = ProtoField.uint64("zab.ttl", "TTL")
local f_joining = ProtoField.string("zab.joining", "Joining")
local f_leaving = ProtoField.string("zab.leaving", "Leaving")
local f_newmembers = ProtoField.string("zab.newmembers", "New Members")
local f_config_id = ProtoField.uint64("zab.config_id", "Config ID", base.HEX)
local f_version = ProtoField.uint64("zab.version", "Version")
local f_cversion = ProtoField.uint64("zab.cversion", "Child Version")
local f_aversion = ProtoField.uint64("zab.aversion", "ACL Version")
local f_readonly = ProtoField.bool("zab.readonly", "Readonly")
local f_eventtype = ProtoField.uint32("zab.eventtype", "Event Type", base.INT, watchEventTypes)
local f_count = ProtoField.uint32("zab.count", "Count")
local f_state = ProtoField.uint32("zab.state", "State")
local f_child = ProtoField.string("zab.child", "Child")
local CLIENTS = {}
local Direction = {
Client2Server = 1,
Server2Client = 2,
}
local DissRes = {
Error = false,
Client = Direction.Client2Server,
Server = Direction.Server2Client,
}
------------------------------------------------------------------------------
local function defaultDissect(buf, pkt, tree, _offset, _stat)
tree:append_text(" [NO IMPL]")
if buf:len() > 0 then
tree:add(f_data, buf)
end
return true
end
local function dispatch(table, index)
if table[index] == nil then
return defaultDissect
end
return table[index]
end
------------------------------------------------------------------------------
local function parseStat(buf)
local offset = 0
local remain = buf:len()
if offset + 8 > remain then return -1, nil end
local czxid = buf(offset, 8)
offset = offset + 8
if offset + 8 > remain then return -1, nil end
local mzxid= buf(offset, 8)
offset = offset + 8
if offset + 16 > remain then return -1, nil end
local ctime = buf(offset, 8)
local mtime = buf(offset + 8, 8)
offset = offset + 16
if offset + 12 > remain then return -1, nil end
local version = buf(offset, 4)
local cversion = buf(offset + 4, 4)
local aversion = buf(offset + 8, 4)
offset = offset + 12
if offset + 16 > remain then return -1, nil end
local ephemeralowner = buf(offset, 8)
local datalength = buf(offset + 8, 4)
local numchildren = buf(offset + 12, 4)
offset = offset + 16
if offset + 8 > remain then return -1, nil end
local pzxid = buf(offset, 8)
offset = offset + 8
return offset, {
czxid=czxid,
mzxid=mzxid,
ctime=ctime,
mtime=mtime,
version=version,
cversion=cversion,
aversion=aversion,
ephemeralowner=ephemeralowner,
datalength=datalength,
numchildren=numchildren,
pzxid=pzxid
}
end
local function reprStat(stat, tree)
local t_zxid = tree:add(f_czxid, stat.czxid)
t_zxid:add(f_czxid_epoch, stat.czxid(0, 4))
t_zxid:add(f_czxid_count, stat.czxid(4, 4))
local t_zxid = tree:add(f_mzxid, stat.mzxid)
t_zxid:add(f_mzxid_epoch, stat.mzxid(0, 4))
t_zxid:add(f_mzxid_count, stat.mzxid(4, 4))
tree:add(f_ctime, stat.ctime)
tree:add(f_mtime, stat.mtime)
tree:add(f_version, stat.version)
tree:add(f_cversion, stat.cversion)
tree:add(f_aversion, stat.aversion)
tree:add(f_ephemeralowner, stat.ephemeralowner)
tree:add(f_datalength, stat.datalength)
tree:add(f_numchildren, stat.numchildren)
local t_zxid = tree:add(f_pzxid, stat.pzxid)
t_zxid:add(f_pzxid_epoch, stat.pzxid(0, 4))
t_zxid:add(f_pzxid_count, stat.pzxid(4, 4))
end
-- Reads a string, returns length,str or 0,nil
local function parseString(buf)
local offset = 0
local remain = buf:len()
if offset + 4 > remain then return -1, nil end
local str_length = buf(offset, 4):int()
offset = offset + 4
if str_length == -1 then str_length = 0 end -- XXX: Is this correct??
if offset + str_length > remain then return -1, nil end
local str = buf(offset, str_length)
offset = offset + str_length
return offset, str
end
local function parseAcl(buf)
-- 4 bytes perms, 4 bytes scheme length, scheme
local offset = 0
local remain = buf:len()
if offset + 4 > remain then return -1, nil end
local perms = buf(offset, 4)
offset = offset + 4
local scheme_offset, scheme = parseString(buf(offset))
if scheme_offset == -1 then return -1, nil end
offset = offset + scheme_offset
local cred_offset, credential = parseString(buf(offset))
if cred_offset == -1 then return -1, nil end
offset = offset + cred_offset
return offset, {
perms=perms,
scheme=scheme,
credential=credential
}
end
local function reprAcl(acl, tree)
tree:add(f_perms, acl.perms)
tree:add(f_scheme, acl.scheme)
tree:add(f_credential, acl.credential)
end
local function parseAclsArray(buf)
local offset = 0
local remain = buf:len()
if offset + 4 > remain then return -1, nil end
local acls_count = buf(offset, 4):int()
offset = offset + 4
local acls = {}
for i = 0, acls_count - 1 do
local acl_offset, acl = parseAcl(buf(offset))
if acl_offset == -1 then return -1, nil end
offset = offset + acl_offset
table.insert(acls, acl)
end
return offset, acls
end
local function reprAclsArray(acls, tree)
for i, acl in ipairs(acls) do
reprAcl(acl, tree)
end
end
------------------------------------------------------------------------------
local function parseResult(buf)
local offset = 0
local remain = buf:len()
if offset + 8 > remain then return -1, nil end
local zxid = buf(offset, 8)
offset = offset + 8
if offset + 4 > remain then return -1, nil end
local err = buf(offset, 4)
offset = offset + 4
return offset, {
zxid=zxid,
err=err
}
end
local function reprResult(result, tree)
local t_zxid = tree:add(f_zxid, result.zxid)
t_zxid:add(f_zxid_epoch, result.zxid(0, 4))
t_zxid:add(f_zxid_count, result.zxid(4, 4))
tree:add(f_err, result.err)
end
------------------------------------------------------------------------------
-- CHECK packets
local function parseCheckRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
if offset + 4 > remain then return -1, nil end
local version = buf(offset, 4)
offset = offset + 4
return offset, {
path=path,
version=version,
}
end
local function reprCheckRequest(check_req, tree)
tree:add(f_path, check_req.path)
tree:add(f_version, check_req.version)
end
local function dissectCheckRequest(buf, pkt, tree, _state)
local offset, check_req = parseCheckRequest(buf)
if offset == -1 then return false end
tree:append_text(" [CHECK]")
reprCheckRequest(check_req, tree)
return DissRes.Client
end
local function parseCheckReply(buf)
-- Nothing to do
end
local function reprCheckReply(check_rep, tree)
-- Nothing to do
end
local function dissectCheckReply(buf, pkt, tree, _state)
-- Nothing to do
end
------------------------------------------------------------------------------
-- GETCHILDREN / GETCHILDREN2 packets
local function parseGetChildrenRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
if offset + 1 > remain then return -1, nil end
local watch = buf(offset, 1)
offset = offset + 1
return offset, {
path=path,
watch=watch,
}
end
local function dissectGetChildrenRequest(buf, pkt, tree, _state)
local offset, getchildren_req = parseGetChildrenRequest(buf)
if offset == -1 then return false end
tree:add(f_path, getchildren_req.path)
tree:add(f_watch, getchildren_req.watch)
return DissRes.Client
end
local function dissectGetChildren2Request(buf, pkt, tree, _state)
local offset, getchildren_req = parseGetChildrenRequest(buf)
if offset == -1 then return false end
tree:add(f_path, getchildren_req.path)
tree:add(f_watch, getchildren_req.watch)
return DissRes.Client
end
local function parseGetChildrenReply(buf)
local offset = 0
local remain = buf:len()
if offset + 4 > remain then return -1, nil end
local count = buf(offset, 4)
offset = offset + 4
local children = {}
for i = 0, count:int() - 1 do
local child_offset, child = parseString(buf(offset))
if child_offset == -1 then return -1, nil end
offset = offset + child_offset
table.insert(children, child)
end
return offset, {
count=count,
children=children,
}
end
local function dissectGetChildrenReply(buf, pkt, tree, _state)
local offset, getchildren_rep = parseGetChildrenReply(buf)
if offset == -1 then return false end
tree:add(f_count, getchildren_rep.count)
for i, child in ipairs(getchildren_rep.children) do
tree:add(f_child, child)
end
return DissRes.Server
end
local function parseGetChildren2Reply(buf)
local offset = 0
local remain = buf:len()
if offset + 4 > remain then return -1, nil end
local count = buf(offset, 4)
offset = offset + 4
local children = {}
for i = 0, count:uint() - 1 do
local child_offset, child = parseString(buf(offset))
if child_offset == -1 then return -1, nil end
offset = offset + child_offset
table.insert(children, child)
end
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
count=count,
children=children,
stat=stat
}
end
local function dissectGetChildren2Reply(buf, pkt, tree, _state)
local offset, getchildren2_rep = parseGetChildren2Reply(buf)
if offset == -1 then return false end
tree:add(f_count, getchildren2_rep.count)
for i, child in ipairs(getchildren2_rep.children) do
tree:add(f_child, child)
end
reprStat(getchildren2_rep.stat, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- SET ACLS packets
local function parseSetAclRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
local acls_offset, acls = parseAclsArray(buf(offset))
if acls_offset == -1 then return -1, nil end
offset = offset + acls_offset
if offset + 4 > remain then return -1, nil end
local version = buf(offset, 4)
offset = offset + 4
return offset, {
path=path,
acls=acls,
version=version,
}
end
local function dissectSetAclRequest(buf, pkt, tree, _state)
local offset, setacl_req = parseSetAclRequest(buf)
if offset == -1 then return false end
tree:add(f_path, setacl_req.path)
reprAclsArray(setacl_req.acls, tree)
tree:add(f_version, setacl_req.version)
return DissRes.Client
end
local function parseSetAclReply(buf)
local offset = 0
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
stat=stat
}
end
local function dissectSetAclReply(buf, pkt, tree, _state)
local offset, setacl_rep = parseSetAclReply(buf)
if offset == -1 then return false end
reprStat(setacl_rep.stat, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- GET ACLS packets
local function parseGetAclRequest(buf)
local offset = 0
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
return offset, {
path=path,
}
end
local function dissectGetAclRequest(buf, pkt, tree, _state)
local offset, getacl_req = parseGetAclRequest(buf)
if offset == -1 then return false end
tree:add(f_path, getacl_req.path)
return DissRes.Client
end
local function parseGetAclReply(buf)
local offset = 0
local acls_offset, acls = parseAclsArray(buf(offset))
if acls_offset == -1 then return -1, nil end
offset = offset + acls_offset
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
acls=acls,
stat=stat,
}
end
local function dissectGetAclReply(buf, pkt, tree, _state)
local offset, getacl_rep = parseGetAclReply(buf)
if offset == -1 then return false end
reprAclsArray(getacl_rep.acls, tree)
reprStat(getacl_rep.stat, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- SET DATA packets
local function parseSetDataRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
local data_offset, data = parseString(buf(offset))
if data_offset == -1 then return -1, nil end
offset = offset + data_offset
if offset + 4 > remain then return -1, nil end
local version = buf(offset, 4)
offset = offset + 4
return offset, {
path=path,
data=data,
version=version,
}
end
local function reprSetDataRequest(setdata_req, tree)
tree:add(f_path, setdata_req.path)
tree:add(f_data, setdata_req.data)
tree:add(f_version, setdata_req.version)
end
local function dissectSetDataRequest(buf, pkt, tree, _state)
local offset, setdata_req = parseSetDataRequest(buf)
if offset == -1 then return false end
reprSetDataRequest(setdata_req, tree)
return DissRes.Client
end
local function parseSetDataReply(buf)
local offset = 0
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
stat=stat
}
end
local reprSetDataReply = reprStat
local function dissectSetDataReply(buf, pkt, tree, _state)
local offset, setdata_rep = parseSetDataReply(buf)
if offset == -1 then return false end
reprSetDataReply(setdata_rep.stat, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- GET DATA packets
local function parseGetDataRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
if offset + 1 > remain then return -1, nil end
local watch = buf(offset, 1)
offset = offset + 1
return offset, {
path=path,
watch=watch,
}
end
local function dissectGetDataRequest(buf, pkt, tree, _state)
local offset, getdata_req = parseGetDataRequest(buf)
if offset == -1 then return false end
tree:add(f_path, getdata_req.path)
tree:add(f_watch, getdata_req.watch)
return DissRes.Client
end
local function parseGetDataReply(buf)
local offset = 0
local data_offset, data = parseString(buf(offset))
if data_offset == -1 then return -1, nil end
offset = offset + data_offset
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
data=data,
stat=stat
}
end
local function dissectGetDataReply(buf, pkt, tree, _state)
local offset, getdata_rep = parseGetDataReply(buf)
if offset == -1 then return false end
tree:add(f_data, getdata_rep.data)
reprStat(getdata_rep.stat, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- CLOSE packets
local function dissectCloseRequest(buf, pkt, tree, _state)
return DissRes.Client
end
local function dissectCloseReply(buf, pkt, tree, state)
-- FIXME: Do this here or in top level somehow?
-- Clear all pending requests
for i, xid in ipairs(state.xids) do
state.xids[xid] = nil
end
return DissRes.Server
end
------------------------------------------------------------------------------
-- DELETE packets
local function parseDeleteRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
if offset + 4 > remain then return -1, nil end
local version = buf(offset, 4)
offset = offset + 4
return offset, {
path=path,
version=version,
}
end
local function reprDeleteRequest(delete_req, tree)
tree:add(f_path, delete_req.path)
tree:add(f_version, delete_req.version)
end
local function dissectDeleteRequest(buf, pkt, tree, _state)
local offset, delete_req = parseDeleteRequest(buf)
if offset == -1 then return false end
reprDeleteRequest(delete_req, tree)
return DissRes.Client
end
local function parseDeleteReply(buf)
-- Nothing to parse
return 0, {}
end
local function reprDeleteReply(delete_rep, tree)
-- Nothing to repr
return
end
local function dissectDeleteReply(buf, pkt, tree, _state)
local offset, delete_rep = parseDeleteReply(buf)
if offset == -1 then return false end
return DissRes.Server
end
------------------------------------------------------------------------------
-- EXISTS packets
local function parseExistsRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
if offset + 1 > remain then return -1, nil end
local watch = buf(offset, 1)
offset = offset + 1
return offset, {
path=path,
watch=watch,
}
end
local function dissectExistsRequest(buf, pkt, tree, _state)
local offset, exists_req = parseExistsRequest(buf)
if offset == -1 then return false end
tree:add(f_path, exists_req.path)
tree:add(f_watch, exists_req.watch)
return DissRes.Client
end
local function parseExistsReply(buf)
local offset = 0
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
stat=stat,
}
end
local function dissectExistsReply(buf, pkt, tree, _state)
local offset, exists_rep = parseExistsReply(buf)
if offset == -1 then return false end
reprStat(exists_rep.stat, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- RECONFIG packets
local function parseReconfigRequest(buf)
local offset = 0
local remain = buf:len()
local joining_offset, joining = parseString(buf(offset))
if joining_offset == -1 then return -1, nil end
offset = offset + joining_offset
local leaving_offset, leaving = parseString(buf(offset))
if leaving_offset == -1 then return -1, nil end
offset = offset + leaving_offset
local new_members_offset, new_members = parseString(buf(offset))
if new_members_offset == -1 then return -1, nil end
offset = offset + new_members_offset
if offset + 8 > remain then return -1, nil end
local config_id = buf(offset, 8)
offset = offset + 8
return offset, {
joining=joining,
leaving=leaving,
new_members=new_members,
config_id=config_id,
}
end
local function reprReconfigRequest(reconfig_req, tree)
tree:add(f_joining, reconfig_req.joining)
tree:add(f_leaving, reconfig_req.leaving)
tree:add(f_newmembers, reconfig_req.new_members)
tree:add(f_config_id, reconfig_req.config_id)
end
local function dissectReconfigRequest(buf, pkt, tree, _state)
local offset, reconfig_req = parseReconfigRequest(buf)
if offset == -1 then return false end
reprReconfigRequest(reconfig_req, tree)
return DissRes.Client
end
local function parseReconfigReply(buf)
local offset = 0
local data_offset, data = parseString(buf(offset))
if data_offset == -1 then return -1, nil end
offset = offset + data_offset
local stat_offset, stat = parseStat(buf(offset))
if stat_offset == -1 then return -1, nil end
offset = offset + stat_offset
return offset, {
data=data,
stat=stat,
}
end
local function reprReconfigReply(reconfig_rep, tree)
reprStat(reconfig_rep.stat, tree)
end
local function dissectReconfigReply(buf, pkt, tree, _state)
local offset, reconfig_rep = parseReconfigReply(buf)
if offset == -1 then return false end
reprReconfigReply(reconfig_rep, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- SYNC packets
local function parseSyncRequest(buf)
local offset = 0
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
return offset, {
path=path
}
end
local function reprSyncRequest(sync_req, tree)
tree:add(f_path, sync_req.path)
end
local function dissectSyncRequest(buf, pkt, tree, _state)
local offset, sync_req = parseSyncRequest(buf)
if offset == -1 then return false end
tree:append_text(" [SYNC]")
reprSyncRequest(sync_req, tree)
return DissRes.Client
end
local function parseSyncReply(buf)
local offset = 0
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
return offset, {
path=path
}
end
local function reprSyncReply(sync_rep, tree)
tree:add(f_path, sync_rep.path)
end
local function dissectSyncReply(buf, pkt, tree, _state)
local offset, sync_rep = parseSyncReply(buf)
if offset == -1 then return false end
tree:append_text(" [SYNC REP]")
reprSyncReply(sync_rep, tree)
return DissRes.Server
end
------------------------------------------------------------------------------
-- CREATE // CREATE2 // CREATE_TTL // CREATE_CONTAINER packets
local function parseCreateRequest(buf)
local offset = 0
local remain = buf:len()
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
local data_offset, data = parseString(buf(offset))
if data_offset == -1 then return -1, nil end
offset = offset + data_offset
local acls_offset, acls = parseAclsArray(buf(offset))
if acls_offset == -1 then return -1, nil end
offset = offset + acls_offset
if offset + 4 > remain then return -1, nil end
local flags = buf(offset, 4)
offset = offset + 4
return offset, {
path=path,
data=data,
acls=acls,
flags=flags,
}
end
local function reprCreateRequest(create_req, tree)
tree:add(f_path, create_req.path)
tree:add(f_data, create_req.data)
reprAclsArray(create_req.acls, tree)
local t_flags = tree:add(f_flags, create_req.flags)
local ephemeral = (bit.band(create_req.flags:uint(), 0x1) == 1)
local sequence = (bit.band(create_req.flags:uint(), 0x2) == 2)
local container = (bit.band(create_req.flags:uint(), 0x4) == 4)
t_flags:add(f_ephemeral, ephemeral)
t_flags:add(f_sequence, sequence)
t_flags:add(f_container, container)
end
local function dissectCreateRequest(buf, pkt, tree, _state)
local offset, create_req = parseCreateRequest(buf)
if offset == -1 then return false end
reprCreateRequest(create_req, tree)
return DissRes.Client
end
local function parseCreateReply(buf)
local offset = 0
local path_offset, path = parseString(buf(offset))
if path_offset == -1 then return -1, nil end
offset = offset + path_offset
return offset, {
path=path
}
end