aboutsummaryrefslogtreecommitdiffstats
path: root/packet-esis.c
blob: eda2b055857231763e12d6e620c7dd22f239b7b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* packet-esis.c
 * Routines for ISO/OSI End System to Intermediate System
 * Routing Exchange Protocol ISO 9542.
 *
 * $Id: packet-esis.c,v 1.28 2003/02/25 19:07:07 guy Exp $
 * Ralf Schneider <Ralf.Schneider@t-online.de>
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <epan/packet.h>
#include "nlpid.h"
#include "packet-osi.h"
#include "packet-osi-options.h"
#include "packet-esis.h"


/* esis base header */
static int  proto_esis        = -1;

static int  hf_esis_nlpi      = -1;
static int  hf_esis_length    = -1;
static int  hf_esis_version   = -1;
static int  hf_esis_reserved  = -1;
static int  hf_esis_type      = -1;
static int  hf_esis_holdtime  = -1;
static int  hf_esis_checksum  = -1;

static gint ett_esis              = -1;
static gint ett_esis_area_addr    = -1;

static const value_string esis_vals[] = {
  { ESIS_ESH_PDU, "ES HELLO"},
  { ESIS_ISH_PDU, "IS HELLO"},
  { ESIS_RD_PDU,  "RD REQUEST"},
  { 0,             NULL} };

/* internal prototypes */

static void esis_dissect_esh_pdu( guchar len, tvbuff_t *tvb,
                           proto_tree *treepd);
static void esis_dissect_ish_pdu( guchar len, tvbuff_t *tvb,
                           proto_tree *tree);
static void esis_dissect_redirect_pdu( guchar len, tvbuff_t *tvb,
                           proto_tree *tree);

/* ################## Descriptions ###########################################*/
/* Parameters for the ESH PDU
 * Source Address Parameter:
 *
 * Octet:    Length:   Parameter Type:
 *     10          1   Number of Source Adresses ( NSAPs served by this Network
 *     11          1   Source Address Length Indicator ( SAL )     #    Entity )
 * 12-m-1   variable   Source Address ( NSAP )
 *      m              Options, dissected in osi.c
 *
 *
 * Parameter for the ISH PDU:
 * Network Entity Title Parameter:
 *
 * Octet:    Length:   Parameter Type:
 *     10          1   Network Entity Title Length Indicator ( NETL )
 * 11-m-1   variable   Network Entity Title ( NET )
 *      m              Options, dissected in osi.c
 *
 *
 * Parameter for the RD PDU:
 * When re-directed to an IS:
 *
 *  Octet:   Length:   Parameter Type:
 *      10         1   Destination Address Length Indicator ( DAL )
 *  11>m-1  variable   Destination Address ( DA )
 *       m         1   Subnetwork Address Length Indicator ( BSNPAL )
 * m+1>n-1  variable   Subnetwork Address ( BSNPA )
 *       n         1   Network Entity Title Length Indicator ( NETL )
 * n+1>p-1  variable   Network Entity Title ( NET )
 *       p             Options, dissected in osi.c
 *
 *
 * Parameter for the RD PDU:
 * When re-directed to an ES:
 *
 *  Octet:   Length:   Parameter Type:
 *      10         1   Destination Address Length Indicator ( DAL )
 *  11>m-1  variable   Destination Address ( DA )
 *       m         1   Subnetwork Address Length Indicator ( BSNPAL )
 * m+1>n-1  variable   Subnetwork Address ( BSNPA )
 *       n         1   Network Entity Title Length Indicator ( NETL ) == 0
 *     n+1             Options, dissected in osi.c
 *
 */

/* ############################ Tool Functions ############################## */


/* ############################## Dissection Functions ###################### */
/*
 * Name: dissect_esis_unknown()
 *
 * Description:
 *   There was some error in the protocol and we are in unknown space
 *   here.  Add a tree item to cover the error and go on.  Note
 *   that we make sure we don't go off the end of the bleedin packet here!
 *
 *   This is just a copy of isis.c and isis.h, so I keep the stuff also
 *   and adapt the names to cover possible protocol errors! Ive really no
 *   idea wether I need this or not.
 *
 * Input
 *   tvbuff_t *      : tvbuff with packet data.
 *   proto_tree *    : tree of display data.  May be NULL.
 *   char *          : format text
 *   subsequent args : arguments to format
 *
 * Output:
 *   void (may modify proto tree)
 */
static void
esis_dissect_unknown( tvbuff_t *tvb, proto_tree *tree, char *fmat, ...){
  va_list ap;

  va_start(ap, fmat);
  proto_tree_add_text_valist(tree, tvb, 0, -1, fmat, ap);
  va_end(ap);
}


