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
14 #include <wsutil/array.h>
15 #include "packet-nfs.h"
17 void proto_register_klm(void);
18 void proto_reg_handoff_klm(void);
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
;
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
[] =
46 { KLM_GRANTED
, "KLM_GRANTED" },
48 { KLM_DENIED
, "KLM_DENIED" },
49 #define KLM_DENIED_NOLOCKS 2
50 { KLM_DENIED_NOLOCKS
, "KLM_DENIED_NOLOCKS" },
52 { KLM_WORKING
, "KLM_WORKING" },
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
,
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
,
73 offset
= dissect_rpc_uint32(tvb
, lock_tree
,
74 hf_klm_offset
, offset
);
76 offset
= dissect_rpc_uint32(tvb
, lock_tree
,
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
,
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
,
101 offset
= dissect_rpc_uint32(tvb
, lock_tree
,
102 hf_klm_offset
, offset
);
104 offset
= dissect_rpc_uint32(tvb
, lock_tree
,
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
);
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);
123 dissect_klm_lock_call(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
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
);
138 dissect_klm_test_reply(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void* data _U_
)
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
);
156 dissect_klm_test_call(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
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
);
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" },
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
}},
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
}},
214 "pid", "klm.pid", FT_UINT32
, BASE_DEC
,
215 NULL
, 0, "ProcessID", HFILL
}},
218 "offset", "klm.offset", FT_UINT32
, BASE_DEC
,
219 NULL
, 0, "File offset", HFILL
}},
222 "length", "klm.len", FT_UINT32
, BASE_DEC
,
223 NULL
, 0, "Length of lock region", HFILL
}},
226 "stats", "klm.stats", FT_UINT32
, BASE_DEC
,
227 VALS(names_klm_stats
), 0, NULL
, HFILL
}},
230 "holder", "klm.holder", FT_NONE
, BASE_NONE
,
231 NULL
, 0, "KLM lock holder", HFILL
}},
234 "block", "klm.block", FT_BOOLEAN
, BASE_NONE
,
235 TFS(&tfs_block
), 0x0, NULL
, HFILL
}},
239 static int *ett
[] = {
245 proto_klm
= proto_register_protocol("Kernel Lock Manager",
247 proto_register_field_array(proto_klm
, hf
, array_length(hf
));
248 proto_register_subtree_array(ett
, array_length(ett
));
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
265 * indent-tabs-mode: t
268 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
269 * :indentSize=8:tabSize=8:noTabs=false: