summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-diffserv-mpls-common.c
blob: f4add8a4a4a298211f727bbd9f78510f3650a7b6 (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
/* packet-diffserv-mpls-common.c
 * Routines for the common part of Diffserv MPLS signaling protocols
 * Author: Endoh Akira (endoh@netmarks.co.jp)
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

/*
 * This module defines routines only for the common part of LDP
 * and RSVP to support for Diffserv MPLS as described in RFC 3270
 * and RFC 3140. Protocol specific routines of each signaling
 * protocol are defined in each dissector.
 */

#include "config.h"

#include <epan/packet.h>
#include "packet-diffserv-mpls-common.h"

#define hf_map         *hfindexes[0]
#define hf_exp         *hfindexes[1]
#define hf_phbid       *hfindexes[2]
#define hf_phbid_dscp  *hfindexes[3]
#define hf_phbid_code  *hfindexes[4]
#define hf_phbid_bit14 *hfindexes[5]
#define hf_phbid_bit15 *hfindexes[6]
#define ett_map        *etts[0]
#define ett_map_phbid  *etts[1]

const value_string phbid_bit14_vals[] = {
    {0, "Single PHB"},
    {1, "Set of PHBs"},
    {0, NULL}
};

const value_string phbid_bit15_vals[] = {
    {0, "PHBs defined by standards action"},
    {1, "PHBs not defined by standards action"},
    {0, NULL}
};

void
dissect_diffserv_mpls_common(tvbuff_t *tvb, proto_tree *tree, int type,
                             int offset, int **hfindexes, int **etts)
{
    proto_item  *ti = NULL, *sub_ti;
    proto_tree  *tree2 = NULL, *phbid_subtree;
    int exp;
    uint16_t phbid;

    switch (type) {
    case 1:  /* E-LSP */
        ti = proto_tree_add_item(tree, hf_map, tvb, offset, 4, ENC_NA);
        tree2 = proto_item_add_subtree(ti, ett_map);
        proto_item_set_text(ti, "MAP: ");
        offset ++;
        exp = tvb_get_uint8(tvb, offset) & 7;
        proto_tree_add_uint(tree2, hf_exp, tvb, offset, 1, exp);
        proto_item_append_text(ti, "EXP %u, ", exp);
        offset ++;
        break;
    case 2:  /* L-LSP */
        tree2 = tree;
        break;
    default:
        return;
    }

    /* PHBID subtree */
    sub_ti = proto_tree_add_item(tree2, hf_phbid, tvb, offset, 2, ENC_NA);
    phbid_subtree = proto_item_add_subtree(sub_ti, ett_map_phbid);
    proto_item_set_text(sub_ti, "%s: ", (type == 1) ? PHBID_DESCRIPTION : "PSC");
    phbid = tvb_get_ntohs(tvb, offset);

    if ((phbid & 1) == 0) {
        /* Case 1 of RFC 3140 */
        proto_tree_add_uint(phbid_subtree, hf_phbid_dscp,
                            tvb, offset, 2, phbid);
        if (type == 1)
            proto_item_append_text(ti, "DSCP %u", phbid >> 10);
        proto_item_append_text(sub_ti, "DSCP %u", phbid >> 10);
    }
    else {
        /* Case 2 of RFC 3140 */
        proto_tree_add_uint(phbid_subtree, hf_phbid_code,
                            tvb, offset, 2, phbid);
        if (type == 1)
            proto_item_append_text(ti, "PHB id code %u", phbid >> 4);
        proto_item_append_text(sub_ti, "PHB id code %u", phbid >> 4);
    }
    proto_tree_add_uint(phbid_subtree, hf_phbid_bit14, tvb, offset, 2, phbid);
    proto_tree_add_uint(phbid_subtree, hf_phbid_bit15, tvb, offset, 2, phbid);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * 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:
 */