2 * Routines for ISO/OSI End System to Intermediate System
3 * Routing Exchange Protocol ISO 9542.
5 * $Id: packet-esis.c,v 1.20 2002/01/21 07:36:34 guy Exp $
6 * Ralf Schneider <Ralf.Schneider@t-online.de>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
38 #include <epan/packet.h>
40 #include "packet-osi.h"
41 #include "packet-osi-options.h"
42 #include "packet-esis.h"
45 /* esis base header */
46 static int proto_esis = -1;
48 static int hf_esis_nlpi = -1;
49 static int hf_esis_length = -1;
50 static int hf_esis_version = -1;
51 static int hf_esis_reserved = -1;
52 static int hf_esis_type = -1;
53 static int hf_esis_holdtime = -1;
54 static int hf_esis_checksum = -1;
56 static gint ett_esis = -1;
57 static gint ett_esis_area_addr = -1;
59 static const value_string esis_vals[] = {
60 { ESIS_ESH_PDU, "ES HELLO"},
61 { ESIS_ISH_PDU, "IS HELLO"},
62 { ESIS_RD_PDU, "RD REQUEST"},
65 /* internal prototypes */
67 static void esis_dissect_esh_pdu( u_char len, tvbuff_t *tvb,
68 packet_info *pinfo, proto_tree *treepd);
69 static void esis_dissect_ish_pdu( u_char len, tvbuff_t *tvb,
70 packet_info *pinfo, proto_tree *tree);
71 static void esis_dissect_redirect_pdu( u_char len, tvbuff_t *tvb,
72 packet_info *pinfo, proto_tree *tree);
74 /* ################## Descriptions ###########################################*/
75 /* Parameters for the ESH PDU
76 * Source Address Parameter:
78 * Octet: Length: Parameter Type:
79 * 10 1 Number of Source Adresses ( NSAPs served by this Network
80 * 11 1 Source Address Length Indicator ( SAL ) # Entity )
81 * 12-m-1 variable Source Address ( NSAP )
82 * m Options, dissected in osi.c
85 * Parameter for the ISH PDU:
86 * Network Entity Title Parameter:
88 * Octet: Length: Parameter Type:
89 * 10 1 Network Entity Title Length Indicator ( NETL )
90 * 11-m-1 variable Network Entity Title ( NET )
91 * m Options, dissected in osi.c
94 * Parameter for the RD PDU:
95 * When re-directed to an IS:
97 * Octet: Length: Parameter Type:
98 * 10 1 Destination Address Length Indicator ( DAL )
99 * 11>m-1 variable Destination Address ( DA )
100 * m 1 Subnetwork Address Length Indicator ( BSNPAL )
101 * m+1>n-1 variable Subnetwork Address ( BSNPA )
102 * n 1 Network Entity Title Length Indicator ( NETL )
103 * n+1>p-1 variable Network Entity Title ( NET )
104 * p Options, dissected in osi.c
107 * Parameter for the RD PDU:
108 * When re-directed to an ES:
110 * Octet: Length: Parameter Type:
111 * 10 1 Destination Address Length Indicator ( DAL )
112 * 11>m-1 variable Destination Address ( DA )
113 * m 1 Subnetwork Address Length Indicator ( BSNPAL )
114 * m+1>n-1 variable Subnetwork Address ( BSNPA )
115 * n 1 Network Entity Title Length Indicator ( NETL ) == 0
116 * n+1 Options, dissected in osi.c
120 /* ############################ Tool Functions ############################## */
123 /* ############################## Dissection Functions ###################### */
125 * Name: dissect_esis_unknown()
128 * There was some error in the protocol and we are in unknown space
129 * here. Add a tree item to cover the error and go on. Note
130 * that we make sure we don't go off the end of the bleedin packet here!
132 * This is just a copy of isis.c and isis.h, so I keep the stuff also
133 * and adapt the names to cover possible protocol errors! Ive really no
134 * idea wether I need this or not.
137 * int offset : Current offset into packet data.
138 * int len : length of to dump.
139 * proto_tree * : tree of display data. May be NULL.
140 * frame_data * fd : frame data
141 * char * : format text
144 * void (may modify proto tree)
147 esis_dissect_unknown( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
152 proto_tree_add_text_valist(tree, tvb, 0, tvb_length(tvb), fmat, ap);
158 esis_dissect_esh_pdu( u_char len, tvbuff_t *tvb, packet_info *pinfo,
160 proto_tree *esis_area_tree;
168 offset += ESIS_HDR_FIXED_LENGTH;
170 no_sa = tvb_get_guint8(tvb, offset);
173 ti = proto_tree_add_text( tree, tvb, offset, tvb_length_remaining(tvb, offset),
174 "Number of Source Addresses (SA, Format: NSAP) : %u", no_sa );
177 esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
178 while ( no_sa-- > 0 ) {
179 sal = (int) tvb_get_guint8(tvb, offset);
181 proto_tree_add_text(esis_area_tree, tvb, offset, 1, "SAL: %2u Octets", sal);
182 proto_tree_add_text(esis_area_tree, tvb, offset + 1, sal,
184 print_nsap_net( tvb_get_ptr(tvb, offset, sal), sal ) );
188 dissect_osi_options( PDU_TYPE_ESIS_ESH, len, tvb, offset, pinfo, tree );
190 } /* esis_dissect_esh_pdu */ ;
193 esis_dissect_ish_pdu( u_char len, tvbuff_t *tvb, packet_info *pinfo,
200 offset += ESIS_HDR_FIXED_LENGTH;
202 netl = (int) tvb_get_guint8(tvb, offset);
203 proto_tree_add_text( tree, tvb, offset, netl + 1,
204 "### Network Entity Titel Section ###");
205 proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", netl);
206 proto_tree_add_text( tree, tvb, offset, netl,
208 print_nsap_net( tvb_get_ptr(tvb, offset, netl), netl ) );
212 dissect_osi_options( PDU_TYPE_ESIS_ISH, len, tvb, offset, pinfo, tree );
217 esis_dissect_redirect_pdu( u_char len, tvbuff_t *tvb, packet_info *pinfo,
224 offset += ESIS_HDR_FIXED_LENGTH;
226 tmpl = (int) tvb_get_guint8(tvb, offset);
227 proto_tree_add_text( tree, tvb, offset, tmpl + 1,
228 "### Destination Address Section ###" );
229 proto_tree_add_text( tree, tvb, offset++, 1, "DAL: %2u Octets", tmpl);
230 proto_tree_add_text( tree, tvb, offset, tmpl,
232 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
235 tmpl = (int) tvb_get_guint8(tvb, offset);
237 proto_tree_add_text( tree, tvb, offset, tmpl + 1,
238 "### Subnetwork Address Section ###");
239 proto_tree_add_text( tree, tvb, offset++, 1, "BSNPAL: %2u Octets", tmpl);
240 proto_tree_add_text( tree, tvb, offset, tmpl,
242 print_system_id( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
245 tmpl = (int) tvb_get_guint8(tvb, offset);
248 proto_tree_add_text( tree, tvb, offset, 1,
249 "### No Network Entity Title Section ###" );
254 proto_tree_add_text( tree, tvb, offset, 1,
255 "### Network Entity Title Section ###" );
256 proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", tmpl );
257 proto_tree_add_text( tree, tvb, offset, tmpl,
259 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
263 dissect_osi_options( PDU_TYPE_ESIS_RD, len, tvb, offset, pinfo, tree );
269 * Name: dissect_esis()
272 * Main entry area for esis de-mangling. This will build the
273 * main esis tree data and call the sub-protocols as needed.
276 * tvbuff * : tvbuff referring to packet data
277 * frame_data * : frame data (whole packet with extra info)
278 * proto_tree * : tree of display data. May be NULL.
281 * void, but we will add to the proto_tree if it is not NULL.
284 dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
285 char *pdu_type_string = NULL;
286 char *pdu_type_format_string = "PDU Type : %s (R:%s%s%s)";
289 proto_tree *esis_tree = NULL;
290 int variable_len = 0;
294 if (check_col(pinfo->cinfo, COL_PROTOCOL))
295 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS");
296 if (check_col(pinfo->cinfo, COL_INFO))
297 col_clear(pinfo->cinfo, COL_INFO);
299 tvb_memcpy(tvb, (guint8 *)&ehdr, 0, sizeof ehdr);
302 ti = proto_tree_add_item(tree, proto_esis, tvb, 0, tvb_length(tvb), FALSE);
303 esis_tree = proto_item_add_subtree(ti, ett_esis);
305 if (ehdr.esis_version != ESIS_REQUIRED_VERSION){
306 esis_dissect_unknown(tvb, pinfo, esis_tree,
307 "Unknown ESIS version (%u vs %u)",
308 ehdr.esis_version, ESIS_REQUIRED_VERSION );
312 proto_tree_add_uint( esis_tree, hf_esis_nlpi, tvb, 0, 1, ehdr.esis_nlpi );
313 proto_tree_add_uint( esis_tree, hf_esis_length, tvb,
314 1, 1, ehdr.esis_length );
315 proto_tree_add_uint( esis_tree, hf_esis_version, tvb, 2, 1,
317 proto_tree_add_uint( esis_tree, hf_esis_reserved, tvb, 3, 1,
318 ehdr.esis_reserved );
320 pdu_type_string = val_to_str(ehdr.esis_type&OSI_PDU_TYPE_MASK,
321 esis_vals, "Unknown (0x%x)");
323 proto_tree_add_uint_format( esis_tree, hf_esis_type, tvb, 4, 1,
325 pdu_type_format_string,
327 (ehdr.esis_type&BIT_8) ? "1" : "0",
328 (ehdr.esis_type&BIT_7) ? "1" : "0",
329 (ehdr.esis_type&BIT_6) ? "1" : "0");
331 tmp_uint = pntohs( ehdr.esis_holdtime );
332 proto_tree_add_uint_format(esis_tree, hf_esis_holdtime, tvb, 5, 2,
333 tmp_uint, "Holding Time : %u seconds",
336 tmp_uint = pntohs( ehdr.esis_checksum );
338 switch (calc_checksum( tvb, 0, ehdr.esis_length, tmp_uint )) {
341 cksum_status = "Not Used";
345 cksum_status = "Not checkable - not all of packet was captured";
349 cksum_status = "Is good";
353 cksum_status = "Is wrong";
358 g_assert_not_reached();
360 proto_tree_add_uint_format( esis_tree, hf_esis_checksum, tvb, 7, 2,
361 tmp_uint, "Checksum : 0x%x ( %s )",
362 tmp_uint, cksum_status );
367 * Let us make sure we use the same names for all our decodes
368 * here. First, dump the name into info column, and THEN
369 * dispatch the sub-type.
371 if (check_col(pinfo->cinfo, COL_INFO)) {
372 col_add_str(pinfo->cinfo, COL_INFO,
373 val_to_str( ehdr.esis_type&OSI_PDU_TYPE_MASK, esis_vals,
374 "Unknown (0x%x)" ) );
377 variable_len = ehdr.esis_length - ESIS_HDR_FIXED_LENGTH;
379 switch (ehdr.esis_type & OSI_PDU_TYPE_MASK) {
381 esis_dissect_esh_pdu( variable_len, tvb, pinfo, esis_tree);
384 esis_dissect_ish_pdu( variable_len, tvb, pinfo, esis_tree);
387 esis_dissect_redirect_pdu( variable_len, tvb, pinfo,
391 esis_dissect_unknown(tvb, pinfo, esis_tree,
392 "Unknown ESIS packet type 0x%x",
393 ehdr.esis_type & OSI_PDU_TYPE_MASK );
399 * Name: proto_register_esis()
402 * main register for esis protocol set. We register some display
403 * formats and the protocol module variables.
405 * NOTE: this procedure to autolinked by the makefile process that
415 proto_register_esis(void) {
416 static hf_register_info hf[] = {
418 { "Network Layer Protocol Identifier", "esis.nlpi",
419 FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, "", HFILL }},
421 { "PDU Length ", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
423 { "Version (==1) ", "esis.ver", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
425 { "Reserved(==0) ", "esis.res", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
427 { "PDU Type ", "esis.type", FT_UINT8, BASE_DEC, VALS(esis_vals),
430 { "Holding Time ", "esis.htime", FT_UINT16, BASE_DEC, NULL, 0x0, " s", HFILL }},
432 { "Checksum ", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }}
438 static gint *ett[] = {
443 proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis");
444 proto_register_field_array(proto_esis, hf, array_length(hf));
445 proto_register_subtree_array(ett, array_length(ett));
449 proto_reg_handoff_esis(void)
451 dissector_handle_t esis_handle;
453 esis_handle = create_dissector_handle(dissect_esis, proto_esis);
454 dissector_add("osinl", NLPID_ISO9542_ESIS, esis_handle);