static void
esis_dissect_esh_pdu( guchar len, tvbuff_t *tvb, proto_tree *tree) {
  proto_tree *esis_area_tree;
  int         offset  = 0;
  int         no_sa   = 0;
  int         sal     = 0;

  proto_item  *ti;

  if (tree) {
    offset += ESIS_HDR_FIXED_LENGTH;

    no_sa  = tvb_get_guint8(tvb, offset);
    len   -= 1;

    ti = proto_tree_add_text( tree, tvb, offset, -1,
            "Number of Source Addresses (SA, Format: NSAP) : %u", no_sa );
    offset++;

    esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
    while ( no_sa-- > 0 ) {
       sal = (int) tvb_get_guint8(tvb, offset);
       offset++;
       proto_tree_add_text(esis_area_tree, tvb, offset, 1, "SAL: %2u Octets", sal);
       proto_tree_add_text(esis_area_tree, tvb, offset + 1, sal,
                           " SA: %s",
			   print_nsap_net( tvb_get_ptr(tvb, offset, sal), sal ) );
       offset += sal;
       len    -= ( sal + 1 );
    }
    dissect_osi_options( len, tvb, offset, tree );
  }
} /* esis_dissect_esh_pdu */ ;

static void
esis_dissect_ish_pdu( guchar len, tvbuff_t *tvb, proto_tree *tree) {

  int   offset  = 0;
  int   netl    = 0;

  if (tree) {
    offset += ESIS_HDR_FIXED_LENGTH;

    netl = (int) tvb_get_guint8(tvb, offset);
    proto_tree_add_text( tree, tvb, offset, netl + 1,
                         "### Network Entity Title Section ###");
    proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", netl);
    proto_tree_add_text( tree, tvb, offset, netl,
                           " NET: %s",
			   print_nsap_net( tvb_get_ptr(tvb, offset, netl), netl ) );
    offset += netl;
    len    -= ( netl + 1 );

    dissect_osi_options( len, tvb, offset, tree );
  }
};

