Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-ipvs-syncd.c
1 /* packet-ipvs-syncd.c   2001 Ronnie Sahlberg <See AUTHORS for email>
2  * Routines for IGMP packet disassembly
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <glib.h>
26
27 #include <epan/packet.h>
28 #include <epan/ipproto.h>
29 #include <epan/in_cksum.h>
30
31 void proto_register_ipvs_syncd(void);
32 void proto_reg_handoff_ipvs_syncd(void);
33
34 static int proto_ipvs_syncd = -1;
35 static int hf_conn_count = -1;
36 static int hf_syncid = -1;
37 static int hf_size = -1;
38 static int hf_resv8 = -1;
39 static int hf_proto = -1;
40 static int hf_cport = -1;
41 static int hf_vport = -1;
42 static int hf_dport = -1;
43 static int hf_caddr = -1;
44 static int hf_vaddr = -1;
45 static int hf_daddr = -1;
46 static int hf_flags = -1;
47 static int hf_flags_conn_type = -1;
48 static int hf_flags_hashed_entry = -1;
49 static int hf_flags_no_output_packets = -1;
50 static int hf_flags_conn_not_established = -1;
51 static int hf_flags_adjust_output_seq = -1;
52 static int hf_flags_adjust_input_seq = -1;
53 static int hf_flags_no_client_port_set = -1;
54 static int hf_state = -1;
55 static int hf_in_seq_init = -1;
56 static int hf_in_seq_delta = -1;
57 static int hf_in_seq_pdelta = -1;
58 static int hf_out_seq_init = -1;
59 static int hf_out_seq_delta = -1;
60 static int hf_out_seq_pdelta = -1;
61
62 static int ett_ipvs_syncd = -1;
63 static int ett_conn = -1;
64 static int ett_flags = -1;
65
66 #define IPVS_SYNCD_MC_GROUP "224.0.0.18"
67 #define IPVS_SYNCD_PORT 8848
68
69 static const value_string proto_strings[] = {
70         {0x06, "TCP"},
71         {0x11, "UDP"},
72         {0x00, NULL},
73 };
74
75 static const value_string state_strings[] = {
76         {0x00, "Input"},
77         {0x04, "Output"},
78         {0x08, "Input Only"},
79         {0x00, NULL},
80 };
81
82 /*
83  *  IPVS Connection Flags
84  *  Pulled from include/net/ip_vs.h in linux kernel source
85  */
86 #define IP_VS_CONN_F_FWD_MASK         0x0007    /* mask for the fwd methods */
87 #define IP_VS_CONN_F_MASQ             0x0000    /* masquerading */
88 #define IP_VS_CONN_F_LOCALNODE        0x0001    /* local node */
89 #define IP_VS_CONN_F_TUNNEL           0x0002    /* tunneling */
90 #define IP_VS_CONN_F_DROUTE           0x0003    /* direct routing */
91 #define IP_VS_CONN_F_BYPASS           0x0004    /* cache bypass */
92 #define IP_VS_CONN_F_HASHED           0x0040    /* hashed entry */
93 #define IP_VS_CONN_F_NOOUTPUT         0x0080    /* no output packets */
94 #define IP_VS_CONN_F_INACTIVE         0x0100    /* not established */
95 #define IP_VS_CONN_F_OUT_SEQ          0x0200    /* must do output seq adjust */
96 #define IP_VS_CONN_F_IN_SEQ           0x0400    /* must do input seq adjust */
97 #define IP_VS_CONN_F_SEQ_MASK         0x0600    /* in/out sequence mask */
98 #define IP_VS_CONN_F_NO_CPORT         0x0800    /* no client port set yet */
99
100 static const value_string connection_type_strings[] = {
101         {IP_VS_CONN_F_MASQ, "Masquerade"},
102         {IP_VS_CONN_F_LOCALNODE, "Local Node"},
103         {IP_VS_CONN_F_TUNNEL, "Tunnel"},
104         {IP_VS_CONN_F_DROUTE, "Direct Routing"},
105         {0x00, NULL},
106 };
107
108
109 static void
110 dissect_ipvs_syncd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
111 {
112         proto_tree *tree;
113         proto_item *item;
114         int offset = 0;
115         guint8 cnt = 0;
116         int conn = 0;
117
118         item = proto_tree_add_item(parent_tree, proto_ipvs_syncd, tvb, offset, -1, ENC_NA);
119         tree = proto_item_add_subtree(item, ett_ipvs_syncd);
120
121
122         col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPVS");
123         col_clear(pinfo->cinfo, COL_INFO);
124
125         cnt = tvb_get_guint8(tvb, offset);
126         proto_tree_add_item(tree, hf_conn_count, tvb, offset, 1, ENC_BIG_ENDIAN);
127         offset += 1;
128
129         proto_tree_add_item(tree, hf_syncid, tvb, offset, 1, ENC_BIG_ENDIAN);
130         offset += 1;
131
132         proto_tree_add_item(tree, hf_size, tvb, offset, 2, ENC_BIG_ENDIAN);
133         offset += 2;
134
135         for (conn = 0; conn < cnt; conn++)
136         {
137                 proto_tree *ctree, *ti;
138                 proto_tree *ftree, *fi;
139                 guint16 flags;
140
141                 ti = proto_tree_add_text(tree, tvb, offset, 24, "Connection #%d", conn+1);
142                 ctree = proto_item_add_subtree(ti, ett_conn);
143
144                 proto_tree_add_item(ctree, hf_resv8, tvb, offset, 1, ENC_BIG_ENDIAN);
145                 offset += 1;
146
147                 proto_tree_add_item(ctree, hf_proto, tvb, offset, 1, ENC_BIG_ENDIAN);
148                 offset += 1;
149
150                 proto_tree_add_item(ctree, hf_cport, tvb, offset, 2, ENC_BIG_ENDIAN);
151                 offset += 2;
152
153                 proto_tree_add_item(ctree, hf_vport, tvb, offset, 2, ENC_BIG_ENDIAN);
154                 offset += 2;
155
156                 proto_tree_add_item(ctree, hf_dport, tvb, offset, 2, ENC_BIG_ENDIAN);
157                 offset += 2;
158
159                 proto_tree_add_item(ctree, hf_caddr, tvb, offset, 4, ENC_BIG_ENDIAN);
160                 offset += 4;
161
162                 proto_tree_add_item(ctree, hf_vaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
163                 offset += 4;
164
165                 proto_tree_add_item(ctree, hf_daddr, tvb, offset, 4, ENC_BIG_ENDIAN);
166                 offset += 4;
167
168                 flags = tvb_get_ntohs(tvb, offset);
169                 fi = proto_tree_add_item(ctree, hf_flags, tvb, offset, 2, ENC_BIG_ENDIAN);
170                 ftree = proto_item_add_subtree(fi, ett_flags);
171                 proto_tree_add_item(ftree, hf_flags_conn_type, tvb, offset, 2, ENC_BIG_ENDIAN);
172                 proto_tree_add_item(ftree, hf_flags_hashed_entry, tvb, offset, 2, ENC_BIG_ENDIAN);
173                 proto_tree_add_item(ftree, hf_flags_no_output_packets, tvb, offset, 2, ENC_BIG_ENDIAN);
174                 proto_tree_add_item(ftree, hf_flags_conn_not_established, tvb, offset, 2, ENC_BIG_ENDIAN);
175                 proto_tree_add_item(ftree, hf_flags_adjust_output_seq, tvb, offset, 2, ENC_BIG_ENDIAN);
176                 proto_tree_add_item(ftree, hf_flags_adjust_input_seq, tvb, offset, 2, ENC_BIG_ENDIAN);
177                 proto_tree_add_item(ftree, hf_flags_no_client_port_set, tvb, offset, 2, ENC_BIG_ENDIAN);
178
179                 offset += 2;
180
181                 proto_tree_add_item(ctree, hf_state, tvb, offset, 2, ENC_BIG_ENDIAN);
182                 offset += 2;
183
184                 /* we have full connection info */
185                 if ( flags & IP_VS_CONN_F_SEQ_MASK )
186                 {
187                         proto_tree_add_item(ctree, hf_in_seq_init, tvb, offset, 4, ENC_BIG_ENDIAN);
188                         offset += 4;
189
190                         proto_tree_add_item(ctree, hf_in_seq_delta, tvb, offset, 4, ENC_BIG_ENDIAN);
191                         offset += 4;
192
193                         proto_tree_add_item(ctree, hf_in_seq_pdelta, tvb, offset, 4, ENC_BIG_ENDIAN);
194                         offset += 4;
195
196                         proto_tree_add_item(ctree, hf_out_seq_init, tvb, offset, 4, ENC_BIG_ENDIAN);
197                         offset += 4;
198
199                         proto_tree_add_item(ctree, hf_out_seq_delta, tvb, offset, 4, ENC_BIG_ENDIAN);
200                         offset += 4;
201
202                         proto_tree_add_item(ctree, hf_out_seq_pdelta, tvb, offset, 4, ENC_BIG_ENDIAN);
203                         offset += 4;
204                 }
205
206         }
207 }
208
209 void
210 proto_register_ipvs_syncd(void)
211 {
212         static hf_register_info hf[] = {
213                 { &hf_conn_count,
214                         { "Connection Count", "ipvs.conncount", FT_UINT8, BASE_DEC,
215                           NULL, 0, NULL, HFILL }},
216
217                 { &hf_syncid,
218                         { "Synchronization ID", "ipvs.syncid", FT_UINT8, BASE_DEC,
219                           NULL, 0, NULL, HFILL }},
220
221                 { &hf_size,
222                         { "Size", "ipvs.size", FT_UINT16, BASE_DEC,
223                           NULL, 0, NULL, HFILL }},
224
225                 { &hf_resv8,
226                         { "Reserved", "ipvs.resv8", FT_UINT8, BASE_HEX,
227                           NULL, 0, NULL, HFILL }},
228
229                 { &hf_proto,
230                         { "Protocol", "ipvs.proto", FT_UINT8, BASE_HEX,
231                           VALS(proto_strings), 0, NULL, HFILL }},
232
233                 { &hf_cport,
234                         { "Client Port", "ipvs.cport", FT_UINT16, BASE_DEC,
235                           NULL, 0, NULL, HFILL }},
236
237                 { &hf_vport,
238                         { "Virtual Port", "ipvs.vport", FT_UINT16, BASE_DEC,
239                           NULL, 0, NULL, HFILL }},
240
241                 { &hf_dport,
242                         { "Destination Port", "ipvs.dport", FT_UINT16, BASE_DEC,
243                           NULL, 0, NULL, HFILL }},
244
245                 { &hf_caddr,
246                         { "Client Address", "ipvs.caddr", FT_IPv4, BASE_NONE,
247                           NULL, 0, NULL, HFILL }},
248
249                 { &hf_vaddr,
250                         { "Virtual Address", "ipvs.vaddr", FT_IPv4, BASE_NONE,
251                           NULL, 0, NULL, HFILL }},
252
253                 { &hf_daddr,
254                         { "Destination Address", "ipvs.daddr", FT_IPv4, BASE_NONE,
255                           NULL, 0, NULL, HFILL }},
256
257                 { &hf_flags,
258                         { "Flags", "ipvs.flags", FT_UINT16, BASE_HEX,
259                           NULL, 0, NULL, HFILL }},
260
261                 { &hf_flags_conn_type,
262                         { "Connection Type", "ipvs.flags.conn_type", FT_UINT16, BASE_HEX,
263                           VALS(connection_type_strings), 0x0F, NULL, HFILL }},
264
265                 { &hf_flags_hashed_entry,
266                         { "Hashed Entry", "ipvs.flags.hashed_entry", FT_BOOLEAN, 16,
267                           TFS(&tfs_true_false), IP_VS_CONN_F_HASHED, NULL, HFILL }},
268
269                 { &hf_flags_no_output_packets,
270                         { "No Output Packets", "ipvs.flags.no_output_packets", FT_BOOLEAN, 16,
271                           TFS(&tfs_true_false), IP_VS_CONN_F_NOOUTPUT, NULL, HFILL }},
272
273                 { &hf_flags_conn_not_established,
274                         { "Connection Not Established", "ipvs.flags.conn_not_established", FT_BOOLEAN, 16,
275                           TFS(&tfs_true_false), IP_VS_CONN_F_INACTIVE, NULL, HFILL }},
276
277                 { &hf_flags_adjust_output_seq,
278                         { "Adjust Output Sequence", "ipvs.flags.adjust_output_seq", FT_BOOLEAN, 16,
279                           TFS(&tfs_true_false), IP_VS_CONN_F_OUT_SEQ, NULL, HFILL }},
280
281                 { &hf_flags_adjust_input_seq,
282                         { "Adjust Input Sequence", "ipvs.flags.adjust_input_seq", FT_BOOLEAN, 16,
283                           TFS(&tfs_true_false), IP_VS_CONN_F_IN_SEQ, NULL, HFILL }},
284
285                 { &hf_flags_no_client_port_set,
286                         { "No Client Port Set", "ipvs.flags.no_client_port_set", FT_BOOLEAN, 16,
287                           TFS(&tfs_true_false), IP_VS_CONN_F_NO_CPORT, NULL, HFILL }},
288
289                 { &hf_state,
290                         { "State", "ipvs.state", FT_UINT16, BASE_HEX,
291                           VALS(state_strings), 0, NULL, HFILL }},
292
293                 { &hf_in_seq_init,
294                         { "Input Sequence (Initial)", "ipvs.in_seq.initial", FT_UINT32,
295                                 BASE_HEX, NULL, 0, NULL, HFILL }},
296
297                 { &hf_in_seq_delta,
298                         { "Input Sequence (Delta)", "ipvs.in_seq.delta", FT_UINT32,
299                                 BASE_HEX, NULL, 0, NULL, HFILL }},
300
301                 { &hf_in_seq_pdelta,
302                         { "Input Sequence (Previous Delta)", "ipvs.in_seq.pdelta", FT_UINT32,
303                                 BASE_HEX, NULL, 0, NULL, HFILL }},
304
305                 { &hf_out_seq_init,
306                         { "Output Sequence (Initial)", "ipvs.out_seq.initial", FT_UINT32,
307                                 BASE_HEX, NULL, 0, NULL, HFILL }},
308
309                 { &hf_out_seq_delta,
310                         { "Output Sequence (Delta)", "ipvs.out_seq.delta", FT_UINT32,
311                                 BASE_HEX, NULL, 0, NULL, HFILL }},
312
313                 { &hf_out_seq_pdelta,
314                         { "Output Sequence (Previous Delta)", "ipvs.out_seq.pdelta", FT_UINT32,
315                                 BASE_HEX, NULL, 0, NULL, HFILL }},
316
317
318
319
320         };
321         static gint *ett[] = {
322                 &ett_ipvs_syncd,
323                 &ett_conn,
324                 &ett_flags,
325         };
326
327         proto_ipvs_syncd = proto_register_protocol("IP Virtual Services Sync Daemon",
328             "IPVS", "ipvs");
329         proto_register_field_array(proto_ipvs_syncd, hf, array_length(hf));
330         proto_register_subtree_array(ett, array_length(ett));
331 }
332
333 void
334 proto_reg_handoff_ipvs_syncd(void)
335 {
336         dissector_handle_t ipvs_syncd_handle;
337
338         ipvs_syncd_handle = create_dissector_handle(dissect_ipvs_syncd, proto_ipvs_syncd);
339         dissector_add_uint("udp.port", IPVS_SYNCD_PORT, ipvs_syncd_handle);
340 }