2 * Routines for Distributed Checksum Clearinghouse packet dissection
3 * DCC Home: http://www.rhyolite.com/anti-spam/dcc/
5 * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
7 * $Id: packet-dccp.c,v 1.10 2003/01/31 03:17:45 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * Copied from packet-tftp.c
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #include <epan/packet.h>
40 #include <packet-dccp.h>
42 static int proto_dccp = -1;
43 static int hf_dccp_len = -1;
44 static int hf_dccp_pkt_vers = -1;
45 static int hf_dccp_op = -1;
46 static int hf_dccp_clientid = -1;
47 static int hf_dccp_opnums_host = -1;
48 static int hf_dccp_opnums_pid = -1;
49 static int hf_dccp_opnums_report = -1;
50 static int hf_dccp_opnums_retrans = -1;
52 static int hf_dccp_signature = -1;
53 static int hf_dccp_max_pkt_vers = -1;
54 static int hf_dccp_qdelay_ms = -1;
55 static int hf_dccp_brand = -1;
57 static int hf_dccp_ck_type = -1;
58 static int hf_dccp_ck_len = -1;
59 static int hf_dccp_ck_sum = -1;
61 static int hf_dccp_date = -1;
63 static int hf_dccp_target = -1;
65 static int hf_dccp_adminop = -1;
66 static int hf_dccp_adminval = -1;
67 static int hf_dccp_floodop = -1;
68 static int hf_dccp_trace = -1;
69 static int hf_dccp_trace_admin = -1;
70 static int hf_dccp_trace_anon = -1;
71 static int hf_dccp_trace_client = -1;
72 static int hf_dccp_trace_rlim = -1;
73 static int hf_dccp_trace_query = -1;
74 static int hf_dccp_trace_ridc = -1;
75 static int hf_dccp_trace_flood = -1;
77 static gint ett_dccp = -1;
78 static gint ett_dccp_opnums = -1;
79 static gint ett_dccp_op = -1;
80 static gint ett_dccp_ck = -1;
81 static gint ett_dccp_trace = -1;
84 #define D_SIGNATURE() \
85 proto_tree_add_item(dccp_optree, hf_dccp_signature, tvb, \
86 offset, sizeof(DCC_SIGNATURE), FALSE); \
87 offset += sizeof(DCC_SIGNATURE);
89 #define D_LABEL(label,len) \
90 proto_tree_add_text(dccp_optree, tvb, offset, len, label); \
93 #define D_TEXT(label, endpad) { \
94 int next_offset,linelen,left; \
96 while (tvb_offset_exists(tvb, offset+endpad)) { \
97 left = tvb_length_remaining(tvb,offset) - endpad; \
98 linelen = tvb_find_line_end(tvb, offset, left, &next_offset, \
100 line = tvb_get_ptr(tvb, offset, linelen); \
101 proto_tree_add_text(dccp_optree, tvb, offset, \
102 next_offset - offset, "%s: %s", \
103 label, tvb_format_text(tvb, offset, next_offset - offset)); \
104 offset = next_offset; \
110 proto_tree_add_item_hidden(dccp_tree, hf_dccp_target, tvb, \
111 offset, sizeof(DCC_TGTS), FALSE); \
112 proto_tree_add_text(dccp_optree, tvb, offset, sizeof(DCC_TGTS), \
113 val_to_str(tvb_get_ntohl(tvb,offset), dccp_target_vals, "Targets (%u)")); \
114 offset += sizeof(DCC_TGTS); \
119 ts.secs = tvb_get_ntohl(tvb,offset); \
120 proto_tree_add_time(dccp_optree, hf_dccp_date, tvb, offset, 4, &ts); \
125 #define D_CHECKSUM() { \
126 proto_tree *cktree, *ti; \
127 ti = proto_tree_add_text(dccp_optree, tvb, offset, sizeof(DCC_CK), \
128 "Checksum - %s", val_to_str(tvb_get_guint8(tvb,offset), \
130 "Unknown Type: %u")); \
131 cktree = proto_item_add_subtree(ti, ett_dccp_ck); \
132 proto_tree_add_item(cktree, hf_dccp_ck_type, tvb, offset, 1, FALSE); \
134 proto_tree_add_item(cktree, hf_dccp_ck_len, tvb, offset, 1, FALSE); \
136 proto_tree_add_item(cktree, hf_dccp_ck_sum, tvb, offset, \
137 sizeof(DCC_SUM), FALSE); \
138 offset += sizeof(DCC_SUM); \
142 /* Lookup string tables */
143 static const value_string dccp_op_vals[] = {
144 {DCC_OP_INVALID, "Invalid Op"},
145 {DCC_OP_NOP, "No-Op"},
146 {DCC_OP_REPORT, "Report and Query"},
147 {DCC_OP_QUERY, "Query"},
148 {DCC_OP_QUERY_RESP, "Server Response"},
149 {DCC_OP_ADMN, "Admin"},
151 {DCC_OP_ERROR, "Server Failing"},
152 {DCC_OP_DELETE, "Delete Checksum(s)"},
156 static const value_string dccp_cktype_vals[] = {
157 {DCC_CK_INVALID, "Invalid/Deleted from DB when seen"},
158 {DCC_CK_IP, "MD5 of binary source IPv6 address"},
159 {DCC_CK_ENV_FROM, "MD5 of envelope Mail From value"},
160 {DCC_CK_FROM, "MD5 of header From: line"},
161 {DCC_CK_SUB, "MD5 of substitute header line"},
162 {DCC_CK_MESSAGE_ID, "MD5 of header Message-ID: line"},
163 {DCC_CK_RECEIVED, "MD5 of last header Received: line"},
164 {DCC_CK_BODY, "MD5 of body"},
165 {DCC_CK_FUZ1, "MD5 of filtered body - FUZ1"},
166 {DCC_CK_FUZ2, "MD5 of filtered body - FUZ2"},
167 {DCC_CK_FUZ3, "MD5 of filtered body - FUZ3"},
168 {DCC_CK_FUZ4, "MD5 of filtered body - FUZ4"},
169 {DCC_CK_SRVR_ID, "hostname for server-ID check "},
170 {DCC_CK_ENV_TO, "MD5 of envelope Rcpt To value"},
174 static const value_string dccp_adminop_vals[] = {
175 {DCC_AOP_OK, "Never sent"},
176 {DCC_AOP_STOP, "Stop Gracefully"},
177 {DCC_AOP_NEW_IDS, "Load keys and client IDs"},
178 {DCC_AOP_FLOD, "Flood control"},
179 {DCC_AOP_DB_UNLOCK, "Start Switch to new database"},
180 {DCC_AOP_DB_NEW, "Finish Switch to new database"},
181 {DCC_AOP_STATS, "Return counters"},
182 {DCC_AOP_STATS_CLEAR, "Return and zero counters"},
183 {DCC_AOP_TRACE_ON, "Enable tracing"},
184 {DCC_AOP_TRACE_OFF, "Disable tracing"},
185 {DCC_AOP_CUR_CLIENTS, "List clients"},
189 static const value_string dccp_target_vals[] = {
190 {DCC_TGTS_TOO_MANY, "Targets (>= 16777200)"},
191 {DCC_TGTS_OK, "Certified not spam"},
192 {DCC_TGTS_OK2, "Half certified not spam"},
193 {DCC_TGTS_DEL, "Deleted checksum"},
194 {DCC_TGTS_INVALID, "Invalid"},
198 static const value_string dccp_floodop_vals[] = {
199 {DCC_AOP_FLOD_CHECK, "Check"},
200 {DCC_AOP_FLOD_SHUTDOWN, "Shutdown"},
201 {DCC_AOP_FLOD_HALT, "Halt"},
202 {DCC_AOP_FLOD_RESUME, "Resume"},
203 {DCC_AOP_FLOD_REWIND, "Rewind"},
204 {DCC_AOP_FLOD_LIST, "List"},
205 {DCC_AOP_FLOD_STATS, "Stats"},
206 {DCC_AOP_FLOD_STATS_CLEAR, "Clear Stats"},
211 dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
213 proto_tree *dccp_tree, *dccp_optree, *dccp_opnumtree, *ti;
214 proto_tree *dccp_tracetree;
216 int client_is_le = 0;
220 if (pinfo->srcport != DCC_PORT && pinfo->destport != DCC_PORT) {
221 /* Not the right port - not a DCC packet. */
225 /* get at least a full packet structure */
226 if ( !tvb_bytes_exist(tvb, 0, sizeof(DCC_HDR)) ) {
227 /* Doesn't have enough bytes to contain packet header. */
231 if (check_col(pinfo->cinfo, COL_PROTOCOL))
232 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DCCP");
235 is_response = pinfo->srcport == DCC_PORT;
237 if (check_col(pinfo->cinfo, COL_INFO)) {
238 col_add_fstr(pinfo->cinfo, COL_INFO,
240 is_response ? "Response" : "Request",
241 val_to_str(tvb_get_guint8(tvb, offset+3),
242 dccp_op_vals, "Unknown Op: %u")
247 ti = proto_tree_add_item(tree, proto_dccp, tvb, offset, -1,
249 dccp_tree = proto_item_add_subtree(ti, ett_dccp);
251 proto_tree_add_item(dccp_tree, hf_dccp_len, tvb,
254 if ( !tvb_bytes_exist(tvb, 0, tvb_get_ntohs(tvb, offset))) {
255 /* Doesn't have number of bytes that header claims. */
256 proto_tree_add_text(dccp_tree, tvb, offset, 2, "Error - packet is shorter than header claims!");
260 proto_tree_add_item(dccp_tree, hf_dccp_pkt_vers, tvb,
264 op = tvb_get_guint8(tvb, offset);
265 proto_tree_add_item(dccp_tree, hf_dccp_op, tvb,
269 proto_tree_add_item(dccp_tree, hf_dccp_clientid, tvb,
273 ti = proto_tree_add_text(dccp_tree, tvb, offset, -1, "Operation Numbers (Opaque to Server)");
274 dccp_opnumtree = proto_item_add_subtree(ti, ett_dccp_opnums);
276 /* Note - these are indeterminate - they are sortof considered opaque to the client */
277 /* Make some attempt to figure out if this data is little endian, not guaranteed to be
278 correct if connection went through a firewall or similar. */
280 /* Very hokey check - if all three of pid/report/retrans look like little-endian
281 numbers, host is probably little endian. Probably innacurate on super-heavily-used
282 DCC clients though. This should be good enough for now. */
283 client_is_le = ( (tvb_get_guint8(tvb, offset+4) | tvb_get_guint8(tvb, offset+4)) &&
284 (tvb_get_guint8(tvb, offset+8) | tvb_get_guint8(tvb, offset+9)) &&
285 (tvb_get_guint8(tvb, offset+12) | tvb_get_guint8(tvb, offset+13)) );
287 proto_tree_add_item(dccp_opnumtree, hf_dccp_opnums_host, tvb,
288 offset, 4, client_is_le);
291 proto_tree_add_item(dccp_opnumtree, hf_dccp_opnums_pid, tvb,
292 offset, 4, client_is_le);
295 proto_tree_add_item(dccp_opnumtree, hf_dccp_opnums_report, tvb,
296 offset, 4, client_is_le);
299 proto_tree_add_item(dccp_opnumtree, hf_dccp_opnums_retrans, tvb,
300 offset, 4, client_is_le);
303 ti = proto_tree_add_text(dccp_tree, tvb, offset, -1, "Operation: %s",
304 val_to_str(op, dccp_op_vals, "Unknown Op: %u"));
305 dccp_optree = proto_item_add_subtree(ti, ett_dccp_op);
314 for (i=0; i<=DCC_QUERY_MAX &&
315 tvb_bytes_exist(tvb, offset+sizeof(DCC_SIGNATURE),1); i++)
322 case DCC_OP_QUERY_RESP:
323 for (i=0; i<=DCC_QUERY_MAX &&
324 tvb_bytes_exist(tvb, offset+sizeof(DCC_SIGNATURE),1); i++)
334 int left = tvb_length_remaining(tvb, offset) -
335 sizeof(DCC_SIGNATURE);
336 if ( left == sizeof(DCC_ADMN_RESP_CLIENTS) )
339 D_LABEL("Id", sizeof(DCC_CLNT_ID));
340 D_LABEL("Last Used", 4);
341 D_LABEL("Requests", 4);
345 D_TEXT("Response Text", sizeof(DCC_SIGNATURE));
355 aop = tvb_get_guint8(tvb, offset+4);
356 proto_tree_add_item(dccp_optree, hf_dccp_adminop, tvb, offset+4,
358 if (check_col(pinfo->cinfo, COL_INFO)) {
359 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
360 val_to_str(tvb_get_guint8(tvb,offset+4),
361 dccp_adminop_vals, "Unknown (%u)"));
364 if (aop == DCC_AOP_TRACE_ON || aop == DCC_AOP_TRACE_OFF )
366 ti = proto_tree_add_item(dccp_optree, hf_dccp_trace, tvb, offset,
368 dccp_tracetree = proto_item_add_subtree(ti, ett_dccp_trace);
369 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_admin, tvb, offset, 4, FALSE);
370 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_anon, tvb, offset, 4, FALSE);
371 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_client, tvb, offset, 4, FALSE);
372 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_rlim, tvb, offset, 4, FALSE);
373 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_query, tvb, offset, 4, FALSE);
374 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_ridc, tvb, offset, 4, FALSE);
375 proto_tree_add_item(dccp_tracetree, hf_dccp_trace_flood, tvb, offset, 4, FALSE);
377 else if ( aop == DCC_AOP_FLOD )
379 proto_tree_add_item(dccp_optree, hf_dccp_floodop,
380 tvb, offset, 4, FALSE);
381 if (check_col(pinfo->cinfo, COL_INFO)) {
382 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
383 val_to_str(tvb_get_ntohl(tvb,offset),
384 dccp_floodop_vals, "Unknown (%u)"));
389 proto_tree_add_item(dccp_optree, hf_dccp_adminval,
390 tvb, offset, 4, FALSE);
394 offset += 1; /* admin op we did in reverse order */
401 proto_tree_add_item(dccp_optree, hf_dccp_max_pkt_vers, tvb,
405 D_LABEL("Unused", 1);
407 proto_tree_add_item(dccp_optree, hf_dccp_qdelay_ms, tvb,
411 proto_tree_add_item(dccp_optree, hf_dccp_brand, tvb,
412 offset, sizeof(DCC_BRAND), FALSE);
413 offset += sizeof(DCC_BRAND);
428 proto_register_dccp(void)
430 static hf_register_info hf[] = {
432 "Packet Length", "dccp.len", FT_UINT16, BASE_DEC,
433 NULL, 0, "Packet Length", HFILL }},
435 { &hf_dccp_pkt_vers, {
436 "Packet Version", "dccp.pkt_vers", FT_UINT16, BASE_DEC,
437 NULL, 0, "Packet Version", HFILL }},
440 "Operation Type", "dccp.op", FT_UINT8, BASE_DEC,
441 VALS(dccp_op_vals), 0, "Operation Type", HFILL }},
443 { &hf_dccp_clientid, {
444 "Client ID", "dccp.clientid", FT_UINT32, BASE_DEC,
445 NULL, 0, "Client ID", HFILL }},
447 { &hf_dccp_opnums_host, {
448 "Host", "dccp.opnums.host", FT_IPv4, BASE_DEC,
449 NULL, 0, "Host", HFILL }},
451 { &hf_dccp_opnums_pid, {
452 "Process ID", "dccp.opnums.pid", FT_UINT32, BASE_DEC,
453 NULL, 0, "Process ID", HFILL }},
455 { &hf_dccp_opnums_report, {
456 "Report", "dccp.opnums.report", FT_UINT32, BASE_DEC,
457 NULL, 0, "Report", HFILL }},
459 { &hf_dccp_opnums_retrans, {
460 "Retransmission", "dccp.opnums.retrans", FT_UINT32, BASE_DEC,
461 NULL, 0, "Retransmission", HFILL }},
463 { &hf_dccp_signature, {
464 "Signature", "dccp.signature", FT_BYTES, BASE_HEX,
465 NULL, 0, "Signature", HFILL }},
467 { &hf_dccp_max_pkt_vers, {
468 "Maximum Packet Version", "dccp.max_pkt_vers", FT_UINT8, BASE_DEC,
469 NULL, 0, "Maximum Packet Version", HFILL }},
471 { &hf_dccp_qdelay_ms, {
472 "Client Delay", "dccp.qdelay_ms", FT_UINT16, BASE_DEC,
473 NULL, 0, "Client Delay", HFILL }},
476 "Server Brand", "dccp.brand", FT_STRING, BASE_DEC,
477 NULL, 0, "Server Brand", HFILL }},
479 { &hf_dccp_ck_type, {
480 "Type", "dccp.checksum.type", FT_UINT8, BASE_DEC,
481 VALS(dccp_cktype_vals), 0, "Checksum Type", HFILL }},
484 "Length", "dccp.checksum.length", FT_UINT8, BASE_DEC,
485 NULL, 0, "Checksum Length", HFILL }},
488 "Sum", "dccp.checksum.sum", FT_BYTES, BASE_HEX,
489 NULL, 0, "Checksum", HFILL }},
492 "Target", "dccp.target", FT_UINT32, BASE_HEX,
493 NULL, 0, "Target", HFILL }},
496 "Date", "dccp.date", FT_ABSOLUTE_TIME, BASE_DEC,
497 NULL, 0, "Date", HFILL }},
499 { &hf_dccp_adminop, {
500 "Admin Op", "dccp.adminop", FT_UINT8, BASE_DEC,
501 VALS(dccp_adminop_vals), 0, "Admin Op", HFILL }},
503 { &hf_dccp_adminval, {
504 "Admin Value", "dccp.adminval", FT_UINT32, BASE_DEC,
505 NULL, 0, "Admin Value", HFILL }},
508 "Trace Bits", "dccp.trace", FT_UINT32, BASE_HEX,
509 NULL, 0, "Trace Bits", HFILL }},
511 { &hf_dccp_trace_admin, {
512 "Admin Requests", "dccp.trace.admin", FT_BOOLEAN, 32,
513 NULL, 0x00000001, "Admin Requests", HFILL }},
515 { &hf_dccp_trace_anon, {
516 "Anonymous Requests", "dccp.trace.anon", FT_BOOLEAN, 32,
517 NULL, 0x00000002, "Anonymous Requests", HFILL }},
519 { &hf_dccp_trace_client, {
520 "Authenticated Client Requests", "dccp.trace.client", FT_BOOLEAN, 32,
521 NULL, 0x00000004, "Authenticated Client Requests", HFILL }},
523 { &hf_dccp_trace_rlim, {
524 "Rate-Limited Requests", "dccp.trace.rlim", FT_BOOLEAN, 32,
525 NULL, 0x00000008, "Rate-Limited Requests", HFILL }},
527 { &hf_dccp_trace_query, {
528 "Queries and Reports", "dccp.trace.query", FT_BOOLEAN, 32,
529 NULL, 0x00000010, "Queries and Reports", HFILL }},
531 { &hf_dccp_trace_ridc, {
532 "RID Cache Messages", "dccp.trace.ridc", FT_BOOLEAN, 32,
533 NULL, 0x00000020, "RID Cache Messages", HFILL }},
535 { &hf_dccp_trace_flood, {
536 "Input/Output Flooding", "dccp.trace.flood", FT_BOOLEAN, 32,
537 NULL, 0x00000040, "Input/Output Flooding", HFILL }},
539 { &hf_dccp_floodop, {
540 "Flood Control Operation", "dccp.floodop", FT_UINT32, BASE_DEC,
541 VALS(dccp_floodop_vals), 0, "Flood Control Operation", HFILL }},
544 static gint *ett[] = {
552 proto_dccp = proto_register_protocol("Distributed Checksum Clearinghouse Prototocl",
555 proto_register_field_array(proto_dccp, hf, array_length(hf));
557 proto_register_subtree_array(ett, array_length(ett));
561 proto_reg_handoff_dccp(void)
563 heur_dissector_add("udp", dissect_dccp, proto_dccp);