Coverage Report

Created: 2026-08-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-esis.c
Line
Count
Source
1
/* packet-esis.c
2
 * Routines for ISO/OSI End System to Intermediate System
3
 * Routing Exchange Protocol ISO 9542.
4
 *
5
 * Ralf Schneider <Ralf.Schneider@t-online.de>
6
 *
7
 * Wireshark - Network traffic analyzer
8
 * By Gerald Combs <gerald@wireshark.org>
9
 * Copyright 1998 Gerald Combs
10
 *
11
 * SPDX-License-Identifier: GPL-2.0-or-later
12
 */
13
14
#include "config.h"
15
16
#include <epan/packet.h>
17
#include <epan/expert.h>
18
#include <epan/unit_strings.h>
19
#include "packet-osi.h"
20
#include "packet-osi-options.h"
21
22
/* The version we support is 1 */
23
543
#define ESIS_REQUIRED_VERSION    1
24
25
/* ESIS PDU types */
26
134
#define ESIS_ESH_PDU    02
27
22
#define ESIS_ISH_PDU    04
28
21
#define ESIS_RD_PDU     06
29
30
/* The length of the fixed part */
31
854
#define ESIS_HDR_FIXED_LENGTH 9
32
33
void proto_register_esis(void);
34
void proto_reg_handoff_esis(void);
35
36
/* esis base header */
37
static int  proto_esis;
38
39
static int  hf_esis_nlpi;
40
static int  hf_esis_length;
41
static int  hf_esis_version;
42
static int  hf_esis_reserved;
43
static int  hf_esis_type;
44
static int  hf_esis_holdtime;
45
static int  hf_esis_checksum;
46
static int  hf_esis_checksum_status;
47
/* Generated from convert_proto_tree_add_text.pl */
48
static int hf_esis_dal;
49
static int hf_esis_number_of_source_addresses;
50
static int hf_esis_netl;
51
static int hf_esis_sal;
52
static int hf_esis_sa;
53
static int hf_esis_bsnpal;
54
static int hf_esis_net;
55
static int hf_esis_da;
56
static int hf_esis_bsnpa;
57
58
static int ett_esis;
59
static int ett_esis_area_addr;
60
static int ett_esis_network;
61
static int ett_esis_dest_addr;
62
static int ett_esis_subnetwork;
63
64
65
static expert_field ei_esis_version;
66
static expert_field ei_esis_length;
67
static expert_field ei_esis_type;
68
static expert_field ei_esis_checksum;
69
70
static dissector_handle_t esis_handle;
71
72
static const value_string esis_vals[] = {
73
  { ESIS_ESH_PDU, "ES HELLO"},
74
  { ESIS_ISH_PDU, "IS HELLO"},
75
  { ESIS_RD_PDU,  "RD REQUEST"},
76
  { 0,             NULL} };
77
78
/* ################## Descriptions ###########################################*/
79
/* Parameters for the ESH PDU
80
 * Source Address Parameter:
81
 *
82
 * Octet:    Length:   Parameter Type:
83
 *     10          1   Number of Source Addresses ( NSAPs served by this Network
84
 *     11          1   Source Address Length Indicator ( SAL )     #    Entity )
85
 * 12-m-1   variable   Source Address ( NSAP )
86
 *      m              Options, dissected in osi.c
87
 *
88
 *
89
 * Parameter for the ISH PDU:
90
 * Network Entity Title Parameter:
91
 *
92
 * Octet:    Length:   Parameter Type:
93
 *     10          1   Network Entity Title Length Indicator ( NETL )
94
 * 11-m-1   variable   Network Entity Title ( NET )
95
 *      m              Options, dissected in osi.c
96
 *
97
 *
98
 * Parameter for the RD PDU:
99
 * When re-directed to an IS:
100
 *
101
 *  Octet:   Length:   Parameter Type:
102
 *      10         1   Destination Address Length Indicator ( DAL )
103
 *  11>m-1  variable   Destination Address ( DA )
104
 *       m         1   Subnetwork Address Length Indicator ( BSNPAL )
105
 * m+1>n-1  variable   Subnetwork Address ( BSNPA )
106
 *       n         1   Network Entity Title Length Indicator ( NETL )
107
 * n+1>p-1  variable   Network Entity Title ( NET )
108
 *       p             Options, dissected in osi.c
109
 *
110
 *
111
 * Parameter for the RD PDU:
112
 * When re-directed to an ES:
113
 *
114
 *  Octet:   Length:   Parameter Type:
115
 *      10         1   Destination Address Length Indicator ( DAL )
116
 *  11>m-1  variable   Destination Address ( DA )
117
 *       m         1   Subnetwork Address Length Indicator ( BSNPAL )
118
 * m+1>n-1  variable   Subnetwork Address ( BSNPA )
119
 *       n         1   Network Entity Title Length Indicator ( NETL ) == 0
120
 *     n+1             Options, dissected in osi.c
121
 *
122
 */
123
124
/* ############################ Tool Functions ############################## */
125
126
127
static void
128
134
esis_dissect_esh_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) {
129
134
    proto_tree *esis_area_tree;
130
134
    int         offset  = 0;
131
134
    unsigned    no_sa, sal;
132
133
134
    proto_item  *ti;
134
135
134
    offset += ESIS_HDR_FIXED_LENGTH;
136
137
134
    ti = proto_tree_add_item_ret_uint( tree, hf_esis_number_of_source_addresses, tvb, offset, 1, ENC_NA, &no_sa);
138
134
    len--;
139
134
    offset++;
140
141
134
    esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
142
2.26k
    while ( no_sa-- > 0 ) {
143
2.12k
      proto_tree_add_item_ret_uint(esis_area_tree, hf_esis_sal, tvb, offset, 1, ENC_NA, &sal);
144
2.12k
      offset++;
145
2.12k
      proto_tree_add_string(esis_area_tree, hf_esis_sa, tvb, offset, sal, print_nsap_net( pinfo->pool, tvb, offset, sal ) );
146
2.12k
      offset += sal;
147
2.12k
      len    -= ( sal + 1 );
148
2.12k
    }
149
134
    dissect_osi_options( len, tvb, offset, tree, pinfo );
150
151
134
} /* esis_dissect_esh_pdu */
152
153
static void
154
22
esis_dissect_ish_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) {
155
156
22
    int   offset  = 0;
157
22
    int   netl    = 0;
158
22
    proto_tree* network_tree;
159
160
22
    offset += ESIS_HDR_FIXED_LENGTH;
161
162
22
    netl = (int) tvb_get_uint8(tvb, offset);
163
22
    network_tree = proto_tree_add_subtree( tree, tvb, offset, netl + 1, ett_esis_network, NULL,
164
22
                         "### Network Entity Title Section ###");
165
22
    proto_tree_add_uint(network_tree, hf_esis_netl, tvb, offset++, 1, netl);
166
22
    proto_tree_add_string(network_tree, hf_esis_net, tvb, offset, netl, print_nsap_net( pinfo->pool, tvb, offset, netl ) );
167
22
    offset += netl;
168
22
    len    -= ( netl + 1 );
169
170
22
    dissect_osi_options( len, tvb, offset, network_tree, pinfo );
171
22
}
172
173
static void
174
21
esis_dissect_redirect_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) {
175
176
21
    int   offset  = 0;
177
21
    int   tmpl    = 0;
178
21
    proto_tree *dest_tree, *subnet_tree, *network_tree;
179
180
21
    offset += ESIS_HDR_FIXED_LENGTH;
181
182
21
    tmpl = (int) tvb_get_uint8(tvb, offset);
183
21
    dest_tree = proto_tree_add_subtree( tree, tvb, offset, tmpl + 1, ett_esis_dest_addr, NULL,
184
21
                         "### Destination Address Section ###" );
185
21
    proto_tree_add_uint(dest_tree, hf_esis_dal, tvb, offset++, 1, tmpl);
186
21
    proto_tree_add_string( dest_tree, hf_esis_da, tvb, offset, tmpl,
187
21
                         print_nsap_net( pinfo->pool, tvb, offset, tmpl ) );
188
21
    offset += tmpl;
189
21
    len    -= ( tmpl + 1 );
190
21
    tmpl    = (int) tvb_get_uint8(tvb, offset);
191
192
21
    subnet_tree = proto_tree_add_subtree( tree, tvb, offset, tmpl + 1, ett_esis_subnetwork, NULL,
193
21
                         "###  Subnetwork Address Section ###");
194
21
    proto_tree_add_uint(subnet_tree, hf_esis_bsnpal, tvb, offset++, 1, tmpl);
195
21
    proto_tree_add_item(subnet_tree, hf_esis_bsnpa, tvb, offset, tmpl, ENC_NA);
196
21
    offset += tmpl;
197
21
    len    -= ( tmpl + 1 );
198
21
    tmpl    = (int) tvb_get_uint8(tvb, offset);
199
200
21
    if ( 0 == tmpl ) {
201
2
      network_tree = proto_tree_add_subtree( tree, tvb, offset, 1, ett_esis_network, NULL,
202
2
                           "### No Network Entity Title Section ###" );
203
2
      offset++;
204
2
      len--;
205
2
    }
206
19
    else {
207
19
      network_tree = proto_tree_add_subtree( tree, tvb, offset, 1, ett_esis_network, NULL,
208
19
                           "### Network Entity Title Section ###" );
209
19
      proto_tree_add_uint(network_tree, hf_esis_netl, tvb, offset++, 1, tmpl);
210
19
      proto_tree_add_string( network_tree, hf_esis_net, tvb, offset, tmpl,
211
19
                           print_nsap_net( pinfo->pool, tvb, offset, tmpl ) );
212
19
      offset += tmpl;
213
19
      len    -= ( tmpl + 1 );
214
19
    }
215
21
    dissect_osi_options( len, tvb, offset, network_tree, pinfo );
216
21
}
217
218
219
/*
220
 * Name: dissect_esis()
221
 *
222
 * Description:
223
 *   Main entry area for esis de-mangling.  This will build the
224
 *   main esis tree data and call the sub-protocols as needed.
225
 *
226
 * Input:
227
 *   tvbuff *      : tvbuff referring to packet data
228
 *   packet_info * : info for current packet
229
 *   proto_tree *  : tree of display data.  May be NULL.
230
 *
231
 * Output:
232
 *   void, but we will add to the proto_tree if it is not NULL.
233
 */
234
static int
235
274
dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
236
274
  uint8_t version, length;
237
274
  proto_item *ti, *type_item;
238
274
  proto_tree *esis_tree    = NULL;
239
274
  uint8_t     variable_len, type;
240
274
  uint16_t    checksum;
241
242
274
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS");
243
274
  col_clear(pinfo->cinfo, COL_INFO);
244
245
274
    ti = proto_tree_add_item(tree, proto_esis, tvb, 0, -1, ENC_NA);
246
274
    esis_tree = proto_item_add_subtree(ti, ett_esis);
247
248
274
    proto_tree_add_item( esis_tree, hf_esis_nlpi, tvb, 0, 1, ENC_BIG_ENDIAN);
249
274
    ti = proto_tree_add_item( esis_tree, hf_esis_length, tvb, 1, 1, ENC_BIG_ENDIAN );
250
274
    length = tvb_get_uint8(tvb, 1);
251
274
    if (length < ESIS_HDR_FIXED_LENGTH) {
252
129
      expert_add_info_format(pinfo, ti, &ei_esis_length,
253
129
                           "Bogus ESIS length (%u, must be >= %u)",
254
129
                           length, ESIS_HDR_FIXED_LENGTH );
255
129
    }
256
257
274
    version = tvb_get_uint8(tvb, 2);
258
274
    ti = proto_tree_add_item( esis_tree, hf_esis_version, tvb, 2, 1, ENC_BIG_ENDIAN);
259
274
    if (version != ESIS_REQUIRED_VERSION){
260
269
      expert_add_info_format(pinfo, ti, &ei_esis_version,
261
269
                           "Unknown ESIS version (%u vs %u)",
262
269
                           version, ESIS_REQUIRED_VERSION );
263
269
    }
264
265
274
    proto_tree_add_item( esis_tree, hf_esis_reserved, tvb, 3, 1, ENC_BIG_ENDIAN);
266
267
274
    type_item = proto_tree_add_item( esis_tree, hf_esis_type, tvb, 4, 1, ENC_BIG_ENDIAN);
268
274
    type = tvb_get_uint8(tvb, 4) & OSI_PDU_TYPE_MASK;
269
270
274
    proto_tree_add_item(esis_tree, hf_esis_holdtime, tvb, 5, 2, ENC_BIG_ENDIAN);
271
272
274
    checksum = tvb_get_ntohs(tvb, 7);
273
274
    if (checksum == 0) {
274
        /* No checksum present */
275
19
        proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NOT_PRESENT);
276
255
    } else {
277
255
        uint32_t c0 = 0, c1 = 0;
278
279
255
        if (osi_calc_checksum(tvb, 0, length, &c0, &c1)) {
280
            /* Successfully processed checksum, verify it */
281
217
            proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, hf_esis_checksum_status, &ei_esis_checksum, pinfo, c0 | c1, ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_ZERO);
282
217
        } else {
283
38
            proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, hf_esis_checksum_status, &ei_esis_checksum, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
284
38
        }
285
255
    }
286
287
  /*
288
   * Let us make sure we use the same names for all our decodes
289
   * here.  First, dump the name into info column, and THEN
290
   * dispatch the sub-type.
291
   */
292
274
  col_add_str(pinfo->cinfo, COL_INFO,
293
274
                val_to_str(pinfo->pool, type, esis_vals,
294
274
                            "Unknown (0x%x)" ) );
295
296
274
  variable_len = length - ESIS_HDR_FIXED_LENGTH;
297
298
274
  switch (type) {
299
134
  case ESIS_ESH_PDU:
300
134
    esis_dissect_esh_pdu( variable_len, tvb, esis_tree, pinfo);
301
134
    break;
302
22
  case ESIS_ISH_PDU:
303
22
    esis_dissect_ish_pdu( variable_len, tvb, esis_tree, pinfo);
304
22
    break;
305
21
  case ESIS_RD_PDU:
306
21
    esis_dissect_redirect_pdu( variable_len, tvb, esis_tree, pinfo);
307
21
    break;
308
96
  default:
309
96
    expert_add_info(pinfo, type_item, &ei_esis_type);
310
274
  }
311
100
  return tvb_captured_length(tvb);
312
274
} /* dissect_esis */
313
314
315
/*
316
 * Name: proto_register_esis()
317
 *
318
 * Description:
319
 *      main register for esis protocol set.  We register some display
320
 *      formats and the protocol module variables.
321
 *
322
 *      NOTE: this procedure to autolinked by the makefile process that
323
 *      builds register.c
324
 *
325
 * Input:
326
 *      void
327
 *
328
 * Output:
329
 *      void
330
 */
331
void
332
16
proto_register_esis(void) {
333
16
  static hf_register_info hf[] = {
334
16
    { &hf_esis_nlpi,
335
16
      { "Network Layer Protocol Identifier", "esis.nlpi",
336
16
        FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, NULL, HFILL }},
337
338
16
    { &hf_esis_length,
339
16
      { "PDU Length", "esis.length",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
340
341
16
    { &hf_esis_version,
342
16
      { "Version", "esis.ver",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
343
344
16
    { &hf_esis_reserved,
345
16
      { "Reserved(==0)", "esis.res",  FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
346
347
16
    { &hf_esis_type,
348
16
      { "PDU Type", "esis.type",      FT_UINT8, BASE_DEC, VALS(esis_vals), OSI_PDU_TYPE_MASK, NULL, HFILL }},
349
350
16
    { &hf_esis_holdtime,
351
16
      { "Holding Time", "esis.htime", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_second_seconds), 0x0, NULL, HFILL }},
352
353
16
    { &hf_esis_checksum,
354
16
      { "Checksum", "esis.chksum",    FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
355
356
16
    { &hf_esis_checksum_status,
357
16
      { "Checksum Status", "esis.chksum.status",    FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0, NULL, HFILL }},
358
359
      /* Generated from convert_proto_tree_add_text.pl */
360
16
      { &hf_esis_number_of_source_addresses, { "Number of Source Addresses (SA, Format: NSAP)", "esis.number_of_source_addresses", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
361
16
      { &hf_esis_sal, { "SAL", "esis.sal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
362
16
      { &hf_esis_sa, { "SA", "esis.sa", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
363
16
      { &hf_esis_netl, { "NETL", "esis.netl", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
364
16
      { &hf_esis_dal, { "DAL", "esis.dal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
365
16
      { &hf_esis_bsnpal, { "BSNPAL", "esis.bsnpal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
366
16
      { &hf_esis_net, { "NET", "esis.net", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
367
16
      { &hf_esis_da, { "DA", "esis.da", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
368
16
      { &hf_esis_bsnpa, { "BSNPA", "esis.bsnpa", FT_SYSTEM_ID, BASE_NONE, NULL, 0x0, NULL, HFILL }},
369
16
  };
370
371
16
  static int *ett[] = {
372
16
    &ett_esis,
373
16
    &ett_esis_area_addr,
374
16
    &ett_esis_network,
375
16
    &ett_esis_dest_addr,
376
16
    &ett_esis_subnetwork
377
16
  };
378
379
16
  static ei_register_info ei[] = {
380
16
    { &ei_esis_version, { "esis.ver.unknown", PI_PROTOCOL, PI_WARN, "Unknown ESIS version", EXPFILL }},
381
16
    { &ei_esis_length, { "esis.length.invalid", PI_MALFORMED, PI_ERROR, "Bogus ESIS length", EXPFILL }},
382
16
    { &ei_esis_type, { "esis.type.unknown", PI_PROTOCOL, PI_WARN, "Unknown ESIS packet type", EXPFILL }},
383
16
    { &ei_esis_checksum, { "esis.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
384
16
  };
385
386
16
  expert_module_t* expert_esis;
387
388
16
  proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis");
389
16
  proto_register_field_array(proto_esis, hf, array_length(hf));
390
16
  proto_register_subtree_array(ett, array_length(ett));
391
16
  expert_esis = expert_register_protocol(proto_esis);
392
16
  expert_register_field_array(expert_esis, ei, array_length(ei));
393
16
  esis_handle = register_dissector("esis", dissect_esis, proto_esis);
394
16
}
395
396
void
397
proto_reg_handoff_esis(void)
398
16
{
399
16
  dissector_add_uint("osinl.incl", NLPID_ISO9542_ESIS, esis_handle);
400
16
}
401
402
/*
403
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
404
 *
405
 * Local Variables:
406
 * c-basic-offset: 2
407
 * tab-width: 8
408
 * indent-tabs-mode: nil
409
 * End:
410
 *
411
 * ex: set shiftwidth=2 tabstop=8 expandtab:
412
 * :indentSize=2:tabSize=8:noTabs=true:
413
 */