2 * Routines for nlm dissection
4 * $Id: packet-nlm.c,v 1.34 2003/01/28 23:56:39 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-mount.c
12 * 2001-JAN Ronnie Sahlberg <See AUTHORS for email>
13 * Updates to version 1 of the protocol.
14 * Added version 3 of the protocol.
15 * Added version 4 of the protocol.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #include "packet-rpc.h"
41 #include "packet-nfs.h"
42 #include "packet-nlm.h"
47 * NFS Lock Manager protocol specs can only be found in actual
48 * implementations or in the nice book:
49 * Brent Callaghan: "NFS Illustrated", Addison-Wesley, ISBN 0-201-32570-5
50 * which I use here as reference (BC).
52 * They can also be found if you go to
54 * http://www.opengroup.org/publications/catalog/c702.htm
56 * and follow the links to the HTML version of the document.
59 static int proto_nlm = -1;
60 static int hf_nlm_procedure_v1 = -1;
61 static int hf_nlm_procedure_v2 = -1;
62 static int hf_nlm_procedure_v3 = -1;
63 static int hf_nlm_procedure_v4 = -1;
64 static int hf_nlm_cookie = -1;
65 static int hf_nlm_block = -1;
66 static int hf_nlm_exclusive = -1;
67 static int hf_nlm_lock = -1;
68 static int hf_nlm_lock_caller_name = -1;
69 static int hf_nlm_lock_owner = -1;
70 static int hf_nlm_lock_svid = -1;
71 static int hf_nlm_lock_l_offset = -1;
72 static int hf_nlm_lock_l_offset64 = -1;
73 static int hf_nlm_lock_l_len = -1;
74 static int hf_nlm_lock_l_len64 = -1;
75 static int hf_nlm_reclaim = -1;
76 static int hf_nlm_stat = -1;
77 static int hf_nlm_state = -1;
78 static int hf_nlm_test_stat = -1;
79 static int hf_nlm_test_stat_stat = -1;
80 static int hf_nlm_holder = -1;
81 static int hf_nlm_share = -1;
82 static int hf_nlm_share_mode = -1;
83 static int hf_nlm_share_access = -1;
84 static int hf_nlm_share_name = -1;
85 static int hf_nlm_sequence = -1;
86 static int hf_nlm_request_in = -1;
87 static int hf_nlm_reply_in = -1;
88 static int hf_nlm_time = -1;
90 static gint ett_nlm = -1;
91 static gint ett_nlm_lock = -1;
96 * stuff to match MSG and RES packets for async NLM
99 static gboolean nlm_match_msgres = FALSE;
100 static GHashTable *nlm_msg_res_unmatched = NULL;
101 static GHashTable *nlm_msg_res_matched = NULL;
103 /* XXX when matching the packets we should really check the conversation (only address
104 NOT ports) and command type as well. I am lazy and thinks the cookie itself is
107 typedef struct _nlm_msg_res_unmatched_data {
112 } nlm_msg_res_unmatched_data;
114 typedef struct _nlm_msg_res_matched_data {
118 } nlm_msg_res_matched_data;
121 nlm_msg_res_unmatched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
123 nlm_msg_res_unmatched_data *umd = (nlm_msg_res_unmatched_data *)value;
125 g_free((gpointer)umd->cookie);
131 nlm_msg_res_matched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
133 nlm_msg_res_matched_data *md = (nlm_msg_res_matched_data *)value;
141 nlm_msg_res_unmatched_hash(gconstpointer k)
143 const nlm_msg_res_unmatched_data *umd = (const nlm_msg_res_unmatched_data *)k;
147 for(i=0;i<umd->cookie_len;i++){
148 hash^=umd->cookie[i];
154 nlm_msg_res_matched_hash(gconstpointer k)
156 guint hash = (guint)k;
162 nlm_msg_res_unmatched_equal(gconstpointer k1, gconstpointer k2)
164 const nlm_msg_res_unmatched_data *umd1 = (const nlm_msg_res_unmatched_data *)k1;
165 const nlm_msg_res_unmatched_data *umd2 = (const nlm_msg_res_unmatched_data *)k2;
167 if(umd1->cookie_len!=umd2->cookie_len){
171 return( !memcmp(umd1->cookie, umd2->cookie, umd1->cookie_len));
174 nlm_msg_res_matched_equal(gconstpointer k1, gconstpointer k2)
176 guint mk1 = (guint)k1;
177 guint mk2 = (guint)k2;
183 nlm_msg_res_match_init(void)
185 if(nlm_msg_res_unmatched != NULL){
186 g_hash_table_foreach_remove(nlm_msg_res_unmatched,
187 nlm_msg_res_unmatched_free_all, NULL);
189 nlm_msg_res_unmatched=g_hash_table_new(nlm_msg_res_unmatched_hash,
190 nlm_msg_res_unmatched_equal);
193 if(nlm_msg_res_matched != NULL){
194 g_hash_table_foreach_remove(nlm_msg_res_matched,
195 nlm_msg_res_matched_free_all, NULL);
197 nlm_msg_res_matched=g_hash_table_new(nlm_msg_res_matched_hash,
198 nlm_msg_res_matched_equal);
203 nlm_print_msgres_reply(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
205 nlm_msg_res_matched_data *md;
207 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
210 proto_tree_add_uint(tree, hf_nlm_request_in, tvb, 0, 0, md->req_frame);
211 ns.secs= pinfo->fd->abs_secs-md->ns.secs;
212 ns.nsecs=pinfo->fd->abs_usecs*1000-md->ns.nsecs;
214 ns.nsecs+=1000000000;
217 proto_tree_add_time(tree, hf_nlm_time, tvb, 0, 0, &ns);
223 nlm_print_msgres_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
225 nlm_msg_res_matched_data *md;
227 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
229 proto_tree_add_uint(tree, hf_nlm_reply_in, tvb, 0, 0, md->rep_frame);
233 nlm_match_fhandle_reply(packet_info *pinfo, proto_tree *tree)
235 nlm_msg_res_matched_data *md;
237 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
238 if(md && md->rep_frame){
239 nfs_fhandle_data_t *fhd;
240 fhd=(nfs_fhandle_data_t *)g_hash_table_lookup(
241 nfs_fhandle_frame_table,
242 (gconstpointer)md->req_frame);
244 dissect_fhandle_hidden(pinfo,
250 nlm_match_fhandle_request(packet_info *pinfo, proto_tree *tree)
252 nlm_msg_res_matched_data *md;
254 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
255 if(md && md->rep_frame){
256 nfs_fhandle_data_t *fhd;
257 fhd=(nfs_fhandle_data_t *)g_hash_table_lookup(
258 nfs_fhandle_frame_table,
259 (gconstpointer)md->rep_frame);
261 dissect_fhandle_hidden(pinfo,
268 nlm_register_unmatched_res(packet_info *pinfo, tvbuff_t *tvb, int offset)
270 nlm_msg_res_unmatched_data umd;
271 nlm_msg_res_unmatched_data *old_umd;
273 umd.cookie_len=tvb_get_ntohl(tvb, offset);
274 umd.cookie=(const char *)tvb_get_ptr(tvb, offset+4, -1);
276 /* have we seen this cookie before? */
277 old_umd=g_hash_table_lookup(nlm_msg_res_unmatched, (gconstpointer)&umd);
279 nlm_msg_res_matched_data *md;
281 md=g_malloc(sizeof(nlm_msg_res_matched_data));
282 md->req_frame=old_umd->req_frame;
283 md->rep_frame=pinfo->fd->num;
285 g_hash_table_insert(nlm_msg_res_matched, (gpointer)md->req_frame, (gpointer)md);
286 g_hash_table_insert(nlm_msg_res_matched, (gpointer)md->rep_frame, (gpointer)md);
288 g_hash_table_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
289 g_free((gpointer)old_umd->cookie);
295 nlm_register_unmatched_msg(packet_info *pinfo, tvbuff_t *tvb, int offset)
297 nlm_msg_res_unmatched_data *umd;
298 nlm_msg_res_unmatched_data *old_umd;
301 /* allocate and build the unmatched structure for this request */
302 umd=g_malloc(sizeof(nlm_msg_res_unmatched_data));
303 umd->req_frame=pinfo->fd->num;
304 umd->ns.secs=pinfo->fd->abs_secs;
305 umd->ns.nsecs=pinfo->fd->abs_usecs*1000;
306 umd->cookie_len=tvb_get_ntohl(tvb, offset);
307 cookie=g_malloc(umd->cookie_len);
308 tvb_memcpy(tvb, (guint8 *)cookie, offset+4, umd->cookie_len);
311 /* remove any old duplicates */
312 old_umd=g_hash_table_lookup(nlm_msg_res_unmatched, (gconstpointer)umd);
314 g_hash_table_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
315 g_free((gpointer)old_umd->cookie);
320 g_hash_table_insert(nlm_msg_res_unmatched, (gpointer)umd, (gpointer)umd);
326 static const value_string names_nlm_stats[] =
328 /* NLM_GRANTED is the function number 5 and the state code 0.
329 * So we use for the state the postfix _S.
331 #define NLM_GRANTED_S 0
332 { NLM_GRANTED_S, "NLM_GRANTED" },
334 { NLM_DENIED, "NLM_DENIED" },
335 #define NLM_DENIED_NOLOCKS 2
336 { NLM_DENIED_NOLOCKS, "NLM_DENIED_NOLOCKS" },
337 #define NLM_BLOCKED 3
338 { NLM_BLOCKED, "NLM_BLOCKED" },
339 #define NLM_DENIED_GRACE_PERIOD 4
340 { NLM_DENIED_GRACE_PERIOD, "NLM_DENIED_GRACE_PERIOD" },
341 #define NLM_DEADLCK 5
342 { NLM_DEADLCK, "NLM_DEADLCK" },
344 { NLM_ROFS, "NLM_ROFS" },
345 #define NLM_STALE_FH 7
346 { NLM_STALE_FH, "NLM_STALE_FH" },
348 { NLM_BIG, "NLM_BIG" },
350 { NLM_FAILED, "NLM_FAILED" },
355 static const value_string names_fsh_mode[] =
358 { FSM_DN, "deny none" },
360 { FSM_DR, "deny read" },
362 { FSM_DW, "deny write" },
364 { FSM_DRW, "deny read/write" },
370 static const value_string names_fsh_access[] =
373 { FSA_NONE, "no access" },
375 { FSA_R, "read-only" },
377 { FSA_W, "write-only" },
379 { FSA_RW, "read/write" },
388 /* **************************** */
389 /* generic dissecting functions */
390 /* **************************** */
392 dissect_lock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int version, int offset)
394 proto_item* lock_item = NULL;
395 proto_tree* lock_tree = NULL;
398 lock_item = proto_tree_add_item(tree, hf_nlm_lock, tvb,
401 lock_tree = proto_item_add_subtree(lock_item, ett_nlm_lock);
404 offset = dissect_rpc_string(tvb,lock_tree,
405 hf_nlm_lock_caller_name, offset, NULL);
406 offset = dissect_nfs_fh3(tvb, offset, pinfo, lock_tree,"fh");
408 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner, offset);
410 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_svid, offset);
413 offset = dissect_rpc_uint64(tvb, lock_tree, hf_nlm_lock_l_offset64, offset);
414 offset = dissect_rpc_uint64(tvb, lock_tree, hf_nlm_lock_l_len64, offset);
417 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_l_offset, offset);
418 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_l_len, offset);
426 dissect_nlm_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
427 proto_tree *tree, int version)
429 if(nlm_match_msgres){
430 rpc_call_info_value *rpc_call=pinfo->private_data;
431 if(rpc_call->proc==6){ /* NLM_TEST_MSG */
432 if( (!pinfo->fd->flags.visited) ){
433 nlm_register_unmatched_msg(pinfo, tvb, offset);
435 nlm_print_msgres_request(pinfo, tree, tvb);
437 /* for the fhandle matching that finds both request and
439 if(nfs_fhandle_reqrep_matching){
440 nlm_match_fhandle_request(pinfo, tree);
445 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
446 dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
448 offset = dissect_lock(tvb, pinfo, tree, version, offset);
453 dissect_nlm_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
454 proto_tree *tree,int version)
456 if(nlm_match_msgres){
457 rpc_call_info_value *rpc_call=pinfo->private_data;
458 if(rpc_call->proc==7){ /* NLM_LOCK_MSG */
459 if( (!pinfo->fd->flags.visited) ){
460 nlm_register_unmatched_msg(pinfo, tvb, offset);
462 nlm_print_msgres_request(pinfo, tree, tvb);
464 /* for the fhandle matching that finds both request and
466 if(nfs_fhandle_reqrep_matching){
467 nlm_match_fhandle_request(pinfo, tree);
472 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
473 offset = dissect_rpc_bool(tvb, tree, hf_nlm_block, offset);
474 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
475 offset = dissect_lock(tvb, pinfo, tree, version, offset);
476 offset = dissect_rpc_bool(tvb, tree, hf_nlm_reclaim, offset);
477 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_state, offset);
482 dissect_nlm_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
483 proto_tree *tree,int version)
485 if(nlm_match_msgres){
486 rpc_call_info_value *rpc_call=pinfo->private_data;
487 if(rpc_call->proc==8){ /* NLM_CANCEL_MSG */
488 if( (!pinfo->fd->flags.visited) ){
489 nlm_register_unmatched_msg(pinfo, tvb, offset);
491 nlm_print_msgres_request(pinfo, tree, tvb);
493 /* for the fhandle matching that finds both request and
495 if(nfs_fhandle_reqrep_matching){
496 nlm_match_fhandle_request(pinfo, tree);
501 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
502 offset = dissect_rpc_bool(tvb, tree, hf_nlm_block, offset);
503 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
504 offset = dissect_lock(tvb, pinfo, tree, version, offset);
509 dissect_nlm_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
510 proto_tree *tree,int version)
512 if(nlm_match_msgres){
513 rpc_call_info_value *rpc_call=pinfo->private_data;
514 if(rpc_call->proc==9){ /* NLM_UNLOCK_MSG */
515 if( (!pinfo->fd->flags.visited) ){
516 nlm_register_unmatched_msg(pinfo, tvb, offset);
518 nlm_print_msgres_request(pinfo, tree, tvb);
520 /* for the fhandle matching that finds both request and
522 if(nfs_fhandle_reqrep_matching){
523 nlm_match_fhandle_request(pinfo, tree);
528 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
529 offset = dissect_lock(tvb, pinfo, tree, version, offset);
534 dissect_nlm_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
535 proto_tree *tree,int version)
537 if(nlm_match_msgres){
538 rpc_call_info_value *rpc_call=pinfo->private_data;
539 if(rpc_call->proc==10){ /* NLM_GRANTED_MSG */
540 if( (!pinfo->fd->flags.visited) ){
541 nlm_register_unmatched_msg(pinfo, tvb, offset);
543 nlm_print_msgres_request(pinfo, tree, tvb);
545 /* for the fhandle matching that finds both request and
547 if(nfs_fhandle_reqrep_matching){
548 nlm_match_fhandle_request(pinfo, tree);
553 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
554 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
555 offset = dissect_lock(tvb, pinfo, tree, version, offset);
561 dissect_nlm_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
562 proto_tree *tree,int version)
564 proto_item* lock_item = NULL;
565 proto_tree* lock_tree = NULL;
567 if(nlm_match_msgres){
568 rpc_call_info_value *rpc_call=pinfo->private_data;
569 if(rpc_call->proc==11){ /* NLM_TEST_RES */
570 if( (!pinfo->fd->flags.visited) ){
571 nlm_register_unmatched_res(pinfo, tvb, offset);
573 nlm_print_msgres_reply(pinfo, tree, tvb);
575 /* for the fhandle matching that finds both request and
577 if(nfs_fhandle_reqrep_matching){
578 nlm_match_fhandle_reply(pinfo, tree);
583 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
586 lock_item = proto_tree_add_item(tree, hf_nlm_test_stat, tvb,
589 lock_tree = proto_item_add_subtree(lock_item,
593 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_test_stat_stat,
596 /* last structure is optional, only supplied for stat==1 (LOCKED) */
597 if(tvb_reported_length_remaining(tvb, offset) == 0){
602 lock_item = proto_tree_add_item(lock_tree, hf_nlm_holder, tvb,
605 lock_tree = proto_item_add_subtree(lock_item,
609 offset = dissect_rpc_bool(tvb, lock_tree, hf_nlm_exclusive,
611 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_svid,
613 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner,
617 offset = dissect_rpc_uint64(tvb, lock_tree,
618 hf_nlm_lock_l_offset64, offset);
619 offset = dissect_rpc_uint64(tvb, lock_tree,
620 hf_nlm_lock_l_len64, offset);
623 offset = dissect_rpc_uint32(tvb, lock_tree,
624 hf_nlm_lock_l_offset, offset);
625 offset = dissect_rpc_uint32(tvb, lock_tree,
626 hf_nlm_lock_l_len, offset);
634 dissect_nlm_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
635 proto_tree *tree,int version _U_)
637 proto_item* lock_item = NULL;
638 proto_tree* lock_tree = NULL;
640 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
643 lock_item = proto_tree_add_item(tree, hf_nlm_share, tvb,
646 lock_tree = proto_item_add_subtree(lock_item,
650 offset = dissect_rpc_string(tvb,lock_tree,
651 hf_nlm_lock_caller_name, offset, NULL);
653 offset = dissect_nfs_fh3(tvb, offset, pinfo, lock_tree, "fh");
655 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner, offset);
657 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_share_mode, offset);
658 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_share_access, offset);
661 offset = dissect_rpc_bool(tvb, tree, hf_nlm_reclaim, offset);
666 dissect_nlm_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
667 proto_tree *tree, int version _U_)
669 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
670 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
671 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_sequence, offset);
676 dissect_nlm_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
677 proto_tree *tree,int version _U_)
679 offset = dissect_rpc_string(tvb,tree,
680 hf_nlm_share_name, offset, NULL);
682 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
691 /* This function is identical for all NLM protocol versions (1-4)*/
693 dissect_nlm_gen_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
696 if(nlm_match_msgres){
697 rpc_call_info_value *rpc_call=pinfo->private_data;
698 if((rpc_call->proc==12) /* NLM_LOCK_RES */
699 || (rpc_call->proc==13) /* NLM_CANCEL_RES */
700 || (rpc_call->proc==14) /* NLM_UNLOCK_RES */
701 || (rpc_call->proc==15) ){ /* NLM_GRENTED_RES */
702 if( (!pinfo->fd->flags.visited) ){
703 nlm_register_unmatched_res(pinfo, tvb, offset);
705 nlm_print_msgres_reply(pinfo, tree, tvb);
707 /* for the fhandle matching that finds both request and
709 if(nfs_fhandle_reqrep_matching){
710 nlm_match_fhandle_reply(pinfo, tree);
715 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
716 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
721 dissect_nlm1_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
724 return dissect_nlm_test(tvb,offset,pinfo,tree,1);
728 dissect_nlm4_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
731 return dissect_nlm_test(tvb,offset,pinfo,tree,4);
736 dissect_nlm1_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
739 return dissect_nlm_lock(tvb,offset,pinfo,tree,1);
743 dissect_nlm4_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
746 return dissect_nlm_lock(tvb,offset,pinfo,tree,4);
751 dissect_nlm1_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
754 return dissect_nlm_cancel(tvb,offset,pinfo,tree,1);
758 dissect_nlm4_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
761 return dissect_nlm_cancel(tvb,offset,pinfo,tree,4);
766 dissect_nlm1_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
769 return dissect_nlm_unlock(tvb,offset,pinfo,tree,1);
773 dissect_nlm4_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
776 return dissect_nlm_unlock(tvb,offset,pinfo,tree,4);
781 dissect_nlm1_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
784 return dissect_nlm_granted(tvb,offset,pinfo,tree,1);
788 dissect_nlm4_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
791 return dissect_nlm_granted(tvb,offset,pinfo,tree,4);
796 dissect_nlm1_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo,
799 return dissect_nlm_test_res(tvb,offset,pinfo,tree,1);
803 dissect_nlm4_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo,
806 return dissect_nlm_test_res(tvb,offset,pinfo,tree,4);
810 dissect_nlm3_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
813 return dissect_nlm_share(tvb,offset,pinfo,tree,3);
817 dissect_nlm4_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
820 return dissect_nlm_share(tvb,offset,pinfo,tree,4);
824 dissect_nlm3_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo,
827 return dissect_nlm_shareres(tvb,offset,pinfo,tree,3);
831 dissect_nlm4_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo,
834 return dissect_nlm_shareres(tvb,offset,pinfo,tree,4);
838 dissect_nlm3_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo,
841 return dissect_nlm_freeall(tvb,offset,pinfo,tree,3);
845 dissect_nlm4_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo,
848 return dissect_nlm_freeall(tvb,offset,pinfo,tree,4);
854 /* proc number, "proc name", dissect_request, dissect_reply */
855 /* NULL as function pointer means: type of arguments is "void". */
856 /* NLM protocol version 1 */
857 static const vsff nlm1_proc[] = {
861 dissect_nlm1_test, dissect_nlm1_test_res },
863 dissect_nlm1_lock, dissect_nlm_gen_reply },
864 { NLM_CANCEL, "CANCEL",
865 dissect_nlm1_cancel, dissect_nlm_gen_reply },
866 { NLM_UNLOCK, "UNLOCK",
867 dissect_nlm1_unlock, dissect_nlm_gen_reply },
868 { NLM_GRANTED, "GRANTED",
869 dissect_nlm1_granted, dissect_nlm_gen_reply },
870 { NLM_TEST_MSG, "TEST_MSG",
871 dissect_nlm1_test, NULL },
872 { NLM_LOCK_MSG, "LOCK_MSG",
873 dissect_nlm1_lock, NULL },
874 { NLM_CANCEL_MSG, "CANCEL_MSG",
875 dissect_nlm1_cancel, NULL },
876 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
877 dissect_nlm1_unlock, NULL },
878 { NLM_GRANTED_MSG, "GRANTED_MSG",
879 dissect_nlm1_granted, NULL },
880 { NLM_TEST_RES, "TEST_RES",
881 dissect_nlm1_test_res, NULL },
882 { NLM_LOCK_RES, "LOCK_RES",
883 dissect_nlm_gen_reply, NULL },
884 { NLM_CANCEL_RES, "CANCEL_RES",
885 dissect_nlm_gen_reply, NULL },
886 { NLM_UNLOCK_RES, "UNLOCK_RES",
887 dissect_nlm_gen_reply, NULL },
888 { NLM_GRANTED_RES, "GRANTED_RES",
889 dissect_nlm_gen_reply, NULL },
893 static const value_string nlm1_proc_vals[] = {
894 { NLM_NULL, "NULL" },
895 { NLM_TEST, "TEST" },
896 { NLM_LOCK, "LOCK" },
897 { NLM_CANCEL, "CANCEL" },
898 { NLM_UNLOCK, "UNLOCK" },
899 { NLM_GRANTED, "GRANTED" },
900 { NLM_TEST_MSG, "TEST_MSG" },
901 { NLM_LOCK_MSG, "LOCK_MSG" },
902 { NLM_CANCEL_MSG, "CANCEL_MSG" },
903 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
904 { NLM_GRANTED_MSG, "GRANTED_MSG" },
905 { NLM_TEST_RES, "TEST_RES" },
906 { NLM_LOCK_RES, "LOCK_RES" },
907 { NLM_CANCEL_RES, "CANCEL_RES" },
908 { NLM_UNLOCK_RES, "UNLOCK_RES" },
909 { NLM_GRANTED_RES, "GRANTED_RES" },
912 /* end of NLM protocol version 1 */
914 /* NLM protocol version 2 */
915 static const vsff nlm2_proc[] = {
919 dissect_nlm1_test, dissect_nlm1_test_res },
921 dissect_nlm1_lock, dissect_nlm_gen_reply },
922 { NLM_CANCEL, "CANCEL",
923 dissect_nlm1_cancel, dissect_nlm_gen_reply },
924 { NLM_UNLOCK, "UNLOCK",
925 dissect_nlm1_unlock, dissect_nlm_gen_reply },
926 { NLM_GRANTED, "GRANTED",
927 dissect_nlm1_granted, dissect_nlm_gen_reply },
928 { NLM_TEST_MSG, "TEST_MSG",
929 dissect_nlm1_test, NULL },
930 { NLM_LOCK_MSG, "LOCK_MSG",
931 dissect_nlm1_lock, NULL },
932 { NLM_CANCEL_MSG, "CANCEL_MSG",
933 dissect_nlm1_cancel, NULL },
934 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
935 dissect_nlm1_unlock, NULL },
936 { NLM_GRANTED_MSG, "GRANTED_MSG",
937 dissect_nlm1_granted, NULL },
938 { NLM_TEST_RES, "TEST_RES",
939 dissect_nlm1_test_res, NULL },
940 { NLM_LOCK_RES, "LOCK_RES",
941 dissect_nlm_gen_reply, NULL },
942 { NLM_CANCEL_RES, "CANCEL_RES",
943 dissect_nlm_gen_reply, NULL },
944 { NLM_UNLOCK_RES, "UNLOCK_RES",
945 dissect_nlm_gen_reply, NULL },
946 { NLM_GRANTED_RES, "GRANTED_RES",
947 dissect_nlm_gen_reply, NULL },
951 static const value_string nlm2_proc_vals[] = {
952 { NLM_NULL, "NULL" },
953 { NLM_TEST, "TEST" },
954 { NLM_LOCK, "LOCK" },
955 { NLM_CANCEL, "CANCEL" },
956 { NLM_UNLOCK, "UNLOCK" },
957 { NLM_GRANTED, "GRANTED" },
958 { NLM_TEST_MSG, "TEST_MSG" },
959 { NLM_LOCK_MSG, "LOCK_MSG" },
960 { NLM_CANCEL_MSG, "CANCEL_MSG" },
961 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
962 { NLM_GRANTED_MSG, "GRANTED_MSG" },
963 { NLM_TEST_RES, "TEST_RES" },
964 { NLM_LOCK_RES, "LOCK_RES" },
965 { NLM_CANCEL_RES, "CANCEL_RES" },
966 { NLM_UNLOCK_RES, "UNLOCK_RES" },
967 { NLM_GRANTED_RES, "GRANTED_RES" },
970 /* end of NLM protocol version 2 */
972 /* NLM protocol version 3 */
973 static const vsff nlm3_proc[] = {
977 dissect_nlm1_test, dissect_nlm1_test_res },
979 dissect_nlm1_lock, dissect_nlm_gen_reply },
980 { NLM_CANCEL, "CANCEL",
981 dissect_nlm1_cancel, dissect_nlm_gen_reply },
982 { NLM_UNLOCK, "UNLOCK",
983 dissect_nlm1_unlock, dissect_nlm_gen_reply },
984 { NLM_GRANTED, "GRANTED",
985 dissect_nlm1_granted, dissect_nlm_gen_reply },
986 { NLM_TEST_MSG, "TEST_MSG",
987 dissect_nlm1_test, NULL },
988 { NLM_LOCK_MSG, "LOCK_MSG",
989 dissect_nlm1_lock, NULL },
990 { NLM_CANCEL_MSG, "CANCEL_MSG",
991 dissect_nlm1_cancel, NULL },
992 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
993 dissect_nlm1_unlock, NULL },
994 { NLM_GRANTED_MSG, "GRANTED_MSG",
995 dissect_nlm1_granted, NULL },
996 { NLM_TEST_RES, "TEST_RES",
997 dissect_nlm1_test_res, NULL },
998 { NLM_LOCK_RES, "LOCK_RES",
999 dissect_nlm_gen_reply, NULL },
1000 { NLM_CANCEL_RES, "CANCEL_RES",
1001 dissect_nlm_gen_reply, NULL },
1002 { NLM_UNLOCK_RES, "UNLOCK_RES",
1003 dissect_nlm_gen_reply, NULL },
1004 { NLM_GRANTED_RES, "GRANTED_RES",
1005 dissect_nlm_gen_reply, NULL },
1006 { NLM_SHARE, "SHARE",
1007 dissect_nlm3_share, dissect_nlm3_shareres },
1008 { NLM_UNSHARE, "UNSHARE",
1009 dissect_nlm3_share, dissect_nlm3_shareres },
1010 { NLM_NM_LOCK, "NM_LOCK",
1011 dissect_nlm1_lock, dissect_nlm_gen_reply },
1012 { NLM_FREE_ALL, "FREE_ALL",
1013 dissect_nlm3_freeall, NULL },
1017 static const value_string nlm3_proc_vals[] = {
1018 { NLM_NULL, "NULL" },
1019 { NLM_TEST, "TEST" },
1020 { NLM_LOCK, "LOCK" },
1021 { NLM_CANCEL, "CANCEL" },
1022 { NLM_UNLOCK, "UNLOCK" },
1023 { NLM_GRANTED, "GRANTED" },
1024 { NLM_TEST_MSG, "TEST_MSG" },
1025 { NLM_LOCK_MSG, "LOCK_MSG" },
1026 { NLM_CANCEL_MSG, "CANCEL_MSG" },
1027 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
1028 { NLM_GRANTED_MSG, "GRANTED_MSG" },
1029 { NLM_TEST_RES, "TEST_RES" },
1030 { NLM_LOCK_RES, "LOCK_RES" },
1031 { NLM_CANCEL_RES, "CANCEL_RES" },
1032 { NLM_UNLOCK_RES, "UNLOCK_RES" },
1033 { NLM_GRANTED_RES, "GRANTED_RES" },
1034 { NLM_SHARE, "SHARE" },
1035 { NLM_UNSHARE, "UNSHARE" },
1036 { NLM_NM_LOCK, "NM_LOCK" },
1037 { NLM_FREE_ALL, "FREE_ALL" },
1040 /* end of NLM protocol version 3 */
1043 /* NLM protocol version 4 */
1044 static const vsff nlm4_proc[] = {
1048 dissect_nlm4_test, dissect_nlm4_test_res },
1050 dissect_nlm4_lock, dissect_nlm_gen_reply },
1051 { NLM_CANCEL, "CANCEL",
1052 dissect_nlm4_cancel, dissect_nlm_gen_reply },
1053 { NLM_UNLOCK, "UNLOCK",
1054 dissect_nlm4_unlock, dissect_nlm_gen_reply },
1055 { NLM_GRANTED, "GRANTED",
1056 dissect_nlm4_granted, dissect_nlm_gen_reply },
1057 { NLM_TEST_MSG, "TEST_MSG",
1058 dissect_nlm4_test, NULL },
1059 { NLM_LOCK_MSG, "LOCK_MSG",
1060 dissect_nlm4_lock, NULL },
1061 { NLM_CANCEL_MSG, "CANCEL_MSG",
1062 dissect_nlm4_cancel, NULL },
1063 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
1064 dissect_nlm4_unlock, NULL },
1065 { NLM_GRANTED_MSG, "GRANTED_MSG",
1066 dissect_nlm4_granted, NULL },
1067 { NLM_TEST_RES, "TEST_RES",
1068 dissect_nlm4_test_res, NULL },
1069 { NLM_LOCK_RES, "LOCK_RES",
1070 dissect_nlm_gen_reply, NULL },
1071 { NLM_CANCEL_RES, "CANCEL_RES",
1072 dissect_nlm_gen_reply, NULL },
1073 { NLM_UNLOCK_RES, "UNLOCK_RES",
1074 dissect_nlm_gen_reply, NULL },
1075 { NLM_GRANTED_RES, "GRANTED_RES",
1076 dissect_nlm_gen_reply, NULL },
1077 { NLM_SHARE, "SHARE",
1078 dissect_nlm4_share, dissect_nlm4_shareres },
1079 { NLM_UNSHARE, "UNSHARE",
1080 dissect_nlm4_share, dissect_nlm4_shareres },
1081 { NLM_NM_LOCK, "NM_LOCK",
1082 dissect_nlm4_lock, dissect_nlm_gen_reply },
1083 { NLM_FREE_ALL, "FREE_ALL",
1084 dissect_nlm4_freeall, NULL },
1088 static const value_string nlm4_proc_vals[] = {
1089 { NLM_NULL, "NULL" },
1090 { NLM_TEST, "TEST" },
1091 { NLM_LOCK, "LOCK" },
1092 { NLM_CANCEL, "CANCEL" },
1093 { NLM_UNLOCK, "UNLOCK" },
1094 { NLM_GRANTED, "GRANTED" },
1095 { NLM_TEST_MSG, "TEST_MSG" },
1096 { NLM_LOCK_MSG, "LOCK_MSG" },
1097 { NLM_CANCEL_MSG, "CANCEL_MSG" },
1098 { NLM_UNLOCK_MSG, "UNLOCK_MSG" },
1099 { NLM_GRANTED_MSG, "GRANTED_MSG" },
1100 { NLM_TEST_RES, "TEST_RES" },
1101 { NLM_LOCK_RES, "LOCK_RES" },
1102 { NLM_CANCEL_RES, "CANCEL_RES" },
1103 { NLM_UNLOCK_RES, "UNLOCK_RES" },
1104 { NLM_GRANTED_RES, "GRANTED_RES" },
1105 { NLM_SHARE, "SHARE" },
1106 { NLM_UNSHARE, "UNSHARE" },
1107 { NLM_NM_LOCK, "NM_LOCK" },
1108 { NLM_FREE_ALL, "FREE_ALL" },
1111 /* end of NLM protocol version 4 */
1114 static struct true_false_string yesno = { "Yes", "No" };
1118 proto_register_nlm(void)
1120 static hf_register_info hf[] = {
1121 { &hf_nlm_procedure_v1, {
1122 "V1 Procedure", "nlm.procedure_v1", FT_UINT32, BASE_DEC,
1123 VALS(nlm1_proc_vals), 0, "V1 Procedure", HFILL }},
1124 { &hf_nlm_procedure_v2, {
1125 "V2 Procedure", "nlm.procedure_v2", FT_UINT32, BASE_DEC,
1126 VALS(nlm2_proc_vals), 0, "V2 Procedure", HFILL }},
1127 { &hf_nlm_procedure_v3, {
1128 "V3 Procedure", "nlm.procedure_v3", FT_UINT32, BASE_DEC,
1129 VALS(nlm3_proc_vals), 0, "V3 Procedure", HFILL }},
1130 { &hf_nlm_procedure_v4, {
1131 "V4 Procedure", "nlm.procedure_v4", FT_UINT32, BASE_DEC,
1132 VALS(nlm4_proc_vals), 0, "V4 Procedure", HFILL }},
1134 "cookie", "nlm.cookie", FT_BYTES, BASE_DEC,
1135 NULL, 0, "cookie", HFILL }},
1137 "block", "nlm.block", FT_BOOLEAN, BASE_NONE,
1138 &yesno, 0, "block", HFILL }},
1139 { &hf_nlm_exclusive, {
1140 "exclusive", "nlm.exclusive", FT_BOOLEAN, BASE_NONE,
1141 &yesno, 0, "exclusive", HFILL }},
1143 "lock", "nlm.lock", FT_NONE, 0,
1144 NULL, 0, "lock", HFILL }},
1145 { &hf_nlm_lock_caller_name, {
1146 "caller_name", "nlm.lock.caller_name", FT_STRING, BASE_NONE,
1147 NULL, 0, "caller_name", HFILL }},
1148 { &hf_nlm_lock_owner, {
1149 "owner", "nlm.lock.owner", FT_BYTES, BASE_DEC,
1150 NULL, 0, "owner", HFILL }},
1151 { &hf_nlm_lock_svid, {
1152 "svid", "nlm.lock.svid", FT_UINT32, BASE_DEC,
1153 NULL, 0, "svid", HFILL }},
1154 { &hf_nlm_lock_l_offset64, {
1155 "l_offset", "nlm.lock.l_offset", FT_UINT64, BASE_DEC,
1156 NULL, 0, "l_offset", HFILL }},
1157 { &hf_nlm_lock_l_offset, {
1158 "l_offset", "nlm.lock.l_offset", FT_UINT32, BASE_DEC,
1159 NULL, 0, "l_offset", HFILL }},
1160 { &hf_nlm_lock_l_len64, {
1161 "l_len", "nlm.lock.l_len", FT_UINT64, BASE_DEC,
1162 NULL, 0, "l_len", HFILL }},
1163 { &hf_nlm_lock_l_len, {
1164 "l_len", "nlm.lock.l_len", FT_UINT32, BASE_DEC,
1165 NULL, 0, "l_len", HFILL }},
1166 { &hf_nlm_reclaim, {
1167 "reclaim", "nlm.reclaim", FT_BOOLEAN, BASE_NONE,
1168 &yesno, 0, "reclaim", HFILL }},
1170 "state", "nlm.state", FT_UINT32, BASE_DEC,
1171 NULL, 0, "STATD state", HFILL }},
1173 "stat", "nlm.stat", FT_UINT32, BASE_DEC,
1174 VALS(names_nlm_stats), 0, "stat", HFILL }},
1175 { &hf_nlm_test_stat, {
1176 "test_stat", "nlm.test_stat", FT_NONE, 0,
1177 NULL, 0, "test_stat", HFILL }},
1178 { &hf_nlm_test_stat_stat, {
1179 "stat", "nlm.test_stat.stat", FT_UINT32, BASE_DEC,
1180 VALS(names_nlm_stats), 0, "stat", HFILL }},
1182 "holder", "nlm.holder", FT_NONE, 0,
1183 NULL, 0, "holder", HFILL }},
1185 "share", "nlm.share", FT_NONE, 0,
1186 NULL, 0, "share", HFILL }},
1187 { &hf_nlm_share_mode, {
1188 "mode", "nlm.share.mode", FT_UINT32, BASE_DEC,
1189 VALS(names_fsh_mode), 0, "mode", HFILL }},
1190 { &hf_nlm_share_access, {
1191 "access", "nlm.share.access", FT_UINT32, BASE_DEC,
1192 VALS(names_fsh_access), 0, "access", HFILL }},
1193 { &hf_nlm_share_name, {
1194 "name", "nlm.share.name", FT_STRING, BASE_NONE,
1195 NULL, 0, "name", HFILL }},
1196 { &hf_nlm_sequence, {
1197 "sequence", "nlm.sequence", FT_INT32, BASE_DEC,
1198 NULL, 0, "sequence", HFILL }},
1199 { &hf_nlm_request_in, {
1200 "Request MSG in", "nlm.msg_in", FT_UINT32, BASE_DEC,
1201 NULL, 0, "The RES packet is a response to the MSG in this packet", HFILL }},
1202 { &hf_nlm_reply_in, {
1203 "Reply RES in", "nlm.res_in", FT_UINT32, BASE_DEC,
1204 NULL, 0, "The response to this MSG packet is in this packet", HFILL }},
1206 "Time from request", "nlm.time", FT_RELATIVE_TIME, BASE_NONE,
1207 NULL, 0, "Time between Request and Reply for async NLM calls", HFILL }},
1211 static gint *ett[] = {
1215 module_t *nlm_module;
1217 proto_nlm = proto_register_protocol("Network Lock Manager Protocol",
1219 proto_register_field_array(proto_nlm, hf, array_length(hf));
1220 proto_register_subtree_array(ett, array_length(ett));
1222 nlm_module = prefs_register_protocol(proto_nlm, NULL);
1223 prefs_register_bool_preference(nlm_module, "msg_res_matching",
1224 "Match MSG/RES packets for async NLM",
1225 "Whether the dissector will track and match MSG and RES calls for asynchronous NLM",
1227 register_init_routine(nlm_msg_res_match_init);
1231 proto_reg_handoff_nlm(void)
1233 /* Register the protocol as RPC */
1234 rpc_init_prog(proto_nlm, NLM_PROGRAM, ett_nlm);
1235 /* Register the procedure tables */
1236 rpc_init_proc_table(NLM_PROGRAM, 1, nlm1_proc, hf_nlm_procedure_v1);
1237 rpc_init_proc_table(NLM_PROGRAM, 2, nlm2_proc, hf_nlm_procedure_v2);
1238 rpc_init_proc_table(NLM_PROGRAM, 3, nlm3_proc, hf_nlm_procedure_v3);
1239 rpc_init_proc_table(NLM_PROGRAM, 4, nlm4_proc, hf_nlm_procedure_v4);