HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-rudp.c
blobe623652229f9db8f75b9c266e4f1c708c33d63bb
1 /* packet-rudp.c
2 * Routines for Reliable UDP Protocol.
3 * Copyright 2004, Duncan Sargeant <dunc-ethereal@rcpt.to>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-data.c, README.developer, and various other files.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * Reliable UDP is a lightweight protocol for providing TCP-like flow
29 * control over UDP. Cisco published an PFC a long time ago, and
30 * their actual implementation is slightly different, having no
31 * checksum field.
33 * I've cheated here - RUDP could be used for anything, but I've only
34 * seen it used to switched telephony calls, so we just call the Cisco SM
35 * dissector from here.
37 * Here are some links:
39 * http://www.watersprings.org/pub/id/draft-ietf-sigtran-reliable-udp-00.txt
40 * http://www.javvin.com/protocolRUDP.html
41 * http://www.cisco.com/univercd/cc/td/doc/product/access/sc/rel7/omts/omts_apb.htm#30052
45 #include "config.h"
47 #include <glib.h>
48 #include <epan/packet.h>
49 #include <epan/prefs.h>
51 /* Disable rudp by default. The previously hardcoded value of
52 * 7000 (used by Cisco) collides with afs and as the draft states:
53 * "RUDP doesn't place any restrictions on which UDP port numbers are used.
54 * Valid port numbers are ports not defined in RFC 1700."
56 /* FIXME: The proper solution would be to convert this dissector into
57 * heuristic dissector, but it isn't complete anyway.
59 static guint udp_port = 0;
61 void proto_reg_handoff_rudp(void);
63 static int proto_rudp = -1;
65 static int hf_rudp_flags = -1;
66 static int hf_rudp_flags_syn = -1;
67 static int hf_rudp_flags_ack = -1;
68 static int hf_rudp_flags_eak = -1;
69 static int hf_rudp_flags_rst = -1;
70 static int hf_rudp_flags_nul = -1;
71 static int hf_rudp_flags_chk = -1;
72 static int hf_rudp_flags_tcs = -1;
73 static int hf_rudp_flags_0 = -1;
74 static int hf_rudp_hlen = -1;
75 static int hf_rudp_seq = -1;
76 static int hf_rudp_ack = -1;
77 static int hf_rudp_cksum = -1;
79 static gint ett_rudp = -1;
80 static gint ett_rudp_flags = -1;
82 static dissector_handle_t sm_handle = NULL;
83 static dissector_handle_t data_handle = NULL;
86 static void
87 dissect_rudp(tvbuff_t *tvb, packet_info *pinfo _U_ , proto_tree *tree)
89 tvbuff_t * next_tvb = NULL;
90 proto_tree *rudp_tree = NULL, *flags_tree;
91 proto_item *ti = NULL;
92 int flags[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
93 int i;
94 guint8 hlen;
96 flags[0] = hf_rudp_flags_syn;
97 flags[1] = hf_rudp_flags_ack;
98 flags[2] = hf_rudp_flags_eak;
99 flags[3] = hf_rudp_flags_rst;
100 flags[4] = hf_rudp_flags_nul;
101 flags[5] = hf_rudp_flags_chk;
102 flags[6] = hf_rudp_flags_tcs;
103 flags[7] = hf_rudp_flags_0;
105 hlen = tvb_get_guint8(tvb, 1);
107 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RUDP");
108 col_clear(pinfo->cinfo, COL_INFO);
110 if (tree) {
111 ti = proto_tree_add_item(tree, proto_rudp, tvb, 0, hlen, ENC_NA);
112 rudp_tree = proto_item_add_subtree(ti, ett_rudp);
114 ti = proto_tree_add_item(rudp_tree, hf_rudp_flags, tvb, 0, 1, ENC_BIG_ENDIAN);
115 flags_tree = proto_item_add_subtree(ti, ett_rudp_flags);
117 for (i = 0; i < 8; i++)
118 proto_tree_add_item(flags_tree, flags[i], tvb, 0, 1, ENC_BIG_ENDIAN);
120 proto_tree_add_item(rudp_tree, hf_rudp_hlen, tvb, 1, 1, ENC_BIG_ENDIAN);
121 proto_tree_add_item(rudp_tree, hf_rudp_seq, tvb, 2, 1, ENC_BIG_ENDIAN);
122 proto_tree_add_item(rudp_tree, hf_rudp_ack, tvb, 3, 1, ENC_BIG_ENDIAN);
124 /* If the header is more than 4 bytes the next 2 bytes are the checksum */
125 if (hlen > 4) {
126 proto_tree_add_item(rudp_tree, hf_rudp_cksum, tvb, 4, 2, ENC_BIG_ENDIAN);
129 /* If we have even more bytes their meaning is unknown - we have seen this
130 * in live captures */
131 if (hlen > 6) {
132 next_tvb = tvb_new_subset(tvb, 6, hlen-6, hlen-6);
133 call_dissector(data_handle, next_tvb, pinfo, rudp_tree);
137 next_tvb = tvb_new_subset_remaining(tvb, hlen);
138 if (tvb_length(next_tvb) && sm_handle)
139 call_dissector(sm_handle, next_tvb, pinfo, tree);
142 void
143 proto_register_rudp(void)
146 static hf_register_info hf[] = {
147 { &hf_rudp_flags,
148 { "RUDP Header flags", "rudp.flags",
149 FT_UINT8, BASE_DEC, NULL, 0x0,
150 NULL, HFILL }
152 { &hf_rudp_flags_syn,
153 { "Syn", "rudp.flags.syn",
154 FT_BOOLEAN, 8, NULL, 0x80,
155 NULL, HFILL }
157 { &hf_rudp_flags_ack,
158 { "Ack", "rudp.flags.ack",
159 FT_BOOLEAN, 8, NULL, 0x40,
160 NULL, HFILL }
162 { &hf_rudp_flags_eak,
163 { "Eak", "rudp.flags.eak",
164 FT_BOOLEAN, 8, NULL, 0x20,
165 "Extended Ack", HFILL }
167 { &hf_rudp_flags_rst,
168 { "RST", "rudp.flags.rst",
169 FT_BOOLEAN, 8, NULL, 0x10,
170 "Reset flag", HFILL }
172 { &hf_rudp_flags_nul,
173 { "NULL", "rudp.flags.nul",
174 FT_BOOLEAN, 8, NULL, 0x08,
175 "Null flag", HFILL }
177 { &hf_rudp_flags_chk,
178 { "CHK", "rudp.flags.chk",
179 FT_BOOLEAN, 8, NULL, 0x04,
180 "Checksum is on header or body", HFILL }
182 { &hf_rudp_flags_tcs,
183 { "TCS", "rudp.flags.tcs",
184 FT_BOOLEAN, 8, NULL, 0x02,
185 "Transfer Connection System", HFILL }
187 { &hf_rudp_flags_0,
188 { "0", "rudp.flags.0",
189 FT_BOOLEAN, 8, NULL, 0x01,
190 NULL, HFILL }
192 { &hf_rudp_hlen,
193 { "Header Length", "rudp.hlen",
194 FT_UINT8, BASE_DEC, NULL, 0x0,
195 NULL, HFILL }
197 { &hf_rudp_seq,
198 { "Seq", "rudp.seq",
199 FT_UINT8, BASE_DEC, NULL, 0x0,
200 "Sequence Number", HFILL }
202 { &hf_rudp_ack,
203 { "Ack", "rudp.ack",
204 FT_UINT8, BASE_DEC, NULL, 0x0,
205 "Acknowledgement Number", HFILL }
207 { &hf_rudp_cksum,
208 { "Checksum", "rudp.cksum",
209 FT_UINT16, BASE_HEX, NULL, 0x0,
210 NULL, HFILL }
215 /* Setup protocol subtree array */
216 static gint *ett[] = {
217 &ett_rudp,
218 &ett_rudp_flags,
222 proto_rudp = proto_register_protocol (
223 "Reliable UDP", /* name */
224 "RUDP", /* short name */
225 "rudp" /* abbrev */
228 proto_register_field_array(proto_rudp, hf, array_length(hf));
229 proto_register_subtree_array(ett, array_length(ett));
232 module_t *rudp_module;
233 rudp_module = prefs_register_protocol(proto_rudp, proto_reg_handoff_rudp);
234 prefs_register_uint_preference(rudp_module,
235 "udp.port",
236 "UDP port for RUDP",
237 "Set the UDP port for Reliable UDP traffic",
239 &udp_port);
244 void
245 proto_reg_handoff_rudp(void) {
247 static gboolean initialized = FALSE;
248 static dissector_handle_t rudp_handle;
249 static guint saved_udp_port;
251 if (!initialized) {
252 rudp_handle = create_dissector_handle(dissect_rudp, proto_rudp);
253 dissector_add_handle("udp.port", rudp_handle); /* for "decode as" */
254 sm_handle = find_dissector("sm");
255 data_handle = find_dissector("data");
256 initialized = TRUE;
257 } else {
258 if (saved_udp_port != 0) {
259 dissector_delete_uint("udp.port", saved_udp_port, rudp_handle);
263 if (udp_port != 0) {
264 dissector_add_uint("udp.port", udp_port, rudp_handle);
266 saved_udp_port = udp_port;