Don't guard col_set_str (COL_INFO) with col_check
[metze/wireshark/wip.git] / epan / dissectors / packet-dlm3.c
1 /* packet-dlm3.c
2  * Routines for dlm3 dissection
3  * Copyright 2007, Masatake YAMATO <jet@gyve.org>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 /* This dissector supports version 3.0 of the dlm(Distributed Lock Manager)
27    protocol
28
29    Actual implementation for the protocol is in linux kernel.
30    See files under linux/fs/dlm/ */
31
32 /*
33  * #defines are mostly copied from
34  * *.[ch] files in linux/fs/dlm/ and linux/include/linux/dlm.h
35  *
36  * dlm_internal.h:
37  * -----------------------------------------------------------------------
38  **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
39  **  Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
40  **
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  * -----------------------------------------------------------------------
45  */
46
47
48 #ifdef HAVE_CONFIG_H
49 # include "config.h"
50 #endif
51
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55
56 #include <glib.h>
57
58 #include <epan/packet.h>
59 #include <epan/prefs.h>
60
61
62
63 #define TCP_PORT_DLM3           21064
64 #define SCTP_PORT_DLM3          TCP_PORT_DLM3
65
66 #define DLM3_MAJOR_VERSION      0x00030000
67 #define DLM3_MINOR_VERSION      0x00000000
68
69 #define DLM3_MSG                1
70 #define DLM3_RCOM               2
71
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
86
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
106
107 #define DLM3_SBF_DEMOTED        0x01
108 #define DLM3_SBF_VALNOTVALID    0x02
109 #define DLM3_SBF_ALTMODE        0x04
110
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 */
124
125 #define DLM3_LKSTS_WAITING      1
126 #define DLM3_LKSTS_GRANTED      2
127 #define DLM3_LKSTS_CONVERT      3
128
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
136
137 #define DLM3_AST_COMP           1
138 #define DLM3_AST_BAST           2
139
140
141 /* see asm-generic/errno-base.h about LINUX_*  */
142 #define LINUX_EAGAIN            11
143 #define LINUX_ENOMEM            12
144 #define LINUX_INVAL             22
145
146 #define DLM3_ECANCEL            0x10001
147 #define DLM3_EUNLOCK            0x10002
148
149
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
158
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
167
168 #define DLM3_RESNAME_MAXLEN     64
169
170 /* Forward declaration we need below */
171 void proto_reg_handoff_dlm3(void);
172
173
174 /* Initialize the protocol and registered fields */
175 static int proto_dlm3 = -1;
176
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;
186
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;
195
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);
219
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;
225
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);
232
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;
239
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);
246
247 static int hf_dlm3_m_result       = -1;
248 static int hf_dlm3_m_extra        = -1;
249
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;
257
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;
262
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;
283
284 /* Initialize the subtree pointers */
285 static gint ett_dlm3         = -1;
286 static gint ett_dlm3_version = -1;
287
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;
293
294 static gint ett_dlm3_rcom        = -1;
295 static gint ett_dlm3_rcom_lock   = -1;
296 static gint ett_dlm3_rcom_config = -1;
297
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;
303
304
305 /* configurable parameters */
306 static guint dlm3_tcp_port  = TCP_PORT_DLM3;
307 static guint dlm3_sctp_port = SCTP_PORT_DLM3;
308
309 /*
310  * Value strings
311  */
312 static const value_string dlm3_cmd[] = {
313   { DLM3_MSG,  "message"          },
314   { DLM3_RCOM, "recovery command" },
315   { 0,         NULL               }
316 };
317
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"      },
333   { 0,                      NULL                 }
334 };
335
336 static const value_string dlm3_status[] = {
337   { DLM3_LKSTS_WAITING, "waiting"  },
338   { DLM3_LKSTS_GRANTED, "granted"  },
339   { DLM3_LKSTS_CONVERT, "convert"  },
340   { 0,                  NULL       }
341 };
342
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"        },
351   { 0,            NULL               }
352 };
353
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" },
360   { 0,             "successful"                    },
361   { 0,             NULL                            }
362 };
363
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"     },
373   { 0,                      NULL             }
374 };
375
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"              },
385   { 0,                 NULL                                  }
386 };
387
388 /*
389  * Fields
390  */
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     ,             \
412     NULL                                        \
413   }
414 DLM3_DEFINE_EXFLAGS_FIELDS(m_exflags);
415
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     ,
420   NULL
421 };
422
423 #define DLM3_DEFINE_FLAGS_FIELDS(NAME)          \
424   static const int* NAME##_fields[] = {         \
425     &hf_dlm3_##NAME##_orphan        ,           \
426     &hf_dlm3_##NAME##_user          ,           \
427     NULL                                        \
428   }
429 DLM3_DEFINE_FLAGS_FIELDS(m_flags);
430
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           ,     \
435     NULL                                        \
436   }
437 DLM3_DEFINE_ASTS_FIELDS(m);
438
439 DLM3_DEFINE_EXFLAGS_FIELDS(rf_lsflags);
440
441 DLM3_DEFINE_EXFLAGS_FIELDS(rl_exflags);
442 DLM3_DEFINE_FLAGS_FIELDS(rl_flags);
443 DLM3_DEFINE_ASTS_FIELDS(rl);
444
445 /* Code to actually dissect the packets */
446 static void
447 dissect_dlm3_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
448                  guint length, int offset)
449 {
450   guint32     m_type;
451   proto_item *sub_item;
452
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,
458                     ": %s",
459                     val_to_str(m_type,
460                                dlm3_msg,
461                                "Unknown"));
462
463   offset += 4;
464   proto_tree_add_item(tree,
465                       hf_dlm3_m_nodeid, tvb, offset, 4, TRUE);
466
467   offset += 4;
468   proto_tree_add_item(tree,
469                       hf_dlm3_m_pid, tvb, offset, 4, TRUE);
470
471   offset += 4;
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. */
476
477   offset += 4;
478   proto_tree_add_item(tree,
479                       hf_dlm3_m_remid, tvb, offset, 4, TRUE);
480
481   offset += 4;
482   proto_tree_add_item(tree,
483                       hf_dlm3_m_parent_lkid, tvb, offset, 4, TRUE);
484
485   offset += 4;
486   proto_tree_add_item(tree,
487                       hf_dlm3_m_parent_remid, tvb, offset, 4, TRUE);
488
489   offset += 4;
490   proto_tree_add_bitmask(tree, tvb, offset,
491                          hf_dlm3_m_exflags, ett_dlm3_m_exflags,
492                          m_exflags_fields, TRUE);
493
494   offset += 4;
495   proto_tree_add_bitmask(tree, tvb, offset,
496                          hf_dlm3_m_sbflags, ett_dlm3_sbflags,
497                          m_sbflags_fields, TRUE);
498
499   offset += 4;
500   proto_tree_add_bitmask(tree, tvb, offset,
501                          hf_dlm3_m_flags, ett_dlm3_m_flags,
502                          m_flags_fields, TRUE);
503
504   offset += 4;
505   proto_tree_add_item(tree,
506                       hf_dlm3_m_lvbseq, tvb, offset, 4, TRUE);
507
508   offset += 4;
509   proto_tree_add_item(tree,
510                       hf_dlm3_m_hash, tvb, offset, 4, TRUE);
511
512   offset += 4;
513   proto_tree_add_item(tree,
514                       hf_dlm3_m_status, tvb, offset, 4, TRUE);
515
516   offset += 4;
517   proto_tree_add_item(tree,
518                       hf_dlm3_m_grmode, tvb, offset, 4, TRUE);
519
520   offset += 4;
521   proto_tree_add_item(tree,
522                       hf_dlm3_m_rqmode, tvb, offset, 4, TRUE);
523
524   offset += 4;
525   proto_tree_add_item(tree,
526                       hf_dlm3_m_bastmode, tvb, offset, 4, TRUE);
527
528
529   offset += 4;
530   proto_tree_add_bitmask(tree, tvb, offset,
531                          hf_dlm3_m_asts, ett_dlm3_m_asts,
532                          m_asts_fields, TRUE);
533   offset += 4;
534   proto_tree_add_item(tree,
535                       hf_dlm3_m_result, tvb, offset, 4, TRUE);
536
537   offset += 4;
538   if ((length - offset) > 0) {
539     sub_item = proto_tree_add_item(tree,
540                                    hf_dlm3_m_extra,
541                                    tvb,
542                                    offset,
543                                    -1,
544                                    TRUE);
545   }
546 }
547
548
549
550 static void
551 dissect_dlm3_rcom_lock(tvbuff_t *tvb, proto_tree *tree,
552                        guint length, int offset)
553 {
554   proto_item *sub_item;
555   proto_tree *sub_tree;
556   int         sub_offset;
557   guint16     namelen;
558   guint32     exflags;
559
560
561   if ((length - offset) < ( 4 * 8 + 4 + 1 * 4 + 2 * 2
562                             + DLM3_RESNAME_MAXLEN ))
563     return;
564
565
566   proto_tree_add_item(tree,
567                       hf_dlm3_rl_ownpid, tvb, offset, 4, TRUE);
568
569   offset += 4;
570   proto_tree_add_item(tree,
571                       hf_dlm3_rl_lkid, tvb, offset, 4, TRUE);
572
573   offset += 4;
574   proto_tree_add_item(tree,
575                       hf_dlm3_rl_remid, tvb, offset, 4, TRUE);
576
577   offset += 4;
578   proto_tree_add_item(tree,
579                       hf_dlm3_rl_parent_lkid, tvb, offset, 4, TRUE);
580
581   offset += 4;
582   proto_tree_add_item(tree,
583                       hf_dlm3_rl_parent_remid, tvb, offset, 4, TRUE);
584
585   offset += 4;
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);
590
591
592   offset += 4;
593   proto_tree_add_bitmask(tree, tvb, offset,
594                          hf_dlm3_rl_flags, ett_dlm3_rl_flags,
595                          rl_flags_fields, TRUE);
596
597   offset += 4;
598   proto_tree_add_item(tree,
599                       hf_dlm3_rl_lvbseq, tvb, offset, 4, TRUE);
600
601   offset += 4;
602   proto_tree_add_item(tree,
603                       hf_dlm3_rl_result, tvb, offset, 4, TRUE);
604
605   offset += 4;
606   proto_tree_add_item(tree,
607                       hf_dlm3_rl_rqmode, tvb, offset, 1, TRUE);
608
609   offset += 1;
610   proto_tree_add_item(tree,
611                       hf_dlm3_rl_grmode, tvb, offset, 1, TRUE);
612
613   offset += 1;
614   proto_tree_add_item(tree,
615                       hf_dlm3_rl_status, tvb, offset, 1, TRUE);
616
617   offset += 1;
618   proto_tree_add_bitmask(tree, tvb, offset,
619                          hf_dlm3_rl_asts, ett_dlm3_rl_asts,
620                          rl_asts_fields, TRUE);
621
622   offset += 1;
623   proto_tree_add_item(tree,
624                       hf_dlm3_rl_wait_type, tvb, offset, 2, TRUE);
625
626   offset += 2;
627   namelen = tvb_get_letohs(tvb, offset);
628   proto_tree_add_uint(tree,
629                       hf_dlm3_rl_namelen, tvb, offset, 2,
630                       namelen);
631
632   offset += 2;
633   sub_item = proto_tree_add_item(tree,
634                                  hf_dlm3_rl_name, tvb, offset,
635                                  DLM3_RESNAME_MAXLEN, TRUE);
636
637   sub_tree = proto_item_add_subtree(sub_item,
638                                     ett_dlm3_rl_name);
639   sub_offset = offset;
640   proto_tree_add_item(sub_tree,
641                       hf_dlm3_rl_name_contents, tvb, sub_offset,
642                       namelen, TRUE);
643
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);
648
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,
653                         -1,
654                         TRUE);
655 }
656
657
658 static void
659 dissect_dlm3_rcom_config(tvbuff_t *tvb, proto_tree *tree,
660                          guint length, int offset)
661 {
662   if ((length - offset) < ( 4 + 4 + 8 ))
663     return;
664
665   proto_tree_add_item(tree,
666                       hf_dlm3_rf_lvblen, tvb, offset, 4, TRUE);
667
668   offset += 4;
669   proto_tree_add_bitmask(tree, tvb, offset,
670                          hf_dlm3_rf_lsflags, ett_dlm3_rf_lsflags,
671                          rf_lsflags_fields, TRUE);
672
673   offset += 4;
674   proto_tree_add_item(tree,
675                       hf_dlm3_rf_unused, tvb, offset, 8, TRUE);
676
677
678   offset += 8;
679   /* END */
680 }
681
682 static void
683 dissect_dlm3_rcom(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
684                   guint length, int offset)
685 {
686   guint32     rc_type;
687
688   proto_item *sub_item;
689   proto_tree *sub_tree;
690
691
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,
697                     ": %s",
698                     val_to_str(rc_type,
699                                dlm3_rcom,
700                                "Unknown"));
701
702   offset += 4;
703   proto_tree_add_item(tree,
704                       hf_dlm3_rc_result, tvb, offset, 4, TRUE);
705
706   offset += 4;
707   proto_tree_add_item(tree,
708                       hf_dlm3_rc_id, tvb, offset, 8, TRUE);
709
710   offset += 8;
711   proto_tree_add_item(tree,
712                       hf_dlm3_rc_seq, tvb, offset, 8, TRUE);
713
714   offset += 8;
715   proto_tree_add_item(tree,
716                       hf_dlm3_rc_seq_reply, tvb, offset, 8, TRUE);
717
718   offset += 8;
719   if ((length - offset) == 0) {
720     /* No rc_buf: Just return */
721     return;
722   }
723
724   /* Decode rc_buf */
725   sub_item = proto_tree_add_item(tree,
726                                  hf_dlm3_rc_buf,
727                                  tvb,
728                                  offset,
729                                  -1,
730                                  TRUE);
731
732   offset += 0;
733   if (rc_type == DLM3_RCOM_LOCK) {
734     sub_tree = proto_item_add_subtree(sub_item,
735                                       ett_dlm3_rcom_lock);
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);
741   }
742
743 }
744
745 static int
746 dissect_dlm3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
747 {
748   proto_item *item, *sub_item;
749   proto_tree *tree, *sub_tree;
750
751   int        offset;
752   guint      length;
753   guint32    h_version;
754   guint8     h_cmd;
755
756
757   /* Check that there's enough data */
758   length = tvb_length(tvb);
759   if (length < 4 + 4 + 4 + 2 + 1 + 1)
760     return 0;
761
762   /* Check the protocol version  */
763   h_version = tvb_get_letohl(tvb, 0);
764   if (h_version != (DLM3_MAJOR_VERSION|DLM3_MINOR_VERSION))
765     return 0;
766
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))
770     return 0;
771
772   if ((h_cmd == DLM3_MSG) && (length < ((4 + 4 + 4 + 2 + 1 + 1)
773                                         + (4 * 12 + 4 * 6))))
774     return 0;
775   else if ((h_cmd == DLM3_RCOM) && (length < 4 + 4 + 8 + 8 + 8))
776     return 0;
777
778
779   col_set_str(pinfo->cinfo, COL_PROTOCOL, "DLM3");
780
781
782   if (check_col(pinfo->cinfo, COL_INFO))
783     col_clear(pinfo->cinfo, COL_INFO);
784   col_set_str(pinfo->cinfo, COL_INFO, "DLM3");
785
786   if (check_col(pinfo->cinfo, COL_INFO))
787     col_set_str(pinfo->cinfo, COL_INFO,
788                 val_to_str(h_cmd,
789                            dlm3_cmd,
790                            "packet-dlm3.c internal bug"));
791
792   if (parent_tree) {
793     offset = 0;
794
795     item = proto_tree_add_item(parent_tree, proto_dlm3, tvb, offset,
796                                -1, TRUE);
797     tree = proto_item_add_subtree(item, ett_dlm3);
798
799     sub_item = proto_tree_add_uint(tree,
800                                    hf_dlm3_h_version, tvb, offset, 4,
801                                    h_version);
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));
809
810
811     offset += 4;
812     proto_tree_add_item(tree,
813                         hf_dlm3_h_lockspace, tvb, offset, 4, TRUE);
814
815     offset += 4;
816     proto_tree_add_item(tree,
817                         hf_dlm3_h_nodeid, tvb, offset, 4, TRUE);
818     offset += 4;
819     proto_tree_add_item(tree,
820                         hf_dlm3_h_length, tvb, offset, 2, TRUE);
821
822     offset += 2;
823     sub_item = proto_tree_add_uint(tree,
824                                    hf_dlm3_h_cmd, tvb, offset, 1, h_cmd);
825
826     offset += 1;
827     proto_tree_add_item(tree,
828                         hf_dlm3_h_pad, tvb, offset, 1, TRUE);
829
830
831     offset += 1;
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);
838     }
839   }
840   return tvb_length(tvb);
841 }
842
843
844 /* Register the protocol with Wireshark */
845
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,                           \
850           NULL, HFILL}},                                                \
851 { &hf_dlm3_##NAME##_remid,                                              \
852     { "Lock ID on Receiver", "dlm3." #NAME ".remid",                    \
853         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,                             \
854         NULL, HFILL}},                                                  \
855 { &hf_dlm3_##NAME##_parent_lkid,                                        \
856     { "Parent Lock ID on Sender", "dlm3." #NAME ".parent_lkid",         \
857         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,                             \
858         NULL, HFILL}},                                                  \
859 { &hf_dlm3_##NAME##_parent_remid,                                       \
860     { "Parent Lock ID on Receiver", "dlm3." #NAME ".parent_remid",      \
861         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,                             \
862         NULL, HFILL}}
863
864 #define DLM3_REGISTER_HF_EXFLAGS(SYMNAME,STRNAME)                       \
865 { &hf_dlm3_##SYMNAME,                                                   \
866   { "External Flags", "dlm3." STRNAME "",                               \
867     FT_UINT32, BASE_HEX, NULL, 0x0,                                     \
868     NULL, HFILL}},                                                      \
869 { &hf_dlm3_##SYMNAME##_noqueue,                                         \
870   { "Don't queue", "dlm3." STRNAME ".noqueue",                          \
871     FT_BOOLEAN, 32, NULL, DLM3_LKF_NOQUEUE,                             \
872     NULL, HFILL}},                                                      \
873 { &hf_dlm3_##SYMNAME##_cancel,                                          \
874   { "Cancel", "dlm3." STRNAME ".cancel",                                \
875     FT_BOOLEAN, 32, NULL, DLM3_LKF_CANCEL,                              \
876     NULL, HFILL}},                                                      \
877 { &hf_dlm3_##SYMNAME##_convert,                                         \
878   { "Convert", "dlm3." STRNAME ".convert",                              \
879     FT_BOOLEAN, 32, NULL, DLM3_LKF_CONVERT,                             \
880     NULL, HFILL}},                                                      \
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,                              \
884     NULL, HFILL}},                                                      \
885 { &hf_dlm3_##SYMNAME##_quecvt,                                          \
886   { "Force a conversion request to be queued", "dlm3." STRNAME ".quecvt", \
887     FT_BOOLEAN, 32, NULL, DLM3_LKF_QUECVT,                              \
888     NULL, HFILL}},                                                      \
889 { &hf_dlm3_##SYMNAME##_ivvalblk,                                        \
890   { "Invalidate the lock value block", "dlm3." STRNAME ".ivvalblk",     \
891     FT_BOOLEAN, 32, NULL, DLM3_LKF_IVVALBLK,                            \
892     NULL, HFILL}},                                                      \
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,                          \
896     NULL, HFILL}},                                                      \
897 { &hf_dlm3_##SYMNAME##_persistent,                                      \
898   { "Persistent", "dlm3." STRNAME ".persistent",                        \
899     FT_BOOLEAN, 32, NULL, DLM3_LKF_PERSISTENT,                          \
900     NULL, HFILL}},                                                      \
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,                            \
904     NULL, HFILL}},                                                      \
905 { &hf_dlm3_##SYMNAME##_nodlckblk,                                       \
906   { "Nodlckblk", "dlm3." STRNAME ".nodlckblk",                          \
907     FT_BOOLEAN, 32, NULL, DLM3_LKF_NODLCKBLK,                           \
908     NULL, HFILL}},                                                      \
909 { &hf_dlm3_##SYMNAME##_expedite,                                        \
910   { "Grant a NL lock immediately", "dlm3." STRNAME ".expedite",         \
911     FT_BOOLEAN, 32, NULL, DLM3_LKF_EXPEDITE,                            \
912     NULL, HFILL}},                                                      \
913 { &hf_dlm3_##SYMNAME##_noqueuebast,                                     \
914   { "Send blocking ASTs even for NOQUEUE operations", "dlm3." STRNAME ".noqueuebast", \
915     FT_BOOLEAN, 32, NULL, DLM3_LKF_NOQUEUEBAST,                         \
916     NULL, HFILL}},                                                      \
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,                             \
920     NULL, HFILL}},                                                      \
921 { &hf_dlm3_##SYMNAME##_noorder,                                         \
922   { "Disregard the standard grant order rules", "dlm3." STRNAME ".noorder", \
923     FT_BOOLEAN, 32, NULL, DLM3_LKF_NOORDER,                             \
924     NULL, HFILL}},                                                      \
925 { &hf_dlm3_##SYMNAME##_orphan,                                          \
926   { "Orphan", "dlm3." STRNAME ".orphan",                                \
927     FT_BOOLEAN, 32, NULL, DLM3_LKF_ORPHAN,                              \
928     NULL, HFILL}},                                                      \
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,                               \
932     NULL, HFILL}},                                                      \
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,                               \
936     NULL, HFILL}},                                                      \
937 { &hf_dlm3_##SYMNAME##_forceunlock,                                     \
938   { "Force unlock", "dlm3." STRNAME ".forceunlock",                     \
939     FT_BOOLEAN, 32, NULL, DLM3_LKF_FORCEUNLOCK,                         \
940     NULL, HFILL}},                                                      \
941 { &hf_dlm3_##SYMNAME##_timeout,                                         \
942   { "Timeout", "dlm3." STRNAME ".timeout",                              \
943     FT_BOOLEAN, 32, NULL, DLM3_LKF_TIMEOUT,                             \
944     NULL, HFILL}}
945
946
947 #define DLM3_REGISTER_HF_FLAGS(SYMNAME,STRNAME)         \
948 { &hf_dlm3_##SYMNAME,                                   \
949   { "Internal Flags", "dlm3." STRNAME,                  \
950     FT_UINT32, BASE_HEX, NULL, 0x0,                     \
951     NULL, HFILL}},                                      \
952 { &hf_dlm3_##SYMNAME##_user,                            \
953   { "User space lock realted", "dlm3." STRNAME ".user", \
954     FT_BOOLEAN, 32, NULL, DLM3_IFL_USER,                \
955     NULL, HFILL}},                                      \
956 { &hf_dlm3_##SYMNAME##_orphan,                          \
957   { "Orphaned lock", "dlm3." STRNAME ".orphan",         \
958     FT_BOOLEAN, 32, NULL, DLM3_IFL_ORPHAN,              \
959     NULL, HFILL}}
960
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,           \
965     NULL, HFILL}},                               \
966 { &hf_dlm3_##NAME##_asts_comp,                   \
967   { "Completion", "dlm3." #NAME ".asts.comp",    \
968     FT_BOOLEAN, SIZE, NULL, DLM3_AST_COMP,       \
969     NULL, HFILL }},                              \
970 { &hf_dlm3_##NAME##_asts_bast,                   \
971   { "Blocking", "dlm3." #NAME ".asts.bast",      \
972     FT_BOOLEAN, SIZE, NULL, DLM3_AST_BAST,       \
973     NULL, HFILL }}
974
975 void
976 proto_register_dlm3(void)
977 {
978   module_t *dlm3_module;
979
980
981   static hf_register_info hf[] = {
982     /* dlm_header */
983     { &hf_dlm3_h_version,
984       { "Version", "dlm3.h.version",
985         FT_UINT32, BASE_HEX, NULL, 0x0,
986         NULL, HFILL }},
987     { &hf_dlm3_h_major_version,
988       { "Major Version", "dlm3.h.major_version",
989         FT_UINT16, BASE_HEX, NULL, 0x0,
990         NULL, HFILL }},
991     { &hf_dlm3_h_minor_version,
992       { "Minor Version", "dlm3.h.minor_version",
993         FT_UINT16, BASE_HEX, NULL, 0x0,
994         NULL, HFILL }},
995     { &hf_dlm3_h_lockspace,
996       { "Lockspace Global ID", "dlm3.h.lockspac",
997         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
998         NULL, HFILL }},
999     { &hf_dlm3_h_nodeid,
1000       { "Sender Node ID", "dlm3.h.nodeid",
1001         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1002         NULL, HFILL }},
1003     { &hf_dlm3_h_length,
1004       { "Length", "dlm3.h.length",
1005         FT_UINT16, BASE_DEC, NULL, 0x0,
1006         NULL, HFILL }},
1007     { &hf_dlm3_h_cmd,
1008       { "Command", "dlm3.h.cmd",
1009         FT_UINT8, BASE_DEC, VALS(dlm3_cmd), 0x0,
1010         NULL, HFILL }},
1011     { &hf_dlm3_h_pad,
1012       { "Padding", "dlm3.h.pad",
1013         FT_UINT8, BASE_DEC, NULL, 0x0,
1014         NULL, HFILL }},
1015
1016     /* dlm_message */
1017     { &hf_dlm3_m_type,
1018       { "Message Type", "dlm3.m.type",
1019         FT_UINT32, BASE_DEC, VALS(dlm3_msg), 0x0,
1020         NULL, HFILL }},
1021     { &hf_dlm3_m_nodeid,
1022       { "Receiver Node ID", "dlm3.m.nodeid",
1023         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1024         NULL, HFILL }},
1025     { &hf_dlm3_m_pid,
1026       { "Process ID of Lock Owner", "dlm3.m.pid",
1027         FT_UINT32, BASE_DEC, NULL, 0x0,
1028         NULL, HFILL }},
1029     DLM3_REGISTER_HF_LOCKID(m),
1030
1031     /* dlm_message::exflags */
1032     DLM3_REGISTER_HF_EXFLAGS(m_exflags, "m.exflags"),
1033
1034     /* dlm_message::sbflags */
1035     { &hf_dlm3_m_sbflags,
1036       { "Status Block Flags", "dlm3.m.sbflags",
1037         FT_UINT32, BASE_HEX, NULL, 0x0,
1038         NULL, HFILL}},
1039     { &hf_dlm3_m_sbflags_demoted,
1040       { "Demoted for deadlock resolution", "dlm3.m.sbflags.demoted",
1041         FT_BOOLEAN, 32, NULL, DLM3_SBF_DEMOTED,
1042         NULL, HFILL}},
1043     { &hf_dlm3_m_sbflags_valnotvalid,
1044       { "Lock Value Block Is Invalid", "dlm3.m.sbflags.valnotvalid",
1045         FT_BOOLEAN, 32, NULL, DLM3_SBF_VALNOTVALID,
1046         NULL, HFILL}},
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,
1050         NULL, HFILL}},
1051
1052     /* dlm_message::flags */
1053     DLM3_REGISTER_HF_FLAGS(m_flags, "m.flags"),
1054
1055     { &hf_dlm3_m_lvbseq,
1056       { "Lock Value Block Sequence Number", "dlm3.m.lvbseq",
1057         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1058         NULL, HFILL}},
1059
1060     { &hf_dlm3_m_hash,
1061       { "Hash value", "dlm3.m.hash",
1062         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1063         NULL, HFILL}},
1064
1065     { &hf_dlm3_m_status,
1066       { "Status", "dlm3.m.status",
1067         FT_INT32, BASE_DEC, VALS(dlm3_status), 0x0,
1068         NULL, HFILL}},
1069
1070     { &hf_dlm3_m_grmode,
1071       { "Granted Mode", "dlm3.m.grmode",
1072         FT_INT32, BASE_DEC, VALS(dlm3_mode), 0x0,
1073         NULL, HFILL}},
1074     { &hf_dlm3_m_rqmode,
1075       { "Request Mode", "dlm3.m.rqmode",
1076         FT_INT32, BASE_DEC, VALS(dlm3_mode), 0x0,
1077         NULL, HFILL}},
1078     { &hf_dlm3_m_bastmode,
1079       { "Mode requested by another node", "dlm3.m.bastmode",
1080         FT_INT32, BASE_DEC, VALS(dlm3_mode), 0x0,
1081         NULL, HFILL}},
1082
1083     /* dlm_message::asts */
1084     DLM3_REGISTER_HF_ASTS(m, 32),
1085
1086     { &hf_dlm3_m_result,
1087       { "Message Result(errno)", "dlm3.m.result",
1088         FT_INT32, BASE_DEC, VALS(dlm3_result), 0x0,
1089         NULL, HFILL}},
1090     { &hf_dlm3_m_extra,
1091       { "Extra Message", "dlm3.m.extra",
1092         FT_BYTES, BASE_NONE, NULL, 0x0,
1093         NULL, HFILL}},
1094
1095     /* dlm_rcom */
1096     { &hf_dlm3_rc_type,
1097       { "Recovery Command Type", "dlm3.rc.type",
1098         FT_UINT32, BASE_DEC, VALS(dlm3_rcom), 0x0,
1099         NULL, HFILL}},
1100     { &hf_dlm3_rc_result,
1101       { "Recovery Command Result", "dlm3.rc.result",
1102         FT_INT32, BASE_DEC, NULL, 0x0,
1103         NULL, HFILL}},
1104     { &hf_dlm3_rc_id,
1105       { "Recovery Command ID", "dlm3.rc.id",
1106         FT_UINT64, BASE_DEC, NULL, 0x0,
1107         NULL, HFILL}},
1108     { &hf_dlm3_rc_seq,
1109       { "Recovery Command Sequence Number of Sender", "dlm3.rc.seq",
1110         FT_UINT64, BASE_DEC, NULL, 0x0,
1111         NULL, HFILL}},
1112     { &hf_dlm3_rc_seq_reply,
1113       { "Recovery Command Sequence Number of Receiver", "dlm3.rc.seq_reply",
1114         FT_UINT64, BASE_DEC, NULL, 0x0,
1115         NULL, HFILL}},
1116     { &hf_dlm3_rc_buf,
1117       { "Recovery Buffer", "dlm3.rc.buf",
1118         FT_BYTES, BASE_NONE, NULL, 0x0,
1119         NULL, HFILL}},
1120
1121     /* rcom_config */
1122     { &hf_dlm3_rf_lvblen,
1123       { "Lock Value Block Length", "dlm3.rf.lvblen",
1124         FT_UINT32, BASE_DEC, NULL, 0x0,
1125         NULL, HFILL}},
1126
1127     /* rcom_config::rf_lsflags */
1128     DLM3_REGISTER_HF_EXFLAGS(rf_lsflags, "rf.lsflags"),
1129
1130     { &hf_dlm3_rf_unused,
1131       { "Unsed area", "dlm3.rf.lsflags.unused",
1132         FT_UINT64, BASE_HEX, NULL, 0x0,
1133         NULL, HFILL}},
1134
1135     /* rcom_lock */
1136     { &hf_dlm3_rl_ownpid,
1137       { "Process ID of Lock Owner", "dlm3.rl.ownpid",
1138         FT_UINT32, BASE_DEC, NULL, 0x0,
1139         NULL, HFILL}},
1140
1141     DLM3_REGISTER_HF_LOCKID(rl),
1142     DLM3_REGISTER_HF_EXFLAGS(rl_exflags, "rl.exflags"),
1143     DLM3_REGISTER_HF_FLAGS(rl_flags, "rl.flags"),
1144
1145     { &hf_dlm3_rl_lvbseq,
1146       { "Lock Value Block Sequence Number", "dlm3.rl.lvbseq",
1147         FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
1148         NULL, HFILL}},
1149     { &hf_dlm3_rl_result,
1150       { "Result of Recovering master copy", "dlm3.rl.result",
1151         FT_INT32, BASE_DEC, VALS(dlm3_result), 0x0,
1152         NULL, HFILL}},
1153     { &hf_dlm3_rl_rqmode,
1154       { "Request Mode", "dlm3.rl.rqmode",
1155         FT_INT8, BASE_DEC, VALS(dlm3_mode), 0x0,
1156         NULL, HFILL}},
1157     { &hf_dlm3_rl_grmode,
1158       { "Granted Mode", "dlm3.rl.grmode",
1159         FT_INT8, BASE_DEC, VALS(dlm3_mode), 0x0,
1160         NULL, HFILL}},
1161     { &hf_dlm3_rl_status,
1162       { "Status", "dlm3.rl.status",
1163         FT_INT8, BASE_DEC, VALS(dlm3_rs), 0x0,
1164         NULL, HFILL}},
1165     DLM3_REGISTER_HF_ASTS(rl, 8),
1166
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,
1170         NULL, HFILL }},
1171
1172     { &hf_dlm3_rl_namelen,
1173       { "Length of `name' field", "dlm3.rl.namelen",
1174         FT_UINT16, BASE_DEC, NULL, 0x0,
1175         NULL, HFILL }},
1176     { &hf_dlm3_rl_name,
1177       { "Name of Resource", "dlm.rl.name",
1178         FT_BYTES, BASE_NONE, NULL, 0x0,
1179         NULL, HFILL }},
1180     { &hf_dlm3_rl_name_contents,
1181       { "Contents actually occupying `name' field", "dlm.rl.name_contents",
1182         FT_STRING, BASE_NONE, NULL, 0x0,
1183         NULL, HFILL }},
1184     { &hf_dlm3_rl_name_padding,
1185       { "Padding", "dlm.rl.name_padding",
1186         FT_BYTES, BASE_NONE, NULL, 0x0,
1187         NULL, HFILL }},
1188     { &hf_dlm3_rl_lvb,
1189       { "Lock Value Block", "dlm.rl.lvb",
1190         FT_BYTES, BASE_NONE, NULL, 0x0,
1191         NULL, HFILL }}
1192   };
1193
1194   static gint *ett[] = {
1195     &ett_dlm3,
1196     &ett_dlm3_version,
1197
1198     &ett_dlm3_msg,
1199     &ett_dlm3_m_exflags,
1200     &ett_dlm3_sbflags,
1201     &ett_dlm3_m_flags,
1202     &ett_dlm3_m_asts,
1203
1204     &ett_dlm3_rcom,
1205     &ett_dlm3_rcom_lock,
1206     &ett_dlm3_rcom_config,
1207
1208     &ett_dlm3_rf_lsflags,
1209     &ett_dlm3_rl_exflags,
1210     &ett_dlm3_rl_flags,
1211     &ett_dlm3_rl_asts,
1212     &ett_dlm3_rl_name
1213   };
1214
1215   proto_dlm3 = proto_register_protocol("Distributed Lock Manager",
1216                                        "DLM3", "dlm3");
1217   proto_register_field_array(proto_dlm3, hf, array_length(hf));
1218   proto_register_subtree_array(ett, array_length(ett));
1219
1220   dlm3_module = prefs_register_protocol(proto_dlm3,
1221                                         proto_reg_handoff_dlm3);
1222
1223   prefs_register_uint_preference(dlm3_module, "tcp.port",
1224                                  "DLM3 TCP Port",
1225                                  "Set the TCP port for Distributed Lock Manager",
1226                                  10,
1227                                  &dlm3_tcp_port);
1228   prefs_register_uint_preference(dlm3_module, "sctp.port",
1229                                  "DLM3 SCTP Port",
1230                                  "Set the SCTP port for Distributed Lock Manager",
1231                                  10,
1232                                  &dlm3_sctp_port);
1233 }
1234
1235
1236 void
1237 proto_reg_handoff_dlm3(void)
1238 {
1239   static gboolean dissector_registered = FALSE;
1240
1241   static guint tcp_port;
1242   static guint sctp_port;
1243
1244   static dissector_handle_t dlm3_tcp_handle;
1245   static dissector_handle_t dlm3_sctp_handle;
1246
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;
1251   } else {
1252     dissector_delete("tcp.port",  tcp_port,  dlm3_tcp_handle);
1253     dissector_delete("sctp.port", sctp_port, dlm3_sctp_handle);
1254   }
1255
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);
1260 }
1261
1262 /* packet-dlm3.c ends here. */