2 * Routines for Web Cache Coordination Protocol dissection
3 * Jerry Talkington <jerryt@netapp.com>
5 * $Id: packet-wccp.c,v 1.22 2001/08/04 01:52:07 guy 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.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
42 #include "packet-wccp.h"
44 static int proto_wccp = -1;
45 static int hf_wccp_message_type = -1; /* the message type */
46 static int hf_wccp_version = -1; /* protocol version */
47 static int hf_hash_revision = -1; /* the version of the hash */
48 static int hf_change_num = -1; /* change number */
49 static int hf_recvd_id = -1;
50 static int hf_cache_ip = -1;
52 static gint ett_wccp = -1;
53 static gint ett_cache_count = -1;
54 static gint ett_buckets = -1;
55 static gint ett_flags = -1;
56 static gint ett_cache_info = -1;
57 static gint ett_security_info = -1;
58 static gint ett_service_info = -1;
59 static gint ett_service_flags = -1;
60 static gint ett_router_identity_element = -1;
61 static gint ett_router_identity_info = -1;
62 static gint ett_wc_identity_element = -1;
63 static gint ett_wc_identity_info = -1;
64 static gint ett_router_view_info = -1;
65 static gint ett_wc_view_info = -1;
66 static gint ett_router_assignment_element = -1;
67 static gint ett_router_assignment_info = -1;
68 static gint ett_query_info = -1;
69 static gint ett_capabilities_info = -1;
70 static gint ett_capability_element = -1;
71 static gint ett_capability_forwarding_method = -1;
72 static gint ett_capability_assignment_method = -1;
73 static gint ett_capability_return_method = -1;
74 static gint ett_unknown_info = -1;
79 * http://www.alternic.org/drafts/drafts-f-g/draft-forster-wrec-wccp-v1-00.html
81 * is a copy of the now-expired Internet-Draft for WCCP 1.0.
85 * http://search.ietf.org/internet-drafts/draft-wilson-wrec-wccp-v2-01.txt
87 * is an Internet-Draft for WCCP 2.0.
90 #define UDP_PORT_WCCP 2048
94 #define WCCP_HERE_I_AM 7
95 #define WCCP_I_SEE_YOU 8
96 #define WCCP_ASSIGN_BUCKET 9
97 #define WCCP2_HERE_I_AM 10
98 #define WCCP2_I_SEE_YOU 11
99 #define WCCP2_REDIRECT_ASSIGN 12
100 #define WCCP2_REMOVAL_QUERY 13
102 static const value_string wccp_type_vals[] = {
103 { WCCP_HERE_I_AM, "1.0 Here I am" },
104 { WCCP_I_SEE_YOU, "1.0 I see you" },
105 { WCCP_ASSIGN_BUCKET, "1.0 Assign bucket" },
106 { WCCP2_HERE_I_AM, "2.0 Here I am" },
107 { WCCP2_I_SEE_YOU, "2.0 I see you" },
108 { WCCP2_REDIRECT_ASSIGN, "2.0 Redirect assign" },
109 { WCCP2_REMOVAL_QUERY, "2.0 Removal query" },
113 static const value_string wccp_version_val[] = {
119 #define HASH_INFO_SIZE (4*(1+8+1))
121 #define WCCP_U_FLAG 0x80000000
123 #define WCCP2_SECURITY_INFO 0
124 #define WCCP2_SERVICE_INFO 1
125 #define WCCP2_ROUTER_ID_INFO 2
126 #define WCCP2_WC_ID_INFO 3
127 #define WCCP2_RTR_VIEW_INFO 4
128 #define WCCP2_WC_VIEW_INFO 5
129 #define WCCP2_REDIRECT_ASSIGNMENT 6
130 #define WCCP2_QUERY_INFO 7
131 #define WCCP2_CAPABILITIES_INFO 8
132 #define WCCP2_ALT_ASSIGNMENT 13
133 #define WCCP2_ASSIGN_MAP 14
134 #define WCCP2_COMMAND_EXTENSION 15
136 static const value_string info_type_vals[] = {
137 { WCCP2_SECURITY_INFO, "Security Info" },
138 { WCCP2_SERVICE_INFO, "Service Info" },
139 { WCCP2_ROUTER_ID_INFO, "Router Identity Info" },
140 { WCCP2_WC_ID_INFO, "Web-Cache Identity Info" },
141 { WCCP2_RTR_VIEW_INFO, "Router View Info" },
142 { WCCP2_WC_VIEW_INFO, "Web-Cache View Info" },
143 { WCCP2_REDIRECT_ASSIGNMENT, "Assignment Info" },
144 { WCCP2_QUERY_INFO, "Query Info" },
145 { WCCP2_CAPABILITIES_INFO, "Capabilities Info" },
146 { WCCP2_COMMAND_EXTENSION, "Command Extension" },
150 const value_string service_id_vals[] = {
155 typedef struct capability_flag {
157 const char *short_name;
158 const char *long_name;
161 static void dissect_hash_data(tvbuff_t *tvb, int offset,
162 proto_tree *wccp_tree);
163 static void dissect_web_cache_list_entry(tvbuff_t *tvb, int offset,
164 int index, proto_tree *wccp_tree);
165 static int wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree,
166 guint32 start, tvbuff_t *tvb, int offset);
167 static gchar *bucket_name(guint8 bucket);
168 static guint16 dissect_wccp2_header(tvbuff_t *tvb, int offset,
169 proto_tree *wccp_tree);
170 static void dissect_wccp2_info(tvbuff_t *tvb, int offset, guint16 length,
171 proto_tree *wccp_tree);
172 static gboolean dissect_wccp2_security_info(tvbuff_t *tvb, int offset,
173 int length, proto_tree *info_tree);
174 static gboolean dissect_wccp2_service_info(tvbuff_t *tvb, int offset,
175 int length, proto_tree *info_tree);
176 static gboolean dissect_wccp2_router_identity_info(tvbuff_t *tvb,
177 int offset, int length, proto_tree *info_tree);
178 static gboolean dissect_wccp2_wc_identity_info(tvbuff_t *tvb, int offset,
179 int length, proto_tree *info_tree);
180 static gboolean dissect_wccp2_router_view_info(tvbuff_t *tvb, int offset,
181 int length, proto_tree *info_tree);
182 static gboolean dissect_wccp2_wc_view_info(tvbuff_t *tvb, int offset,
183 int length, proto_tree *info_tree);
184 static gboolean dissect_wccp2_assignment_info(tvbuff_t *tvb, int offset,
185 int length, proto_tree *info_tree);
186 static gboolean dissect_wccp2_router_query_info(tvbuff_t *tvb, int offset,
187 int length, proto_tree *info_tree);
188 static gboolean dissect_wccp2_capability_info(tvbuff_t *tvb, int offset,
189 int length, proto_tree *info_tree);
190 static void dissect_32_bit_capability_flags(tvbuff_t *tvb, int curr_offset,
191 guint16 capability_len, gint ett, const capability_flag *flags,
192 proto_tree *element_tree);
195 dissect_wccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
198 proto_tree *wccp_tree = NULL;
199 proto_item *wccp_tree_item;
200 guint32 wccp_message_type;
205 if(check_col(pinfo->fd, COL_PROTOCOL)) {
206 col_set_str(pinfo->fd, COL_PROTOCOL, "WCCP");
208 if(check_col(pinfo->fd, COL_INFO)) {
209 col_clear(pinfo->fd, COL_INFO);
212 wccp_message_type = tvb_get_ntohl(tvb, offset);
214 if(check_col(pinfo->fd, COL_INFO)) {
215 col_add_str(pinfo->fd, COL_INFO, val_to_str(wccp_message_type,
216 wccp_type_vals, "Unknown WCCP message (%u)"));
220 wccp_tree_item = proto_tree_add_item(tree, proto_wccp, tvb, offset,
221 tvb_length(tvb), FALSE);
222 wccp_tree = proto_item_add_subtree(wccp_tree_item, ett_wccp);
224 proto_tree_add_uint(wccp_tree, hf_wccp_message_type, tvb, offset,
225 sizeof(wccp_message_type), wccp_message_type);
226 offset += sizeof(wccp_message_type);
228 switch (wccp_message_type) {
231 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb,
234 dissect_hash_data(tvb, offset, wccp_tree);
235 offset += HASH_INFO_SIZE;
236 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
242 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb,
245 proto_tree_add_item(wccp_tree, hf_change_num, tvb, offset,
248 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
251 cache_count = tvb_get_ntohl(tvb, offset);
252 proto_tree_add_text(wccp_tree, tvb, offset, 4,
253 "Number of Web Caches: %u", cache_count);
255 for (i = 0; i < cache_count; i++) {
256 dissect_web_cache_list_entry(tvb, offset, i,
258 offset += 4 + HASH_INFO_SIZE;
262 case WCCP_ASSIGN_BUCKET:
264 * This hasn't been tested, since I don't have any
265 * traces with this in it.
267 * The V1 spec claims that this does, indeed,
268 * have a Received ID field after the type,
269 * rather than a Version field.
271 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
274 cache_count = tvb_get_ntohl(tvb, offset);
275 proto_tree_add_text(wccp_tree, tvb, offset, 4,
276 "Number of Web Caches: %u", cache_count);
278 for (i = 0; i < cache_count; i++) {
279 proto_tree_add_ipv4_format(wccp_tree,
280 hf_cache_ip, tvb, offset, 4,
281 tvb_get_ntohl(tvb, offset),
282 "Web Cache %d IP Address: %s", i,
283 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
286 for (i = 0; i < 256; i += 4) {
287 proto_tree_add_text(wccp_tree, tvb, offset, 4,
288 "Buckets %d - %d: %10s %10s %10s %10s",
290 bucket_name(tvb_get_guint8(tvb, offset)),
291 bucket_name(tvb_get_guint8(tvb, offset+1)),
292 bucket_name(tvb_get_guint8(tvb, offset+2)),
293 bucket_name(tvb_get_guint8(tvb, offset+3)));
298 case WCCP2_HERE_I_AM:
299 case WCCP2_I_SEE_YOU:
300 case WCCP2_REMOVAL_QUERY:
301 case WCCP2_REDIRECT_ASSIGN:
302 default: /* assume unknown packets are v2 */
303 length = dissect_wccp2_header(tvb, offset, wccp_tree);
305 dissect_wccp2_info(tvb, offset, length, wccp_tree);
312 dissect_hash_data(tvbuff_t *tvb, int offset, proto_tree *wccp_tree)
314 proto_item *bucket_item;
315 proto_tree *bucket_tree;
317 proto_tree *field_tree;
323 proto_tree_add_item(wccp_tree, hf_hash_revision, tvb, offset, 4,
327 bucket_item = proto_tree_add_text(wccp_tree, tvb, offset, 32,
329 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
331 for (i = 0, n = 0; i < 32; i++) {
332 bucket_info = tvb_get_guint8(tvb, offset);
333 n = wccp_bucket_info(bucket_info, bucket_tree, n, tvb, offset);
336 flags = tvb_get_ntohl(tvb, offset);
337 tf = proto_tree_add_text(wccp_tree, tvb, offset, 4,
338 "Flags: 0x%08X (%s)", flags,
339 ((flags & WCCP_U_FLAG) ?
340 "Hash information is historical" :
341 "Hash information is current"));
342 field_tree = proto_item_add_subtree(tf, ett_flags);
343 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
344 decode_boolean_bitfield(flags, WCCP_U_FLAG,
346 "Hash information is historical",
347 "Hash information is current"));
351 dissect_web_cache_list_entry(tvbuff_t *tvb, int offset, int index,
352 proto_tree *wccp_tree)
355 proto_tree *list_entry_tree;
357 tl = proto_tree_add_text(wccp_tree, tvb, offset, 4 + HASH_INFO_SIZE,
358 "Web-Cache List Entry(%d)", index);
359 list_entry_tree = proto_item_add_subtree(tl, ett_cache_info);
360 proto_tree_add_item(list_entry_tree, hf_cache_ip, tvb, offset, 4,
362 dissect_hash_data(tvb, offset + 4, list_entry_tree);
367 * takes an integer representing a "Hash Information" bitmap, and spits out
368 * the corresponding proto_tree entries, returning the next bucket number.
371 wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree, guint32 start,
372 tvbuff_t *tvb, int offset)
376 for(i = 0; i < 8; i++) {
377 proto_tree_add_text(bucket_tree, tvb, offset, sizeof(bucket_info), "Bucket %3d: %s", start, (bucket_info & 1<<i ? "Assigned" : "Not Assigned") );
384 bucket_name(guint8 bucket)
386 static gchar str[4][10+1];
389 if (cur == &str[0][0])
391 else if (cur == &str[1][0])
393 else if (cur == &str[2][0])
398 strcpy(cur, "Unassigned");
400 sprintf(cur, "%u", bucket);
405 dissect_wccp2_header(tvbuff_t *tvb, int offset, proto_tree *wccp_tree)
409 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb, offset, 2,
412 length = tvb_get_ntohs(tvb, offset);
413 proto_tree_add_text(wccp_tree, tvb, offset, 2, "Length: %u",
419 dissect_wccp2_info(tvbuff_t *tvb, int offset, guint16 length,
420 proto_tree *wccp_tree)
425 proto_tree *info_tree;
427 gboolean (*dissector)(tvbuff_t *, int, int, proto_tree *);
429 while (length != 0) {
430 type = tvb_get_ntohs(tvb, offset);
431 item_length = tvb_get_ntohs(tvb, offset+2);
435 case WCCP2_SECURITY_INFO:
436 ett = ett_security_info;
437 dissector = dissect_wccp2_security_info;
440 case WCCP2_SERVICE_INFO:
441 ett = ett_service_info;
442 dissector = dissect_wccp2_service_info;
445 case WCCP2_ROUTER_ID_INFO:
446 ett = ett_router_identity_info;
447 dissector = dissect_wccp2_router_identity_info;
450 case WCCP2_WC_ID_INFO:
451 ett = ett_wc_identity_info;
452 dissector = dissect_wccp2_wc_identity_info;
455 case WCCP2_RTR_VIEW_INFO:
456 ett = ett_router_view_info;
457 dissector = dissect_wccp2_router_view_info;
460 case WCCP2_WC_VIEW_INFO:
461 ett = ett_wc_view_info;
462 dissector = dissect_wccp2_wc_view_info;
465 case WCCP2_REDIRECT_ASSIGNMENT:
466 ett = ett_router_assignment_info;
467 dissector = dissect_wccp2_assignment_info;
470 case WCCP2_QUERY_INFO:
471 ett = ett_query_info;
472 dissector = dissect_wccp2_router_query_info;
475 case WCCP2_CAPABILITIES_INFO:
476 ett = ett_capabilities_info;
477 dissector = dissect_wccp2_capability_info;
481 ett = ett_unknown_info;
486 ti = proto_tree_add_text(wccp_tree, tvb, offset, item_length + 4,
487 val_to_str(type, info_type_vals, "Unknown info type (%u)"));
488 info_tree = proto_item_add_subtree(ti, ett);
489 proto_tree_add_text(info_tree, tvb, offset, 2,
491 val_to_str(type, info_type_vals, "Unknown info type (%u)"));
492 proto_tree_add_text(info_tree, tvb, offset+2, 2,
493 "Length: %u", item_length);
498 * XXX - pass in "length" and check for that as well.
500 if (dissector != NULL) {
501 if (!(*dissector)(tvb, offset, item_length, info_tree))
502 return; /* ran out of data */
504 proto_tree_add_text(info_tree, tvb, offset, item_length,
505 "Data: %u byte%s", item_length,
506 plurality(item_length, "", "s"));
508 offset += item_length;
509 length -= item_length;
513 #define SECURITY_INFO_LEN 4
515 #define WCCP2_NO_SECURITY 0
516 #define WCCP2_MD5_SECURITY 1
519 dissect_wccp2_security_info(tvbuff_t *tvb, int offset, int length,
520 proto_tree *info_tree)
522 guint32 security_option;
524 if (length < SECURITY_INFO_LEN) {
525 proto_tree_add_text(info_tree, tvb, offset, 0,
526 "Item length is %u, should be %u", length,
531 security_option = tvb_get_ntohl(tvb, offset);
532 switch (security_option) {
534 case WCCP2_NO_SECURITY:
535 proto_tree_add_text(info_tree, tvb, offset, 4,
536 "Security Option: None");
539 case WCCP2_MD5_SECURITY:
540 proto_tree_add_text(info_tree, tvb, offset, 4,
541 "Security Option: MD5");
544 proto_tree_add_text(info_tree, tvb, offset,
545 length - 4, "MD5 checksum: %s",
546 tvb_bytes_to_str(tvb, offset, length - 4));
551 proto_tree_add_text(info_tree, tvb, offset, 4,
552 "Security Option: Unknown (%u)", security_option);
558 #define SERVICE_INFO_LEN (4+4+8*2)
560 #define WCCP2_SERVICE_STANDARD 0
561 #define WCCP2_SERVICE_DYNAMIC 1
566 #define WCCP2_SI_SRC_IP_HASH 0x0001
567 #define WCCP2_SI_DST_IP_HASH 0x0002
568 #define WCCP2_SI_SRC_PORT_HASH 0x0004
569 #define WCCP2_SI_DST_PORT_HASH 0x0008
570 #define WCCP2_SI_PORTS_DEFINED 0x0010
571 #define WCCP2_SI_PORTS_SOURCE 0x0020
572 #define WCCP2_SI_SRC_IP_ALT_HASH 0x0100
573 #define WCCP2_SI_DST_IP_ALT_HASH 0x0200
574 #define WCCP2_SI_SRC_PORT_ALT_HASH 0x0400
575 #define WCCP2_SI_DST_PORT_ALT_HASH 0x0800
578 dissect_wccp2_service_info(tvbuff_t *tvb, int offset, int length,
579 proto_tree *info_tree)
584 proto_tree *field_tree;
587 if (length != SERVICE_INFO_LEN) {
588 proto_tree_add_text(info_tree, tvb, offset, 0,
589 "Item length is %u, should be %u", length,
594 service_type = tvb_get_guint8(tvb, offset);
595 switch (service_type) {
597 case WCCP2_SERVICE_STANDARD:
598 proto_tree_add_text(info_tree, tvb, offset, 1,
599 "Service Type: Well-known service");
600 proto_tree_add_text(info_tree, tvb, offset+1, 1,
602 val_to_str(tvb_get_guint8(tvb, offset+1), service_id_vals,
603 "Unknown (0x%02X)"));
607 case WCCP2_SERVICE_DYNAMIC:
608 proto_tree_add_text(info_tree, tvb, offset, 1,
609 "Service Type: Dynamic service");
610 proto_tree_add_text(info_tree, tvb, offset+1, 1,
612 val_to_str(tvb_get_guint8(tvb, offset+1), service_id_vals,
613 "Unknown (0x%02X)"));
614 proto_tree_add_text(info_tree, tvb, offset+2, 1,
615 "Priority: %u", tvb_get_guint8(tvb, offset+2));
617 * XXX - does "IP protocol identifier" mean this is a
618 * protocol type of the sort you get in IP headers?
619 * If so, we should get a table of those from the
620 * IP dissector, and use that.
622 proto_tree_add_text(info_tree, tvb, offset+3, 1,
623 "Protocol: %u", tvb_get_guint8(tvb, offset+3)); /* IP protocol identifier */
627 proto_tree_add_text(info_tree, tvb, offset, 1,
628 "Service Type: Unknown (%u)", service_type);
633 flags = tvb_get_ntohl(tvb, offset);
634 tf = proto_tree_add_text(info_tree, tvb, offset, 4,
635 "Flags: 0x%08X", flags);
636 field_tree = proto_item_add_subtree(tf, ett_service_flags);
637 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
638 decode_boolean_bitfield(flags, WCCP2_SI_SRC_IP_HASH,
640 "Use source IP address in primary hash",
641 "Don't use source IP address in primary hash"));
642 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
643 decode_boolean_bitfield(flags, WCCP2_SI_DST_IP_HASH,
645 "Use destination IP address in primary hash",
646 "Don't use destination IP address in primary hash"));
647 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
648 decode_boolean_bitfield(flags, WCCP2_SI_SRC_PORT_HASH,
650 "Use source port in primary hash",
651 "Don't use source port in primary hash"));
652 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
653 decode_boolean_bitfield(flags, WCCP2_SI_DST_PORT_HASH,
655 "Use destination port in primary hash",
656 "Don't use destination port in primary hash"));
657 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
658 decode_boolean_bitfield(flags, WCCP2_SI_PORTS_DEFINED,
661 "Ports not defined"));
662 if (flags & WCCP2_SI_PORTS_DEFINED) {
663 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
664 decode_boolean_bitfield(flags, WCCP2_SI_PORTS_SOURCE,
666 "Ports refer to source port",
667 "Ports refer to destination port"));
669 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
670 decode_boolean_bitfield(flags, WCCP2_SI_SRC_IP_ALT_HASH,
672 "Use source IP address in secondary hash",
673 "Don't use source IP address in secondary hash"));
674 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
675 decode_boolean_bitfield(flags, WCCP2_SI_DST_IP_ALT_HASH,
677 "Use destination IP address in secondary hash",
678 "Don't use destination IP address in secondary hash"));
679 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
680 decode_boolean_bitfield(flags, WCCP2_SI_SRC_PORT_ALT_HASH,
682 "Use source port in secondary hash",
683 "Don't use source port in secondary hash"));
684 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
685 decode_boolean_bitfield(flags, WCCP2_SI_DST_PORT_ALT_HASH,
687 "Use destination port in secondary hash",
688 "Don't use destination port in secondary hash"));
691 if (flags & WCCP2_SI_PORTS_DEFINED) {
692 for (i = 0; i < 8; i++) {
693 proto_tree_add_text(info_tree, tvb, offset, 2,
694 "Port %d: %u", i, tvb_get_ntohs(tvb, offset));
702 #define ROUTER_ID_INFO_MIN_LEN (8+4+4)
705 dissect_wccp2_router_identity_element(tvbuff_t *tvb, int offset,
708 proto_tree_add_text(tree, tvb, offset, 4,
709 "IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
710 proto_tree_add_text(tree, tvb, offset + 4, 4,
711 "Receive ID: %u", tvb_get_ntohl(tvb, offset + 4));
715 dissect_wccp2_router_identity_info(tvbuff_t *tvb, int offset, int length,
716 proto_tree *info_tree)
718 guint32 n_received_from;
721 proto_tree *element_tree;
723 if (length < ROUTER_ID_INFO_MIN_LEN) {
724 proto_tree_add_text(info_tree, tvb, offset, 0,
725 "Item length is %u, should be >= %u", length,
726 ROUTER_ID_INFO_MIN_LEN);
730 te = proto_tree_add_text(info_tree, tvb, offset, 8,
731 "Router Identity Element: IP address %s",
732 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
733 element_tree = proto_item_add_subtree(te,
734 ett_router_identity_element);
735 dissect_wccp2_router_identity_element(tvb, offset, element_tree);
738 proto_tree_add_text(info_tree, tvb, offset, 4,
739 "Sent To IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
742 n_received_from = tvb_get_ntohl(tvb, offset);
743 proto_tree_add_text(info_tree, tvb, offset, 4,
744 "Number of Received From IP addresses: %u", n_received_from);
747 for (i = 0; i < n_received_from; i++) {
748 proto_tree_add_text(info_tree, tvb, offset, 4,
749 "Received From IP Address %d: %s", i,
750 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
757 #define WC_ID_INFO_LEN (4+4+8*4+4)
760 dissect_wccp2_web_cache_identity_element(tvbuff_t *tvb, int offset,
763 proto_item *bucket_item;
764 proto_tree *bucket_tree;
766 proto_tree *field_tree;
772 proto_tree_add_text(tree, tvb, offset, 4,
773 "Web-Cache IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
776 proto_tree_add_text(tree, tvb, offset, 2,
777 "Hash Revision %u", tvb_get_ntohs(tvb, offset));
780 flags = tvb_get_ntohs(tvb, offset);
781 tf = proto_tree_add_text(tree, tvb, offset, 2,
782 "Flags: 0x%04X (%s)", flags,
784 "Hash information is historical" :
785 "Hash information is current"));
786 field_tree = proto_item_add_subtree(tf, ett_flags);
787 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
788 decode_boolean_bitfield(flags, 0x8000,
790 "Hash information is historical",
791 "Hash information is current"));
794 bucket_item = proto_tree_add_text(tree, tvb, offset, 8*4,
796 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
797 for (i = 0, n = 0; i < 32; i++) {
798 bucket_info = tvb_get_guint8(tvb, offset);
799 n = wccp_bucket_info(bucket_info, bucket_tree, n, tvb, offset);
803 proto_tree_add_text(tree, tvb, offset, 2,
804 "Assignment Weight: %u", tvb_get_ntohs(tvb, offset));
807 proto_tree_add_text(tree, tvb, offset, 2,
808 "Status: 0x%04X", tvb_get_ntohs(tvb, offset));
815 dissect_wccp2_wc_identity_info(tvbuff_t *tvb, int offset, int length,
816 proto_tree *info_tree)
819 proto_tree *element_tree;
821 if (length != WC_ID_INFO_LEN) {
822 proto_tree_add_text(info_tree, tvb, offset, 0,
823 "Item length is %u, should be %u", length, WC_ID_INFO_LEN);
827 te = proto_tree_add_text(info_tree, tvb, offset, 4+2+2+32+2+2,
828 "Web-Cache Identity Element: IP address %s",
829 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
830 element_tree = proto_item_add_subtree(te, ett_wc_identity_element);
831 if (!dissect_wccp2_web_cache_identity_element(tvb, offset,
833 return FALSE; /* ran out of data */
838 #define ROUTER_VIEW_INFO_MIN_LEN (4+8+4)
841 dissect_wccp2_assignment_key(tvbuff_t *tvb, int offset,
842 proto_tree *info_tree)
844 proto_tree_add_text(info_tree, tvb, offset, 4,
845 "Assignment Key IP Address: %s",
846 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
847 proto_tree_add_text(info_tree, tvb, offset + 4, 4,
848 "Assignment Key Change Number: %u", tvb_get_ntohl(tvb, offset + 4));
852 dissect_wccp2_router_view_info(tvbuff_t *tvb, int offset, int length,
853 proto_tree *info_tree)
856 guint32 n_web_caches;
859 proto_tree *element_tree;
861 if (length < ROUTER_VIEW_INFO_MIN_LEN) {
862 proto_tree_add_text(info_tree, tvb, offset, 0,
863 "Item length is %u, should be >= %u", length,
864 ROUTER_VIEW_INFO_MIN_LEN);
868 proto_tree_add_text(info_tree, tvb, offset, 4,
869 "Member Change Number: %u", tvb_get_ntohl(tvb, offset));
872 dissect_wccp2_assignment_key(tvb, offset, info_tree);
875 n_routers = tvb_get_ntohl(tvb, offset);
876 proto_tree_add_text(info_tree, tvb, offset, 4,
877 "Number of Routers: %u", n_routers);
880 for (i = 0; i < n_routers; i++) {
881 proto_tree_add_text(info_tree, tvb, offset, 4,
882 "Router %d IP Address: %s", i,
883 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
887 n_web_caches = tvb_get_ntohl(tvb, offset);
888 proto_tree_add_text(info_tree, tvb, offset, 4,
889 "Number of Web Caches: %u", n_web_caches);
892 for (i = 0; i < n_web_caches; i++) {
893 te = proto_tree_add_text(info_tree, tvb, offset, WC_ID_INFO_LEN,
894 "Web-Cache Identity Element %d: IP address %s", i,
895 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
896 element_tree = proto_item_add_subtree(te,
897 ett_wc_identity_element);
898 if (!dissect_wccp2_web_cache_identity_element(tvb,
899 offset, element_tree))
900 return FALSE; /* ran out of data */
901 offset += WC_ID_INFO_LEN;
907 #define WC_VIEW_INFO_MIN_LEN (4+4)
910 dissect_wccp2_wc_view_info(tvbuff_t *tvb, int offset, int length,
911 proto_tree *info_tree)
914 guint32 n_web_caches;
917 proto_tree *element_tree;
919 if (length < WC_VIEW_INFO_MIN_LEN) {
920 proto_tree_add_text(info_tree, tvb, offset, 0,
921 "Item length is %u, should be >= %u", length,
922 WC_VIEW_INFO_MIN_LEN);
926 proto_tree_add_text(info_tree, tvb, offset, 4,
927 "Change Number: %u", tvb_get_ntohl(tvb, offset));
930 n_routers = tvb_get_ntohl(tvb, offset);
931 proto_tree_add_text(info_tree, tvb, offset, 4,
932 "Number of Routers: %u", n_routers);
935 for (i = 0; i < n_routers; i++) {
936 te = proto_tree_add_text(info_tree, tvb, offset, 8,
937 "Router %d Identity Element: IP address %s", i,
938 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
939 element_tree = proto_item_add_subtree(te,
940 ett_router_identity_element);
941 dissect_wccp2_router_identity_element(tvb, offset, element_tree);
945 n_web_caches = tvb_get_ntohl(tvb, offset);
946 proto_tree_add_text(info_tree, tvb, offset, 4,
947 "Number of Web Caches: %u", n_web_caches);
950 for (i = 0; i < n_web_caches; i++) {
951 proto_tree_add_text(info_tree, tvb, offset, 4,
952 "Web-Cache %d: IP address %s", i,
953 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
960 #define ASSIGNMENT_INFO_MIN_LEN (8+4)
963 dissect_wccp2_router_assignment_element(tvbuff_t *tvb, int offset,
966 proto_tree_add_text(tree, tvb, offset, 4,
967 "IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
968 proto_tree_add_text(tree, tvb, offset + 4, 4,
969 "Receive ID: %u", tvb_get_ntohl(tvb, offset + 4));
970 proto_tree_add_text(tree, tvb, offset + 8, 4,
971 "Change Number: %u", tvb_get_ntohl(tvb, offset + 8));
975 assignment_bucket_name(guint8 bucket)
977 static gchar str[4][10+1];
980 if (cur == &str[0][0])
982 else if (cur == &str[1][0])
984 else if (cur == &str[2][0])
989 strcpy(cur, "Unassigned");
991 sprintf(cur, "%u%s", bucket >> 1,
992 (bucket & 0x01) ? " (Alt)" : "");
998 dissect_wccp2_assignment_info(tvbuff_t *tvb, int offset, int length,
999 proto_tree *info_tree)
1002 guint32 n_web_caches;
1005 proto_tree *element_tree;
1007 if (length < ASSIGNMENT_INFO_MIN_LEN) {
1008 proto_tree_add_text(info_tree, tvb, offset, 0,
1009 "Item length is %u, should be >= %u", length,
1010 ASSIGNMENT_INFO_MIN_LEN);
1014 dissect_wccp2_assignment_key(tvb, offset, info_tree);
1017 n_routers = tvb_get_ntohl(tvb, offset);
1018 proto_tree_add_text(info_tree, tvb, offset, 4,
1019 "Number of Routers: %u", n_routers);
1022 for (i = 0; i < n_routers; i++) {
1023 te = proto_tree_add_text(info_tree, tvb, offset, 4,
1024 "Router %d Assignment Element: IP address %s", i,
1025 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1026 element_tree = proto_item_add_subtree(te,
1027 ett_router_assignment_element);
1028 dissect_wccp2_router_assignment_element(tvb, offset,
1033 n_web_caches = tvb_get_ntohl(tvb, offset);
1034 proto_tree_add_text(info_tree, tvb, offset, 4,
1035 "Number of Web Caches: %u", n_web_caches);
1038 for (i = 0; i < n_web_caches; i++) {
1039 proto_tree_add_text(info_tree, tvb, offset, 4,
1040 "Web-Cache %d: IP address %s", i,
1041 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1045 for (i = 0; i < 256; i += 4) {
1046 proto_tree_add_text(info_tree, tvb, offset, 4,
1047 "Buckets %d - %d: %10s %10s %10s %10s",
1049 assignment_bucket_name(tvb_get_guint8(tvb, offset)),
1050 assignment_bucket_name(tvb_get_guint8(tvb, offset+1)),
1051 assignment_bucket_name(tvb_get_guint8(tvb, offset+2)),
1052 assignment_bucket_name(tvb_get_guint8(tvb, offset+3)));
1059 #define QUERY_INFO_LEN (4+4+4+4)
1062 dissect_wccp2_router_query_info(tvbuff_t *tvb, int offset, int length,
1063 proto_tree *info_tree)
1065 if (length != QUERY_INFO_LEN) {
1066 proto_tree_add_text(info_tree, tvb, offset, 0,
1067 "Item length is %u, should be %u", length, QUERY_INFO_LEN);
1071 proto_tree_add_text(info_tree, tvb, offset, 4,
1072 "Router IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1075 proto_tree_add_text(info_tree, tvb, offset, 4,
1076 "Receive ID: %u", tvb_get_ntohl(tvb, offset));
1079 proto_tree_add_text(info_tree, tvb, offset, 4,
1080 "Sent To IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1083 proto_tree_add_text(info_tree, tvb, offset, 4,
1084 "Target IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1090 #define WCCP2_FORWARDING_METHOD 0x01
1091 #define WCCP2_ASSIGNMENT_METHOD 0x02
1092 #define WCCP2_PACKET_RETURN_METHOD 0x03
1094 static const value_string capability_type_vals[] = {
1095 { WCCP2_FORWARDING_METHOD, "Forwarding Method" },
1096 { WCCP2_ASSIGNMENT_METHOD, "Assignment Method" },
1097 { WCCP2_PACKET_RETURN_METHOD, "Return Method" },
1101 #define WCCP2_FORWARDING_METHOD_GRE 0x00000001
1102 #define WCCP2_FORWARDING_METHOD_L2 0x00000002
1104 static const capability_flag forwarding_method_flags[] = {
1105 { WCCP2_FORWARDING_METHOD_GRE,
1106 "IP-GRE", "GRE-encapsulated" },
1107 { WCCP2_FORWARDING_METHOD_L2,
1108 "L2", "L2 rewrite" },
1113 #define WCCP2_ASSIGNMENT_METHOD_HASH 0x00000001
1114 #define WCCP2_ASSIGNMENT_METHOD_MASK 0x00000002
1116 static const capability_flag assignment_method_flags[] = {
1117 { WCCP2_ASSIGNMENT_METHOD_HASH, "Hash", "Hash" },
1118 { WCCP2_ASSIGNMENT_METHOD_MASK, "Mask", "Mask" },
1122 #define WCCP2_PACKET_RETURN_METHOD_GRE 0x00000001
1123 #define WCCP2_PACKET_RETURN_METHOD_L2 0x00000002
1125 static const capability_flag packet_return_method_flags[] = {
1126 { WCCP2_PACKET_RETURN_METHOD_GRE,
1127 "IP-GRE", "GRE-encapsulated" },
1128 { WCCP2_PACKET_RETURN_METHOD_L2,
1129 "L2", "L2 rewrite" },
1135 dissect_wccp2_capability_info(tvbuff_t *tvb, int offset, int length,
1136 proto_tree *info_tree)
1138 guint16 capability_type;
1139 guint16 capability_len;
1142 proto_tree *element_tree;
1144 for (curr_offset = offset; curr_offset < (length + offset);
1145 curr_offset += capability_len) {
1146 capability_type = tvb_get_ntohs(tvb, curr_offset);
1147 capability_len = tvb_get_ntohs(tvb, curr_offset + 2);
1148 te = proto_tree_add_text(info_tree, tvb, curr_offset,
1149 capability_len, "%s",
1150 val_to_str(capability_type,
1151 capability_type_vals, "Unknown Capability Element (0x%08X)"));
1152 element_tree = proto_item_add_subtree(te,
1153 ett_capability_element);
1155 proto_tree_add_text(element_tree, tvb, curr_offset, 2,
1157 val_to_str(capability_type,
1158 capability_type_vals, "Unknown (0x%08X)"));
1160 if (capability_len < 4) {
1161 proto_tree_add_text(element_tree, tvb, curr_offset+2, 2,
1162 "Length: %u (illegal, must be >= 4)",
1166 proto_tree_add_text(element_tree, tvb, curr_offset+2, 2,
1167 "Length: %u", capability_len);
1169 switch (capability_type) {
1171 case WCCP2_FORWARDING_METHOD:
1172 dissect_32_bit_capability_flags(tvb, curr_offset,
1173 capability_len, ett_capability_forwarding_method,
1174 forwarding_method_flags, element_tree);
1177 case WCCP2_ASSIGNMENT_METHOD:
1178 dissect_32_bit_capability_flags(tvb, curr_offset,
1179 capability_len, 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,
1185 capability_len, ett_capability_return_method,
1186 packet_return_method_flags, element_tree);
1190 proto_tree_add_text(element_tree, tvb,
1191 curr_offset+4, capability_len-4,
1193 tvb_bytes_to_str(tvb, curr_offset+4, capability_len-4));
1202 dissect_32_bit_capability_flags(tvbuff_t *tvb, int curr_offset,
1203 guint16 capability_len, gint ett, const capability_flag *flags,
1204 proto_tree *element_tree)
1206 guint32 capability_val;
1208 proto_tree *method_tree;
1210 char flags_string[128+1];
1215 if (capability_len != 8) {
1216 proto_tree_add_text(element_tree, tvb,
1217 curr_offset+4, capability_len-4,
1218 "Illegal length (must be 8)");
1222 capability_val = tvb_get_ntohl(tvb, curr_offset + 4);
1223 flags_string[0] = '\0';
1224 p = &flags_string[0];
1225 space_left = sizeof flags_string;
1226 for (i = 0; flags[i].short_name != NULL; i++) {
1227 if (capability_val & flags[i].value) {
1228 if (p != &flags_string[0]) {
1229 snprintf(p, space_left, ",");
1230 p = &flags_string[strlen(flags_string)];
1232 snprintf(p, space_left, "%s", flags[i].short_name);
1233 p = &flags_string[strlen(flags_string)];
1236 tm = proto_tree_add_text(element_tree, tvb, curr_offset+4, 4,
1237 "Value: 0x%08X (%s)", capability_val, flags_string);
1238 method_tree = proto_item_add_subtree(tm, ett);
1239 for (i = 0; flags[i].long_name != NULL; i++) {
1240 p = decode_bitfield_value(buf, capability_val,
1241 flags[i].value, 32);
1242 strcpy(p, flags[i].long_name);
1244 if (capability_val & flags[i].value)
1245 strcat(p, "Supported");
1247 strcat(p, "Not supported");
1248 proto_tree_add_text(method_tree, tvb, curr_offset+4, 4,
1254 proto_register_wccp(void)
1256 static hf_register_info hf[] = {
1257 { &hf_wccp_message_type,
1258 { "WCCP Message Type", "wccp.message", FT_UINT32, BASE_DEC, VALS(wccp_type_vals), 0x0,
1259 "The WCCP message that was sent", HFILL }
1262 { "WCCP Version", "wccp.version", FT_UINT32, BASE_HEX, VALS(wccp_version_val), 0x0,
1263 "The WCCP version", HFILL }
1265 { &hf_hash_revision,
1266 { "Hash Revision", "wccp.hash_revision", FT_UINT32, BASE_DEC, 0x0, 0x0,
1267 "The cache hash revision", HFILL }
1270 { "Change Number", "wccp.change_num", FT_UINT32, BASE_DEC, 0x0, 0x0,
1271 "The Web-Cache list entry change number", HFILL }
1274 { "Received ID", "wccp.recvd_id", FT_UINT32, BASE_DEC, 0x0, 0x0,
1275 "The number of I_SEE_YOU's that have been sent", HFILL }
1278 { "Web Cache IP address", "wccp.cache_ip", FT_IPv4, BASE_NONE, NULL, 0x0,
1279 "The IP address of a Web cache", HFILL }
1282 static gint *ett[] = {
1291 &ett_router_identity_element,
1292 &ett_router_identity_info,
1293 &ett_wc_identity_element,
1294 &ett_wc_identity_info,
1295 &ett_router_view_info,
1298 &ett_router_assignment_element,
1299 &ett_router_assignment_info,
1300 &ett_capabilities_info,
1301 &ett_capability_element,
1302 &ett_capability_forwarding_method,
1303 &ett_capability_assignment_method,
1304 &ett_capability_return_method,
1308 proto_wccp = proto_register_protocol("Web Cache Coordination Protocol",
1310 proto_register_field_array(proto_wccp, hf, array_length(hf));
1311 proto_register_subtree_array(ett, array_length(ett));
1315 proto_reg_handoff_wccp(void)
1317 dissector_add("udp.port", UDP_PORT_WCCP, dissect_wccp, proto_wccp);