2 * Routines for Quick UDP Internet Connections dissection
3 * Copyright 2013, Alexis La Goutte <alexis.lagoutte at gmail dot com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 QUIC Wire Layout Specification : https://docs.google.com/document/d/1WJvyZflAO2pq77yOLbp9NsGjC1CHetAXV8I0fQe-B_U/
27 QUIC source code in Chromium : https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_utils.h&sq=package:chromium
32 #include <epan/packet.h>
33 #include <epan/prefs.h>
35 void proto_register_quic(void);
36 void proto_reg_handoff_quic(void);
38 static int proto_quic = -1;
39 static int hf_quic_puflags = -1;
40 static int hf_quic_puflags_vrsn = -1;
41 static int hf_quic_puflags_rst = -1;
42 static int hf_quic_puflags_cid = -1;
43 static int hf_quic_puflags_seq = -1;
44 static int hf_quic_puflags_rsv = -1;
45 static int hf_quic_cid = -1;
46 static int hf_quic_version = -1;
47 static int hf_quic_sequence = -1;
48 #if 0 /* Decode Private Flags is not yet ready... */
49 static int hf_quic_prflags = -1;
50 static int hf_quic_prflags_entropy = -1;
51 static int hf_quic_prflags_fecg = -1;
52 static int hf_quic_prflags_fec = -1;
53 static int hf_quic_prflags_rsv = -1;
55 static int hf_quic_payload = -1;
57 static guint g_quic_port = 80;
58 static guint g_quics_port = 443;
60 static gint ett_quic = -1;
61 static gint ett_quic_puflags = -1;
62 static gint ett_quic_prflags = -1;
64 #define QUIC_MIN_LENGTH 3
66 /**************************************************************************/
68 /**************************************************************************/
69 #define PUFLAGS_VRSN 0x01
70 #define PUFLAGS_RST 0x02
71 #define PUFLAGS_CID 0x0C
72 #define PUFLAGS_SEQ 0x30
73 #define PUFLAGS_RSV 0xC0
75 static const value_string puflags_cid_vals[] = {
83 static const value_string puflags_seq_vals[] = {
91 /**************************************************************************/
93 /**************************************************************************/
94 #define PRFLAGS_ENTROPY 0x01
95 #define PRFLAGS_FECG 0x02
96 #define PRFLAGS_FEC 0x04
97 #define PRFLAGS_RSV 0xF8
100 dissect_quic_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
103 proto_item *ti, *ti_puflags/*, *ti_prflags, *expert_ti*/;
104 proto_tree *quic_tree, *puflags_tree/*, *prflags_tree*/;
106 guint8 puflags, len_cid, len_seq;
109 if (tvb_length(tvb) < QUIC_MIN_LENGTH)
112 col_set_str(pinfo->cinfo, COL_PROTOCOL, "QUIC");
114 ti = proto_tree_add_item(tree, proto_quic, tvb, 0, -1, ENC_NA);
115 quic_tree = proto_item_add_subtree(ti, ett_quic);
118 ti_puflags = proto_tree_add_item(quic_tree, hf_quic_puflags, tvb, offset, 1, ENC_LITTLE_ENDIAN);
119 puflags_tree = proto_item_add_subtree(ti_puflags, ett_quic_puflags);
120 proto_tree_add_item(puflags_tree, hf_quic_puflags_vrsn, tvb, offset, 1, ENC_NA);
121 proto_tree_add_item(puflags_tree, hf_quic_puflags_rst, tvb, offset, 1, ENC_NA);
122 proto_tree_add_item(puflags_tree, hf_quic_puflags_cid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
123 proto_tree_add_item(puflags_tree, hf_quic_puflags_seq, tvb, offset, 1, ENC_LITTLE_ENDIAN);
124 proto_tree_add_item(puflags_tree, hf_quic_puflags_rsv, tvb, offset, 1, ENC_LITTLE_ENDIAN);
126 puflags = tvb_get_guint8(tvb, offset);
132 /* Get len of CID (and CID), may be a more easy function to get the length... */
133 switch((puflags & PUFLAGS_CID) >> 2){
140 cid = tvb_get_guint8(tvb, offset);
144 cid = tvb_get_letohl(tvb, offset);
148 cid = tvb_get_letoh64(tvb, offset);
150 default: /* It is only between 0..3 but Clang(Analyser) i don't like this... ;-) */
152 cid = tvb_get_letoh64(tvb, offset);
157 proto_tree_add_item(quic_tree, hf_quic_cid, tvb, offset, len_cid, ENC_LITTLE_ENDIAN);
162 if(puflags & PUFLAGS_VRSN){
163 proto_tree_add_item(quic_tree, hf_quic_version, tvb, offset, 4, ENC_ASCII|ENC_NA);
169 /* Get len of sequence (and sequence), may be a more easy function to get the length... */
170 switch((puflags & PUFLAGS_SEQ) >> 4){
173 seq = tvb_get_guint8(tvb, offset);
177 seq = tvb_get_letohs(tvb, offset);
181 seq = tvb_get_letohl(tvb, offset);
185 seq = tvb_get_letoh48(tvb, offset);
187 default: /* It is only between 0..3 but Clang(Analyser) i don't like this... ;-) */
189 seq = tvb_get_letoh48(tvb, offset);
192 proto_tree_add_item(quic_tree, hf_quic_sequence, tvb, offset, len_seq, ENC_LITTLE_ENDIAN);
195 col_add_fstr(pinfo->cinfo, COL_INFO, "CID: %" G_GINT64_MODIFIER "u, Seq: %" G_GINT64_MODIFIER "u", cid, seq);
197 #if 0 /* Decode Private Flags is not yet ready... */
199 ti_prflags = proto_tree_add_item(quic_tree, hf_quic_prflags, tvb, offset, 1, ENC_LITTLE_ENDIAN);
200 prflags_tree = proto_item_add_subtree(ti_prflags, ett_quic_prflags);
201 proto_tree_add_item(prflags_tree, hf_quic_prflags_entropy, tvb, offset, 1, ENC_NA);
202 proto_tree_add_item(prflags_tree, hf_quic_prflags_fecg, tvb, offset, 1, ENC_NA);
203 proto_tree_add_item(prflags_tree, hf_quic_prflags_fec, tvb, offset, 1, ENC_NA);
204 proto_tree_add_item(prflags_tree, hf_quic_prflags_rsv, tvb, offset, 1, ENC_LITTLE_ENDIAN);
208 /* Payload... (encrypted... TODO FIX !) */
209 proto_tree_add_item(quic_tree, hf_quic_payload, tvb, offset, -1, ENC_NA);
215 dissect_quic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
218 return dissect_quic_common(tvb, pinfo, tree, NULL);
222 dissect_quics(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
225 return dissect_quic_common(tvb, pinfo, tree, NULL);
229 proto_register_quic(void)
231 module_t *quic_module;
233 static hf_register_info hf[] = {
235 { "Public Flags", "quic.puflags",
236 FT_UINT8, BASE_HEX, NULL, 0x0,
237 "Specifying per-packet public flags", HFILL }
239 { &hf_quic_puflags_vrsn,
240 { "Version", "quic.puflags.version",
241 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PUFLAGS_VRSN,
242 "Signifies that this packet also contains the version of the QUIC protocol", HFILL }
244 { &hf_quic_puflags_rst,
245 { "Reset", "quic.puflags.reset",
246 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PUFLAGS_RST,
247 "Signifies that this packet is a public reset packet", HFILL }
249 { &hf_quic_puflags_cid,
250 { "CID Length", "quic.puflags.cid",
251 FT_UINT8, BASE_HEX, VALS(puflags_cid_vals), PUFLAGS_CID,
252 "Signifies the Length of CID", HFILL }
254 { &hf_quic_puflags_seq,
255 { "Sequence Length", "quic.puflags.seq",
256 FT_UINT8, BASE_HEX, VALS(puflags_seq_vals), PUFLAGS_SEQ,
257 "Signifies the Length of Sequence", HFILL }
259 { &hf_quic_puflags_rsv,
260 { "Reserved", "quic.puflags.rsv",
261 FT_UINT8, BASE_HEX, NULL, PUFLAGS_RSV,
262 "Must be Zero", HFILL }
266 FT_UINT64, BASE_DEC, NULL, 0x0,
267 "Connection ID 64 bit pseudo random number", HFILL }
270 { "Version", "quic.version",
271 FT_STRING, BASE_NONE, NULL, 0x0,
272 "32 bit opaque tag that represents the version of the QUIC", HFILL }
275 { "Sequence", "quic.sequence",
276 FT_UINT64, BASE_DEC, NULL, 0x0,
277 "The lower 8, 16, 32, or 48 bits of the sequence number", HFILL }
279 #if 0 /* Decode Private Flags is not yet ready... */
281 { "Private Flags", "quic.prflags",
282 FT_UINT8, BASE_HEX, NULL, 0x0,
283 "Specifying per-packet Private flags", HFILL }
285 { &hf_quic_prflags_entropy,
286 { "Entropy", "quic.prflags.entropy",
287 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PRFLAGS_ENTROPY,
288 "For data packets, signifies that this packet contains the 1 bit of entropy, for fec packets, contains the xor of the entropy of protected packets", HFILL }
290 { &hf_quic_prflags_fecg,
291 { "FEC Group", "quic.prflags.fecg",
292 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PRFLAGS_FECG,
293 "Indicates whether the fec byte is present.", HFILL }
295 { &hf_quic_prflags_fec,
296 { "FEC", "quic.prflags.fec",
297 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PRFLAGS_FEC,
298 "Signifies that this packet represents an FEC packet", HFILL }
300 { &hf_quic_prflags_rsv,
301 { "Reserved", "quic.prflags.rsv",
302 FT_UINT8, BASE_HEX, NULL, PRFLAGS_RSV,
303 "Must be Zero", HFILL }
308 { "Payload", "quic.payload",
309 FT_BYTES, BASE_NONE, NULL, 0x0,
310 "Quic Payload..", HFILL }
316 static gint *ett[] = {
322 proto_quic = proto_register_protocol("QUIC (Quick UDP Internet Connections)",
325 proto_register_field_array(proto_quic, hf, array_length(hf));
326 proto_register_subtree_array(ett, array_length(ett));
328 quic_module = prefs_register_protocol(proto_quic, proto_reg_handoff_quic);
331 prefs_register_uint_preference(quic_module, "udp.quic.port", "QUIC UDP Port",
332 "QUIC UDP port if other than the default",
335 prefs_register_uint_preference(quic_module, "udp.quics.port", "QUICS UDP Port",
336 "QUICS (Secure) UDP port if other than the default",
341 proto_reg_handoff_quic(void)
343 static gboolean initialized = FALSE;
344 static dissector_handle_t quic_handle;
345 static dissector_handle_t quics_handle;
346 static int current_quic_port;
347 static int current_quics_port;
350 quic_handle = new_create_dissector_handle(dissect_quic,
352 quics_handle = new_create_dissector_handle(dissect_quics,
357 dissector_delete_uint("udp.port", current_quic_port, quic_handle);
358 dissector_delete_uint("udp.port", current_quics_port, quics_handle);
361 current_quic_port = g_quic_port;
362 current_quics_port = g_quics_port;
365 dissector_add_uint("udp.port", current_quic_port, quic_handle);
366 dissector_add_uint("udp.port", current_quics_port, quics_handle);
371 * Editor modelines - http://www.wireshark.org/tools/modelines.html
376 * indent-tabs-mode: nil
379 * vi: set shiftwidth=4 tabstop=8 expandtab:
380 * :indentSize=4:tabSize=8:noTabs=true: