2 * Routines for KDP (Kontiki Delivery Protocol) packet disassembly
6 * Copyright (c) 2008 by Kontiki Inc.
7 * Wade Hennessey <wade@kontiki.com>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1999 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/packet.h>
35 #define KDP_PORT 19948
36 #define BUFFER_SIZE 80
37 static int proto_kdp = -1;
38 static gint ett_kdp = -1;
39 static gint ett_kdp_flags = -1;
41 static int hf_kdp_version = -1;
42 static int hf_kdp_headerlen = -1;
43 static int hf_kdp_flags = -1;
44 static int hf_kdp_errors = -1;
45 static int hf_kdp_destflowid = -1;
46 static int hf_kdp_srcflowid = -1;
47 static int hf_kdp_sequence = -1;
48 static int hf_kdp_ack = -1;
49 static int hf_kdp_maxsegmentsize = -1;
50 static int hf_kdp_optionnumber = -1;
51 static int hf_kdp_optionlen = -1;
52 static int hf_kdp_option1 = -1;
53 static int hf_kdp_option2 = -1;
54 static int hf_kdp_fragment = -1;
55 static int hf_kdp_fragtotal = -1;
56 static int hf_kdp_body = -1;
57 static int hf_kdp_xml_body = -1;
59 #define KDP_DROP_FLAG (1 << 0)
60 #define KDP_SYN_FLAG (1 << 1)
61 #define KDP_ACK_FLAG (1 << 2)
62 #define KDP_RST_FLAG (1 << 3)
63 #define KDP_BCST_FLAG (1 << 4)
64 #define KDP_DUP_FLAG (1 << 5)
66 static int hf_kdp_drop_flag = -1;
67 static int hf_kdp_syn_flag = -1;
68 static int hf_kdp_ack_flag = -1;
69 static int hf_kdp_rst_flag = -1;
70 static int hf_kdp_bcst_flag = -1;
71 static int hf_kdp_dup_flag = -1;
73 static void dissect_kdp(tvbuff_t *tvb,
78 guint8 header_len = 0;
79 guint8 packet_flags = 0;
80 guint8 packet_errors = 0;
81 guint32 sequence_number = G_MAXUINT32;
82 guint32 ack_number = G_MAXUINT32;
83 guint32 src_flowid = G_MAXUINT32;
86 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
87 col_set_str(pinfo->cinfo, COL_PROTOCOL, "KDP");
89 if (check_col(pinfo->cinfo, COL_INFO)) {
90 col_clear(pinfo->cinfo, COL_INFO);
94 proto_tree *kdp_tree, *flags_tree;
99 ti = proto_tree_add_item(tree, proto_kdp, tvb, 0, -1, FALSE);
100 kdp_tree = proto_item_add_subtree(ti, ett_kdp);
102 version = tvb_get_guint8(tvb, 0);
104 /* Version other than 2 is really SDDP in UDP */
105 proto_tree_add_item(kdp_tree, hf_kdp_version, tvb, 0, 1, FALSE);
106 proto_tree_add_item(kdp_tree, hf_kdp_xml_body, tvb, 0, -1, FALSE);
108 header_len = tvb_get_guint8(tvb, 1) * 4;
109 body_len = tvb_reported_length(tvb);
110 if (header_len > body_len) {
111 body_len = 0; /* malformed packet */
113 body_len = body_len - header_len;
115 packet_flags = tvb_get_guint8(tvb, 2);
116 packet_errors = tvb_get_guint8(tvb, 3);
117 proto_tree_add_item(kdp_tree, hf_kdp_version, tvb, 0, 1, FALSE);
118 proto_tree_add_item(kdp_tree, hf_kdp_headerlen, tvb, 1, 1, FALSE);
119 ti = proto_tree_add_item(kdp_tree, hf_kdp_flags, tvb, 2, 1, FALSE);
120 flags_tree = proto_item_add_subtree(ti, ett_kdp_flags);
122 proto_tree_add_item(flags_tree, hf_kdp_drop_flag, tvb, 2, 1, FALSE);
123 proto_tree_add_item(flags_tree, hf_kdp_syn_flag, tvb, 2, 1, FALSE);
124 proto_tree_add_item(flags_tree, hf_kdp_ack_flag, tvb, 2, 1, FALSE);
125 proto_tree_add_item(flags_tree, hf_kdp_rst_flag, tvb, 2, 1, FALSE);
126 proto_tree_add_item(flags_tree, hf_kdp_bcst_flag, tvb, 2, 1, FALSE);
127 proto_tree_add_item(flags_tree, hf_kdp_dup_flag, tvb, 2, 1, FALSE);
129 proto_tree_add_item(kdp_tree, hf_kdp_errors, tvb, 3, 1, FALSE);
131 if (header_len > 4) {
133 if (packet_flags & KDP_ACK_FLAG) {
134 proto_tree_add_item(kdp_tree, hf_kdp_destflowid, tvb, offset, 4, FALSE);
138 if (packet_flags & (KDP_SYN_FLAG | KDP_BCST_FLAG)) {
139 proto_tree_add_item(kdp_tree, hf_kdp_srcflowid, tvb, offset, 4, FALSE);
140 src_flowid = tvb_get_ntohl(tvb, offset);
144 proto_tree_add_item(kdp_tree, hf_kdp_sequence, tvb, offset, 4, FALSE);
145 sequence_number = tvb_get_ntohl(tvb, offset);
148 if (packet_flags & KDP_ACK_FLAG) {
149 proto_tree_add_item(kdp_tree, hf_kdp_ack, tvb, offset, 4, FALSE);
150 ack_number = tvb_get_ntohl(tvb, offset);
153 if (packet_flags & KDP_SYN_FLAG) {
154 proto_tree_add_item(kdp_tree,
155 hf_kdp_maxsegmentsize, tvb, offset, 4, FALSE);
159 while (offset < ((body_len > 0) ? header_len - 4 : header_len)) {
160 guint8 option_number;
162 option_number = tvb_get_guint8(tvb, offset);
164 proto_tree_add_item(kdp_tree,
165 hf_kdp_optionnumber, tvb, offset, 1, FALSE);
167 if (option_number > 0) {
168 proto_tree_add_item(kdp_tree,
169 hf_kdp_optionlen, tvb, offset, 1, FALSE);
173 switch (option_number) {
177 proto_tree_add_item(kdp_tree, hf_kdp_option1, tvb, offset, 2, FALSE);
181 proto_tree_add_item(kdp_tree, hf_kdp_option2, tvb, offset, 2, FALSE);
184 default: body_len = 0; /* Invalid option - ignore rest of packet */
189 proto_tree_add_item(kdp_tree, hf_kdp_fragment, tvb, offset, 2, FALSE);
192 proto_tree_add_item(kdp_tree, hf_kdp_fragtotal, tvb, offset, 2, FALSE);
195 proto_tree_add_item(kdp_tree, hf_kdp_body, tvb, offset, -1, FALSE);
200 /* Now that we know sequence number and optional ack number, we can
201 print more detailed summary info */
202 if (check_col(pinfo->cinfo, COL_INFO)) {
204 col_add_fstr(pinfo->cinfo, COL_INFO, "SDDP message");
206 char ack_string[BUFFER_SIZE];
207 char seq_num_string[BUFFER_SIZE];
208 char src_flowid_string[BUFFER_SIZE];
210 if (packet_flags & KDP_ACK_FLAG) {
211 g_snprintf(ack_string, sizeof(ack_string), "ACK=%x ", ack_number);
213 ack_string[0] = '\0';
215 if (header_len > 4) {
216 g_snprintf(seq_num_string, sizeof(seq_num_string), "SEQ=%x ", sequence_number);
218 seq_num_string[0] = '\0';
220 if (packet_flags & (KDP_SYN_FLAG | KDP_BCST_FLAG)) {
221 g_snprintf(src_flowid_string, sizeof(src_flowid_string), "SRC_FLOWID=%x ", src_flowid);
223 src_flowid_string[0] = '\0';
225 col_add_fstr(pinfo->cinfo, COL_INFO, "%s%s%s%s%s%s%s%serrors=%d",
226 ((packet_flags & KDP_DROP_FLAG) ? "DROP " : ""),
227 ((packet_flags & KDP_SYN_FLAG) ? "SYN " : ""),
228 ((packet_flags & KDP_RST_FLAG) ? "RST " : ""),
229 ((packet_flags & KDP_BCST_FLAG) ? "BCST " : ""),
230 ((packet_flags & KDP_DUP_FLAG) ? "DUP " : ""),
239 void proto_register_kdp(void) {
241 static hf_register_info hf[] = {
243 {"KDP version", "kdp.version",
244 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}
247 {"KDP header len", "kdp.headerlen",
248 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}
251 {"KDP flags", "kdp.flags",
252 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}
255 {"KDP DROP Flag", "kdp.flags.drop",
256 FT_BOOLEAN, 8, NULL, KDP_DROP_FLAG, NULL, HFILL}
259 {"KDP SYN Flag", "kdp.flags.syn",
260 FT_BOOLEAN, 8, NULL, KDP_SYN_FLAG, NULL, HFILL}
263 {"KDP ACK Flag", "kdp.flags.ack",
264 FT_BOOLEAN, 8, NULL, KDP_ACK_FLAG, NULL, HFILL}
267 {"KDP RST Flag", "kdp.flags.rst",
268 FT_BOOLEAN, 8, NULL, KDP_RST_FLAG, NULL, HFILL}
271 {"KDP BCST Flag", "kdp.flags.bcst",
272 FT_BOOLEAN, 8, NULL, KDP_BCST_FLAG, NULL, HFILL}
275 {"KDP DUP Flag", "kdp.flags.dup",
276 FT_BOOLEAN, 8, NULL, KDP_DUP_FLAG, NULL, HFILL}
279 {"KDP errors", "kdp.errors",
280 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}
282 { &hf_kdp_destflowid,
283 { "DestFlowID", "kdp.destflowid",
284 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
287 { "SrcFlowID", "kdp.srcflowid",
288 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
291 { "Sequence", "kdp.sequence",
292 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
296 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
298 { &hf_kdp_maxsegmentsize,
299 { "MaxSegmentSize", "kdp.maxsegmentsize",
300 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
302 { &hf_kdp_optionnumber,
303 { "Option Number", "kdp.optionnumber",
304 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}
307 { "Option Len", "kdp.option",
308 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}
311 { "Option1 - Max Window", "kdp.option1",
312 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
315 { "Option2 - TCP Fraction", "kdp.option2",
316 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
319 { "Fragment", "kdp.fragment",
320 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
323 { "FragTotal", "kdp.fragtotal",
324 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
327 { "Encrypted Body", "kdp.body",
328 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}
331 { "XML Body", "kdp.body",
332 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}
336 /* Setup protocol subtree array */
337 static gint *ett[] = {
338 &ett_kdp, &ett_kdp_flags
341 proto_kdp = proto_register_protocol("Kontiki Delivery Protocol", /* name */
342 "KDP", /* short name */
344 proto_register_field_array(proto_kdp, hf, array_length(hf));
345 proto_register_subtree_array(ett, array_length(ett));
349 proto_reg_handoff_kdp(void) {
350 dissector_handle_t kdp_handle;
351 kdp_handle = create_dissector_handle(dissect_kdp, proto_kdp);
352 dissector_add("udp.port", KDP_PORT, kdp_handle);