2 * Routines for Ethernet header disassembly of FW1 "monitor" files
3 * Copyright 2002,2003, Alfred Koebler <ako@icon.de>
5 * $Id: packet-fw1.c,v 1.9 2003/10/01 07:11:44 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Alfred Koebler <ako@icon.de>
9 * Copyright 2002,2003 Alfred Koebler
11 * To use this dissector use the command line option
12 * -o eth.interpret_as_fw1_monitor:TRUE
14 * At the moment the way with the option is the best one.
15 * A automatic way is not possible, because the file format isn't different
18 * With "fw monitor" it is possible to collect packets on several places.
19 * The additional information:
20 * - is it a incoming or outgoing packet
21 * - is it before or after the firewall
22 * i incoming before the firewall
23 * I incoming after the firewall
24 * o outcoming before the firewall
25 * O outcoming after the firewall
26 * - the name of the interface
28 * What's the problem ?
29 * Think about one packet traveling across the firewall.
30 * With ethereal you will see 4 lines in the Top Pane.
31 * To analyze a problem it is helpful to see the additional information
32 * in the protocol tree of the Middle Pane.
34 * The presentation of the summary line is designed in the following way:
35 * Every time the next selected packet in the Top Pane includes a
36 * "new" interface name the name is added to the list in the summary line.
37 * The interface names are listed one after the other.
38 * The position of the interface names didn't change.
40 * And who are the 4 places represented ?
41 * The interface name represents the firewall module of the interface.
42 * On the left side of the interface name is the interface module.
43 * On the right side of the interface name is the "IP" module.
45 * Example for a ping from the firewall to another host:
46 * For the four lines in the Top Pane you will see the according lines
53 * Example for a packet traversing through the Firewall, first through
54 * the inner side firewall module then through the outer side firewall module:
61 * Add new column with summary of FW-1 interface/direction
64 * Additional interpretation of field Chain Position.
65 * Show the chain position in the interface list.
66 * Support for new format of fw monitor file
67 * writen by option -u | -s for UUID/SUUID.
68 * NOTICE: First paket will have UUID == 0 !
70 * This program is free software; you can redistribute it and/or
71 * modify it under the terms of the GNU General Public License
72 * as published by the Free Software Foundation; either version 2
73 * of the License, or (at your option) any later version.
75 * This program is distributed in the hope that it will be useful,
76 * but WITHOUT ANY WARRANTY; without even the implied warranty of
77 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78 * GNU General Public License for more details.
80 * You should have received a copy of the GNU General Public License
81 * along with this program; if not, write to the Free Software
82 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
92 #include <epan/packet.h>
96 /* Place FW1 summary in proto tree */
97 static gboolean fw1_summary_in_tree = TRUE;
98 static gboolean fw1_with_uuid = FALSE;
99 static gboolean fw1_iflist_with_chain = FALSE;
101 /* Initialize the protocol and registered fields */
102 static int proto_fw1 = -1;
103 static int hf_fw1_direction = -1;
104 static int hf_fw1_chain = -1;
105 static int hf_fw1_interface = -1;
106 static int hf_fw1_uuid = -1;
107 static int hf_fw1_type = -1;
108 static int hf_fw1_trailer = -1;
110 /* Initialize the subtree pointers */
111 static gint ett_fw1 = -1;
113 #define ETH_HEADER_SIZE 14
115 static dissector_handle_t eth_handle;
118 dissect_fw1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
120 /* Set up structures needed to add the protocol subtree and manage it */
122 proto_tree *volatile fh_tree = NULL;
125 char interface_name[10+1];
133 #define MAX_INTERFACES 20
134 static char *p_interfaces[MAX_INTERFACES];
135 static int interface_anzahl=0;
136 static char header1[] = "FW1 Monitor";
138 #ifdef DID_NOT_FIND_A_PLACE_TO_START_THE_RESET_LIST_OF_INTERFACES
139 if (fw1_reset_list_of_if_on_next_begin) {
140 /* without FW1 summary delete all remembered names of interfaces */
141 for (i=0; i<interface_anzahl && i<MAX_INTERFACES; i++) {
142 free(p_interfaces[i]);
144 interface_anzahl = 0;
145 fw1_reset_list_of_if_on_next_begin = FALSE;
149 /* Make entries in Protocol column and Info column on summary display */
150 if (check_col(pinfo->cinfo, COL_PROTOCOL))
151 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FW1");
152 if (check_col(pinfo->cinfo, COL_INFO))
153 col_clear(pinfo->cinfo, COL_INFO);
155 etype = tvb_get_ntohs(tvb, 12);
157 sprintf(header, header1);
159 /* fetch info to local variable */
160 direction[0] = tvb_get_guint8(tvb, 0);
162 chain[0] = tvb_get_guint8(tvb, 1);
165 if (!fw1_with_uuid) {
166 tvb_get_nstringz0(tvb, 2, 6, interface_name);
169 tvb_get_nstringz0(tvb, 2, sizeof interface_name, interface_name);
170 uuid = tvb_get_ntohl(tvb, 8);
173 /* Known interface name - if not, remember it */
175 for (i=0; i<interface_anzahl && i<MAX_INTERFACES; i++) {
176 if ( strcmp(p_interfaces[i], interface_name) == 0 ) {
181 p_interfaces[interface_anzahl] = strdup(interface_name);
184 /* display all interfaces always in the same order */
185 for (i=0; i<interface_anzahl; i++) {
187 if ( strcmp(p_interfaces[i], interface_name) == 0 ) {
190 p_header = header + strlen(header);
191 if (!fw1_iflist_with_chain) {
192 sprintf(p_header, " %c %s %c",
193 found==0 ? (direction[0]=='i' ? 'i' : (direction[0]=='O' ? 'O' : ' ')) : ' ',
195 found==0 ? (direction[0]=='I' ? 'I' : (direction[0]=='o' ? 'o' : ' ')) : ' '
198 sprintf(p_header, " %c%c %s %c%c",
199 found==0 ? (direction[0]=='i' ? 'i' : (direction[0]=='O' ? 'O' : ' ')) : ' ',
200 found==0 ? (direction[0]=='i' ? chain[0] : (direction[0]=='O' ? chain[0] : ' ')) : ' ',
202 found==0 ? (direction[0]=='I' ? 'I' : (direction[0]=='o' ? 'o' : ' ')) : ' ',
203 found==0 ? (direction[0]=='I' ? chain[0] : (direction[0]=='o' ? chain[0] : ' ')) : ' '
208 if (check_col(pinfo->cinfo, COL_IF_DIR))
209 col_add_str(pinfo->cinfo, COL_IF_DIR, header + strlen(header1) + 1);
212 if (!fw1_summary_in_tree) {
213 /* Do not show the summary in Protocol Tree */
214 sprintf(header, header1);
216 ti = proto_tree_add_protocol_format(tree, proto_fw1, tvb, 0, ETH_HEADER_SIZE, header);
218 /* create display subtree for the protocol */
219 fh_tree = proto_item_add_subtree(ti, ett_fw1);
221 proto_tree_add_item(fh_tree, hf_fw1_direction, tvb, 0, 1, FALSE);
222 proto_tree_add_item(fh_tree, hf_fw1_chain, tvb, 1, 1, FALSE);
224 if (!fw1_with_uuid) {
225 proto_tree_add_string_format(fh_tree, hf_fw1_interface,
227 interface_name, "Interface: %s", interface_name);
229 proto_tree_add_string_format(fh_tree, hf_fw1_interface,
231 interface_name, "Interface: %s", interface_name);
232 proto_tree_add_item(fh_tree, hf_fw1_uuid, tvb, 8, 4, FALSE);
235 ethertype(etype, tvb, ETH_HEADER_SIZE, pinfo, tree, fh_tree, hf_fw1_type,
240 proto_register_fw1(void)
242 static hf_register_info hf[] = {
244 { "Direction", "fw1.direction", FT_STRING, BASE_NONE, NULL, 0x0,
245 "Direction", HFILL }},
247 { "Chain Position", "fw1.chain", FT_STRING, BASE_NONE, NULL, 0x0,
248 "Chain Position", HFILL }},
250 { "Interface", "fw1.interface", FT_STRING, BASE_NONE, NULL, 0x0,
251 "Interface", HFILL }},
253 { "UUID", "fw1.uuid", FT_UINT32, BASE_DEC, NULL, 0x0,
255 /* registered here but handled in ethertype.c */
257 { "Type", "fw1.type", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0,
260 /* Setup protocol subtree array */
261 static gint *ett[] = {
264 module_t *fw1_module;
266 /* Register the protocol name and description */
267 proto_fw1 = proto_register_protocol("Checkpoint FW-1", "FW-1", "fw1");
268 /* Required function calls to register the header fields and subtrees used */
269 proto_register_field_array(proto_fw1, hf, array_length(hf));
270 proto_register_subtree_array(ett, array_length(ett));
272 /* Register configuration preferences */
273 fw1_module = prefs_register_protocol(proto_fw1, NULL);
274 prefs_register_bool_preference(fw1_module, "summary_in_tree",
275 "Show FireWall-1 summary in protocol tree",
276 "Whether the FireWall-1 summary line should be shown in the protocol tree",
277 &fw1_summary_in_tree);
278 prefs_register_bool_preference(fw1_module, "with_uuid",
279 "fw monitor file includes UUID",
280 "Whether the fw monitor file includes information of UUID",
282 prefs_register_bool_preference(fw1_module, "iflist_with_chain",
283 "Interface list with chain position",
284 "Whether the interface list includes chain position",
285 &fw1_iflist_with_chain);
287 register_dissector("fw1", dissect_fw1, proto_fw1);
291 proto_reg_handoff_fw1(void)
294 * Get handles for the Ethernet dissectors.
296 eth_handle = find_dissector("eth");