2 * Routines for Web Cache Coordination Protocol dissection
3 * Jerry Talkington <jtalkington@users.sourceforge.net>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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 <epan/emem.h>
35 #include "packet-wccp.h"
37 static int proto_wccp = -1;
38 static int hf_wccp_message_type = -1; /* the message type */
39 static int hf_wccp_version = -1; /* protocol version */
40 static int hf_hash_revision = -1; /* the version of the hash */
41 static int hf_change_num = -1; /* change number */
42 static int hf_recvd_id = -1;
43 static int hf_cache_ip = -1;
45 static gint ett_wccp = -1;
46 static gint ett_cache_count = -1;
47 static gint ett_buckets = -1;
48 static gint ett_flags = -1;
49 static gint ett_cache_info = -1;
50 static gint ett_security_info = -1;
51 static gint ett_service_info = -1;
52 static gint ett_service_flags = -1;
53 static gint ett_router_identity_element = -1;
54 static gint ett_router_identity_info = -1;
55 static gint ett_wc_identity_element = -1;
56 static gint ett_wc_identity_info = -1;
57 static gint ett_router_view_info = -1;
58 static gint ett_wc_view_info = -1;
59 static gint ett_router_assignment_element = -1;
60 static gint ett_router_assignment_info = -1;
61 static gint ett_query_info = -1;
62 static gint ett_capabilities_info = -1;
63 static gint ett_capability_element = -1;
64 static gint ett_capability_forwarding_method = -1;
65 static gint ett_capability_assignment_method = -1;
66 static gint ett_capability_return_method = -1;
67 static gint ett_unknown_info = -1;
72 * http://www.alternic.org/drafts/drafts-f-g/draft-forster-wrec-wccp-v1-00.html
74 * is a copy of the now-expired Internet-Draft for WCCP 1.0.
78 * http://search.ietf.org/internet-drafts/draft-wilson-wrec-wccp-v2-01.txt
80 * is an Internet-Draft for WCCP 2.0.
83 #define UDP_PORT_WCCP 2048
87 #define WCCP_HERE_I_AM 7
88 #define WCCP_I_SEE_YOU 8
89 #define WCCP_ASSIGN_BUCKET 9
90 #define WCCP2_HERE_I_AM 10
91 #define WCCP2_I_SEE_YOU 11
92 #define WCCP2_REDIRECT_ASSIGN 12
93 #define WCCP2_REMOVAL_QUERY 13
95 static const value_string wccp_type_vals[] = {
96 { WCCP_HERE_I_AM, "1.0 Here I am" },
97 { WCCP_I_SEE_YOU, "1.0 I see you" },
98 { WCCP_ASSIGN_BUCKET, "1.0 Assign bucket" },
99 { WCCP2_HERE_I_AM, "2.0 Here I am" },
100 { WCCP2_I_SEE_YOU, "2.0 I see you" },
101 { WCCP2_REDIRECT_ASSIGN, "2.0 Redirect assign" },
102 { WCCP2_REMOVAL_QUERY, "2.0 Removal query" },
106 static const value_string wccp_version_val[] = {
112 #define HASH_INFO_SIZE (4*(1+8+1))
114 #define WCCP_U_FLAG 0x80000000
116 #define WCCP2_SECURITY_INFO 0
117 #define WCCP2_SERVICE_INFO 1
118 #define WCCP2_ROUTER_ID_INFO 2
119 #define WCCP2_WC_ID_INFO 3
120 #define WCCP2_RTR_VIEW_INFO 4
121 #define WCCP2_WC_VIEW_INFO 5
122 #define WCCP2_REDIRECT_ASSIGNMENT 6
123 #define WCCP2_QUERY_INFO 7
124 #define WCCP2_CAPABILITIES_INFO 8
125 #define WCCP2_ALT_ASSIGNMENT 13
126 #define WCCP2_ASSIGN_MAP 14
127 #define WCCP2_COMMAND_EXTENSION 15
129 static const value_string info_type_vals[] = {
130 { WCCP2_SECURITY_INFO, "Security Info" },
131 { WCCP2_SERVICE_INFO, "Service Info" },
132 { WCCP2_ROUTER_ID_INFO, "Router Identity Info" },
133 { WCCP2_WC_ID_INFO, "Web-Cache Identity Info" },
134 { WCCP2_RTR_VIEW_INFO, "Router View Info" },
135 { WCCP2_WC_VIEW_INFO, "Web-Cache View Info" },
136 { WCCP2_REDIRECT_ASSIGNMENT, "Assignment Info" },
137 { WCCP2_QUERY_INFO, "Query Info" },
138 { WCCP2_CAPABILITIES_INFO, "Capabilities Info" },
139 { WCCP2_COMMAND_EXTENSION, "Command Extension" },
143 const value_string service_id_vals[] = {
148 typedef struct capability_flag {
150 const char *short_name;
151 const char *long_name;
154 static void dissect_hash_data(tvbuff_t *tvb, int offset,
155 proto_tree *wccp_tree);
156 static void dissect_web_cache_list_entry(tvbuff_t *tvb, int offset,
157 int index, proto_tree *wccp_tree);
158 static int wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree,
159 guint32 start, tvbuff_t *tvb, int offset);
160 static gchar *bucket_name(guint8 bucket);
161 static guint16 dissect_wccp2_header(tvbuff_t *tvb, int offset,
162 proto_tree *wccp_tree);
163 static void dissect_wccp2_info(tvbuff_t *tvb, int offset, guint16 length,
164 proto_tree *wccp_tree);
165 static gboolean dissect_wccp2_security_info(tvbuff_t *tvb, int offset,
166 int length, proto_tree *info_tree);
167 static gboolean dissect_wccp2_service_info(tvbuff_t *tvb, int offset,
168 int length, proto_tree *info_tree);
169 static gboolean dissect_wccp2_router_identity_info(tvbuff_t *tvb,
170 int offset, int length, proto_tree *info_tree);
171 static gboolean dissect_wccp2_wc_identity_info(tvbuff_t *tvb, int offset,
172 int length, proto_tree *info_tree);
173 static gboolean dissect_wccp2_router_view_info(tvbuff_t *tvb, int offset,
174 int length, proto_tree *info_tree);
175 static gboolean dissect_wccp2_wc_view_info(tvbuff_t *tvb, int offset,
176 int length, proto_tree *info_tree);
177 static gboolean dissect_wccp2_assignment_info(tvbuff_t *tvb, int offset,
178 int length, proto_tree *info_tree);
179 static gboolean dissect_wccp2_router_query_info(tvbuff_t *tvb, int offset,
180 int length, proto_tree *info_tree);
181 static gboolean dissect_wccp2_capability_info(tvbuff_t *tvb, int offset,
182 int length, proto_tree *info_tree);
183 static void dissect_32_bit_capability_flags(tvbuff_t *tvb, int curr_offset,
184 guint16 capability_val_len, gint ett, const capability_flag *flags,
185 proto_tree *element_tree);
188 dissect_wccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
191 proto_tree *wccp_tree = NULL;
192 proto_item *wccp_tree_item;
193 guint32 wccp_message_type;
199 if(check_col(pinfo->cinfo, COL_PROTOCOL)) {
200 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WCCP");
202 if(check_col(pinfo->cinfo, COL_INFO)) {
203 col_clear(pinfo->cinfo, COL_INFO);
206 wccp_message_type = tvb_get_ntohl(tvb, offset);
208 if(check_col(pinfo->cinfo, COL_INFO)) {
209 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(wccp_message_type,
210 wccp_type_vals, "Unknown WCCP message (%u)"));
214 wccp_tree_item = proto_tree_add_item(tree, proto_wccp, tvb, offset,
216 wccp_tree = proto_item_add_subtree(wccp_tree_item, ett_wccp);
218 proto_tree_add_uint(wccp_tree, hf_wccp_message_type, tvb, offset,
219 sizeof(wccp_message_type), wccp_message_type);
220 offset += sizeof(wccp_message_type);
222 switch (wccp_message_type) {
225 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb,
228 dissect_hash_data(tvb, offset, wccp_tree);
229 offset += HASH_INFO_SIZE;
230 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
236 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb,
239 proto_tree_add_item(wccp_tree, hf_change_num, tvb, offset,
242 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
245 cache_count = tvb_get_ntohl(tvb, offset);
246 proto_tree_add_text(wccp_tree, tvb, offset, 4,
247 "Number of Web Caches: %u", cache_count);
249 for (i = 0; i < cache_count; i++) {
250 dissect_web_cache_list_entry(tvb, offset, i,
252 offset += 4 + HASH_INFO_SIZE;
256 case WCCP_ASSIGN_BUCKET:
258 * This hasn't been tested, since I don't have any
259 * traces with this in it.
261 * The V1 spec claims that this does, indeed,
262 * have a Received ID field after the type,
263 * rather than a Version field.
265 proto_tree_add_item(wccp_tree, hf_recvd_id, tvb, offset,
268 cache_count = tvb_get_ntohl(tvb, offset);
269 proto_tree_add_text(wccp_tree, tvb, offset, 4,
270 "Number of Web Caches: %u", cache_count);
272 for (i = 0; i < cache_count; i++) {
273 ipaddr = tvb_get_ipv4(tvb, offset);
274 proto_tree_add_ipv4_format(wccp_tree,
275 hf_cache_ip, tvb, offset, 4,
277 "Web Cache %d IP Address: %s", i,
278 ip_to_str((guint8 *)&ipaddr));
281 for (i = 0; i < 256; i += 4) {
282 proto_tree_add_text(wccp_tree, tvb, offset, 4,
283 "Buckets %d - %d: %10s %10s %10s %10s",
285 bucket_name(tvb_get_guint8(tvb, offset)),
286 bucket_name(tvb_get_guint8(tvb, offset+1)),
287 bucket_name(tvb_get_guint8(tvb, offset+2)),
288 bucket_name(tvb_get_guint8(tvb, offset+3)));
293 case WCCP2_HERE_I_AM:
294 case WCCP2_I_SEE_YOU:
295 case WCCP2_REMOVAL_QUERY:
296 case WCCP2_REDIRECT_ASSIGN:
297 default: /* assume unknown packets are v2 */
298 length = dissect_wccp2_header(tvb, offset, wccp_tree);
300 dissect_wccp2_info(tvb, offset, length, wccp_tree);
307 dissect_hash_data(tvbuff_t *tvb, int offset, proto_tree *wccp_tree)
309 proto_item *bucket_item;
310 proto_tree *bucket_tree;
312 proto_tree *field_tree;
318 proto_tree_add_item(wccp_tree, hf_hash_revision, tvb, offset, 4,
322 bucket_item = proto_tree_add_text(wccp_tree, tvb, offset, 32,
324 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
326 for (i = 0, n = 0; i < 32; i++) {
327 bucket_info = tvb_get_guint8(tvb, offset);
328 n = wccp_bucket_info(bucket_info, bucket_tree, n, tvb, offset);
331 flags = tvb_get_ntohl(tvb, offset);
332 tf = proto_tree_add_text(wccp_tree, tvb, offset, 4,
333 "Flags: 0x%08X (%s)", flags,
334 ((flags & WCCP_U_FLAG) ?
335 "Hash information is historical" :
336 "Hash information is current"));
337 field_tree = proto_item_add_subtree(tf, ett_flags);
338 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
339 decode_boolean_bitfield(flags, WCCP_U_FLAG,
341 "Hash information is historical",
342 "Hash information is current"));
346 dissect_web_cache_list_entry(tvbuff_t *tvb, int offset, int index,
347 proto_tree *wccp_tree)
350 proto_tree *list_entry_tree;
352 tl = proto_tree_add_text(wccp_tree, tvb, offset, 4 + HASH_INFO_SIZE,
353 "Web-Cache List Entry(%d)", index);
354 list_entry_tree = proto_item_add_subtree(tl, ett_cache_info);
355 proto_tree_add_item(list_entry_tree, hf_cache_ip, tvb, offset, 4,
357 dissect_hash_data(tvb, offset + 4, list_entry_tree);
362 * takes an integer representing a "Hash Information" bitmap, and spits out
363 * the corresponding proto_tree entries, returning the next bucket number.
366 wccp_bucket_info(guint8 bucket_info, proto_tree *bucket_tree, guint32 start,
367 tvbuff_t *tvb, int offset)
371 for(i = 0; i < 8; i++) {
372 proto_tree_add_text(bucket_tree, tvb, offset, sizeof(bucket_info), "Bucket %3d: %s", start, (bucket_info & 1<<i ? "Assigned" : "Not Assigned") );
379 bucket_name(guint8 bucket)
383 if (bucket == 0xff) {
387 g_snprintf(cur, 10+1, "%u", bucket);
393 dissect_wccp2_header(tvbuff_t *tvb, int offset, proto_tree *wccp_tree)
397 proto_tree_add_item(wccp_tree, hf_wccp_version, tvb, offset, 2,
400 length = tvb_get_ntohs(tvb, offset);
401 proto_tree_add_text(wccp_tree, tvb, offset, 2, "Length: %u",
407 dissect_wccp2_info(tvbuff_t *tvb, int offset, guint16 length,
408 proto_tree *wccp_tree)
413 proto_tree *info_tree;
415 gboolean (*dissector)(tvbuff_t *, int, int, proto_tree *);
417 while (length != 0) {
418 type = tvb_get_ntohs(tvb, offset);
419 item_length = tvb_get_ntohs(tvb, offset+2);
423 case WCCP2_SECURITY_INFO:
424 ett = ett_security_info;
425 dissector = dissect_wccp2_security_info;
428 case WCCP2_SERVICE_INFO:
429 ett = ett_service_info;
430 dissector = dissect_wccp2_service_info;
433 case WCCP2_ROUTER_ID_INFO:
434 ett = ett_router_identity_info;
435 dissector = dissect_wccp2_router_identity_info;
438 case WCCP2_WC_ID_INFO:
439 ett = ett_wc_identity_info;
440 dissector = dissect_wccp2_wc_identity_info;
443 case WCCP2_RTR_VIEW_INFO:
444 ett = ett_router_view_info;
445 dissector = dissect_wccp2_router_view_info;
448 case WCCP2_WC_VIEW_INFO:
449 ett = ett_wc_view_info;
450 dissector = dissect_wccp2_wc_view_info;
453 case WCCP2_REDIRECT_ASSIGNMENT:
454 ett = ett_router_assignment_info;
455 dissector = dissect_wccp2_assignment_info;
458 case WCCP2_QUERY_INFO:
459 ett = ett_query_info;
460 dissector = dissect_wccp2_router_query_info;
463 case WCCP2_CAPABILITIES_INFO:
464 ett = ett_capabilities_info;
465 dissector = dissect_wccp2_capability_info;
469 ett = ett_unknown_info;
474 ti = proto_tree_add_text(wccp_tree, tvb, offset, item_length + 4,
475 val_to_str(type, info_type_vals, "Unknown info type (%u)"));
476 info_tree = proto_item_add_subtree(ti, ett);
477 proto_tree_add_text(info_tree, tvb, offset, 2,
479 val_to_str(type, info_type_vals, "Unknown info type (%u)"));
480 proto_tree_add_text(info_tree, tvb, offset+2, 2,
481 "Length: %u", item_length);
486 * XXX - pass in "length" and check for that as well.
488 if (dissector != NULL) {
489 if (!(*dissector)(tvb, offset, item_length, info_tree))
490 return; /* ran out of data */
492 proto_tree_add_text(info_tree, tvb, offset, item_length,
493 "Data: %u byte%s", item_length,
494 plurality(item_length, "", "s"));
496 offset += item_length;
497 length -= item_length;
501 #define SECURITY_INFO_LEN 4
503 #define WCCP2_NO_SECURITY 0
504 #define WCCP2_MD5_SECURITY 1
507 dissect_wccp2_security_info(tvbuff_t *tvb, int offset, int length,
508 proto_tree *info_tree)
510 guint32 security_option;
512 if (length < SECURITY_INFO_LEN) {
513 proto_tree_add_text(info_tree, tvb, offset, 0,
514 "Item length is %u, should be %u", length,
519 security_option = tvb_get_ntohl(tvb, offset);
520 switch (security_option) {
522 case WCCP2_NO_SECURITY:
523 proto_tree_add_text(info_tree, tvb, offset, 4,
524 "Security Option: None");
527 case WCCP2_MD5_SECURITY:
528 proto_tree_add_text(info_tree, tvb, offset, 4,
529 "Security Option: MD5");
532 proto_tree_add_text(info_tree, tvb, offset,
533 length - 4, "MD5 checksum: %s",
534 tvb_bytes_to_str(tvb, offset, length - 4));
539 proto_tree_add_text(info_tree, tvb, offset, 4,
540 "Security Option: Unknown (%u)", security_option);
546 #define SERVICE_INFO_LEN (4+4+8*2)
548 #define WCCP2_SERVICE_STANDARD 0
549 #define WCCP2_SERVICE_DYNAMIC 1
554 #define WCCP2_SI_SRC_IP_HASH 0x0001
555 #define WCCP2_SI_DST_IP_HASH 0x0002
556 #define WCCP2_SI_SRC_PORT_HASH 0x0004
557 #define WCCP2_SI_DST_PORT_HASH 0x0008
558 #define WCCP2_SI_PORTS_DEFINED 0x0010
559 #define WCCP2_SI_PORTS_SOURCE 0x0020
560 #define WCCP2_SI_SRC_IP_ALT_HASH 0x0100
561 #define WCCP2_SI_DST_IP_ALT_HASH 0x0200
562 #define WCCP2_SI_SRC_PORT_ALT_HASH 0x0400
563 #define WCCP2_SI_DST_PORT_ALT_HASH 0x0800
566 dissect_wccp2_service_info(tvbuff_t *tvb, int offset, int length,
567 proto_tree *info_tree)
572 proto_tree *field_tree;
575 if (length != SERVICE_INFO_LEN) {
576 proto_tree_add_text(info_tree, tvb, offset, 0,
577 "Item length is %u, should be %u", length,
582 service_type = tvb_get_guint8(tvb, offset);
583 switch (service_type) {
585 case WCCP2_SERVICE_STANDARD:
586 proto_tree_add_text(info_tree, tvb, offset, 1,
587 "Service Type: Well-known service");
588 proto_tree_add_text(info_tree, tvb, offset+1, 1,
590 val_to_str(tvb_get_guint8(tvb, offset+1), service_id_vals,
591 "Unknown (0x%02X)"));
595 case WCCP2_SERVICE_DYNAMIC:
596 proto_tree_add_text(info_tree, tvb, offset, 1,
597 "Service Type: Dynamic 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)"));
602 proto_tree_add_text(info_tree, tvb, offset+2, 1,
603 "Priority: %u", tvb_get_guint8(tvb, offset+2));
605 * XXX - does "IP protocol identifier" mean this is a
606 * protocol type of the sort you get in IP headers?
607 * If so, we should get a table of those from the
608 * IP dissector, and use that.
610 proto_tree_add_text(info_tree, tvb, offset+3, 1,
611 "Protocol: %u", tvb_get_guint8(tvb, offset+3)); /* IP protocol identifier */
615 proto_tree_add_text(info_tree, tvb, offset, 1,
616 "Service Type: Unknown (%u)", service_type);
621 flags = tvb_get_ntohl(tvb, offset);
622 tf = proto_tree_add_text(info_tree, tvb, offset, 4,
623 "Flags: 0x%08X", flags);
624 field_tree = proto_item_add_subtree(tf, ett_service_flags);
625 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
626 decode_boolean_bitfield(flags, WCCP2_SI_SRC_IP_HASH,
628 "Use source IP address in primary hash",
629 "Don't use source IP address in primary hash"));
630 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
631 decode_boolean_bitfield(flags, WCCP2_SI_DST_IP_HASH,
633 "Use destination IP address in primary hash",
634 "Don't use destination IP address in primary hash"));
635 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
636 decode_boolean_bitfield(flags, WCCP2_SI_SRC_PORT_HASH,
638 "Use source port in primary hash",
639 "Don't use source port in primary hash"));
640 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
641 decode_boolean_bitfield(flags, WCCP2_SI_DST_PORT_HASH,
643 "Use destination port in primary hash",
644 "Don't use destination port in primary hash"));
645 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
646 decode_boolean_bitfield(flags, WCCP2_SI_PORTS_DEFINED,
649 "Ports not defined"));
650 if (flags & WCCP2_SI_PORTS_DEFINED) {
651 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
652 decode_boolean_bitfield(flags, WCCP2_SI_PORTS_SOURCE,
654 "Ports refer to source port",
655 "Ports refer to destination port"));
657 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
658 decode_boolean_bitfield(flags, WCCP2_SI_SRC_IP_ALT_HASH,
660 "Use source IP address in secondary hash",
661 "Don't use source IP address in secondary hash"));
662 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
663 decode_boolean_bitfield(flags, WCCP2_SI_DST_IP_ALT_HASH,
665 "Use destination IP address in secondary hash",
666 "Don't use destination IP address in secondary hash"));
667 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
668 decode_boolean_bitfield(flags, WCCP2_SI_SRC_PORT_ALT_HASH,
670 "Use source port in secondary hash",
671 "Don't use source port in secondary hash"));
672 proto_tree_add_text(field_tree, tvb, offset, 4, "%s",
673 decode_boolean_bitfield(flags, WCCP2_SI_DST_PORT_ALT_HASH,
675 "Use destination port in secondary hash",
676 "Don't use destination port in secondary hash"));
679 if (flags & WCCP2_SI_PORTS_DEFINED) {
680 for (i = 0; i < 8; i++) {
681 proto_tree_add_text(info_tree, tvb, offset, 2,
682 "Port %d: %u", i, tvb_get_ntohs(tvb, offset));
690 #define ROUTER_ID_INFO_MIN_LEN (8+4+4)
693 dissect_wccp2_router_identity_element(tvbuff_t *tvb, int offset,
696 proto_tree_add_text(tree, tvb, offset, 4,
697 "IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
698 proto_tree_add_text(tree, tvb, offset + 4, 4,
699 "Receive ID: %u", tvb_get_ntohl(tvb, offset + 4));
703 dissect_wccp2_router_identity_info(tvbuff_t *tvb, int offset, int length,
704 proto_tree *info_tree)
706 guint32 n_received_from;
709 proto_tree *element_tree;
711 if (length < ROUTER_ID_INFO_MIN_LEN) {
712 proto_tree_add_text(info_tree, tvb, offset, 0,
713 "Item length is %u, should be >= %u", length,
714 ROUTER_ID_INFO_MIN_LEN);
718 te = proto_tree_add_text(info_tree, tvb, offset, 8,
719 "Router Identity Element: IP address %s",
720 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
721 element_tree = proto_item_add_subtree(te,
722 ett_router_identity_element);
723 dissect_wccp2_router_identity_element(tvb, offset, element_tree);
726 proto_tree_add_text(info_tree, tvb, offset, 4,
727 "Sent To IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
730 n_received_from = tvb_get_ntohl(tvb, offset);
731 proto_tree_add_text(info_tree, tvb, offset, 4,
732 "Number of Received From IP addresses: %u", n_received_from);
735 for (i = 0; i < n_received_from; i++) {
736 proto_tree_add_text(info_tree, tvb, offset, 4,
737 "Received From IP Address %d: %s", i,
738 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
745 #define WC_ID_INFO_LEN (4+4+8*4+4)
748 dissect_wccp2_web_cache_identity_element(tvbuff_t *tvb, int offset,
751 proto_item *bucket_item;
752 proto_tree *bucket_tree;
754 proto_tree *field_tree;
760 proto_tree_add_text(tree, tvb, offset, 4,
761 "Web-Cache IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
764 proto_tree_add_text(tree, tvb, offset, 2,
765 "Hash Revision %u", tvb_get_ntohs(tvb, offset));
768 flags = tvb_get_ntohs(tvb, offset);
769 tf = proto_tree_add_text(tree, tvb, offset, 2,
770 "Flags: 0x%04X (%s)", flags,
772 "Hash information is historical" :
773 "Hash information is current"));
774 field_tree = proto_item_add_subtree(tf, ett_flags);
775 proto_tree_add_text(field_tree, tvb, offset, 2, "%s",
776 decode_boolean_bitfield(flags, 0x8000,
778 "Hash information is historical",
779 "Hash information is current"));
782 bucket_item = proto_tree_add_text(tree, tvb, offset, 8*4,
784 bucket_tree = proto_item_add_subtree(bucket_item, ett_buckets);
785 for (i = 0, n = 0; i < 32; i++) {
786 bucket_info = tvb_get_guint8(tvb, offset);
787 n = wccp_bucket_info(bucket_info, bucket_tree, n, tvb, offset);
791 proto_tree_add_text(tree, tvb, offset, 2,
792 "Assignment Weight: %u", tvb_get_ntohs(tvb, offset));
795 proto_tree_add_text(tree, tvb, offset, 2,
796 "Status: 0x%04X", tvb_get_ntohs(tvb, offset));
803 dissect_wccp2_wc_identity_info(tvbuff_t *tvb, int offset, int length,
804 proto_tree *info_tree)
807 proto_tree *element_tree;
809 if (length != WC_ID_INFO_LEN) {
810 proto_tree_add_text(info_tree, tvb, offset, 0,
811 "Item length is %u, should be %u", length, WC_ID_INFO_LEN);
815 te = proto_tree_add_text(info_tree, tvb, offset, 4+2+2+32+2+2,
816 "Web-Cache Identity Element: IP address %s",
817 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
818 element_tree = proto_item_add_subtree(te, ett_wc_identity_element);
819 if (!dissect_wccp2_web_cache_identity_element(tvb, offset,
821 return FALSE; /* ran out of data */
826 #define ROUTER_VIEW_INFO_MIN_LEN (4+8+4)
829 dissect_wccp2_assignment_key(tvbuff_t *tvb, int offset,
830 proto_tree *info_tree)
832 proto_tree_add_text(info_tree, tvb, offset, 4,
833 "Assignment Key IP Address: %s",
834 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
835 proto_tree_add_text(info_tree, tvb, offset + 4, 4,
836 "Assignment Key Change Number: %u", tvb_get_ntohl(tvb, offset + 4));
840 dissect_wccp2_router_view_info(tvbuff_t *tvb, int offset, int length,
841 proto_tree *info_tree)
844 guint32 n_web_caches;
847 proto_tree *element_tree;
849 if (length < ROUTER_VIEW_INFO_MIN_LEN) {
850 proto_tree_add_text(info_tree, tvb, offset, 0,
851 "Item length is %u, should be >= %u", length,
852 ROUTER_VIEW_INFO_MIN_LEN);
856 proto_tree_add_text(info_tree, tvb, offset, 4,
857 "Member Change Number: %u", tvb_get_ntohl(tvb, offset));
860 dissect_wccp2_assignment_key(tvb, offset, info_tree);
863 n_routers = tvb_get_ntohl(tvb, offset);
864 proto_tree_add_text(info_tree, tvb, offset, 4,
865 "Number of Routers: %u", n_routers);
868 for (i = 0; i < n_routers; i++) {
869 proto_tree_add_text(info_tree, tvb, offset, 4,
870 "Router %d IP Address: %s", i,
871 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
875 n_web_caches = tvb_get_ntohl(tvb, offset);
876 proto_tree_add_text(info_tree, tvb, offset, 4,
877 "Number of Web Caches: %u", n_web_caches);
880 for (i = 0; i < n_web_caches; i++) {
881 te = proto_tree_add_text(info_tree, tvb, offset, WC_ID_INFO_LEN,
882 "Web-Cache Identity Element %d: IP address %s", i,
883 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
884 element_tree = proto_item_add_subtree(te,
885 ett_wc_identity_element);
886 if (!dissect_wccp2_web_cache_identity_element(tvb,
887 offset, element_tree))
888 return FALSE; /* ran out of data */
889 offset += WC_ID_INFO_LEN;
895 #define WC_VIEW_INFO_MIN_LEN (4+4)
898 dissect_wccp2_wc_view_info(tvbuff_t *tvb, int offset, int length,
899 proto_tree *info_tree)
902 guint32 n_web_caches;
905 proto_tree *element_tree;
907 if (length < WC_VIEW_INFO_MIN_LEN) {
908 proto_tree_add_text(info_tree, tvb, offset, 0,
909 "Item length is %u, should be >= %u", length,
910 WC_VIEW_INFO_MIN_LEN);
914 proto_tree_add_text(info_tree, tvb, offset, 4,
915 "Change Number: %u", tvb_get_ntohl(tvb, offset));
918 n_routers = tvb_get_ntohl(tvb, offset);
919 proto_tree_add_text(info_tree, tvb, offset, 4,
920 "Number of Routers: %u", n_routers);
923 for (i = 0; i < n_routers; i++) {
924 te = proto_tree_add_text(info_tree, tvb, offset, 8,
925 "Router %d Identity Element: IP address %s", i,
926 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
927 element_tree = proto_item_add_subtree(te,
928 ett_router_identity_element);
929 dissect_wccp2_router_identity_element(tvb, offset, element_tree);
933 n_web_caches = tvb_get_ntohl(tvb, offset);
934 proto_tree_add_text(info_tree, tvb, offset, 4,
935 "Number of Web Caches: %u", n_web_caches);
938 for (i = 0; i < n_web_caches; i++) {
939 proto_tree_add_text(info_tree, tvb, offset, 4,
940 "Web-Cache %d: IP address %s", i,
941 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
948 #define ASSIGNMENT_INFO_MIN_LEN (8+4)
951 dissect_wccp2_router_assignment_element(tvbuff_t *tvb, int offset,
954 proto_tree_add_text(tree, tvb, offset, 4,
955 "IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
956 proto_tree_add_text(tree, tvb, offset + 4, 4,
957 "Receive ID: %u", tvb_get_ntohl(tvb, offset + 4));
958 proto_tree_add_text(tree, tvb, offset + 8, 4,
959 "Change Number: %u", tvb_get_ntohl(tvb, offset + 8));
963 assignment_bucket_name(guint8 bucket)
967 if (bucket == 0xff) {
971 g_snprintf(cur, 10+1, "%u%s", bucket >> 1,
972 (bucket & 0x01) ? " (Alt)" : "");
978 dissect_wccp2_assignment_info(tvbuff_t *tvb, int offset, int length,
979 proto_tree *info_tree)
982 guint32 n_web_caches;
985 proto_tree *element_tree;
987 if (length < ASSIGNMENT_INFO_MIN_LEN) {
988 proto_tree_add_text(info_tree, tvb, offset, 0,
989 "Item length is %u, should be >= %u", length,
990 ASSIGNMENT_INFO_MIN_LEN);
994 dissect_wccp2_assignment_key(tvb, offset, info_tree);
997 n_routers = tvb_get_ntohl(tvb, offset);
998 proto_tree_add_text(info_tree, tvb, offset, 4,
999 "Number of Routers: %u", n_routers);
1002 for (i = 0; i < n_routers; i++) {
1003 te = proto_tree_add_text(info_tree, tvb, offset, 4,
1004 "Router %d Assignment Element: IP address %s", i,
1005 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1006 element_tree = proto_item_add_subtree(te,
1007 ett_router_assignment_element);
1008 dissect_wccp2_router_assignment_element(tvb, offset,
1013 n_web_caches = tvb_get_ntohl(tvb, offset);
1014 proto_tree_add_text(info_tree, tvb, offset, 4,
1015 "Number of Web Caches: %u", n_web_caches);
1018 for (i = 0; i < n_web_caches; i++) {
1019 proto_tree_add_text(info_tree, tvb, offset, 4,
1020 "Web-Cache %d: IP address %s", i,
1021 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1025 for (i = 0; i < 256; i += 4) {
1026 proto_tree_add_text(info_tree, tvb, offset, 4,
1027 "Buckets %d - %d: %10s %10s %10s %10s",
1029 assignment_bucket_name(tvb_get_guint8(tvb, offset)),
1030 assignment_bucket_name(tvb_get_guint8(tvb, offset+1)),
1031 assignment_bucket_name(tvb_get_guint8(tvb, offset+2)),
1032 assignment_bucket_name(tvb_get_guint8(tvb, offset+3)));
1039 #define QUERY_INFO_LEN (4+4+4+4)
1042 dissect_wccp2_router_query_info(tvbuff_t *tvb, int offset, int length,
1043 proto_tree *info_tree)
1045 if (length != QUERY_INFO_LEN) {
1046 proto_tree_add_text(info_tree, tvb, offset, 0,
1047 "Item length is %u, should be %u", length, QUERY_INFO_LEN);
1051 proto_tree_add_text(info_tree, tvb, offset, 4,
1052 "Router IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1055 proto_tree_add_text(info_tree, tvb, offset, 4,
1056 "Receive ID: %u", tvb_get_ntohl(tvb, offset));
1059 proto_tree_add_text(info_tree, tvb, offset, 4,
1060 "Sent To IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1063 proto_tree_add_text(info_tree, tvb, offset, 4,
1064 "Target IP Address: %s", ip_to_str(tvb_get_ptr(tvb, offset, 4)));
1070 #define WCCP2_FORWARDING_METHOD 0x01
1071 #define WCCP2_ASSIGNMENT_METHOD 0x02
1072 #define WCCP2_PACKET_RETURN_METHOD 0x03
1074 static const value_string capability_type_vals[] = {
1075 { WCCP2_FORWARDING_METHOD, "Forwarding Method" },
1076 { WCCP2_ASSIGNMENT_METHOD, "Assignment Method" },
1077 { WCCP2_PACKET_RETURN_METHOD, "Return Method" },
1081 #define WCCP2_FORWARDING_METHOD_GRE 0x00000001
1082 #define WCCP2_FORWARDING_METHOD_L2 0x00000002
1084 static const capability_flag forwarding_method_flags[] = {
1085 { WCCP2_FORWARDING_METHOD_GRE,
1086 "IP-GRE", "GRE-encapsulated" },
1087 { WCCP2_FORWARDING_METHOD_L2,
1088 "L2", "L2 rewrite" },
1093 #define WCCP2_ASSIGNMENT_METHOD_HASH 0x00000001
1094 #define WCCP2_ASSIGNMENT_METHOD_MASK 0x00000002
1096 static const capability_flag assignment_method_flags[] = {
1097 { WCCP2_ASSIGNMENT_METHOD_HASH, "Hash", "Hash" },
1098 { WCCP2_ASSIGNMENT_METHOD_MASK, "Mask", "Mask" },
1102 #define WCCP2_PACKET_RETURN_METHOD_GRE 0x00000001
1103 #define WCCP2_PACKET_RETURN_METHOD_L2 0x00000002
1105 static const capability_flag packet_return_method_flags[] = {
1106 { WCCP2_PACKET_RETURN_METHOD_GRE,
1107 "IP-GRE", "GRE-encapsulated" },
1108 { WCCP2_PACKET_RETURN_METHOD_L2,
1109 "L2", "L2 rewrite" },
1115 dissect_wccp2_capability_info(tvbuff_t *tvb, int offset, int length,
1116 proto_tree *info_tree)
1118 guint16 capability_type;
1119 guint16 capability_val_len;
1122 proto_tree *element_tree;
1124 for (curr_offset = offset; curr_offset < (length + offset);
1125 curr_offset += (capability_val_len + 4)) {
1126 capability_type = tvb_get_ntohs(tvb, curr_offset);
1127 capability_val_len = tvb_get_ntohs(tvb, curr_offset + 2);
1128 te = proto_tree_add_text(info_tree, tvb, curr_offset,
1129 capability_val_len + 4, "%s",
1130 val_to_str(capability_type,
1131 capability_type_vals, "Unknown Capability Element (0x%08X)"));
1132 element_tree = proto_item_add_subtree(te,
1133 ett_capability_element);
1135 proto_tree_add_text(element_tree, tvb, curr_offset, 2,
1137 val_to_str(capability_type,
1138 capability_type_vals, "Unknown (0x%08X)"));
1140 if (capability_val_len < 4) {
1141 proto_tree_add_text(element_tree, tvb, curr_offset+2, 2,
1142 "Value Length: %u (illegal, must be >= 4)",
1143 capability_val_len);
1146 proto_tree_add_text(element_tree, tvb, curr_offset+2, 2,
1147 "Value Length: %u", capability_val_len);
1149 switch (capability_type) {
1151 case WCCP2_FORWARDING_METHOD:
1152 dissect_32_bit_capability_flags(tvb, curr_offset,
1154 ett_capability_forwarding_method,
1155 forwarding_method_flags, element_tree);
1158 case WCCP2_ASSIGNMENT_METHOD:
1159 dissect_32_bit_capability_flags(tvb, curr_offset,
1161 ett_capability_assignment_method,
1162 assignment_method_flags, element_tree);
1165 case WCCP2_PACKET_RETURN_METHOD:
1166 dissect_32_bit_capability_flags(tvb, curr_offset,
1168 ett_capability_return_method,
1169 packet_return_method_flags, element_tree);
1173 proto_tree_add_text(element_tree, tvb,
1174 curr_offset+4, capability_val_len,
1176 tvb_bytes_to_str(tvb, curr_offset+4,
1177 capability_val_len));
1186 dissect_32_bit_capability_flags(tvbuff_t *tvb, int curr_offset,
1187 guint16 capability_val_len, gint ett, const capability_flag *flags,
1188 proto_tree *element_tree)
1190 guint32 capability_val;
1192 proto_tree *method_tree;
1196 size_t returned_length, str_index = 0;
1199 if (capability_val_len != 4) {
1200 proto_tree_add_text(element_tree, tvb,
1201 curr_offset+4, capability_val_len,
1202 "Illegal length (must be 4)");
1206 capability_val = tvb_get_ntohl(tvb, curr_offset + 4);
1207 #define FLAGS_STRING_LEN (128+1)
1208 flags_string=ep_alloc(FLAGS_STRING_LEN);
1209 flags_string[0] = 0;
1210 for (i = 0; flags[i].short_name != NULL; i++) {
1211 if (capability_val & flags[i].value) {
1212 if (str_index != 0) {
1213 returned_length = g_snprintf(&flags_string[str_index],
1214 FLAGS_STRING_LEN-str_index, ",");
1215 str_index += MIN(returned_length, FLAGS_STRING_LEN-str_index);
1217 returned_length = g_snprintf(&flags_string[str_index],
1218 FLAGS_STRING_LEN-str_index, "%s", flags[i].short_name);
1219 str_index += MIN(returned_length, FLAGS_STRING_LEN-str_index);
1222 tm = proto_tree_add_text(element_tree, tvb, curr_offset+4, 4,
1223 "Value: 0x%08X (%s)", capability_val, flags_string);
1225 method_tree = proto_item_add_subtree(tm, ett);
1226 #define BUF_SIZE 1024
1227 buf=ep_alloc(BUF_SIZE);
1229 for (i = 0; flags[i].long_name != NULL; i++) {
1230 p = decode_bitfield_value(buf, capability_val,
1231 flags[i].value, 32);
1232 str_index = MIN(p-buf, BUF_SIZE);
1233 returned_length = g_snprintf(&flags_string[str_index], BUF_SIZE-str_index,
1234 "%s: %s", flags[i].long_name,
1235 (capability_val & flags[i].value)?
1239 str_index += MIN(returned_length, BUF_SIZE-str_index);
1240 proto_tree_add_text(method_tree, tvb, curr_offset+4, 4,
1246 proto_register_wccp(void)
1248 static hf_register_info hf[] = {
1249 { &hf_wccp_message_type,
1250 { "WCCP Message Type", "wccp.message", FT_UINT32, BASE_DEC, VALS(wccp_type_vals), 0x0,
1251 "The WCCP message that was sent", HFILL }
1254 { "WCCP Version", "wccp.version", FT_UINT32, BASE_HEX, VALS(wccp_version_val), 0x0,
1255 "The WCCP version", HFILL }
1257 { &hf_hash_revision,
1258 { "Hash Revision", "wccp.hash_revision", FT_UINT32, BASE_DEC, 0x0, 0x0,
1259 "The cache hash revision", HFILL }
1262 { "Change Number", "wccp.change_num", FT_UINT32, BASE_DEC, 0x0, 0x0,
1263 "The Web-Cache list entry change number", HFILL }
1266 { "Received ID", "wccp.recvd_id", FT_UINT32, BASE_DEC, 0x0, 0x0,
1267 "The number of I_SEE_YOU's that have been sent", HFILL }
1270 { "Web Cache IP address", "wccp.cache_ip", FT_IPv4, BASE_NONE, NULL, 0x0,
1271 "The IP address of a Web cache", HFILL }
1274 static gint *ett[] = {
1283 &ett_router_identity_element,
1284 &ett_router_identity_info,
1285 &ett_wc_identity_element,
1286 &ett_wc_identity_info,
1287 &ett_router_view_info,
1290 &ett_router_assignment_element,
1291 &ett_router_assignment_info,
1292 &ett_capabilities_info,
1293 &ett_capability_element,
1294 &ett_capability_forwarding_method,
1295 &ett_capability_assignment_method,
1296 &ett_capability_return_method,
1300 proto_wccp = proto_register_protocol("Web Cache Coordination Protocol",
1302 proto_register_field_array(proto_wccp, hf, array_length(hf));
1303 proto_register_subtree_array(ett, array_length(ett));
1307 proto_reg_handoff_wccp(void)
1309 dissector_handle_t wccp_handle;
1311 wccp_handle = create_dissector_handle(dissect_wccp, proto_wccp);
1312 dissector_add("udp.port", UDP_PORT_WCCP, wccp_handle);