2 * Routines for Cisco HDLC packet disassembly
4 * $Id: packet-chdlc.c,v 1.19 2003/01/27 19:28:52 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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/packet.h>
32 #include "chdlctypes.h"
33 #include <epan/resolv.h>
34 #include "packet-chdlc.h"
35 #include "packet-ip.h"
38 * See section 4.3.1 of RFC 1547, and
40 * http://www.nethelp.no/net/cisco-hdlc.txt
43 static int proto_chdlc = -1;
44 static int hf_chdlc_addr = -1;
45 static int hf_chdlc_proto = -1;
47 static gint ett_chdlc = -1;
49 static int proto_slarp = -1;
50 static int hf_slarp_ptype = -1;
51 static int hf_slarp_address = -1;
52 static int hf_slarp_mysequence = -1;
53 static int hf_slarp_yoursequence = -1;
55 static gint ett_slarp = -1;
57 static dissector_handle_t data_handle;
60 * Protocol types for the Cisco HDLC format.
62 * As per the above, according to RFC 1547, these are "standard 16 bit
63 * Ethernet protocol type code[s]", but 0x8035 is Reverse ARP, and
64 * that is (at least according to the Linux ISDN code) not the
65 * same as Cisco SLARP.
67 * In addition, 0x2000 is apparently the Cisco Discovery Protocol, but
68 * on Ethernet those are encapsulated inside SNAP with an OUI of
69 * OUI_CISCO, not OUI_ENCAP_ETHER.
71 * Perhaps we should set up a protocol table for those protocols
72 * that differ between Ethernet and Cisco HDLC, and have the PPP
73 * code first try that table and, if it finds nothing in that
74 * table, call "ethertype()". (Unfortunately, that means that -
75 * assuming we had a Cisco SLARP dissector - said dissector were
76 * disabled, SLARP packets would be dissected as Reverse ARP
77 * packets, not as data.)
79 #define CISCO_SLARP 0x8035 /* Cisco SLARP protocol */
81 static dissector_table_t subdissector_table;
83 static const value_string chdlc_address_vals[] = {
84 {CHDLC_ADDR_UNICAST, "Unicast"},
85 {CHDLC_ADDR_MULTICAST, "Multicast"},
89 const value_string chdlc_vals[] = {
90 {0x2000, "Cisco Discovery Protocol"},
92 {CISCO_SLARP, "SLARP"},
93 {ETHERTYPE_DEC_LB, "DEC LanBridge"},
94 {CHDLCTYPE_BPDU, "Spanning Tree BPDU"},
95 {ETHERTYPE_ATALK, "Appletalk"},
96 {ETHERTYPE_AARP, "AARP"},
97 {ETHERTYPE_IPX, "Netware IPX/SPX"},
98 {ETHERTYPE_ETHBRIDGE, "Transparent Ethernet bridging" },
99 {CHDLCTYPE_OSI, "OSI" },
100 {ETHERTYPE_MPLS, "MPLS unicast"},
101 {ETHERTYPE_MPLS_MULTI, "MPLS multicast"},
106 capture_chdlc( const guchar *pd, int offset, int len, packet_counts *ld ) {
107 if (!BYTES_ARE_IN_FRAME(offset, len, 2)) {
111 switch (pntohs(&pd[offset + 2])) {
113 capture_ip(pd, offset + 4, len, ld);
122 chdlctype(guint16 chdlctype, tvbuff_t *tvb, int offset_after_chdlctype,
123 packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
129 proto_tree_add_uint(fh_tree, chdlctype_id, tvb,
130 offset_after_chdlctype - 2, 2, chdlctype);
133 next_tvb = tvb_new_subset(tvb, offset_after_chdlctype, -1, -1);
135 /* do lookup with the subdissector table */
136 if (!dissector_try_port(subdissector_table, chdlctype, next_tvb, pinfo, tree)) {
137 if (check_col(pinfo->cinfo, COL_PROTOCOL))
138 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "0x%04x", chdlctype);
139 call_dissector(data_handle,next_tvb, pinfo, tree);
144 dissect_chdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
147 proto_tree *fh_tree = NULL;
151 if (check_col(pinfo->cinfo, COL_PROTOCOL))
152 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CHDLC");
153 if (check_col(pinfo->cinfo, COL_INFO))
154 col_clear(pinfo->cinfo, COL_INFO);
156 switch (pinfo->p2p_dir) {
159 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
160 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
161 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
162 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
166 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
167 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
168 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
169 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
173 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
174 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A");
175 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
176 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A");
180 addr = tvb_get_guint8(tvb, 0);
181 proto = tvb_get_ntohs(tvb, 2);
184 ti = proto_tree_add_item(tree, proto_chdlc, tvb, 0, 4, FALSE);
185 fh_tree = proto_item_add_subtree(ti, ett_chdlc);
187 proto_tree_add_uint(fh_tree, hf_chdlc_addr, tvb, 0, 1, addr);
190 chdlctype(proto, tvb, 4, pinfo, tree, fh_tree, hf_chdlc_proto);
194 proto_register_chdlc(void)
196 static hf_register_info hf[] = {
198 { "Address", "chdlc.address", FT_UINT8, BASE_HEX,
199 VALS(chdlc_address_vals), 0x0, "", HFILL }},
201 { "Protocol", "chdlc.protocol", FT_UINT16, BASE_HEX,
202 VALS(chdlc_vals), 0x0, "", HFILL }},
204 static gint *ett[] = {
208 proto_chdlc = proto_register_protocol("Cisco HDLC", "CHDLC", "chdlc");
209 proto_register_field_array(proto_chdlc, hf, array_length(hf));
210 proto_register_subtree_array(ett, array_length(ett));
212 /* subdissector code */
213 subdissector_table = register_dissector_table("chdlctype",
214 "Cisco HDLC frame type", FT_UINT16, BASE_HEX);
216 register_dissector("chdlc", dissect_chdlc, proto_chdlc);
220 proto_reg_handoff_chdlc(void)
222 dissector_handle_t chdlc_handle;
224 data_handle = find_dissector("data");
225 chdlc_handle = find_dissector("chdlc");
226 dissector_add("wtap_encap", WTAP_ENCAP_CHDLC, chdlc_handle);
229 #define SLARP_REQUEST 0
230 #define SLARP_REPLY 1
231 #define SLARP_LINECHECK 2
233 static const value_string slarp_ptype_vals[] = {
234 {SLARP_REQUEST, "Request"},
235 {SLARP_REPLY, "Reply"},
236 {SLARP_LINECHECK, "Line keepalive"},
241 dissect_slarp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
244 proto_tree *slarp_tree = NULL;
248 guint32 yoursequence;
250 if (check_col(pinfo->cinfo, COL_PROTOCOL))
251 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SLARP");
252 if (check_col(pinfo->cinfo, COL_INFO))
253 col_clear(pinfo->cinfo, COL_INFO);
255 code = tvb_get_ntohl(tvb, 0);
258 ti = proto_tree_add_item(tree, proto_slarp, tvb, 0, 14, FALSE);
259 slarp_tree = proto_item_add_subtree(ti, ett_slarp);
266 if (check_col(pinfo->cinfo, COL_INFO)) {
267 tvb_memcpy(tvb, (guint8 *)&address, 4, 4);
268 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, from %s, mask %s",
269 match_strval(code, slarp_ptype_vals),
270 get_hostname(address),
271 ip_to_str(tvb_get_ptr(tvb, 8, 4)));
274 proto_tree_add_uint(slarp_tree, hf_slarp_ptype, tvb, 0, 4, code);
275 proto_tree_add_item(slarp_tree, hf_slarp_address, tvb, 4, 4, FALSE);
276 proto_tree_add_text(slarp_tree, tvb, 8, 4,
277 "Netmask: %s", ip_to_str(tvb_get_ptr(tvb, 8, 4)));
281 case SLARP_LINECHECK:
282 mysequence = tvb_get_ntohl(tvb, 4);
283 yoursequence = tvb_get_ntohl(tvb, 8);
284 if (check_col(pinfo->cinfo, COL_INFO)) {
285 col_add_fstr(pinfo->cinfo, COL_INFO,
286 "%s, outgoing sequence %u, returned sequence %u",
287 match_strval(code, slarp_ptype_vals),
288 mysequence, yoursequence);
291 proto_tree_add_uint(slarp_tree, hf_slarp_ptype, tvb, 0, 4, code);
292 proto_tree_add_uint(slarp_tree, hf_slarp_mysequence, tvb, 4, 4,
294 proto_tree_add_uint(slarp_tree, hf_slarp_mysequence, tvb, 8, 4,
300 if (check_col(pinfo->cinfo, COL_INFO))
301 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown packet type 0x%08X", code);
303 proto_tree_add_uint(slarp_tree, hf_slarp_ptype, tvb, 0, 4, code);
304 call_dissector(data_handle, tvb_new_subset(tvb, 4, -1, -1), pinfo,
312 proto_register_slarp(void)
314 static hf_register_info hf[] = {
316 { "Packet type", "slarp.ptype", FT_UINT32, BASE_DEC,
317 VALS(slarp_ptype_vals), 0x0, "", HFILL }},
319 { "Address", "slarp.address", FT_IPv4, BASE_NONE,
320 NULL, 0x0, "", HFILL }},
321 /* XXX - need an FT_ for netmasks, which is like FT_IPV4 but doesn't
322 get translated to a host name. */
323 { &hf_slarp_mysequence,
324 { "Outgoing sequence number", "slarp.mysequence", FT_UINT32, BASE_DEC,
325 NULL, 0x0, "", HFILL }},
326 { &hf_slarp_yoursequence,
327 { "Returned sequence number", "slarp.yoursequence", FT_UINT32, BASE_DEC,
328 NULL, 0x0, "", HFILL }},
330 static gint *ett[] = {
335 proto_slarp = proto_register_protocol("Cisco SLARP", "SLARP", "slarp");
336 proto_register_field_array(proto_slarp, hf, array_length(hf));
337 proto_register_subtree_array(ett, array_length(ett));
341 proto_reg_handoff_slarp(void)
343 dissector_handle_t slarp_handle;
345 slarp_handle = create_dissector_handle(dissect_slarp, proto_slarp);
346 dissector_add("chdlctype", CISCO_SLARP, slarp_handle);