Coverage Report

Created: 2026-01-02 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-klm.c
Line
Count
Source
1
/* packet-klm.c    2001 Ronnie Sahlberg <See AUTHORS for email>
2
 * Routines for klm dissection
3
 *
4
 * Wireshark - Network traffic analyzer
5
 * By Gerald Combs <gerald@wireshark.org>
6
 * Copyright 1998 Gerald Combs
7
 *
8
 * SPDX-License-Identifier: GPL-2.0-or-later
9
 */
10
11
#include "config.h"
12
13
#include <epan/tfs.h>
14
#include <wsutil/array.h>
15
#include "packet-nfs.h"
16
17
void proto_register_klm(void);
18
void proto_reg_handoff_klm(void);
19
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;
31
32
static int ett_klm;
33
static int ett_klm_lock;
34
static int ett_klm_holder;
35
36
#define KLMPROC_TEST   1
37
#define KLMPROC_LOCK   2
38
#define KLMPROC_CANCEL 3
39
#define KLMPROC_UNLOCK 4
40
41
14
#define KLM_PROGRAM 100020
42
43
static const value_string names_klm_stats[] =
44
{
45
#define KLM_GRANTED   0
46
    { KLM_GRANTED,  "KLM_GRANTED" },
47
0
#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 }
54
};
55
56
static int
57
dissect_holder(tvbuff_t *tvb, proto_tree *tree, int offset)
58
0
{
59
0
  proto_item* lock_item = NULL;
60
0
  proto_tree* lock_tree = NULL;
61
62
0
  lock_item = proto_tree_add_item(tree, hf_klm_holder, tvb,
63
0
      offset, -1, ENC_NA);
64
65
0
  lock_tree = proto_item_add_subtree(lock_item, ett_klm_holder);
66
67
0
  offset = dissect_rpc_bool( tvb, lock_tree,
68
0
      hf_klm_exclusive, offset);
69
70
0
  offset = dissect_rpc_uint32(tvb, lock_tree,
71
0
      hf_klm_pid, offset);
72
73
0
  offset = dissect_rpc_uint32(tvb, lock_tree,
74
0
      hf_klm_offset, offset);
75
76
0
  offset = dissect_rpc_uint32(tvb, lock_tree,
77
0
      hf_klm_len, offset);
78
79
0
  return offset;
80
0
}
81
82
static int
83
dissect_lock(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, int offset, rpc_call_info_value *civ)
84
0
{
85
0
  proto_item* lock_item = NULL;
86
0
  proto_tree* lock_tree = NULL;
87
88
0
  lock_item = proto_tree_add_item(tree, hf_klm_lock, tvb,
89
0
      offset, -1, ENC_NA);
90
91
0
  lock_tree = proto_item_add_subtree(lock_item, ett_klm_lock);
92
93
0
  offset = dissect_rpc_string(tvb, pinfo, lock_tree,
94
0
      hf_klm_servername, offset, NULL);
95
96
0
  offset = dissect_nfs3_fh(tvb, offset, pinfo, lock_tree,"fh", NULL, civ);
97
98
0
  offset = dissect_rpc_uint32(tvb, lock_tree,
99
0
      hf_klm_pid, offset);
100
101
0
  offset = dissect_rpc_uint32(tvb, lock_tree,
102
0
      hf_klm_offset, offset);
103
104
0
  offset = dissect_rpc_uint32(tvb, lock_tree,
105
0
      hf_klm_len, offset);
106
107
0
  return offset;
108
0
}
109
110
static int
111
dissect_klm_unlock_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
112
0
{
113
0
  return dissect_lock(tvb, pinfo, tree, 0, (rpc_call_info_value*)data);
114
0
}
115
116
static int
117
dissect_klm_stat_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
118
0
{
119
0
  return dissect_rpc_uint32(tvb, tree, hf_klm_stats, 0);
120
0
}
121
122
static int
123
dissect_klm_lock_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
124
0
{
125
0
  int offset = 0;
126
0
  offset = dissect_rpc_bool( tvb, tree,
127
0
      hf_klm_block, offset);
128
129
0
  offset = dissect_rpc_bool( tvb, tree,
130
0
      hf_klm_exclusive, offset);
131
132
0
  offset = dissect_lock(tvb, pinfo, tree, offset, (rpc_call_info_value*)data);
133
134
0
  return offset;
135
0
}
136
137
static int
138
dissect_klm_test_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
139
0
{
140
0
  int32_t stats;
141
0
  int offset = 0;
142
143
0
  stats = tvb_get_ntohl(tvb, offset);
144
145
0
  offset = dissect_rpc_uint32(tvb, tree,
146
0
      hf_klm_stats, offset);
147
148
0
  if (stats == KLM_DENIED) {
149
0
    offset = dissect_holder(tvb, tree, offset);
150
0
  }
151
152
0
  return offset;
153
0
}
154
155
static int
156
dissect_klm_test_call(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
157
0
{
158
0
  int offset = 0;
159
0
  offset = dissect_rpc_bool( tvb, tree,
160
0
      hf_klm_exclusive, offset);
161
162
0
  offset = dissect_lock(tvb, pinfo, tree, offset, (rpc_call_info_value*)data);
163
164
0
  return offset;
165
0
}
166
167
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 }
179
};
180
static const rpc_prog_vers_info klm_vers_info[] = {
181
  { 1, klm1_proc, &hf_klm_procedure_v1 },
182
};
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}
189
};
190
191
void
192
proto_register_klm(void)
193
14
{
194
14
  static struct true_false_string tfs_exclusive = { "Exclusive", "Not exclusive" };
195
14
  static struct true_false_string tfs_block = { "Block", "Do not block" };
196
197
14
  static hf_register_info hf[] = {
198
14
    { &hf_klm_procedure_v1, {
199
14
      "V1 Procedure", "klm.procedure_v1", FT_UINT32, BASE_DEC,
200
14
      VALS(klm1_proc_vals), 0, NULL, HFILL }},
201
14
    { &hf_klm_exclusive, {
202
14
      "exclusive", "klm.exclusive", FT_BOOLEAN, BASE_NONE,
203
14
      TFS(&tfs_exclusive), 0x0, "Exclusive lock", HFILL }},
204
205
14
    { &hf_klm_lock, {
206
14
      "lock", "klm.lock", FT_NONE, BASE_NONE,
207
14
      NULL, 0, "KLM lock structure", HFILL }},
208
209
14
    { &hf_klm_servername, {
210
14
      "server name", "klm.servername", FT_STRING, BASE_NONE,
211
14
      NULL, 0, NULL, HFILL }},
212
213
14
    { &hf_klm_pid, {
214
14
      "pid", "klm.pid", FT_UINT32, BASE_DEC,
215
14
      NULL, 0, "ProcessID", HFILL }},
216
217
14
    { &hf_klm_offset, {
218
14
      "offset", "klm.offset", FT_UINT32, BASE_DEC,
219
14
      NULL, 0, "File offset", HFILL }},
220
221
14
    { &hf_klm_len, {
222
14
      "length", "klm.len", FT_UINT32, BASE_DEC,
223
14
      NULL, 0, "Length of lock region", HFILL }},
224
225
14
    { &hf_klm_stats, {
226
14
      "stats", "klm.stats", FT_UINT32, BASE_DEC,
227
14
      VALS(names_klm_stats), 0, NULL, HFILL }},
228
229
14
    { &hf_klm_holder, {
230
14
      "holder", "klm.holder", FT_NONE, BASE_NONE,
231
14
      NULL, 0, "KLM lock holder", HFILL }},
232
233
14
    { &hf_klm_block, {
234
14
      "block", "klm.block", FT_BOOLEAN, BASE_NONE,
235
14
      TFS(&tfs_block), 0x0, NULL, HFILL }},
236
237
14
  };
238
239
14
  static int *ett[] = {
240
14
    &ett_klm,
241
14
    &ett_klm_lock,
242
14
    &ett_klm_holder,
243
14
  };
244
245
14
  proto_klm = proto_register_protocol("Kernel Lock Manager",
246
14
      "KLM", "klm");
247
14
  proto_register_field_array(proto_klm, hf, array_length(hf));
248
14
  proto_register_subtree_array(ett, array_length(ett));
249
14
}
250
251
void
252
proto_reg_handoff_klm(void)
253
14
{
254
  /* Register the protocol as RPC */
255
14
  rpc_init_prog(proto_klm, KLM_PROGRAM, ett_klm,
256
      G_N_ELEMENTS(klm_vers_info), klm_vers_info);
257
14
}
258
259
/*
260
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
261
 *
262
 * Local variables:
263
 * c-basic-offset: 8
264
 * tab-width: 8
265
 * indent-tabs-mode: t
266
 * End:
267
 *
268
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
269
 * :indentSize=8:tabSize=8:noTabs=false:
270
 */