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
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
[] = {
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" },
34 static const value_string stat_res
[] =
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
;
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
;
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)
73 my_id_len(tvbuff_t
*tvb
, int offset
)
77 len
= tvb_get_ntohl(tvb
, offset
);
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.
91 mon_id_len(tvbuff_t
*tvb
, int offset
)
95 len
= tvb_get_ntohl(tvb
, offset
);
102 return len
+my_id_len(tvb
,offset
+len
);
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
);
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
;
119 sub_item
= proto_tree_add_item(tree
, hf_stat_stat_res
, tvb
,
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
);
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
);
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
;
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
);
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
);
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
);
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);
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
;
201 int start_offset
= offset
;
203 sub_item
= proto_tree_add_item(tree
, hf_stat_stat_chge
, tvb
,
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
);
212 proto_item_set_len(sub_item
, offset
- start_offset
);
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
[] = {
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
},
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,
259 { "Name", "stat.name",
260 FT_STRING
, BASE_NONE
, NULL
, 0,
264 { "Status Result", "stat.stat_res",
265 FT_NONE
, BASE_NONE
, NULL
, 0,
268 { &hf_stat_stat_res_res
,
269 { "Result", "stat.stat_res.res",
270 FT_UINT32
, BASE_DEC
, VALS(stat_res
), 0,
273 { &hf_stat_stat_res_state
,
274 { "State", "stat.stat_res.state",
275 FT_UINT32
, BASE_DEC
, NULL
, 0,
279 { "State", "stat.state",
280 FT_UINT32
, BASE_DEC
, NULL
, 0,
281 "State of local NSM", HFILL
}
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,
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
}
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
[] = {
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
));
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
357 * indent-tabs-mode: t
360 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
361 * :indentSize=8:tabSize=8:noTabs=false: