Put the value(s) of a parameter into the top-level item for that
[obnox/wireshark/wip.git] / packet-ipvs-syncd.c
1 /* packet-ipvs-syncd.c   2001 Ronnie Sahlberg <See AUTHORS for email>
2  * Routines for IGMP packet disassembly
3  *
4  * $Id: packet-ipvs-syncd.c,v 1.1 2004/03/21 17:13:01 nneul Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <glib.h>
32
33 #ifdef NEED_SNPRINTF_H
34 # include "snprintf.h"
35 #endif
36
37 #include <epan/packet.h>
38 #include "ipproto.h"
39 #include "in_cksum.h"
40
41 static int proto_ipvs_syncd = -1;
42 static int hf_conn_count = -1;
43 static int hf_syncid = -1;
44 static int hf_size = -1;
45 static int hf_resv8 = -1;
46 static int hf_proto = -1;
47 static int hf_cport = -1;
48 static int hf_vport = -1;
49 static int hf_dport = -1;
50 static int hf_caddr = -1;
51 static int hf_vaddr = -1;
52 static int hf_daddr = -1;
53 static int hf_flags = -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, "UDP"},
71         {0x11, "TCP"},
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
101 static void
102 dissect_ipvs_syncd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
103 {
104         proto_tree *tree;
105         proto_item *item;
106         int offset = 0;
107         guint8 cnt = 0;
108         int conn = 0;
109
110         item = proto_tree_add_item(parent_tree, proto_ipvs_syncd, tvb, offset, -1, FALSE);
111         tree = proto_item_add_subtree(item, ett_ipvs_syncd);
112
113
114         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
115                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPVS");
116         }
117         if (check_col(pinfo->cinfo, COL_INFO)) {
118                 col_clear(pinfo->cinfo, COL_INFO);
119         }
120
121         cnt = tvb_get_guint8(tvb, offset);
122         proto_tree_add_item(tree, hf_conn_count, tvb, offset, 1, FALSE);
123         offset += 1;
124
125         proto_tree_add_item(tree, hf_syncid, tvb, offset, 1, FALSE);
126         offset += 1;
127
128         proto_tree_add_item(tree, hf_size, tvb, offset, 2, TRUE);
129         offset += 2;
130
131         for (conn = 0; conn < cnt; conn++)
132         {
133                 proto_tree *ctree, *ti; 
134                 proto_tree *ftree, *fi;
135                 guint16 flags; 
136
137                 ti = proto_tree_add_text(tree, tvb, offset, 24, "Connection #%d", conn+1);
138                 ctree = proto_item_add_subtree(ti, ett_conn);
139
140                 proto_tree_add_item(ctree, hf_resv8, tvb, offset, 1, FALSE);
141                 offset += 1;
142                 
143                 proto_tree_add_item(ctree, hf_proto, tvb, offset, 1, FALSE);
144                 offset += 1;
145                 
146                 proto_tree_add_item(ctree, hf_cport, tvb, offset, 2, FALSE);
147                 offset += 2;
148                 
149                 proto_tree_add_item(ctree, hf_vport, tvb, offset, 2, FALSE);
150                 offset += 2;
151                 
152                 proto_tree_add_item(ctree, hf_dport, tvb, offset, 2, FALSE);
153                 offset += 2;
154                 
155                 proto_tree_add_item(ctree, hf_caddr, tvb, offset, 4, FALSE);
156                 offset += 4;
157                 
158                 proto_tree_add_item(ctree, hf_vaddr, tvb, offset, 4, FALSE);
159                 offset += 4;
160                 
161                 proto_tree_add_item(ctree, hf_daddr, tvb, offset, 4, FALSE);
162                 offset += 4;
163                 
164                 flags = tvb_get_ntohs(tvb, offset);
165                 fi = proto_tree_add_item(ctree, hf_flags, tvb, offset, 2, FALSE);
166                 ftree = proto_item_add_subtree(fi, ett_flags);
167
168                 if ( (flags & 0x0F) == IP_VS_CONN_F_MASQ )
169                 {
170                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Masquerade");
171                 }
172                 else if ( (flags & 0x0F) == IP_VS_CONN_F_LOCALNODE )
173                 {
174                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Local Node");
175                 }
176                 else if ( (flags & 0x0F) == IP_VS_CONN_F_TUNNEL )
177                 {
178                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Tunnel");
179                 }
180                 else if ( (flags & 0x0F) == IP_VS_CONN_F_DROUTE )
181                 {
182                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Direct Routing");
183                 }
184                 else
185                 {
186                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Unknown (%d)", 
187                                 flags & IP_VS_CONN_F_FWD_MASK);
188                 }
189
190                 if ( flags & IP_VS_CONN_F_HASHED )
191                 {
192                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Hashed Entry");
193                 }
194
195                 if ( flags & IP_VS_CONN_F_NOOUTPUT )
196                 {
197                         proto_tree_add_text(ftree, tvb, offset+1, 1, "No Output Packets");
198                 }
199
200                 if ( flags & IP_VS_CONN_F_INACTIVE )
201                 {
202                         proto_tree_add_text(ftree, tvb, offset, 1, "Connection Not Established");
203                 }
204
205                 if ( flags & IP_VS_CONN_F_OUT_SEQ )
206                 {
207                         proto_tree_add_text(ftree, tvb, offset, 1, "Adjust Output Sequence");
208                 }
209
210                 if ( flags & IP_VS_CONN_F_IN_SEQ )
211                 {
212                         proto_tree_add_text(ftree, tvb, offset, 1, "Adjust Input Sequence");
213                 }
214
215                 if ( flags & IP_VS_CONN_F_NO_CPORT )
216                 {
217                         proto_tree_add_text(ftree, tvb, offset, 1, "No Client Port Set");
218                 }
219                 
220                 offset += 2;
221                 
222                 proto_tree_add_item(ctree, hf_state, tvb, offset, 2, FALSE);
223                 offset += 2;
224                 
225                 /* we have full connection info */
226                 if ( flags & IP_VS_CONN_F_SEQ_MASK )
227                 {
228                         proto_tree_add_item(ctree, hf_in_seq_init, tvb, offset, 4, FALSE);
229                         offset += 4;
230                 
231                         proto_tree_add_item(ctree, hf_in_seq_delta, tvb, offset, 4, FALSE);
232                         offset += 4;
233                 
234                         proto_tree_add_item(ctree, hf_in_seq_pdelta, tvb, offset, 4, FALSE);
235                         offset += 4;
236                 
237                         proto_tree_add_item(ctree, hf_out_seq_init, tvb, offset, 4, FALSE);
238                         offset += 4;
239                 
240                         proto_tree_add_item(ctree, hf_out_seq_delta, tvb, offset, 4, FALSE);
241                         offset += 4;
242                 
243                         proto_tree_add_item(ctree, hf_out_seq_pdelta, tvb, offset, 4, FALSE);
244                         offset += 4;
245                 }
246                 
247         }
248 }
249
250 void
251 proto_register_ipvs_syncd(void)
252 {
253         static hf_register_info hf[] = {
254                 { &hf_conn_count,
255                         { "Connection Count", "ipvs.conncount", FT_UINT8, BASE_DEC,
256                           NULL, 0, "Connection Count", HFILL }},
257
258                 { &hf_syncid,
259                         { "Synchronization ID", "ipvs.syncid", FT_UINT8, BASE_DEC,
260                           NULL, 0, "Syncronization ID", HFILL }},
261
262                 { &hf_size,
263                         { "Size", "ipvs.size", FT_UINT16, BASE_DEC,
264                           NULL, 0, "Size", HFILL }},
265
266                 { &hf_resv8,
267                         { "Reserved", "ipvs.resv8", FT_UINT8, BASE_HEX,
268                           NULL, 0, "Reserved", HFILL }},
269
270                 { &hf_proto,
271                         { "Protocol", "ipvs.proto", FT_UINT8, BASE_HEX,
272                           VALS(&proto_strings), 0, "Protocol", HFILL }},
273
274                 { &hf_cport,
275                         { "Client Port", "ipvs.cport", FT_UINT16, BASE_DEC,
276                           NULL, 0, "Client Port", HFILL }},
277
278                 { &hf_vport,
279                         { "Virtual Port", "ipvs.vport", FT_UINT16, BASE_DEC,
280                           NULL, 0, "Virtual Port", HFILL }},
281
282                 { &hf_dport,
283                         { "Destination Port", "ipvs.dport", FT_UINT16, BASE_DEC,
284                           NULL, 0, "Destination Port", HFILL }},
285
286                 { &hf_caddr,
287                         { "Client Address", "ipvs.caddr", FT_IPv4, BASE_HEX,
288                           NULL, 0, "Client Address", HFILL }},
289
290                 { &hf_vaddr,
291                         { "Virtual Address", "ipvs.vaddr", FT_IPv4, BASE_HEX,
292                           NULL, 0, "Virtual Address", HFILL }},
293
294                 { &hf_daddr,
295                         { "Destination Address", "ipvs.daddr", FT_IPv4, BASE_HEX,
296                           NULL, 0, "Destination Address", HFILL }},
297
298                 { &hf_flags,
299                         { "Flags", "ipvs.flags", FT_UINT16, BASE_HEX,
300                           NULL, 0, "Flags", HFILL }},
301
302                 { &hf_state,
303                         { "State", "ipvs.state", FT_UINT16, BASE_HEX,
304                           VALS(&state_strings), 0, "State", HFILL }},
305         
306                 { &hf_in_seq_init,
307                         { "Input Sequence (Initial)", "ipvs.in_seq.initial", FT_UINT32, 
308                                 BASE_HEX, NULL, 0, "Input Sequence (Initial)", HFILL }},
309         
310                 { &hf_in_seq_delta,
311                         { "Input Sequence (Delta)", "ipvs.in_seq.delta", FT_UINT32, 
312                                 BASE_HEX, NULL, 0, "Input Sequence (Delta)", HFILL }},
313         
314                 { &hf_in_seq_pdelta,
315                         { "Input Sequence (Previous Delta)", "ipvs.in_seq.pdelta", FT_UINT32, 
316                                 BASE_HEX, NULL, 0, "Input Sequence (Previous Delta)", HFILL }},
317         
318                 { &hf_out_seq_init,
319                         { "Output Sequence (Initial)", "ipvs.out_seq.initial", FT_UINT32, 
320                                 BASE_HEX, NULL, 0, "Output Sequence (Initial)", HFILL }},
321         
322                 { &hf_out_seq_delta,
323                         { "Output Sequence (Delta)", "ipvs.out_seq.delta", FT_UINT32, 
324                                 BASE_HEX, NULL, 0, "Output Sequence (Delta)", HFILL }},
325         
326                 { &hf_out_seq_pdelta,
327                         { "Output Sequence (Previous Delta)", "ipvs.out_seq.pdelta", FT_UINT32, 
328                                 BASE_HEX, NULL, 0, "Output Sequence (Previous Delta)", HFILL }},
329         
330
331
332
333         };
334         static gint *ett[] = {
335                 &ett_ipvs_syncd,
336                 &ett_conn,
337                 &ett_flags,
338         };
339
340         proto_ipvs_syncd = proto_register_protocol("IP Virtual Services Sync Daemon",
341             "IPVS", "ipvs");
342         proto_register_field_array(proto_ipvs_syncd, hf, array_length(hf));
343         proto_register_subtree_array(ett, array_length(ett));
344 }
345
346 void
347 proto_reg_handoff_ipvs_syncd(void)
348 {
349         dissector_handle_t ipvs_syncd_handle;
350
351         ipvs_syncd_handle = create_dissector_handle(dissect_ipvs_syncd, proto_ipvs_syncd);
352         dissector_add("udp.port", IPVS_SYNCD_PORT, ipvs_syncd_handle);
353 }