2 * Routines for MPLS data packet disassembly
4 * (c) Copyright Ashok Narayanan <ashokn@cisco.com>
6 * $Id: packet-mpls.c,v 1.7 2000/05/31 05:07:19 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 * This module defines routines to handle Ethernet-encapsulated MPLS IP packets.
32 * It should implement all the functionality in <draft-ietf-mpls-label-encaps-07.txt>
33 * Multicast MPLS support is not tested yet
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
48 #include "packet-ip.h"
50 static gint proto_mpls = -1;
52 static gint ett_mpls = -1;
54 /* Special labels in MPLS */
56 IP4_EXPLICIT_NULL = 0,
64 static const value_string special_labels[] = {
65 {IP4_EXPLICIT_NULL, "IPv4 Explicit-Null"},
66 {ROUTER_ALERT, "Router Alert"},
67 {IP6_EXPLICIT_NULL, "IPv6 Explicit-Null"},
68 {IMPLICIT_NULL, "Implicit-Null"},
72 /* MPLS filter values */
73 enum mpls_filter_keys {
75 /* Is the packet MPLS-encapsulated? */
78 /* MPLS encap properties */
81 MPLSF_BOTTOM_OF_STACK,
87 static int mpls_filter[MPLSF_MAX];
88 static hf_register_info mplsf_info[] = {
90 /* {&mpls_filter[MPLSF_PACKET],
91 {"MPLS Label Switched Packet", "mpls", FT_UINT8, BASE_NONE, NULL, 0x0,
94 {&mpls_filter[MPLSF_LABEL],
95 {"MPLS Label", "mpls.label", FT_UINT32, BASE_DEC, VALS(special_labels), 0x0,
98 {&mpls_filter[MPLSF_EXP],
99 {"MPLS Experimental Bits", "mpls.exp", FT_UINT8, BASE_DEC, NULL, 0x0,
102 {&mpls_filter[MPLSF_BOTTOM_OF_STACK],
103 {"MPLS Bottom Of Label Stack", "mpls.bottom", FT_UINT8, BASE_DEC, NULL, 0x0,
106 {&mpls_filter[MPLSF_TTL],
107 {"MPLS TTL", "mpls.ttl", FT_UINT8, BASE_DEC, NULL, 0x0,
112 * Given a 4-byte MPLS label starting at "start", decode this.
113 * Return the label in "label", EXP bits in "exp",
114 * bottom_of_stack in "bos", and TTL in "ttl"
116 void decode_mpls_label(const unsigned char *start,
117 guint32 *label, guint8 *exp,
118 guint8 *bos, guint8 *ttl)
120 *label = (start[0] << 12) + (start[1] << 4) + ((start[2] >> 4) & 0xff);
121 *exp = (start[2] >> 1) & 0x7;
122 *bos = (start[2] & 0x1);
127 dissect_mpls(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
134 proto_tree *mpls_tree;
137 if (check_col(fd, COL_PROTOCOL)) {
138 col_add_str(fd,COL_PROTOCOL, "MPLS");
141 if (check_col(fd,COL_INFO)) {
142 col_add_fstr(fd,COL_INFO,"MPLS Label Switched Packet");
145 /* Start Decoding Here. */
147 if (!BYTES_ARE_IN_FRAME(offset, 4)) {
148 dissect_data(pd, offset, fd, tree);
152 decode_mpls_label(pd+offset, &label, &exp, &bos, &ttl);
156 ti = proto_tree_add_item(tree, proto_mpls, NullTVB, offset, 4, FALSE);
157 mpls_tree = proto_item_add_subtree(ti, ett_mpls);
159 if (label <= MAX_RESERVED)
160 proto_tree_add_uint_format(mpls_tree, mpls_filter[MPLSF_LABEL], NullTVB,
161 offset, 3, label, "Label: %d (%s)",
162 label, val_to_str(label, special_labels,
163 "Reserved - Unknown"));
165 proto_tree_add_uint(mpls_tree, mpls_filter[MPLSF_LABEL], NullTVB,
168 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_EXP], NullTVB,
170 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_BOTTOM_OF_STACK], NullTVB,
172 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_TTL], NullTVB,
178 dissect_ip(pd, offset, fd, tree);
182 proto_register_mpls(void)
184 static gint *ett[] = {
188 proto_mpls = proto_register_protocol("MultiProtocol Label Switching Header", "mpls");
189 proto_register_field_array(proto_mpls, mplsf_info, array_length(mplsf_info));
190 proto_register_subtree_array(ett, array_length(ett));
194 proto_reg_handoff_mpls(void)
196 dissector_add("ethertype", ETHERTYPE_MPLS, dissect_mpls);