2 * Routines for KDP (Kontiki Delivery Protocol) packet disassembly
4 * Copyright (c) 2008 by Kontiki Inc.
5 * Wade Hennessey <wade@kontiki.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1999 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <epan/packet.h>
17 void proto_register_kdp(void);
18 void proto_reg_handoff_kdp(void);
20 static dissector_handle_t kdp_handle
;
22 #define KDP_PORT 19948 /* Not IANA registered */
23 #define BUFFER_SIZE 80
26 static int ett_kdp_flags
;
28 static int hf_kdp_version
;
29 static int hf_kdp_headerlen
;
30 static int hf_kdp_flags
;
31 static int hf_kdp_errors
;
32 static int hf_kdp_destflowid
;
33 static int hf_kdp_srcflowid
;
34 static int hf_kdp_sequence
;
35 static int hf_kdp_ack
;
36 static int hf_kdp_maxsegmentsize
;
37 static int hf_kdp_optionnumber
;
38 static int hf_kdp_optionlen
;
39 static int hf_kdp_option1
;
40 static int hf_kdp_option2
;
41 static int hf_kdp_option3
;
42 static int hf_kdp_option4
;
43 static int hf_kdp_option5
;
44 static int hf_kdp_option6
;
45 static int hf_kdp_option7
;
46 static int hf_kdp_option8
;
47 static int hf_kdp_option9
;
48 static int hf_kdp_option_unknown
;
49 static int hf_kdp_fragment
;
50 static int hf_kdp_fragtotal
;
51 static int hf_kdp_body
;
52 static int hf_kdp_xml_body
;
54 #define KDP_DROP_FLAG (1 << 0)
55 #define KDP_SYN_FLAG (1 << 1)
56 #define KDP_ACK_FLAG (1 << 2)
57 #define KDP_RST_FLAG (1 << 3)
58 #define KDP_BCST_FLAG (1 << 4)
59 #define KDP_DUP_FLAG (1 << 5)
61 static int hf_kdp_drop_flag
;
62 static int hf_kdp_syn_flag
;
63 static int hf_kdp_ack_flag
;
64 static int hf_kdp_rst_flag
;
65 static int hf_kdp_bcst_flag
;
66 static int hf_kdp_dup_flag
;
68 static int dissect_kdp(tvbuff_t
*tvb
,
70 proto_tree
*tree
, void* data _U_
) {
75 uint8_t header_len
= 0;
76 uint8_t packet_flags
= 0;
77 uint8_t packet_errors
= 0;
78 uint32_t sequence_number
= UINT32_MAX
;
79 uint32_t ack_number
= UINT32_MAX
;
80 uint32_t src_flowid
= UINT32_MAX
;
82 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "KDP");
83 col_clear(pinfo
->cinfo
, COL_INFO
);
85 ti
= proto_tree_add_item(tree
, proto_kdp
, tvb
, 0, -1, ENC_NA
);
86 kdp_tree
= proto_item_add_subtree(ti
, ett_kdp
);
88 version
= tvb_get_uint8(tvb
, 0);
90 /* Version other than 2 is really SDDP in UDP */
91 proto_tree_add_item(kdp_tree
, hf_kdp_version
, tvb
, 0, 1, ENC_BIG_ENDIAN
);
92 proto_tree_add_item(kdp_tree
, hf_kdp_xml_body
, tvb
, 0, -1, ENC_ASCII
);
94 proto_tree
*flags_tree
;
95 header_len
= tvb_get_uint8(tvb
, 1) * 4;
96 body_len
= tvb_reported_length(tvb
);
97 if (header_len
> body_len
) {
98 body_len
= 0; /* malformed packet */
100 body_len
= body_len
- header_len
;
102 packet_flags
= tvb_get_uint8(tvb
, 2);
103 packet_errors
= tvb_get_uint8(tvb
, 3);
104 proto_tree_add_item(kdp_tree
, hf_kdp_version
, tvb
, 0, 1, ENC_BIG_ENDIAN
);
105 proto_tree_add_item(kdp_tree
, hf_kdp_headerlen
, tvb
, 1, 1, ENC_BIG_ENDIAN
);
106 ti
= proto_tree_add_item(kdp_tree
, hf_kdp_flags
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
107 flags_tree
= proto_item_add_subtree(ti
, ett_kdp_flags
);
109 proto_tree_add_item(flags_tree
, hf_kdp_drop_flag
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
110 proto_tree_add_item(flags_tree
, hf_kdp_syn_flag
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
111 proto_tree_add_item(flags_tree
, hf_kdp_ack_flag
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
112 proto_tree_add_item(flags_tree
, hf_kdp_rst_flag
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
113 proto_tree_add_item(flags_tree
, hf_kdp_bcst_flag
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
114 proto_tree_add_item(flags_tree
, hf_kdp_dup_flag
, tvb
, 2, 1, ENC_BIG_ENDIAN
);
116 proto_tree_add_item(kdp_tree
, hf_kdp_errors
, tvb
, 3, 1, ENC_BIG_ENDIAN
);
118 if (header_len
> 4) {
121 if (packet_flags
& KDP_ACK_FLAG
) {
122 proto_tree_add_item(kdp_tree
, hf_kdp_destflowid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
126 if (packet_flags
& (KDP_SYN_FLAG
| KDP_BCST_FLAG
)) {
127 proto_tree_add_item(kdp_tree
, hf_kdp_srcflowid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
128 src_flowid
= tvb_get_ntohl(tvb
, offset
);
132 proto_tree_add_item(kdp_tree
, hf_kdp_sequence
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
133 sequence_number
= tvb_get_ntohl(tvb
, offset
);
136 if (packet_flags
& KDP_ACK_FLAG
) {
137 proto_tree_add_item(kdp_tree
, hf_kdp_ack
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
138 ack_number
= tvb_get_ntohl(tvb
, offset
);
141 if (packet_flags
& KDP_SYN_FLAG
) {
142 proto_tree_add_item(kdp_tree
, hf_kdp_maxsegmentsize
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
146 while (offset
< ((body_len
> 0) ? header_len
- 4 : header_len
)) {
147 uint8_t option_number
;
148 uint8_t option_len
= 0;
150 option_number
= tvb_get_uint8(tvb
, offset
);
152 proto_tree_add_item(kdp_tree
, hf_kdp_optionnumber
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
154 if (option_number
> 0) {
155 option_len
= tvb_get_uint8(tvb
, offset
);
156 proto_tree_add_item(kdp_tree
, hf_kdp_optionlen
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
160 switch (option_number
) {
164 proto_tree_add_item(kdp_tree
, hf_kdp_option1
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
168 proto_tree_add_item(kdp_tree
, hf_kdp_option2
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
172 proto_tree_add_item(kdp_tree
, hf_kdp_option3
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
176 proto_tree_add_item(kdp_tree
, hf_kdp_option4
, tvb
, offset
, 0, ENC_NA
);
179 proto_tree_add_item(kdp_tree
, hf_kdp_option5
, tvb
, offset
, 0, ENC_NA
);
182 proto_tree_add_item(kdp_tree
, hf_kdp_option6
, tvb
, offset
, option_len
- 2, ENC_NA
);
183 offset
= offset
+ option_len
- 2;
186 proto_tree_add_item(kdp_tree
, hf_kdp_option7
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
190 proto_tree_add_item(kdp_tree
, hf_kdp_option8
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
194 proto_tree_add_item(kdp_tree
, hf_kdp_option9
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
198 proto_tree_add_item(kdp_tree
, hf_kdp_option_unknown
, tvb
, offset
, option_len
- 2, ENC_NA
);
199 offset
= offset
+ option_len
- 2;
205 proto_tree_add_item(kdp_tree
, hf_kdp_fragment
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
208 proto_tree_add_item(kdp_tree
, hf_kdp_fragtotal
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
211 proto_tree_add_item(kdp_tree
, hf_kdp_body
, tvb
, offset
, -1, ENC_NA
);
215 /* Now that we know sequence number and optional ack number, we can
216 print more detailed summary info */
218 col_set_str(pinfo
->cinfo
, COL_INFO
, "SDDP message");
220 char ack_string
[BUFFER_SIZE
];
221 char seq_num_string
[BUFFER_SIZE
];
222 char src_flowid_string
[BUFFER_SIZE
];
224 if (packet_flags
& KDP_ACK_FLAG
) {
225 snprintf(ack_string
, sizeof(ack_string
), "ACK=%x ", ack_number
);
227 ack_string
[0] = '\0';
229 if (header_len
> 4) {
230 snprintf(seq_num_string
, sizeof(seq_num_string
), "SEQ=%x ", sequence_number
);
232 seq_num_string
[0] = '\0';
234 if (packet_flags
& (KDP_SYN_FLAG
| KDP_BCST_FLAG
)) {
235 snprintf(src_flowid_string
, sizeof(src_flowid_string
), "SRC_FLOWID=%x ", src_flowid
);
237 src_flowid_string
[0] = '\0';
239 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s%s%s%s%s%s%s%serrors=%d",
240 ((packet_flags
& KDP_DROP_FLAG
) ? "DROP " : ""),
241 ((packet_flags
& KDP_SYN_FLAG
) ? "SYN " : ""),
242 ((packet_flags
& KDP_RST_FLAG
) ? "RST " : ""),
243 ((packet_flags
& KDP_BCST_FLAG
) ? "BCST " : ""),
244 ((packet_flags
& KDP_DUP_FLAG
) ? "DUP " : ""),
251 return tvb_captured_length(tvb
);
254 void proto_register_kdp(void) {
256 static hf_register_info hf
[] = {
258 {"KDP version", "kdp.version",
259 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
262 {"KDP header len", "kdp.headerlen",
263 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
266 {"KDP flags", "kdp.flags",
267 FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
270 {"KDP DROP Flag", "kdp.flags.drop",
271 FT_BOOLEAN
, 8, NULL
, KDP_DROP_FLAG
, NULL
, HFILL
}
274 {"KDP SYN Flag", "kdp.flags.syn",
275 FT_BOOLEAN
, 8, NULL
, KDP_SYN_FLAG
, NULL
, HFILL
}
278 {"KDP ACK Flag", "kdp.flags.ack",
279 FT_BOOLEAN
, 8, NULL
, KDP_ACK_FLAG
, NULL
, HFILL
}
282 {"KDP RST Flag", "kdp.flags.rst",
283 FT_BOOLEAN
, 8, NULL
, KDP_RST_FLAG
, NULL
, HFILL
}
286 {"KDP BCST Flag", "kdp.flags.bcst",
287 FT_BOOLEAN
, 8, NULL
, KDP_BCST_FLAG
, NULL
, HFILL
}
290 {"KDP DUP Flag", "kdp.flags.dup",
291 FT_BOOLEAN
, 8, NULL
, KDP_DUP_FLAG
, NULL
, HFILL
}
294 {"KDP errors", "kdp.errors",
295 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
297 { &hf_kdp_destflowid
,
298 { "DestFlowID", "kdp.destflowid",
299 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
302 { "SrcFlowID", "kdp.srcflowid",
303 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
306 { "Sequence", "kdp.sequence",
307 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
311 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
313 { &hf_kdp_maxsegmentsize
,
314 { "MaxSegmentSize", "kdp.maxsegmentsize",
315 FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
317 { &hf_kdp_optionnumber
,
318 { "Option Number", "kdp.optionnumber",
319 FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
322 { "Option Len", "kdp.option",
323 FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
326 { "Option1 - Max Window", "kdp.option1",
327 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
330 { "Option2 - TCP Fraction", "kdp.option2",
331 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
334 { "Option3 - KDP Version", "kdp.option3",
335 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
338 { "Option4 - Enable Reliable", "kdp.option4",
339 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
342 { "Option5 - Disable Reliable", "kdp.option5",
343 FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
346 { "Option6 - SACK", "kdp.option6",
347 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
350 { "Option7 - COS", "kdp.option7",
351 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
354 { "Option8 - BWMIN", "kdp.option8",
355 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
358 { "Option9 - INT", "kdp.option9",
359 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
361 { &hf_kdp_option_unknown
,
362 { "Unknown option", "kdp.option_unknown",
363 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
366 { "Fragment", "kdp.fragment",
367 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
370 { "FragTotal", "kdp.fragtotal",
371 FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
374 { "Encrypted Body", "kdp.body",
375 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
378 { "XML Body", "kdp.xml_body",
379 FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
383 /* Setup protocol subtree array */
384 static int *ett
[] = {
385 &ett_kdp
, &ett_kdp_flags
388 proto_kdp
= proto_register_protocol("Kontiki Delivery Protocol", /* name */
389 "KDP", /* short name */
391 proto_register_field_array(proto_kdp
, hf
, array_length(hf
));
392 proto_register_subtree_array(ett
, array_length(ett
));
394 kdp_handle
= register_dissector("kdp", dissect_kdp
, proto_kdp
);
398 proto_reg_handoff_kdp(void) {
399 dissector_add_uint_with_preference("udp.port", KDP_PORT
, kdp_handle
);
403 * Editor modelines - https://www.wireshark.org/tools/modelines.html
408 * indent-tabs-mode: nil
411 * ex: set shiftwidth=2 tabstop=8 expandtab:
412 * :indentSize=2:tabSize=8:noTabs=true: