Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-stat.c
blobb62b96c11b21c161e5ca24d2f123e95f87582b0b
1 /* packet-stat.c
2 * Routines for stat dissection
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * Copied from packet-smb.c
10 * 2001 Ronnie Sahlberg <See AUTHORS for email>
11 * Added the dissectors for STAT protocol
13 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include "config.h"
17 #include "packet-rpc.h"
18 #include "packet-stat.h"
20 void proto_register_stat(void);
21 void proto_reg_handoff_stat(void);
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 }
34 static const value_string stat_res[] =
36 { 0, "STAT_SUCC" },
37 { 1, "STAT_FAIL" },
38 { 0, NULL }
41 static int proto_stat;
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;
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;
65 #define STAT_SUCC 0
66 #define STAT_FAIL 1
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)
72 static int
73 my_id_len(tvbuff_t *tvb, int offset)
75 int len;
77 len = tvb_get_ntohl(tvb, offset);
78 if(len&0x03)
79 len = (len&0xfc)+4;
81 len += 16;
83 return len;
86 /* Calculate length (including padding) of my_id structure.
87 * First read the length of the string and round it upwards to nearest
88 * multiple of 4, then add 4 (string len) and size of my_id struct.
90 static int
91 mon_id_len(tvbuff_t *tvb, int offset)
93 int len;
95 len = tvb_get_ntohl(tvb, offset);
96 if(len&0x03){
97 len = (len&0xfc)+4;
100 len += 4;
102 return len+my_id_len(tvb,offset+len);
105 static int
106 dissect_stat_stat(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
108 return dissect_rpc_string(tvb,tree,hf_stat_mon_name,0,NULL);
111 static int
112 dissect_stat_stat_res(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
114 proto_item *sub_item;
115 proto_tree *sub_tree;
116 int32_t res;
117 int offset = 0;
119 sub_item = proto_tree_add_item(tree, hf_stat_stat_res, tvb,
120 offset, -1, ENC_NA);
121 sub_tree = proto_item_add_subtree(sub_item, ett_stat_stat_res);
123 res = tvb_get_ntohl(tvb, offset);
124 offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_stat_res_res,offset);
126 if (res==STAT_SUCC) {
127 offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_stat_res_state,offset);
128 } else {
129 offset += 4;
132 return offset;
135 static int
136 dissect_stat_my_id(tvbuff_t *tvb, int offset, proto_tree *tree)
138 proto_item *sub_item;
139 proto_tree *sub_tree;
141 sub_item = proto_tree_add_item(tree, hf_stat_my_id, tvb,
142 offset, my_id_len(tvb,offset), ENC_NA);
143 sub_tree = proto_item_add_subtree(sub_item, ett_stat_my_id);
145 offset = dissect_rpc_string(tvb,sub_tree,hf_stat_my_id_hostname,offset,NULL);
146 offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_my_id_prog,offset);
147 offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_my_id_vers,offset);
148 offset = dissect_rpc_uint32(tvb,sub_tree,hf_stat_my_id_proc,offset);
150 return offset;
153 static int
154 dissect_stat_mon_id(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
156 proto_item *sub_item;
157 proto_tree *sub_tree;
158 int offset = 0;
160 sub_item = proto_tree_add_item(tree, hf_stat_mon, tvb,
161 offset, mon_id_len(tvb,offset), ENC_NA);
162 sub_tree = proto_item_add_subtree(sub_item, ett_stat_mon);
164 offset = dissect_rpc_string(tvb,sub_tree,hf_stat_mon_id_name,offset,NULL);
166 offset = dissect_stat_my_id(tvb,offset,sub_tree);
168 return offset;
171 static int
172 dissect_stat_priv(tvbuff_t *tvb, int offset, proto_tree *tree)
174 proto_tree_add_item(tree, hf_stat_priv, tvb, offset, 16, ENC_NA);
175 offset += 16;
177 return offset;
180 static int
181 dissect_stat_mon(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
183 int offset = dissect_stat_mon_id(tvb,pinfo,tree,data);
185 offset = dissect_stat_priv(tvb,offset,tree);
186 return offset;
189 static int
190 dissect_stat_state(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
192 return dissect_rpc_uint32(tvb,tree,hf_stat_state,0);
195 static int
196 dissect_stat_notify(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
198 proto_item *sub_item;
199 proto_tree *sub_tree;
200 int offset = 0;
201 int start_offset = offset;
203 sub_item = proto_tree_add_item(tree, hf_stat_stat_chge, tvb,
204 offset, -1, ENC_NA);
205 sub_tree = proto_item_add_subtree(sub_item, ett_stat_stat_chge);
207 offset = dissect_rpc_string(tvb,sub_tree,hf_stat_mon_id_name,offset,NULL);
209 offset = dissect_rpc_uint32(tvb,tree,hf_stat_state,offset);
211 if(sub_item)
212 proto_item_set_len(sub_item, offset - start_offset);
214 return offset;
217 static int
218 dissect_stat_umon_all(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
220 return dissect_stat_my_id(tvb,0,tree);
223 /* proc number, "proc name", dissect_request, dissect_reply */
225 static const vsff stat1_proc[] = {
226 { 0, "NULL",
227 dissect_rpc_void, dissect_rpc_void },
228 { STATPROC_STAT, "STAT",
229 dissect_stat_stat, dissect_stat_stat_res },
230 { STATPROC_MON, "MON",
231 dissect_stat_mon, dissect_stat_stat_res },
232 { STATPROC_UNMON, "UNMON",
233 dissect_stat_mon_id, dissect_stat_state },
234 { STATPROC_UNMON_ALL, "UNMON_ALL",
235 dissect_stat_umon_all, dissect_stat_state },
236 { STATPROC_SIMU_CRASH, "SIMU_CRASH",
237 dissect_rpc_void, dissect_rpc_void },
238 { STATPROC_NOTIFY, "NOTIFY",
239 dissect_stat_notify, dissect_rpc_void },
240 { 0, NULL, NULL, NULL }
242 /* end of stat version 1 */
245 static const rpc_prog_vers_info stat_vers_info[] = {
246 { 1, stat1_proc, &hf_stat_procedure_v1 },
249 void
250 proto_register_stat(void)
252 static hf_register_info hf[] = {
253 { &hf_stat_procedure_v1,
254 { "V1 Procedure", "stat.procedure_v1",
255 FT_UINT32, BASE_DEC, VALS(stat1_proc_vals), 0,
256 NULL, HFILL }
258 { &hf_stat_mon_name,
259 { "Name", "stat.name",
260 FT_STRING, BASE_NONE, NULL, 0,
261 NULL, HFILL }
263 { &hf_stat_stat_res,
264 { "Status Result", "stat.stat_res",
265 FT_NONE, BASE_NONE, NULL, 0,
266 NULL, HFILL }
268 { &hf_stat_stat_res_res,
269 { "Result", "stat.stat_res.res",
270 FT_UINT32, BASE_DEC, VALS(stat_res), 0,
271 NULL, HFILL }
273 { &hf_stat_stat_res_state,
274 { "State", "stat.stat_res.state",
275 FT_UINT32, BASE_DEC, NULL, 0,
276 NULL, HFILL }
278 { &hf_stat_state,
279 { "State", "stat.state",
280 FT_UINT32, BASE_DEC, NULL, 0,
281 "State of local NSM", HFILL }
283 { &hf_stat_mon,
284 { "Monitor", "stat.mon",
285 FT_NONE, BASE_NONE, NULL, 0,
286 "Monitor Host", HFILL }
288 { &hf_stat_mon_id_name,
289 { "Monitor ID Name", "stat.mon_id.name",
290 FT_STRING, BASE_NONE, NULL, 0,
291 NULL, HFILL }
293 { &hf_stat_my_id,
294 { "My ID", "stat.my_id",
295 FT_NONE, BASE_NONE, NULL, 0,
296 "My_ID structure", HFILL }
298 { &hf_stat_my_id_hostname,
299 { "Hostname", "stat.my_id.hostname",
300 FT_STRING, BASE_NONE, NULL, 0,
301 "My_ID Host to callback", HFILL }
303 { &hf_stat_my_id_prog,
304 { "Program", "stat.my_id.prog",
305 FT_UINT32, BASE_DEC, NULL, 0,
306 "My_ID Program to callback", HFILL }
308 { &hf_stat_my_id_vers,
309 { "Version", "stat.my_id.vers",
310 FT_UINT32, BASE_DEC, NULL, 0,
311 "My_ID Version of callback", HFILL }
313 { &hf_stat_my_id_proc,
314 { "Procedure", "stat.my_id.proc",
315 FT_UINT32, BASE_DEC, NULL, 0,
316 "My_ID Procedure to callback", HFILL }
318 { &hf_stat_priv,
319 { "Priv", "stat.priv",
320 FT_BYTES, BASE_NONE, NULL, 0,
321 "Private client supplied opaque data", HFILL }
323 { &hf_stat_stat_chge,
324 { "Status Change", "stat.stat_chge",
325 FT_NONE, BASE_NONE, NULL, 0,
326 "Status Change structure", HFILL }
330 static int *ett[] = {
331 &ett_stat,
332 &ett_stat_stat_res,
333 &ett_stat_mon,
334 &ett_stat_my_id,
335 &ett_stat_stat_chge,
338 proto_stat = proto_register_protocol("Network Status Monitor Protocol", "STAT", "stat");
339 proto_register_field_array(proto_stat, hf, array_length(hf));
340 proto_register_subtree_array(ett, array_length(ett));
343 void
344 proto_reg_handoff_stat(void)
346 /* Register the protocol as RPC */
347 rpc_init_prog(proto_stat, STAT_PROGRAM, ett_stat,
348 G_N_ELEMENTS(stat_vers_info), stat_vers_info);
352 * Editor modelines - https://www.wireshark.org/tools/modelines.html
354 * Local variables:
355 * c-basic-offset: 8
356 * tab-width: 8
357 * indent-tabs-mode: t
358 * End:
360 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
361 * :indentSize=8:tabSize=8:noTabs=false: