3 * Routines for UDT packet dissection
5 * Copyright 2013 (c) chas williams <chas@cmf.nrl.navy.mil>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/packet.h>
34 #include <epan/conversation.h>
35 #include <epan/expert.h>
38 * based on http://tools.ietf.org/html/draft-gg-udt-03
41 #define UDT_TYPE_DATA 0
42 #define UDT_TYPE_CONTROL 1
44 #define UDT_PACKET_TYPE_HANDSHAKE 0x0000
45 #define UDT_PACKET_TYPE_KEEPALIVE 0x0001
46 #define UDT_PACKET_TYPE_ACK 0x0002
47 #define UDT_PACKET_TYPE_NAK 0x0003
48 #define UDT_PACKET_TYPE_SHUTDOWN 0x0005
49 #define UDT_PACKET_TYPE_ACK2 0x0006
51 #define UDT_HANDSHAKE_TYPE_STREAM 0
52 #define UDT_HANDSHAKE_TYPE_DGRAM 1
54 static const value_string udt_packet_types
[] = {
55 {UDT_PACKET_TYPE_HANDSHAKE
, "handshake"},
56 {UDT_PACKET_TYPE_KEEPALIVE
, "keepalive"},
57 {UDT_PACKET_TYPE_ACK
, "ack"},
58 {UDT_PACKET_TYPE_NAK
, "nak"},
59 {UDT_PACKET_TYPE_SHUTDOWN
, "shutdown"},
60 {UDT_PACKET_TYPE_ACK2
, "ack2"},
64 static const value_string udt_handshake_types
[] = {
65 {UDT_HANDSHAKE_TYPE_STREAM
, "STREAM"},
66 {UDT_HANDSHAKE_TYPE_DGRAM
, "DGRAM"},
70 static const value_string udt_types
[] = {
71 {UDT_TYPE_DATA
, "DATA"},
72 {UDT_TYPE_CONTROL
, "CONTROL"},
76 static int proto_udt
= -1;
77 static int hf_udt_iscontrol
= -1;
78 static int hf_udt_type
= -1;
79 static int hf_udt_seqno
= -1;
80 static int hf_udt_ack_seqno
= -1;
81 static int hf_udt_ackno
= -1;
82 static int hf_udt_msgno
= -1;
83 static int hf_udt_msgno_first
= -1;
84 static int hf_udt_msgno_last
= -1;
85 static int hf_udt_msgno_inorder
= -1;
86 static int hf_udt_timestamp
= -1;
87 static int hf_udt_id
= -1;
88 static int hf_udt_addinfo
= -1;
89 static int hf_udt_rtt
= -1;
90 static int hf_udt_rttvar
= -1;
91 static int hf_udt_bufavail
= -1;
92 static int hf_udt_rate
= -1;
93 static int hf_udt_linkcap
= -1;
94 static int hf_udt_handshake_version
= -1;
95 static int hf_udt_handshake_type
= -1;
96 static int hf_udt_handshake_isn
= -1;
97 static int hf_udt_handshake_mtu
= -1;
98 static int hf_udt_handshake_flow_window
= -1;
99 static int hf_udt_handshake_reqtype
= -1;
100 static int hf_udt_handshake_id
= -1;
101 static int hf_udt_handshake_cookie
= -1;
102 static int hf_udt_handshake_peerip
= -1;
104 static gint ett_udt
= -1;
106 static expert_field ei_udt_nak_seqno
= EI_INIT
;
108 static dissector_handle_t udt_handle
;
109 static dissector_handle_t data_handle
;
112 dissect_udt(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* parent_tree
,
116 proto_item
*udt_item
;
117 int is_control
, type
;
120 /* Ensure we have enough data */
121 if (tvb_length(tvb
) < 16)
124 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "UDT");
125 col_clear(pinfo
->cinfo
, COL_INFO
);
127 is_control
= tvb_get_ntohl(tvb
, 0) & 0x80000000;
128 type
= (tvb_get_ntohl(tvb
, 0) >> 16) & 0x7fff;
131 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "UDT type: %s id: %x",
132 val_to_str(type
, udt_packet_types
,
133 "Unknown Control Type (%x)"),
134 tvb_get_ntohl(tvb
, 12));
136 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
137 "UDT type: data seqno: %u msgno: %u id: %x",
138 tvb_get_ntohl(tvb
, 0) & 0x7fffffff,
139 tvb_get_ntohl(tvb
, 4) & 0x1fffffff,
140 tvb_get_ntohl(tvb
, 12));
142 udt_item
= proto_tree_add_item(parent_tree
, proto_udt
, tvb
,
144 tree
= proto_item_add_subtree(udt_item
, ett_udt
);
146 proto_tree_add_item(tree
, hf_udt_iscontrol
, tvb
, 0, 4, ENC_BIG_ENDIAN
);
148 proto_tree_add_item(tree
, hf_udt_type
, tvb
, 0, 2,
151 case UDT_PACKET_TYPE_ACK
:
152 proto_tree_add_item(tree
, hf_udt_ackno
, tvb
, 4, 4,
155 case UDT_PACKET_TYPE_ACK2
:
156 proto_tree_add_item(tree
, hf_udt_ackno
, tvb
, 4, 4,
160 proto_tree_add_item(tree
, hf_udt_addinfo
, tvb
, 4, 4,
163 proto_tree_add_item(tree
, hf_udt_timestamp
, tvb
, 8, 4,
165 proto_tree_add_item(tree
, hf_udt_id
, tvb
, 12, 4,
169 case UDT_PACKET_TYPE_HANDSHAKE
:
170 proto_tree_add_item(tree
, hf_udt_handshake_version
, tvb
,
171 16, 4, ENC_BIG_ENDIAN
);
172 proto_tree_add_item(tree
, hf_udt_handshake_type
, tvb
,
173 20, 4, ENC_BIG_ENDIAN
);
174 proto_tree_add_item(tree
, hf_udt_handshake_isn
, tvb
, 24,
176 proto_tree_add_item(tree
, hf_udt_handshake_mtu
, tvb
, 28,
178 proto_tree_add_item(tree
, hf_udt_handshake_flow_window
,
179 tvb
, 32, 4, ENC_BIG_ENDIAN
);
180 proto_tree_add_item(tree
, hf_udt_handshake_reqtype
, tvb
,
181 36, 4, ENC_BIG_ENDIAN
);
182 proto_tree_add_item(tree
, hf_udt_handshake_id
, tvb
, 40,
184 proto_tree_add_item(tree
, hf_udt_handshake_cookie
, tvb
,
185 44, 4, ENC_BIG_ENDIAN
);
186 proto_tree_add_item(tree
, hf_udt_handshake_peerip
, tvb
,
188 proto_item_set_len(udt_item
, 64);
190 case UDT_PACKET_TYPE_ACK
:
191 proto_tree_add_item(tree
, hf_udt_ack_seqno
, tvb
, 16, 4,
193 proto_tree_add_item(tree
, hf_udt_rtt
, tvb
, 20, 4,
195 proto_tree_add_item(tree
, hf_udt_rttvar
, tvb
, 24, 4,
197 proto_tree_add_item(tree
, hf_udt_bufavail
, tvb
, 28, 4,
199 /* if not a light ack, decode the rate and link capacity */
200 if (tvb_length(tvb
) == 40) {
201 proto_tree_add_item(tree
, hf_udt_rate
, tvb
, 32,
203 proto_tree_add_item(tree
, hf_udt_linkcap
, tvb
,
204 36, 4, ENC_BIG_ENDIAN
);
205 proto_item_set_len(udt_item
, 40);
209 proto_item_set_len(udt_item
, 32);
212 case UDT_PACKET_TYPE_NAK
:
213 for (i
= 16; i
< tvb_length(tvb
); i
= i
+ 4) {
214 guint32 start
, finish
;
217 is_range
= tvb_get_ntohl(tvb
, i
) & 0x80000000;
218 start
= tvb_get_ntohl(tvb
, i
) & 0x7fffffff;
221 finish
= tvb_get_ntohl(tvb
, i
+ 4) & 0x7fffffff;
223 proto_tree_add_expert_format(tree
, pinfo
, &ei_udt_nak_seqno
,
224 tvb
, i
, 8, "Missing Sequence Number(s): %u-%u",
228 proto_tree_add_expert_format(tree
, pinfo
, &ei_udt_nak_seqno
,
229 tvb
, i
, 4, "Missing Sequence Number: %u",
234 proto_item_set_len(udt_item
, tvb_length(tvb
));
238 /* otherwise, a data packet */
241 proto_tree_add_item(tree
, hf_udt_seqno
, tvb
, 0, 4,
243 proto_tree_add_item(tree
, hf_udt_msgno_first
, tvb
, 4, 4,
245 proto_tree_add_item(tree
, hf_udt_msgno_last
, tvb
, 4, 4,
247 proto_tree_add_item(tree
, hf_udt_msgno_inorder
, tvb
, 4, 4,
249 proto_tree_add_item(tree
, hf_udt_msgno
, tvb
, 4, 4,
251 proto_tree_add_item(tree
, hf_udt_timestamp
, tvb
, 8, 4,
253 proto_tree_add_item(tree
, hf_udt_id
, tvb
, 12, 4,
256 next_tvb
= tvb_new_subset_remaining(tvb
, 16);
257 call_dissector(data_handle
, next_tvb
, pinfo
, parent_tree
);
260 return tvb_length(tvb
);
264 dissect_udt_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
266 conversation_t
*conv
;
268 /* Must have at least 20 bytes */
269 if (tvb_reported_length(tvb
) < 20)
272 /* detect handshake control packet */
273 if (tvb_get_ntohl(tvb
, 0) != (0x80000000 | UDT_PACKET_TYPE_HANDSHAKE
))
276 /* must be version 4 */
277 if ((tvb_get_ntohl(tvb
, 16) != 4))
280 /* must be datagram or stream */
281 if ((tvb_get_ntohl(tvb
, 20) != UDT_HANDSHAKE_TYPE_DGRAM
)
282 && (tvb_get_ntohl(tvb
, 20) != UDT_HANDSHAKE_TYPE_STREAM
))
285 conv
= find_or_create_conversation(pinfo
);
286 conversation_set_dissector(conv
, udt_handle
);
287 dissect_udt(tvb
, pinfo
, tree
, data
);
292 void proto_register_udt(void)
294 expert_module_t
*expert_udt
;
296 static hf_register_info hf
[] = {
297 {&hf_udt_iscontrol
, {
298 "Type", "udt.iscontrol", FT_UINT32
,
300 VALS(udt_types
), 0x80000000, NULL
, HFILL
}},
303 "Type", "udt.type", FT_UINT16
, BASE_HEX
,
304 VALS(udt_packet_types
), 0x7fff, NULL
, HFILL
}},
307 "Sequence Number", "udt.seqno", FT_UINT32
,
309 NULL
, 0x7fffffff, NULL
, HFILL
}},
312 "Additional Info", "udt.addinfo", FT_UINT32
,
314 NULL
, 0, NULL
, HFILL
}},
317 "Message Number", "udt.msgno", FT_UINT32
,
319 NULL
, 0x1fffffff, NULL
, HFILL
}},
321 {&hf_udt_msgno_first
, {
322 "First Indicator", "udt.msg.first",
324 NULL
, 0x80000000, NULL
, HFILL
}},
326 {&hf_udt_msgno_last
, {
327 "Last Indicator", "udt.msg.last",
329 NULL
, 0x40000000, NULL
, HFILL
}},
331 {&hf_udt_msgno_inorder
, {
332 "In-Order Indicator", "udt.msg.order",
334 NULL
, 0x20000000, NULL
, HFILL
}},
336 {&hf_udt_timestamp
, {
337 "Timestamp", "udt.timestamp", FT_UINT32
,
339 NULL
, 0, NULL
, HFILL
}},
342 "ID", "udt.id", FT_UINT32
, BASE_HEX
,
343 NULL
, 0, NULL
, HFILL
}},
345 {&hf_udt_ack_seqno
, {
346 "Ack Sequence Number", "udt.ack_seqno",
348 NULL
, 0, NULL
, HFILL
}},
351 "Ack Number", "udt.ackno", FT_UINT32
, BASE_DEC
,
352 NULL
, 0, NULL
, HFILL
}},
355 "RTT (microseconds)", "udt.rtt", FT_UINT32
,
357 NULL
, 0, NULL
, HFILL
}},
360 "RTT Variance (microseconds)", "udt.rttvar",
362 NULL
, 0, NULL
, HFILL
}},
365 "Buffer Available (packets)", "udt.rttvar",
367 NULL
, 0, NULL
, HFILL
}},
370 "Rate (packets/second)", "udt.rate", FT_UINT32
,
372 NULL
, 0, NULL
, HFILL
}},
375 "Link Capacity (packets/second)",
376 "udt.linkcap", FT_UINT32
, BASE_DEC
,
377 NULL
, 0, NULL
, HFILL
}},
379 {&hf_udt_handshake_version
, {
380 "Version", "udt.hs.version",
382 NULL
, 0, NULL
, HFILL
}},
384 {&hf_udt_handshake_type
, {
385 "Type", "udt.hs.type", FT_UINT32
,
387 VALS(udt_handshake_types
), 0, NULL
,
390 {&hf_udt_handshake_isn
, {
391 "Initial Sequence Number",
392 "udt.hs.isn", FT_UINT32
, BASE_DEC
,
393 NULL
, 0, NULL
, HFILL
}},
395 {&hf_udt_handshake_mtu
, {
396 "MTU", "udt.hs.mtu", FT_UINT32
,
398 NULL
, 0, NULL
, HFILL
}},
400 {&hf_udt_handshake_flow_window
, {
402 "udt.hs.flow_window",
404 NULL
, 0, NULL
, HFILL
}},
406 {&hf_udt_handshake_reqtype
, {
407 "Requested Type", "udt.hs.reqtype",
409 NULL
, 0, NULL
, HFILL
}},
411 {&hf_udt_handshake_id
, {
412 "ID", "udt.hs.id", FT_UINT32
, BASE_DEC
,
413 NULL
, 0, NULL
, HFILL
}},
415 {&hf_udt_handshake_cookie
, {
416 "SYN Cookie", "udt.hs.cookie",
418 NULL
, 0, NULL
, HFILL
}},
420 {&hf_udt_handshake_peerip
, {
421 "Peer IP Address", "udt.hs.peerip",
423 NULL
, 0, NULL
, HFILL
}},
426 static gint
*ett
[] = {
430 static ei_register_info ei
[] = {
432 { "udt.nak_seqno", PI_SEQUENCE
, PI_NOTE
,
433 "Missing Sequence Number(s)", EXPFILL
}},
436 proto_udt
= proto_register_protocol("UDT Protocol", "UDT", "udt");
437 proto_register_field_array(proto_udt
, hf
, array_length(hf
));
438 proto_register_subtree_array(ett
, array_length(ett
));
440 expert_udt
= expert_register_protocol(proto_udt
);
441 expert_register_field_array(expert_udt
, ei
, array_length(ei
));
444 void proto_reg_handoff_udt(void)
446 data_handle
= find_dissector("data");
447 udt_handle
= new_create_dissector_handle(dissect_udt
, proto_udt
);
449 heur_dissector_add("udp", dissect_udt_heur
, proto_udt
);
450 dissector_add_handle("udp.port", udt_handle
);