2 * Routines for ISO/OSI End System to Intermediate System
3 * Routing Exchange Protocol ISO 9542.
5 * $Id: packet-esis.c,v 1.31 2003/12/21 05:51:33 jmayer 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.
34 #include <epan/packet.h>
36 #include "packet-osi.h"
37 #include "packet-osi-options.h"
38 #include "packet-esis.h"
41 /* esis base header */
42 static int proto_esis = -1;
44 static int hf_esis_nlpi = -1;
45 static int hf_esis_length = -1;
46 static int hf_esis_version = -1;
47 static int hf_esis_reserved = -1;
48 static int hf_esis_type = -1;
49 static int hf_esis_holdtime = -1;
50 static int hf_esis_checksum = -1;
52 static gint ett_esis = -1;
53 static gint ett_esis_area_addr = -1;
55 static const value_string esis_vals[] = {
56 { ESIS_ESH_PDU, "ES HELLO"},
57 { ESIS_ISH_PDU, "IS HELLO"},
58 { ESIS_RD_PDU, "RD REQUEST"},
61 /* internal prototypes */
63 static void esis_dissect_esh_pdu( guint8 len, tvbuff_t *tvb,
65 static void esis_dissect_ish_pdu( guint8 len, tvbuff_t *tvb,
67 static void esis_dissect_redirect_pdu( guint8 len, tvbuff_t *tvb,
70 /* ################## Descriptions ###########################################*/
71 /* Parameters for the ESH PDU
72 * Source Address Parameter:
74 * Octet: Length: Parameter Type:
75 * 10 1 Number of Source Adresses ( NSAPs served by this Network
76 * 11 1 Source Address Length Indicator ( SAL ) # Entity )
77 * 12-m-1 variable Source Address ( NSAP )
78 * m Options, dissected in osi.c
81 * Parameter for the ISH PDU:
82 * Network Entity Title Parameter:
84 * Octet: Length: Parameter Type:
85 * 10 1 Network Entity Title Length Indicator ( NETL )
86 * 11-m-1 variable Network Entity Title ( NET )
87 * m Options, dissected in osi.c
90 * Parameter for the RD PDU:
91 * When re-directed to an IS:
93 * Octet: Length: Parameter Type:
94 * 10 1 Destination Address Length Indicator ( DAL )
95 * 11>m-1 variable Destination Address ( DA )
96 * m 1 Subnetwork Address Length Indicator ( BSNPAL )
97 * m+1>n-1 variable Subnetwork Address ( BSNPA )
98 * n 1 Network Entity Title Length Indicator ( NETL )
99 * n+1>p-1 variable Network Entity Title ( NET )
100 * p Options, dissected in osi.c
103 * Parameter for the RD PDU:
104 * When re-directed to an ES:
106 * Octet: Length: Parameter Type:
107 * 10 1 Destination Address Length Indicator ( DAL )
108 * 11>m-1 variable Destination Address ( DA )
109 * m 1 Subnetwork Address Length Indicator ( BSNPAL )
110 * m+1>n-1 variable Subnetwork Address ( BSNPA )
111 * n 1 Network Entity Title Length Indicator ( NETL ) == 0
112 * n+1 Options, dissected in osi.c
116 /* ############################ Tool Functions ############################## */
119 /* ############################## Dissection Functions ###################### */
121 * Name: dissect_esis_unknown()
124 * There was some error in the protocol and we are in unknown space
125 * here. Add a tree item to cover the error and go on. Note
126 * that we make sure we don't go off the end of the bleedin packet here!
128 * This is just a copy of isis.c and isis.h, so I keep the stuff also
129 * and adapt the names to cover possible protocol errors! Ive really no
130 * idea wether I need this or not.
133 * tvbuff_t * : tvbuff with packet data.
134 * proto_tree * : tree of display data. May be NULL.
135 * char * : format text
136 * subsequent args : arguments to format
139 * void (may modify proto tree)
142 esis_dissect_unknown( tvbuff_t *tvb, proto_tree *tree, char *fmat, ...){
146 proto_tree_add_text_valist(tree, tvb, 0, -1, fmat, ap);
152 esis_dissect_esh_pdu( guint8 len, tvbuff_t *tvb, proto_tree *tree) {
153 proto_tree *esis_area_tree;
161 offset += ESIS_HDR_FIXED_LENGTH;
163 no_sa = tvb_get_guint8(tvb, offset);
166 ti = proto_tree_add_text( tree, tvb, offset, -1,
167 "Number of Source Addresses (SA, Format: NSAP) : %u", no_sa );
170 esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
171 while ( no_sa-- > 0 ) {
172 sal = (int) tvb_get_guint8(tvb, offset);
174 proto_tree_add_text(esis_area_tree, tvb, offset, 1, "SAL: %2u Octets", sal);
175 proto_tree_add_text(esis_area_tree, tvb, offset + 1, sal,
177 print_nsap_net( tvb_get_ptr(tvb, offset, sal), sal ) );
181 dissect_osi_options( len, tvb, offset, tree );
183 } /* esis_dissect_esh_pdu */
186 esis_dissect_ish_pdu( guint8 len, tvbuff_t *tvb, proto_tree *tree) {
192 offset += ESIS_HDR_FIXED_LENGTH;
194 netl = (int) tvb_get_guint8(tvb, offset);
195 proto_tree_add_text( tree, tvb, offset, netl + 1,
196 "### Network Entity Title Section ###");
197 proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", netl);
198 proto_tree_add_text( tree, tvb, offset, netl,
200 print_nsap_net( tvb_get_ptr(tvb, offset, netl), netl ) );
204 dissect_osi_options( len, tvb, offset, tree );
209 esis_dissect_redirect_pdu( guint8 len, tvbuff_t *tvb, proto_tree *tree) {
215 offset += ESIS_HDR_FIXED_LENGTH;
217 tmpl = (int) tvb_get_guint8(tvb, offset);
218 proto_tree_add_text( tree, tvb, offset, tmpl + 1,
219 "### Destination Address Section ###" );
220 proto_tree_add_text( tree, tvb, offset++, 1, "DAL: %2u Octets", tmpl);
221 proto_tree_add_text( tree, tvb, offset, tmpl,
223 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
226 tmpl = (int) tvb_get_guint8(tvb, offset);
228 proto_tree_add_text( tree, tvb, offset, tmpl + 1,
229 "### Subnetwork Address Section ###");
230 proto_tree_add_text( tree, tvb, offset++, 1, "BSNPAL: %2u Octets", tmpl);
231 proto_tree_add_text( tree, tvb, offset, tmpl,
233 print_system_id( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
236 tmpl = (int) tvb_get_guint8(tvb, offset);
239 proto_tree_add_text( tree, tvb, offset, 1,
240 "### No Network Entity Title Section ###" );
245 proto_tree_add_text( tree, tvb, offset, 1,
246 "### Network Entity Title Section ###" );
247 proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", tmpl );
248 proto_tree_add_text( tree, tvb, offset, tmpl,
250 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
254 dissect_osi_options( len, tvb, offset, tree );
260 * Name: dissect_esis()
263 * Main entry area for esis de-mangling. This will build the
264 * main esis tree data and call the sub-protocols as needed.
267 * tvbuff * : tvbuff referring to packet data
268 * packet_info * : info for current packet
269 * proto_tree * : tree of display data. May be NULL.
272 * void, but we will add to the proto_tree if it is not NULL.
275 dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
276 char *pdu_type_string = NULL;
277 char *pdu_type_format_string = "PDU Type : %s (R:%s%s%s)";
280 proto_tree *esis_tree = NULL;
285 if (check_col(pinfo->cinfo, COL_PROTOCOL))
286 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS");
287 if (check_col(pinfo->cinfo, COL_INFO))
288 col_clear(pinfo->cinfo, COL_INFO);
290 tvb_memcpy(tvb, (guint8 *)&ehdr, 0, sizeof ehdr);
293 ti = proto_tree_add_item(tree, proto_esis, tvb, 0, -1, FALSE);
294 esis_tree = proto_item_add_subtree(ti, ett_esis);
296 if (ehdr.esis_version != ESIS_REQUIRED_VERSION){
297 esis_dissect_unknown(tvb, esis_tree,
298 "Unknown ESIS version (%u vs %u)",
299 ehdr.esis_version, ESIS_REQUIRED_VERSION );
303 if (ehdr.esis_length < ESIS_HDR_FIXED_LENGTH) {
304 esis_dissect_unknown(tvb, esis_tree,
305 "Bogus ESIS length (%u, must be >= %u)",
306 ehdr.esis_length, ESIS_HDR_FIXED_LENGTH );
309 proto_tree_add_uint( esis_tree, hf_esis_nlpi, tvb, 0, 1, ehdr.esis_nlpi );
310 proto_tree_add_uint( esis_tree, hf_esis_length, tvb,
311 1, 1, ehdr.esis_length );
312 proto_tree_add_uint( esis_tree, hf_esis_version, tvb, 2, 1,
314 proto_tree_add_uint( esis_tree, hf_esis_reserved, tvb, 3, 1,
315 ehdr.esis_reserved );
317 pdu_type_string = val_to_str(ehdr.esis_type&OSI_PDU_TYPE_MASK,
318 esis_vals, "Unknown (0x%x)");
320 proto_tree_add_uint_format( esis_tree, hf_esis_type, tvb, 4, 1,
322 pdu_type_format_string,
324 (ehdr.esis_type&BIT_8) ? "1" : "0",
325 (ehdr.esis_type&BIT_7) ? "1" : "0",
326 (ehdr.esis_type&BIT_6) ? "1" : "0");
328 tmp_uint = pntohs( ehdr.esis_holdtime );
329 proto_tree_add_uint_format(esis_tree, hf_esis_holdtime, tvb, 5, 2,
330 tmp_uint, "Holding Time : %u seconds",
333 tmp_uint = pntohs( ehdr.esis_checksum );
335 switch (calc_checksum( tvb, 0, ehdr.esis_length, tmp_uint )) {
338 cksum_status = "Not Used";
342 cksum_status = "Not checkable - not all of packet was captured";
346 cksum_status = "Is good";
350 cksum_status = "Is wrong";
355 g_assert_not_reached();
357 proto_tree_add_uint_format( esis_tree, hf_esis_checksum, tvb, 7, 2,
358 tmp_uint, "Checksum : 0x%x ( %s )",
359 tmp_uint, cksum_status );
364 * Let us make sure we use the same names for all our decodes
365 * here. First, dump the name into info column, and THEN
366 * dispatch the sub-type.
368 if (check_col(pinfo->cinfo, COL_INFO)) {
369 col_add_str(pinfo->cinfo, COL_INFO,
370 val_to_str( ehdr.esis_type&OSI_PDU_TYPE_MASK, esis_vals,
371 "Unknown (0x%x)" ) );
374 variable_len = ehdr.esis_length - ESIS_HDR_FIXED_LENGTH;
376 switch (ehdr.esis_type & OSI_PDU_TYPE_MASK) {
378 esis_dissect_esh_pdu( variable_len, tvb, esis_tree);
381 esis_dissect_ish_pdu( variable_len, tvb, esis_tree);
384 esis_dissect_redirect_pdu( variable_len, tvb, esis_tree);
387 esis_dissect_unknown(tvb, esis_tree,
388 "Unknown ESIS packet type 0x%x",
389 ehdr.esis_type & OSI_PDU_TYPE_MASK );
395 * Name: proto_register_esis()
398 * main register for esis protocol set. We register some display
399 * formats and the protocol module variables.
401 * NOTE: this procedure to autolinked by the makefile process that
411 proto_register_esis(void) {
412 static hf_register_info hf[] = {
414 { "Network Layer Protocol Identifier", "esis.nlpi",
415 FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, "", HFILL }},
417 { "PDU Length ", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
419 { "Version (==1) ", "esis.ver", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
421 { "Reserved(==0) ", "esis.res", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
423 { "PDU Type ", "esis.type", FT_UINT8, BASE_DEC, VALS(esis_vals),
426 { "Holding Time ", "esis.htime", FT_UINT16, BASE_DEC, NULL, 0x0, " s", HFILL }},
428 { "Checksum ", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }}
434 static gint *ett[] = {
439 proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis");
440 proto_register_field_array(proto_esis, hf, array_length(hf));
441 proto_register_subtree_array(ett, array_length(ett));
445 proto_reg_handoff_esis(void)
447 dissector_handle_t esis_handle;
449 esis_handle = create_dissector_handle(dissect_esis, proto_esis);
450 register_dissector("esis", dissect_esis, proto_esis);
451 dissector_add("osinl", NLPID_ISO9542_ESIS, esis_handle);