aboutsummaryrefslogtreecommitdiffstats
path: root/packet-diffserv-mpls-common.c
blob: 71d93490c23c31b4b3f15a1255f9026977f97255 (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
111
112
113
114
/* packet-diffserv-mpls-common.c
 * Routines for the common part of Diffserv MPLS signaling protocols
 * Author: Endoh Akira (endoh@netmarks.co.jp)
 *
 * $Id: packet-diffserv-mpls-common.c,v 1.2 2003/10/13 20:53:30 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
 * 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.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <glib.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, gint **etts)
{
    proto_item  *ti = NULL, *sub_ti;
    proto_tree  *tree2 = NULL, *phbid_subtree;
    int exp;
    guint16 phbid;

    switch (type) {
    case 1:  /* E-LSP */
	ti = proto_tree_add_item(tree, hf_map, tvb, offset, 4, FALSE);
	tree2 = proto_item_add_subtree(ti, ett_map);
	proto_item_set_text(ti, "MAP: ");
	offset ++;
	exp = tvb_get_guint8(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, FALSE);
    phbid_subtree = proto_item_add_subtree(sub_ti, ett_map_phbid);
    proto_item_set_text(sub_ti, "%s: ", (type == 1) ? "PHBID" : "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);
}