-
Notifications
You must be signed in to change notification settings - Fork 3
/
packet-gluster.c
237 lines (206 loc) · 7.21 KB
/
packet-gluster.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* packet-gluster.c
* Routines for gluster dissection
* Copyright 2012, Niels de Vos <[email protected]>
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <[email protected]>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*
* References to source files point in general to the glusterfs sources.
* There is currently no RFC or other document where the protocol is
* completely described. The glusterfs sources can be found at:
* - http://git.gluster.com/?p=glusterfs.git
* - https://github.com/gluster/glusterfs
*
* The coding-style is roughly the same as the one use in the Linux kernel,
* see http://www.kernel.org/doc/Documentation/CodingStyle.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glib.h>
#include <string.h>
#include <epan/packet.h>
#include <epan/tfs.h>
#include "packet-rpc.h"
#include "packet-gluster.h"
/* Initialize the protocol and registered fields */
gint proto_gluster = -1;
static gint proto_gluster_mgmt = -1;
/* programs and procedures */
static gint hf_gluster_mgmt_proc = -1;
/* fields used by multiple programs/procedures */
gint hf_gluster_gfid = -1;
gint hf_gluster_op = -1;
gint hf_gluster_op_ret = -1;
gint hf_gluster_dict = -1;
static gint hf_gluster_dict_key = -1;
static gint hf_gluster_dict_value = -1;
static gint hf_gluster_op_errno = -1;
/* Initialize the subtree pointers */
static gint ett_gluster = -1;
static gint ett_gluster_mgmt = -1;
static gint ett_gluster_dict = -1;
static gint ett_gluster_dict_items = -1;
/* function for dissecting and adding a gluster dict_t to the tree */
int
gluster_rpc_dissect_dict(proto_tree *tree, tvbuff_t *tvb, int hfindex, int offset)
{
gchar *key, *value;
gint items, i, len, roundup, value_len, key_len;
proto_item *subtree_item;
proto_tree *subtree;
proto_item *dict_item;
proto_tree *dict_tree;
/* create a subtree for all the items in the dict */
if (hfindex >= 0) {
header_field_info *hfinfo = proto_registrar_get_nth(hfindex);
subtree_item = proto_tree_add_text(tree, tvb, offset, -1, "%s", hfinfo->name);
} else {
subtree_item = proto_tree_add_text(tree, tvb, offset, -1, "<NAMELESS DICT STRUCTURE>");
}
subtree = proto_item_add_subtree(subtree_item, ett_gluster_dict);
len = tvb_get_ntohl(tvb, offset);
roundup = rpc_roundup(len) - len;
proto_tree_add_text(subtree, tvb, offset, 4, "[Size: %d (%d bytes inc. RPC-roundup)]", len, rpc_roundup(len));
offset += 4;
if (len == 0)
return offset;
items = tvb_get_ntohl(tvb, offset);
proto_tree_add_text(subtree, tvb, offset, 4, "[Items: %d]", items);
offset += 4;
for (i = 0; i < items; i++) {
dict_item = proto_tree_add_text(subtree, tvb, offset, -1, "Item %d", i);
dict_tree = proto_item_add_subtree(dict_item, ett_gluster_dict_items);
/* key_len is the length of the key without the terminating '\0' */
/* key_len = tvb_get_ntohl(tvb, offset) + 1; // will be read later */
offset += 4;
value_len = tvb_get_ntohl(tvb, offset);
offset += 4;
/* read the key, '\0' terminated */
key = tvb_get_stringz(tvb, offset, &key_len);
if (tree)
proto_tree_add_string(dict_tree, hf_gluster_dict_key, tvb, offset, key_len, key);
offset += key_len;
g_free(key);
/* read the value, '\0' terminated */
value = tvb_get_string(tvb, offset, value_len);
if (tree)
proto_tree_add_string(dict_tree, hf_gluster_dict_value, tvb, offset, value_len, value);
offset += value_len;
g_free(value);
}
if (roundup) {
if (tree)
proto_tree_add_text(subtree, tvb, offset, -1, "RPC-roundup bytes: %d", roundup);
offset += roundup;
}
return offset;
}
/* GLUSTERD1_MGMT_PROGRAM from xlators/mgmt/glusterd/src/glusterd-rpc-ops.c */
static const vsff gluster_mgmt_proc[] = {
{ GLUSTERD_MGMT_NULL, "NULL", NULL, NULL },
{ GLUSTERD_MGMT_PROBE_QUERY, "PROBE_QUERY", NULL, NULL },
{ GLUSTERD_MGMT_FRIEND_ADD, "FRIEND_ADD", NULL, NULL },
{ GLUSTERD_MGMT_CLUSTER_LOCK, "CLUSTER_LOCK", NULL, NULL },
{ GLUSTERD_MGMT_CLUSTER_UNLOCK, "CLUSTER_UNLOCK", NULL, NULL },
{ GLUSTERD_MGMT_STAGE_OP, "STAGE_OP", NULL, NULL },
{ GLUSTERD_MGMT_COMMIT_OP, "COMMIT_OP", NULL, NULL },
{ GLUSTERD_MGMT_FRIEND_REMOVE, "FRIEND_REMOVE", NULL, NULL },
{ GLUSTERD_MGMT_FRIEND_UPDATE, "FRIEND_UPDATE", NULL, NULL },
{ 0, NULL, NULL, NULL }
};
static const value_string gluster_mgmt_proc_vals[] = {
{ GLUSTERD_MGMT_NULL, "NULL" },
{ GLUSTERD_MGMT_PROBE_QUERY, "PROBE_QUERY" },
{ GLUSTERD_MGMT_FRIEND_ADD, "FRIEND_ADD" },
{ GLUSTERD_MGMT_CLUSTER_LOCK, "CLUSTER_LOCK" },
{ GLUSTERD_MGMT_CLUSTER_UNLOCK, "CLUSTER_UNLOCK" },
{ GLUSTERD_MGMT_STAGE_OP, "STAGE_OP" },
{ GLUSTERD_MGMT_COMMIT_OP, "COMMIT_OP" },
{ GLUSTERD_MGMT_FRIEND_REMOVE, "FRIEND_REMOVE" },
{ GLUSTERD_MGMT_FRIEND_UPDATE, "FRIEND_UPDATE" },
{ 0, NULL }
};
void
proto_register_gluster(void)
{
/* Setup list of header fields See Section 1.6.1 for details */
static hf_register_info hf[] = {
/* programs */
{ &hf_gluster_mgmt_proc,
{ "Gluster Management", "gluster.mgmt", FT_UINT32,
BASE_DEC, VALS(gluster_mgmt_proc_vals), 0,
NULL, HFILL }
},
/* fields used by procedures */
{ &hf_gluster_gfid,
{ "GFID", "gluster.gfid", FT_BYTES,
BASE_NONE, NULL, 0, NULL, HFILL }
},
{ &hf_gluster_op,
{ "Operation (FIXME?)", "gluster.op", FT_INT32, BASE_DEC,
NULL, 0, NULL, HFILL }
},
{ &hf_gluster_op_ret,
{ "Return value", "gluster.op_ret", FT_INT32, BASE_DEC,
NULL, 0, NULL, HFILL }
},
{ &hf_gluster_op_errno,
{ "Errno", "gluster.op_errno", FT_INT32, BASE_DEC,
NULL, 0, NULL, HFILL }
},
/* fields used by gluster_rpc_dissect_dict() */
{ &hf_gluster_dict,
{ "Dict", "gluster.dict", FT_STRING, BASE_NONE,
NULL, 0, NULL, HFILL }
},
{ &hf_gluster_dict_key,
{ "Key", "gluster.dict.key", FT_STRING, BASE_NONE,
NULL, 0, NULL, HFILL }
},
{ &hf_gluster_dict_value,
{ "Value", "gluster.dict.value", FT_STRING, BASE_NONE,
NULL, 0, NULL, HFILL }
}
};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_gluster,
&ett_gluster_mgmt,
&ett_gluster_dict,
&ett_gluster_dict_items
};
/* Register the protocol name and description */
proto_gluster = proto_register_protocol("Gluster", "Gluster",
"gluster");
proto_register_subtree_array(ett, array_length(ett));
proto_register_field_array(proto_gluster, hf, array_length(hf));
proto_gluster_mgmt = proto_register_protocol("Gluster Management",
"Gluster Management", "gluster-mgmt");
}
void
proto_reg_handoff_gluster(void)
{
rpc_init_prog(proto_gluster_mgmt, GLUSTERD1_MGMT_PROGRAM,
ett_gluster_mgmt);
rpc_init_proc_table(GLUSTERD1_MGMT_PROGRAM, 1, gluster_mgmt_proc,
hf_gluster_mgmt_proc);
}