2 * Routines for ISO/OSI End System to Intermediate System
3 * Routing Exchange Protocol ISO 9542.
5 * $Id: packet-esis.c,v 1.24 2002/04/07 22:00: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,
69 static void esis_dissect_ish_pdu( u_char len, tvbuff_t *tvb,
71 static void esis_dissect_redirect_pdu( u_char len, tvbuff_t *tvb,
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 * tvbuff_t * : tvbuff with packet data.
138 * proto_tree * : tree of display data. May be NULL.
139 * char * : format text
140 * subsequent args : arguments to format
143 * void (may modify proto tree)
146 esis_dissect_unknown( tvbuff_t *tvb, proto_tree *tree, char *fmat, ...){
150 proto_tree_add_text_valist(tree, tvb, 0, -1, fmat, ap);
156 esis_dissect_esh_pdu( u_char len, tvbuff_t *tvb, proto_tree *tree) {
157 proto_tree *esis_area_tree;
165 offset += ESIS_HDR_FIXED_LENGTH;
167 no_sa = tvb_get_guint8(tvb, offset);
170 ti = proto_tree_add_text( tree, tvb, offset, -1,
171 "Number of Source Addresses (SA, Format: NSAP) : %u", no_sa );
174 esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
175 while ( no_sa-- > 0 ) {
176 sal = (int) tvb_get_guint8(tvb, offset);
178 proto_tree_add_text(esis_area_tree, tvb, offset, 1, "SAL: %2u Octets", sal);
179 proto_tree_add_text(esis_area_tree, tvb, offset + 1, sal,
181 print_nsap_net( tvb_get_ptr(tvb, offset, sal), sal ) );
185 dissect_osi_options( PDU_TYPE_ESIS_ESH, len, tvb, offset, tree );
187 } /* esis_dissect_esh_pdu */ ;
190 esis_dissect_ish_pdu( u_char len, tvbuff_t *tvb, proto_tree *tree) {
196 offset += ESIS_HDR_FIXED_LENGTH;
198 netl = (int) tvb_get_guint8(tvb, offset);
199 proto_tree_add_text( tree, tvb, offset, netl + 1,
200 "### Network Entity Title Section ###");
201 proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", netl);
202 proto_tree_add_text( tree, tvb, offset, netl,
204 print_nsap_net( tvb_get_ptr(tvb, offset, netl), netl ) );
208 dissect_osi_options( PDU_TYPE_ESIS_ISH, len, tvb, offset, tree );
213 esis_dissect_redirect_pdu( u_char len, tvbuff_t *tvb, proto_tree *tree) {
219 offset += ESIS_HDR_FIXED_LENGTH;
221 tmpl = (int) tvb_get_guint8(tvb, offset);
222 proto_tree_add_text( tree, tvb, offset, tmpl + 1,
223 "### Destination Address Section ###" );
224 proto_tree_add_text( tree, tvb, offset++, 1, "DAL: %2u Octets", tmpl);
225 proto_tree_add_text( tree, tvb, offset, tmpl,
227 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
230 tmpl = (int) tvb_get_guint8(tvb, offset);
232 proto_tree_add_text( tree, tvb, offset, tmpl + 1,
233 "### Subnetwork Address Section ###");
234 proto_tree_add_text( tree, tvb, offset++, 1, "BSNPAL: %2u Octets", tmpl);
235 proto_tree_add_text( tree, tvb, offset, tmpl,
237 print_system_id( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
240 tmpl = (int) tvb_get_guint8(tvb, offset);
243 proto_tree_add_text( tree, tvb, offset, 1,
244 "### No Network Entity Title Section ###" );
249 proto_tree_add_text( tree, tvb, offset, 1,
250 "### Network Entity Title Section ###" );
251 proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", tmpl );
252 proto_tree_add_text( tree, tvb, offset, tmpl,
254 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
258 dissect_osi_options( PDU_TYPE_ESIS_RD, len, tvb, offset, tree );
264 * Name: dissect_esis()
267 * Main entry area for esis de-mangling. This will build the
268 * main esis tree data and call the sub-protocols as needed.
271 * tvbuff * : tvbuff referring to packet data
272 * packet_info * : info for current packet
273 * proto_tree * : tree of display data. May be NULL.
276 * void, but we will add to the proto_tree if it is not NULL.
279 dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
280 char *pdu_type_string = NULL;
281 char *pdu_type_format_string = "PDU Type : %s (R:%s%s%s)";
284 proto_tree *esis_tree = NULL;
285 int variable_len = 0;
289 if (check_col(pinfo->cinfo, COL_PROTOCOL))
290 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS");
291 if (check_col(pinfo->cinfo, COL_INFO))
292 col_clear(pinfo->cinfo, COL_INFO);
294 tvb_memcpy(tvb, (guint8 *)&ehdr, 0, sizeof ehdr);
297 ti = proto_tree_add_item(tree, proto_esis, tvb, 0, -1, FALSE);
298 esis_tree = proto_item_add_subtree(ti, ett_esis);
300 if (ehdr.esis_version != ESIS_REQUIRED_VERSION){
301 esis_dissect_unknown(tvb, esis_tree,
302 "Unknown ESIS version (%u vs %u)",
303 ehdr.esis_version, ESIS_REQUIRED_VERSION );
307 proto_tree_add_uint( esis_tree, hf_esis_nlpi, tvb, 0, 1, ehdr.esis_nlpi );
308 proto_tree_add_uint( esis_tree, hf_esis_length, tvb,
309 1, 1, ehdr.esis_length );
310 proto_tree_add_uint( esis_tree, hf_esis_version, tvb, 2, 1,
312 proto_tree_add_uint( esis_tree, hf_esis_reserved, tvb, 3, 1,
313 ehdr.esis_reserved );
315 pdu_type_string = val_to_str(ehdr.esis_type&OSI_PDU_TYPE_MASK,
316 esis_vals, "Unknown (0x%x)");
318 proto_tree_add_uint_format( esis_tree, hf_esis_type, tvb, 4, 1,
320 pdu_type_format_string,
322 (ehdr.esis_type&BIT_8) ? "1" : "0",
323 (ehdr.esis_type&BIT_7) ? "1" : "0",
324 (ehdr.esis_type&BIT_6) ? "1" : "0");
326 tmp_uint = pntohs( ehdr.esis_holdtime );
327 proto_tree_add_uint_format(esis_tree, hf_esis_holdtime, tvb, 5, 2,
328 tmp_uint, "Holding Time : %u seconds",
331 tmp_uint = pntohs( ehdr.esis_checksum );
333 switch (calc_checksum( tvb, 0, ehdr.esis_length, tmp_uint )) {
336 cksum_status = "Not Used";
340 cksum_status = "Not checkable - not all of packet was captured";
344 cksum_status = "Is good";
348 cksum_status = "Is wrong";
353 g_assert_not_reached();
355 proto_tree_add_uint_format( esis_tree, hf_esis_checksum, tvb, 7, 2,
356 tmp_uint, "Checksum : 0x%x ( %s )",
357 tmp_uint, cksum_status );
362 * Let us make sure we use the same names for all our decodes
363 * here. First, dump the name into info column, and THEN
364 * dispatch the sub-type.
366 if (check_col(pinfo->cinfo, COL_INFO)) {
367 col_add_str(pinfo->cinfo, COL_INFO,
368 val_to_str( ehdr.esis_type&OSI_PDU_TYPE_MASK, esis_vals,
369 "Unknown (0x%x)" ) );
372 variable_len = ehdr.esis_length - ESIS_HDR_FIXED_LENGTH;
374 switch (ehdr.esis_type & OSI_PDU_TYPE_MASK) {
376 esis_dissect_esh_pdu( variable_len, tvb, esis_tree);
379 esis_dissect_ish_pdu( variable_len, tvb, esis_tree);
382 esis_dissect_redirect_pdu( variable_len, tvb, esis_tree);
385 esis_dissect_unknown(tvb, esis_tree,
386 "Unknown ESIS packet type 0x%x",
387 ehdr.esis_type & OSI_PDU_TYPE_MASK );
393 * Name: proto_register_esis()
396 * main register for esis protocol set. We register some display
397 * formats and the protocol module variables.
399 * NOTE: this procedure to autolinked by the makefile process that
409 proto_register_esis(void) {
410 static hf_register_info hf[] = {
412 { "Network Layer Protocol Identifier", "esis.nlpi",
413 FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, "", HFILL }},
415 { "PDU Length ", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
417 { "Version (==1) ", "esis.ver", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
419 { "Reserved(==0) ", "esis.res", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
421 { "PDU Type ", "esis.type", FT_UINT8, BASE_DEC, VALS(esis_vals),
424 { "Holding Time ", "esis.htime", FT_UINT16, BASE_DEC, NULL, 0x0, " s", HFILL }},
426 { "Checksum ", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }}
432 static gint *ett[] = {
437 proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis");
438 proto_register_field_array(proto_esis, hf, array_length(hf));
439 proto_register_subtree_array(ett, array_length(ett));
443 proto_reg_handoff_esis(void)
445 dissector_handle_t esis_handle;
447 esis_handle = create_dissector_handle(dissect_esis, proto_esis);
448 dissector_add("osinl", NLPID_ISO9542_ESIS, esis_handle);