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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #define NEW_PROTO_TREE_API
30 #include <epan/arptypes.h>
31 #include <epan/prefs.h>
32 #include <epan/packet.h>
33 #include <wsutil/pint.h>
34 #include "packet-sll.h"
35 #include "packet-ipx.h"
36 #include "packet-llc.h"
37 #include "packet-eth.h"
38 #include "packet-ppp.h"
39 #include "packet-gre.h"
40 #include <epan/addr_resolv.h>
41 #include <epan/etypes.h>
44 * A DLT_LINUX_SLL fake link-layer header.
46 #define SLL_HEADER_SIZE 16 /* total header length */
47 #define SLL_ADDRLEN 8 /* length of address field */
50 * The LINUX_SLL_ values for "sll_pkttype".
52 #define LINUX_SLL_HOST 0
53 #define LINUX_SLL_BROADCAST 1
54 #define LINUX_SLL_MULTICAST 2
55 #define LINUX_SLL_OTHERHOST 3
56 #define LINUX_SLL_OUTGOING 4
58 static const value_string packet_type_vals
[] = {
59 { LINUX_SLL_HOST
, "Unicast to us" },
60 { LINUX_SLL_BROADCAST
, "Broadcast" },
61 { LINUX_SLL_MULTICAST
, "Multicast" },
62 { LINUX_SLL_OTHERHOST
, "Unicast to another host" },
63 { LINUX_SLL_OUTGOING
, "Sent by us" },
67 static const value_string ltype_vals
[] = {
68 { LINUX_SLL_P_802_3
, "Raw 802.3" },
69 { LINUX_SLL_P_ETHERNET
, "Ethernet" },
70 { LINUX_SLL_P_802_2
, "802.2 LLC" },
71 { LINUX_SLL_P_PPPHDLC
, "PPP (HDLC)" },
72 { LINUX_SLL_P_CAN
, "CAN" },
73 { LINUX_SLL_P_IRDA_LAP
, "IrDA LAP" },
74 { LINUX_SLL_P_IEEE802154
, "IEEE 802.15.4" },
79 static dissector_handle_t sll_handle
;
81 static header_field_info
*hfi_sll
= NULL
;
83 #define SLL_HFI_INIT HFI_INIT(proto_sll)
85 static header_field_info hfi_sll_pkttype SLL_HFI_INIT
=
86 { "Packet type", "sll.pkttype", FT_UINT16
, BASE_DEC
,
87 VALS(packet_type_vals
), 0x0, NULL
, HFILL
};
89 /* ARP hardware type? With Linux extensions? */
90 static header_field_info hfi_sll_hatype SLL_HFI_INIT
=
91 { "Link-layer address type", "sll.hatype", FT_UINT16
, BASE_DEC
,
92 NULL
, 0x0, NULL
, HFILL
};
94 static header_field_info hfi_sll_halen SLL_HFI_INIT
=
95 { "Link-layer address length", "sll.halen", FT_UINT16
, BASE_DEC
,
96 NULL
, 0x0, NULL
, HFILL
};
98 /* Source address if it's an Ethernet-type address */
99 static header_field_info hfi_sll_src_eth SLL_HFI_INIT
=
100 { "Source", "sll.src.eth", FT_ETHER
, BASE_NONE
,
101 NULL
, 0x0, "Source link-layer address", HFILL
};
103 /* Source address if it's an IPv4 address */
104 static header_field_info hfi_sll_src_ipv4 SLL_HFI_INIT
=
105 { "Source", "sll.src.ipv4", FT_IPv4
, BASE_NONE
,
106 NULL
, 0x0, "Source link-layer address", HFILL
};
108 /* Source address if it's not an Ethernet-type address */
109 static header_field_info hfi_sll_src_other SLL_HFI_INIT
=
110 { "Source", "sll.src.other", FT_BYTES
, BASE_NONE
,
111 NULL
, 0x0, "Source link-layer address", HFILL
};
113 /* if the protocol field is an internal Linux protocol type */
114 static header_field_info hfi_sll_ltype SLL_HFI_INIT
=
115 { "Protocol", "sll.ltype", FT_UINT16
, BASE_HEX
,
116 VALS(ltype_vals
), 0x0, "Linux protocol type", HFILL
};
118 /* if the protocol field is a GRE protocol type */
119 static header_field_info hfi_sll_gretype SLL_HFI_INIT
=
120 { "Protocol", "sll.gretype", FT_UINT16
, BASE_HEX
,
121 VALS(gre_typevals
), 0x0, "GRE protocol type", HFILL
};
123 /* registered here but handled in ethertype.c */
124 static header_field_info hfi_sll_etype SLL_HFI_INIT
=
125 { "Protocol", "sll.etype", FT_UINT16
, BASE_HEX
,
126 VALS(etype_vals
), 0x0, "Ethernet protocol type", HFILL
};
128 static header_field_info hfi_sll_trailer SLL_HFI_INIT
=
129 { "Trailer", "sll.trailer", FT_BYTES
, BASE_NONE
,
130 NULL
, 0x0, NULL
, HFILL
};
133 static gint ett_sll
= -1;
135 static dissector_table_t sll_linux_dissector_table
;
136 static dissector_table_t gre_dissector_table
;
137 static dissector_handle_t data_handle
;
140 capture_sll(const guchar
*pd
, int len
, packet_counts
*ld
)
144 if (!BYTES_ARE_IN_FRAME(0, len
, SLL_HEADER_SIZE
)) {
148 protocol
= pntohs(&pd
[14]);
149 if (protocol
<= 1536) { /* yes, 1536 - that's how Linux does it */
151 * "proto" is *not* a length field, it's a Linux internal
156 case LINUX_SLL_P_802_2
:
160 capture_llc(pd
, len
, SLL_HEADER_SIZE
, ld
);
163 case LINUX_SLL_P_ETHERNET
:
167 capture_eth(pd
, SLL_HEADER_SIZE
, len
, ld
);
170 case LINUX_SLL_P_802_3
:
172 * Novell IPX inside 802.3 with no 802.2 LLC
178 case LINUX_SLL_P_PPPHDLC
:
182 capture_ppp_hdlc(pd
, len
, SLL_HEADER_SIZE
, ld
);
190 capture_ethertype(protocol
, pd
, SLL_HEADER_SIZE
, len
, ld
);
194 dissect_sll(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
198 guint16 hatype
, halen
;
202 proto_tree
*fh_tree
= NULL
;
204 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "SLL");
205 col_clear(pinfo
->cinfo
, COL_INFO
);
207 pkttype
= tvb_get_ntohs(tvb
, 0);
210 * Set "pinfo->p2p_dir" if the packet wasn't received
216 case LINUX_SLL_BROADCAST
:
217 case LINUX_SLL_MULTICAST
:
218 pinfo
->p2p_dir
= P2P_DIR_RECV
;
221 case LINUX_SLL_OUTGOING
:
222 pinfo
->p2p_dir
= P2P_DIR_SENT
;
226 col_add_str(pinfo
->cinfo
, COL_INFO
,
227 val_to_str(pkttype
, packet_type_vals
, "Unknown (%u)"));
230 ti
= proto_tree_add_protocol_format(tree
, hfi_sll
->id
, tvb
, 0,
231 SLL_HEADER_SIZE
, "Linux cooked capture");
232 fh_tree
= proto_item_add_subtree(ti
, ett_sll
);
233 proto_tree_add_item(fh_tree
, &hfi_sll_pkttype
, tvb
, 0, 2, ENC_BIG_ENDIAN
);
237 * XXX - check the link-layer address type value?
238 * For now, we just assume 6 means Ethernet.
240 hatype
= tvb_get_ntohs(tvb
, 2);
241 halen
= tvb_get_ntohs(tvb
, 4);
243 proto_tree_add_uint(fh_tree
, &hfi_sll_hatype
, tvb
, 2, 2, hatype
);
244 proto_tree_add_uint(fh_tree
, &hfi_sll_halen
, tvb
, 4, 2, halen
);
248 src
= tvb_get_ptr(tvb
, 6, 4);
249 SET_ADDRESS(&pinfo
->dl_src
, AT_IPv4
, 4, src
);
250 SET_ADDRESS(&pinfo
->src
, AT_IPv4
, 4, src
);
252 proto_tree_add_item(fh_tree
, &hfi_sll_src_ipv4
, tvb
,
253 6, 4, ENC_BIG_ENDIAN
);
257 src
= tvb_get_ptr(tvb
, 6, 6);
258 SET_ADDRESS(&pinfo
->dl_src
, AT_ETHER
, 6, src
);
259 SET_ADDRESS(&pinfo
->src
, AT_ETHER
, 6, src
);
261 proto_tree_add_ether(fh_tree
, hfi_sll_src_eth
.id
, tvb
,
269 proto_tree_add_item(fh_tree
, &hfi_sll_src_other
, tvb
,
270 6, halen
> 8 ? 8 : halen
, ENC_NA
);
275 protocol
= tvb_get_ntohs(tvb
, 14);
276 next_tvb
= tvb_new_subset_remaining(tvb
, SLL_HEADER_SIZE
);
277 if (protocol
<= 1536) { /* yes, 1536 - that's how Linux does it */
279 * "proto" is *not* a length field, it's a Linux internal
281 * We therefore cannot say how much of the packet will
283 * XXX - do the same thing we do for packets with Ethertypes?
285 proto_tree_add_uint(fh_tree
, &hfi_sll_ltype
, tvb
, 14, 2,
288 if(!dissector_try_uint(sll_linux_dissector_table
, protocol
,
289 next_tvb
, pinfo
, tree
)) {
290 call_dissector(data_handle
, next_tvb
, pinfo
, tree
);
295 proto_tree_add_uint(fh_tree
, &hfi_sll_gretype
, tvb
, 14, 2,
297 dissector_try_uint(gre_dissector_table
,
298 protocol
, next_tvb
, pinfo
, tree
);
301 ethertype(protocol
, tvb
, SLL_HEADER_SIZE
, pinfo
, tree
,
302 fh_tree
, hfi_sll_etype
.id
, hfi_sll_trailer
.id
, 0);
309 proto_register_sll(void)
311 #ifndef HAVE_HFI_SECTION_INIT
312 static header_field_info
*hfi
[] = {
314 /* ARP hardware type? With Linux extensions? */
322 /* registered here but handled in ethertype.c */
328 static gint
*ett
[] = {
334 proto_sll
= proto_register_protocol("Linux cooked-mode capture",
336 hfi_sll
= proto_registrar_get_nth(proto_sll
);
338 proto_register_fields(proto_sll
, hfi
, array_length(hfi
));
339 proto_register_subtree_array(ett
, array_length(ett
));
341 sll_handle
= create_dissector_handle(dissect_sll
, proto_sll
);
343 sll_linux_dissector_table
= register_dissector_table (
345 "Linux SLL protocol type",
352 proto_reg_handoff_sll(void)
355 * Get handles for the IPX and LLC dissectors.
357 gre_dissector_table
= find_dissector_table("gre.proto");
358 data_handle
= find_dissector("data");
360 dissector_add_uint("wtap_encap", WTAP_ENCAP_SLL
, sll_handle
);