2 * Routines for Web Cache Coordination Protocol dissection
3 * Jerry Talkington <jerryt@netapp.com>
5 * $Id: packet-wccp.c,v 1.4 1999/12/14 02:09:52 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
42 static int proto_wccp = -1;
43 static int hf_wccp_message_type = -1; /* the message type */
44 static int hf_wccp_version = -1; /* protocol version */
45 static int hf_hash_revision = -1; /* the version of the hash */
46 static int hf_change_num = -1; /* change number */
47 static int hf_recvd_id = -1;
48 static int hf_cache_ip = -1;
50 static gint ett_wccp = -1;
51 static gint ett_cache_count = -1;
52 static gint ett_buckets = -1;
53 static gint ett_flags = -1;
54 static gint ett_cache_info = -1;
59 * http://search.ietf.org/internet-drafts/draft-ietf-wrec-web-pro-00.txt
61 * if it hasn't expired yet.
64 #define WCCP_HERE_I_AM 7
65 #define WCCP_I_SEE_YOU 8
66 #define WCCP_ASSIGN_BUCKET 9
68 static const value_string wccp_type_vals[] = {
69 { WCCP_HERE_I_AM, "Here I am" },
70 { WCCP_I_SEE_YOU, "I see you" },
71 { WCCP_ASSIGN_BUCKET, "Assign bucket" },
75 static const value_string wccp_version_val[] = {
80 #define HASH_INFO_SIZE (4*(1+8+1))
82 #define WCCP_U_FLAG 0x80000000
84 static void dissect_hash_data(const u_char *pd, int offset,
85 proto_tree *wccp_tree);
86 static void dissect_web_cache_list_entry(const u_char *pd, int offset,
87 int index, proto_tree *wccp_tree);
88 static int wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree,
89 guint32 start, int offset);
90 static gchar *bucket_name(guint8 bucket);
93 dissect_wccp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
95 proto_tree *wccp_tree = NULL;
96 proto_item *wccp_tree_item;
97 guint32 wccp_message_type;
102 if(check_col(fd, COL_PROTOCOL)) {
103 col_add_str(fd, COL_PROTOCOL, "WCCP");
106 wccp_message_type = pntohl(&pd[offset]);
108 if(check_col(fd, COL_INFO)) {
109 col_add_str(fd, COL_INFO, val_to_str(wccp_message_type,
110 wccp_type_vals, "Unknown WCCP message (%u)"));
114 wccp_tree_item = proto_tree_add_item(tree, proto_wccp, offset,
116 wccp_tree = proto_item_add_subtree(wccp_tree_item, ett_wccp);
118 proto_tree_add_item(wccp_tree, hf_wccp_message_type, offset,
119 sizeof(wccp_message_type), wccp_message_type);
120 offset += sizeof(wccp_message_type);
122 switch (wccp_message_type) {
125 wccp_version = pntohl(&pd[offset]);
126 proto_tree_add_item(wccp_tree, hf_wccp_version,
127 offset, 4, wccp_version);
129 dissect_hash_data(pd, offset, wccp_tree);
130 offset += HASH_INFO_SIZE;
131 proto_tree_add_item(wccp_tree, hf_recvd_id, offset,
132 4, pntohl(&pd[offset]));
137 wccp_version = pntohl(&pd[offset]);
138 proto_tree_add_item(wccp_tree, hf_wccp_version,
139 offset, 4, wccp_version);
141 proto_tree_add_item(wccp_tree, hf_change_num, offset,
142 4, pntohl(&pd[offset]));
144 proto_tree_add_item(wccp_tree, hf_recvd_id, offset,
145 4, pntohl(&pd[offset]));
147 cache_count = pntohl(&pd[offset]);
148 proto_tree_add_text(wccp_tree, offset, 4,
149 "Number of Web Caches: %u", cache_count);
151 for (i = 0; i < cache_count; i++) {
152 dissect_web_cache_list_entry(pd, offset, i,
154 offset += 4 + HASH_INFO_SIZE;
158 case WCCP_ASSIGN_BUCKET:
160 * This hasn't been tested, since I don't have any
161 * traces with this in it.
163 proto_tree_add_item(wccp_tree, hf_recvd_id, offset,
164 4, pntohl(&pd[offset]));
166 cache_count = pntohl(&pd[offset]);
167 proto_tree_add_text(wccp_tree, offset, 4,
168 "Number of Web Caches: %u", cache_count);
170 for (i = 0; i < cache_count; i++) {
171 proto_tree_add_item_format(wccp_tree,
172 hf_cache_ip, offset, 4,
174 "Web Cache %d IP Address: %s", i,
175 ip_to_str((guint8 *) &pd[offset]));
178 for (i = 0; i < 256; i += 4) {
179 proto_tree_add_text(wccp_tree, offset, 4,
180 "Buckets %d - %d: %10s %10s %10s %10s",
182 bucket_name(pd[offset]),
183 bucket_name(pd[offset+1]),
184 bucket_name(pd[offset+2]),
185 bucket_name(pd[offset+3]));
191 wccp_version = pntohl(&pd[offset]);
192 proto_tree_add_item(wccp_tree, hf_wccp_version,
193 offset, 4, wccp_version);
195 dissect_data(pd, offset, fd, wccp_tree);
202 dissect_hash_data(const u_char *pd, int offset, proto_tree *wccp_tree)
204 proto_item *bucket_item;
205 proto_tree *bucket_tree;
207 proto_tree *field_tree;
213 proto_tree_add_item(wccp_tree, hf_hash_revision, offset, 4,
214 pntohl(&pd[offset]));
217 bucket_item = proto_tree_add_text(wccp_tree, offset, 32,
219 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
221 for (i = 0, n = 0; i < 32; i++) {
222 bucket_info = pd[offset];
223 n = wccp_bucket_info(bucket_info, bucket_tree, n, offset);
226 flags = pntohl(&pd[offset]);
227 tf = proto_tree_add_text(wccp_tree, offset, 4,
228 "Flags: 0x%08X (%s)", flags,
229 ((flags & WCCP_U_FLAG) ?
230 "Hash information is historical" :
231 "Hash information is current"));
232 field_tree = proto_item_add_subtree(tf, ett_flags);
233 proto_tree_add_text(field_tree, offset, 4, "%s",
234 decode_boolean_bitfield(flags, WCCP_U_FLAG,
236 "Hash information is historical",
237 "Hash information is current"));
241 dissect_web_cache_list_entry(const u_char *pd, int offset, int index,
242 proto_tree *wccp_tree)
245 proto_tree *list_entry_tree;
247 tl = proto_tree_add_text(wccp_tree, offset, 4 + HASH_INFO_SIZE,
248 "Web-Cache List Entry(%d)", index);
249 list_entry_tree = proto_item_add_subtree(tl,
251 proto_tree_add_item(list_entry_tree, hf_cache_ip, offset, 4,
252 pntohl(&pd[offset]));
253 dissect_hash_data(pd, offset + 4, list_entry_tree);
258 * takes an integer representing a "Hash Information" bitmap, and spits out
259 * the corresponding proto_tree entries, returning the next bucket number.
262 wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree, guint32 start,
267 for(i = 0; i < 8; i++) {
268 proto_tree_add_text(bucket_tree, offset, sizeof(bucket_info), "Bucket %3d: %s", start, (bucket_info & 1<<i ? "Assigned" : "Not Assigned") );
275 bucket_name(guint8 bucket)
277 static gchar str[4][10+1];
280 if (cur == &str[0][0])
282 else if (cur == &str[1][0])
284 else if (cur == &str[2][0])
289 strcpy(cur, "Unassigned");
291 sprintf(cur, "%u", bucket);
296 proto_register_wccp(void)
298 static hf_register_info hf[] = {
299 { &hf_wccp_message_type,
300 { "WCCP Message Type", "wccp.message", FT_UINT32, BASE_DEC, VALS(wccp_type_vals), 0x0,
301 "The WCCP message that was sent"}
304 { "WCCP Version", "wccp.version", FT_UINT32, BASE_DEC, VALS(wccp_version_val), 0x0,
308 { "Hash Revision", "wccp.hash_revision", FT_UINT32, BASE_DEC, 0x0, 0x0,
309 "The cache hash revision"}
312 { "Change Number", "wccp.change_num", FT_UINT32, BASE_DEC, 0x0, 0x0,
313 "The Web-Cache list entry change number"}
316 { "Received ID", "wccp.recvd_id", FT_UINT32, BASE_DEC, 0x0, 0x0,
317 "The number of I_SEE_YOU's that have been sent"}
320 { "Web Cache IP address", "wccp.cache_ip", FT_IPv4, BASE_NONE, NULL, 0x0,
321 "The IP address of a Web cache"}
324 static gint *ett[] = {
332 proto_wccp = proto_register_protocol("Web Cache Coordination Protocol",
334 proto_register_field_array(proto_wccp, hf, array_length(hf));
335 proto_register_subtree_array(ett, array_length(ett));