2 * Routines for dlm3 dissection
3 * Copyright 2007, Masatake YAMATO <jet@gyve.org>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 /* This dissector supports version 3.0 of the dlm(Distributed Lock Manager)
29 Actual implementation for the protocol is in linux kernel.
30 See files under linux/fs/dlm/ */
33 * #defines are mostly copied from
34 * *.[ch] files in linux/fs/dlm/ and linux/include/linux/dlm.h
37 * -----------------------------------------------------------------------
38 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
39 ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
41 ** This copyrighted material is made available to anyone wishing to use,
42 ** modify, copy, or redistribute it subject to the terms and conditions
43 ** of the GNU General Public License v.2.
44 * -----------------------------------------------------------------------
58 #include <epan/packet.h>
59 #include <epan/prefs.h>
63 #define TCP_PORT_DLM3 21064
64 #define SCTP_PORT_DLM3 TCP_PORT_DLM3
66 #define DLM3_MAJOR_VERSION 0x00030000
67 #define DLM3_MINOR_VERSION 0x00000000
72 #define DLM3_MSG_REQUEST 1
73 #define DLM3_MSG_CONVERT 2
74 #define DLM3_MSG_UNLOCK 3
75 #define DLM3_MSG_CANCEL 4
76 #define DLM3_MSG_REQUEST_REPLY 5
77 #define DLM3_MSG_CONVERT_REPLY 6
78 #define DLM3_MSG_UNLOCK_REPLY 7
79 #define DLM3_MSG_CANCEL_REPLY 8
80 #define DLM3_MSG_GRANT 9
81 #define DLM3_MSG_BAST 10
82 #define DLM3_MSG_LOOKUP 11
83 #define DLM3_MSG_REMOVE 12
84 #define DLM3_MSG_LOOKUP_REPLY 13
85 #define DLM3_MSG_PURGE 14
87 #define DLM3_LKF_NOQUEUE 0x00000001
88 #define DLM3_LKF_CANCEL 0x00000002
89 #define DLM3_LKF_CONVERT 0x00000004
90 #define DLM3_LKF_VALBLK 0x00000008
91 #define DLM3_LKF_QUECVT 0x00000010
92 #define DLM3_LKF_IVVALBLK 0x00000020
93 #define DLM3_LKF_CONVDEADLK 0x00000040
94 #define DLM3_LKF_PERSISTENT 0x00000080
95 #define DLM3_LKF_NODLCKWT 0x00000100
96 #define DLM3_LKF_NODLCKBLK 0x00000200
97 #define DLM3_LKF_EXPEDITE 0x00000400
98 #define DLM3_LKF_NOQUEUEBAST 0x00000800
99 #define DLM3_LKF_HEADQUE 0x00001000
100 #define DLM3_LKF_NOORDER 0x00002000
101 #define DLM3_LKF_ORPHAN 0x00004000
102 #define DLM3_LKF_ALTPR 0x00008000
103 #define DLM3_LKF_ALTCW 0x00010000
104 #define DLM3_LKF_FORCEUNLOCK 0x00020000
105 #define DLM3_LKF_TIMEOUT 0x00040000
107 #define DLM3_SBF_DEMOTED 0x01
108 #define DLM3_SBF_VALNOTVALID 0x02
109 #define DLM3_SBF_ALTMODE 0x04
111 #define DLM3_IFL_USER 0x00000001
112 #define DLM3_IFL_ORPHAN 0x00000002
113 /* They may not be used in receiver side.
114 --------------------------------------
115 #define DLM3_IFL_MSTCPY 0x00010000
116 #define DLM3_IFL_RESEND 0x00020000
117 #define DLM3_IFL_DEAD 0x00040000
118 #define DLM3_IFL_OVERLAP_UNLOCK 0x00080000
119 #define DLM3_IFL_OVERLAP_CANCEL 0x00100000
120 #define DLM3_IFL_ENDOFLIFE 0x00200000
121 #define DLM3_IFL_WATCH_TIMEWARN 0x00400000
122 #define DLM3_IFL_TIMEOUT_CANCEL 0x00800000
123 #define DLM3_IFL_DEADLOCK_CANCEL 0x01000000 */
125 #define DLM3_LKSTS_WAITING 1
126 #define DLM3_LKSTS_GRANTED 2
127 #define DLM3_LKSTS_CONVERT 3
129 #define DLM3_LOCK_IV -1
130 #define DLM3_LOCK_NL 0
131 #define DLM3_LOCK_CR 1
132 #define DLM3_LOCK_CW 2
133 #define DLM3_LOCK_PR 3
134 #define DLM3_LOCK_PW 4
135 #define DLM3_LOCK_EX 5
137 #define DLM3_AST_COMP 1
138 #define DLM3_AST_BAST 2
141 /* see asm-generic/errno-base.h about LINUX_* */
142 #define LINUX_EAGAIN 11
143 #define LINUX_ENOMEM 12
144 #define LINUX_INVAL 22
146 #define DLM3_ECANCEL 0x10001
147 #define DLM3_EUNLOCK 0x10002
150 #define DLM3_RCOM_STATUS 1
151 #define DLM3_RCOM_NAMES 2
152 #define DLM3_RCOM_LOOKUP 3
153 #define DLM3_RCOM_LOCK 4
154 #define DLM3_RCOM_STATUS_REPLY 5
155 #define DLM3_RCOM_NAMES_REPLY 6
156 #define DLM3_RCOM_LOOKUP_REPLY 7
157 #define DLM3_RCOM_LOCK_REPLY 8
159 #define DLM3_RS_NODES 0x00000001
160 #define DLM3_RS_NODES_ALL 0x00000002
161 #define DLM3_RS_DIR 0x00000004
162 #define DLM3_RS_DIR_ALL 0x00000008
163 #define DLM3_RS_LOCKS 0x00000010
164 #define DLM3_RS_LOCKS_ALL 0x00000020
165 #define DLM3_RS_DONE 0x00000040
166 #define DLM3_RS_DONE_ALL 0x00000080
168 #define DLM3_RESNAME_MAXLEN 64
170 /* Forward declaration we need below */
171 void proto_reg_handoff_dlm3(void);
174 /* Initialize the protocol and registered fields */
175 static int proto_dlm3 = -1;
177 /* fields for struct dlm_header(h) */
178 static int hf_dlm3_h_version = -1;
179 static int hf_dlm3_h_major_version = -1;
180 static int hf_dlm3_h_minor_version = -1;
181 static int hf_dlm3_h_lockspace = -1;
182 static int hf_dlm3_h_nodeid = -1;
183 static int hf_dlm3_h_length = -1;
184 static int hf_dlm3_h_cmd = -1;
185 static int hf_dlm3_h_pad = -1;
187 /* fields for struct dlm_message(m) */
188 static int hf_dlm3_m_type = -1;
189 static int hf_dlm3_m_nodeid = -1;
190 static int hf_dlm3_m_pid = -1;
191 static int hf_dlm3_m_lkid = -1;
192 static int hf_dlm3_m_remid = -1;
193 static int hf_dlm3_m_parent_lkid = -1;
194 static int hf_dlm3_m_parent_remid = -1;
196 /* bit fields for dlm_message::exflags */
197 #define DLM3_DEFINE_HF_EXFLAGS(NAME) \
198 static int hf_dlm3_##NAME = -1; \
199 static int hf_dlm3_##NAME##_noqueue = -1; \
200 static int hf_dlm3_##NAME##_cancel = -1; \
201 static int hf_dlm3_##NAME##_convert = -1; \
202 static int hf_dlm3_##NAME##_valblk = -1; \
203 static int hf_dlm3_##NAME##_quecvt = -1; \
204 static int hf_dlm3_##NAME##_ivvalblk = -1; \
205 static int hf_dlm3_##NAME##_convdeadlk = -1; \
206 static int hf_dlm3_##NAME##_persistent = -1; \
207 static int hf_dlm3_##NAME##_nodlckwt = -1; \
208 static int hf_dlm3_##NAME##_nodlckblk = -1; \
209 static int hf_dlm3_##NAME##_expedite = -1; \
210 static int hf_dlm3_##NAME##_noqueuebast = -1; \
211 static int hf_dlm3_##NAME##_headque = -1; \
212 static int hf_dlm3_##NAME##_noorder = -1; \
213 static int hf_dlm3_##NAME##_orphan = -1; \
214 static int hf_dlm3_##NAME##_altpr = -1; \
215 static int hf_dlm3_##NAME##_altcw = -1; \
216 static int hf_dlm3_##NAME##_forceunlock = -1; \
217 static int hf_dlm3_##NAME##_timeout = -1
218 DLM3_DEFINE_HF_EXFLAGS(m_exflags);
220 /* bit fields for dlm_message::sbflags */
221 static int hf_dlm3_m_sbflags = -1;
222 static int hf_dlm3_m_sbflags_demoted = -1;
223 static int hf_dlm3_m_sbflags_valnotvalid = -1;
224 static int hf_dlm3_m_sbflags_altmode = -1;
226 /* bit fields for dlm_message::flags */
227 #define DLM3_DEFINE_HF_FLAGS(NAME) \
228 static int hf_dlm3_##NAME = -1; \
229 static int hf_dlm3_##NAME##_user = -1; \
230 static int hf_dlm3_##NAME##_orphan = -1
231 DLM3_DEFINE_HF_FLAGS(m_flags);
233 static int hf_dlm3_m_lvbseq = -1;
234 static int hf_dlm3_m_hash = -1;
235 static int hf_dlm3_m_status = -1;
236 static int hf_dlm3_m_grmode = -1;
237 static int hf_dlm3_m_rqmode = -1;
238 static int hf_dlm3_m_bastmode = -1;
240 /* bit fields for dlm_message::asts */
241 #define DLM3_DEFINE_HF_ASTS(NAME) \
242 static int hf_dlm3_##NAME##_asts = -1; \
243 static int hf_dlm3_##NAME##_asts_comp = -1; \
244 static int hf_dlm3_##NAME##_asts_bast = -1
245 DLM3_DEFINE_HF_ASTS(m);
247 static int hf_dlm3_m_result = -1;
248 static int hf_dlm3_m_extra = -1;
250 /* fields for struct dlm_rcom(rc) */
251 static int hf_dlm3_rc_type = -1;
252 static int hf_dlm3_rc_result = -1;
253 static int hf_dlm3_rc_id = -1;
254 static int hf_dlm3_rc_seq = -1;
255 static int hf_dlm3_rc_seq_reply = -1;
256 static int hf_dlm3_rc_buf = -1;
258 /* fields for struct rcom_config(rf) */
259 static int hf_dlm3_rf_lvblen = -1;
260 DLM3_DEFINE_HF_EXFLAGS(rf_lsflags);
261 static int hf_dlm3_rf_unused = -1;
263 /* fields for struct rcom_lock(rl) */
264 static int hf_dlm3_rl_ownpid = -1;
265 static int hf_dlm3_rl_lkid = -1;
266 static int hf_dlm3_rl_remid = -1;
267 static int hf_dlm3_rl_parent_lkid = -1;
268 static int hf_dlm3_rl_parent_remid = -1;
269 DLM3_DEFINE_HF_EXFLAGS(rl_exflags);
270 DLM3_DEFINE_HF_FLAGS(rl_flags);
271 static int hf_dlm3_rl_lvbseq = -1;
272 static int hf_dlm3_rl_result = -1;
273 static int hf_dlm3_rl_rqmode = -1;
274 static int hf_dlm3_rl_grmode = -1;
275 static int hf_dlm3_rl_status = -1;
276 DLM3_DEFINE_HF_ASTS(rl);
277 static int hf_dlm3_rl_wait_type = -1;
278 static int hf_dlm3_rl_namelen = -1;
279 static int hf_dlm3_rl_name = -1;
280 static int hf_dlm3_rl_name_contents = -1;
281 static int hf_dlm3_rl_name_padding = -1;
282 static int hf_dlm3_rl_lvb = -1;
284 /* Initialize the subtree pointers */
285 static gint ett_dlm3 = -1;
286 static gint ett_dlm3_version = -1;
288 static gint ett_dlm3_msg = -1;
289 static gint ett_dlm3_m_exflags = -1;
290 static gint ett_dlm3_sbflags = -1;
291 static gint ett_dlm3_m_flags = -1;
292 static gint ett_dlm3_m_asts = -1;
294 static gint ett_dlm3_rcom = -1;
295 static gint ett_dlm3_rcom_lock = -1;
296 static gint ett_dlm3_rcom_config = -1;
298 static gint ett_dlm3_rf_lsflags = -1;
299 static gint ett_dlm3_rl_exflags = -1;
300 static gint ett_dlm3_rl_flags = -1;
301 static gint ett_dlm3_rl_asts = -1;
302 static gint ett_dlm3_rl_name = -1;
305 /* configurable parameters */
306 static guint dlm3_tcp_port = TCP_PORT_DLM3;
307 static guint dlm3_sctp_port = SCTP_PORT_DLM3;
312 static const value_string dlm3_cmd[] = {
313 { DLM3_MSG, "message" },
314 { DLM3_RCOM, "recovery command" },
318 static const value_string dlm3_msg[] = {
319 { DLM3_MSG_REQUEST, "request message" },
320 { DLM3_MSG_CONVERT, "conversion message" },
321 { DLM3_MSG_UNLOCK, "unlock message" },
322 { DLM3_MSG_CANCEL, "cancel message" },
323 { DLM3_MSG_REQUEST_REPLY, "request reply" },
324 { DLM3_MSG_CONVERT_REPLY, "conversion reply" },
325 { DLM3_MSG_UNLOCK_REPLY, "unlock reply" },
326 { DLM3_MSG_CANCEL_REPLY, "cancel reply" },
327 { DLM3_MSG_GRANT, "grant message" },
328 { DLM3_MSG_BAST, "bast message" },
329 { DLM3_MSG_LOOKUP, "lookup message" },
330 { DLM3_MSG_REMOVE, "remove message" },
331 { DLM3_MSG_LOOKUP_REPLY, "lookup reply" },
332 { DLM3_MSG_PURGE, "purge orphans" },
336 static const value_string dlm3_status[] = {
337 { DLM3_LKSTS_WAITING, "waiting" },
338 { DLM3_LKSTS_GRANTED, "granted" },
339 { DLM3_LKSTS_CONVERT, "convert" },
343 static const value_string dlm3_mode[] = {
344 { DLM3_LOCK_IV, "invalid" },
345 { DLM3_LOCK_NL, "null" },
346 { DLM3_LOCK_CR, "concurrent read" },
347 { DLM3_LOCK_CW, "concurrent write" },
348 { DLM3_LOCK_PR, "protected read" },
349 { DLM3_LOCK_PW, "protected write" },
350 { DLM3_LOCK_EX, "exclusive" },
354 static const value_string dlm3_result[] = {
355 { -LINUX_EAGAIN, "blocked" },
356 { -LINUX_ENOMEM, "no memory" },
357 { -LINUX_INVAL, "invalid parameters" },
358 { -DLM3_ECANCEL, "cancel completed successfully" },
359 { -DLM3_EUNLOCK, "unlock request was successful" },
364 static const value_string dlm3_rcom[] = {
365 { DLM3_RCOM_STATUS, "status command" },
366 { DLM3_RCOM_NAMES, "names command" },
367 { DLM3_RCOM_LOOKUP, "lookup command" },
368 { DLM3_RCOM_LOCK, "lock command" },
369 { DLM3_RCOM_STATUS_REPLY, "status reply" },
370 { DLM3_RCOM_NAMES_REPLY, "names reply" },
371 { DLM3_RCOM_LOOKUP_REPLY, "lookup reply" },
372 { DLM3_RCOM_LOCK_REPLY, "lock reply" },
376 static const value_string dlm3_rs[] = {
377 { DLM3_RS_NODES, "recovering nodes" },
378 { DLM3_RS_NODES_ALL, "recovering all nodes" },
379 { DLM3_RS_DIR, "recovering resource directory" },
380 { DLM3_RS_DIR_ALL, "recovering all resource directories" },
381 { DLM3_RS_LOCKS, "recovering lock" },
382 { DLM3_RS_LOCKS_ALL, "recovering all locks" },
383 { DLM3_RS_DONE, "recovering is done" },
384 { DLM3_RS_DONE_ALL, "all recovering is done" },
391 #define DLM3_DEFINE_EXFLAGS_FIELDS(NAME) \
392 static const int* NAME##_fields[] = { \
393 &hf_dlm3_##NAME##_timeout , \
394 &hf_dlm3_##NAME##_forceunlock , \
395 &hf_dlm3_##NAME##_altcw , \
396 &hf_dlm3_##NAME##_altpr , \
397 &hf_dlm3_##NAME##_orphan , \
398 &hf_dlm3_##NAME##_noorder , \
399 &hf_dlm3_##NAME##_headque , \
400 &hf_dlm3_##NAME##_noqueuebast , \
401 &hf_dlm3_##NAME##_expedite , \
402 &hf_dlm3_##NAME##_nodlckblk , \
403 &hf_dlm3_##NAME##_nodlckwt , \
404 &hf_dlm3_##NAME##_persistent , \
405 &hf_dlm3_##NAME##_convdeadlk , \
406 &hf_dlm3_##NAME##_ivvalblk , \
407 &hf_dlm3_##NAME##_quecvt , \
408 &hf_dlm3_##NAME##_valblk , \
409 &hf_dlm3_##NAME##_convert , \
410 &hf_dlm3_##NAME##_cancel , \
411 &hf_dlm3_##NAME##_noqueue , \
414 DLM3_DEFINE_EXFLAGS_FIELDS(m_exflags);
416 static const int *m_sbflags_fields[] = {
417 &hf_dlm3_m_sbflags_altmode ,
418 &hf_dlm3_m_sbflags_valnotvalid ,
419 &hf_dlm3_m_sbflags_demoted ,
423 #define DLM3_DEFINE_FLAGS_FIELDS(NAME) \
424 static const int* NAME##_fields[] = { \
425 &hf_dlm3_##NAME##_orphan , \
426 &hf_dlm3_##NAME##_user , \
429 DLM3_DEFINE_FLAGS_FIELDS(m_flags);
431 #define DLM3_DEFINE_ASTS_FIELDS(NAME) \
432 static const int* NAME##_asts_fields[] = { \
433 &hf_dlm3_##NAME##_asts_bast , \
434 &hf_dlm3_##NAME##_asts_comp , \
437 DLM3_DEFINE_ASTS_FIELDS(m);
439 DLM3_DEFINE_EXFLAGS_FIELDS(rf_lsflags);
441 DLM3_DEFINE_EXFLAGS_FIELDS(rl_exflags);
442 DLM3_DEFINE_FLAGS_FIELDS(rl_flags);
443 DLM3_DEFINE_ASTS_FIELDS(rl);
445 /* Code to actually dissect the packets */
447 dissect_dlm3_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
448 guint length, int offset)
451 proto_item *sub_item;
453 m_type = tvb_get_letohl(tvb, offset);
454 proto_tree_add_uint(tree,
455 hf_dlm3_m_type, tvb, offset, 4, m_type);
456 if (check_col(pinfo->cinfo, COL_INFO))
457 col_append_fstr(pinfo->cinfo, COL_INFO,
464 proto_tree_add_item(tree,
465 hf_dlm3_m_nodeid, tvb, offset, 4, TRUE);
468 proto_tree_add_item(tree,
469 hf_dlm3_m_pid, tvb, offset, 4, TRUE);
472 proto_tree_add_item(tree,
473 hf_dlm3_m_lkid, tvb, offset, 4, TRUE);
474 /* TODO: See `create_lkb'
475 lkid has some structure. We dissect more. */
478 proto_tree_add_item(tree,
479 hf_dlm3_m_remid, tvb, offset, 4, TRUE);
482 proto_tree_add_item(tree,
483 hf_dlm3_m_parent_lkid, tvb, offset, 4, TRUE);
486 proto_tree_add_item(tree,
487 hf_dlm3_m_parent_remid, tvb, offset, 4, TRUE);
490 proto_tree_add_bitmask(tree, tvb, offset,
491 hf_dlm3_m_exflags, ett_dlm3_m_exflags,
492 m_exflags_fields, TRUE);
495 proto_tree_add_bitmask(tree, tvb, offset,
496 hf_dlm3_m_sbflags, ett_dlm3_sbflags,
497 m_sbflags_fields, TRUE);
500 proto_tree_add_bitmask(tree, tvb, offset,
501 hf_dlm3_m_flags, ett_dlm3_m_flags,
502 m_flags_fields, TRUE);
505 proto_tree_add_item(tree,
506 hf_dlm3_m_lvbseq, tvb, offset, 4, TRUE);
509 proto_tree_add_item(tree,
510 hf_dlm3_m_hash, tvb, offset, 4, TRUE);
513 proto_tree_add_item(tree,
514 hf_dlm3_m_status, tvb, offset, 4, TRUE);
517 proto_tree_add_item(tree,
518 hf_dlm3_m_grmode, tvb, offset, 4, TRUE);
521 proto_tree_add_item(tree,
522 hf_dlm3_m_rqmode, tvb, offset, 4, TRUE);
525 proto_tree_add_item(tree,
526 hf_dlm3_m_bastmode, tvb, offset, 4, TRUE);
530 proto_tree_add_bitmask(tree, tvb, offset,
531 hf_dlm3_m_asts, ett_dlm3_m_asts,
532 m_asts_fields, TRUE);
534 proto_tree_add_item(tree,
535 hf_dlm3_m_result, tvb, offset, 4, TRUE);
538 if ((length - offset) > 0) {
539 sub_item = proto_tree_add_item(tree,
551 dissect_dlm3_rcom_lock(tvbuff_t *tvb, proto_tree *tree,
552 guint length, int offset)
554 proto_item *sub_item;
555 proto_tree *sub_tree;
561 if ((length - offset) < ( 4 * 8 + 4 + 1 * 4 + 2 * 2
562 + DLM3_RESNAME_MAXLEN ))
566 proto_tree_add_item(tree,
567 hf_dlm3_rl_ownpid, tvb, offset, 4, TRUE);
570 proto_tree_add_item(tree,
571 hf_dlm3_rl_lkid, tvb, offset, 4, TRUE);
574 proto_tree_add_item(tree,
575 hf_dlm3_rl_remid, tvb, offset, 4, TRUE);
578 proto_tree_add_item(tree,
579 hf_dlm3_rl_parent_lkid, tvb, offset, 4, TRUE);
582 proto_tree_add_item(tree,
583 hf_dlm3_rl_parent_remid, tvb, offset, 4, TRUE);
586 proto_tree_add_bitmask(tree, tvb, offset,
587 hf_dlm3_rl_exflags, ett_dlm3_rl_exflags,
588 rl_exflags_fields, TRUE);
589 exflags = tvb_get_letohl(tvb, offset);
593 proto_tree_add_bitmask(tree, tvb, offset,
594 hf_dlm3_rl_flags, ett_dlm3_rl_flags,
595 rl_flags_fields, TRUE);
598 proto_tree_add_item(tree,
599 hf_dlm3_rl_lvbseq, tvb, offset, 4, TRUE);
602 proto_tree_add_item(tree,
603 hf_dlm3_rl_result, tvb, offset, 4, TRUE);
606 proto_tree_add_item(tree,
607 hf_dlm3_rl_rqmode, tvb, offset, 1, TRUE);
610 proto_tree_add_item(tree,
611 hf_dlm3_rl_grmode, tvb, offset, 1, TRUE);
614 proto_tree_add_item(tree,
615 hf_dlm3_rl_status, tvb, offset, 1, TRUE);
618 proto_tree_add_bitmask(tree, tvb, offset,
619 hf_dlm3_rl_asts, ett_dlm3_rl_asts,
620 rl_asts_fields, TRUE);
623 proto_tree_add_item(tree,
624 hf_dlm3_rl_wait_type, tvb, offset, 2, TRUE);
627 namelen = tvb_get_letohs(tvb, offset);
628 proto_tree_add_uint(tree,
629 hf_dlm3_rl_namelen, tvb, offset, 2,
633 sub_item = proto_tree_add_item(tree,
634 hf_dlm3_rl_name, tvb, offset,
635 DLM3_RESNAME_MAXLEN, TRUE);
637 sub_tree = proto_item_add_subtree(sub_item,
640 proto_tree_add_item(sub_tree,
641 hf_dlm3_rl_name_contents, tvb, sub_offset,
644 sub_offset += namelen;
645 proto_tree_add_item(sub_tree,
646 hf_dlm3_rl_name_padding, tvb, sub_offset,
647 DLM3_RESNAME_MAXLEN - namelen, TRUE);
649 offset += DLM3_RESNAME_MAXLEN;
650 if (((length - offset) > 0) && (exflags & DLM3_LKF_VALBLK))
651 proto_tree_add_item(tree,
652 hf_dlm3_rl_lvb, tvb, offset,
659 dissect_dlm3_rcom_config(tvbuff_t *tvb, proto_tree *tree,
660 guint length, int offset)
662 if ((length - offset) < ( 4 + 4 + 8 ))
665 proto_tree_add_item(tree,
666 hf_dlm3_rf_lvblen, tvb, offset, 4, TRUE);
669 proto_tree_add_bitmask(tree, tvb, offset,
670 hf_dlm3_rf_lsflags, ett_dlm3_rf_lsflags,
671 rf_lsflags_fields, TRUE);
674 proto_tree_add_item(tree,
675 hf_dlm3_rf_unused, tvb, offset, 8, TRUE);
683 dissect_dlm3_rcom(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
684 guint length, int offset)
688 proto_item *sub_item;
689 proto_tree *sub_tree;
692 rc_type = tvb_get_letohl(tvb, offset);
693 proto_tree_add_uint(tree,
694 hf_dlm3_rc_type, tvb, offset, 4, rc_type);
695 if (check_col(pinfo->cinfo, COL_INFO))
696 col_append_fstr(pinfo->cinfo, COL_INFO,
703 proto_tree_add_item(tree,
704 hf_dlm3_rc_result, tvb, offset, 4, TRUE);
707 proto_tree_add_item(tree,
708 hf_dlm3_rc_id, tvb, offset, 8, TRUE);
711 proto_tree_add_item(tree,
712 hf_dlm3_rc_seq, tvb, offset, 8, TRUE);
715 proto_tree_add_item(tree,
716 hf_dlm3_rc_seq_reply, tvb, offset, 8, TRUE);
719 if ((length - offset) == 0) {
720 /* No rc_buf: Just return */
725 sub_item = proto_tree_add_item(tree,
733 if (rc_type == DLM3_RCOM_LOCK) {
734 sub_tree = proto_item_add_subtree(sub_item,
736 dissect_dlm3_rcom_lock(tvb, sub_tree, length, offset);
737 } else if (rc_type == DLM3_RCOM_STATUS_REPLY) {
738 sub_tree = proto_item_add_subtree(sub_item,
739 ett_dlm3_rcom_config);
740 dissect_dlm3_rcom_config(tvb, sub_tree, length, offset);
746 dissect_dlm3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
748 proto_item *item, *sub_item;
749 proto_tree *tree, *sub_tree;
757 /* Check that there's enough data */
758 length = tvb_length(tvb);
759 if (length < 4 + 4 + 4 + 2 + 1 + 1)
762 /* Check the protocol version */
763 h_version = tvb_get_letohl(tvb, 0);
764 if (h_version != (DLM3_MAJOR_VERSION|DLM3_MINOR_VERSION))
767 /* Check the command */
768 h_cmd = tvb_get_guint8(tvb, 4 + 4 + 4 + 2) ;
769 if ((h_cmd != DLM3_MSG) && (h_cmd != DLM3_RCOM))
772 if ((h_cmd == DLM3_MSG) && (length < ((4 + 4 + 4 + 2 + 1 + 1)
773 + (4 * 12 + 4 * 6))))
775 else if ((h_cmd == DLM3_RCOM) && (length < 4 + 4 + 8 + 8 + 8))
779 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DLM3");
782 if (check_col(pinfo->cinfo, COL_INFO))
783 col_clear(pinfo->cinfo, COL_INFO);
784 col_set_str(pinfo->cinfo, COL_INFO, "DLM3");
786 if (check_col(pinfo->cinfo, COL_INFO))
787 col_set_str(pinfo->cinfo, COL_INFO,
790 "packet-dlm3.c internal bug"));
795 item = proto_tree_add_item(parent_tree, proto_dlm3, tvb, offset,
797 tree = proto_item_add_subtree(item, ett_dlm3);
799 sub_item = proto_tree_add_uint(tree,
800 hf_dlm3_h_version, tvb, offset, 4,
802 sub_tree = proto_item_add_subtree(sub_item, ett_dlm3_version);
803 proto_tree_add_uint(sub_tree,
804 hf_dlm3_h_major_version, tvb, offset + 0, 2,
805 (h_version & 0xFFFF0000) >> 16);
806 proto_tree_add_uint(sub_tree,
807 hf_dlm3_h_minor_version, tvb, offset + 2, 2,
808 (h_version & 0x0000FFFF));
812 proto_tree_add_item(tree,
813 hf_dlm3_h_lockspace, tvb, offset, 4, TRUE);
816 proto_tree_add_item(tree,
817 hf_dlm3_h_nodeid, tvb, offset, 4, TRUE);
819 proto_tree_add_item(tree,
820 hf_dlm3_h_length, tvb, offset, 2, TRUE);
823 sub_item = proto_tree_add_uint(tree,
824 hf_dlm3_h_cmd, tvb, offset, 1, h_cmd);
827 proto_tree_add_item(tree,
828 hf_dlm3_h_pad, tvb, offset, 1, TRUE);
832 if (h_cmd == DLM3_MSG) {
833 sub_tree = proto_item_add_subtree(sub_item, ett_dlm3_msg);
834 dissect_dlm3_msg(tvb, pinfo, sub_tree, length, offset);
835 } else if (h_cmd== DLM3_RCOM) {
836 sub_tree = proto_item_add_subtree(sub_item, ett_dlm3_rcom);
837 dissect_dlm3_rcom(tvb, pinfo, sub_item, length, offset);
840 return tvb_length(tvb);
844 /* Register the protocol with Wireshark */
846 #define DLM3_REGISTER_HF_LOCKID(NAME) \
847 { &hf_dlm3_##NAME##_lkid, \
848 { "Lock ID on Sender", "dlm3." #NAME ".lkid", \
849 FT_UINT32, BASE_DEC_HEX, NULL, 0x0, \
851 { &hf_dlm3_##NAME##_remid, \
852 { "Lock ID on Receiver", "dlm3." #NAME ".remid", \
853 FT_UINT32, BASE_DEC_HEX, NULL, 0x0, \
855 { &hf_dlm3_##NAME##_parent_lkid, \
856 { "Parent Lock ID on Sender", "dlm3." #NAME ".parent_lkid", \
857 FT_UINT32, BASE_DEC_HEX, NULL, 0x0, \
859 { &hf_dlm3_##NAME##_parent_remid, \
860 { "Parent Lock ID on Receiver", "dlm3." #NAME ".parent_remid", \
861 FT_UINT32, BASE_DEC_HEX, NULL, 0x0, \
864 #define DLM3_REGISTER_HF_EXFLAGS(SYMNAME,STRNAME) \
865 { &hf_dlm3_##SYMNAME, \
866 { "External Flags", "dlm3." STRNAME "", \
867 FT_UINT32, BASE_HEX, NULL, 0x0, \
869 { &hf_dlm3_##SYMNAME##_noqueue, \
870 { "Don't queue", "dlm3." STRNAME ".noqueue", \
871 FT_BOOLEAN, 32, NULL, DLM3_LKF_NOQUEUE, \
873 { &hf_dlm3_##SYMNAME##_cancel, \
874 { "Cancel", "dlm3." STRNAME ".cancel", \
875 FT_BOOLEAN, 32, NULL, DLM3_LKF_CANCEL, \
877 { &hf_dlm3_##SYMNAME##_convert, \
878 { "Convert", "dlm3." STRNAME ".convert", \
879 FT_BOOLEAN, 32, NULL, DLM3_LKF_CONVERT, \
881 { &hf_dlm3_##SYMNAME##_valblk, \
882 { "Return the contents of the lock value block", "dlm3." STRNAME ".valblk", \
883 FT_BOOLEAN, 32, NULL, DLM3_LKF_VALBLK, \
885 { &hf_dlm3_##SYMNAME##_quecvt, \
886 { "Force a conversion request to be queued", "dlm3." STRNAME ".quecvt", \
887 FT_BOOLEAN, 32, NULL, DLM3_LKF_QUECVT, \
889 { &hf_dlm3_##SYMNAME##_ivvalblk, \
890 { "Invalidate the lock value block", "dlm3." STRNAME ".ivvalblk", \
891 FT_BOOLEAN, 32, NULL, DLM3_LKF_IVVALBLK, \
893 { &hf_dlm3_##SYMNAME##_convdeadlk, \
894 { "Forced down to NL to resolve a conversion deadlock", "dlm3." STRNAME ".convdeadlk", \
895 FT_BOOLEAN, 32, NULL, DLM3_LKF_CONVDEADLK, \
897 { &hf_dlm3_##SYMNAME##_persistent, \
898 { "Persistent", "dlm3." STRNAME ".persistent", \
899 FT_BOOLEAN, 32, NULL, DLM3_LKF_PERSISTENT, \
901 { &hf_dlm3_##SYMNAME##_nodlckwt, \
902 { "Don't cancel the lock if it gets into conversion deadlock", "dlm3." STRNAME ".nodlckwt", \
903 FT_BOOLEAN, 32, NULL, DLM3_LKF_NODLCKWT, \
905 { &hf_dlm3_##SYMNAME##_nodlckblk, \
906 { "Nodlckblk", "dlm3." STRNAME ".nodlckblk", \
907 FT_BOOLEAN, 32, NULL, DLM3_LKF_NODLCKBLK, \
909 { &hf_dlm3_##SYMNAME##_expedite, \
910 { "Grant a NL lock immediately", "dlm3." STRNAME ".expedite", \
911 FT_BOOLEAN, 32, NULL, DLM3_LKF_EXPEDITE, \
913 { &hf_dlm3_##SYMNAME##_noqueuebast, \
914 { "Send blocking ASTs even for NOQUEUE operations", "dlm3." STRNAME ".noqueuebast", \
915 FT_BOOLEAN, 32, NULL, DLM3_LKF_NOQUEUEBAST, \
917 { &hf_dlm3_##SYMNAME##_headque, \
918 { "Add a lock to the head of the queue", "dlm3." STRNAME ".headque", \
919 FT_BOOLEAN, 32, NULL, DLM3_LKF_HEADQUE, \
921 { &hf_dlm3_##SYMNAME##_noorder, \
922 { "Disregard the standard grant order rules", "dlm3." STRNAME ".noorder", \
923 FT_BOOLEAN, 32, NULL, DLM3_LKF_NOORDER, \
925 { &hf_dlm3_##SYMNAME##_orphan, \
926 { "Orphan", "dlm3." STRNAME ".orphan", \
927 FT_BOOLEAN, 32, NULL, DLM3_LKF_ORPHAN, \
929 { &hf_dlm3_##SYMNAME##_altpr, \
930 { "Try to grant the lock in `protected read' mode", "dlm3." STRNAME ".altpr", \
931 FT_BOOLEAN, 32, NULL, DLM3_LKF_ALTPR, \
933 { &hf_dlm3_##SYMNAME##_altcw, \
934 { "Try to grant the lock in `concurrent read' mode", "dlm3." STRNAME ".altcw", \
935 FT_BOOLEAN, 32, NULL, DLM3_LKF_ALTCW, \
937 { &hf_dlm3_##SYMNAME##_forceunlock, \
938 { "Force unlock", "dlm3." STRNAME ".forceunlock", \
939 FT_BOOLEAN, 32, NULL, DLM3_LKF_FORCEUNLOCK, \
941 { &hf_dlm3_##SYMNAME##_timeout, \
942 { "Timeout", "dlm3." STRNAME ".timeout", \
943 FT_BOOLEAN, 32, NULL, DLM3_LKF_TIMEOUT, \
947 #define DLM3_REGISTER_HF_FLAGS(SYMNAME,STRNAME) \
948 { &hf_dlm3_##SYMNAME, \
949 { "Internal Flags", "dlm3." STRNAME, \
950 FT_UINT32, BASE_HEX, NULL, 0x0, \
952 { &hf_dlm3_##SYMNAME##_user, \
953 { "User space lock realted", "dlm3." STRNAME ".user", \
954 FT_BOOLEAN, 32, NULL, DLM3_IFL_USER, \
956 { &hf_dlm3_##SYMNAME##_orphan, \
957 { "Orphaned lock", "dlm3." STRNAME ".orphan", \
958 FT_BOOLEAN, 32, NULL, DLM3_IFL_ORPHAN, \
961 #define DLM3_REGISTER_HF_ASTS(NAME,SIZE) \
962 { &hf_dlm3_##NAME##_asts, \
963 { "Asynchronous Traps", "dlm3." #NAME ".asts", \
964 FT_UINT##SIZE, BASE_HEX, NULL, 0x0, \
966 { &hf_dlm3_##NAME##_asts_comp, \
967 { "Completion", "dlm3." #NAME ".asts.comp", \
968 FT_BOOLEAN, SIZE, NULL, DLM3_AST_COMP, \
970 { &hf_dlm3_##NAME##_asts_bast, \
971 { "Blocking", "dlm3." #NAME ".asts.bast", \
972 FT_BOOLEAN, SIZE, NULL, DLM3_AST_BAST, \
976 proto_register_dlm3(void)
978 module_t *dlm3_module;
981 static hf_register_info hf[] = {
983 { &hf_dlm3_h_version,
984 { "Version", "dlm3.h.version",
985 FT_UINT32, BASE_HEX, NULL, 0x0,
987 { &hf_dlm3_h_major_version,
988 { "Major Version", "dlm3.h.major_version",
989 FT_UINT16, BASE_HEX, NULL, 0x0,
991 { &hf_dlm3_h_minor_version,
992 { "Minor Version", "dlm3.h.minor_version",
993 FT_UINT16, BASE_HEX, NULL, 0x0,
995 { &hf_dlm3_h_lockspace,
996 { "Lockspace Global ID", "dlm3.h.lockspac",
997 FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1000 { "Sender Node ID", "dlm3.h.nodeid",
1001 FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1003 { &hf_dlm3_h_length,
1004 { "Length", "dlm3.h.length",
1005 FT_UINT16, BASE_DEC, NULL, 0x0,
1008 { "Command", "dlm3.h.cmd",
1009 FT_UINT8, BASE_DEC, VALS(dlm3_cmd), 0x0,
1012 { "Padding", "dlm3.h.pad",
1013 FT_UINT8, BASE_DEC, NULL, 0x0,
1018 { "Message Type", "dlm3.m.type",
1019 FT_UINT32, BASE_DEC, VALS(dlm3_msg), 0x0,
1021 { &hf_dlm3_m_nodeid,
1022 { "Receiver Node ID", "dlm3.m.nodeid",
1023 FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1026 { "Process ID of Lock Owner", "dlm3.m.pid",
1027 FT_UINT32, BASE_DEC, NULL, 0x0,
1029 DLM3_REGISTER_HF_LOCKID(m),
1031 /* dlm_message::exflags */
1032 DLM3_REGISTER_HF_EXFLAGS(m_exflags, "m.exflags"),
1034 /* dlm_message::sbflags */
1035 { &hf_dlm3_m_sbflags,
1036 { "Status Block Flags", "dlm3.m.sbflags",
1037 FT_UINT32, BASE_HEX, NULL, 0x0,
1039 { &hf_dlm3_m_sbflags_demoted,
1040 { "Demoted for deadlock resolution", "dlm3.m.sbflags.demoted",
1041 FT_BOOLEAN, 32, NULL, DLM3_SBF_DEMOTED,
1043 { &hf_dlm3_m_sbflags_valnotvalid,
1044 { "Lock Value Block Is Invalid", "dlm3.m.sbflags.valnotvalid",
1045 FT_BOOLEAN, 32, NULL, DLM3_SBF_VALNOTVALID,
1047 { &hf_dlm3_m_sbflags_altmode,
1048 { "Try to Grant in Alternative Mode", "dlm3.m.sbflags.altmode",
1049 FT_BOOLEAN, 32, NULL, DLM3_SBF_ALTMODE,
1052 /* dlm_message::flags */
1053 DLM3_REGISTER_HF_FLAGS(m_flags, "m.flags"),
1055 { &hf_dlm3_m_lvbseq,
1056 { "Lock Value Block Sequence Number", "dlm3.m.lvbseq",
1057 FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1061 { "Hash value", "dlm3.m.hash",
1062 FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1065 { &hf_dlm3_m_status,
1066 { "Status", "dlm3.m.status",
1067 FT_INT32, BASE_DEC, VALS(dlm3_status), 0x0,
1070 { &hf_dlm3_m_grmode,
1071 { "Granted Mode", "dlm3.m.grmode",
1072 FT_INT32, BASE_DEC, VALS(dlm3_mode), 0x0,
1074 { &hf_dlm3_m_rqmode,
1075 { "Request Mode", "dlm3.m.rqmode",
1076 FT_INT32, BASE_DEC, VALS(dlm3_mode), 0x0,
1078 { &hf_dlm3_m_bastmode,
1079 { "Mode requested by another node", "dlm3.m.bastmode",
1080 FT_INT32, BASE_DEC, VALS(dlm3_mode), 0x0,
1083 /* dlm_message::asts */
1084 DLM3_REGISTER_HF_ASTS(m, 32),
1086 { &hf_dlm3_m_result,
1087 { "Message Result(errno)", "dlm3.m.result",
1088 FT_INT32, BASE_DEC, VALS(dlm3_result), 0x0,
1091 { "Extra Message", "dlm3.m.extra",
1092 FT_BYTES, BASE_NONE, NULL, 0x0,
1097 { "Recovery Command Type", "dlm3.rc.type",
1098 FT_UINT32, BASE_DEC, VALS(dlm3_rcom), 0x0,
1100 { &hf_dlm3_rc_result,
1101 { "Recovery Command Result", "dlm3.rc.result",
1102 FT_INT32, BASE_DEC, NULL, 0x0,
1105 { "Recovery Command ID", "dlm3.rc.id",
1106 FT_UINT64, BASE_DEC, NULL, 0x0,
1109 { "Recovery Command Sequence Number of Sender", "dlm3.rc.seq",
1110 FT_UINT64, BASE_DEC, NULL, 0x0,
1112 { &hf_dlm3_rc_seq_reply,
1113 { "Recovery Command Sequence Number of Receiver", "dlm3.rc.seq_reply",
1114 FT_UINT64, BASE_DEC, NULL, 0x0,
1117 { "Recovery Buffer", "dlm3.rc.buf",
1118 FT_BYTES, BASE_NONE, NULL, 0x0,
1122 { &hf_dlm3_rf_lvblen,
1123 { "Lock Value Block Length", "dlm3.rf.lvblen",
1124 FT_UINT32, BASE_DEC, NULL, 0x0,
1127 /* rcom_config::rf_lsflags */
1128 DLM3_REGISTER_HF_EXFLAGS(rf_lsflags, "rf.lsflags"),
1130 { &hf_dlm3_rf_unused,
1131 { "Unsed area", "dlm3.rf.lsflags.unused",
1132 FT_UINT64, BASE_HEX, NULL, 0x0,
1136 { &hf_dlm3_rl_ownpid,
1137 { "Process ID of Lock Owner", "dlm3.rl.ownpid",
1138 FT_UINT32, BASE_DEC, NULL, 0x0,
1141 DLM3_REGISTER_HF_LOCKID(rl),
1142 DLM3_REGISTER_HF_EXFLAGS(rl_exflags, "rl.exflags"),
1143 DLM3_REGISTER_HF_FLAGS(rl_flags, "rl.flags"),
1145 { &hf_dlm3_rl_lvbseq,
1146 { "Lock Value Block Sequence Number", "dlm3.rl.lvbseq",
1147 FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1149 { &hf_dlm3_rl_result,
1150 { "Result of Recovering master copy", "dlm3.rl.result",
1151 FT_INT32, BASE_DEC, VALS(dlm3_result), 0x0,
1153 { &hf_dlm3_rl_rqmode,
1154 { "Request Mode", "dlm3.rl.rqmode",
1155 FT_INT8, BASE_DEC, VALS(dlm3_mode), 0x0,
1157 { &hf_dlm3_rl_grmode,
1158 { "Granted Mode", "dlm3.rl.grmode",
1159 FT_INT8, BASE_DEC, VALS(dlm3_mode), 0x0,
1161 { &hf_dlm3_rl_status,
1162 { "Status", "dlm3.rl.status",
1163 FT_INT8, BASE_DEC, VALS(dlm3_rs), 0x0,
1165 DLM3_REGISTER_HF_ASTS(rl, 8),
1167 { &hf_dlm3_rl_wait_type,
1168 { "Message Type the waiter is waiting for", "dlm3.rl.wait_type",
1169 FT_UINT16, BASE_DEC, VALS(dlm3_msg), 0x0,
1172 { &hf_dlm3_rl_namelen,
1173 { "Length of `name' field", "dlm3.rl.namelen",
1174 FT_UINT16, BASE_DEC, NULL, 0x0,
1177 { "Name of Resource", "dlm.rl.name",
1178 FT_BYTES, BASE_NONE, NULL, 0x0,
1180 { &hf_dlm3_rl_name_contents,
1181 { "Contents actually occupying `name' field", "dlm.rl.name_contents",
1182 FT_STRING, BASE_NONE, NULL, 0x0,
1184 { &hf_dlm3_rl_name_padding,
1185 { "Padding", "dlm.rl.name_padding",
1186 FT_BYTES, BASE_NONE, NULL, 0x0,
1189 { "Lock Value Block", "dlm.rl.lvb",
1190 FT_BYTES, BASE_NONE, NULL, 0x0,
1194 static gint *ett[] = {
1199 &ett_dlm3_m_exflags,
1205 &ett_dlm3_rcom_lock,
1206 &ett_dlm3_rcom_config,
1208 &ett_dlm3_rf_lsflags,
1209 &ett_dlm3_rl_exflags,
1215 proto_dlm3 = proto_register_protocol("Distributed Lock Manager",
1217 proto_register_field_array(proto_dlm3, hf, array_length(hf));
1218 proto_register_subtree_array(ett, array_length(ett));
1220 dlm3_module = prefs_register_protocol(proto_dlm3,
1221 proto_reg_handoff_dlm3);
1223 prefs_register_uint_preference(dlm3_module, "tcp.port",
1225 "Set the TCP port for Distributed Lock Manager",
1228 prefs_register_uint_preference(dlm3_module, "sctp.port",
1230 "Set the SCTP port for Distributed Lock Manager",
1237 proto_reg_handoff_dlm3(void)
1239 static gboolean dissector_registered = FALSE;
1241 static guint tcp_port;
1242 static guint sctp_port;
1244 static dissector_handle_t dlm3_tcp_handle;
1245 static dissector_handle_t dlm3_sctp_handle;
1247 if (!dissector_registered) {
1248 dlm3_sctp_handle = new_create_dissector_handle(dissect_dlm3, proto_dlm3);
1249 dlm3_tcp_handle = new_create_dissector_handle(dissect_dlm3, proto_dlm3);
1250 dissector_registered = TRUE;
1252 dissector_delete("tcp.port", tcp_port, dlm3_tcp_handle);
1253 dissector_delete("sctp.port", sctp_port, dlm3_sctp_handle);
1256 tcp_port = dlm3_tcp_port;
1257 sctp_port = dlm3_sctp_port;
1258 dissector_add("tcp.port", tcp_port, dlm3_tcp_handle);
1259 dissector_add("sctp.port", sctp_port, dlm3_sctp_handle);
1262 /* packet-dlm3.c ends here. */