1 /* packet-klm.c 2001 Ronnie Sahlberg <rsahlber@bigpond.net.au>
2 * Routines for klm dissection
4 * Ethereal - Network traffic analyzer
5 * By Gerald Combs <gerald@zing.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
33 #include "packet-rpc.h"
34 #include "packet-nfs.h"
35 #include "packet-klm.h"
37 static int proto_klm = -1;
38 static int hf_klm_exclusive = -1;
39 static int hf_klm_lock = -1;
40 static int hf_klm_servername = -1;
41 static int hf_klm_pid = -1;
42 static int hf_klm_offset = -1;
43 static int hf_klm_len = -1;
44 static int hf_klm_stats = -1;
45 static int hf_klm_holder = -1;
46 static int hf_klm_block = -1;
48 static gint ett_klm = -1;
49 static gint ett_klm_lock = -1;
50 static gint ett_klm_holder = -1;
52 const value_string names_klm_stats[] =
55 { KLM_GRANTED, "KLM_GRANTED" },
57 { KLM_DENIED, "KLM_DENIED" },
58 #define KLM_DENIED_NOLOCKS 2
59 { KLM_DENIED_NOLOCKS, "KLM_DENIED_NOLOCKS" },
61 { KLM_WORKING, "KLM_WORKING" },
65 dissect_holder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
67 proto_item* lock_item = NULL;
68 proto_tree* lock_tree = NULL;
70 lock_item = proto_tree_add_item(tree, hf_klm_holder, tvb,
71 offset, tvb_length_remaining(tvb, offset), FALSE);
73 lock_tree = proto_item_add_subtree(lock_item, ett_klm_holder);
75 offset = dissect_rpc_bool_tvb( tvb, pinfo, lock_tree,
76 hf_klm_exclusive, offset);
78 offset = dissect_rpc_uint32_tvb(tvb, pinfo, lock_tree,
81 offset = dissect_rpc_uint32_tvb(tvb, pinfo, lock_tree,
82 hf_klm_offset, offset);
84 offset = dissect_rpc_uint32_tvb(tvb, pinfo, lock_tree,
91 dissect_lock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
93 proto_item* lock_item = NULL;
94 proto_tree* lock_tree = NULL;
96 lock_item = proto_tree_add_item(tree, hf_klm_lock, tvb,
97 offset, tvb_length_remaining(tvb, offset), FALSE);
99 lock_tree = proto_item_add_subtree(lock_item, ett_klm_lock);
101 offset = dissect_rpc_string_tvb(tvb, pinfo, lock_tree,
102 hf_klm_servername, offset, NULL);
104 offset = dissect_nfs_fh3(tvb, offset, pinfo, lock_tree,"fh");
106 offset = dissect_rpc_uint32_tvb(tvb, pinfo, lock_tree,
109 offset = dissect_rpc_uint32_tvb(tvb, pinfo, lock_tree,
110 hf_klm_offset, offset);
112 offset = dissect_rpc_uint32_tvb(tvb, pinfo, lock_tree,
119 dissect_klm_unlock_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
121 offset = dissect_lock(tvb, pinfo, tree, offset);
127 dissect_klm_stat_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
130 offset = dissect_rpc_uint32_tvb(tvb, pinfo, tree,
131 hf_klm_stats, offset);
137 dissect_klm_lock_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
139 offset = dissect_rpc_bool_tvb( tvb, pinfo, tree,
140 hf_klm_block, offset);
142 offset = dissect_rpc_bool_tvb( tvb, pinfo, tree,
143 hf_klm_exclusive, offset);
145 offset = dissect_lock(tvb, pinfo, tree, offset);
151 dissect_klm_test_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
155 stats = tvb_get_ntohl(tvb, offset);
157 offset = dissect_rpc_uint32_tvb(tvb, pinfo, tree,
158 hf_klm_stats, offset);
160 if (stats == KLM_DENIED) {
161 offset = dissect_holder(tvb, pinfo, tree, offset);
168 dissect_klm_test_call(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
170 offset = dissect_rpc_bool_tvb( tvb, pinfo, tree,
171 hf_klm_exclusive, offset);
173 offset = dissect_lock(tvb, pinfo, tree, offset);
179 /* proc number, "proc name", dissect_request, dissect_reply */
180 /* NULL as function pointer means: type of arguments is "void". */
181 static const vsff klm1_proc[] = {
182 { KLMPROC_TEST, "TEST",
183 dissect_klm_test_call, dissect_klm_test_reply },
184 { KLMPROC_LOCK, "LOCK",
185 dissect_klm_lock_call, dissect_klm_stat_reply },
186 { KLMPROC_CANCEL, "CANCEL",
187 dissect_klm_lock_call, dissect_klm_stat_reply },
188 { KLMPROC_UNLOCK, "UNLOCK",
189 dissect_klm_unlock_call, dissect_klm_stat_reply },
190 { 0, NULL, NULL, NULL }
194 proto_register_klm(void)
196 static struct true_false_string tfs_exclusive = { "Exclusive", "Not exclusive" };
197 static struct true_false_string tfs_block = { "Block", "Do not block" };
199 static hf_register_info hf[] = {
200 { &hf_klm_exclusive, {
201 "exclusive", "klm.exclusive", FT_BOOLEAN, BASE_NONE,
202 &tfs_exclusive, 0, "Exclusive lock" }},
205 "lock", "klm.lock", FT_NONE, BASE_NONE,
206 NULL, 0, "KLM lock structure" }},
208 { &hf_klm_servername, {
209 "server name", "klm.servername", FT_STRING, BASE_NONE,
210 NULL, 0, "Server name" }},
213 "pid", "klm.pid", FT_UINT32, BASE_DEC,
214 NULL, 0, "ProcessID" }},
217 "offset", "klm.offset", FT_UINT32, BASE_DEC,
218 NULL, 0, "File offset" }},
221 "length", "klm.len", FT_UINT32, BASE_DEC,
222 NULL, 0, "Length of lock region" }},
225 "stats", "klm.stats", FT_UINT32, BASE_DEC,
226 VALS(names_klm_stats), 0, "stats" }},
229 "holder", "klm.holder", FT_NONE, BASE_NONE,
230 NULL, 0, "KLM lock holder" }},
233 "block", "klm.block", FT_BOOLEAN, BASE_NONE,
234 &tfs_block, 0, "Block" }},
238 static gint *ett[] = {
244 proto_klm = proto_register_protocol("Kernel Lock Manager",
246 proto_register_field_array(proto_klm, hf, array_length(hf));
247 proto_register_subtree_array(ett, array_length(ett));
251 proto_reg_handoff_klm(void)
253 /* Register the protocol as RPC */
254 rpc_init_prog(proto_klm, KLM_PROGRAM, ett_klm);
255 /* Register the procedure tables */
256 rpc_init_proc_table(KLM_PROGRAM, 1, klm1_proc);