2 * Routines for MPLS data packet disassembly
4 * (c) Copyright Ashok Narayanan <ashokn@cisco.com>
6 * $Id: packet-mpls.c,v 1.14 2001/01/06 05:09:35 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 #include "packet-ppp.h"
52 static gint proto_mpls = -1;
54 static gint ett_mpls = -1;
56 /* Special labels in MPLS */
58 IP4_EXPLICIT_NULL = 0,
66 static const value_string special_labels[] = {
67 {IP4_EXPLICIT_NULL, "IPv4 Explicit-Null"},
68 {ROUTER_ALERT, "Router Alert"},
69 {IP6_EXPLICIT_NULL, "IPv6 Explicit-Null"},
70 {IMPLICIT_NULL, "Implicit-Null"},
74 /* MPLS filter values */
75 enum mpls_filter_keys {
77 /* Is the packet MPLS-encapsulated? */
80 /* MPLS encap properties */
83 MPLSF_BOTTOM_OF_STACK,
89 static int mpls_filter[MPLSF_MAX];
90 static hf_register_info mplsf_info[] = {
92 /* {&mpls_filter[MPLSF_PACKET],
93 {"MPLS Label Switched Packet", "mpls", FT_UINT8, BASE_NONE, NULL, 0x0,
96 {&mpls_filter[MPLSF_LABEL],
97 {"MPLS Label", "mpls.label", FT_UINT32, BASE_DEC, VALS(special_labels), 0x0,
100 {&mpls_filter[MPLSF_EXP],
101 {"MPLS Experimental Bits", "mpls.exp", FT_UINT8, BASE_DEC, NULL, 0x0,
104 {&mpls_filter[MPLSF_BOTTOM_OF_STACK],
105 {"MPLS Bottom Of Label Stack", "mpls.bottom", FT_UINT8, BASE_DEC, NULL, 0x0,
108 {&mpls_filter[MPLSF_TTL],
109 {"MPLS TTL", "mpls.ttl", FT_UINT8, BASE_DEC, NULL, 0x0,
113 static dissector_handle_t ip_handle;
116 * Given a 4-byte MPLS label starting at offset "offset", in tvbuff "tvb",
118 * Return the label in "label", EXP bits in "exp",
119 * bottom_of_stack in "bos", and TTL in "ttl"
121 void decode_mpls_label(tvbuff_t *tvb, int offset,
122 guint32 *label, guint8 *exp,
123 guint8 *bos, guint8 *ttl)
125 guint8 octet0 = tvb_get_guint8(tvb, offset+0);
126 guint8 octet1 = tvb_get_guint8(tvb, offset+1);
127 guint8 octet2 = tvb_get_guint8(tvb, offset+2);
129 *label = (octet0 << 12) + (octet1 << 4) + ((octet2 >> 4) & 0xff);
130 *exp = (octet2 >> 1) & 0x7;
131 *bos = (octet2 & 0x1);
132 *ttl = tvb_get_guint8(tvb, offset+3);
136 dissect_mpls(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
144 proto_tree *mpls_tree;
148 CHECK_DISPLAY_AS_DATA(proto_mpls, tvb, pinfo, tree);
150 if (check_col(pinfo->fd, COL_PROTOCOL)) {
151 col_set_str(pinfo->fd,COL_PROTOCOL, "MPLS");
154 if (check_col(pinfo->fd,COL_INFO)) {
155 col_add_fstr(pinfo->fd,COL_INFO,"MPLS Label Switched Packet");
158 /* Start Decoding Here. */
159 while (tvb_reported_length_remaining(tvb, offset) > 0) {
160 decode_mpls_label(tvb, offset, &label, &exp, &bos, &ttl);
164 ti = proto_tree_add_item(tree, proto_mpls, tvb, offset, 4, FALSE);
165 mpls_tree = proto_item_add_subtree(ti, ett_mpls);
167 if (label <= MAX_RESERVED)
168 proto_tree_add_uint_format(mpls_tree, mpls_filter[MPLSF_LABEL], tvb,
169 offset, 3, label, "Label: %u (%s)",
170 label, val_to_str(label, special_labels,
171 "Reserved - Unknown"));
173 proto_tree_add_uint(mpls_tree, mpls_filter[MPLSF_LABEL], tvb,
176 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_EXP], tvb,
178 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_BOTTOM_OF_STACK], tvb,
180 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_TTL], tvb,
186 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
187 call_dissector(ip_handle, next_tvb, pinfo, tree);
191 proto_register_mpls(void)
193 static gint *ett[] = {
197 proto_mpls = proto_register_protocol("MultiProtocol Label Switching Header",
199 proto_register_field_array(proto_mpls, mplsf_info, array_length(mplsf_info));
200 proto_register_subtree_array(ett, array_length(ett));
204 proto_reg_handoff_mpls(void)
207 * Get a handle for the IP dissector.
209 ip_handle = find_dissector("ip");
211 dissector_add("ethertype", ETHERTYPE_MPLS, dissect_mpls);
212 dissector_add("ppp.protocol", PPP_MPLS_UNI, dissect_mpls);