packet-tpkt.c 22.4 KB
Newer Older
1
2
/* packet-tpkt.c
 *
3
 * Routine to check for RFC 1006 TPKT header and to dissect TPKT header
4
 * Copyright 2000, Philips Electronics N.V.
5
 * Andreas Sikkema <h323@ramdyne.nl>
6
 *
7
8
9
 * Routine to dissect RFC 1006 TPKT packet containing OSI TP PDU
 * Copyright 2001, Martin Thomas <Martin_A_Thomas@yahoo.com>
 *
10
11
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
12
 * Copyright 1998 Gerald Combs
13
 *
14
 * SPDX-License-Identifier: GPL-2.0-or-later
15
16
 */

17
#include "config.h"
18

19
#include <epan/packet.h>
20
#include <epan/exceptions.h>
21
22
#include <epan/prefs.h>
#include <epan/show_exception.h>
23
#include <epan/conversation.h>
24
25

#include "packet-tpkt.h"
26

27
28
29
void proto_register_tpkt(void);
void proto_reg_handoff_tpkt(void);

30
31
static heur_dissector_list_t tpkt_heur_subdissector_list;

32
/* TPKT header fields             */
33
static int proto_tpkt                = -1;
34
static int proto_tpkt_heur           = -1;
35
static protocol_t *proto_tpkt_ptr;
36
37
38
39
static int hf_tpkt_version           = -1;
static int hf_tpkt_reserved          = -1;
static int hf_tpkt_length            = -1;
static int hf_tpkt_continuation_data = -1;
40

Anders Broman's avatar
Anders Broman committed
41

42
43
44
/* TPKT fields defining a sub tree */
static gint ett_tpkt           = -1;

45
46
47
/* desegmentation of OSI over TPKT over TCP */
static gboolean tpkt_desegment = TRUE;

48
49
#define TCP_PORT_TPKT_RANGE       "102"

50
51
52
/* IANA registered port for RDP (as ms-wbt-server) */
#define TCP_PORT_RDP 3389

53
/* find the dissector for OSI TP (aka COTP) */
54
static dissector_handle_t osi_tp_handle;
55
static dissector_handle_t tpkt_handle;
56

57
58
#define DEFAULT_TPKT_PORT_RANGE "102"

59
60
/*
 * Check whether this could be a TPKT-encapsulated PDU.
61
62
 * Returns -1 if it's not, and the PDU length from the TPKT header
 * if it is.
63
64
65
66
 *
 * "min_len" is the minimum length of the PDU; the length field in the
 * TPKT header must be at least "4+min_len" in order for this to be a
 * valid TPKT PDU for the protocol in question.
67
 */
68
int
69
is_tpkt(tvbuff_t *tvb, int min_len)
70
{
71
72
73
74
75
76
77
78
79
80
    guint16 pkt_len;

    /*
     * If TPKT is disabled, don't dissect it, just return -1, meaning
     * "this isn't TPKT".
     */
    if (!proto_is_protocol_enabled(proto_tpkt_ptr))
        return -1;

    /* There should at least be 4 bytes left in the frame */
81
    if (tvb_captured_length(tvb) < 4)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
        return -1;  /* there aren't */

    /*
     * The first octet should be 3 and the second one should be 0
     * The H.323 implementers guide suggests that this might not
     * always be the case....
     */
    if (!(tvb_get_guint8(tvb, 0) == 3 && tvb_get_guint8(tvb, 1) == 0))
        return -1;  /* they're not */

    /*
     * Get the length from the TPKT header.  Make sure it's large
     * enough.
     */
    pkt_len = tvb_get_ntohs(tvb, 2);
    if (pkt_len < 4 + min_len)
        return -1;  /* it's not */

    /*
     * Return the length from the header.
     */
    return pkt_len;
104
}
105
106
guint16
is_asciitpkt(tvbuff_t *tvb)
Anders Broman's avatar
Anders Broman committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
    guint16 count;
        /*
         * If TPKT is disabled, don't dissect it, just return -1, meaning
         * "this isn't TPKT".
         */
    if (!proto_is_protocol_enabled(proto_tpkt_ptr))
       return -1;

          /* There should at least be 8 bytes left in the frame */
    if (!tvb_bytes_exist(tvb, 0, 8))
        return -1;      /* there aren't */

        /*
121
         * The first four  octets should be alphanumeric ASCII
Anders Broman's avatar
Anders Broman committed
122
123
124
         */
    for (count = 0; count <=7 ; count ++)
        {
125
        if(!g_ascii_isalnum(tvb_get_guint8(tvb,count)))
Anders Broman's avatar
Anders Broman committed
126
127
128
129
130
131
132
133
          {
          return 0;
          }
        }
     return 1;


}
134
135
static int
parseLengthText ( guint8* pTpktData )
Anders Broman's avatar
Anders Broman committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
    int value = 0;
    const guint8 * pData = pTpktData;
    int bitvalue = 0, count1 = 3;
    int count;
    for (count = 0; count <= 3; count++)
        {
        if (('0' <= *(pData + count)) && (*(pData + count) <= '9'))
            bitvalue = *(pData + count) - 48;
        else if (('a' <= *(pData + count)) && (*(pData + count) <= 'f' ))
            bitvalue = *(pData + count) - 87;
        else if (('A' <= *(pData + count)) && (*(pData + count) <= 'F' ))
            bitvalue = *(pData + count) - 55;

        value += bitvalue << (4*count1);
        count1--;
        }
    return value;
}
155
156
static int
parseVersionText ( guint8* pTpktData )
Anders Broman's avatar
Anders Broman committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
{
    int value = 0;
    guint8 * pData = pTpktData;
    int bitvalue = 0, count1 = 1;
    int count;
    for (count = 0; count <= 1; count++)
        {
        if (('0' <= *(pData + count)) && (*(pData + count) <= '9'))
            bitvalue = *(pData + count) - 48;
        else if (('a' <= *(pData + count)) && (*(pData + count) <= 'f' ))
            bitvalue = *(pData + count) - 87;
        else if (('A' <= *(pData + count)) && (*(pData + count) <= 'F' ))
            bitvalue = *(pData + count) - 55;

        value += bitvalue << (4*count1);
        count1--;
        }

    return value;
}
177
178
static int
parseReservedText ( guint8* pTpktData )
Anders Broman's avatar
Anders Broman committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
    int value = 0;
    guint8 * pData = pTpktData;
    int bitvalue = 0, count1 = 1;
    int count;
    for (count = 0; count <= 1; count++)
        {
        if (('0' <= *(pData + count)) && (*(pData + count) <= '9'))
            bitvalue = *(pData + count) - 48;
        else if (('a' <= *(pData + count)) && (*(pData + count) <= 'f' ))
            bitvalue = *(pData + count) - 87;
        else if (('A' <= *(pData + count)) && (*(pData + count) <= 'F' ))
            bitvalue = *(pData + count) - 55;

        value += bitvalue << (4*count1);
        count1--;
        }

    return value;
}
199
200
201
202
203
204

/*
 * Length of the TPKT text-layer header.
 */
static const int TEXT_LAYER_LENGTH   = 9;

Anders Broman's avatar
Anders Broman committed
205
206
207
208
209
/*
 * Dissect ASCII TPKT-encapsulated data in a TCP stream.
 */
void
dissect_asciitpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
210
          dissector_handle_t subdissector_handle)
