2 * Routines for Web Cache Coordination Protocol dissection
3 * Jerry Talkington <jerryt@netapp.com>
5 * $Id: packet-wccp.c,v 1.33 2002/08/28 21:00:37 jmayer Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/packet.h>
33 #include <epan/strutil.h>
34 #include "packet-wccp.h"
36 #ifdef NEED_SNPRINTF_H
37 # include "snprintf.h"
40 static int proto_wccp = -1;
41 static int hf_wccp_message_type = -1; /* the message type */
42 static int hf_wccp_version = -1; /* protocol version */
43 static int hf_hash_revision = -1; /* the version of the hash */
44 static int hf_change_num = -1; /* change number */
45 static int hf_recvd_id = -1;
46 static int hf_cache_ip = -1;
48 static gint ett_wccp = -1;
49 static gint ett_cache_count = -1;
50 static gint ett_buckets = -1;
51 static gint ett_flags = -1;
52 static gint ett_cache_info = -1;
53 static gint ett_security_info = -1;
54 static gint ett_service_info = -1;
55 static gint ett_service_flags = -1;
56 static gint ett_router_identity_element = -1;
57 static gint ett_router_identity_info = -1;
58 static gint ett_wc_identity_element = -1;
59 static gint ett_wc_identity_info = -1;
60 static gint ett_router_view_info = -1;
61 static gint ett_wc_view_info = -1;
62 static gint ett_router_assignment_element = -1;
63 static gint ett_router_assignment_info = -1;
64 static gint ett_query_info = -1;
65 static gint ett_capabilities_info = -1;
66 static gint ett_capability_element = -1;
67 static gint ett_capability_forwarding_method = -1;
68 static gint ett_capability_assignment_method = -1;
69 static gint ett_capability_return_method = -1;
70 static gint ett_unknown_info = -1;
75 * http://www.alternic.org/drafts/drafts-f-g/draft-forster-wrec-wccp-v1-00.html
77 * is a copy of the now-expired Internet-Draft for WCCP 1.0.
81 * http://search.ietf.org/internet-drafts/draft-wilson-wrec-wccp-v2-01.txt
83 * is an Internet-Draft for WCCP 2.0.
86 #define UDP_PORT_WCCP 2048
90 #define WCCP_HERE_I_AM 7
91 #define WCCP_I_SEE_YOU 8
92 #define WCCP_ASSIGN_BUCKET 9
93 #define WCCP2_HERE_I_AM 10
94 #define WCCP2_I_SEE_YOU 11
95 #define WCCP2_REDIRECT_ASSIGN 12
96 #define WCCP2_REMOVAL_QUERY 13
98 static const value_string wccp_type_vals[] = {
99 { WCCP_HERE_I_AM, "1.0 Here I am" },
100 { WCCP_I_SEE_YOU, "1.0 I see you" },
101 { WCCP_ASSIGN_BUCKET, "1.0 Assign bucket" },
102 { WCCP2_HERE_I_AM, "2.0 Here I am" },
103 { WCCP2_I_SEE_YOU, "2.0 I see you" },
104 { WCCP2_REDIRECT_ASSIGN, "2.0 Redirect assign" },
105 { WCCP2_REMOVAL_QUERY, "2.0 Removal query" },
109 static const value_string wccp_version_val[] = {
115 #define HASH_INFO_SIZE (4*(1+8+1))
117 #define WCCP_U_FLAG 0x80000000
119 #define WCCP2_SECURITY_INFO 0
120 #define WCCP2_SERVICE_INFO 1
121 #define WCCP2_ROUTER_ID_INFO 2
122 #define WCCP2_WC_ID_INFO 3
123 #define WCCP2_RTR_VIEW_INFO 4
124 #define WCCP2_WC_VIEW_INFO 5
125 #define WCCP2_REDIRECT_ASSIGNMENT 6
126 #define WCCP2_QUERY_INFO 7
127 #define WCCP2_CAPABILITIES_INFO 8
128 #define WCCP2_ALT_ASSIGNMENT 13
129 #define WCCP2_ASSIGN_MAP 14
130 #define WCCP2_COMMAND_EXTENSION 15
132 static const value_string info_type_vals[] = {
133 { WCCP2_SECURITY_INFO, "Security Info" },
134 { WCCP2_SERVICE_INFO, "Service Info" },
135 { WCCP2_ROUTER_ID_INFO, "Router Identity Info" },
136 { WCCP2_WC_ID_INFO, "Web-Cache Identity Info" },
137 { WCCP2_RTR_VIEW_INFO, "Router View Info" },
138 { WCCP2_WC_VIEW_INFO, "Web-Cache View Info" },
139 { WCCP2_REDIRECT_ASSIGNMENT, "Assignment Info" },
140 { WCCP2_QUERY_INFO, "Query Info" },
141 { WCCP2_CAPABILITIES_INFO, "Capabilities Info" },
142 { WCCP2_COMMAND_EXTENSION, "Command Extension" },
146 const value_string service_id_vals[] = {
151 typedef struct capability_flag {
153 const char *short_name;
154 const char *long_name;
157 static void dissect_hash_data(tvbuff_t *tvb, int offset,
158 proto_tree *wccp_tree);
159 static void dissect_web_cache_list_entry(tvbuff_t *tvb, int offset,
160 int index, proto_tree *wccp_tree);
161 static int wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree,
162 guint32 start, tvbuff_t *tvb, int offset);
163 static gchar *bucket_name(guint8 bucket);
164 static guint16 dissect_wccp2_header(tvbuff_t *tvb, int offset,
165 proto_tree *wccp_tree);
166 static void dissect_wccp2_info(tvbuff_t *tvb, int offset, guint16 length,
167 proto_tree *wccp_tree);
168 static gboolean dissect_wccp2_security_info(tvbuff_t *tvb, int offset,
169 int length, proto_tree *info_tree);
170 static gboolean dissect_wccp2_service_info(tvbuff_t *tvb, int offset,
171 int length, proto_tree *info_tree);
172 static gboolean dissect_wccp2_router_identity_info(tvbuff_t *tvb,
173 int offset, int length, proto_tree *info_tree);
174 static gboolean dissect_wccp2_wc_identity_info(tvbuff_t *tvb, int offset,
175 int length, proto_tree *info_tree);
176 static gboolean dissect_wccp2_router_view_info(tvbuff_t *tvb, int offset,
177 int length, proto_tree *info_tree);
178 static gboolean dissect_wccp2_wc_view_info(tvbuff_t *tvb, int offset,
179 int length, proto_tree *info_tree);
180 static gboolean dissect_wccp2_assignment_info(tvbuff_t *tvb, int offset,
181 int length, proto_tree *info_tree);
182 static gboolean dissect_wccp2_router_query_info(tvbuff_t *tvb, int offset,
183 int length, proto_tree *info_tree);
184 static gboolean dissect_wccp2_capability_info(tvbuff_t *tvb, int offset,
185 int length, proto_tree *info_tree);
186 static void dissect_32_bit_capability_flags(tvbuff_t *tvb, int curr_offset,
187 guint16 capability_val_len, gint ett, const capability_flag *flags,
188 proto_tree *element_tree);
191 dissect_wccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
194 proto_tree *wccp_tree = NULL;
195 proto_item *wccp_tree_item;
196 guint32 wccp_message_type;
202 if(check_col(pinfo->cinfo, COL_PROTOCOL)) {
203 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WCCP");
205 if(check_col(pinfo->cinfo, COL_INFO)) {
206 col_clear(pinfo->cinfo, COL_INFO);
209 wccp_message_type = tvb_get_ntohl(tvb, offset);
211 if(check_col(pinfo->cinfo, COL_INFO)) {
212 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(wccp_message_type,
213 wccp_type_vals, "Unknown WCCP message (%u)"));
217 wccp_tree_item = proto_tree_add_item(tree, proto_wccp, tvb, offset,
219 wccp_tree = proto_item_add_subtree(wccp_tree_item, ett_wccp);
221 proto_tree_add_uint(wccp_tree, hf_wccp_message_type, tvb, offset,
222 sizeof(wccp_message_type), wccp_message_type);
223 offset += sizeof(wccp_message_type);
225 switch (wccp_message_type) {
228 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb,
231 dissect_hash_data(tvb, offset, wccp_tree);
232 offset += HASH_INFO_SIZE;
233 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
239 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb,
242 proto_tree_add_item(wccp_tree, hf_change_num, tvb, offset,
245 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
248 cache_count = tvb_get_ntohl(tvb, offset);
249 proto_tree_add_text(wccp_tree, tvb, offset, 4,
250 "Number of Web Caches: %u", cache_count);
252 for (i = 0; i < cache_count; i++) {
253 dissect_web_cache_list_entry(tvb, offset, i,
255 offset += 4 + HASH_INFO_SIZE;
259 case WCCP_ASSIGN_BUCKET:
261 * This hasn't been tested, since I don't have any
262 * traces with this in it.
264 * The V1 spec claims that this does, indeed,
265 * have a Received ID field after the type,
266 * rather than a Version field.
268 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
271 cache_count = tvb_get_ntohl(tvb, offset);
272 proto_tree_add_text(wccp_tree, tvb, offset, 4,
273 "Number of Web Caches: %u", cache_count);
275 for (i = 0; i < cache_count; i++) {
276 tvb_memcpy(tvb, (guint8 *)&ipaddr, offset, 4);
277 proto_tree_add_ipv4_format(wccp_tree,
278 hf_cache_ip, tvb, offset, 4,
280 "Web Cache %d IP Address: %s", i,
281 ip_to_str((guint8 *)&ipaddr));
284 for (i = 0; i < 256; i += 4) {
285 proto_tree_add_text(wccp_tree, tvb, offset, 4,
286 "Buckets %d - %d: %10s %10s %10s %10s",
288 bucket_name(tvb_get_guint8(tvb, offset)),
289 bucket_name(tvb_get_guint8(tvb, offset+1)),
290 bucket_name(tvb_get_guint8(tvb, offset+2)),
291 bucket_name(tvb_get_guint8(tvb, offset+3)));
296 case WCCP2_HERE_I_AM:
297 case WCCP2_I_SEE_YOU:
298 case WCCP2_REMOVAL_QUERY:
299 case WCCP2_REDIRECT_ASSIGN:
300 default: /* assume unknown packets are v2 */
301 length = dissect_wccp2_header(tvb, offset, wccp_tree);
303 dissect_wccp2_info(tvb, offset, length, wccp_tree);
310 dissect_hash_data(tvbuff_t *tvb, int offset, proto_tree *wccp_tree)
312 proto_item *bucket_item;
313 proto_tree *bucket_tree;
315 proto_tree *field_tree;
321 proto_tree_add_item(wccp_tree, hf_hash_revision, tvb, offset, 4,
325 bucket_item = proto_tree_add_text(wccp_tree, tvb, offset, 32,
327 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
329 for (i = 0, n = 0; i < 32; i++) {
330 bucket_info = tvb_get_guint8(tvb, offset);
331 n = wccp_bucket_info(bucket_info, bucket_tree, n, tvb, offset);
334 flags = tvb_get_ntohl(tvb, offset);
335 tf = proto_tree_add_text(wccp_tree, tvb, offset, 4,
336 "Flags: 0x%08X (%s)", flags,
337 ((flags & WCCP_U_FLAG) ?
338 "Hash information is historical" :
339 "Hash information is current"));
340 field_tree = proto_item_add_subtree(tf, ett_flags);
341 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
342 decode_boolean_bitfield(flags, WCCP_U_FLAG,
344 "Hash information is historical",
345 "Hash information is current"));
349 dissect_web_cache_list_entry(tvbuff_t *tvb, int offset, int index,
350 proto_tree *wccp_tree)
353 proto_tree *list_entry_tree;
355 tl = proto_tree_add_text(wccp_tree, tvb, offset, 4 + HASH_INFO_SIZE,
356 "Web-Cache List Entry(%d)", index);
357 list_entry_tree = proto_item_add_subtree(tl, ett_cache_info);
358 proto_tree_add_item(list_entry_tree, hf_cache_ip, tvb, offset, 4,
360 dissect_hash_data(tvb, offset + 4, list_entry_tree);
365 * takes an integer representing a "Hash Information" bitmap, and spits out
366 * the corresponding proto_tree entries, returning the next bucket number.
369 wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree, guint32 start,
370 tvbuff_t *tvb, int offset)
374 for(i = 0; i < 8; i++) {
375 proto_tree_add_text(bucket_tree, tvb, offset, sizeof(bucket_info), "Bucket %3d: %s", start, (bucket_info & 1<<i ? "Assigned" : "Not Assigned") );
382 bucket_name(guint8 bucket)
384 static gchar str[4][10+1];
387 if (cur == &str[0][0])
389 else if (cur == &str[1][0])
391 else if (cur == &str[2][0])
396 strcpy(cur, "Unassigned");
398 sprintf(cur, "%u", bucket);
403 dissect_wccp2_header(tvbuff_t *tvb, int offset, proto_tree *wccp_tree)
407 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb, offset, 2,
410 length = tvb_get_ntohs(tvb, offset);
411 proto_tree_add_text(wccp_tree, tvb, offset, 2, "Length: %u",
417 dissect_wccp2_info(tvbuff_t *tvb, int offset, guint16 length,
418 proto_tree *wccp_tree)
423 proto_tree *info_tree;
425 gboolean (*dissector)(tvbuff_t *, int, int, proto_tree *);
427 while (length != 0) {
428 type = tvb_get_ntohs(tvb, offset);
429 item_length = tvb_get_ntohs(tvb, offset+2);
433 case WCCP2_SECURITY_INFO:
434 ett = ett_security_info;
435 dissector = dissect_wccp2_security_info;
438 case WCCP2_SERVICE_INFO:
439 ett = ett_service_info;
440 dissector = dissect_wccp2_service_info;
443 case WCCP2_ROUTER_ID_INFO:
444 ett = ett_router_identity_info;
445 dissector = dissect_wccp2_router_identity_info;
448 case WCCP2_WC_ID_INFO:
449 ett = ett_wc_identity_info;
450 dissector = dissect_wccp2_wc_identity_info;
453 case WCCP2_RTR_VIEW_INFO:
454 ett = ett_router_view_info;
455 dissector = dissect_wccp2_router_view_info;
458 case WCCP2_WC_VIEW_INFO:
459 ett = ett_wc_view_info;
460 dissector = dissect_wccp2_wc_view_info;
463 case WCCP2_REDIRECT_ASSIGNMENT:
464 ett = ett_router_assignment_info;
465 dissector = dissect_wccp2_assignment_info;
468 case WCCP2_QUERY_INFO:
469 ett = ett_query_info;
470 dissector = dissect_wccp2_router_query_info;
473 case WCCP2_CAPABILITIES_INFO:
474 ett = ett_capabilities_info;
475 dissector = dissect_wccp2_capability_info;
479 ett = ett_unknown_info;
484 ti = proto_tree_add_text(wccp_tree, tvb, offset, item_length + 4,
485 val_to_str(type, info_type_vals, "Unknown info type (%u)"));
486 info_tree = proto_item_add_subtree(ti, ett);
487 proto_tree_add_text(info_tree, tvb, offset, 2,
489 val_to_str(type, info_type_vals, "Unknown info type (%u)"));
490 proto_tree_add_text(info_tree, tvb, offset+2, 2,
491 "Length: %u", item_length);
496 * XXX - pass in "length" and check for that as well.
498 if (dissector != NULL) {
499 if (!(*dissector)(tvb, offset, item_length, info_tree))
500 return; /* ran out of data */
502 proto_tree_add_text(info_tree, tvb, offset, item_length,
503 "Data: %u byte%s", item_length,
504 plurality(item_length, "", "s"));
506 offset += item_length;
507 length -= item_length;
511 #define SECURITY_INFO_LEN 4
513 #define WCCP2_NO_SECURITY 0
514 #define WCCP2_MD5_SECURITY 1
517 dissect_wccp2_security_info(tvbuff_t *tvb, int offset, int length,
518 proto_tree *info_tree)
520 guint32 security_option;
522 if (length < SECURITY_INFO_LEN) {
523 proto_tree_add_text(info_tree, tvb, offset, 0,
524 "Item length is %u, should be %u", length,
529 security_option = tvb_get_ntohl(tvb, offset);
530 switch (security_option) {
532 case WCCP2_NO_SECURITY:
533 proto_tree_add_text(info_tree, tvb, offset, 4,
534 "Security Option: None");
537 case WCCP2_MD5_SECURITY:
538 proto_tree_add_text(info_tree, tvb, offset, 4,
539 "Security Option: MD5");
542 proto_tree_add_text(info_tree, tvb, offset,
543 length - 4, "MD5 checksum: %s",
544 tvb_bytes_to_str(tvb, offset, length - 4));
549 proto_tree_add_text(info_tree, tvb, offset, 4,
550 "Security Option: Unknown (%u)", security_option);
556 #define SERVICE_INFO_LEN (4+4+8*2)
558 #define WCCP2_SERVICE_STANDARD 0
559 #define WCCP2_SERVICE_DYNAMIC 1
564 #define WCCP2_SI_SRC_IP_HASH 0x0001
565 #define WCCP2_SI_DST_IP_HASH 0x0002
566 #define WCCP2_SI_SRC_PORT_HASH 0x0004
567 #define WCCP2_SI_DST_PORT_HASH 0x0008
568 #define WCCP2_SI_PORTS_DEFINED 0x0010
569 #define WCCP2_SI_PORTS_SOURCE 0x0020
570 #define WCCP2_SI_SRC_IP_ALT_HASH 0x0100
571 #define WCCP2_SI_DST_IP_ALT_HASH 0x0200
572 #define WCCP2_SI_SRC_PORT_ALT_HASH 0x0400
573 #define WCCP2_SI_DST_PORT_ALT_HASH 0x0800
576 dissect_wccp2_service_info(tvbuff_t *tvb, int offset, int length,
577 proto_tree *info_tree)
582 proto_tree *field_tree;
585 if (length != SERVICE_INFO_LEN) {
586 proto_tree_add_text(info_tree, tvb, offset, 0,
587 "Item length is %u, should be %u", length,
592 service_type = tvb_get_guint8(tvb, offset);
593 switch (service_type) {
595 case WCCP2_SERVICE_STANDARD:
596 proto_tree_add_text(info_tree, tvb, offset, 1,
597 "Service Type: Well-known service");
598 proto_tree_add_text(info_tree, tvb, offset+1, 1,
600 val_to_str(tvb_get_guint8(tvb, offset+1), service_id_vals,
601 "Unknown (0x%02X)"));
605 case WCCP2_SERVICE_DYNAMIC:
606 proto_tree_add_text(info_tree, tvb, offset, 1,
607 "Service Type: Dynamic service");
608 proto_tree_add_text(info_tree, tvb, offset+1, 1,
610 val_to_str(tvb_get_guint8(tvb, offset+1), service_id_vals,
611 "Unknown (0x%02X)"));
612 proto_tree_add_text(info_tree, tvb, offset+2, 1,
613 "Priority: %u", tvb_get_guint8(tvb, offset+2));
615 * XXX - does "IP protocol identifier" mean this is a
616 * protocol type of the sort you get in IP headers?
617 * If so, we should get a table of those from the
618 * IP dissector, and use that.
620 proto_tree_add_text(info_tree, tvb, offset+3, 1,
621 "Protocol: %u", tvb_get_guint8(tvb, offset+3)); /* IP protocol identifier */
625 proto_tree_add_text(info_tree, tvb, offset, 1,
626 "Service Type: Unknown (%u)", service_type);
631 flags = tvb_get_ntohl(tvb, offset);
632 tf = proto_tree_add_text(info_tree, tvb, offset, 4,
633 "Flags: 0x%08X", flags);
634 field_tree = proto_item_add_subtree(tf, ett_service_flags);
635 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
636 decode_boolean_bitfield(flags, WCCP2_SI_SRC_IP_HASH,
638 "Use source IP address in primary hash",
639 "Don't use source IP address in primary hash"));
640 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
641 decode_boolean_bitfield(flags, WCCP2_SI_DST_IP_HASH,
643 "Use destination IP address in primary hash",
644 "Don't use destination IP address in primary hash"));
645 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
646 decode_boolean_bitfield(flags, WCCP2_SI_SRC_PORT_HASH,
648 "Use source port in primary hash",
649 "Don't use source port in primary hash"));
650 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
651 decode_boolean_bitfield(flags, WCCP2_SI_DST_PORT_HASH,
653 "Use destination port in primary hash",
654 "Don't use destination port in primary hash"));
655 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
656 decode_boolean_bitfield(flags, WCCP2_SI_PORTS_DEFINED,
659 "Ports not defined"));
660 if (flags & WCCP2_SI_PORTS_DEFINED) {
661 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
662 decode_boolean_bitfield(flags, WCCP2_SI_PORTS_SOURCE,
664 "Ports refer to source port",
665 "Ports refer to destination port"));
667 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
668 decode_boolean_bitfield(flags, WCCP2_SI_SRC_IP_ALT_HASH,
670 "Use source IP address in secondary hash",
671 "Don't use source IP address in secondary hash"));
672 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
673 decode_boolean_bitfield(flags, WCCP2_SI_DST_IP_ALT_HASH,
675 "Use destination IP address in secondary hash",
676 "Don't use destination IP address in secondary hash"));
677 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
678 decode_boolean_bitfield(flags, WCCP2_SI_SRC_PORT_ALT_HASH,
680 "Use source port in secondary hash",
681 "Don't use source port in secondary hash"));
682 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
683 decode_boolean_bitfield(flags, WCCP2_SI_DST_PORT_ALT_HASH,
685 "Use destination port in secondary hash",
686 "Don't use destination port in secondary hash"));
689 if (flags & WCCP2_SI_PORTS_DEFINED) {
690 for (i = 0; i < 8; i++) {
691 proto_tree_add_text(info_tree, tvb, offset, 2,
692 "Port %d: %u", i, tvb_get_ntohs(tvb, offset));
700 #define ROUTER_ID_INFO_MIN_LEN (8+4+4)
703 dissect_wccp2_router_identity_element(tvbuff_t *tvb, int offset,
706 proto_tree_add_text(tree, tvb, offset, 4,
707 "IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
708 proto_tree_add_text(tree, tvb, offset + 4, 4,
709 "Receive ID: %u", tvb_get_ntohl(tvb, offset + 4));
713 dissect_wccp2_router_identity_info(tvbuff_t *tvb, int offset, int length,
714 proto_tree *info_tree)
716 guint32 n_received_from;
719 proto_tree *element_tree;
721 if (length < ROUTER_ID_INFO_MIN_LEN) {
722 proto_tree_add_text(info_tree, tvb, offset, 0,
723 "Item length is %u, should be >= %u", length,
724 ROUTER_ID_INFO_MIN_LEN);
728 te = proto_tree_add_text(info_tree, tvb, offset, 8,
729 "Router Identity Element: IP address %s",
730 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
731 element_tree = proto_item_add_subtree(te,
732 ett_router_identity_element);
733 dissect_wccp2_router_identity_element(tvb, offset, element_tree);
736 proto_tree_add_text(info_tree, tvb, offset, 4,
737 "Sent To IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
740 n_received_from = tvb_get_ntohl(tvb, offset);
741 proto_tree_add_text(info_tree, tvb, offset, 4,
742 "Number of Received From IP addresses: %u", n_received_from);
745 for (i = 0; i < n_received_from; i++) {
746 proto_tree_add_text(info_tree, tvb, offset, 4,
747 "Received From IP Address %d: %s", i,
748 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
755 #define WC_ID_INFO_LEN (4+4+8*4+4)
758 dissect_wccp2_web_cache_identity_element(tvbuff_t *tvb, int offset,
761 proto_item *bucket_item;
762 proto_tree *bucket_tree;
764 proto_tree *field_tree;
770 proto_tree_add_text(tree, tvb, offset, 4,
771 "Web-Cache IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
774 proto_tree_add_text(tree, tvb, offset, 2,
775 "Hash Revision %u", tvb_get_ntohs(tvb, offset));
778 flags = tvb_get_ntohs(tvb, offset);
779 tf = proto_tree_add_text(tree, tvb, offset, 2,
780 "Flags: 0x%04X (%s)", flags,
782 "Hash information is historical" :
783 "Hash information is current"));
784 field_tree = proto_item_add_subtree(tf, ett_flags);
785 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
786 decode_boolean_bitfield(flags, 0x8000,
788 "Hash information is historical",
789 "Hash information is current"));
792 bucket_item = proto_tree_add_text(tree, tvb, offset, 8*4,
794 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
795 for (i = 0, n = 0; i < 32; i++) {
796 bucket_info = tvb_get_guint8(tvb, offset);
797 n = wccp_bucket_info(bucket_info, bucket_tree, n, tvb, offset);
801 proto_tree_add_text(tree, tvb, offset, 2,
802 "Assignment Weight: %u", tvb_get_ntohs(tvb, offset));
805 proto_tree_add_text(tree, tvb, offset, 2,
806 "Status: 0x%04X", tvb_get_ntohs(tvb, offset));
813 dissect_wccp2_wc_identity_info(tvbuff_t *tvb, int offset, int length,
814 proto_tree *info_tree)
817 proto_tree *element_tree;
819 if (length != WC_ID_INFO_LEN) {
820 proto_tree_add_text(info_tree, tvb, offset, 0,
821 "Item length is %u, should be %u", length, WC_ID_INFO_LEN);
825 te = proto_tree_add_text(info_tree, tvb, offset, 4+2+2+32+2+2,
826 "Web-Cache Identity Element: IP address %s",
827 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
828 element_tree = proto_item_add_subtree(te, ett_wc_identity_element);
829 if (!dissect_wccp2_web_cache_identity_element(tvb, offset,
831 return FALSE; /* ran out of data */
836 #define ROUTER_VIEW_INFO_MIN_LEN (4+8+4)
839 dissect_wccp2_assignment_key(tvbuff_t *tvb, int offset,
840 proto_tree *info_tree)
842 proto_tree_add_text(info_tree, tvb, offset, 4,
843 "Assignment Key IP Address: %s",
844 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
845 proto_tree_add_text(info_tree, tvb, offset + 4, 4,
846 "Assignment Key Change Number: %u", tvb_get_ntohl(tvb, offset + 4));
850 dissect_wccp2_router_view_info(tvbuff_t *tvb, int offset, int length,
851 proto_tree *info_tree)
854 guint32 n_web_caches;
857 proto_tree *element_tree;
859 if (length < ROUTER_VIEW_INFO_MIN_LEN) {
860 proto_tree_add_text(info_tree, tvb, offset, 0,
861 "Item length is %u, should be >= %u", length,
862 ROUTER_VIEW_INFO_MIN_LEN);
866 proto_tree_add_text(info_tree, tvb, offset, 4,
867 "Member Change Number: %u", tvb_get_ntohl(tvb, offset));
870 dissect_wccp2_assignment_key(tvb, offset, info_tree);
873 n_routers = tvb_get_ntohl(tvb, offset);
874 proto_tree_add_text(info_tree, tvb, offset, 4,
875 "Number of Routers: %u", n_routers);
878 for (i = 0; i < n_routers; i++) {
879 proto_tree_add_text(info_tree, tvb, offset, 4,
880 "Router %d IP Address: %s", i,
881 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
885 n_web_caches = tvb_get_ntohl(tvb, offset);
886 proto_tree_add_text(info_tree, tvb, offset, 4,
887 "Number of Web Caches: %u", n_web_caches);
890 for (i = 0; i < n_web_caches; i++) {
891 te = proto_tree_add_text(info_tree, tvb, offset, WC_ID_INFO_LEN,
892 "Web-Cache Identity Element %d: IP address %s", i,
893 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
894 element_tree = proto_item_add_subtree(te,
895 ett_wc_identity_element);
896 if (!dissect_wccp2_web_cache_identity_element(tvb,
897 offset, element_tree))
898 return FALSE; /* ran out of data */
899 offset += WC_ID_INFO_LEN;
905 #define WC_VIEW_INFO_MIN_LEN (4+4)
908 dissect_wccp2_wc_view_info(tvbuff_t *tvb, int offset, int length,
909 proto_tree *info_tree)
912 guint32 n_web_caches;
915 proto_tree *element_tree;
917 if (length < WC_VIEW_INFO_MIN_LEN) {
918 proto_tree_add_text(info_tree, tvb, offset, 0,
919 "Item length is %u, should be >= %u", length,
920 WC_VIEW_INFO_MIN_LEN);
924 proto_tree_add_text(info_tree, tvb, offset, 4,
925 "Change Number: %u", tvb_get_ntohl(tvb, offset));
928 n_routers = tvb_get_ntohl(tvb, offset);
929 proto_tree_add_text(info_tree, tvb, offset, 4,
930 "Number of Routers: %u", n_routers);
933 for (i = 0; i < n_routers; i++) {
934 te = proto_tree_add_text(info_tree, tvb, offset, 8,
935 "Router %d Identity Element: IP address %s", i,
936 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
937 element_tree = proto_item_add_subtree(te,
938 ett_router_identity_element);
939 dissect_wccp2_router_identity_element(tvb, offset, element_tree);
943 n_web_caches = tvb_get_ntohl(tvb, offset);
944 proto_tree_add_text(info_tree, tvb, offset, 4,
945 "Number of Web Caches: %u", n_web_caches);
948 for (i = 0; i < n_web_caches; i++) {
949 proto_tree_add_text(info_tree, tvb, offset, 4,
950 "Web-Cache %d: IP address %s", i,
951 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
958 #define ASSIGNMENT_INFO_MIN_LEN (8+4)
961 dissect_wccp2_router_assignment_element(tvbuff_t *tvb, int offset,
964 proto_tree_add_text(tree, tvb, offset, 4,
965 "IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
966 proto_tree_add_text(tree, tvb, offset + 4, 4,
967 "Receive ID: %u", tvb_get_ntohl(tvb, offset + 4));
968 proto_tree_add_text(tree, tvb, offset + 8, 4,
969 "Change Number: %u", tvb_get_ntohl(tvb, offset + 8));
973 assignment_bucket_name(guint8 bucket)
975 static gchar str[4][10+1];
978 if (cur == &str[0][0])
980 else if (cur == &str[1][0])
982 else if (cur == &str[2][0])
987 strcpy(cur, "Unassigned");
989 sprintf(cur, "%u%s", bucket >> 1,
990 (bucket & 0x01) ? " (Alt)" : "");
996 dissect_wccp2_assignment_info(tvbuff_t *tvb, int offset, int length,
997 proto_tree *info_tree)
1000 guint32 n_web_caches;
1003 proto_tree *element_tree;
1005 if (length < ASSIGNMENT_INFO_MIN_LEN) {
1006 proto_tree_add_text(info_tree, tvb, offset, 0,
1007 "Item length is %u, should be >= %u", length,
1008 ASSIGNMENT_INFO_MIN_LEN);
1012 dissect_wccp2_assignment_key(tvb, offset, info_tree);
1015 n_routers = tvb_get_ntohl(tvb, offset);
1016 proto_tree_add_text(info_tree, tvb, offset, 4,
1017 "Number of Routers: %u", n_routers);
1020 for (i = 0; i < n_routers; i++) {
1021 te = proto_tree_add_text(info_tree, tvb, offset, 4,
1022 "Router %d Assignment Element: IP address %s", i,
1023 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1024 element_tree = proto_item_add_subtree(te,
1025 ett_router_assignment_element);
1026 dissect_wccp2_router_assignment_element(tvb, offset,
1031 n_web_caches = tvb_get_ntohl(tvb, offset);
1032 proto_tree_add_text(info_tree, tvb, offset, 4,
1033 "Number of Web Caches: %u", n_web_caches);
1036 for (i = 0; i < n_web_caches; i++) {
1037 proto_tree_add_text(info_tree, tvb, offset, 4,
1038 "Web-Cache %d: IP address %s", i,
1039 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1043 for (i = 0; i < 256; i += 4) {
1044 proto_tree_add_text(info_tree, tvb, offset, 4,
1045 "Buckets %d - %d: %10s %10s %10s %10s",
1047 assignment_bucket_name(tvb_get_guint8(tvb, offset)),
1048 assignment_bucket_name(tvb_get_guint8(tvb, offset+1)),
1049 assignment_bucket_name(tvb_get_guint8(tvb, offset+2)),
1050 assignment_bucket_name(tvb_get_guint8(tvb, offset+3)));
1057 #define QUERY_INFO_LEN (4+4+4+4)
1060 dissect_wccp2_router_query_info(tvbuff_t *tvb, int offset, int length,
1061 proto_tree *info_tree)
1063 if (length != QUERY_INFO_LEN) {
1064 proto_tree_add_text(info_tree, tvb, offset, 0,
1065 "Item length is %u, should be %u", length, QUERY_INFO_LEN);
1069 proto_tree_add_text(info_tree, tvb, offset, 4,
1070 "Router IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1073 proto_tree_add_text(info_tree, tvb, offset, 4,
1074 "Receive ID: %u", tvb_get_ntohl(tvb, offset));
1077 proto_tree_add_text(info_tree, tvb, offset, 4,
1078 "Sent To IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1081 proto_tree_add_text(info_tree, tvb, offset, 4,
1082 "Target IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1088 #define WCCP2_FORWARDING_METHOD 0x01
1089 #define WCCP2_ASSIGNMENT_METHOD 0x02
1090 #define WCCP2_PACKET_RETURN_METHOD 0x03
1092 static const value_string capability_type_vals[] = {
1093 { WCCP2_FORWARDING_METHOD, "Forwarding Method" },
1094 { WCCP2_ASSIGNMENT_METHOD, "Assignment Method" },
1095 { WCCP2_PACKET_RETURN_METHOD, "Return Method" },
1099 #define WCCP2_FORWARDING_METHOD_GRE 0x00000001
1100 #define WCCP2_FORWARDING_METHOD_L2 0x00000002
1102 static const capability_flag forwarding_method_flags[] = {
1103 { WCCP2_FORWARDING_METHOD_GRE,
1104 "IP-GRE", "GRE-encapsulated" },
1105 { WCCP2_FORWARDING_METHOD_L2,
1106 "L2", "L2 rewrite" },
1111 #define WCCP2_ASSIGNMENT_METHOD_HASH 0x00000001
1112 #define WCCP2_ASSIGNMENT_METHOD_MASK 0x00000002
1114 static const capability_flag assignment_method_flags[] = {
1115 { WCCP2_ASSIGNMENT_METHOD_HASH, "Hash", "Hash" },
1116 { WCCP2_ASSIGNMENT_METHOD_MASK, "Mask", "Mask" },
1120 #define WCCP2_PACKET_RETURN_METHOD_GRE 0x00000001
1121 #define WCCP2_PACKET_RETURN_METHOD_L2 0x00000002
1123 static const capability_flag packet_return_method_flags[] = {
1124 { WCCP2_PACKET_RETURN_METHOD_GRE,
1125 "IP-GRE", "GRE-encapsulated" },
1126 { WCCP2_PACKET_RETURN_METHOD_L2,
1127 "L2", "L2 rewrite" },
1133 dissect_wccp2_capability_info(tvbuff_t *tvb, int offset, int length,
1134 proto_tree *info_tree)
1136 guint16 capability_type;
1137 guint16 capability_val_len;
1140 proto_tree *element_tree;
1142 for (curr_offset = offset; curr_offset < (length + offset);
1143 curr_offset += (capability_val_len + 4)) {
1144 capability_type = tvb_get_ntohs(tvb, curr_offset);
1145 capability_val_len = tvb_get_ntohs(tvb, curr_offset + 2);
1146 te = proto_tree_add_text(info_tree, tvb, curr_offset,
1147 capability_val_len + 4, "%s",
1148 val_to_str(capability_type,
1149 capability_type_vals, "Unknown Capability Element (0x%08X)"));
1150 element_tree = proto_item_add_subtree(te,
1151 ett_capability_element);
1153 proto_tree_add_text(element_tree, tvb, curr_offset, 2,
1155 val_to_str(capability_type,
1156 capability_type_vals, "Unknown (0x%08X)"));
1158 if (capability_val_len < 4) {
1159 proto_tree_add_text(element_tree, tvb, curr_offset+2, 2,
1160 "Value Length: %u (illegal, must be >= 4)",
1161 capability_val_len);
1164 proto_tree_add_text(element_tree, tvb, curr_offset+2, 2,
1165 "Value Length: %u", capability_val_len);
1167 switch (capability_type) {
1169 case WCCP2_FORWARDING_METHOD:
1170 dissect_32_bit_capability_flags(tvb, curr_offset,
1172 ett_capability_forwarding_method,
1173 forwarding_method_flags, element_tree);
1176 case WCCP2_ASSIGNMENT_METHOD:
1177 dissect_32_bit_capability_flags(tvb, curr_offset,
1179 ett_capability_assignment_method,
1180 assignment_method_flags, element_tree);
1183 case WCCP2_PACKET_RETURN_METHOD:
1184 dissect_32_bit_capability_flags(tvb, curr_offset,
1186 ett_capability_return_method,
1187 packet_return_method_flags, element_tree);
1191 proto_tree_add_text(element_tree, tvb,
1192 curr_offset+4, capability_val_len,
1194 tvb_bytes_to_str(tvb, curr_offset+4,
1195 capability_val_len));
1204 dissect_32_bit_capability_flags(tvbuff_t *tvb, int curr_offset,
1205 guint16 capability_val_len, gint ett, const capability_flag *flags,
1206 proto_tree *element_tree)
1208 guint32 capability_val;
1210 proto_tree *method_tree;
1212 char flags_string[128+1];
1217 if (capability_val_len != 4) {
1218 proto_tree_add_text(element_tree, tvb,
1219 curr_offset+4, capability_val_len,
1220 "Illegal length (must be 4)");
1224 capability_val = tvb_get_ntohl(tvb, curr_offset + 4);
1225 flags_string[0] = '\0';
1226 p = &flags_string[0];
1227 space_left = sizeof flags_string;
1228 for (i = 0; flags[i].short_name != NULL; i++) {
1229 if (capability_val & flags[i].value) {
1230 if (p != &flags_string[0]) {
1231 snprintf(p, space_left, ",");
1232 p = &flags_string[strlen(flags_string)];
1234 snprintf(p, space_left, "%s", flags[i].short_name);
1235 p = &flags_string[strlen(flags_string)];
1238 tm = proto_tree_add_text(element_tree, tvb, curr_offset+4, 4,
1239 "Value: 0x%08X (%s)", capability_val, flags_string);
1240 method_tree = proto_item_add_subtree(tm, ett);
1241 for (i = 0; flags[i].long_name != NULL; i++) {
1242 p = decode_bitfield_value(buf, capability_val,
1243 flags[i].value, 32);
1244 strcpy(p, flags[i].long_name);
1246 if (capability_val & flags[i].value)
1247 strcat(p, "Supported");
1249 strcat(p, "Not supported");
1250 proto_tree_add_text(method_tree, tvb, curr_offset+4, 4,
1256 proto_register_wccp(void)
1258 static hf_register_info hf[] = {
1259 { &hf_wccp_message_type,
1260 { "WCCP Message Type", "wccp.message", FT_UINT32, BASE_DEC, VALS(wccp_type_vals), 0x0,
1261 "The WCCP message that was sent", HFILL }
1264 { "WCCP Version", "wccp.version", FT_UINT32, BASE_HEX, VALS(wccp_version_val), 0x0,
1265 "The WCCP version", HFILL }
1267 { &hf_hash_revision,
1268 { "Hash Revision", "wccp.hash_revision", FT_UINT32, BASE_DEC, 0x0, 0x0,
1269 "The cache hash revision", HFILL }
1272 { "Change Number", "wccp.change_num", FT_UINT32, BASE_DEC, 0x0, 0x0,
1273 "The Web-Cache list entry change number", HFILL }
1276 { "Received ID", "wccp.recvd_id", FT_UINT32, BASE_DEC, 0x0, 0x0,
1277 "The number of I_SEE_YOU's that have been sent", HFILL }
1280 { "Web Cache IP address", "wccp.cache_ip", FT_IPv4, BASE_NONE, NULL, 0x0,
1281 "The IP address of a Web cache", HFILL }
1284 static gint *ett[] = {
1293 &ett_router_identity_element,
1294 &ett_router_identity_info,
1295 &ett_wc_identity_element,
1296 &ett_wc_identity_info,
1297 &ett_router_view_info,
1300 &ett_router_assignment_element,
1301 &ett_router_assignment_info,
1302 &ett_capabilities_info,
1303 &ett_capability_element,
1304 &ett_capability_forwarding_method,
1305 &ett_capability_assignment_method,
1306 &ett_capability_return_method,
1310 proto_wccp = proto_register_protocol("Web Cache Coordination Protocol",
1312 proto_register_field_array(proto_wccp, hf, array_length(hf));
1313 proto_register_subtree_array(ett, array_length(ett));
1317 proto_reg_handoff_wccp(void)
1319 dissector_handle_t wccp_handle;
1321 wccp_handle = create_dissector_handle(dissect_wccp, proto_wccp);
1322 dissector_add("udp.port", UDP_PORT_WCCP, wccp_handle);