Coverage Report

Created: 2026-11-12 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-stat.c
Line
Count
Source
1
/* packet-stat.c
2
 * Routines for stat dissection
3
 *
4
 * Wireshark - Network traffic analyzer
5
 * By Gerald Combs <gerald@wireshark.org>
6
 * Copyright 1998 Gerald Combs
7
 *
8
 * Copied from packet-smb.c
9
 *
10
 * 2001  Ronnie Sahlberg <See AUTHORS for email>
11
 *     Added the dissectors for STAT protocol
12
 *
13
 * SPDX-License-Identifier: GPL-2.0-or-later
14
 */
15
#include "config.h"
16
17
#include "packet-rpc.h"
18
#include "packet-stat.h"
19
20
void proto_register_stat(void);
21
void proto_reg_handoff_stat(void);
22
23
static const value_string stat1_proc_vals[] = {
24
  { 0,                   "NULL" },
25
  { STATPROC_STAT,       "STAT" },
26
  { STATPROC_MON,        "MON" },
27
  { STATPROC_UNMON,      "UNMON" },
28
  { STATPROC_UNMON_ALL,  "UNMON_ALL" },
29
  { STATPROC_SIMU_CRASH, "SIMU_CRASH" },
30
  { STATPROC_NOTIFY,     "NOTIFY" },
31
  { 0, NULL }
32
};
33
34
static const value_string stat_res[] =
35
{
36
  { 0, "STAT_SUCC" },
37
  { 1, "STAT_FAIL" },
38
  { 0, NULL }
39
};
40
41
static int proto_stat;
42
43
static int hf_stat_mon;
44
static int hf_stat_mon_id_name;
45
static int hf_stat_mon_name;
46
static int hf_stat_my_id;
47
static int hf_stat_my_id_hostname;
48
static int hf_stat_my_id_proc;
49
static int hf_stat_my_id_prog;
50
static int hf_stat_my_id_vers;
51
static int hf_stat_priv;
52
static int hf_stat_procedure_v1;
53
static int hf_stat_stat_chge;
54
static int hf_stat_stat_res;
55
static int hf_stat_stat_res_res;
56
static int hf_stat_stat_res_state;
57
static int hf_stat_state;
58
59
static int ett_stat;
60
static int ett_stat_stat_res;
61
static int ett_stat_mon;
62
static int ett_stat_my_id;
63
static int ett_stat_stat_chge;
64
65
0
#define STAT_SUCC 0
66
#define STAT_FAIL 1
67
68
/* Calculate length (including padding) of my_id structure.
69
 * First read the length of the string and round it upwards to nearest
70
 * multiple of 4, then add 16 (4*uint32)
71
 */
72
static int
73
my_id_len(tvbuff_t *tvb, int offset)
74
0
{
75
0
  uint64_t len;
76
77
0
  len = tvb_get_ntohl(tvb, offset);
78
0
  len = (len + 3) & ~(uint64_t)3;
79
0
  len += 16;
80
81
0
  return (len > INT32_MAX) ? INT32_MAX : (int)len;
82
0
}
83
84
/* Calculate length (including padding) of my_id structure.
85
 * First read the length of the string and round it upwards to nearest
86
 * multiple of 4, then add 4 (string len) and size of my_id struct.
87
 */
88
static int
89
mon_id_len(tvbuff_t *tvb, int offset)
90
0
{
91
0
  uint64_t len;
92
93
0
  len = tvb_get_ntohl(tvb, offset);
94
0
  len = (len + 3) & ~(uint64_t)3;
95
0
  len += 4;
96
0
  if (len > INT32_MAX) {
97
0
    return INT32_MAX;
98
0
  }
99
100
0
  len += my_id_len(tvb, offset + (int)len);
101
0
  return (len > INT32_MAX) ? INT32_MAX : (int)len;
102
0
}
103
104
static int
105
dissect_stat_stat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
106
0
{
107
0
  return dissect_rpc_string(tvb,pinfo,tree,hf_stat_mon_name,0,NULL);
108
0
}
109
110
static int
111
dissect_stat_stat_res(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
112
0
{
113
0
  proto_item *sub_item;
114
0
  proto_tree *sub_tree;
115
0
  int32_t res;
116
0
  unsigned offset = 0;
117
118
0
  sub_item = proto_tree_add_item(tree, hf_stat_stat_res, tvb,
119
0
        offset, -1, ENC_NA);
120
0
  sub_tree = proto_item_add_subtree(sub_item, ett_stat_stat_res);
121
122
0
  res = tvb_get_ntohl(tvb, offset);
123
0
  offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_stat_res_res,offset);
124
125
0
  if (res==STAT_SUCC) {
126
0
    offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_stat_res_state,offset);
127
0
  } else {
128
0
    offset += 4;
129
0
  }
