3 * Routines to put exception information into the protocol tree
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 2000 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (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
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <epan/packet.h>
28 #include <epan/exceptions.h>
29 #include <epan/expert.h>
30 #include <epan/show_exception.h>
32 static int proto_short = -1;
33 static int proto_malformed = -1;
34 static int proto_unreassembled = -1;
36 static expert_field ei_malformed_dissector_bug = EI_INIT;
37 static expert_field ei_malformed_reassembly = EI_INIT;
38 static expert_field ei_malformed = EI_INIT;
41 register_show_exception(void)
43 static ei_register_info ei[] = {
44 { &ei_malformed_dissector_bug, { "_ws.malformed.dissector_bug", PI_MALFORMED, PI_ERROR, "Dissector bug", EXPFILL }},
45 { &ei_malformed_reassembly, { "_ws.malformed.reassembly", PI_MALFORMED, PI_ERROR, "Reassembly error", EXPFILL }},
46 { &ei_malformed, { "_ws.malformed.expert", PI_MALFORMED, PI_ERROR, "Malformed Packet (Exception occurred)", EXPFILL }},
49 expert_module_t* expert_malformed;
51 proto_short = proto_register_protocol("Short Frame", "Short frame", "_ws.short");
52 proto_malformed = proto_register_protocol("Malformed Packet",
53 "Malformed packet", "_ws.malformed");
54 proto_unreassembled = proto_register_protocol(
55 "Unreassembled Fragmented Packet",
56 "Unreassembled fragmented packet", "_ws.unreassembled");
58 expert_malformed = expert_register_protocol(proto_malformed);
59 expert_register_field_array(expert_malformed, ei, array_length(ei));
61 /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented
62 Packet" aren't really protocols, they're error indications;
63 disabling them makes no sense. */
64 proto_set_cant_toggle(proto_short);
65 proto_set_cant_toggle(proto_malformed);
66 proto_set_cant_toggle(proto_unreassembled);
70 show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
71 unsigned long exception, const char *exception_message)
73 static const char dissector_error_nomsg[] =
74 "Dissector writer didn't bother saying what the error was";
77 if (exception == ReportedBoundsError && pinfo->fragmented)
78 exception = FragmentBoundsError;
83 col_append_str(pinfo->cinfo, COL_INFO, "[SCSI transfer limited due to allocation_length too small]");
84 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
85 "SCSI transfer limited due to allocation_length too small: %s truncated]", pinfo->current_proto);
86 /* Don't record ScsiBoundsError exceptions as expert events - they merely
87 * reflect a normal SCSI condition.
88 * (any case where it's caused by something else is a bug). */
92 col_append_str(pinfo->cinfo, COL_INFO, "[Packet size limited during capture]");
93 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
94 "[Packet size limited during capture: %s truncated]", pinfo->current_proto);
95 /* Don't record BoundsError exceptions as expert events - they merely
96 * reflect a capture done with a snapshot length too short to capture
98 * (any case where it's caused by something else is a bug). */
101 case FragmentBoundsError:
102 col_append_fstr(pinfo->cinfo, COL_INFO, "[Unreassembled Packet%s]", pinfo->noreassembly_reason);
103 proto_tree_add_protocol_format(tree, proto_unreassembled,
104 tvb, 0, 0, "[Unreassembled Packet%s: %s]",
105 pinfo->noreassembly_reason, pinfo->current_proto);
106 /* Don't record FragmentBoundsError exceptions as expert events - they merely
107 * reflect dissection done with reassembly turned off
108 * (any case where it's caused by something else is a bug). */
111 case ReportedBoundsError:
112 show_reported_bounds_error(tvb, pinfo, tree);
116 col_append_fstr(pinfo->cinfo, COL_INFO,
117 "[Dissector bug, protocol %s: %s]",
118 pinfo->current_proto,
119 exception_message == NULL ?
120 dissector_error_nomsg : exception_message);
121 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
122 "[Dissector bug, protocol %s: %s]",
123 pinfo->current_proto,
124 exception_message == NULL ?
125 dissector_error_nomsg : exception_message);
126 g_warning("Dissector bug, protocol %s, in packet %u: %s",
127 pinfo->current_proto, pinfo->fd->num,
128 exception_message == NULL ?
129 dissector_error_nomsg : exception_message);
130 expert_add_info_format(pinfo, item, &ei_malformed_dissector_bug, "%s",
131 exception_message == NULL ?
132 dissector_error_nomsg : exception_message);
135 case ReassemblyError:
136 col_append_fstr(pinfo->cinfo, COL_INFO,
137 "[Reassembly error, protocol %s: %s]",
138 pinfo->current_proto,
139 exception_message == NULL ?
140 dissector_error_nomsg : exception_message);
141 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
142 "[Reassembly error, protocol %s: %s]",
143 pinfo->current_proto,
144 exception_message == NULL ?
145 dissector_error_nomsg : exception_message);
146 expert_add_info_format(pinfo, item, &ei_malformed_reassembly, "%s",
147 exception_message == NULL ?
148 dissector_error_nomsg : exception_message);
152 /* XXX - we want to know, if an unknown exception passed until here, don't we? */
153 g_assert_not_reached();
158 show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
162 col_append_str(pinfo->cinfo, COL_INFO,
163 "[Malformed Packet]");
164 item = proto_tree_add_protocol_format(tree, proto_malformed,
165 tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto);
166 expert_add_info(pinfo, item, &ei_malformed);