From Didier Gautheron:
[obnox/wireshark/wip.git] / epan / dissectors / packet-symantec.c
1 /* packet-symantec.c
2  * Routines for dissection of packets from the Axent Raptor firewall/
3  * Symantec Enterprise Firewall/Symantec Gateway Security appliance
4  * v2/Symantec Gateway Security appliance v3.
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31
32 #include <epan/packet.h>
33
34 #include <epan/etypes.h>
35
36 static dissector_table_t ethertype_dissector_table;
37
38 /* protocols and header fields */
39 static int proto_symantec = -1;
40 static int hf_symantec_if = -1;
41 static int hf_symantec_etype = -1;
42
43 static gint ett_symantec = -1;
44
45 static void
46 dissect_symantec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
47 {
48         proto_item *ti;
49         proto_tree *symantec_tree = NULL;
50         guint16 etypev2, etypev3;
51         tvbuff_t *next_tvb;
52
53         /*
54          * Symantec records come in two variants:
55          *
56          * The older variant, dating from Axent days and continuing until
57          * the SGS v2.0.1 code level, is 44 bytes long.
58          * The first 4 bytes are the IPv4 address of the interface that
59          * captured the data, followed by 2 bytes of 0, then an Ethernet
60          * type, followed by 36 bytes of 0.
61          *
62          * The newer variant, introduced either in SGS v3.0 or v3.0.1
63          * (possibly in concert with VLAN support), is 56 bytes long.
64          * The first 4 bytes are the IPv4 address of the interface that
65          * captured the data, followed by 6 bytes of 0, then an Ethernet
66          * type, followed by 44 bytes of 0.
67          *
68          * Unfortunately, there is no flag to distiguish between the two
69          * flavours.  The only indication of which flavour you have is the
70          * offset of the ETHERTYPE field.  Fortunately, Symantec didn't
71          * use ETHERTYPE_UNK as a valid value.
72          */
73
74         etypev2 = tvb_get_ntohs(tvb, 6);
75         etypev3 = tvb_get_ntohs(tvb, 10);
76         
77         /* a valid packet can't be both v2 and v3 or neither v2 nor v3, */
78         if ((etypev2 == 0) == (etypev3 == 0))
79                 return;
80                 
81         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Symantec");
82                 
83         if (etypev3 == 0) {     /* SEF and SGS v2 processing */
84                 col_set_str(pinfo->cinfo, COL_INFO, "Symantec Enterprise Firewall");
85                 if (tree) {
86                         ti = proto_tree_add_protocol_format(tree, proto_symantec, tvb,
87                                 0, 44, "Symantec firewall");
88                         symantec_tree = proto_item_add_subtree(ti, ett_symantec);
89                 }
90                 if (tree) {
91                         proto_tree_add_item(symantec_tree, hf_symantec_if, tvb,
92                                 0, 4, FALSE);
93                         proto_tree_add_uint(symantec_tree, hf_symantec_etype, tvb,
94                                 6, 2, etypev2);
95                 }
96                 next_tvb = tvb_new_subset_remaining(tvb, 44);
97                 dissector_try_port(ethertype_dissector_table, etypev2, next_tvb, pinfo,
98                         tree);
99         }
100
101         if (etypev2 == 0) {     /* SGS v3 processing */
102                 col_set_str(pinfo->cinfo, COL_INFO, "Symantec SGS v3");
103                 if (tree) {
104                         ti = proto_tree_add_protocol_format(tree, proto_symantec, tvb,
105                                 0, 56, "Symantec SGSv3");
106                         symantec_tree = proto_item_add_subtree(ti, ett_symantec);
107                 }
108                 if (tree) {
109                         proto_tree_add_item(symantec_tree, hf_symantec_if, tvb,
110                                 0, 4, FALSE);
111                         proto_tree_add_uint(symantec_tree, hf_symantec_etype, tvb,
112                                 10, 2, etypev3);
113                 }
114                 /*
115                  * Dissection of VLAN information will have to wait until
116                  * availability of a capture file from an SGSv3 box using VLAN
117                  * tagging.
118                  */
119                 next_tvb = tvb_new_subset_remaining(tvb, 56);
120                 dissector_try_port(ethertype_dissector_table, etypev3, next_tvb, pinfo,
121                         tree);
122         }
123 }
124
125 void
126 proto_register_symantec(void)
127 {
128         static hf_register_info hf[] = {
129                 { &hf_symantec_if,
130                     { "Interface", "symantec.if", FT_IPv4,  BASE_NONE, NULL, 0x0,
131                         NULL, HFILL }},
132                 { &hf_symantec_etype,
133                     { "Type",    "symantec.type", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0,
134                         NULL, HFILL }},
135         };
136         static gint *ett[] = {
137                 &ett_symantec,
138         };
139
140         proto_symantec = proto_register_protocol("Symantec Enterprise Firewall",
141             "Symantec", "symantec");
142         proto_register_field_array(proto_symantec, hf, array_length(hf));
143         proto_register_subtree_array(ett, array_length(ett));
144 }
145
146 void
147 proto_reg_handoff_symantec(void)
148 {
149         dissector_handle_t symantec_handle;
150
151         ethertype_dissector_table = find_dissector_table("ethertype");
152
153         symantec_handle = create_dissector_handle(dissect_symantec,
154             proto_symantec);
155         dissector_add("wtap_encap", WTAP_ENCAP_SYMANTEC, symantec_handle);
156 }