2 * Routines for Web Cache Coordination Protocol dissection
3 * Jerry Talkington <jerryt@netapp.com>
5 * $Id: packet-wccp.c,v 1.7 2000/05/11 08:15:55 gram 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 UDP_PORT_WCCP 2048
67 #define WCCP_HERE_I_AM 7
68 #define WCCP_I_SEE_YOU 8
69 #define WCCP_ASSIGN_BUCKET 9
71 static const value_string wccp_type_vals[] = {
72 { WCCP_HERE_I_AM, "Here I am" },
73 { WCCP_I_SEE_YOU, "I see you" },
74 { WCCP_ASSIGN_BUCKET, "Assign bucket" },
78 static const value_string wccp_version_val[] = {
83 #define HASH_INFO_SIZE (4*(1+8+1))
85 #define WCCP_U_FLAG 0x80000000
87 static void dissect_hash_data(const u_char *pd, int offset,
88 proto_tree *wccp_tree);
89 static void dissect_web_cache_list_entry(const u_char *pd, int offset,
90 int index, proto_tree *wccp_tree);
91 static int wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree,
92 guint32 start, int offset);
93 static gchar *bucket_name(guint8 bucket);
96 dissect_wccp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
98 proto_tree *wccp_tree = NULL;
99 proto_item *wccp_tree_item;
100 guint32 wccp_message_type;
101 guint32 wccp_version;
105 if(check_col(fd, COL_PROTOCOL)) {
106 col_add_str(fd, COL_PROTOCOL, "WCCP");
109 wccp_message_type = pntohl(&pd[offset]);
111 if(check_col(fd, COL_INFO)) {
112 col_add_str(fd, COL_INFO, val_to_str(wccp_message_type,
113 wccp_type_vals, "Unknown WCCP message (%u)"));
117 wccp_tree_item = proto_tree_add_item(tree, proto_wccp, NullTVB, offset,
119 wccp_tree = proto_item_add_subtree(wccp_tree_item, ett_wccp);
121 proto_tree_add_item(wccp_tree, hf_wccp_message_type, NullTVB, offset,
122 sizeof(wccp_message_type), wccp_message_type);
123 offset += sizeof(wccp_message_type);
125 switch (wccp_message_type) {
128 wccp_version = pntohl(&pd[offset]);
129 proto_tree_add_item(wccp_tree, hf_wccp_version, NullTVB,
130 offset, 4, wccp_version);
132 dissect_hash_data(pd, offset, wccp_tree);
133 offset += HASH_INFO_SIZE;
134 proto_tree_add_item(wccp_tree, hf_recvd_id, NullTVB, offset,
135 4, pntohl(&pd[offset]));
140 wccp_version = pntohl(&pd[offset]);
141 proto_tree_add_item(wccp_tree, hf_wccp_version, NullTVB,
142 offset, 4, wccp_version);
144 proto_tree_add_item(wccp_tree, hf_change_num, NullTVB, offset,
145 4, pntohl(&pd[offset]));
147 proto_tree_add_item(wccp_tree, hf_recvd_id, NullTVB, offset,
148 4, pntohl(&pd[offset]));
150 cache_count = pntohl(&pd[offset]);
151 proto_tree_add_text(wccp_tree, NullTVB, offset, 4,
152 "Number of Web Caches: %u", cache_count);
154 for (i = 0; i < cache_count; i++) {
155 dissect_web_cache_list_entry(pd, offset, i,
157 offset += 4 + HASH_INFO_SIZE;
161 case WCCP_ASSIGN_BUCKET:
163 * This hasn't been tested, since I don't have any
164 * traces with this in it.
166 proto_tree_add_item(wccp_tree, hf_recvd_id, NullTVB, offset,
167 4, pntohl(&pd[offset]));
169 cache_count = pntohl(&pd[offset]);
170 proto_tree_add_text(wccp_tree, NullTVB, offset, 4,
171 "Number of Web Caches: %u", cache_count);
173 for (i = 0; i < cache_count; i++) {
174 proto_tree_add_ipv4_format(wccp_tree,
175 hf_cache_ip, NullTVB, offset, 4,
177 "Web Cache %d IP Address: %s", i,
178 ip_to_str((guint8 *) &pd[offset]));
181 for (i = 0; i < 256; i += 4) {
182 proto_tree_add_text(wccp_tree, NullTVB, offset, 4,
183 "Buckets %d - %d: %10s %10s %10s %10s",
185 bucket_name(pd[offset]),
186 bucket_name(pd[offset+1]),
187 bucket_name(pd[offset+2]),
188 bucket_name(pd[offset+3]));
194 wccp_version = pntohl(&pd[offset]);
195 proto_tree_add_item(wccp_tree, hf_wccp_version, NullTVB,
196 offset, 4, wccp_version);
198 dissect_data(pd, offset, fd, wccp_tree);
205 dissect_hash_data(const u_char *pd, int offset, proto_tree *wccp_tree)
207 proto_item *bucket_item;
208 proto_tree *bucket_tree;
210 proto_tree *field_tree;
216 proto_tree_add_item(wccp_tree, hf_hash_revision, NullTVB, offset, 4,
217 pntohl(&pd[offset]));
220 bucket_item = proto_tree_add_text(wccp_tree, NullTVB, offset, 32,
222 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
224 for (i = 0, n = 0; i < 32; i++) {
225 bucket_info = pd[offset];
226 n = wccp_bucket_info(bucket_info, bucket_tree, n, offset);
229 flags = pntohl(&pd[offset]);
230 tf = proto_tree_add_text(wccp_tree, NullTVB, offset, 4,
231 "Flags: 0x%08X (%s)", flags,
232 ((flags & WCCP_U_FLAG) ?
233 "Hash information is historical" :
234 "Hash information is current"));
235 field_tree = proto_item_add_subtree(tf, ett_flags);
236 proto_tree_add_text(field_tree, NullTVB, offset, 4, "%s",
237 decode_boolean_bitfield(flags, WCCP_U_FLAG,
239 "Hash information is historical",
240 "Hash information is current"));
244 dissect_web_cache_list_entry(const u_char *pd, int offset, int index,
245 proto_tree *wccp_tree)
248 proto_tree *list_entry_tree;
250 tl = proto_tree_add_text(wccp_tree, NullTVB, offset, 4 + HASH_INFO_SIZE,
251 "Web-Cache List Entry(%d)", index);
252 list_entry_tree = proto_item_add_subtree(tl,
254 proto_tree_add_item(list_entry_tree, hf_cache_ip, NullTVB, offset, 4,
255 pntohl(&pd[offset]));
256 dissect_hash_data(pd, offset + 4, list_entry_tree);
261 * takes an integer representing a "Hash Information" bitmap, and spits out
262 * the corresponding proto_tree entries, returning the next bucket number.
265 wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree, guint32 start,
270 for(i = 0; i < 8; i++) {
271 proto_tree_add_text(bucket_tree, NullTVB, offset, sizeof(bucket_info), "Bucket %3d: %s", start, (bucket_info & 1<<i ? "Assigned" : "Not Assigned") );
278 bucket_name(guint8 bucket)
280 static gchar str[4][10+1];
283 if (cur == &str[0][0])
285 else if (cur == &str[1][0])
287 else if (cur == &str[2][0])
292 strcpy(cur, "Unassigned");
294 sprintf(cur, "%u", bucket);
299 proto_register_wccp(void)
301 static hf_register_info hf[] = {
302 { &hf_wccp_message_type,
303 { "WCCP Message Type", "wccp.message", FT_UINT32, BASE_DEC, VALS(wccp_type_vals), 0x0,
304 "The WCCP message that was sent"}
307 { "WCCP Version", "wccp.version", FT_UINT32, BASE_DEC, VALS(wccp_version_val), 0x0,
311 { "Hash Revision", "wccp.hash_revision", FT_UINT32, BASE_DEC, 0x0, 0x0,
312 "The cache hash revision"}
315 { "Change Number", "wccp.change_num", FT_UINT32, BASE_DEC, 0x0, 0x0,
316 "The Web-Cache list entry change number"}
319 { "Received ID", "wccp.recvd_id", FT_UINT32, BASE_DEC, 0x0, 0x0,
320 "The number of I_SEE_YOU's that have been sent"}
323 { "Web Cache IP address", "wccp.cache_ip", FT_IPv4, BASE_NONE, NULL, 0x0,
324 "The IP address of a Web cache"}
327 static gint *ett[] = {
335 proto_wccp = proto_register_protocol("Web Cache Coordination Protocol",
337 proto_register_field_array(proto_wccp, hf, array_length(hf));
338 proto_register_subtree_array(ett, array_length(ett));
342 proto_reg_handoff_wccp(void)
344 dissector_add("udp.port", UDP_PORT_WCCP, dissect_wccp);