130
131
0
  return offset;
132
0
}
133
134
static int
135
dissect_stat_my_id(tvbuff_t *tvb, packet_info* pinfo, int offset, proto_tree *tree)
136
0
{
137
0
  proto_item *sub_item;
138
0
  proto_tree *sub_tree;
139
140
0
  sub_item = proto_tree_add_item(tree, hf_stat_my_id, tvb,
141
0
        offset, my_id_len(tvb,offset), ENC_NA);
142
0
  sub_tree = proto_item_add_subtree(sub_item, ett_stat_my_id);
143
144
0
  offset = dissect_rpc_string(tvb,pinfo,sub_tree,hf_stat_my_id_hostname,offset,NULL);
145
0
  offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_my_id_prog,offset);
146
0
  offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_my_id_vers,offset);
147
0
  offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_my_id_proc,offset);
148
149
0
  return offset;
150
0
}
151
152
static int
153
dissect_stat_mon_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
154
0
{
155
0
  proto_item *sub_item;
156
0
  proto_tree *sub_tree;
157
0
  unsigned offset = 0;
158
159
0
  sub_item = proto_tree_add_item(tree, hf_stat_mon, tvb,
160
0
        offset, mon_id_len(tvb,offset), ENC_NA);
161
0
  sub_tree = proto_item_add_subtree(sub_item, ett_stat_mon);
162
163
0
  offset = dissect_rpc_string(tvb,pinfo,sub_tree,hf_stat_mon_id_name,offset,NULL);
164
165
0
  offset = dissect_stat_my_id(tvb,pinfo,offset,sub_tree);
166
167
0
  return offset;
168
0
}
169
170
static int
171
dissect_stat_priv(tvbuff_t *tvb, int offset, proto_tree *tree)
172
0
{
173
0
  proto_tree_add_item(tree, hf_stat_priv, tvb, offset, 16, ENC_NA);
174
0
  offset += 16;
175
176
0
  return offset;
177
0
}
178
179
static int
180
dissect_stat_mon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
181
0
{
182
0
  int offset = dissect_stat_mon_id(tvb,pinfo,tree,data);
183
184
0
  offset = dissect_stat_priv(tvb,offset,tree);
185
0
  return offset;
186
0
}
187
188
static int
189
dissect_stat_state(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
190
0
{
191
0
  return dissect_rpc_uint32(tvb,tree,hf_stat_state,0);
192
0
}
193
194
static int
195
dissect_stat_notify(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
196
0
{
197
0
  proto_item *sub_item;
198
0
  proto_tree *sub_tree;
199
0
  unsigned offset = 0;
200
0
  int start_offset = offset;
201
202
0
  sub_item = proto_tree_add_item(tree, hf_stat_stat_chge, tvb,
203
0
        offset, -1, ENC_NA);
204
0
  sub_tree = proto_item_add_subtree(sub_item, ett_stat_stat_chge);
205
206
0
  offset = dissect_rpc_string(tvb,pinfo,sub_tree,hf_stat_mon_id_name,offset,NULL);
207
208
0
  offset = dissect_rpc_uint32(tvb,tree,hf_stat_state,offset);
209
210
0
  if(sub_item)
211
0
    proto_item_set_len(sub_item, offset - start_offset);
212
213
0
  return offset;
214
0
}
215
216
static int
217
dissect_stat_umon_all(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
218
0
{
219
0
  return dissect_stat_my_id(tvb,pinfo,0,tree);
220
0
}
221
222
/* proc number, "proc name", dissect_request, dissect_reply */
223
224
static const vsff stat1_proc[] = {
225
  { 0, "NULL",
226
    dissect_rpc_void, dissect_rpc_void },
227
  { STATPROC_STAT,       "STAT",
228
    dissect_stat_stat, dissect_stat_stat_res },
229
  { STATPROC_MON,        "MON",
230
    dissect_stat_mon, dissect_stat_stat_res },
231
  { STATPROC_UNMON,      "UNMON",
232
    dissect_stat_mon_id, dissect_stat_state },
233
  { STATPROC_UNMON_ALL,  "UNMON_ALL",
234
    dissect_stat_umon_all, dissect_stat_state },
235
  { STATPROC_SIMU_CRASH, "SIMU_CRASH",
236
    dissect_rpc_void, dissect_rpc_void },
237
  { STATPROC_NOTIFY,     "NOTIFY",
238
    dissect_stat_notify, dissect_rpc_void },
239
  { 0, NULL, NULL, NULL }
240
};
241
/* end of stat version 1 */
242
243
244
static const rpc_prog_vers_info stat_vers_info[] = {
245
  { 1, stat1_proc, &hf_stat_procedure_v1 },
246
};
247
248
void
249
proto_register_stat(void)
250
16
{
251
16
  static hf_register_info hf[] = {
252
16
    { &hf_stat_procedure_v1,
253
16
      { "V1 Procedure", "stat.procedure_v1",
254
16
        FT_UINT32, BASE_DEC, VALS(stat1_proc_vals), 0,
255
16
        NULL, HFILL }
256
16
    },
257
16
    { &hf_stat_mon_name,
258
16
      { "Name", "stat.name",
259
16
        FT_STRING, BASE_NONE, NULL, 0,
260
16
        NULL, HFILL }
261
16
    },
262
16
    { &hf_stat_stat_res,
263
16
      { "Status Result", "stat.stat_res",
264
16
        FT_NONE, BASE_NONE, NULL, 0,
265
16
        NULL, HFILL }
266
16
    },
267
16
    { &hf_stat_stat_res_res,
268
16
      { "Result", "stat.stat_res.res",
269
16
        FT_UINT32, BASE_DEC, VALS(stat_res), 0,
270
16
        NULL, HFILL }
271
16
    },
272
16
    { &hf_stat_stat_res_state,
273
16
      { "State", "stat.stat_res.state",
274
16
        FT_UINT32, BASE_DEC, NULL, 0,
275
16
        NULL, HFILL }
276
16
    },
277
16
    { &hf_stat_state,
278
16
      { "State", "stat.state",
279
16
        FT_UINT32, BASE_DEC, NULL, 0,
280
16
        "State of local NSM", HFILL }
281
16
    },
282
16
    { &hf_stat_mon,
283
16
      { "Monitor", "stat.mon",
284
16
        FT_NONE, BASE_NONE, NULL, 0,
285
16
        "Monitor Host", HFILL }
286
16
    },
287
16
    { &hf_stat_mon_id_name,
288
16
      { "Monitor ID Name", "stat.mon_id.name",
289
16
        FT_STRING, BASE_NONE, NULL, 0,
290
16
        NULL, HFILL }
291
16
    },
292
16
    { &hf_stat_my_id,
293
16
      { "My ID", "stat.my_id",
294
16
        FT_NONE, BASE_NONE, NULL, 0,
295
16
        "My_ID structure", HFILL }
296
16
    },
297
16
    { &hf_stat_my_id_hostname,
298
16
      { "Hostname", "stat.my_id.hostname",
299
16
        FT_STRING, BASE_NONE, NULL, 0,
300
16
        "My_ID Host to callback", HFILL }
301
16
    },
302
16
    { &hf_stat_my_id_prog,
303
16
      { "Program", "stat.my_id.prog",
304
16
        FT_UINT32, BASE_DEC, NULL, 0,
305
16
        "My_ID Program to callback", HFILL }
306
16
    },
307
16
    { &hf_stat_my_id_vers,
308
16
      { "Version", "stat.my_id.vers",
309
16
        FT_UINT32, BASE_DEC, NULL, 0,
310
16
        "My_ID Version of callback", HFILL }
311
16
    },
312
16
    { &hf_stat_my_id_proc,
313
16
      { "Procedure", "stat.my_id.proc",
314
16
        FT_UINT32, BASE_DEC, NULL, 0,
315
16
        "My_ID Procedure to callback", HFILL }
316
16
    },
317
16
    { &hf_stat_priv,
318
16
      { "Priv", "stat.priv",
319
16
        FT_BYTES, BASE_NONE, NULL, 0,
320
16
        "Private client supplied opaque data", HFILL }
321
16
    },
322
16
    { &hf_stat_stat_chge,
323
16
      { "Status Change", "stat.stat_chge",
324
16
        FT_NONE, BASE_NONE, NULL, 0,
325
16
        "Status Change structure", HFILL }
326
16
    },
327
16
  };
328
329
16
  static int *ett[] = {
330
16
    &ett_stat,
331
16
    &ett_stat_stat_res,
332
16
    &ett_stat_mon,
333
16
    &ett_stat_my_id,
334
16
    &ett_stat_stat_chge,
335
16
  };
336
337
16
  proto_stat = proto_register_protocol("Network Status Monitor Protocol", "STAT", "stat");
338
16
  proto_register_field_array(proto_stat, hf, array_length(hf));
339
16
  proto_register_subtree_array(ett, array_length(ett));
340
16
}
341
342
void
343
proto_reg_handoff_stat(void)
344
16
{
345
  /* Register the protocol as RPC */
346
16
  rpc_init_prog(proto_stat, STAT_PROGRAM, ett_stat,
347
      G_N_ELEMENTS(stat_vers_info), stat_vers_info);
348
16
}
349
350
/*
351
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
352
 *
353
 * Local variables:
354
 * c-basic-offset: 8
355
 * tab-width: 8
356
 * indent-tabs-mode: t
357
 * End:
358
 *
359
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
360
 * :indentSize=8:tabSize=8:noTabs=false:
361
 */