Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-diffserv-mpls-common.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-diffserv-mpls-common.c
2
 * Routines for the common part of Diffserv MPLS signaling protocols
3
 * Author: Endoh Akira (endoh@netmarks.co.jp)
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
/*
13
 * This module defines routines only for the common part of LDP
14
 * and RSVP to support for Diffserv MPLS as described in RFC 3270
15
 * and RFC 3140. Protocol specific routines of each signaling
16
 * protocol are defined in each dissector.
17
 */
18
19
#include "config.h"
20
21
#include <epan/packet.h>
22
#include "packet-diffserv-mpls-common.h"
23
24
53
#define hf_map         *hfindexes[0]
25
53
#define hf_exp         *hfindexes[1]
26
51
#define hf_phbid       *hfindexes[2]
27
30
#define hf_phbid_dscp  *hfindexes[3]
28
21
#define hf_phbid_code  *hfindexes[4]
29
51
#define hf_phbid_bit14 *hfindexes[5]
30
51
#define hf_phbid_bit15 *hfindexes[6]
31
53
#define ett_map        *etts[0]
32
51
#define ett_map_phbid  *etts[1]
33
34
const value_string phbid_bit14_vals[] = {
35
    {0, "Single PHB"},
36
    {1, "Set of PHBs"},
37
    {0, NULL}
38
};
39
40
const value_string phbid_bit15_vals[] = {
41
    {0, "PHBs defined by standards action"},
42
    {1, "PHBs not defined by standards action"},
43
    {0, NULL}
44
};
45
46
void
47
dissect_diffserv_mpls_common(tvbuff_t *tvb, proto_tree *tree, int type,
48
                             int offset, int **hfindexes, int **etts)
49
54
{
50
54
    proto_item  *ti = NULL, *sub_ti;
51
54
    proto_tree  *tree2 = NULL, *phbid_subtree;
52
54
    int exp;
53
54
    uint16_t phbid;
54
55
54
    switch (type) {
56
53
    case 1:  /* E-LSP */
57
53
        ti = proto_tree_add_item(tree, hf_map, tvb, offset, 4, ENC_NA);
58
53
        tree2 = proto_item_add_subtree(ti, ett_map);
59
53
        proto_item_set_text(ti, "MAP: ");
60
53
        offset ++;
61
53
        exp = tvb_get_uint8(tvb, offset) & 7;
62
53
        proto_tree_add_uint(tree2, hf_exp, tvb, offset, 1, exp);
63
53
        proto_item_append_text(ti, "EXP %u, ", exp);
64
53
        offset ++;
65
53
        break;
66
1
    case 2:  /* L-LSP */
67
1
        tree2 = tree;
68
1
        break;
69
0
    default:
70
0
        return;
71
54
    }
72
73
    /* PHBID subtree */
74
51
    sub_ti = proto_tree_add_item(tree2, hf_phbid, tvb, offset, 2, ENC_NA);
75
51
    phbid_subtree = proto_item_add_subtree(sub_ti, ett_map_phbid);
76
51
    proto_item_set_text(sub_ti, "%s: ", (type == 1) ? PHBID_DESCRIPTION : "PSC");
77
51
    phbid = tvb_get_ntohs(tvb, offset);
78
79
51
    if ((phbid & 1) == 0) {
80
        /* Case 1 of RFC 3140 */
81
30
        proto_tree_add_uint(phbid_subtree, hf_phbid_dscp,
82
30
                            tvb, offset, 2, phbid);
83
30
        if (type == 1)
84
29
            proto_item_append_text(ti, "DSCP %u", phbid >> 10);
85
30
        proto_item_append_text(sub_ti, "DSCP %u", phbid >> 10);
86
30
    }
87
21
    else {
88
        /* Case 2 of RFC 3140 */
89
21
        proto_tree_add_uint(phbid_subtree, hf_phbid_code,
90
21
                            tvb, offset, 2, phbid);
91
21
        if (type == 1)
92
19
            proto_item_append_text(ti, "PHB id code %u", phbid >> 4);
93
21
        proto_item_append_text(sub_ti, "PHB id code %u", phbid >> 4);
94
21
    }
95
51
    proto_tree_add_uint(phbid_subtree, hf_phbid_bit14, tvb, offset, 2, phbid);
96
51
    proto_tree_add_uint(phbid_subtree, hf_phbid_bit15, tvb, offset, 2, phbid);
97
51
}
98
99
/*
100
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
101
 *
102
 * Local variables:
103
 * c-basic-offset: 4
104
 * tab-width: 8
105
 * indent-tabs-mode: nil
106
 * End:
107
 *
108
 * vi: set shiftwidth=4 tabstop=8 expandtab:
109
 * :indentSize=4:tabSize=8:noTabs=true:
110
 */