Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-kdp.c
blob727b617a311d7f6a655602f9ff4c893ea04b9c6e
1 /* packet-kdp.c
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
14 #include "config.h"
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
24 static int proto_kdp;
25 static int ett_kdp;
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,
69 packet_info *pinfo,
70 proto_tree *tree, void* data _U_) {
71 proto_item *ti;
72 proto_tree *kdp_tree;
73 unsigned body_len;
74 uint8_t version;
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);
89 if (version != 2) {
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);
93 } else {
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 */
99 } else {
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) {
119 int offset;
120 offset = 4;
121 if (packet_flags & KDP_ACK_FLAG) {
122 proto_tree_add_item(kdp_tree, hf_kdp_destflowid, tvb, offset, 4, ENC_BIG_ENDIAN);
123 offset = offset + 4;
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);
129 offset = offset + 4;
132 proto_tree_add_item(kdp_tree, hf_kdp_sequence, tvb, offset, 4, ENC_BIG_ENDIAN);
133 sequence_number = tvb_get_ntohl(tvb, offset);
134 offset = offset + 4;
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);
139 offset = offset + 4;
141 if (packet_flags & KDP_SYN_FLAG) {
142 proto_tree_add_item(kdp_tree, hf_kdp_maxsegmentsize, tvb, offset, 4, ENC_BIG_ENDIAN);
143 offset = offset + 4;
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);
153 offset = offset + 1;
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);
157 offset = offset + 1;
160 switch (option_number) {
161 case 0:
162 break;
163 case 1:
164 proto_tree_add_item(kdp_tree, hf_kdp_option1, tvb, offset, 2, ENC_BIG_ENDIAN);
165 offset = offset + 2;
166 break;
167 case 2:
168 proto_tree_add_item(kdp_tree, hf_kdp_option2, tvb, offset, 2, ENC_BIG_ENDIAN);
169 offset = offset + 2;
170 break;
171 case 3:
172 proto_tree_add_item(kdp_tree, hf_kdp_option3, tvb, offset, 2, ENC_BIG_ENDIAN);
173 offset = offset + 2;
174 break;
175 case 4:
176 proto_tree_add_item(kdp_tree, hf_kdp_option4, tvb, offset, 0, ENC_NA);
177 break;
178 case 5:
179 proto_tree_add_item(kdp_tree, hf_kdp_option5, tvb, offset, 0, ENC_NA);
180 break;
181 case 6:
182 proto_tree_add_item(kdp_tree, hf_kdp_option6, tvb, offset, option_len - 2, ENC_NA);
183 offset = offset + option_len - 2;
184 break;
185 case 7:
186 proto_tree_add_item(kdp_tree, hf_kdp_option7, tvb, offset, 2, ENC_BIG_ENDIAN);
187 offset = offset + 2;
188 break;
189 case 8:
190 proto_tree_add_item(kdp_tree, hf_kdp_option8, tvb, offset, 2, ENC_BIG_ENDIAN);
191 offset = offset + 2;
192 break;
193 case 9:
194 proto_tree_add_item(kdp_tree, hf_kdp_option9, tvb, offset, 2, ENC_BIG_ENDIAN);
195 offset = offset + 2;
196 break;
197 default:
198 proto_tree_add_item(kdp_tree, hf_kdp_option_unknown, tvb, offset, option_len - 2, ENC_NA);
199 offset = offset + option_len - 2;
200 break;
204 if (body_len > 0) {
205 proto_tree_add_item(kdp_tree, hf_kdp_fragment, tvb, offset, 2, ENC_BIG_ENDIAN);
206 offset = offset + 2;
208 proto_tree_add_item(kdp_tree, hf_kdp_fragtotal, tvb, offset, 2, ENC_BIG_ENDIAN);
209 offset = offset + 2;
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 */
217 if (version != 2) {
218 col_set_str(pinfo->cinfo, COL_INFO, "SDDP message");
219 } else {
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);
226 } else {
227 ack_string[0] = '\0';
229 if (header_len > 4) {
230 snprintf(seq_num_string, sizeof(seq_num_string), "SEQ=%x ", sequence_number);
231 } else {
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);
236 } else {
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 " : ""),
245 ack_string,
246 seq_num_string,
247 src_flowid_string,
248 packet_errors);
251 return tvb_captured_length(tvb);
254 void proto_register_kdp(void) {
256 static hf_register_info hf[] = {
257 { &hf_kdp_version,
258 {"KDP version", "kdp.version",
259 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}
261 { &hf_kdp_headerlen,
262 {"KDP header len", "kdp.headerlen",
263 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL}
265 { &hf_kdp_flags,
266 {"KDP flags", "kdp.flags",
267 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}
269 { &hf_kdp_drop_flag,
270 {"KDP DROP Flag", "kdp.flags.drop",
271 FT_BOOLEAN, 8, NULL, KDP_DROP_FLAG, NULL, HFILL}
273 { &hf_kdp_syn_flag,
274 {"KDP SYN Flag", "kdp.flags.syn",
275 FT_BOOLEAN, 8, NULL, KDP_SYN_FLAG, NULL, HFILL}
277 { &hf_kdp_ack_flag,
278 {"KDP ACK Flag", "kdp.flags.ack",
279 FT_BOOLEAN, 8, NULL, KDP_ACK_FLAG, NULL, HFILL}
281 { &hf_kdp_rst_flag,
282 {"KDP RST Flag", "kdp.flags.rst",
283 FT_BOOLEAN, 8, NULL, KDP_RST_FLAG, NULL, HFILL}
285 { &hf_kdp_bcst_flag,
286 {"KDP BCST Flag", "kdp.flags.bcst",
287 FT_BOOLEAN, 8, NULL, KDP_BCST_FLAG, NULL, HFILL}
289 { &hf_kdp_dup_flag,
290 {"KDP DUP Flag", "kdp.flags.dup",
291 FT_BOOLEAN, 8, NULL, KDP_DUP_FLAG, NULL, HFILL}
293 { &hf_kdp_errors,
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}
301 { &hf_kdp_srcflowid,
302 { "SrcFlowID", "kdp.srcflowid",
303 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
305 { &hf_kdp_sequence,
306 { "Sequence", "kdp.sequence",
307 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}
309 { &hf_kdp_ack,
310 { "Ack", "kdp.ack",
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}
321 { &hf_kdp_optionlen,
322 { "Option Len", "kdp.option",
323 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL}
325 { &hf_kdp_option1,
326 { "Option1 - Max Window", "kdp.option1",
327 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
329 { &hf_kdp_option2,
330 { "Option2 - TCP Fraction", "kdp.option2",
331 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
333 { &hf_kdp_option3,
334 { "Option3 - KDP Version", "kdp.option3",
335 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
337 { &hf_kdp_option4,
338 { "Option4 - Enable Reliable", "kdp.option4",
339 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL}
341 { &hf_kdp_option5,
342 { "Option5 - Disable Reliable", "kdp.option5",
343 FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL}
345 { &hf_kdp_option6,
346 { "Option6 - SACK", "kdp.option6",
347 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}
349 { &hf_kdp_option7,
350 { "Option7 - COS", "kdp.option7",
351 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
353 { &hf_kdp_option8,
354 { "Option8 - BWMIN", "kdp.option8",
355 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
357 { &hf_kdp_option9,
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}
365 { &hf_kdp_fragment,
366 { "Fragment", "kdp.fragment",
367 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
369 { &hf_kdp_fragtotal,
370 { "FragTotal", "kdp.fragtotal",
371 FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL}
373 { &hf_kdp_body,
374 { "Encrypted Body", "kdp.body",
375 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}
377 { &hf_kdp_xml_body,
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 */
390 "kdp"); /* abbrev */
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);
397 void
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
405 * Local Variables:
406 * c-basic-offset: 2
407 * tab-width: 8
408 * indent-tabs-mode: nil
409 * End:
411 * ex: set shiftwidth=2 tabstop=8 expandtab:
412 * :indentSize=2:tabSize=8:noTabs=true: