2 * Routines for nlm dissection
4 * $Id: packet-nlm.c,v 1.28 2002/08/02 23:35:55 jmayer 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;
61 static int hf_nlm_cookie = -1;
62 static int hf_nlm_block = -1;
63 static int hf_nlm_exclusive = -1;
64 static int hf_nlm_lock = -1;
65 static int hf_nlm_lock_caller_name = -1;
66 static int hf_nlm_lock_owner = -1;
67 static int hf_nlm_lock_svid = -1;
68 static int hf_nlm_lock_l_offset = -1;
69 static int hf_nlm_lock_l_offset64 = -1;
70 static int hf_nlm_lock_l_len = -1;
71 static int hf_nlm_lock_l_len64 = -1;
72 static int hf_nlm_reclaim = -1;
73 static int hf_nlm_stat = -1;
74 static int hf_nlm_state = -1;
75 static int hf_nlm_test_stat = -1;
76 static int hf_nlm_test_stat_stat = -1;
77 static int hf_nlm_holder = -1;
78 static int hf_nlm_share = -1;
79 static int hf_nlm_share_mode = -1;
80 static int hf_nlm_share_access = -1;
81 static int hf_nlm_share_name = -1;
82 static int hf_nlm_sequence = -1;
83 static int hf_nlm_request_in = -1;
84 static int hf_nlm_reply_in = -1;
85 static int hf_nlm_time = -1;
87 static gint ett_nlm = -1;
88 static gint ett_nlm_lock = -1;
93 * stuff to match MSG and RES packets for async NLM
96 static gboolean nlm_match_msgres = FALSE;
97 static GHashTable *nlm_msg_res_unmatched = NULL;
98 static GHashTable *nlm_msg_res_matched = NULL;
100 /* XXX when matching the packets we should really check the conversation (only address
101 NOT ports) and command type as well. I am lazy and thinks the cookie itself is
104 typedef struct _nlm_msg_res_unmatched_data {
109 } nlm_msg_res_unmatched_data;
111 typedef struct _nlm_msg_res_matched_data {
115 } nlm_msg_res_matched_data;
118 nlm_msg_res_unmatched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
120 nlm_msg_res_unmatched_data *umd = (nlm_msg_res_unmatched_data *)value;
128 nlm_msg_res_matched_free_all(gpointer key_arg _U_, gpointer value, gpointer user_data _U_)
130 nlm_msg_res_matched_data *md = (nlm_msg_res_matched_data *)value;
138 nlm_msg_res_unmatched_hash(gconstpointer k)
140 nlm_msg_res_unmatched_data *umd = (nlm_msg_res_unmatched_data *)k;
144 for(i=0;i<umd->cookie_len;i++){
145 hash^=umd->cookie[i];
151 nlm_msg_res_matched_hash(gconstpointer k)
153 guint hash = (guint)k;
159 nlm_msg_res_unmatched_equal(gconstpointer k1, gconstpointer k2)
161 nlm_msg_res_unmatched_data *umd1 = (nlm_msg_res_unmatched_data *)k1;
162 nlm_msg_res_unmatched_data *umd2 = (nlm_msg_res_unmatched_data *)k2;
164 if(umd1->cookie_len!=umd2->cookie_len){
168 return( !memcmp(umd1->cookie, umd2->cookie, umd1->cookie_len));
171 nlm_msg_res_matched_equal(gconstpointer k1, gconstpointer k2)
173 guint mk1 = (guint)k1;
174 guint mk2 = (guint)k2;
180 nlm_msg_res_match_init(void)
182 if(nlm_msg_res_unmatched != NULL){
183 g_hash_table_foreach_remove(nlm_msg_res_unmatched,
184 nlm_msg_res_unmatched_free_all, NULL);
186 nlm_msg_res_unmatched=g_hash_table_new(nlm_msg_res_unmatched_hash,
187 nlm_msg_res_unmatched_equal);
190 if(nlm_msg_res_matched != NULL){
191 g_hash_table_foreach_remove(nlm_msg_res_matched,
192 nlm_msg_res_matched_free_all, NULL);
194 nlm_msg_res_matched=g_hash_table_new(nlm_msg_res_matched_hash,
195 nlm_msg_res_matched_equal);
200 nlm_print_msgres_reply(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
202 nlm_msg_res_matched_data *md;
204 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
207 proto_tree_add_uint(tree, hf_nlm_request_in, tvb, 0, 0, md->req_frame);
208 ns.secs= pinfo->fd->abs_secs-md->ns.secs;
209 ns.nsecs=pinfo->fd->abs_usecs*1000-md->ns.nsecs;
211 ns.nsecs+=1000000000;
214 proto_tree_add_time(tree, hf_nlm_time, tvb, 0, 0, &ns);
220 nlm_print_msgres_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb)
222 nlm_msg_res_matched_data *md;
224 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
226 proto_tree_add_uint(tree, hf_nlm_reply_in, tvb, 0, 0, md->rep_frame);
230 nlm_match_fhandle_reply(packet_info *pinfo, proto_tree *tree)
232 nlm_msg_res_matched_data *md;
234 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
235 if(md && md->rep_frame){
236 nfs_fhandle_data_t *fhd;
237 fhd=(nfs_fhandle_data_t *)g_hash_table_lookup(
238 nfs_fhandle_frame_table,
239 (gconstpointer)md->req_frame);
241 dissect_fhandle_hidden(pinfo,
247 nlm_match_fhandle_request(packet_info *pinfo, proto_tree *tree)
249 nlm_msg_res_matched_data *md;
251 md=g_hash_table_lookup(nlm_msg_res_matched, (gconstpointer)pinfo->fd->num);
252 if(md && md->rep_frame){
253 nfs_fhandle_data_t *fhd;
254 fhd=(nfs_fhandle_data_t *)g_hash_table_lookup(
255 nfs_fhandle_frame_table,
256 (gconstpointer)md->rep_frame);
258 dissect_fhandle_hidden(pinfo,
265 nlm_register_unmatched_res(packet_info *pinfo, tvbuff_t *tvb, int offset)
267 nlm_msg_res_unmatched_data umd;
268 nlm_msg_res_unmatched_data *old_umd;
270 umd.cookie_len=tvb_get_ntohl(tvb, offset);
271 umd.cookie=(char *)tvb_get_ptr(tvb, offset+4, -1);
273 /* have we seen this cookie before? */
274 old_umd=g_hash_table_lookup(nlm_msg_res_unmatched, (gconstpointer)&umd);
276 nlm_msg_res_matched_data *md;
278 md=g_malloc(sizeof(nlm_msg_res_matched_data));
279 md->req_frame=old_umd->req_frame;
280 md->rep_frame=pinfo->fd->num;
282 g_hash_table_insert(nlm_msg_res_matched, (gpointer)md->req_frame, (gpointer)md);
283 g_hash_table_insert(nlm_msg_res_matched, (gpointer)md->rep_frame, (gpointer)md);
285 g_hash_table_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
286 g_free(old_umd->cookie);
292 nlm_register_unmatched_msg(packet_info *pinfo, tvbuff_t *tvb, int offset)
294 nlm_msg_res_unmatched_data *umd;
295 nlm_msg_res_unmatched_data *old_umd;
297 /* allocate and build the unmatched structure for this request */
298 umd=g_malloc(sizeof(nlm_msg_res_unmatched_data));
299 umd->req_frame=pinfo->fd->num;
300 umd->ns.secs=pinfo->fd->abs_secs;
301 umd->ns.nsecs=pinfo->fd->abs_usecs*1000;
302 umd->cookie_len=tvb_get_ntohl(tvb, offset);
303 umd->cookie=g_malloc(umd->cookie_len);
304 tvb_memcpy(tvb, (guint8 *)umd->cookie, offset+4, umd->cookie_len);
306 /* remove any old duplicates */
307 old_umd=g_hash_table_lookup(nlm_msg_res_unmatched, (gconstpointer)umd);
309 g_hash_table_remove(nlm_msg_res_unmatched, (gconstpointer)old_umd);
310 g_free(old_umd->cookie);
315 g_hash_table_insert(nlm_msg_res_unmatched, (gpointer)umd, (gpointer)umd);
321 static const value_string names_nlm_stats[] =
323 /* NLM_GRANTED is the function number 5 and the state code 0.
324 * So we use for the state the postfix _S.
326 #define NLM_GRANTED_S 0
327 { NLM_GRANTED_S, "NLM_GRANTED" },
329 { NLM_DENIED, "NLM_DENIED" },
330 #define NLM_DENIED_NOLOCKS 2
331 { NLM_DENIED_NOLOCKS, "NLM_DENIED_NOLOCKS" },
332 #define NLM_BLOCKED 3
333 { NLM_BLOCKED, "NLM_BLOCKED" },
334 #define NLM_DENIED_GRACE_PERIOD 4
335 { NLM_DENIED_GRACE_PERIOD, "NLM_DENIED_GRACE_PERIOD" },
336 #define NLM_DEADLCK 5
337 { NLM_DEADLCK, "NLM_DEADLCK" },
339 { NLM_ROFS, "NLM_ROFS" },
340 #define NLM_STALE_FH 7
341 { NLM_STALE_FH, "NLM_STALE_FH" },
343 { NLM_BIG, "NLM_BIG" },
345 { NLM_FAILED, "NLM_FAILED" },
350 static const value_string names_fsh_mode[] =
353 { FSM_DN, "deny none" },
355 { FSM_DR, "deny read" },
357 { FSM_DW, "deny write" },
359 { FSM_DRW, "deny read/write" },
365 static const value_string names_fsh_access[] =
368 { FSA_NONE, "no access" },
370 { FSA_R, "read-only" },
372 { FSA_W, "write-only" },
374 { FSA_RW, "read/write" },
383 /* **************************** */
384 /* generic dissecting functions */
385 /* **************************** */
387 dissect_lock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int version, int offset)
389 proto_item* lock_item = NULL;
390 proto_tree* lock_tree = NULL;
393 lock_item = proto_tree_add_item(tree, hf_nlm_lock, tvb,
396 lock_tree = proto_item_add_subtree(lock_item, ett_nlm_lock);
399 offset = dissect_rpc_string(tvb,lock_tree,
400 hf_nlm_lock_caller_name, offset, NULL);
401 offset = dissect_nfs_fh3(tvb, offset, pinfo, lock_tree,"fh");
403 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner, offset);
405 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_svid, offset);
408 offset = dissect_rpc_uint64(tvb, lock_tree, hf_nlm_lock_l_offset64, offset);
409 offset = dissect_rpc_uint64(tvb, lock_tree, hf_nlm_lock_l_len64, offset);
412 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_l_offset, offset);
413 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_l_len, offset);
421 dissect_nlm_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
422 proto_tree *tree, int version)
424 if(nlm_match_msgres){
425 rpc_call_info_value *rpc_call=pinfo->private_data;
426 if(rpc_call->proc==6){ /* NLM_TEST_MSG */
427 if( (!pinfo->fd->flags.visited) ){
428 nlm_register_unmatched_msg(pinfo, tvb, offset);
430 nlm_print_msgres_request(pinfo, tree, tvb);
432 /* for the fhandle matching that finds both request and
434 if(nfs_fhandle_reqrep_matching){
435 nlm_match_fhandle_request(pinfo, tree);
440 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
441 dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
443 offset = dissect_lock(tvb, pinfo, tree, version, offset);
448 dissect_nlm_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
449 proto_tree *tree,int version)
451 if(nlm_match_msgres){
452 rpc_call_info_value *rpc_call=pinfo->private_data;
453 if(rpc_call->proc==7){ /* NLM_LOCK_MSG */
454 if( (!pinfo->fd->flags.visited) ){
455 nlm_register_unmatched_msg(pinfo, tvb, offset);
457 nlm_print_msgres_request(pinfo, tree, tvb);
459 /* for the fhandle matching that finds both request and
461 if(nfs_fhandle_reqrep_matching){
462 nlm_match_fhandle_request(pinfo, tree);
467 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
468 offset = dissect_rpc_bool(tvb, tree, hf_nlm_block, offset);
469 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
470 offset = dissect_lock(tvb, pinfo, tree, version, offset);
471 offset = dissect_rpc_bool(tvb, tree, hf_nlm_reclaim, offset);
472 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_state, offset);
477 dissect_nlm_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
478 proto_tree *tree,int version)
480 if(nlm_match_msgres){
481 rpc_call_info_value *rpc_call=pinfo->private_data;
482 if(rpc_call->proc==8){ /* NLM_CANCEL_MSG */
483 if( (!pinfo->fd->flags.visited) ){
484 nlm_register_unmatched_msg(pinfo, tvb, offset);
486 nlm_print_msgres_request(pinfo, tree, tvb);
488 /* for the fhandle matching that finds both request and
490 if(nfs_fhandle_reqrep_matching){
491 nlm_match_fhandle_request(pinfo, tree);
496 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
497 offset = dissect_rpc_bool(tvb, tree, hf_nlm_block, offset);
498 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
499 offset = dissect_lock(tvb, pinfo, tree, version, offset);
504 dissect_nlm_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
505 proto_tree *tree,int version)
507 if(nlm_match_msgres){
508 rpc_call_info_value *rpc_call=pinfo->private_data;
509 if(rpc_call->proc==9){ /* NLM_UNLOCK_MSG */
510 if( (!pinfo->fd->flags.visited) ){
511 nlm_register_unmatched_msg(pinfo, tvb, offset);
513 nlm_print_msgres_request(pinfo, tree, tvb);
515 /* for the fhandle matching that finds both request and
517 if(nfs_fhandle_reqrep_matching){
518 nlm_match_fhandle_request(pinfo, tree);
523 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
524 offset = dissect_lock(tvb, pinfo, tree, version, offset);
529 dissect_nlm_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
530 proto_tree *tree,int version)
532 if(nlm_match_msgres){
533 rpc_call_info_value *rpc_call=pinfo->private_data;
534 if(rpc_call->proc==10){ /* NLM_GRANTED_MSG */
535 if( (!pinfo->fd->flags.visited) ){
536 nlm_register_unmatched_msg(pinfo, tvb, offset);
538 nlm_print_msgres_request(pinfo, tree, tvb);
540 /* for the fhandle matching that finds both request and
542 if(nfs_fhandle_reqrep_matching){
543 nlm_match_fhandle_request(pinfo, tree);
548 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
549 offset = dissect_rpc_bool(tvb, tree, hf_nlm_exclusive, offset);
550 offset = dissect_lock(tvb, pinfo, tree, version, offset);
556 dissect_nlm_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
557 proto_tree *tree,int version)
559 proto_item* lock_item = NULL;
560 proto_tree* lock_tree = NULL;
562 if(nlm_match_msgres){
563 rpc_call_info_value *rpc_call=pinfo->private_data;
564 if(rpc_call->proc==11){ /* NLM_TEST_RES */
565 if( (!pinfo->fd->flags.visited) ){
566 nlm_register_unmatched_res(pinfo, tvb, offset);
568 nlm_print_msgres_reply(pinfo, tree, tvb);
570 /* for the fhandle matching that finds both request and
572 if(nfs_fhandle_reqrep_matching){
573 nlm_match_fhandle_reply(pinfo, tree);
578 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
581 lock_item = proto_tree_add_item(tree, hf_nlm_test_stat, tvb,
584 lock_tree = proto_item_add_subtree(lock_item,
588 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_test_stat_stat,
591 /* last structure is optional, only supplied for stat==1 (LOCKED) */
592 if(tvb_reported_length_remaining(tvb, offset) == 0){
597 lock_item = proto_tree_add_item(lock_tree, hf_nlm_holder, tvb,
600 lock_tree = proto_item_add_subtree(lock_item,
604 offset = dissect_rpc_bool(tvb, lock_tree, hf_nlm_exclusive,
606 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_lock_svid,
608 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner,
612 offset = dissect_rpc_uint64(tvb, lock_tree,
613 hf_nlm_lock_l_offset64, offset);
614 offset = dissect_rpc_uint64(tvb, lock_tree,
615 hf_nlm_lock_l_len64, offset);
618 offset = dissect_rpc_uint32(tvb, lock_tree,
619 hf_nlm_lock_l_offset, offset);
620 offset = dissect_rpc_uint32(tvb, lock_tree,
621 hf_nlm_lock_l_len, offset);
629 dissect_nlm_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
630 proto_tree *tree,int version _U_)
632 proto_item* lock_item = NULL;
633 proto_tree* lock_tree = NULL;
635 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
638 lock_item = proto_tree_add_item(tree, hf_nlm_share, tvb,
641 lock_tree = proto_item_add_subtree(lock_item,
645 offset = dissect_rpc_string(tvb,lock_tree,
646 hf_nlm_lock_caller_name, offset, NULL);
648 offset = dissect_nfs_fh3(tvb, offset, pinfo, lock_tree, "fh");
650 offset = dissect_rpc_data(tvb, lock_tree, hf_nlm_lock_owner, offset);
652 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_share_mode, offset);
653 offset = dissect_rpc_uint32(tvb, lock_tree, hf_nlm_share_access, offset);
656 offset = dissect_rpc_bool(tvb, tree, hf_nlm_reclaim, offset);
661 dissect_nlm_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
662 proto_tree *tree, int version _U_)
664 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
665 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
666 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_sequence, offset);
671 dissect_nlm_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
672 proto_tree *tree,int version _U_)
674 offset = dissect_rpc_string(tvb,tree,
675 hf_nlm_share_name, offset, NULL);
677 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
686 /* This function is identical for all NLM protocol versions (1-4)*/
688 dissect_nlm_gen_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
691 if(nlm_match_msgres){
692 rpc_call_info_value *rpc_call=pinfo->private_data;
693 if((rpc_call->proc==12) /* NLM_LOCK_RES */
694 || (rpc_call->proc==13) /* NLM_CANCEL_RES */
695 || (rpc_call->proc==14) /* NLM_UNLOCK_RES */
696 || (rpc_call->proc==15) ){ /* NLM_GRENTED_RES */
697 if( (!pinfo->fd->flags.visited) ){
698 nlm_register_unmatched_res(pinfo, tvb, offset);
700 nlm_print_msgres_reply(pinfo, tree, tvb);
702 /* for the fhandle matching that finds both request and
704 if(nfs_fhandle_reqrep_matching){
705 nlm_match_fhandle_reply(pinfo, tree);
710 offset = dissect_rpc_data(tvb, tree, hf_nlm_cookie, offset);
711 offset = dissect_rpc_uint32(tvb, tree, hf_nlm_stat, offset);
716 dissect_nlm1_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
719 return dissect_nlm_test(tvb,offset,pinfo,tree,1);
723 dissect_nlm4_test(tvbuff_t *tvb, int offset, packet_info *pinfo,
726 return dissect_nlm_test(tvb,offset,pinfo,tree,4);
731 dissect_nlm1_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
734 return dissect_nlm_lock(tvb,offset,pinfo,tree,1);
738 dissect_nlm4_lock(tvbuff_t *tvb, int offset, packet_info *pinfo,
741 return dissect_nlm_lock(tvb,offset,pinfo,tree,4);
746 dissect_nlm1_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
749 return dissect_nlm_cancel(tvb,offset,pinfo,tree,1);
753 dissect_nlm4_cancel(tvbuff_t *tvb, int offset, packet_info *pinfo,
756 return dissect_nlm_cancel(tvb,offset,pinfo,tree,4);
761 dissect_nlm1_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
764 return dissect_nlm_unlock(tvb,offset,pinfo,tree,1);
768 dissect_nlm4_unlock(tvbuff_t *tvb, int offset, packet_info *pinfo,
771 return dissect_nlm_unlock(tvb,offset,pinfo,tree,4);
776 dissect_nlm1_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
779 return dissect_nlm_granted(tvb,offset,pinfo,tree,1);
783 dissect_nlm4_granted(tvbuff_t *tvb, int offset, packet_info *pinfo,
786 return dissect_nlm_granted(tvb,offset,pinfo,tree,4);
791 dissect_nlm1_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo,
794 return dissect_nlm_test_res(tvb,offset,pinfo,tree,1);
798 dissect_nlm4_test_res(tvbuff_t *tvb, int offset, packet_info *pinfo,
801 return dissect_nlm_test_res(tvb,offset,pinfo,tree,4);
805 dissect_nlm3_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
808 return dissect_nlm_share(tvb,offset,pinfo,tree,3);
812 dissect_nlm4_share(tvbuff_t *tvb, int offset, packet_info *pinfo,
815 return dissect_nlm_share(tvb,offset,pinfo,tree,4);
819 dissect_nlm3_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo,
822 return dissect_nlm_shareres(tvb,offset,pinfo,tree,3);
826 dissect_nlm4_shareres(tvbuff_t *tvb, int offset, packet_info *pinfo,
829 return dissect_nlm_shareres(tvb,offset,pinfo,tree,4);
833 dissect_nlm3_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo,
836 return dissect_nlm_freeall(tvb,offset,pinfo,tree,3);
840 dissect_nlm4_freeall(tvbuff_t *tvb, int offset, packet_info *pinfo,
843 return dissect_nlm_freeall(tvb,offset,pinfo,tree,4);
849 /* proc number, "proc name", dissect_request, dissect_reply */
850 /* NULL as function pointer means: type of arguments is "void". */
851 /* NLM protocol version 1 */
852 static const vsff nlm1_proc[] = {
856 dissect_nlm1_test, dissect_nlm1_test_res },
858 dissect_nlm1_lock, dissect_nlm_gen_reply },
859 { NLM_CANCEL, "CANCEL",
860 dissect_nlm1_cancel, dissect_nlm_gen_reply },
861 { NLM_UNLOCK, "UNLOCK",
862 dissect_nlm1_unlock, dissect_nlm_gen_reply },
863 { NLM_GRANTED, "GRANTED",
864 dissect_nlm1_granted, dissect_nlm_gen_reply },
865 { NLM_TEST_MSG, "TEST_MSG",
866 dissect_nlm1_test, NULL },
867 { NLM_LOCK_MSG, "LOCK_MSG",
868 dissect_nlm1_lock, NULL },
869 { NLM_CANCEL_MSG, "CANCEL_MSG",
870 dissect_nlm1_cancel, NULL },
871 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
872 dissect_nlm1_unlock, NULL },
873 { NLM_GRANTED_MSG, "GRANTED_MSG",
874 dissect_nlm1_granted, NULL },
875 { NLM_TEST_RES, "TEST_RES",
876 dissect_nlm1_test_res, NULL },
877 { NLM_LOCK_RES, "LOCK_RES",
878 dissect_nlm_gen_reply, NULL },
879 { NLM_CANCEL_RES, "CANCEL_RES",
880 dissect_nlm_gen_reply, NULL },
881 { NLM_UNLOCK_RES, "UNLOCK_RES",
882 dissect_nlm_gen_reply, NULL },
883 { NLM_GRANTED_RES, "GRANTED_RES",
884 dissect_nlm_gen_reply, NULL },
888 /* end of NLM protocol version 1 */
890 /* NLM protocol version 2 */
891 static const vsff nlm2_proc[] = {
895 dissect_nlm1_test, dissect_nlm1_test_res },
897 dissect_nlm1_lock, dissect_nlm_gen_reply },
898 { NLM_CANCEL, "CANCEL",
899 dissect_nlm1_cancel, dissect_nlm_gen_reply },
900 { NLM_UNLOCK, "UNLOCK",
901 dissect_nlm1_unlock, dissect_nlm_gen_reply },
902 { NLM_GRANTED, "GRANTED",
903 dissect_nlm1_granted, dissect_nlm_gen_reply },
904 { NLM_TEST_MSG, "TEST_MSG",
905 dissect_nlm1_test, NULL },
906 { NLM_LOCK_MSG, "LOCK_MSG",
907 dissect_nlm1_lock, NULL },
908 { NLM_CANCEL_MSG, "CANCEL_MSG",
909 dissect_nlm1_cancel, NULL },
910 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
911 dissect_nlm1_unlock, NULL },
912 { NLM_GRANTED_MSG, "GRANTED_MSG",
913 dissect_nlm1_granted, NULL },
914 { NLM_TEST_RES, "TEST_RES",
915 dissect_nlm1_test_res, NULL },
916 { NLM_LOCK_RES, "LOCK_RES",
917 dissect_nlm_gen_reply, NULL },
918 { NLM_CANCEL_RES, "CANCEL_RES",
919 dissect_nlm_gen_reply, NULL },
920 { NLM_UNLOCK_RES, "UNLOCK_RES",
921 dissect_nlm_gen_reply, NULL },
922 { NLM_GRANTED_RES, "GRANTED_RES",
923 dissect_nlm_gen_reply, NULL },
927 /* end of NLM protocol version 2 */
929 /* NLM protocol version 3 */
930 static const vsff nlm3_proc[] = {
934 dissect_nlm1_test, dissect_nlm1_test_res },
936 dissect_nlm1_lock, dissect_nlm_gen_reply },
937 { NLM_CANCEL, "CANCEL",
938 dissect_nlm1_cancel, dissect_nlm_gen_reply },
939 { NLM_UNLOCK, "UNLOCK",
940 dissect_nlm1_unlock, dissect_nlm_gen_reply },
941 { NLM_GRANTED, "GRANTED",
942 dissect_nlm1_granted, dissect_nlm_gen_reply },
943 { NLM_TEST_MSG, "TEST_MSG",
944 dissect_nlm1_test, NULL },
945 { NLM_LOCK_MSG, "LOCK_MSG",
946 dissect_nlm1_lock, NULL },
947 { NLM_CANCEL_MSG, "CANCEL_MSG",
948 dissect_nlm1_cancel, NULL },
949 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
950 dissect_nlm1_unlock, NULL },
951 { NLM_GRANTED_MSG, "GRANTED_MSG",
952 dissect_nlm1_granted, NULL },
953 { NLM_TEST_RES, "TEST_RES",
954 dissect_nlm1_test_res, NULL },
955 { NLM_LOCK_RES, "LOCK_RES",
956 dissect_nlm_gen_reply, NULL },
957 { NLM_CANCEL_RES, "CANCEL_RES",
958 dissect_nlm_gen_reply, NULL },
959 { NLM_UNLOCK_RES, "UNLOCK_RES",
960 dissect_nlm_gen_reply, NULL },
961 { NLM_GRANTED_RES, "GRANTED_RES",
962 dissect_nlm_gen_reply, NULL },
963 { NLM_SHARE, "SHARE",
964 dissect_nlm3_share, dissect_nlm3_shareres },
965 { NLM_UNSHARE, "UNSHARE",
966 dissect_nlm3_share, dissect_nlm3_shareres },
967 { NLM_NM_LOCK, "NM_LOCK",
968 dissect_nlm1_lock, dissect_nlm_gen_reply },
969 { NLM_FREE_ALL, "FREE_ALL",
970 dissect_nlm3_freeall, NULL },
974 /* end of NLM protocol version 3 */
977 /* NLM protocol version 4 */
978 static const vsff nlm4_proc[] = {
982 dissect_nlm4_test, dissect_nlm4_test_res },
984 dissect_nlm4_lock, dissect_nlm_gen_reply },
985 { NLM_CANCEL, "CANCEL",
986 dissect_nlm4_cancel, dissect_nlm_gen_reply },
987 { NLM_UNLOCK, "UNLOCK",
988 dissect_nlm4_unlock, dissect_nlm_gen_reply },
989 { NLM_GRANTED, "GRANTED",
990 dissect_nlm4_granted, dissect_nlm_gen_reply },
991 { NLM_TEST_MSG, "TEST_MSG",
992 dissect_nlm4_test, NULL },
993 { NLM_LOCK_MSG, "LOCK_MSG",
994 dissect_nlm4_lock, NULL },
995 { NLM_CANCEL_MSG, "CANCEL_MSG",
996 dissect_nlm4_cancel, NULL },
997 { NLM_UNLOCK_MSG, "UNLOCK_MSG",
998 dissect_nlm4_unlock, NULL },
999 { NLM_GRANTED_MSG, "GRANTED_MSG",
1000 dissect_nlm4_granted, NULL },
1001 { NLM_TEST_RES, "TEST_RES",
1002 dissect_nlm4_test_res, NULL },
1003 { NLM_LOCK_RES, "LOCK_RES",
1004 dissect_nlm_gen_reply, NULL },
1005 { NLM_CANCEL_RES, "CANCEL_RES",
1006 dissect_nlm_gen_reply, NULL },
1007 { NLM_UNLOCK_RES, "UNLOCK_RES",
1008 dissect_nlm_gen_reply, NULL },
1009 { NLM_GRANTED_RES, "GRANTED_RES",
1010 dissect_nlm_gen_reply, NULL },
1011 { NLM_SHARE, "SHARE",
1012 dissect_nlm4_share, dissect_nlm4_shareres },
1013 { NLM_UNSHARE, "UNSHARE",
1014 dissect_nlm4_share, dissect_nlm4_shareres },
1015 { NLM_NM_LOCK, "NM_LOCK",
1016 dissect_nlm4_lock, dissect_nlm_gen_reply },
1017 { NLM_FREE_ALL, "FREE_ALL",
1018 dissect_nlm4_freeall, NULL },
1022 /* end of NLM protocol version 4 */
1025 static struct true_false_string yesno = { "Yes", "No" };
1029 proto_register_nlm(void)
1031 static hf_register_info hf[] = {
1033 "cookie", "nlm.cookie", FT_BYTES, BASE_DEC,
1034 NULL, 0, "cookie", HFILL }},
1036 "block", "nlm.block", FT_BOOLEAN, BASE_NONE,
1037 &yesno, 0, "block", HFILL }},
1038 { &hf_nlm_exclusive, {
1039 "exclusive", "nlm.exclusive", FT_BOOLEAN, BASE_NONE,
1040 &yesno, 0, "exclusive", HFILL }},
1042 "lock", "nlm.lock", FT_NONE, 0,
1043 NULL, 0, "lock", HFILL }},
1044 { &hf_nlm_lock_caller_name, {
1045 "caller_name", "nlm.lock.caller_name", FT_STRING, BASE_NONE,
1046 NULL, 0, "caller_name", HFILL }},
1047 { &hf_nlm_lock_owner, {
1048 "owner", "nlm.lock.owner", FT_BYTES, BASE_DEC,
1049 NULL, 0, "owner", HFILL }},
1050 { &hf_nlm_lock_svid, {
1051 "svid", "nlm.lock.svid", FT_UINT32, BASE_DEC,
1052 NULL, 0, "svid", HFILL }},
1053 { &hf_nlm_lock_l_offset64, {
1054 "l_offset", "nlm.lock.l_offset", FT_UINT64, BASE_DEC,
1055 NULL, 0, "l_offset", HFILL }},
1056 { &hf_nlm_lock_l_offset, {
1057 "l_offset", "nlm.lock.l_offset", FT_UINT32, BASE_DEC,
1058 NULL, 0, "l_offset", HFILL }},
1059 { &hf_nlm_lock_l_len64, {
1060 "l_len", "nlm.lock.l_len", FT_UINT64, BASE_DEC,
1061 NULL, 0, "l_len", HFILL }},
1062 { &hf_nlm_lock_l_len, {
1063 "l_len", "nlm.lock.l_len", FT_UINT32, BASE_DEC,
1064 NULL, 0, "l_len", HFILL }},
1065 { &hf_nlm_reclaim, {
1066 "reclaim", "nlm.reclaim", FT_BOOLEAN, BASE_NONE,
1067 &yesno, 0, "reclaim", HFILL }},
1069 "state", "nlm.state", FT_UINT32, BASE_DEC,
1070 NULL, 0, "STATD state", HFILL }},
1072 "stat", "nlm.stat", FT_UINT32, BASE_DEC,
1073 VALS(names_nlm_stats), 0, "stat", HFILL }},
1074 { &hf_nlm_test_stat, {
1075 "test_stat", "nlm.test_stat", FT_NONE, 0,
1076 NULL, 0, "test_stat", HFILL }},
1077 { &hf_nlm_test_stat_stat, {
1078 "stat", "nlm.test_stat.stat", FT_UINT32, BASE_DEC,
1079 VALS(names_nlm_stats), 0, "stat", HFILL }},
1081 "holder", "nlm.holder", FT_NONE, 0,
1082 NULL, 0, "holder", HFILL }},
1084 "share", "nlm.share", FT_NONE, 0,
1085 NULL, 0, "share", HFILL }},
1086 { &hf_nlm_share_mode, {
1087 "mode", "nlm.share.mode", FT_UINT32, BASE_DEC,
1088 VALS(names_fsh_mode), 0, "mode", HFILL }},
1089 { &hf_nlm_share_access, {
1090 "access", "nlm.share.access", FT_UINT32, BASE_DEC,
1091 VALS(names_fsh_access), 0, "access", HFILL }},
1092 { &hf_nlm_share_name, {
1093 "name", "nlm.share.name", FT_STRING, BASE_NONE,
1094 NULL, 0, "name", HFILL }},
1095 { &hf_nlm_sequence, {
1096 "sequence", "nlm.sequence", FT_INT32, BASE_DEC,
1097 NULL, 0, "sequence", HFILL }},
1098 { &hf_nlm_request_in, {
1099 "Request MSG in", "nlm.msg_in", FT_UINT32, BASE_DEC,
1100 NULL, 0, "The RES packet is a response to the MSG in this packet", HFILL }},
1101 { &hf_nlm_reply_in, {
1102 "Reply RES in", "nlm.res_in", FT_UINT32, BASE_DEC,
1103 NULL, 0, "The response to this MSG packet is in this packet", HFILL }},
1105 "Time from request", "nlm.time", FT_RELATIVE_TIME, BASE_NONE,
1106 NULL, 0, "Time between Request and Reply for async NLM calls", HFILL }},
1110 static gint *ett[] = {
1114 module_t *nlm_module;
1116 proto_nlm = proto_register_protocol("Network Lock Manager Protocol",
1118 proto_register_field_array(proto_nlm, hf, array_length(hf));
1119 proto_register_subtree_array(ett, array_length(ett));
1121 nlm_module = prefs_register_protocol(proto_nlm, NULL);
1122 prefs_register_bool_preference(nlm_module, "nlm_msg_res_matching",
1123 "Match MSG/RES packets for async NLM",
1124 "Whether the dissector will track and match MSG and RES calls for asynchronous NLM",
1126 register_init_routine(nlm_msg_res_match_init);
1130 proto_reg_handoff_nlm(void)
1132 /* Register the protocol as RPC */
1133 rpc_init_prog(proto_nlm, NLM_PROGRAM, ett_nlm);
1134 /* Register the procedure tables */
1135 rpc_init_proc_table(NLM_PROGRAM, 1, nlm1_proc);
1136 rpc_init_proc_table(NLM_PROGRAM, 2, nlm2_proc);
1137 rpc_init_proc_table(NLM_PROGRAM, 3, nlm3_proc);
1138 rpc_init_proc_table(NLM_PROGRAM, 4, nlm4_proc);