2 * Routines for disassembly of packets from Linux "cooked mode" captures
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include <epan/arptypes.h>
31 #include <epan/prefs.h>
32 #include <epan/packet.h>
33 #include "packet-sll.h"
34 #include "packet-ipx.h"
35 #include "packet-llc.h"
36 #include "packet-eth.h"
37 #include "packet-ppp.h"
38 #include "packet-gre.h"
39 #include <epan/addr_resolv.h>
40 #include <epan/etypes.h>
42 static int proto_sll = -1;
43 static int hf_sll_pkttype = -1;
44 static int hf_sll_hatype = -1;
45 static int hf_sll_halen = -1;
46 static int hf_sll_src_eth = -1;
47 static int hf_sll_src_ipv4 = -1;
48 static int hf_sll_src_other = -1;
49 static int hf_sll_ltype = -1;
50 static int hf_sll_gretype = -1;
51 static int hf_sll_etype = -1;
52 static int hf_sll_trailer = -1;
54 static gint ett_sll = -1;
57 * A DLT_LINUX_SLL fake link-layer header.
59 #define SLL_HEADER_SIZE 16 /* total header length */
60 #define SLL_ADDRLEN 8 /* length of address field */
63 * The LINUX_SLL_ values for "sll_pkttype".
65 #define LINUX_SLL_HOST 0
66 #define LINUX_SLL_BROADCAST 1
67 #define LINUX_SLL_MULTICAST 2
68 #define LINUX_SLL_OTHERHOST 3
69 #define LINUX_SLL_OUTGOING 4
71 static const value_string packet_type_vals[] = {
72 { LINUX_SLL_HOST, "Unicast to us" },
73 { LINUX_SLL_BROADCAST, "Broadcast" },
74 { LINUX_SLL_MULTICAST, "Multicast" },
75 { LINUX_SLL_OTHERHOST, "Unicast to another host" },
76 { LINUX_SLL_OUTGOING, "Sent by us" },
80 static const value_string ltype_vals[] = {
81 { LINUX_SLL_P_802_3, "Raw 802.3" },
82 { LINUX_SLL_P_ETHERNET, "Ethernet" },
83 { LINUX_SLL_P_802_2, "802.2 LLC" },
84 { LINUX_SLL_P_PPPHDLC, "PPP (HDLC)" },
85 { LINUX_SLL_P_CAN, "CAN" },
89 static dissector_table_t sll_linux_dissector_table;
90 static dissector_table_t gre_dissector_table;
91 static dissector_handle_t data_handle;
94 capture_sll(const guchar *pd, int len, packet_counts *ld)
98 if (!BYTES_ARE_IN_FRAME(0, len, SLL_HEADER_SIZE)) {
102 protocol = pntohs(&pd[14]);
103 if (protocol <= 1536) { /* yes, 1536 - that's how Linux does it */
105 * "proto" is *not* a length field, it's a Linux internal
110 case LINUX_SLL_P_802_2:
114 capture_llc(pd, len, SLL_HEADER_SIZE, ld);
117 case LINUX_SLL_P_ETHERNET:
121 capture_eth(pd, SLL_HEADER_SIZE, len, ld);
124 case LINUX_SLL_P_802_3:
126 * Novell IPX inside 802.3 with no 802.2 LLC
132 case LINUX_SLL_P_PPPHDLC:
136 capture_ppp_hdlc(pd, len, SLL_HEADER_SIZE, ld);
144 capture_ethertype(protocol, pd, SLL_HEADER_SIZE, len, ld);
148 dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
152 guint16 hatype, halen;
156 proto_tree *fh_tree = NULL;
158 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SLL");
159 col_clear(pinfo->cinfo, COL_INFO);
161 pkttype = tvb_get_ntohs(tvb, 0);
164 * Set "pinfo->p2p_dir" if the packet wasn't received
170 case LINUX_SLL_BROADCAST:
171 case LINUX_SLL_MULTICAST:
172 pinfo->p2p_dir = P2P_DIR_RECV;
175 case LINUX_SLL_OUTGOING:
176 pinfo->p2p_dir = P2P_DIR_SENT;
180 if (check_col(pinfo->cinfo, COL_INFO))
181 col_add_str(pinfo->cinfo, COL_INFO,
182 val_to_str(pkttype, packet_type_vals, "Unknown (%u)"));
185 ti = proto_tree_add_protocol_format(tree, proto_sll, tvb, 0,
186 SLL_HEADER_SIZE, "Linux cooked capture");
187 fh_tree = proto_item_add_subtree(ti, ett_sll);
188 proto_tree_add_item(fh_tree, hf_sll_pkttype, tvb, 0, 2, FALSE);
192 * XXX - check the link-layer address type value?
193 * For now, we just assume 6 means Ethernet.
195 hatype = tvb_get_ntohs(tvb, 2);
196 halen = tvb_get_ntohs(tvb, 4);
198 proto_tree_add_uint(fh_tree, hf_sll_hatype, tvb, 2, 2, hatype);
199 proto_tree_add_uint(fh_tree, hf_sll_halen, tvb, 4, 2, halen);
203 src = tvb_get_ptr(tvb, 6, 4);
204 SET_ADDRESS(&pinfo->dl_src, AT_IPv4, 4, src);
205 SET_ADDRESS(&pinfo->src, AT_IPv4, 4, src);
207 proto_tree_add_ipv4(fh_tree, hf_sll_src_ipv4, tvb,
212 src = tvb_get_ptr(tvb, 6, 6);
213 SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src);
214 SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src);
216 proto_tree_add_ether(fh_tree, hf_sll_src_eth, tvb,
224 proto_tree_add_item(fh_tree, hf_sll_src_other, tvb,
225 6, halen > 8 ? 8 : halen, FALSE);
230 protocol = tvb_get_ntohs(tvb, 14);
231 next_tvb = tvb_new_subset_remaining(tvb, SLL_HEADER_SIZE);
232 if (protocol <= 1536) { /* yes, 1536 - that's how Linux does it */
234 * "proto" is *not* a length field, it's a Linux internal
236 * We therefore cannot say how much of the packet will
238 * XXX - do the same thing we do for packets with Ethertypes?
240 proto_tree_add_uint(fh_tree, hf_sll_ltype, tvb, 14, 2,
243 if(!dissector_try_port(sll_linux_dissector_table, protocol,
244 next_tvb, pinfo, tree)) {
245 call_dissector(data_handle, next_tvb, pinfo, tree);
250 proto_tree_add_uint(fh_tree, hf_sll_gretype, tvb, 14, 2,
252 dissector_try_port(gre_dissector_table,
253 protocol, next_tvb, pinfo, tree);
256 ethertype(protocol, tvb, SLL_HEADER_SIZE, pinfo, tree,
257 fh_tree, hf_sll_etype, hf_sll_trailer, 0);
264 proto_register_sll(void)
266 static hf_register_info hf[] = {
268 { "Packet type", "sll.pkttype", FT_UINT16, BASE_DEC,
269 VALS(packet_type_vals), 0x0, NULL, HFILL }},
271 /* ARP hardware type? With Linux extensions? */
273 { "Link-layer address type", "sll.hatype", FT_UINT16, BASE_DEC,
274 NULL, 0x0, NULL, HFILL }},
277 { "Link-layer address length", "sll.halen", FT_UINT16, BASE_DEC,
278 NULL, 0x0, NULL, HFILL }},
280 /* Source address if it's an Ethernet-type address */
282 { "Source", "sll.src.eth", FT_ETHER, BASE_NONE, NULL, 0x0,
283 "Source link-layer address", HFILL }},
285 /* Source address if it's an IPv4 address */
287 { "Source", "sll.src.ipv4", FT_IPv4, BASE_NONE, NULL, 0x0,
288 "Source link-layer address", HFILL }},
290 /* Source address if it's not an Ethernet-type address */
292 { "Source", "sll.src.other", FT_BYTES, BASE_NONE, NULL, 0x0,
293 "Source link-layer address", HFILL }},
295 /* if the protocol field is an internal Linux protocol type */
297 { "Protocol", "sll.ltype", FT_UINT16, BASE_HEX,
298 VALS(ltype_vals), 0x0, "Linux protocol type", HFILL }},
300 /* if the protocol field is a GRE protocol type */
302 { "Protocol", "sll.gretype", FT_UINT16, BASE_HEX,
303 VALS(gre_typevals), 0x0, "GRE protocol type", HFILL }},
305 /* registered here but handled in ethertype.c */
307 { "Protocol", "sll.etype", FT_UINT16, BASE_HEX,
308 VALS(etype_vals), 0x0, "Ethernet protocol type", HFILL }},
311 { "Trailer", "sll.trailer", FT_BYTES, BASE_NONE, NULL, 0x0,
314 static gint *ett[] = {
318 proto_sll = proto_register_protocol("Linux cooked-mode capture",
320 proto_register_field_array(proto_sll, hf, array_length(hf));
321 proto_register_subtree_array(ett, array_length(ett));
323 sll_linux_dissector_table = register_dissector_table (
325 "Linux protocol type",
332 proto_reg_handoff_sll(void)
334 dissector_handle_t sll_handle;
337 * Get handles for the IPX and LLC dissectors.
339 gre_dissector_table = find_dissector_table("gre.proto");
340 data_handle = find_dissector("data");
342 sll_handle = create_dissector_handle(dissect_sll, proto_sll);
343 dissector_add("wtap_encap", WTAP_ENCAP_SLL, sll_handle);