HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-gluster_pmap.c
1 /* packet-gluster_pmap.c
2  * Routines for Gluster Portmapper and Gluster DUMP dissection
3  * Copyright 2012, Niels de Vos <ndevos@redhat.com>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  *
11  *
12  * References to source files point in general to the glusterfs sources.
13  * There is currently no RFC or other document where the protocol is
14  * completely described. The glusterfs sources can be found at:
15  * - http://git.gluster.com/?p=glusterfs.git
16  * - https://github.com/gluster/glusterfs
17  *
18  * The coding-style is roughly the same as the one use in the Linux kernel,
19  * see http://www.kernel.org/doc/Documentation/CodingStyle.
20  */
21
22 #include "config.h"
23
24 #include <epan/packet.h>
25
26 #include "packet-rpc.h"
27 #include "packet-gluster.h"
28
29 void proto_register_gluster_pmap(void);
30 void proto_reg_handoff_gluster_pmap(void);
31 void proto_register_gluster_dump(void);
32 void proto_reg_handoff_gluster_dump(void);
33
34 /* Initialize the protocol and registered fields */
35 static gint proto_gluster_pmap = -1;
36 static gint proto_gluster_dump = -1;
37
38 /* programs and procedures */
39 static gint hf_gluster_pmap_proc = -1;
40 static gint hf_gluster_dump_proc = -1;
41
42 /* fields used by multiple programs/procedures */
43 static gint hf_gluster_brick = -1;
44 static gint hf_gluster_brick_status = -1;
45 static gint hf_gluster_brick_port = -1;
46 static gint hf_gluster_gfsid = -1;
47 static gint hf_gluster_progname = -1;
48 static gint hf_gluster_prognum = -1;
49 static gint hf_gluster_progver = -1;
50
51 /* Initialize the subtree pointers */
52 static gint ett_gluster_pmap = -1;
53 static gint ett_gluster_dump = -1;
54 static gint ett_gluster_dump_detail = -1;
55
56 /* PMAP PORTBYBRICK */
57 static int
58 gluster_pmap_portbybrick_reply(tvbuff_t *tvb, packet_info *pinfo,
59                                                         proto_tree *tree, void* data)
60 {
61         int offset = 0;
62         offset = gluster_dissect_common_reply(tvb, offset, pinfo, tree, data);
63         offset = dissect_rpc_uint32(tvb, tree, hf_gluster_brick_status, offset);
64         offset = dissect_rpc_uint32(tvb, tree, hf_gluster_brick_port, offset);
65
66         return offset;
67 }
68
69 static int
70 gluster_pmap_portbybrick_call(tvbuff_t *tvb,
71                                 packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
72 {
73         return dissect_rpc_string(tvb, tree, hf_gluster_brick, 0, NULL);
74 }
75
76 /* Based on rpc/rpc-lib/src/rpc-common.c, but xdr encoding/decoding is broken.
77  * The structure in rpc/rpc-lib/src/xdr-common.h lists 2x unit64_t, but to
78  * encode/decode, xdr_u_quad_t() is used (which is uint32_t).
79  */
80 static int
81 gluster_dump_reply_detail(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
82                                                         proto_tree *tree, void* data _U_)
83 {
84         proto_item *detail_item;
85         proto_tree *detail_tree;
86         const gchar *progname = NULL;
87
88         detail_tree = proto_tree_add_subtree(tree, tvb, offset, -1,
89                                                         ett_gluster_dump_detail, &detail_item, "Available Program: ");
90
91         /* progname */
92         offset = dissect_rpc_string(tvb, detail_tree, hf_gluster_progname,
93                                                         offset, &progname);
94         proto_item_append_text(detail_item, "%s", progname);
95
96         /* prognumber (marked as uint64) */
97         offset = dissect_rpc_uint64(tvb, detail_tree, hf_gluster_prognum,
98                                                                 offset);
99         /* progversion (marked as uint64) */
100         offset = dissect_rpc_uint64(tvb, detail_tree, hf_gluster_progver,
101                                                                 offset);
102
103         return offset;
104 }
105
106 static int
107 gluster_dump_reply(tvbuff_t *tvb, packet_info *pinfo,
108                                                         proto_tree *tree, void* data)
109 {
110         int offset = 0;
111
112         offset = dissect_rpc_uint64(tvb, tree, hf_gluster_gfsid, offset);
113         offset = gluster_dissect_common_reply(tvb, offset, pinfo, tree, data);
114
115         offset = dissect_rpc_list(tvb, pinfo, tree, offset,
116                                   gluster_dump_reply_detail, NULL);
117
118         return offset;
119 }
120
121 /* DUMP request */
122 static int
123 gluster_dump_call(tvbuff_t *tvb, packet_info *pinfo _U_,
124                                                         proto_tree *tree, void* data _U_)
125 {
126         return dissect_rpc_uint64(tvb, tree, hf_gluster_gfsid, 0);
127 }
128
129 /* GLUSTER_PMAP_PROGRAM from xlators/mgmt/glusterd/src/glusterd-pmap.c */
130 static const vsff gluster_pmap_proc[] = {
131         {
132                 GF_PMAP_NULL,        "NULL",
133                 dissect_rpc_void, dissect_rpc_void
134         },
135         {
136                 GF_PMAP_PORTBYBRICK, "PORTBYBRICK",
137                 gluster_pmap_portbybrick_call, gluster_pmap_portbybrick_reply
138         },
139         { GF_PMAP_BRICKBYPORT, "BRICKBYPORT", dissect_rpc_unknown, dissect_rpc_unknown },
140         { GF_PMAP_SIGNIN,      "SIGNIN",      dissect_rpc_unknown, dissect_rpc_unknown },
141         { GF_PMAP_SIGNOUT,     "SIGNOUT",     dissect_rpc_unknown, dissect_rpc_unknown },
142         { GF_PMAP_SIGNUP,      "SIGNUP",      dissect_rpc_unknown, dissect_rpc_unknown },
143         { 0, NULL, NULL, NULL }
144 };
145 static const value_string gluster_pmap_proc_vals[] = {
146         { GF_PMAP_NULL,        "NULL" },
147         { GF_PMAP_PORTBYBRICK, "PORTBYBRICK" },
148         { GF_PMAP_BRICKBYPORT, "BRICKBYPORT" },
149         { GF_PMAP_SIGNIN,      "SIGNIN" },
150         { GF_PMAP_SIGNOUT,     "SIGNOUT" },
151         { GF_PMAP_SIGNUP,      "SIGNUP" },
152         { 0, NULL }
153 };
154 static const rpc_prog_vers_info gluster_pmap_vers_info[] = {
155         { 1, gluster_pmap_proc, &hf_gluster_pmap_proc }
156 };
157
158 /* procedures for GLUSTER_DUMP_PROGRAM */
159 static const vsff gluster_dump_proc[] = {
160         { 0, "NULL", dissect_rpc_void, dissect_rpc_void },
161         { GF_DUMP_DUMP, "DUMP", gluster_dump_call, gluster_dump_reply },
162         { 0, NULL, NULL, NULL }
163 };
164 static const value_string gluster_dump_proc_vals[] = {
165         { 0,            "NULL" },
166         { GF_DUMP_DUMP, "DUMP" },
167         { 0, NULL }
168 };
169 static const rpc_prog_vers_info gluster_dump_vers_info[] = {
170         { 1, gluster_dump_proc, &hf_gluster_dump_proc }
171 };
172
173 void
174 proto_register_gluster_pmap(void)
175 {
176         /* Setup list of header fields  See Section 1.6.1 for details */
177         static hf_register_info hf[] = {
178                 /* programs */
179                 { &hf_gluster_pmap_proc,
180                         { "Gluster Portmap", "gluster.pmap.proc", FT_UINT32,
181                                 BASE_DEC, VALS(gluster_pmap_proc_vals), 0,
182                                 NULL, HFILL }
183                 },
184                 { &hf_gluster_brick,
185                         { "Brick", "gluster.brick", FT_STRINGZ, BASE_NONE,
186                                 NULL, 0, NULL, HFILL }
187                 },
188                 { &hf_gluster_brick_status,
189                         { "Status", "gluster.brick.status", FT_INT32, BASE_DEC,
190                                 NULL, 0, NULL, HFILL }
191                 },
192                 { &hf_gluster_brick_port,
193                         { "Port", "gluster.brick.port", FT_INT32, BASE_DEC,
194                                 NULL, 0, NULL, HFILL }
195                 }
196         };
197
198         /* Setup protocol subtree array */
199         static gint *ett[] = {
200                 &ett_gluster_pmap
201         };
202
203         proto_gluster_pmap = proto_register_protocol("Gluster Portmap",
204                                         "Gluster Portmap", "gluster.pmap");
205         proto_register_subtree_array(ett, array_length(ett));
206         proto_register_field_array(proto_gluster_pmap, hf, array_length(hf));
207 }
208
209 void
210 proto_reg_handoff_gluster_pmap(void)
211 {
212         rpc_init_prog(proto_gluster_pmap, GLUSTER_PMAP_PROGRAM,
213             ett_gluster_pmap,
214             G_N_ELEMENTS(gluster_pmap_vers_info), gluster_pmap_vers_info);
215 }
216
217 void
218 proto_register_gluster_dump(void)
219 {
220         /* Setup list of header fields  See Section 1.6.1 for details */
221         static hf_register_info hf[] = {
222                 /* programs */
223                 { &hf_gluster_dump_proc,
224                         { "Gluster DUMP", "gluster.dump.proc", FT_UINT32,
225                                 BASE_DEC, VALS(gluster_dump_proc_vals), 0,
226                                 NULL, HFILL }
227                 },
228                 { &hf_gluster_progname,
229                         { "Program Name", "gluster.dump.progname", FT_STRING,
230                                 BASE_NONE, NULL, 0, NULL, HFILL }
231                 },
232                 { &hf_gluster_prognum,
233                         { "Program Number", "gluster.dump.prognum",
234                                 FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL }
235                 },
236                 { &hf_gluster_progver,
237                         { "Program Version", "gluster.dump.progver",
238                                 FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL }
239                 },
240                 { &hf_gluster_gfsid,
241                         { "GFS ID", "gluster.gfsid", FT_UINT64, BASE_HEX, NULL,
242                                 0, NULL, HFILL }
243                 }
244         };
245
246         /* Setup protocol subtree array */
247         static gint *ett[] = {
248                 &ett_gluster_dump,
249                 &ett_gluster_dump_detail
250         };
251
252         proto_gluster_dump = proto_register_protocol("Gluster Dump",
253                                         "Gluster Dump", "gluster.dump");
254         proto_register_subtree_array(ett, array_length(ett));
255         proto_register_field_array(proto_gluster_dump, hf, array_length(hf));
256 }
257
258 void
259 proto_reg_handoff_gluster_dump(void)
260 {
261         rpc_init_prog(proto_gluster_dump, GLUSTER_DUMP_PROGRAM,
262             ett_gluster_dump,
263             G_N_ELEMENTS(gluster_dump_vers_info), gluster_dump_vers_info);
264 }
265
266 /*
267  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
268  *
269  * Local variables:
270  * c-basic-offset: 8
271  * tab-width: 8
272  * indent-tabs-mode: t
273  * End:
274  *
275  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
276  * :indentSize=8:tabSize=8:noTabs=false:
277  */