2 * Routines for ISO/OSI End System to Intermediate System
3 * Routeing Exchange Protocol ISO 9542.
5 * $Id: packet-esis.c,v 1.6 2000/08/10 16:04:33 deniel Exp $
6 * Ralf Schneider <Ralf.Schneider@t-online.de>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
43 #include "packet-osi.h"
44 #include "packet-osi-options.h"
45 #include "packet-esis.h"
48 /* esis base header */
49 static int proto_esis = -1;
51 static int hf_esis_nlpi = -1;
52 static int hf_esis_length = -1;
53 static int hf_esis_version = -1;
54 static int hf_esis_reserved = -1;
55 static int hf_esis_type = -1;
56 static int hf_esis_holdtime = -1;
57 static int hf_esis_checksum = -1;
59 static gint ett_esis = -1;
60 static gint ett_esis_area_addr = -1;
62 static const value_string esis_vals[] = {
63 { ESIS_ESH_PDU, "ES HELLO"},
64 { ESIS_ISH_PDU, "IS HELLO"},
65 { ESIS_RD_PDU, "RD REQUEST"},
68 /* internal prototypes */
70 void esis_dissect_esh_pdu( u_char len, const u_char *pd, int offset,
71 frame_data *fd, proto_tree *treepd);
72 void esis_dissect_ish_pdu( u_char len, const u_char *pd, int offset,
73 frame_data *fd, proto_tree *tree);
74 void esis_dissect_redirect_pdu( u_char len, const u_char *pd, int offset,
75 frame_data *fd, proto_tree *tree);
77 /* ################## Descriptions ###########################################*/
78 /* Parameters for the ESH PDU
79 * Source Address Parameter:
81 * Octet: Length: Parameter Type:
82 * 10 1 Number of Source Adresses ( NSAPs served by this Network
83 * 11 1 Source Address Length Indicator ( SAL ) # Entity )
84 * 12-m-1 variable Source Address ( NSAP )
85 * m Options, dissected in osi.c
88 * Parameter for the ISH PDU:
89 * Network Entity Title Parameter:
91 * Octet: Length: Parameter Type:
92 * 10 1 Network Entity Title Length Indicator ( NETL )
93 * 11-m-1 variable Network Entity Title ( NET )
94 * m Options, dissected in osi.c
97 * Parameter for the RD PDU:
98 * When re-directed to an IS:
100 * Octet: Length: Parameter Type:
101 * 10 1 Destination Address Length Indicator ( DAL )
102 * 11>m-1 variable Destination Address ( DA )
103 * m 1 Subnetwork Address Length Indicator ( BSNPAL )
104 * m+1>n-1 variable Subnetwork Address ( BSNPA )
105 * n 1 Network Entity Title Length Indicator ( NETL )
106 * n+1>p-1 variable Network Entity Title ( NET )
107 * p Options, dissected in osi.c
110 * Parameter for the RD PDU:
111 * When re-directed to an ES:
113 * Octet: Length: Parameter Type:
114 * 10 1 Destination Address Length Indicator ( DAL )
115 * 11>m-1 variable Destination Address ( DA )
116 * m 1 Subnetwork Address Length Indicator ( BSNPAL )
117 * m+1>n-1 variable Subnetwork Address ( BSNPA )
118 * n 1 Network Entity Title Length Indicator ( NETL ) == 0
119 * n+1 Options, dissected in osi.c
123 /* ############################ Tool Functions ############################## */
126 /* ############################## Dissection Functions ###################### */
128 * Name: dissect_esis_unknown()
131 * There was some error in the protocol and we are in unknown space
132 * here. Add a tree item to cover the error and go on. Note
133 * that we make sure we don't go off the end of the bleedin packet here!
135 * This is just a copy of isis.c and isis.h, so I keep the stuff also
136 * and adapt the names to cover possible protocol errors! Ive really no
137 * idea wether I need this or not.
140 * int offset : Current offset into packet data.
141 * int len : length of to dump.
142 * proto_tree * : tree of display data. May be NULL.
143 * frame_data * fd : frame data
144 * char * : format text
147 * void (may modify proto tree)
150 esis_dissect_unknown(int offset,guint length,proto_tree *tree,frame_data *fd,
154 if ( !IS_DATA_IN_FRAME(offset) ) {
156 * big oops They were off the end of the packet already.
157 * Just ignore this one.
161 if ( !BYTES_ARE_IN_FRAME(offset, length) ) {
163 * length will take us past eop. Truncate length.
165 length = END_OF_FRAME;
169 proto_tree_add_text_valist(tree, NullTVB, offset, length, fmat, ap);
175 esis_dissect_esh_pdu( u_char len, const u_char *pd, int offset,
176 frame_data *fd, proto_tree *tree) {
177 proto_tree *esis_area_tree;
184 offset += ESIS_HDR_FIXED_LENGTH;
189 ti = proto_tree_add_text( tree, NullTVB, offset++, END_OF_FRAME,
190 "Number of Source Addresses (SA, Format: NSAP) : %u", no_sa );
192 esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
193 while ( no_sa-- > 0 ) {
194 sal = (int) pd[offset++];
195 proto_tree_add_text(esis_area_tree, NullTVB, offset, 1, "SAL: %2u Octets", sal);
196 proto_tree_add_text(esis_area_tree, NullTVB, offset + 1, sal,
197 " SA: %s", print_nsap_net( &pd[offset], sal ) );
201 dissect_osi_options( PDU_TYPE_ESIS_ESH, len, pd, offset, fd, tree );
203 } /* esis_dissect_esh_pdu */ ;
206 esis_dissect_ish_pdu( u_char len, const u_char *pd, int offset,
207 frame_data *fd, proto_tree *tree) {
212 offset += ESIS_HDR_FIXED_LENGTH;
214 netl = (int) pd[ offset ];
215 proto_tree_add_text( tree, NullTVB, offset, netl + 1,
216 "### Network Entity Titel Section ###");
217 proto_tree_add_text( tree, NullTVB, offset++, 1, "NETL: %2u Octets", netl);
218 proto_tree_add_text( tree, NullTVB, offset, netl,
219 " NET: %s", print_nsap_net( &pd[offset], netl ) );
223 dissect_osi_options( PDU_TYPE_ESIS_ISH, len, pd, offset, fd, tree );
228 esis_dissect_redirect_pdu( u_char len, const u_char *pd, int offset,
229 frame_data *fd, proto_tree *tree) {
234 offset += ESIS_HDR_FIXED_LENGTH;
236 tmpl = (int) pd[ offset ];
237 proto_tree_add_text( tree, NullTVB, offset, tmpl + 1,
238 "### Destination Address Section ###" );
239 proto_tree_add_text( tree, NullTVB, offset++, 1, "DAL: %2u Octets", tmpl);
240 proto_tree_add_text( tree, NullTVB, offset, tmpl,
241 " DA : %s", print_nsap_net( &pd[offset], tmpl ) );
244 tmpl = (int) pd[ offset ];
246 proto_tree_add_text( tree, NullTVB, offset, tmpl + 1,
247 "### Subnetwork Address Section ###");
248 proto_tree_add_text( tree, NullTVB, offset++, 1, "BSNPAL: %2u Octets", tmpl);
249 proto_tree_add_text( tree, NullTVB, offset, tmpl,
250 " BSNPA: %s", print_system_id( &pd[offset], tmpl ) );
253 tmpl = (int) pd[ offset ];
256 proto_tree_add_text( tree, NullTVB, offset, 1,
257 "### No Network Entity Title Section ###" );
262 proto_tree_add_text( tree, NullTVB, offset, 1,
263 "### Network Entity Title Section ###" );
264 proto_tree_add_text( tree, NullTVB, offset++, 1, "NETL: %2u Octets", tmpl );
265 proto_tree_add_text( tree, NullTVB, offset, tmpl,
266 " NET: %s", print_nsap_net( &pd[offset], tmpl ) );
270 dissect_osi_options( PDU_TYPE_ESIS_RD, len, pd, offset, fd, tree );
276 * Name: dissect_esis()
279 * Main entry area for esis de-mangling. This will build the
280 * main esis tree data and call the sub-protocols as needed.
283 * u_char * : packet data
284 * int : offset into packet where we are (packet_data[offset]== start
285 * of what we care about)
286 * frame_data * : frame data (whole packet with extra info)
287 * proto_tree * : tree of display data. May be NULL.
290 * void, but we will add to the proto_tree if it is not NULL.
293 dissect_esis(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
294 char *pdu_type_string = NULL;
295 char *pdu_type_format_string = "PDU Type : %s (R:%s%s%s)";
298 proto_tree *esis_tree = NULL;
299 int variable_len = 0;
302 if (check_col(fd, COL_PROTOCOL))
303 col_add_str(fd, COL_PROTOCOL, "ESIS");
305 if (!BYTES_ARE_IN_FRAME(offset, sizeof(*ehdr))) {
306 esis_dissect_unknown(offset, sizeof(*ehdr), tree, fd,
307 "Not enough capture data for header (%d vs %d)",
308 sizeof(*ehdr), END_OF_FRAME);
312 ehdr = (esis_hdr_t *) &pd[offset];
314 if (ehdr->esis_version != ESIS_REQUIRED_VERSION){
315 esis_dissect_unknown(offset, END_OF_FRAME, tree, fd,
316 "Unknown ESIS version (%d vs %d)",
317 ehdr->esis_version, ESIS_REQUIRED_VERSION );
322 ti = proto_tree_add_item(tree, proto_esis, NullTVB, offset, END_OF_FRAME, FALSE);
323 esis_tree = proto_item_add_subtree(ti, ett_esis);
325 proto_tree_add_uint( esis_tree, hf_esis_nlpi, NullTVB, offset, 1, ehdr->esis_nlpi );
326 proto_tree_add_uint( esis_tree, hf_esis_length, NullTVB,
327 offset + 1, 1, ehdr->esis_length );
328 proto_tree_add_uint( esis_tree, hf_esis_version, NullTVB, offset + 2, 1,
329 ehdr->esis_version );
330 proto_tree_add_uint( esis_tree, hf_esis_reserved, NullTVB, offset + 3, 1,
331 ehdr->esis_reserved );
333 pdu_type_string = val_to_str(ehdr->esis_type&OSI_PDU_TYPE_MASK,
334 esis_vals, "Unknown (0x%x)");
336 proto_tree_add_uint_format( esis_tree, hf_esis_type, NullTVB, offset + 4, 1,
338 pdu_type_format_string,
340 (ehdr->esis_type&BIT_8) ? "1" : "0",
341 (ehdr->esis_type&BIT_7) ? "1" : "0",
342 (ehdr->esis_type&BIT_6) ? "1" : "0");
344 tmp_uint = pntohs( ehdr->esis_holdtime );
345 proto_tree_add_uint_format(esis_tree, hf_esis_holdtime, NullTVB, offset + 5, 2,
346 tmp_uint, "Holding Time : %u seconds",
349 tmp_uint = pntohs( ehdr->esis_checksum );
351 proto_tree_add_uint_format( esis_tree, hf_esis_checksum, NullTVB, offset + 7, 2,
352 tmp_uint, "Checksum : 0x%x ( %s )",
353 tmp_uint, calc_checksum( &pd[offset],
360 * Let us make sure we use the same names for all our decodes
361 * here. First, dump the name into info column, and THEN
362 * dispatch the sub-type.
364 if (check_col(fd, COL_INFO)) {
365 col_add_str(fd, COL_INFO,
366 val_to_str( ehdr->esis_type&OSI_PDU_TYPE_MASK, esis_vals,
367 "Unknown (0x%x)" ) );
370 variable_len = ehdr->esis_length - ESIS_HDR_FIXED_LENGTH;
372 switch (ehdr->esis_type) {
374 esis_dissect_esh_pdu( variable_len, pd, offset, fd, esis_tree);
377 esis_dissect_ish_pdu( variable_len, pd, offset, fd, esis_tree);
380 esis_dissect_redirect_pdu( variable_len, pd, offset, fd,
384 esis_dissect_unknown(offset, END_OF_FRAME, tree, fd,
385 "unknown esis packet type" );
391 * Name: proto_register_esisesis()
394 * main register for esis protocol set. We register some display
395 * formats and the protocol module variables.
397 * NOTE: this procedure to autolinked by the makefile process that
407 proto_register_esis(void) {
408 static hf_register_info hf[] = {
410 { "Network Layer Protocol Identifier", "esis.nlpi",
411 FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, "" }},
413 { "PDU Length ", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
415 { "Version (==1) ", "esis.ver", FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
417 { "Reserved(==0) ", "esis.res", FT_UINT8, BASE_DEC, NULL, 0x0, "" }},
419 { "PDU Type ", "esis.type", FT_UINT8, BASE_DEC, VALS(esis_vals),
422 { "Holding Time ", "esis.htime", FT_UINT16, BASE_DEC, NULL, 0x0, " s"}},
424 { "Checksum ", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, "" }}
430 static gint *ett[] = {
435 proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "esis");
436 proto_register_field_array(proto_esis, hf, array_length(hf));
437 proto_register_subtree_array(ett, array_length(ett));
441 proto_reg_handoff_esis(void)
443 old_dissector_add("osinl", NLPID_ISO9542_ESIS, dissect_esis);