static void
esis_dissect_redirect_pdu( guchar len, tvbuff_t *tvb, proto_tree *tree) {

  int   offset  = 0;
  int   tmpl    = 0;

  if (tree) {
    offset += ESIS_HDR_FIXED_LENGTH;

    tmpl = (int) tvb_get_guint8(tvb, offset);
    proto_tree_add_text( tree, tvb, offset, tmpl + 1,
                         "### Destination Address Section ###" );
    proto_tree_add_text( tree, tvb, offset++, 1, "DAL: %2u Octets", tmpl);
    proto_tree_add_text( tree, tvb, offset, tmpl,
                         " DA : %s",
			 print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
    offset += tmpl;
    len    -= ( tmpl + 1 );
    tmpl    = (int) tvb_get_guint8(tvb, offset);

    proto_tree_add_text( tree, tvb, offset, tmpl + 1,
                         "###  Subnetwork Address Section ###");
    proto_tree_add_text( tree, tvb, offset++, 1, "BSNPAL: %2u Octets", tmpl);
    proto_tree_add_text( tree, tvb, offset, tmpl,
                           " BSNPA: %s",
			   print_system_id( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
    offset += tmpl;
    len    -= ( tmpl + 1 );
    tmpl    = (int) tvb_get_guint8(tvb, offset);

    if ( 0 == tmpl ) {
      proto_tree_add_text( tree, tvb, offset, 1,
                           "### No Network Entity Title Section ###" );
      offset++;
      len--;
    }
    else {
      proto_tree_add_text( tree, tvb, offset, 1,
                           "### Network Entity Title Section ###" );
      proto_tree_add_text( tree, tvb, offset++, 1, "NETL: %2u Octets", tmpl );
      proto_tree_add_text( tree, tvb, offset, tmpl,
                           " NET: %s",
			   print_nsap_net( tvb_get_ptr(tvb, offset, tmpl), tmpl ) );
      offset += tmpl;
      len    -= ( tmpl + 1 );
    }
    dissect_osi_options( len, tvb, offset, tree );
  }
}


/*
 * Name: dissect_esis()
 *
 * Description:
 *   Main entry area for esis de-mangling.  This will build the
 *   main esis tree data and call the sub-protocols as needed.
 *
 * Input:
 *   tvbuff *      : tvbuff referring to packet data
 *   packet_info * : info for current packet
 *   proto_tree *  : tree of display data.  May be NULL.
 *
 * Output:
 *   void, but we will add to the proto_tree if it is not NULL.
 */
static void
dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
   char       *pdu_type_string        = NULL;
   char       *pdu_type_format_string = "PDU Type      : %s (R:%s%s%s)";
   esis_hdr_t  ehdr;
   proto_item *ti;
   proto_tree *esis_tree    = NULL;
   int         variable_len = 0;
   guint       tmp_uint     = 0;
   char       *cksum_status;

   if (check_col(pinfo->cinfo, COL_PROTOCOL))
     col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS");
   if (check_col(pinfo->cinfo, COL_INFO))
     col_clear(pinfo->cinfo, COL_INFO);

   tvb_memcpy(tvb, (guint8 *)&ehdr, 0, sizeof ehdr);

   if (tree) {
     ti = proto_tree_add_item(tree, proto_esis, tvb, 0, -1, FALSE);
     esis_tree = proto_item_add_subtree(ti, ett_esis);

     if (ehdr.esis_version != ESIS_REQUIRED_VERSION){
       esis_dissect_unknown(tvb, esis_tree,
                          "Unknown ESIS version (%u vs %u)",
                           ehdr.esis_version, ESIS_REQUIRED_VERSION );
       return;
     }

     proto_tree_add_uint( esis_tree, hf_esis_nlpi, tvb, 0, 1, ehdr.esis_nlpi );
     proto_tree_add_uint( esis_tree, hf_esis_length, tvb,
                          1, 1, ehdr.esis_length );
     proto_tree_add_uint( esis_tree, hf_esis_version, tvb, 2, 1,
                          ehdr.esis_version );
     proto_tree_add_uint( esis_tree, hf_esis_reserved, tvb, 3, 1,
                          ehdr.esis_reserved );

     pdu_type_string = val_to_str(ehdr.esis_type&OSI_PDU_TYPE_MASK,
                                  esis_vals, "Unknown (0x%x)");

     proto_tree_add_uint_format( esis_tree, hf_esis_type, tvb, 4, 1,
                                 ehdr.esis_type,
                                 pdu_type_format_string,
                                 pdu_type_string,
                                 (ehdr.esis_type&BIT_8) ? "1" : "0",
                                 (ehdr.esis_type&BIT_7) ? "1" : "0",
                                 (ehdr.esis_type&BIT_6) ? "1" : "0");

     tmp_uint = pntohs( ehdr.esis_holdtime );
     proto_tree_add_uint_format(esis_tree, hf_esis_holdtime, tvb, 5, 2,
                                tmp_uint, "Holding Time  : %u seconds",
                                tmp_uint );

     tmp_uint = pntohs( ehdr.esis_checksum );

     switch (calc_checksum( tvb, 0, ehdr.esis_length, tmp_uint )) {

     case NO_CKSUM:
	cksum_status = "Not Used";
	break;

     case DATA_MISSING:
	cksum_status = "Not checkable - not all of packet was captured";
	break;

     case CKSUM_OK:
	cksum_status = "Is good";
	break;

     case CKSUM_NOT_OK:
	cksum_status = "Is wrong";
	break;

     default:
	cksum_status = NULL;
	g_assert_not_reached();
     }
     proto_tree_add_uint_format( esis_tree, hf_esis_checksum, tvb, 7, 2,
                                 tmp_uint, "Checksum      : 0x%x ( %s )",
                                 tmp_uint, cksum_status );
   }


   /*
    * Let us make sure we use the same names for all our decodes
    * here.  First, dump the name into info column, and THEN
    * dispatch the sub-type.
    */
   if (check_col(pinfo->cinfo, COL_INFO)) {
     col_add_str(pinfo->cinfo, COL_INFO,
                 val_to_str( ehdr.esis_type&OSI_PDU_TYPE_MASK, esis_vals,
                             "Unknown (0x%x)" ) );
   }

   variable_len = ehdr.esis_length - ESIS_HDR_FIXED_LENGTH;

   switch (ehdr.esis_type & OSI_PDU_TYPE_MASK) {
     case ESIS_ESH_PDU:
          esis_dissect_esh_pdu( variable_len, tvb, esis_tree);
     break;
     case ESIS_ISH_PDU:
          esis_dissect_ish_pdu( variable_len, tvb, esis_tree);
     break;
     case ESIS_RD_PDU:
          esis_dissect_redirect_pdu( variable_len, tvb, esis_tree);
     break;
     default:
         esis_dissect_unknown(tvb, esis_tree,
			      "Unknown ESIS packet type 0x%x",
			      ehdr.esis_type & OSI_PDU_TYPE_MASK );
   }
} /* dissect_esis */


/*
 * Name: proto_register_esis()
 *
 * Description:
 *	main register for esis protocol set.  We register some display
 *	formats and the protocol module variables.
 *
 * 	NOTE: this procedure to autolinked by the makefile process that
 *	builds register.c
 *
 * Input:
 *	void
 *
 * Output:
 *	void
 */
void
proto_register_esis(void) {
  static hf_register_info hf[] = {
    { &hf_esis_nlpi,
      { "Network Layer Protocol Identifier", "esis.nlpi",
        FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, "", HFILL }},
    { &hf_esis_length,
      { "PDU Length    ", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
    { &hf_esis_version,
      { "Version (==1) ", "esis.ver",    FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
    { &hf_esis_reserved,
      { "Reserved(==0) ", "esis.res",    FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }},
    { &hf_esis_type,
      { "PDU Type      ", "esis.type",   FT_UINT8, BASE_DEC, VALS(esis_vals),
         0xff, "", HFILL }},
    { &hf_esis_holdtime,
      { "Holding Time  ", "esis.htime",  FT_UINT16, BASE_DEC, NULL, 0x0, " s", HFILL }},
    { &hf_esis_checksum,
      { "Checksum      ", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }}
  };
  /*
   *
   *
   */
  static gint *ett[] = {
    &ett_esis,
    &ett_esis_area_addr,
  };

  proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis");
  proto_register_field_array(proto_esis, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));
};

void
proto_reg_handoff_esis(void)
{
  dissector_handle_t esis_handle;

  esis_handle = create_dissector_handle(dissect_esis, proto_esis);
  register_dissector("esis", dissect_esis, proto_esis);
  dissector_add("osinl", NLPID_ISO9542_ESIS, esis_handle);
}