Don't guard col_set_str (COL_INFO/COL_PROTOCOL) with col_check
[obnox/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  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
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 #include <epan/packet.h>
34 #include <epan/ipproto.h>
35 #include <epan/in_cksum.h>
36
37 static int proto_ipvs_syncd = -1;
38 static int hf_conn_count = -1;
39 static int hf_syncid = -1;
40 static int hf_size = -1;
41 static int hf_resv8 = -1;
42 static int hf_proto = -1;
43 static int hf_cport = -1;
44 static int hf_vport = -1;
45 static int hf_dport = -1;
46 static int hf_caddr = -1;
47 static int hf_vaddr = -1;
48 static int hf_daddr = -1;
49 static int hf_flags = -1;
50 static int hf_state = -1;
51 static int hf_in_seq_init = -1;
52 static int hf_in_seq_delta = -1;
53 static int hf_in_seq_pdelta = -1;
54 static int hf_out_seq_init = -1;
55 static int hf_out_seq_delta = -1;
56 static int hf_out_seq_pdelta = -1;
57
58 static int ett_ipvs_syncd = -1;
59 static int ett_conn = -1;
60 static int ett_flags = -1;
61
62 #define IPVS_SYNCD_MC_GROUP "224.0.0.18"
63 #define IPVS_SYNCD_PORT 8848
64
65 static const value_string proto_strings[] = {
66         {0x06, "TCP"},
67         {0x11, "UDP"},
68         {0x00, NULL},
69 };
70
71 static const value_string state_strings[] = {
72         {0x00, "Input"},
73         {0x04, "Output"},
74         {0x08, "Input Only"},
75         {0x00, NULL},
76 };
77
78 /*
79  *  IPVS Connection Flags
80  *  Pulled from include/net/ip_vs.h in linux kernel source
81  */
82 #define IP_VS_CONN_F_FWD_MASK         0x0007    /* mask for the fwd methods */
83 #define IP_VS_CONN_F_MASQ             0x0000    /* masquerading */
84 #define IP_VS_CONN_F_LOCALNODE        0x0001    /* local node */
85 #define IP_VS_CONN_F_TUNNEL           0x0002    /* tunneling */
86 #define IP_VS_CONN_F_DROUTE           0x0003    /* direct routing */
87 #define IP_VS_CONN_F_BYPASS           0x0004    /* cache bypass */
88 #define IP_VS_CONN_F_HASHED           0x0040    /* hashed entry */
89 #define IP_VS_CONN_F_NOOUTPUT         0x0080    /* no output packets */
90 #define IP_VS_CONN_F_INACTIVE         0x0100    /* not established */
91 #define IP_VS_CONN_F_OUT_SEQ          0x0200    /* must do output seq adjust */
92 #define IP_VS_CONN_F_IN_SEQ           0x0400    /* must do input seq adjust */
93 #define IP_VS_CONN_F_SEQ_MASK         0x0600    /* in/out sequence mask */
94 #define IP_VS_CONN_F_NO_CPORT         0x0800    /* no client port set yet */
95
96
97 static void
98 dissect_ipvs_syncd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
99 {
100         proto_tree *tree;
101         proto_item *item;
102         int offset = 0;
103         guint8 cnt = 0;
104         int conn = 0;
105
106         item = proto_tree_add_item(parent_tree, proto_ipvs_syncd, tvb, offset, -1, FALSE);
107         tree = proto_item_add_subtree(item, ett_ipvs_syncd);
108
109
110         col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPVS");
111         if (check_col(pinfo->cinfo, COL_INFO)) {
112                 col_clear(pinfo->cinfo, COL_INFO);
113         }
114
115         cnt = tvb_get_guint8(tvb, offset);
116         proto_tree_add_item(tree, hf_conn_count, tvb, offset, 1, FALSE);
117         offset += 1;
118
119         proto_tree_add_item(tree, hf_syncid, tvb, offset, 1, FALSE);
120         offset += 1;
121
122         proto_tree_add_item(tree, hf_size, tvb, offset, 2, FALSE);
123         offset += 2;
124
125         for (conn = 0; conn < cnt; conn++)
126         {
127                 proto_tree *ctree, *ti; 
128                 proto_tree *ftree, *fi;
129                 guint16 flags; 
130
131                 ti = proto_tree_add_text(tree, tvb, offset, 24, "Connection #%d", conn+1);
132                 ctree = proto_item_add_subtree(ti, ett_conn);
133
134                 proto_tree_add_item(ctree, hf_resv8, tvb, offset, 1, FALSE);
135                 offset += 1;
136                 
137                 proto_tree_add_item(ctree, hf_proto, tvb, offset, 1, FALSE);
138                 offset += 1;
139                 
140                 proto_tree_add_item(ctree, hf_cport, tvb, offset, 2, FALSE);
141                 offset += 2;
142                 
143                 proto_tree_add_item(ctree, hf_vport, tvb, offset, 2, FALSE);
144                 offset += 2;
145                 
146                 proto_tree_add_item(ctree, hf_dport, tvb, offset, 2, FALSE);
147                 offset += 2;
148                 
149                 proto_tree_add_item(ctree, hf_caddr, tvb, offset, 4, FALSE);
150                 offset += 4;
151                 
152                 proto_tree_add_item(ctree, hf_vaddr, tvb, offset, 4, FALSE);
153                 offset += 4;
154                 
155                 proto_tree_add_item(ctree, hf_daddr, tvb, offset, 4, FALSE);
156                 offset += 4;
157                 
158                 flags = tvb_get_ntohs(tvb, offset);
159                 fi = proto_tree_add_item(ctree, hf_flags, tvb, offset, 2, FALSE);
160                 ftree = proto_item_add_subtree(fi, ett_flags);
161
162                 if ( (flags & 0x0F) == IP_VS_CONN_F_MASQ )
163                 {
164                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Masquerade");
165                 }
166                 else if ( (flags & 0x0F) == IP_VS_CONN_F_LOCALNODE )
167                 {
168                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Local Node");
169                 }
170                 else if ( (flags & 0x0F) == IP_VS_CONN_F_TUNNEL )
171                 {
172                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Tunnel");
173                 }
174                 else if ( (flags & 0x0F) == IP_VS_CONN_F_DROUTE )
175                 {
176                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Direct Routing");
177                 }
178                 else
179                 {
180                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Connection Type: Unknown (%d)", 
181                                 flags & IP_VS_CONN_F_FWD_MASK);
182                 }
183
184                 if ( flags & IP_VS_CONN_F_HASHED )
185                 {
186                         proto_tree_add_text(ftree, tvb, offset+1, 1, "Hashed Entry");
187                 }
188
189                 if ( flags & IP_VS_CONN_F_NOOUTPUT )
190                 {
191                         proto_tree_add_text(ftree, tvb, offset+1, 1, "No Output Packets");
192                 }
193
194                 if ( flags & IP_VS_CONN_F_INACTIVE )
195                 {
196                         proto_tree_add_text(ftree, tvb, offset, 1, "Connection Not Established");
197                 }
198
199                 if ( flags & IP_VS_CONN_F_OUT_SEQ )
200                 {
201                         proto_tree_add_text(ftree, tvb, offset, 1, "Adjust Output Sequence");
202                 }
203
204                 if ( flags & IP_VS_CONN_F_IN_SEQ )
205                 {
206                         proto_tree_add_text(ftree, tvb, offset, 1, "Adjust Input Sequence");
207                 }
208
209                 if ( flags & IP_VS_CONN_F_NO_CPORT )
210                 {
211                         proto_tree_add_text(ftree, tvb, offset, 1, "No Client Port Set");
212                 }
213                 
214                 offset += 2;
215                 
216                 proto_tree_add_item(ctree, hf_state, tvb, offset, 2, FALSE);
217                 offset += 2;
218                 
219                 /* we have full connection info */
220                 if ( flags & IP_VS_CONN_F_SEQ_MASK )
221                 {
222                         proto_tree_add_item(ctree, hf_in_seq_init, tvb, offset, 4, FALSE);
223                         offset += 4;
224                 
225                         proto_tree_add_item(ctree, hf_in_seq_delta, tvb, offset, 4, FALSE);
226                         offset += 4;
227                 
228                         proto_tree_add_item(ctree, hf_in_seq_pdelta, tvb, offset, 4, FALSE);
229                         offset += 4;
230                 
231                         proto_tree_add_item(ctree, hf_out_seq_init, tvb, offset, 4, FALSE);
232                         offset += 4;
233                 
234                         proto_tree_add_item(ctree, hf_out_seq_delta, tvb, offset, 4, FALSE);
235                         offset += 4;
236                 
237                         proto_tree_add_item(ctree, hf_out_seq_pdelta, tvb, offset, 4, FALSE);
238                         offset += 4;
239                 }
240                 
241         }
242 }
243
244 void
245 proto_register_ipvs_syncd(void)
246 {
247         static hf_register_info hf[] = {
248                 { &hf_conn_count,
249                         { "Connection Count", "ipvs.conncount", FT_UINT8, BASE_DEC,
250                           NULL, 0, NULL, HFILL }},
251
252                 { &hf_syncid,
253                         { "Synchronization ID", "ipvs.syncid", FT_UINT8, BASE_DEC,
254                           NULL, 0, NULL, HFILL }},
255
256                 { &hf_size,
257                         { "Size", "ipvs.size", FT_UINT16, BASE_DEC,
258                           NULL, 0, NULL, HFILL }},
259
260                 { &hf_resv8,
261                         { "Reserved", "ipvs.resv8", FT_UINT8, BASE_HEX,
262                           NULL, 0, NULL, HFILL }},
263
264                 { &hf_proto,
265                         { "Protocol", "ipvs.proto", FT_UINT8, BASE_HEX,
266                           VALS(&proto_strings), 0, NULL, HFILL }},
267
268                 { &hf_cport,
269                         { "Client Port", "ipvs.cport", FT_UINT16, BASE_DEC,
270                           NULL, 0, NULL, HFILL }},
271
272                 { &hf_vport,
273                         { "Virtual Port", "ipvs.vport", FT_UINT16, BASE_DEC,
274                           NULL, 0, NULL, HFILL }},
275
276                 { &hf_dport,
277                         { "Destination Port", "ipvs.dport", FT_UINT16, BASE_DEC,
278                           NULL, 0, NULL, HFILL }},
279
280                 { &hf_caddr,
281                         { "Client Address", "ipvs.caddr", FT_IPv4, BASE_NONE,
282                           NULL, 0, NULL, HFILL }},
283
284                 { &hf_vaddr,
285                         { "Virtual Address", "ipvs.vaddr", FT_IPv4, BASE_NONE,
286                           NULL, 0, NULL, HFILL }},
287
288                 { &hf_daddr,
289                         { "Destination Address", "ipvs.daddr", FT_IPv4, BASE_NONE,
290                           NULL, 0, NULL, HFILL }},
291
292                 { &hf_flags,
293                         { "Flags", "ipvs.flags", FT_UINT16, BASE_HEX,
294                           NULL, 0, NULL, HFILL }},
295
296                 { &hf_state,
297                         { "State", "ipvs.state", FT_UINT16, BASE_HEX,
298                           VALS(&state_strings), 0, NULL, HFILL }},
299         
300                 { &hf_in_seq_init,
301                         { "Input Sequence (Initial)", "ipvs.in_seq.initial", FT_UINT32, 
302                                 BASE_HEX, NULL, 0, NULL, HFILL }},
303         
304                 { &hf_in_seq_delta,
305                         { "Input Sequence (Delta)", "ipvs.in_seq.delta", FT_UINT32, 
306                                 BASE_HEX, NULL, 0, NULL, HFILL }},
307         
308                 { &hf_in_seq_pdelta,
309                         { "Input Sequence (Previous Delta)", "ipvs.in_seq.pdelta", FT_UINT32, 
310                                 BASE_HEX, NULL, 0, NULL, HFILL }},
311         
312                 { &hf_out_seq_init,
313                         { "Output Sequence (Initial)", "ipvs.out_seq.initial", FT_UINT32, 
314                                 BASE_HEX, NULL, 0, NULL, HFILL }},
315         
316                 { &hf_out_seq_delta,
317                         { "Output Sequence (Delta)", "ipvs.out_seq.delta", FT_UINT32, 
318                                 BASE_HEX, NULL, 0, NULL, HFILL }},
319         
320                 { &hf_out_seq_pdelta,
321                         { "Output Sequence (Previous Delta)", "ipvs.out_seq.pdelta", FT_UINT32, 
322                                 BASE_HEX, NULL, 0, NULL, HFILL }},
323         
324
325
326
327         };
328         static gint *ett[] = {
329                 &ett_ipvs_syncd,
330                 &ett_conn,
331                 &ett_flags,
332         };
333
334         proto_ipvs_syncd = proto_register_protocol("IP Virtual Services Sync Daemon",
335             "IPVS", "ipvs");
336         proto_register_field_array(proto_ipvs_syncd, hf, array_length(hf));
337         proto_register_subtree_array(ett, array_length(ett));
338 }
339
340 void
341 proto_reg_handoff_ipvs_syncd(void)
342 {
343         dissector_handle_t ipvs_syncd_handle;
344
345         ipvs_syncd_handle = create_dissector_handle(dissect_ipvs_syncd, proto_ipvs_syncd);
346         dissector_add("udp.port", IPVS_SYNCD_PORT, ipvs_syncd_handle);
347 }