Anders Broman's avatar
Anders Broman committed
211
212
213
214
215
216
{
    proto_item *ti = NULL;
    proto_tree *tpkt_tree = NULL;
    volatile int offset = 0;
    int length_remaining;
    int data_len;
217
    volatile int mgcp_packet_len = 0;
Anders Broman's avatar
Anders Broman committed
218
219
220
    int mgcp_version = 0;
    int mgcp_reserved = 0;
    volatile int length;
Stig Bjørlykke's avatar
Stig Bjørlykke committed
221
    tvbuff_t *volatile next_tvb;
Anders Broman's avatar
Anders Broman committed
222
223
    const char *saved_proto;
    guint8 string[4];
224

Anders Broman's avatar
Anders Broman committed
225
226
227
228
229
230
231
232
233
234
    /*
     * If we're reassembling segmented TPKT PDUs, empty the COL_INFO
     * column, so subdissectors can append information
     * without having to worry about emptying the column.
     *
     * We use "col_add_str()" because the subdissector
     * might be appending information to the column, in
     * which case we'd have to zero the buffer out explicitly
     * anyway.
     */
235
    if (tpkt_desegment)
236
        col_set_str(pinfo->cinfo, COL_INFO, "");
Anders Broman's avatar
Anders Broman committed
237
238
239
240
241
242
243
244
245
246
247
248
249

    while (tvb_reported_length_remaining(tvb, offset) != 0) {
        /*
         * Is the first byte of this putative TPKT header
         * a valid TPKT version number, i.e. 3?
         */
        if (tvb_get_guint8(tvb, offset) != 48) {
            /*
             * No, so don't assume this is a TPKT header;
             * we might be in the middle of TPKT data,
             * so don't get the length and don't try to
             * do reassembly.
             */
250
            col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
251
            col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
Anders Broman's avatar
Anders Broman committed
252
253
            if (tree) {
                ti = proto_tree_add_item(tree, proto_tpkt, tvb,
254
                             offset, -1, ENC_NA);
Anders Broman's avatar
Anders Broman committed
255
256
                tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);

257
                proto_tree_add_item(tpkt_tree, hf_tpkt_continuation_data, tvb, offset, -1, ENC_NA);
Anders Broman's avatar
Anders Broman committed
258
259
260
261
            }
            return;
        }

262
        length_remaining = tvb_captured_length_remaining(tvb, offset);
Anders Broman's avatar
Anders Broman committed
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

        /*
         * Get the length from the TPKT header.
         */

        tvb_memcpy(tvb, (guint8 *)string, offset, 2);
        mgcp_version = parseVersionText(string);
        tvb_memcpy(tvb, (guint8 *)string, offset +2, 2);
        mgcp_reserved = parseReservedText(string);
        tvb_memcpy(tvb, (guint8 *)string, offset + 4, 4);
        mgcp_packet_len = parseLengthText(string);
        data_len = mgcp_packet_len;

        /*
         * Dissect the TPKT header.
         * Save and restore "pinfo->current_proto".
         */
        saved_proto = pinfo->current_proto;
        pinfo->current_proto = "TPKT";

283
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
Anders Broman's avatar
Anders Broman committed
284
285
286
287
288
289
290
291
292
        /*
         * Don't add the TPKT header information if we're
         * reassembling segmented TPKT PDUs or if this
         * PDU isn't reassembled.
         *
         * XXX - the first is so that subdissectors can append
         * information without getting TPKT stuff in the middle;
         * why the second?
         */
293
        if (!tpkt_desegment && !pinfo->fragmented) {
Anders Broman's avatar
Anders Broman committed
294
            col_add_fstr(pinfo->cinfo, COL_INFO,
295
                     "TPKT Data length = %u", data_len);
Anders Broman's avatar
Anders Broman committed
296
297
298
299
        }

        if (tree) {
            ti = proto_tree_add_item(tree, proto_tpkt, tvb,
300
                         offset, 8, ENC_NA);
Anders Broman's avatar
Anders Broman committed
301
302
303
304
305
            tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);
            proto_item_set_text(ti, "TPKT");

            /* Version */
            proto_tree_add_uint(tpkt_tree, hf_tpkt_version, tvb,
306
                        offset, 2, mgcp_version);
Anders Broman's avatar
Anders Broman committed
307
308
309

            /* Reserved octet*/
            proto_tree_add_uint(tpkt_tree, hf_tpkt_reserved, tvb,
310
                        offset + 2, 2, mgcp_reserved);
Anders Broman's avatar
Anders Broman committed
311
312
313

            /* Length */
            proto_tree_add_uint(tpkt_tree, hf_tpkt_length, tvb,
314
                        offset + 4, 4, mgcp_packet_len);
Anders Broman's avatar
Anders Broman committed
315
316
317
318
319
320
321
322
323
        }
        pinfo->current_proto = saved_proto;

        /* Skip the TPKT header. */
        offset += TEXT_LAYER_LENGTH;
        length = length_remaining - TEXT_LAYER_LENGTH;
        if (length > data_len)
            length = data_len;

324
        next_tvb = tvb_new_subset_length_caplen(tvb, offset,length, data_len);
Anders Broman's avatar
Anders Broman committed
325
326
327
328

        /*
         * Call the subdissector.
         *
329
330
331
         * If it gets an error that means there's no point in
         * dissecting any more TPKT messages, rethrow the
         * exception in question.
Anders Broman's avatar
Anders Broman committed
332
         *
333
334
335
336
         * If it gets any other error, report it and continue, as that
         * means that TPKT message got an error, but that doesn't mean
         * we should stop dissecting TPKT messages within this frame
         * or chunk of reassembled data.
Anders Broman's avatar
Anders Broman committed
337
338
339
         */
        TRY {
            call_dissector(subdissector_handle, next_tvb, pinfo,
340
                       tree);
Anders Broman's avatar
Anders Broman committed
341
        }
342
        CATCH_NONFATAL_ERRORS {
343

344
            show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
Anders Broman's avatar
Anders Broman committed
345
346
347
348
349
350
351
352
353
        }
        ENDTRY;

        /*
         * Skip the payload.
         */
        offset += data_len;
    }
}
354

355
/*
356
 * Dissect TPKT-encapsulated data in a TCP stream.
357
 */
358
359
void
dissect_tpkt_encap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
360
           gboolean desegment, dissector_handle_t subdissector_handle)
361
{
362
363
364
365
366
367
368
369
    proto_item *ti = NULL;
    proto_tree *tpkt_tree = NULL;
    volatile int offset = 0;
    int length_remaining;
    int data_len;
    volatile int length;
    tvbuff_t *volatile next_tvb;
    const char *saved_proto;
370
    heur_dtbl_entry_t *hdtbl_entry;
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

    /*
     * If we're reassembling segmented TPKT PDUs, empty the COL_INFO
     * column, so subdissectors can append information
     * without having to worry about emptying the column.
     *
     * We use "col_add_str()" because the subdissector
     * might be appending information to the column, in
     * which case we'd have to zero the buffer out explicitly
     * anyway.
     */
    if (desegment)
        col_set_str(pinfo->cinfo, COL_INFO, "");

    while (tvb_reported_length_remaining(tvb, offset) != 0) {
        /*
         * Is the first byte of this putative TPKT header
         * a valid TPKT version number, i.e. 3?
         */
        if (tvb_get_guint8(tvb, offset) != 3) {
            /*
             * No, so don't assume this is a TPKT header;
             * we might be in the middle of TPKT data,
             * so don't get the length and don't try to
             * do reassembly.
             */
397
398
399
400
401
402
403

            if (dissector_try_heuristic(tpkt_heur_subdissector_list, tvb,
                                        pinfo, proto_tree_get_root(tree),
                                        &hdtbl_entry, NULL)) {
                return;
            }

404
405
406
407
408
409
410
411
412
413
414
415
            col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
            col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
            if (tree) {
                ti = proto_tree_add_item(tree, proto_tpkt, tvb,
                    offset, -1, ENC_NA);
                tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);

                proto_tree_add_item(tpkt_tree, hf_tpkt_continuation_data, tvb, offset, -1, ENC_NA);
            }
            return;
        }

416
        length_remaining = tvb_captured_length_remaining(tvb, offset);
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535

        /*
         * Can we do reassembly?
         */
        if (desegment && pinfo->can_desegment) {
            /*
             * Yes - is the TPKT header split across segment
             * boundaries?
             */
            if (length_remaining < 4) {
                /*
                 * Yes.  Tell the TCP dissector where the data
                 * for this message starts in the data it
                 * handed us and that we need "some more data."
                 * Don't tell it exactly how many bytes we need
                 * because if/when we ask for even more (after
                 * the header) that will break reassembly.
                 */
                pinfo->desegment_offset = offset;
                pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
                return;
            }
        }

        /*
         * Get the length from the TPKT header.
         */
        data_len = tvb_get_ntohs(tvb, offset + 2);

        /*
         * Can we do reassembly?
         */
        if (desegment && pinfo->can_desegment) {
            /*
             * Yes - is the payload split across segment
             * boundaries?
             */
            if (length_remaining < data_len) {
                /*
                 * Yes.  Tell the TCP dissector where
                 * the data for this message starts in
                 * the data it handed us, and how many
                 * more bytes we need, and return.
                 */
                pinfo->desegment_offset = offset;
                pinfo->desegment_len =
                    data_len - length_remaining;
                return;
            }
        }

        /*
         * Dissect the TPKT header.
         * Save and restore "pinfo->current_proto".
         */
        saved_proto = pinfo->current_proto;
        pinfo->current_proto = "TPKT";

        col_set_str(pinfo->cinfo, COL_PROTOCOL, "TPKT");
        /*
         * Don't add the TPKT header information if we're
         * reassembling segmented TPKT PDUs or if this
         * PDU isn't reassembled.
         *
         * XXX - the first is so that subdissectors can append
         * information without getting TPKT stuff in the middle;
         * why the second?
         */
        if (!desegment && !pinfo->fragmented) {
            col_add_fstr(pinfo->cinfo, COL_INFO,
                "TPKT Data length = %u", data_len);
        }

        if (tree) {
            ti = proto_tree_add_item(tree, proto_tpkt, tvb,
                offset, 4, ENC_NA);
            tpkt_tree = proto_item_add_subtree(ti, ett_tpkt);
            proto_item_set_text(ti, "TPKT");

            /* Version */
            proto_tree_add_item(tpkt_tree, hf_tpkt_version, tvb,
                offset, 1, ENC_BIG_ENDIAN);
            proto_item_append_text(ti, ", Version: 3");

            /* Reserved octet*/
            proto_tree_add_item(tpkt_tree, hf_tpkt_reserved, tvb,
                offset + 1, 1, ENC_BIG_ENDIAN);

            /* Length */
            proto_tree_add_uint(tpkt_tree, hf_tpkt_length, tvb,
                offset + 2, 2, data_len);
            proto_item_append_text(ti, ", Length: %u", data_len);
        }
        pinfo->current_proto = saved_proto;

        /* Skip the TPKT header. */
        offset += 4;
        data_len -= 4;

        /*
         * Construct a tvbuff containing the amount of the payload
         * we have available.  Make its reported length the
         * amount of data in this TPKT packet.
         *
         * XXX - if reassembly isn't enabled. the subdissector
         * will throw a BoundsError exception, rather than a
         * ReportedBoundsError exception.  We really want
         * a tvbuff where the length is "length", the reported
         * length is "plen + 2", and the "if the snapshot length
         * were infinite" length were the minimum of the
         * reported length of the tvbuff handed to us and "plen+2",
         * with a new type of exception thrown if the offset is
         * within the reported length but beyond that third length,
         * with that exception getting the "Unreassembled Packet"
         * error.
         */
        length = length_remaining - 4;
        if (length > data_len)
            length = data_len;
536
        next_tvb = tvb_new_subset_length_caplen(tvb, offset, length, data_len);
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564

        /*
         * Call the subdissector.
         *
         * If it gets an error that means there's no point in
         * dissecting any more TPKT messages, rethrow the
         * exception in question.
         *
         * If it gets any other error, report it and continue,
         * as that means that TPKT message got an error, but
         * that doesn't mean we should stop dissecting TPKT
         * messages within this frame or chunk of reassembled
         * data.
         */
        TRY {
            call_dissector(subdissector_handle, next_tvb, pinfo,
                tree);
        }
        CATCH_NONFATAL_ERRORS {
            show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
        }
        ENDTRY;

        /*
         * Skip the payload.
         */
        offset += length;
    }
565
566
}

567
568
569
570
/*
 * Dissect RFC 1006 TPKT, which wraps a TPKT header around an OSI TP
 * PDU.
 */
571
572
static int
dissect_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
573
{
574
    dissect_tpkt_encap(tvb, pinfo, tree, tpkt_desegment, osi_tp_handle);
575
    return tvb_captured_length(tvb);
576
577
}

Anders Broman's avatar
Anders Broman committed
578
579
580
/*
 * Dissect ASCII TPKT, which wraps a ASCII TPKT header around an OSI TP
 * PDU.
581
582
 */
#if 0
583
584
static int
dissect_ascii_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
Anders Broman's avatar
Anders Broman committed
585
{
586
    dissect_asciitpkt(tvb, pinfo, tree, osi_tp_handle);
587
    return tvb_captured_length(tvb);
Anders Broman's avatar
Anders Broman committed
588
}
589
#endif
590

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/* A heuristic dissector for TPKT. This is useful for RDP, where TLS may
 * or may not be present depending on the RDP security settings.
 */
static int
dissect_tpkt_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
    conversation_t    *conversation;

    if (is_tpkt(tvb, 0) == -1) {
        /* Doesn't look like TPKT directly. Might be over TLS, so reject
         * and let the TLS heuristic dissector take a look
         */
        return 0;
    }

    conversation = find_or_create_conversation(pinfo);
    conversation_set_dissector(conversation, tpkt_handle);
    return dissect_tpkt(tvb, pinfo, tree, data);
}

611
612
613
void
proto_register_tpkt(void)
{
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
    static hf_register_info hf[] = {
        {
            &hf_tpkt_version,
            {
                "Version",
                "tpkt.version",
                FT_UINT8,
                BASE_DEC,
                NULL,
                0x0,
                "Version, only version 3 is defined", HFILL
            }
        },
        {
            &hf_tpkt_reserved,
            {
                "Reserved",
                "tpkt.reserved",
                FT_UINT8,
                BASE_DEC,
                NULL,
                0x0,
                "Reserved, should be 0", HFILL
            }
        },
        {
            &hf_tpkt_length,
            {
                "Length",
                "tpkt.length",
                FT_UINT16,
                BASE_DEC,
                NULL,
                0x0,
                "Length of data unit, including this header", HFILL
            }
        },
        {
            &hf_tpkt_continuation_data,
            {
                "Continuation data",
                "tpkt.continuation_data",
                FT_BYTES,
                BASE_NONE,
                NULL,
                0x0,
                NULL, HFILL
            }
        },
    };

    static gint *ett[] =
    {
        &ett_tpkt,
    };
    module_t *tpkt_module;

    proto_tpkt = proto_register_protocol("TPKT - ISO on TCP - RFC1006", "TPKT", "tpkt");
    proto_tpkt_ptr = find_protocol_by_id(proto_tpkt);
    proto_register_field_array(proto_tpkt, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
675
    tpkt_handle = register_dissector("tpkt", dissect_tpkt, proto_tpkt);
676

John Thacker's avatar
John Thacker committed
677
    tpkt_module = prefs_register_protocol(proto_tpkt, NULL);
678
679
680
681
682
    prefs_register_bool_preference(tpkt_module, "desegment",
        "Reassemble TPKT messages spanning multiple TCP segments",
        "Whether the TPKT dissector should reassemble messages spanning multiple TCP segments. "
        "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
        &tpkt_desegment);
683

684
685
686
    /* heuristic dissectors for premable CredSSP before RDP and Fast-Path RDP packets */
    tpkt_heur_subdissector_list = register_heur_dissector_list("tpkt", proto_tpkt);

687
    proto_tpkt_heur = proto_register_protocol_in_name_only("TPKT Heuristic (for RDP)", "TPKT Heuristic (for RDP)", "tpkt", proto_tpkt, FT_PROTOCOL);
688
}
689
690
691
692

void
proto_reg_handoff_tpkt(void)
{
693
694
    osi_tp_handle = find_dissector("ositp");
    dissector_add_uint_range_with_preference("tcp.port", TCP_PORT_TPKT_RANGE, tpkt_handle);
695

696
    /* ssl_dissector_add registers TLS as the dissector for TCP for the
697
698
     * given port. We can't use it, since on port 3389 TPKT (for RDP) can be
     * over TLS or directly over TCP, depending on the RDP security settings.
699
700
701
     * TPKT heuristics are also too weak to enable in general. Instead,
     * use the heuristic dissector by default just on the RDP port, and
     * if rejected the TLS heuristic dissector will be tried.
702
     */
703
704
705
    dissector_add_uint("tls.port", TCP_PORT_RDP, tpkt_handle);
    dissector_add_uint("tcp.port", TCP_PORT_RDP, create_dissector_handle(dissect_tpkt_heur, proto_tpkt_heur));
    heur_dissector_add("tcp", dissect_tpkt_heur, "TPKT over TCP", "tpkt_tcp", proto_tpkt, HEURISTIC_DISABLE);
706

707
    /*
708
    tpkt_ascii_handle = create_dissector_handle(dissect_ascii_tpkt, proto_tpkt);
709
710
    dissector_add_uint("tcp.port", TCP_PORT_TPKT, tpkt_ascii_handle);
    */
711

712
}
713
714

/*
Guy Harris's avatar
Guy Harris committed
715
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
716
717
718
719
720
721
722
723
724
725
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */