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 #define hf_map         *hfindexes[0]
25 #define hf_exp         *hfindexes[1]
26 #define hf_phbid       *hfindexes[2]
27 #define hf_phbid_dscp  *hfindexes[3]
28 #define hf_phbid_code  *hfindexes[4]
29 #define hf_phbid_bit14 *hfindexes[5]
30 #define hf_phbid_bit15 *hfindexes[6]
31 #define ett_map        *etts[0]
32 #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
dissect_diffserv_mpls_common(tvbuff_t * tvb,proto_tree * tree,int type,int offset,int ** hfindexes,gint ** etts)47 dissect_diffserv_mpls_common(tvbuff_t *tvb, proto_tree *tree, int type,
48                              int offset, int **hfindexes, gint **etts)
49 {
50     proto_item  *ti = NULL, *sub_ti;
51     proto_tree  *tree2 = NULL, *phbid_subtree;
52     int exp;
53     guint16 phbid;
54 
55     switch (type) {
56     case 1:  /* E-LSP */
57         ti = proto_tree_add_item(tree, hf_map, tvb, offset, 4, ENC_NA);
58         tree2 = proto_item_add_subtree(ti, ett_map);
59         proto_item_set_text(ti, "MAP: ");
60         offset ++;
61         exp = tvb_get_guint8(tvb, offset) & 7;
62         proto_tree_add_uint(tree2, hf_exp, tvb, offset, 1, exp);
63         proto_item_append_text(ti, "EXP %u, ", exp);
64         offset ++;
65         break;
66     case 2:  /* L-LSP */
67         tree2 = tree;
68         break;
69     default:
70         return;
71     }
72 
73     /* PHBID subtree */
74     sub_ti = proto_tree_add_item(tree2, hf_phbid, tvb, offset, 2, ENC_NA);
75     phbid_subtree = proto_item_add_subtree(sub_ti, ett_map_phbid);
76     proto_item_set_text(sub_ti, "%s: ", (type == 1) ? PHBID_DESCRIPTION : "PSC");
77     phbid = tvb_get_ntohs(tvb, offset);
78 
79     if ((phbid & 1) == 0) {
80         /* Case 1 of RFC 3140 */
81         proto_tree_add_uint(phbid_subtree, hf_phbid_dscp,
82                             tvb, offset, 2, phbid);
83         if (type == 1)
84             proto_item_append_text(ti, "DSCP %u", phbid >> 10);
85         proto_item_append_text(sub_ti, "DSCP %u", phbid >> 10);
86     }
87     else {
88         /* Case 2 of RFC 3140 */
89         proto_tree_add_uint(phbid_subtree, hf_phbid_code,
90                             tvb, offset, 2, phbid);
91         if (type == 1)
92             proto_item_append_text(ti, "PHB id code %u", phbid >> 4);
93         proto_item_append_text(sub_ti, "PHB id code %u", phbid >> 4);
94     }
95     proto_tree_add_uint(phbid_subtree, hf_phbid_bit14, tvb, offset, 2, phbid);
96     proto_tree_add_uint(phbid_subtree, hf_phbid_bit15, tvb, offset, 2, phbid);
97 }
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  */
111