Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-klm.c
blobeb1df126784708fa019132e131ef3c55d936bc7f
1 /* packet-klm.c 2001 Ronnie Sahlberg <See AUTHORS for email>
2 * Routines for klm dissection
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <epan/tfs.h>
14 #include <wsutil/array.h>
15 #include "packet-nfs.h"
17 void proto_register_klm(void);
18 void proto_reg_handoff_klm(void);
20 static int proto_klm;
21 static int hf_klm_procedure_v1;
22 static int hf_klm_exclusive;
23 static int hf_klm_lock;
24 static int hf_klm_servername;
25 static int hf_klm_pid;
26 static int hf_klm_offset;
27 static int hf_klm_len;
28 static int hf_klm_stats;
29 static int hf_klm_holder;
30 static int hf_klm_block;
32 static int ett_klm;
33 static int ett_klm_lock;
34 static int ett_klm_holder;
36 #define KLMPROC_TEST 1
37 #define KLMPROC_LOCK 2
38 #define KLMPROC_CANCEL 3
39 #define KLMPROC_UNLOCK 4
41 #define KLM_PROGRAM 100020
43 static const value_string names_klm_stats[] =
45 #define KLM_GRANTED 0
46 { KLM_GRANTED, "KLM_GRANTED" },
47 #define KLM_DENIED 1
48 { KLM_DENIED, "KLM_DENIED" },
49 #define KLM_DENIED_NOLOCKS 2
50 { KLM_DENIED_NOLOCKS, "KLM_DENIED_NOLOCKS" },
51 #define KLM_WORKING 3
52 { KLM_WORKING, "KLM_WORKING" },
53 { 0, NULL }
56 static int
57 dissect_holder(tvbuff_t *tvb, proto_tree *tree, int offset)
59 proto_item* lock_item = NULL;
60 proto_tree* lock_tree = NULL;
62 lock_item = proto_tree_add_item(tree, hf_klm_holder, tvb,
63 offset, -1, ENC_NA);
65 lock_tree = proto_item_add_subtree(lock_item, ett_klm_holder);
67 offset = dissect_rpc_bool( tvb, lock_tree,
68 hf_klm_exclusive, offset);
70 offset = dissect_rpc_uint32(tvb, lock_tree,
71 hf_klm_pid, offset);
73 offset = dissect_rpc_uint32(tvb, lock_tree,
74 hf_klm_offset, offset);
76 offset = dissect_rpc_uint32(tvb, lock_tree,
77 hf_klm_len, offset);
79 return offset;
82 static int
83 dissect_lock(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, int offset, rpc_call_info_value *civ)
85 proto_item* lock_item = NULL;
86 proto_tree* lock_tree = NULL;
88 lock_item = proto_tree_add_item(tree, hf_klm_lock, tvb,
89 offset, -1, ENC_NA);
91 lock_tree = proto_item_add_subtree(lock_item, ett_klm_lock);
93 offset = dissect_rpc_string(tvb, lock_tree,
94 hf_klm_servername, offset, NULL);
96 offset = dissect_nfs3_fh(tvb, offset, pinfo, lock_tree,"fh", NULL, civ);
98 offset = dissect_rpc_uint32(tvb, lock_tree,
99 hf_klm_pid, offset);
101 offset = dissect_rpc_uint32(tvb, lock_tree,
102 hf_klm_offset, offset);
104 offset = dissect_rpc_uint32(tvb, lock_tree,
105 hf_klm_len, offset);
107 return offset;
110 static int
111 dissect_klm_unlock_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
113 return dissect_lock(tvb, pinfo, tree, 0, (rpc_call_info_value*)data);
116 static int
117 dissect_klm_stat_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
119 return dissect_rpc_uint32(tvb, tree, hf_klm_stats, 0);
122 static int
123 dissect_klm_lock_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
125 int offset = 0;
126 offset = dissect_rpc_bool( tvb, tree,
127 hf_klm_block, offset);
129 offset = dissect_rpc_bool( tvb, tree,
130 hf_klm_exclusive, offset);
132 offset = dissect_lock(tvb, pinfo, tree, offset, (rpc_call_info_value*)data);
134 return offset;
137 static int
138 dissect_klm_test_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
140 int32_t stats;
141 int offset = 0;
143 stats = tvb_get_ntohl(tvb, offset);
145 offset = dissect_rpc_uint32(tvb, tree,
146 hf_klm_stats, offset);
148 if (stats == KLM_DENIED) {
149 offset = dissect_holder(tvb, tree, offset);
152 return offset;
155 static int
156 dissect_klm_test_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
158 int offset = 0;
159 offset = dissect_rpc_bool( tvb, tree,
160 hf_klm_exclusive, offset);
162 offset = dissect_lock(tvb, pinfo, tree, offset, (rpc_call_info_value*)data);
164 return offset;
168 /* proc number, "proc name", dissect_request, dissect_reply */
169 static const vsff klm1_proc[] = {
170 { KLMPROC_TEST, "TEST",
171 dissect_klm_test_call, dissect_klm_test_reply },
172 { KLMPROC_LOCK, "LOCK",
173 dissect_klm_lock_call, dissect_klm_stat_reply },
174 { KLMPROC_CANCEL, "CANCEL",
175 dissect_klm_lock_call, dissect_klm_stat_reply },
176 { KLMPROC_UNLOCK, "UNLOCK",
177 dissect_klm_unlock_call, dissect_klm_stat_reply },
178 { 0, NULL, NULL, NULL }
180 static const rpc_prog_vers_info klm_vers_info[] = {
181 { 1, klm1_proc, &hf_klm_procedure_v1 },
183 static const value_string klm1_proc_vals[] = {
184 { KLMPROC_TEST, "TEST" },
185 { KLMPROC_LOCK, "LOCK" },
186 { KLMPROC_CANCEL, "CANCEL" },
187 { KLMPROC_UNLOCK, "UNLOCK" },
188 { 0, NULL}
191 void
192 proto_register_klm(void)
194 static struct true_false_string tfs_exclusive = { "Exclusive", "Not exclusive" };
195 static struct true_false_string tfs_block = { "Block", "Do not block" };
197 static hf_register_info hf[] = {
198 { &hf_klm_procedure_v1, {
199 "V1 Procedure", "klm.procedure_v1", FT_UINT32, BASE_DEC,
200 VALS(klm1_proc_vals), 0, NULL, HFILL }},
201 { &hf_klm_exclusive, {
202 "exclusive", "klm.exclusive", FT_BOOLEAN, BASE_NONE,
203 TFS(&tfs_exclusive), 0x0, "Exclusive lock", HFILL }},
205 { &hf_klm_lock, {
206 "lock", "klm.lock", FT_NONE, BASE_NONE,
207 NULL, 0, "KLM lock structure", HFILL }},
209 { &hf_klm_servername, {
210 "server name", "klm.servername", FT_STRING, BASE_NONE,
211 NULL, 0, NULL, HFILL }},
213 { &hf_klm_pid, {
214 "pid", "klm.pid", FT_UINT32, BASE_DEC,
215 NULL, 0, "ProcessID", HFILL }},
217 { &hf_klm_offset, {
218 "offset", "klm.offset", FT_UINT32, BASE_DEC,
219 NULL, 0, "File offset", HFILL }},
221 { &hf_klm_len, {
222 "length", "klm.len", FT_UINT32, BASE_DEC,
223 NULL, 0, "Length of lock region", HFILL }},
225 { &hf_klm_stats, {
226 "stats", "klm.stats", FT_UINT32, BASE_DEC,
227 VALS(names_klm_stats), 0, NULL, HFILL }},
229 { &hf_klm_holder, {
230 "holder", "klm.holder", FT_NONE, BASE_NONE,
231 NULL, 0, "KLM lock holder", HFILL }},
233 { &hf_klm_block, {
234 "block", "klm.block", FT_BOOLEAN, BASE_NONE,
235 TFS(&tfs_block), 0x0, NULL, HFILL }},
239 static int *ett[] = {
240 &ett_klm,
241 &ett_klm_lock,
242 &ett_klm_holder,
245 proto_klm = proto_register_protocol("Kernel Lock Manager",
246 "KLM", "klm");
247 proto_register_field_array(proto_klm, hf, array_length(hf));
248 proto_register_subtree_array(ett, array_length(ett));
251 void
252 proto_reg_handoff_klm(void)
254 /* Register the protocol as RPC */
255 rpc_init_prog(proto_klm, KLM_PROGRAM, ett_klm,
256 G_N_ELEMENTS(klm_vers_info), klm_vers_info);
260 * Editor modelines - https://www.wireshark.org/tools/modelines.html
262 * Local variables:
263 * c-basic-offset: 8
264 * tab-width: 8
265 * indent-tabs-mode: t
266 * End:
268 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
269 * :indentSize=8:tabSize=8:noTabs=false: