Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-isis-clv.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-isis-clv.c
2
 * Common CLV decode routines.
3
 *
4
 * Stuart Stanley <stuarts@mxmail.net>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * SPDX-License-Identifier: GPL-2.0-or-later
11
 */
12
13
#include "config.h"
14
15
#include <epan/packet.h>
16
#include <epan/expert.h>
17
#include "packet-isis.h"
18
#include "packet-isis-clv.h"
19
#include <epan/nlpid.h>
20
21
static const value_string algorithm_vals[] = {
22
    { 16, "hmac-md5" },
23
    { 20, "hmac-sha1" },
24
    { 28, "hmac-sha224" },
25
    { 32, "hmac-sha256" },
26
    { 48, "hmac-sha384" },
27
    { 64, "hmac-sha512" },
28
    { 0,  NULL }
29
};
30
31
static const value_string mt_id_vals[] = {
32
    { 0, "IPv4 Unicast" },
33
    { 1, "IPv4 In-Band Management" },
34
    { 2, "IPv6 Unicast" },
35
    { 3, "IPv4 Multicast" },
36
    { 4, "IPv6 Multicast" },
37
    { 5, "IPv6 In-Band Management" },
38
    { 4095, "Development, Experimental or Proprietary" },
39
    { 0,  NULL }
40
};
41
42
/*
43
 * Name: isis_dissect_area_address_clv()
44
 *
45
 * Description:
46
 *    Take an area address CLV and display it pieces.  An area address
47
 *    CLV is n, x byte hex strings.
48
 *
49
 * Input:
50
 *    tvbuff_t * : tvbuffer for packet data
51
 *    proto_tree * : protocol display tree to fill out.  May be NULL
52
 *    int : offset into packet data where we are.
53
 *    int : length of clv we are decoding
54
 *
55
 * Output:
56
 *    void, but we will add to proto tree if !NULL.
57
 */
58
void
59
isis_dissect_area_address_clv(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb,
60
        expert_field* expert, int hf_area, int offset, int length)
61
1.08k
{
62
1.08k
    int        arealen,area_idx;
63
64
1.80k
    while ( length > 0 ) {
65
1.66k
        arealen = tvb_get_uint8(tvb, offset);
66
1.66k
        length--;
67
1.66k
        if (length<=0) {
68
798
            proto_tree_add_expert_format(tree, pinfo, expert, tvb, offset, -1,
69
798
                "short address (no length for payload)");
70
798
            return;
71
798
        }
72
870
        if ( arealen > length) {
73
150
            proto_tree_add_expert_format(tree, pinfo, expert, tvb, offset, -1,
74
150
                "short address, packet says %d, we have %d left",
75
150
                arealen, length );
76
150
            return;
77
150
        }
78
79
720
        if ( tree ) {
80
717
            proto_item *ti;
81
82
717
            ti = proto_tree_add_bytes_format( tree, hf_area, tvb, offset, arealen + 1,
83
717
                NULL, "Area address (%d): ", arealen );
84
85
            /*
86
             * Lets turn the area address into "standard"
87
             * xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx format string.
88
             * this is a private routine as the print_nsap_net in
89
             * epan/osi_utils.c is incomplete and we need only
90
             * a subset - actually some nice placing of dots ....
91
             */
92
4.26k
            for (area_idx = 0; area_idx < arealen; area_idx++) {
93
3.54k
                proto_item_append_text(ti, "%02x",
94
3.54k
                    tvb_get_uint8(tvb, offset+area_idx+1));
95
3.54k
                if (((area_idx & 1) == 0) &&
96
3.54k
                    (area_idx + 1 < arealen)) {
97
1.62k
                    proto_item_append_text(ti, ".");
98
1.62k
                }
99
3.54k
            }
100
717
        }
101
720
        offset += arealen + 1;
102
720
        length -= arealen;    /* length already adjusted for len fld*/
103
720
    }
104
1.08k
}
105
106
/*
107
 * Name: isis_dissect_instance_identifier_clv()
108
 *
109
 *
110
 * Input:
111
 *    tvbuff_t * : tvbuffer for packet data
112
 *    proto_tree * : protocol display tree to fill out.  May be NULL
113
 *    int : offset into packet data where we are.
114
 *    int : length of clv we are decoding
115
 *
116
 * Output:
117
 *    void, but we will add to proto tree if !NULL.
118
 */
119
void
120
isis_dissect_instance_identifier_clv(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb,
121
        expert_field* expert, int hf_iid, int hf_supported_itid, int offset, int length)
122
192
{
123
124
192
    length--;
125
192
    if (length<=0) {
126
10
        proto_tree_add_expert_format(tree, pinfo, expert, tvb, offset, -1,
127
10
            "short address (no length for payload)");
128
10
        return;
129
10
    }
130
131
182
    proto_tree_add_item(tree, hf_iid, tvb, offset, 2, ENC_BIG_ENDIAN);
132
182
    offset += 2;
133
182
    length -= 2;
134
135
1.20k
    while ( length > 0 ) {
136
137
1.02k
        proto_tree_add_item(tree, hf_supported_itid, tvb, offset, 2, ENC_BIG_ENDIAN);
138
1.02k
        offset += 2;
139
1.02k
        length -= 2;
140
141
1.02k
    }
142
182
}
143
144
/*
145
 * Name: isis_dissect_authentication_clv()
146
 *
147
 * Description:
148
 *    Take apart the CLV that hold authentication information.  This
149
 *    is currently 1 octet auth type.
150
 *      the two defined authentication types
151
 *      are 1 for a clear text password,
152
 *           54 for a HMAC-MD5 digest and
153
 *           3 for CRYPTO_AUTH (rfc5310)
154
 *
155
 * Input:
156
 *    tvbuff_t * : tvbuffer for packet data
157
 *    proto_tree * : protocol display tree to fill out.  May be NULL
158
 *    int : offset into packet data where we are.
159
 *    int : length of clv we are decoding
160
 *
161
 * Output:
162
 *    void, but we will add to proto tree if !NULL.
163
 */
164
void
165
isis_dissect_authentication_clv(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb,
166
        int hf_auth_bytes, int hf_key_id, expert_field* auth_expert, int offset, int length)
167
229
{
168
229
    unsigned char pw_type;
169
229
    int auth_unsupported;
170
229
    const char *algorithm = NULL;
171
172
229
    if ( length <= 0 ) {
173
11
        return;
174
11
    }
175
176
218
    pw_type = tvb_get_uint8(tvb, offset);
177
218
    offset += 1;
178
218
    length--;
179
218
    auth_unsupported = false;
180
181
218
    switch (pw_type) {
182
1
    case 1:
183
1
        if ( length > 0 ) {
184
0
            proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
185
0
                NULL, "clear text (1), password (length %d) = %s", length, tvb_format_text(pinfo->pool, tvb, offset, length));
186
1
        } else {
187
1
            proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
188
1
                NULL, "clear text (1), no clear-text password found!!!");
189
1
        }
190
1
        break;
191
0
    case 54:
192
0
        if ( length == 16 ) {
193
0
            proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
194
0
                NULL, "hmac-md5 (54), message digest (length %d) = %s", length, tvb_bytes_to_str(pinfo->pool, tvb, offset, length));
195
0
        } else {
196
0
            proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
197
0
                NULL, "hmac-md5 (54), illegal hmac-md5 digest format (must be 16 bytes)");
198
0
        }
199
0
        break;
200
4
    case 3:
201
4
        proto_tree_add_item(tree, hf_key_id, tvb, offset, 2, ENC_BIG_ENDIAN);
202
4
        offset += 2;
203
4
        length -= 2;
204
4
        algorithm = try_val_to_str(length, algorithm_vals);
205
4
        if ( algorithm ) {
206
0
            proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
207
0
                NULL, "CRYPTO_AUTH %s (3), message digest (length %d) = %s", algorithm,
208
0
                length, tvb_bytes_to_str(pinfo->pool, tvb, offset, length));
209
4
        } else {
210
4
            proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
211
4
                NULL, "CRYPTO_AUTH (3) illegal message digest format");
212
4
        }
213
4
        break;
214
213
    default:
215
213
        proto_tree_add_bytes_format( tree, hf_auth_bytes, tvb, offset, length,
216
213
                NULL, "type 0x%02x (0x%02x)", pw_type, length);
217
213
        auth_unsupported=true;
218
213
        break;
219
218
    }
220
221
213
    if ( auth_unsupported ) {
222
208
        proto_tree_add_expert(tree, pinfo, auth_expert, tvb, offset, -1);
223
208
    }
224
213
}
225
226
/*
227
 * Name: isis_dissect_hostname_clv()
228
 *
229
 * Description:
230
 *      dump the hostname information found in TLV 137
231
 *      pls note that the hostname is not null terminated
232
 *
233
 * Input:
234
 *      tvbuff_t * : tvbuffer for packet data
235
 *      proto_tree * : protocol display tree to fill out.  May be NULL
236
 *      int : offset into packet data where we are.
237
 *      int : length of clv we are decoding
238
 *      int : tree id to use for proto tree.
239
 *
240
 * Output:
241
 *      void, but we will add to proto tree if !NULL.
242
 */
243
244
245
void
246
isis_dissect_hostname_clv(tvbuff_t *tvb, proto_tree *tree, int offset,
247
    int length, int tree_id)
248
8
{
249
8
    proto_item* ti = proto_tree_add_item( tree, tree_id, tvb, offset, length, ENC_ASCII|ENC_NA);
250
8
    if ( length == 0 ) {
251
1
        proto_item_append_text(ti, "--none--" );
252
1
    }
253
8
}
254
255
256
257
258
void
259
isis_dissect_mt_clv(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, int offset, int length,
260
    int tree_id, expert_field* mtid_expert)
261
34
{
262
34
    uint16_t mt_block;
263
34
    const char *mt_desc;
264
265
2.05k
    while (length>0) {
266
        /* length can only be a multiple of 2, otherwise there is
267
           something broken -> so decode down until length is 1 */
268
2.03k
        if (length!=1) {
269
        /* fetch two bytes */
270
2.02k
        mt_block=tvb_get_ntohs(tvb, offset);
271
272
2.02k
        mt_desc = val_to_str_const(mt_block&0x0fff, mt_id_vals, "Unknown");
273
2.02k
        proto_tree_add_uint_format ( tree, tree_id, tvb, offset, 2,
274
2.02k
            mt_block,
275
2.02k
            "%s Topology (0x%03x)%s%s",
276
2.02k
                      mt_desc,
277
2.02k
                      mt_block&0xfff,
278
2.02k
                      (mt_block&0x8000) ? ", Overload bit set" : "",
279
2.02k
                      (mt_block&0x4000) ? ", ATT bit set" : "" );
280
2.02k
        } else {
281
14
        proto_tree_add_expert( tree, pinfo, mtid_expert, tvb, offset, 1);
282
14
        break;
283
14
        }
284
2.02k
        length -= 2;
285
2.02k
        offset += 2;
286
2.02k
    }
287
34
}
288
289
290
/*
291
 * Name: isis_dissect_ip_int_clv()
292
 *
293
 * Description:
294
 *    Take apart the CLV that lists all the IP interfaces.  The
295
 *    meaning of which is slightly different for the different base packet
296
 *    types, but the display is not different.  What we have is n ip
297
 *    addresses, plain and simple.
298
 *
299
 * Input:
300
 *    tvbuff_t * : tvbuffer for packet data
301
 *    proto_tree * : protocol display tree to fill out.  May be NULL
302
 *    int : offset into packet data where we are.
303
 *    int : length of clv we are decoding
304
 *    int : tree id to use for proto tree.
305
 *
306
 * Output:
307
 *    void, but we will add to proto tree if !NULL.
308
 */
309
void
310
isis_dissect_ip_int_clv(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb, expert_field* expert,
311
    int offset, int length, int tree_id)
312
54
{
313
54
    if ( length <= 0 ) {
314
2
        return;
315
2
    }
316
317
1.12k
    while ( length > 0 ) {
318
1.08k
        if ( length < 4 ) {
319
14
            proto_tree_add_expert_format(tree, pinfo, expert, tvb, offset, -1,
320
14
                "Short IP interface address (%d vs 4)",length );
321
14
            return;
322
14
        }
323
324
1.06k
        if ( tree ) {
325
1.06k
            proto_tree_add_item(tree, tree_id, tvb, offset, 4, ENC_BIG_ENDIAN);
326
1.06k
        }
327
1.06k
        offset += 4;
328
1.06k
        length -= 4;
329
1.06k
    }
330
52
}
331
332
/*
333
 * Name: isis_dissect_ipv6_int_clv()
334
 *
335
 * Description:
336
 *    Take apart the CLV that lists all the IPv6 interfaces.  The
337
 *    meaning of which is slightly different for the different base packet
338
 *    types, but the display is not different.  What we have is n ip
339
 *    addresses, plain and simple.
340
 *
341
 * Input:
342
 *    tvbuff_t * : tvbuffer for packet data
343
 *    proto_tree * : protocol display tree to fill out.  May be NULL
344
 *    int : offset into packet data where we are.
345
 *    int : length of clv we are decoding
346
 *    int : tree id to use for proto tree.
347
 *
348
 * Output:
349
 *    void, but we will add to proto tree if !NULL.
350
 */
351
void
352
isis_dissect_ipv6_int_clv(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb, expert_field* expert,
353
    int offset, int length, int tree_id)
354
44
{
355
44
    ws_in6_addr addr;
356
357
44
    if ( length <= 0 ) {
358
9
        return;
359
9
    }
360
361
283
    while ( length > 0 ) {
362
268
        if ( length < 16 ) {
363
20
            proto_tree_add_expert_format(tree, pinfo, expert, tvb, offset, -1,
364
20
                "Short IPv6 interface address (%d vs 16)",length );
365
20
            return;
366
20
        }
367
248
        tvb_get_ipv6(tvb, offset, &addr);
368
248
        if ( tree ) {
369
234
            proto_tree_add_ipv6(tree, tree_id, tvb, offset, 16, &addr);
370
234
        }
371
248
        offset += 16;
372
248
        length -= 16;
373
248
    }
374
35
}
375
376
377
/*
378
 * Name: isis_dissect_te_router_id_clv()
379
 *
380
 * Description:
381
 *      Display the Traffic Engineering Router ID TLV #134.
382
 *      This TLV is like the IP Interface TLV, except that
383
 *      only _one_ IP address is present
384
 *
385
 * Input:
386
 *      tvbuff_t * : tvbuffer for packet data
387
 *      proto_tree * : protocol display tree to fill out.  May be NULL
388
 *      int : offset into packet data where we are.
389
 *      int : length of clv we are decoding
390
 *      int : tree id to use for proto tree.
391
 *
392
 * Output:
393
 *      void, but we will add to proto tree if !NULL.
394
 */
395
void
396
isis_dissect_te_router_id_clv(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb, expert_field* expert,
397
    int offset, int length, int tree_id)
398
8
{
399
8
    if ( length <= 0 ) {
400
3
        return;
401
3
    }
402
403
5
    if ( length != 4 ) {
404
5
        proto_tree_add_expert_format(tree, pinfo, expert, tvb, offset, -1,
405
5
            "malformed Traffic Engineering Router ID (%d vs 4)",length );
406
5
        return;
407
5
    }
408
409
0
    proto_tree_add_item(tree, tree_id, tvb, offset, 4, ENC_BIG_ENDIAN);
410
0
}
411
412
/*
413
 * Name: isis_dissect_nlpid_clv()
414
 *
415
 * Description:
416
 *    Take apart a NLPID packet and display it.  The NLPID (for integrated
417
 *    ISIS, contains n network layer protocol IDs that the box supports.
418
 *    We max out at 256 entries.
419
 *
420
 * Input:
421
 *    tvbuff_t * : tvbuffer for packet data
422
 *    proto_tree * : protocol display tree to fill out.  May be NULL
423
 *    int : offset into packet data where we are.
424
 *    int : length of clv we are decoding
425
 *
426
 * Output:
427
 *    void, but we will add to proto tree if !NULL.
428
 */
429
430
54
#define PLURALIZE(n)  (((n) > 1) ? "s" : "")
431
432
void
433
isis_dissect_nlpid_clv(tvbuff_t *tvb, proto_tree *tree, int ett_nlpid, int hf_nlpid, int offset, int length)
434
58
{
435
58
    proto_tree *nlpid_tree;
436
58
    proto_item *ti;
437
58
    uint8_t nlpid;
438
439
58
    if (length <= 0) {
440
4
        proto_tree_add_subtree_format(tree, tvb, offset, 0, ett_nlpid, NULL, "No NLPIDs");
441
54
    } else {
442
54
        nlpid_tree = proto_tree_add_subtree_format(tree, tvb, offset, length, ett_nlpid, &ti, "NLPID%s: ", PLURALIZE(length));
443
4.85k
        while (length-- > 0 ) {
444
4.80k
            nlpid = tvb_get_uint8(tvb, offset);
445
4.80k
            proto_item_append_text(ti, "%s (0x%02x)",
446
                   /* NLPID_IEEE_8021AQ conflicts with NLPID_SNDCF. In this context, we want the former. */
447
4.80k
                   (nlpid == NLPID_IEEE_8021AQ ? "IEEE 802.1aq (SPB)" : val_to_str_const(nlpid, nlpid_vals, "Unknown")),
448
4.80k
                   nlpid);
449
4.80k
            if (length) {
450
4.74k
                proto_item_append_text(ti, ", ");
451
4.74k
            }
452
4.80k
            proto_tree_add_uint(nlpid_tree, hf_nlpid, tvb, offset, 1, nlpid);
453
4.80k
            offset++;
454
4.80k
        }
455
54
    }
456
58
}
457
458
/*
459
 * Name: isis_dissect_clvs()
460
 *
461
 * Description:
462
 *    Dispatch routine to shred all the CLVs in a packet.  We just
463
 *    walk through the clv entries in the packet.  For each one, we
464
 *    search the passed in valid clv's for this protocol (opts) for
465
 *    a matching code.  If found, we add to the display tree and
466
 *    then call the dissector.  If it is not, we just post an
467
 *    "unknown" clv entry using the passed in unknown clv tree id.
468
 *
469
 * Input:
470
 *    tvbuff_t * : tvbuffer for packet data
471
 *    packet_info * : packet_info for dissection
472
 *    proto_tree * : protocol display tree to fill out.  May be NULL
473
 *    int : offset into packet data where we are.
474
 *    isis_clv_handle_t * : NULL dissector terminated array of codes
475
 *        and handlers (along with tree text and tree id's).
476
 *    expert_field * : expert info for short length
477
 *    isis_data_t * : data about the PDU from earlier headers
478
 *    int : unknown clv tree id
479
 *
480
 * Output:
481
 *    void, but we will add to proto tree if !NULL.
482
 */
483
void
484
isis_dissect_clvs(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, int offset,
485
    const isis_clv_handle_t *opts, expert_field *expert_short_len, isis_data_t *isis,
486
    int unknown_tree_id _U_, int tree_type, int tree_length, expert_field *ei_unknown)
487
1.01k
{
488
1.01k
    unsigned len = isis->pdu_length - isis->header_length; /* length of CLV area */
489
1.01k
    uint8_t code;
490
1.01k
    uint8_t length;
491
1.01k
    int q;
492
1.01k
    proto_tree    *clv_tree;
493
494
17.1k
    while ( len != 0 ) {
495
16.1k
        code = tvb_get_uint8(tvb, offset);
496
16.1k
        offset += 1;
497
16.1k
        len -= 1;
498
16.1k
        if (len == 0)
499
1
            break;
500
501
16.1k
        length = tvb_get_uint8(tvb, offset);
502
16.1k
        offset += 1;
503
16.1k
        len -= 1;
504
16.1k
        if (len == 0)
505
2
            break;
506
507
16.1k
        if ( len < length ) {
508
23
            proto_tree_add_expert_format(tree, pinfo, expert_short_len, tvb, offset, -1,
509
23
                "Short CLV header (%d vs %d)",
510
23
                length, len );
511
23
            return;
512
23
        }
513
16.1k
        q = 0;
514
382k
        while ((opts[q].dissect != NULL )&&( opts[q].optcode != code )){
515
366k
            q++;
516
366k
        }
517
16.1k
        if ( opts[q].dissect ) {
518
            /* adjust by 2 for code/len octets */
519
4.74k
            clv_tree = proto_tree_add_subtree_format(tree, tvb, offset - 2,
520
4.74k
                    length + 2, *opts[q].tree_id, NULL, "%s (t=%u, l=%u)",
521
4.74k
                    opts[q].tree_text, opts[q].optcode, length);
522
523
4.74k
            proto_tree_add_item(clv_tree, tree_type, tvb, offset - 2, 1, ENC_BIG_ENDIAN);
524
4.74k
            proto_tree_add_item(clv_tree, tree_length, tvb, offset - 1, 1, ENC_BIG_ENDIAN);
525
4.74k
            opts[q].dissect(tvb, pinfo, clv_tree, offset, isis, length);
526
11.3k
        } else {
527
11.3k
            clv_tree = proto_tree_add_subtree_format(tree, tvb, offset - 2,
528
11.3k
                    length + 2, unknown_tree_id, NULL, "Unknown code (t=%u, l=%u)",
529
11.3k
                    code, length);
530
11.3k
            proto_tree_add_item(clv_tree, tree_type, tvb, offset - 2, 1, ENC_BIG_ENDIAN);
531
11.3k
            proto_tree_add_item(clv_tree, tree_length, tvb, offset - 1, 1, ENC_BIG_ENDIAN);
532
11.3k
            proto_tree_add_expert_format(clv_tree, pinfo, ei_unknown, tvb, offset, length, "Dissector for IS-IS CLV (%d)"
533
11.3k
              " code not implemented, Contact Wireshark developers if you want this supported", code);
534
11.3k
        }
535
16.1k
        offset += length;
536
16.1k
        len -= length;
537
16.1k
    }
538
1.01k
}
539
540
/*
541
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
542
 *
543
 * Local variables:
544
 * c-basic-offset: 4
545
 * tab-width: 8
546
 * indent-tabs-mode: nil
547
 * End:
548
 *
549
 * vi: set shiftwidth=4 tabstop=8 expandtab:
550
 * :indentSize=4:tabSize=8:noTabs=true:
551
 */