2 * Routines for nlm dissection
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * Copied from packet-mount.c
10 * 2001-JAN Ronnie Sahlberg <See AUTHORS for email>
11 * Updates to version 1 of the protocol.
12 * Added version 3 of the protocol.
13 * Added version 4 of the protocol.
16 * SPDX-License-Identifier: GPL-2.0-or-later
22 #include "packet-nfs.h"
23 #include "packet-nlm.h"
24 #include <epan/prefs.h>
26 void proto_register_nlm(void);
27 void proto_reg_handoff_nlm(void);
30 * NFS Lock Manager protocol specs can only be found in actual
31 * implementations or in the nice book:
32 * Brent Callaghan: "NFS Illustrated", Addison-Wesley, ISBN 0-201-32570-5
33 * which I use here as reference (BC).
35 * They can also be found if you go to
37 * http://www.opengroup.org/publications/catalog/c702.htm
39 * and follow the links to the HTML version of the document.
42 static int proto_nlm = -1;
43 static int hf_nlm_procedure_v1 = -1;
44 static int hf_nlm_procedure_v2 = -1;
45 static int hf_nlm_procedure_v3 = -1;
46 static int hf_nlm_procedure_v4 = -1;
47 static int hf_nlm_cookie = -1;
48 static int hf_nlm_block = -1;
49 static int hf_nlm_exclusive = -1;
50 static int hf_nlm_lock = -1;
51 static int hf_nlm_lock_caller_name = -1;
52 static int hf_nlm_lock_owner = -1;
53 static int hf_nlm_lock_svid = -1;
54 static int hf_nlm_lock_l_offset = -1;
55 static int hf_nlm_lock_l_offset64 = -1;
56 static int hf_nlm_lock_l_len = -1;
57 static int hf_nlm_lock_l_len64 = -1;
58 static int hf_nlm_reclaim = -1;
59 static int hf_nlm_stat = -1;
60 static int hf_nlm_state = -1;
61 static int hf_nlm_test_stat = -1;
62 static int hf_nlm_test_stat_stat = -1;
63 static int hf_nlm_holder = -1;
64 static int hf_nlm_share = -1;
65 static int hf_nlm_share_mode = -1;
66 static int hf_nlm_share_access = -1;
67 static int hf_nlm_share_name = -1;
68 static int hf_nlm_sequence = -1;
69 static int hf_nlm_request_in = -1;
70 static int hf_nlm_reply_in = -1;
71 static int hf_nlm_time = -1;
73 static gint ett_nlm = -1;
74 static gint ett_nlm_lock = -1;
79 * stuff to match MSG and RES packets for async NLM
82 static gboolean nlm_match_msgres = FALSE;
83 static wmem_map_t *nlm_msg_res_unmatched = NULL;
84 static wmem_map_t *nlm_msg_res_matched = NULL;
86 /* XXX when matching the packets we should really check the conversation (only address
87 NOT ports) and command type as well. I am lazy and thinks the cookie itself is
90 typedef struct _nlm_msg_res_unmatched_data {
95 } nlm_msg_res_unmatched_data;
97 typedef struct _nlm_msg_res_matched_data {
101 } nlm_msg_res_matched_data;
104 nlm_msg_res_unmatched_hash(gconstpointer k)
106 const nlm_msg_res_unmatched_data *umd = (const nlm_msg_res_unmatched_data *)k;
110 for(i=0;i<umd->cookie_len;i++){
111 hash^=umd->cookie[i];
117 nlm_msg_res_matched_hash(gconstpointer k)
119 guint hash = GPOINTER_TO_UINT(k);
125 nlm_msg_res_unmatched_equal(gconstpointer k1, gconstpointer k2)
127 const nlm_msg_res_unmatched_data *umd1 = (const nlm_msg_res_unmatched_data *)k1;
128 const nlm_msg_res_unmatched_data *umd2 = (const nlm_msg_res_unmatched_data *)k2;
130 if(umd1->cookie_len!=umd2->cookie_len){
134 return( memcmp(umd1->cookie, umd2->cookie, umd1->cookie_len) == 0);
137 nlm_msg_res_matched_equal(gconstpointer k1, gconstpointer k2)
139 guint mk1 = GPOINTER_TO_UINT(k1);
140 guint mk2 = GPOINTER_TO_UINT(k2);
146 nlm_print_msgres_reply(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
148 nlm_msg_res_matched_data *md;
150 md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
153 proto_tree_add_uint(tree, hf_nlm_request_in, tvb, 0, 0, md->req_frame);
154 nstime_delta(&ns, &pinfo->abs_ts, &md->ns);
155 proto_tree_add_time(tree, hf_nlm_time, tvb, 0, 0, &ns);
160 nlm_print_msgres_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
162 nlm_msg_res_matched_data *md;
164 md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
166 proto_tree_add_uint(tree, hf_nlm_reply_in, tvb, 0, 0, md->rep_frame);
170 nlm_match_fhandle_reply(packet_info *pinfo, proto_tree *tree)
172 nlm_msg_res_matched_data *md;
174 md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
175 if(md && md->rep_frame){
176 dissect_fhandle_hidden(pinfo,
177 tree, md->req_frame);
181 nlm_match_fhandle_request(packet_info *pinfo, proto_tree *tree)
183 nlm_msg_res_matched_data *md;
185 md=(nlm_msg_res_matched_data *)wmem_map_lookup(nlm_msg_res_matched, GINT_TO_POINTER(pinfo->num));
186 if(md && md->rep_frame){
187 dissect_fhandle_hidden(pinfo,
188 tree, md->rep_frame);
193 nlm_register_unmatched_res(packet_info *pinfo, tvbuff_t *tvb, int offset)
195 nlm_msg_res_unmatched_data umd;
196 nlm_msg_res_unmatched_data *old_umd;
198 umd.cookie_len=tvb_get_ntohl(tvb, offset);
199 umd.cookie=tvb_get_ptr(tvb, offset+4, -1);
201 /* have we seen this cookie before? */
202 old_umd=(nlm_msg_res_unmatched_data *)wmem_map_lookup(nlm_msg_res_unmatched, (gconstpointer)&umd);
204 nlm_msg_res_matched_data *md_req, *md_rep;
206 md_req = wmem_new(wmem_file_scope(), nlm_msg_res_matched_data);
207 md_req->req_frame = old_umd->req_frame;
208 md_req->rep_frame = pinfo->num;
209 md_req->ns = old_umd->ns;
210 md_rep = (nlm_msg_res_matched_data *)wmem_memdup(wmem_file_scope(), md_req, sizeof(nlm_msg_res_matched_data));
211 wmem_map_insert(nlm_msg_res_matched, GINT_TO_POINTER(md_req->req_frame), md_req);
212 wmem_map_insert(nlm_msg_res_matched, GINT_TO_POINTER(md_rep->rep_frame), md_rep);
214 wmem_map_remove(nlm_msg_res_unmatched, old_umd);
219 nlm_register_unmatched_msg(packet_info *pinfo, tvbuff_t *tvb, int offset)
221 nlm_msg_res_unmatched_data *umd;
222 nlm_msg_res_unmatched_data *old_umd;
224 /* allocate and build the unmatched structure for this request */
225 umd = wmem_new(wmem_file_scope(), nlm_msg_res_unmatched_data);
226 umd->req_frame = pinfo->num;
227 umd->ns = pinfo->abs_ts;
228 umd->cookie_len = tvb_get_ntohl(tvb, offset);
229 umd->cookie = (const guint8 *)tvb_memdup(wmem_file_scope(), tvb, offset+4, umd->cookie_len);
231 /* remove any old duplicates */
232 old_umd=(nlm_msg_res_unmatched_data *)wmem_map_lookup(nlm_msg_res_unmatched, umd);
234 wmem_map_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
238 wmem_map_insert(nlm_msg_res_unmatched, umd, umd);
244 static const value_string names_nlm_stats[] =
246 /* NLM_GRANTED is the function number 5 and the state code 0.
247 * So we use for the state the postfix _S.
249 #define NLM_GRANTED_S 0
250 { NLM_GRANTED_S, "NLM_GRANTED" },
252 { NLM_DENIED, "NLM_DENIED" },
253 #define NLM_DENIED_NOLOCKS 2
254 { NLM_DENIED_NOLOCKS, "NLM_DENIED_NOLOCKS" },
255 #define NLM_BLOCKED 3
256 { NLM_BLOCKED, "NLM_BLOCKED" },
257 #define NLM_DENIED_GRACE_PERIOD 4
258 { NLM_DENIED_GRACE_PERIOD, "NLM_DENIED_GRACE_PERIOD" },
259 #define NLM_DEADLCK 5
260 { NLM_DEADLCK, "NLM_DEADLCK" },
262 { NLM_ROFS, "NLM_ROFS" },
263 #define NLM_STALE_FH 7
264 { NLM_STALE_FH, "NLM_STALE_FH" },
266 { NLM_BIG, "NLM_BIG" },
268 { NLM_FAILED, "NLM_FAILED" },
273 static const value_string names_fsh_mode[] =
276 { FSM_DN, "deny none" },
278 { FSM_DR, "deny read" },
280 { FSM_DW, "deny write" },
282 { FSM_DRW, "deny read/write" },
288 static const value_string names_fsh_access[] =
291 { FSA_NONE, "no access" },
293 { FSA_R, "read-only" },
295 { FSA_W, "write-only" },
297 { FSA_RW, "read/write" },
306 /* **************************** */
307 /* generic dissecting functions */
308 /* **************************** */
310 dissect_lock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int version, int offset, rpc_call_info_value* civ)
312 proto_item* lock_item = NULL;
313 proto_tree* lock_tree = NULL;
314 guint32 fh_hash, svid, start_offset=0, end_offset=0;
317 lock_item = proto_tree_add_item(tree, hf_nlm_lock, tvb,
320 lock_tree = proto_item_add_subtree(lock_item, ett_nlm_lock);
323 offset = dissect_rpc_string(tvb,lock_tree,
324 hf_nlm_lock_caller_name, offset, NULL);
325 offset = dissect_nfs3_fh(tvb, offset, pinfo, lock_tree, "fh", &fh_hash, civ);
326 col_append_fstr(pinfo->cinfo, COL_INFO, " FH:0x%08x", fh_hash);
328 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner, offset);
330 svid = tvb_get_ntohl(tvb, offset);
331 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_svid, offset);
332 col_append_fstr(pinfo->cinfo, COL_INFO, " svid:%d", svid);
335 start_offset = tvb_get_ntohl(tvb, offset);
336 offset = dissect_rpc_uint64(tvb, lock_tree, hf_nlm_lock_l_offset64, offset);
337 end_offset = tvb_get_ntohl(tvb, offset);
338 offset = dissect_rpc_uint64(tvb, lock_tree, hf_nlm_lock_l_len64, offset);
341 start_offset = tvb_get_ntohl(tvb, offset);
342 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_l_offset, offset);
343 end_offset = tvb_get_ntohl(tvb, offset);
344 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_l_len, offset);
347 col_append_fstr(pinfo->cinfo, COL_INFO, " pos:%d-%d", start_offset, end_offset);
354 dissect_nlm_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
355 proto_tree *tree, int version, rpc_call_info_value* rpc_call)
357 if(nlm_match_msgres){
358 if(rpc_call->proc==6){ /* NLM_TEST_MSG */
359 if( (!pinfo->fd->flags.visited) ){
360 nlm_register_unmatched_msg(pinfo, tvb, offset);
362 nlm_print_msgres_request(pinfo, tree, tvb);
364 /* for the fhandle matching that finds both request and
366 if(nfs_fhandle_reqrep_matching){
367 nlm_match_fhandle_request(pinfo, tree);
372 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
373 dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
375 offset = dissect_lock(tvb, pinfo, tree, version, offset, rpc_call);
380 dissect_nlm_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
381 proto_tree *tree,int version, rpc_call_info_value* rpc_call)
383 if(nlm_match_msgres){
384 if(rpc_call->proc==7){ /* NLM_LOCK_MSG */
385 if( (!pinfo->fd->flags.visited) ){
386 nlm_register_unmatched_msg(pinfo, tvb, offset);
388 nlm_print_msgres_request(pinfo, tree, tvb);
390 /* for the fhandle matching that finds both request and
392 if(nfs_fhandle_reqrep_matching){
393 nlm_match_fhandle_request(pinfo, tree);
398 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
399 offset = dissect_rpc_bool(tvb, tree, hf_nlm_block, offset);
400 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
401 offset = dissect_lock(tvb, pinfo, tree, version, offset, rpc_call);
402 offset = dissect_rpc_bool(tvb, tree, hf_nlm_reclaim, offset);
403 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_state, offset);
408 dissect_nlm_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
409 proto_tree *tree,int version, rpc_call_info_value* rpc_call)
411 if(nlm_match_msgres){
412 if(rpc_call->proc==8){ /* NLM_CANCEL_MSG */
413 if( (!pinfo->fd->flags.visited) ){
414 nlm_register_unmatched_msg(pinfo, tvb, offset);
416 nlm_print_msgres_request(pinfo, tree, tvb);
418 /* for the fhandle matching that finds both request and
420 if(nfs_fhandle_reqrep_matching){
421 nlm_match_fhandle_request(pinfo, tree);
426 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
427 offset = dissect_rpc_bool(tvb, tree, hf_nlm_block, offset);
428 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
429 offset = dissect_lock(tvb, pinfo, tree, version, offset, rpc_call);
434 dissect_nlm_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
435 proto_tree *tree,int version, rpc_call_info_value* rpc_call)
437 if(nlm_match_msgres){
438 if(rpc_call->proc==9){ /* NLM_UNLOCK_MSG */
439 if( (!pinfo->fd->flags.visited) ){
440 nlm_register_unmatched_msg(pinfo, tvb, offset);
442 nlm_print_msgres_request(pinfo, tree, tvb);
444 /* for the fhandle matching that finds both request and
446 if(nfs_fhandle_reqrep_matching){
447 nlm_match_fhandle_request(pinfo, tree);
452 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
453 offset = dissect_lock(tvb, pinfo, tree, version, offset, rpc_call);
458 dissect_nlm_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
459 proto_tree *tree,int version, rpc_call_info_value* rpc_call)
461 if(nlm_match_msgres){
462 if(rpc_call->proc==10){ /* NLM_GRANTED_MSG */
463 if( (!pinfo->fd->flags.visited) ){
464 nlm_register_unmatched_msg(pinfo, tvb, offset);
466 nlm_print_msgres_request(pinfo, tree, tvb);
468 /* for the fhandle matching that finds both request and
470 if(nfs_fhandle_reqrep_matching){
471 nlm_match_fhandle_request(pinfo, tree);
476 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
477 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
478 offset = dissect_lock(tvb, pinfo, tree, version, offset, rpc_call);
484 dissect_nlm_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
485 proto_tree *tree, int version, rpc_call_info_value *rpc_call)
487 proto_item* lock_item = NULL;
488 proto_tree* lock_tree = NULL;
490 if(nlm_match_msgres){
491 if(rpc_call->proc==11){ /* NLM_TEST_RES */
492 if( (!pinfo->fd->flags.visited) ){
493 nlm_register_unmatched_res(pinfo, tvb, offset);
495 nlm_print_msgres_reply(pinfo, tree, tvb);
497 /* for the fhandle matching that finds both request and
499 if(nfs_fhandle_reqrep_matching){
500 nlm_match_fhandle_reply(pinfo, tree);
505 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
508 lock_item = proto_tree_add_item(tree, hf_nlm_test_stat, tvb,
510 lock_tree = proto_item_add_subtree(lock_item, ett_nlm_lock);
513 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_test_stat_stat,
516 /* last structure is optional, only supplied for stat==1 (LOCKED) */
517 if(tvb_reported_length_remaining(tvb, offset) == 0){
522 lock_item = proto_tree_add_item(lock_tree, hf_nlm_holder, tvb,
525 lock_tree = proto_item_add_subtree(lock_item,
529 offset = dissect_rpc_bool(tvb, lock_tree, hf_nlm_exclusive,
531 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_svid,
533 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner,
537 offset = dissect_rpc_uint64(tvb, lock_tree,
538 hf_nlm_lock_l_offset64, offset);
539 offset = dissect_rpc_uint64(tvb, lock_tree,
540 hf_nlm_lock_l_len64, offset);
543 offset = dissect_rpc_uint32(tvb, lock_tree,
544 hf_nlm_lock_l_offset, offset);
545 offset = dissect_rpc_uint32(tvb, lock_tree,
546 hf_nlm_lock_l_len, offset);
554 dissect_nlm_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
555 proto_tree *tree,int version _U_, rpc_call_info_value* civ)
557 proto_item* lock_item = NULL;
558 proto_tree* lock_tree = NULL;
561 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
564 lock_item = proto_tree_add_item(tree, hf_nlm_share, tvb,
567 lock_tree = proto_item_add_subtree(lock_item,
571 offset = dissect_rpc_string(tvb,lock_tree,
572 hf_nlm_lock_caller_name, offset, NULL);
574 offset = dissect_nfs3_fh(tvb, offset, pinfo, lock_tree, "fh", &fh_hash, civ);
575 col_append_fstr(pinfo->cinfo, COL_INFO, " FH:0x%08x", fh_hash);
577 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner, offset);
579 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_share_mode, offset);
580 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_share_access, offset);
583 offset = dissect_rpc_bool(tvb, tree, hf_nlm_reclaim, offset);
588 dissect_nlm_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
589 proto_tree *tree, int version _U_)
593 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
594 nlm_stat = tvb_get_ntohl(tvb, offset);
596 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
597 val_to_str(nlm_stat, names_nlm_stats, "Unknown Status (%u)"));
599 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
600 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_sequence, offset);
605 dissect_nlm_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
606 proto_tree *tree,int version _U_)
608 offset = dissect_rpc_string(tvb,tree,
609 hf_nlm_share_name, offset, NULL);
611 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_state, offset);
620 /* This function is identical for all NLM protocol versions (1-4)*/
622 dissect_nlm_gen_reply(tvbuff_t *tvb, packet_info *pinfo _U_,
623 proto_tree *tree, void* data)
628 if(nlm_match_msgres){
629 rpc_call_info_value *rpc_call=(rpc_call_info_value *)data;
630 if((rpc_call->proc==12) /* NLM_LOCK_RES */
631 || (rpc_call->proc==13) /* NLM_CANCEL_RES */
632 || (rpc_call->proc==14) /* NLM_UNLOCK_RES */
633 || (rpc_call->proc==15) ){ /* NLM_GRENTED_RES */
634 if( (!pinfo->fd->flags.visited) ){
635 nlm_register_unmatched_res(pinfo, tvb, offset);
637 nlm_print_msgres_reply(pinfo, tree, tvb);
639 /* for the fhandle matching that finds both request and
641 if(nfs_fhandle_reqrep_matching){
642 nlm_match_fhandle_reply(pinfo, tree);
647 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
649 nlm_stat = tvb_get_ntohl(tvb, offset);
651 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
652 val_to_str(nlm_stat, names_nlm_stats, "Unknown Status (%u)"));
654 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
659 dissect_nlm1_test(tvbuff_t *tvb, packet_info *pinfo,
660 proto_tree *tree, void* data)
662 return dissect_nlm_test(tvb,0,pinfo,tree,1,(rpc_call_info_value*)data);
666 dissect_nlm4_test(tvbuff_t *tvb, packet_info *pinfo,
667 proto_tree *tree, void* data)
669 return dissect_nlm_test(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
674 dissect_nlm1_lock(tvbuff_t *tvb, packet_info *pinfo,
675 proto_tree *tree, void* data)
677 return dissect_nlm_lock(tvb,0,pinfo,tree,1,(rpc_call_info_value*)data);
681 dissect_nlm4_lock(tvbuff_t *tvb, packet_info *pinfo,
682 proto_tree *tree, void* data)
684 return dissect_nlm_lock(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
689 dissect_nlm1_cancel(tvbuff_t *tvb, packet_info *pinfo,
690 proto_tree *tree, void* data)
692 return dissect_nlm_cancel(tvb,0,pinfo,tree,1,(rpc_call_info_value*)data);
696 dissect_nlm4_cancel(tvbuff_t *tvb, packet_info *pinfo,
697 proto_tree *tree, void* data)
699 return dissect_nlm_cancel(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
704 dissect_nlm1_unlock(tvbuff_t *tvb, packet_info *pinfo,
705 proto_tree *tree, void* data)
707 return dissect_nlm_unlock(tvb,0,pinfo,tree,1,(rpc_call_info_value*)data);
711 dissect_nlm4_unlock(tvbuff_t *tvb, packet_info *pinfo,
712 proto_tree *tree, void* data)
714 return dissect_nlm_unlock(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
719 dissect_nlm1_granted(tvbuff_t *tvb, packet_info *pinfo,
720 proto_tree *tree, void* data)
722 return dissect_nlm_granted(tvb,0,pinfo,tree,1,(rpc_call_info_value*)data);
726 dissect_nlm4_granted(tvbuff_t *tvb, packet_info *pinfo,
727 proto_tree *tree, void* data)
729 return dissect_nlm_granted(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
734 dissect_nlm1_test_res(tvbuff_t *tvb, packet_info *pinfo,
735 proto_tree *tree, void* data)
737 return dissect_nlm_test_res(tvb,0,pinfo,tree,1,(rpc_call_info_value*)data);
741 dissect_nlm4_test_res(tvbuff_t *tvb, packet_info *pinfo,
742 proto_tree *tree, void* data)
744 return dissect_nlm_test_res(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
748 dissect_nlm3_share(tvbuff_t *tvb, packet_info *pinfo,
749 proto_tree *tree, void* data _U_)
751 return dissect_nlm_share(tvb,0,pinfo,tree,3,(rpc_call_info_value*)data);
755 dissect_nlm4_share(tvbuff_t *tvb, packet_info *pinfo,
756 proto_tree *tree, void* data _U_)
758 return dissect_nlm_share(tvb,0,pinfo,tree,4,(rpc_call_info_value*)data);
762 dissect_nlm3_shareres(tvbuff_t *tvb, packet_info *pinfo,
763 proto_tree *tree, void* data _U_)
765 return dissect_nlm_shareres(tvb,0,pinfo,tree,3);
769 dissect_nlm4_shareres(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
771 return dissect_nlm_shareres(tvb,0,pinfo,tree,4);
775 dissect_nlm3_freeall(tvbuff_t *tvb, packet_info *pinfo,
776 proto_tree *tree, void* data _U_)
778 return dissect_nlm_freeall(tvb,0,pinfo,tree,3);
782 dissect_nlm4_freeall(tvbuff_t *tvb, packet_info *pinfo,
783 proto_tree *tree, void* data _U_)
785 return dissect_nlm_freeall(tvb,0,pinfo,tree,4);
791 /* proc number, "proc name", dissect_request, dissect_reply */
792 /* NLM protocol version 1 */
793 static const vsff nlm1_proc[] = {
795 dissect_rpc_void, dissect_rpc_void },
797 dissect_nlm1_test, dissect_nlm1_test_res },
799 dissect_nlm1_lock, dissect_nlm_gen_reply },
800 { NLM_CANCEL, "CANCEL",
801 dissect_nlm1_cancel, dissect_nlm_gen_reply },
802 { NLM_UNLOCK, "UNLOCK",
803 dissect_nlm1_unlock, dissect_nlm_gen_reply },
804 { NLM_GRANTED, "GRANTED",
805 dissect_nlm1_granted, dissect_nlm_gen_reply },
806 { NLM_TEST_MSG, "TEST_MSG",
807 dissect_nlm1_test, dissect_rpc_void },
808 { NLM_LOCK_MSG, "LOCK_MSG",
809 dissect_nlm1_lock, dissect_rpc_void },
810 { NLM_CANCEL_MSG, "CANCEL_MSG",
811 dissect_nlm1_cancel, dissect_rpc_void },
812 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
813 dissect_nlm1_unlock, dissect_rpc_void },
814 { NLM_GRANTED_MSG, "GRANTED_MSG",
815 dissect_nlm1_granted, dissect_rpc_void },
816 { NLM_TEST_RES, "TEST_RES",
817 dissect_nlm1_test_res, dissect_rpc_void },
818 { NLM_LOCK_RES, "LOCK_RES",
819 dissect_nlm_gen_reply, dissect_rpc_void },
820 { NLM_CANCEL_RES, "CANCEL_RES",
821 dissect_nlm_gen_reply, dissect_rpc_void },
822 { NLM_UNLOCK_RES, "UNLOCK_RES",
823 dissect_nlm_gen_reply, dissect_rpc_void },
824 { NLM_GRANTED_RES, "GRANTED_RES",
825 dissect_nlm_gen_reply, dissect_rpc_void },
829 static const value_string nlm1_proc_vals[] = {
830 { NLM_NULL, "NULL" },
831 { NLM_TEST, "TEST" },
832 { NLM_LOCK, "LOCK" },
833 { NLM_CANCEL, "CANCEL" },
834 { NLM_UNLOCK, "UNLOCK" },
835 { NLM_GRANTED, "GRANTED" },
836 { NLM_TEST_MSG, "TEST_MSG" },
837 { NLM_LOCK_MSG, "LOCK_MSG" },
838 { NLM_CANCEL_MSG, "CANCEL_MSG" },
839 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
840 { NLM_GRANTED_MSG, "GRANTED_MSG" },
841 { NLM_TEST_RES, "TEST_RES" },
842 { NLM_LOCK_RES, "LOCK_RES" },
843 { NLM_CANCEL_RES, "CANCEL_RES" },
844 { NLM_UNLOCK_RES, "UNLOCK_RES" },
845 { NLM_GRANTED_RES, "GRANTED_RES" },
848 /* end of NLM protocol version 1 */
850 /* NLM protocol version 2 */
851 static const vsff nlm2_proc[] = {
853 dissect_rpc_void, dissect_rpc_void },
855 dissect_nlm1_test, dissect_nlm1_test_res },
857 dissect_nlm1_lock, dissect_nlm_gen_reply },
858 { NLM_CANCEL, "CANCEL",
859 dissect_nlm1_cancel, dissect_nlm_gen_reply },
860 { NLM_UNLOCK, "UNLOCK",
861 dissect_nlm1_unlock, dissect_nlm_gen_reply },
862 { NLM_GRANTED, "GRANTED",
863 dissect_nlm1_granted, dissect_nlm_gen_reply },
864 { NLM_TEST_MSG, "TEST_MSG",
865 dissect_nlm1_test, dissect_rpc_void },
866 { NLM_LOCK_MSG, "LOCK_MSG",
867 dissect_nlm1_lock, dissect_rpc_void },
868 { NLM_CANCEL_MSG, "CANCEL_MSG",
869 dissect_nlm1_cancel, dissect_rpc_void },
870 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
871 dissect_nlm1_unlock, dissect_rpc_void },
872 { NLM_GRANTED_MSG, "GRANTED_MSG",
873 dissect_nlm1_granted, dissect_rpc_void },
874 { NLM_TEST_RES, "TEST_RES",
875 dissect_nlm1_test_res, dissect_rpc_void },
876 { NLM_LOCK_RES, "LOCK_RES",
877 dissect_nlm_gen_reply, dissect_rpc_void },
878 { NLM_CANCEL_RES, "CANCEL_RES",
879 dissect_nlm_gen_reply, dissect_rpc_void },
880 { NLM_UNLOCK_RES, "UNLOCK_RES",
881 dissect_nlm_gen_reply, dissect_rpc_void },
882 { NLM_GRANTED_RES, "GRANTED_RES",
883 dissect_nlm_gen_reply, dissect_rpc_void },
887 static const value_string nlm2_proc_vals[] = {
888 { NLM_NULL, "NULL" },
889 { NLM_TEST, "TEST" },
890 { NLM_LOCK, "LOCK" },
891 { NLM_CANCEL, "CANCEL" },
892 { NLM_UNLOCK, "UNLOCK" },
893 { NLM_GRANTED, "GRANTED" },
894 { NLM_TEST_MSG, "TEST_MSG" },
895 { NLM_LOCK_MSG, "LOCK_MSG" },
896 { NLM_CANCEL_MSG, "CANCEL_MSG" },
897 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
898 { NLM_GRANTED_MSG, "GRANTED_MSG" },
899 { NLM_TEST_RES, "TEST_RES" },
900 { NLM_LOCK_RES, "LOCK_RES" },
901 { NLM_CANCEL_RES, "CANCEL_RES" },
902 { NLM_UNLOCK_RES, "UNLOCK_RES" },
903 { NLM_GRANTED_RES, "GRANTED_RES" },
906 /* end of NLM protocol version 2 */
908 /* NLM protocol version 3 */
909 static const vsff nlm3_proc[] = {
911 dissect_rpc_void, dissect_rpc_void },
913 dissect_nlm1_test, dissect_nlm1_test_res },
915 dissect_nlm1_lock, dissect_nlm_gen_reply },
916 { NLM_CANCEL, "CANCEL",
917 dissect_nlm1_cancel, dissect_nlm_gen_reply },
918 { NLM_UNLOCK, "UNLOCK",
919 dissect_nlm1_unlock, dissect_nlm_gen_reply },
920 { NLM_GRANTED, "GRANTED",
921 dissect_nlm1_granted, dissect_nlm_gen_reply },
922 { NLM_TEST_MSG, "TEST_MSG",
923 dissect_nlm1_test, dissect_rpc_void },
924 { NLM_LOCK_MSG, "LOCK_MSG",
925 dissect_nlm1_lock, dissect_rpc_void },
926 { NLM_CANCEL_MSG, "CANCEL_MSG",
927 dissect_nlm1_cancel, dissect_rpc_void },
928 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
929 dissect_nlm1_unlock, dissect_rpc_void },
930 { NLM_GRANTED_MSG, "GRANTED_MSG",
931 dissect_nlm1_granted, dissect_rpc_void },
932 { NLM_TEST_RES, "TEST_RES",
933 dissect_nlm1_test_res, dissect_rpc_void },
934 { NLM_LOCK_RES, "LOCK_RES",
935 dissect_nlm_gen_reply, dissect_rpc_void },
936 { NLM_CANCEL_RES, "CANCEL_RES",
937 dissect_nlm_gen_reply, dissect_rpc_void },
938 { NLM_UNLOCK_RES, "UNLOCK_RES",
939 dissect_nlm_gen_reply, dissect_rpc_void },
940 { NLM_GRANTED_RES, "GRANTED_RES",
941 dissect_nlm_gen_reply, dissect_rpc_void },
942 { NLM_SHARE, "SHARE",
943 dissect_nlm3_share, dissect_nlm3_shareres },
944 { NLM_UNSHARE, "UNSHARE",
945 dissect_nlm3_share, dissect_nlm3_shareres },
946 { NLM_NM_LOCK, "NM_LOCK",
947 dissect_nlm1_lock, dissect_nlm_gen_reply },
948 { NLM_FREE_ALL, "FREE_ALL",
949 dissect_nlm3_freeall, dissect_rpc_void },
953 static const value_string nlm3_proc_vals[] = {
954 { NLM_NULL, "NULL" },
955 { NLM_TEST, "TEST" },
956 { NLM_LOCK, "LOCK" },
957 { NLM_CANCEL, "CANCEL" },
958 { NLM_UNLOCK, "UNLOCK" },
959 { NLM_GRANTED, "GRANTED" },
960 { NLM_TEST_MSG, "TEST_MSG" },
961 { NLM_LOCK_MSG, "LOCK_MSG" },
962 { NLM_CANCEL_MSG, "CANCEL_MSG" },
963 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
964 { NLM_GRANTED_MSG, "GRANTED_MSG" },
965 { NLM_TEST_RES, "TEST_RES" },
966 { NLM_LOCK_RES, "LOCK_RES" },
967 { NLM_CANCEL_RES, "CANCEL_RES" },
968 { NLM_UNLOCK_RES, "UNLOCK_RES" },
969 { NLM_GRANTED_RES, "GRANTED_RES" },
970 { NLM_SHARE, "SHARE" },
971 { NLM_UNSHARE, "UNSHARE" },
972 { NLM_NM_LOCK, "NM_LOCK" },
973 { NLM_FREE_ALL, "FREE_ALL" },
976 /* end of NLM protocol version 3 */
979 /* NLM protocol version 4 */
980 static const vsff nlm4_proc[] = {
982 dissect_rpc_void, dissect_rpc_void },
984 dissect_nlm4_test, dissect_nlm4_test_res },
986 dissect_nlm4_lock, dissect_nlm_gen_reply },
987 { NLM_CANCEL, "CANCEL",
988 dissect_nlm4_cancel, dissect_nlm_gen_reply },
989 { NLM_UNLOCK, "UNLOCK",
990 dissect_nlm4_unlock, dissect_nlm_gen_reply },
991 { NLM_GRANTED, "GRANTED",
992 dissect_nlm4_granted, dissect_nlm_gen_reply },
993 { NLM_TEST_MSG, "TEST_MSG",
994 dissect_nlm4_test, dissect_rpc_void },
995 { NLM_LOCK_MSG, "LOCK_MSG",
996 dissect_nlm4_lock, dissect_rpc_void },
997 { NLM_CANCEL_MSG, "CANCEL_MSG",
998 dissect_nlm4_cancel, dissect_rpc_void },
999 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
1000 dissect_nlm4_unlock, dissect_rpc_void },
1001 { NLM_GRANTED_MSG, "GRANTED_MSG",
1002 dissect_nlm4_granted, dissect_rpc_void },
1003 { NLM_TEST_RES, "TEST_RES",
1004 dissect_nlm4_test_res, dissect_rpc_void },
1005 { NLM_LOCK_RES, "LOCK_RES",
1006 dissect_nlm_gen_reply, dissect_rpc_void },
1007 { NLM_CANCEL_RES, "CANCEL_RES",
1008 dissect_nlm_gen_reply, dissect_rpc_void },
1009 { NLM_UNLOCK_RES, "UNLOCK_RES",
1010 dissect_nlm_gen_reply, dissect_rpc_void },
1011 { NLM_GRANTED_RES, "GRANTED_RES",
1012 dissect_nlm_gen_reply, dissect_rpc_void },
1013 { NLM_SHARE, "SHARE",
1014 dissect_nlm4_share, dissect_nlm4_shareres },
1015 { NLM_UNSHARE, "UNSHARE",
1016 dissect_nlm4_share, dissect_nlm4_shareres },
1017 { NLM_NM_LOCK, "NM_LOCK",
1018 dissect_nlm4_lock, dissect_nlm_gen_reply },
1019 { NLM_FREE_ALL, "FREE_ALL",
1020 dissect_nlm4_freeall, dissect_rpc_void },
1024 static const value_string nlm4_proc_vals[] = {
1025 { NLM_NULL, "NULL" },
1026 { NLM_TEST, "TEST" },
1027 { NLM_LOCK, "LOCK" },
1028 { NLM_CANCEL, "CANCEL" },
1029 { NLM_UNLOCK, "UNLOCK" },
1030 { NLM_GRANTED, "GRANTED" },
1031 { NLM_TEST_MSG, "TEST_MSG" },
1032 { NLM_LOCK_MSG, "LOCK_MSG" },
1033 { NLM_CANCEL_MSG, "CANCEL_MSG" },
1034 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
1035 { NLM_GRANTED_MSG, "GRANTED_MSG" },
1036 { NLM_TEST_RES, "TEST_RES" },
1037 { NLM_LOCK_RES, "LOCK_RES" },
1038 { NLM_CANCEL_RES, "CANCEL_RES" },
1039 { NLM_UNLOCK_RES, "UNLOCK_RES" },
1040 { NLM_GRANTED_RES, "GRANTED_RES" },
1041 { NLM_SHARE, "SHARE" },
1042 { NLM_UNSHARE, "UNSHARE" },
1043 { NLM_NM_LOCK, "NM_LOCK" },
1044 { NLM_FREE_ALL, "FREE_ALL" },
1047 /* end of NLM protocol version 4 */
1049 static const rpc_prog_vers_info nlm_vers_info[] = {
1050 { 1, nlm1_proc, &hf_nlm_procedure_v1 },
1051 { 2, nlm2_proc, &hf_nlm_procedure_v2 },
1052 { 3, nlm3_proc, &hf_nlm_procedure_v3 },
1053 { 4, nlm4_proc, &hf_nlm_procedure_v4 },
1057 proto_register_nlm(void)
1059 static hf_register_info hf[] = {
1060 { &hf_nlm_procedure_v1, {
1061 "V1 Procedure", "nlm.procedure_v1", FT_UINT32, BASE_DEC,
1062 VALS(nlm1_proc_vals), 0, NULL, HFILL }},
1063 { &hf_nlm_procedure_v2, {
1064 "V2 Procedure", "nlm.procedure_v2", FT_UINT32, BASE_DEC,
1065 VALS(nlm2_proc_vals), 0, NULL, HFILL }},
1066 { &hf_nlm_procedure_v3, {
1067 "V3 Procedure", "nlm.procedure_v3", FT_UINT32, BASE_DEC,
1068 VALS(nlm3_proc_vals), 0, NULL, HFILL }},
1069 { &hf_nlm_procedure_v4, {
1070 "V4 Procedure", "nlm.procedure_v4", FT_UINT32, BASE_DEC,
1071 VALS(nlm4_proc_vals), 0, NULL, HFILL }},
1073 "cookie", "nlm.cookie", FT_BYTES, BASE_NONE,
1074 NULL, 0, NULL, HFILL }},
1076 "block", "nlm.block", FT_BOOLEAN, BASE_NONE,
1077 TFS(&tfs_yes_no), 0x0, NULL, HFILL }},
1078 { &hf_nlm_exclusive, {
1079 "exclusive", "nlm.exclusive", FT_BOOLEAN, BASE_NONE,
1080 TFS(&tfs_yes_no), 0x0, NULL, HFILL }},
1082 "lock", "nlm.lock", FT_NONE, BASE_NONE,
1083 NULL, 0, NULL, HFILL }},
1084 { &hf_nlm_lock_caller_name, {
1085 "caller_name", "nlm.lock.caller_name", FT_STRING, BASE_NONE,
1086 NULL, 0, NULL, HFILL }},
1087 { &hf_nlm_lock_owner, {
1088 "owner", "nlm.lock.owner", FT_BYTES, BASE_NONE,
1089 NULL, 0, NULL, HFILL }},
1090 { &hf_nlm_lock_svid, {
1091 "svid", "nlm.lock.svid", FT_UINT32, BASE_DEC,
1092 NULL, 0, NULL, HFILL }},
1093 { &hf_nlm_lock_l_offset64, {
1094 "l_offset", "nlm.lock.l_offset64", FT_UINT64, BASE_DEC,
1095 NULL, 0, NULL, HFILL }},
1096 { &hf_nlm_lock_l_offset, {
1097 "l_offset", "nlm.lock.l_offset", FT_UINT32, BASE_DEC,
1098 NULL, 0, NULL, HFILL }},
1099 { &hf_nlm_lock_l_len64, {
1100 "l_len", "nlm.lock.l_len64", FT_UINT64, BASE_DEC,
1101 NULL, 0, NULL, HFILL }},
1102 { &hf_nlm_lock_l_len, {
1103 "l_len", "nlm.lock.l_len", FT_UINT32, BASE_DEC,
1104 NULL, 0, NULL, HFILL }},
1105 { &hf_nlm_reclaim, {
1106 "reclaim", "nlm.reclaim", FT_BOOLEAN, BASE_NONE,
1107 TFS(&tfs_yes_no), 0x0, NULL, HFILL }},
1109 "state", "nlm.state", FT_UINT32, BASE_DEC,
1110 NULL, 0, "STATD state", HFILL }},
1112 "stat", "nlm.stat", FT_UINT32, BASE_DEC,
1113 VALS(names_nlm_stats), 0, NULL, HFILL }},
1114 { &hf_nlm_test_stat, {
1115 "test_stat", "nlm.test_stat", FT_NONE, BASE_NONE,
1116 NULL, 0, NULL, HFILL }},
1117 { &hf_nlm_test_stat_stat, {
1118 "stat", "nlm.test_stat.stat", FT_UINT32, BASE_DEC,
1119 VALS(names_nlm_stats), 0, NULL, HFILL }},
1121 "holder", "nlm.holder", FT_NONE, BASE_NONE,
1122 NULL, 0, NULL, HFILL }},
1124 "share", "nlm.share", FT_NONE, BASE_NONE,
1125 NULL, 0, NULL, HFILL }},
1126 { &hf_nlm_share_mode, {
1127 "mode", "nlm.share.mode", FT_UINT32, BASE_DEC,
1128 VALS(names_fsh_mode), 0, NULL, HFILL }},
1129 { &hf_nlm_share_access, {
1130 "access", "nlm.share.access", FT_UINT32, BASE_DEC,
1131 VALS(names_fsh_access), 0, NULL, HFILL }},
1132 { &hf_nlm_share_name, {
1133 "name", "nlm.share.name", FT_STRING, BASE_NONE,
1134 NULL, 0, NULL, HFILL }},
1135 { &hf_nlm_sequence, {
1136 "sequence", "nlm.sequence", FT_INT32, BASE_DEC,
1137 NULL, 0, NULL, HFILL }},
1138 { &hf_nlm_request_in, {
1139 "Request MSG in", "nlm.msg_in", FT_UINT32, BASE_DEC,
1140 NULL, 0, "The RES packet is a response to the MSG in this packet", HFILL }},
1141 { &hf_nlm_reply_in, {
1142 "Reply RES in", "nlm.res_in", FT_UINT32, BASE_DEC,
1143 NULL, 0, "The response to this MSG packet is in this packet", HFILL }},
1145 "Time from request", "nlm.time", FT_RELATIVE_TIME, BASE_NONE,
1146 NULL, 0, "Time between Request and Reply for async NLM calls", HFILL }},
1150 static gint *ett[] = {
1154 module_t *nlm_module;
1156 proto_nlm = proto_register_protocol("Network Lock Manager Protocol",
1158 proto_register_field_array(proto_nlm, hf, array_length(hf));
1159 proto_register_subtree_array(ett, array_length(ett));
1161 nlm_module = prefs_register_protocol(proto_nlm, NULL);
1162 prefs_register_bool_preference(nlm_module, "msg_res_matching",
1163 "Match MSG/RES packets for async NLM",
1164 "Whether the dissector will track and match MSG and RES calls for asynchronous NLM",
1167 nlm_msg_res_unmatched = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(),
1168 nlm_msg_res_unmatched_hash, nlm_msg_res_unmatched_equal);
1169 nlm_msg_res_matched = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(),
1170 nlm_msg_res_matched_hash, nlm_msg_res_matched_equal);
1174 proto_reg_handoff_nlm(void)
1176 /* Register the protocol as RPC */
1177 rpc_init_prog(proto_nlm, NLM_PROGRAM, ett_nlm,
1178 G_N_ELEMENTS(nlm_vers_info), nlm_vers_info);
1182 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1187 * indent-tabs-mode: t
1190 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1191 * :indentSize=8:tabSize=8:noTabs=false: