2 * Routines for MPLS data packet disassembly
5 * (c) Copyright Ashok Narayanan <ashokn@cisco.com>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * 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
42 #include <epan/packet.h>
46 #include "packet-ppp.h"
48 static gint proto_mpls = -1;
50 static gint ett_mpls = -1;
51 static gint ett_mpls_control = -1;
53 /* Special labels in MPLS */
55 IP4_EXPLICIT_NULL = 0,
63 static const value_string special_labels[] = {
64 {IP4_EXPLICIT_NULL, "IPv4 Explicit-Null"},
65 {ROUTER_ALERT, "Router Alert"},
66 {IP6_EXPLICIT_NULL, "IPv6 Explicit-Null"},
67 {IMPLICIT_NULL, "Implicit-Null"},
71 /* MPLS filter values */
72 enum mpls_filter_keys {
74 /* Is the packet MPLS-encapsulated? */
77 /* MPLS encap properties */
80 MPLSF_BOTTOM_OF_STACK,
86 static int mpls_filter[MPLSF_MAX];
87 static int hf_mpls_control_control = -1;
88 static int hf_mpls_control_res = -1;
90 static hf_register_info mplsf_info[] = {
92 /* {&mpls_filter[MPLSF_PACKET],
93 {"MPLS Label Switched Packet", "mpls", FT_UINT8, BASE_DEC, 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,
112 {&hf_mpls_control_control,
113 {"MPLS Control Channel", "mpls.cw.control", FT_UINT8, BASE_DEC, NULL, 0xF0,
114 "First nibble", HFILL }},
116 {&hf_mpls_control_res,
117 {"Reserved", "mpls.cw.res", FT_UINT16, BASE_HEX, NULL, 0xFFF,
118 "Reserved", HFILL }},
121 static dissector_handle_t ipv4_handle;
122 static dissector_handle_t ipv6_handle;
123 static dissector_handle_t eth_handle;
124 static dissector_handle_t data_handle;
125 static dissector_table_t ppp_subdissector_table;
128 * Given a 4-byte MPLS label starting at offset "offset", in tvbuff "tvb",
130 * Return the label in "label", EXP bits in "exp",
131 * bottom_of_stack in "bos", and TTL in "ttl"
133 void decode_mpls_label(tvbuff_t *tvb, int offset,
134 guint32 *label, guint8 *exp,
135 guint8 *bos, guint8 *ttl)
137 guint8 octet0 = tvb_get_guint8(tvb, offset+0);
138 guint8 octet1 = tvb_get_guint8(tvb, offset+1);
139 guint8 octet2 = tvb_get_guint8(tvb, offset+2);
141 *label = (octet0 << 12) + (octet1 << 4) + ((octet2 >> 4) & 0xff);
142 *exp = (octet2 >> 1) & 0x7;
143 *bos = (octet2 & 0x1);
144 *ttl = tvb_get_guint8(tvb, offset+3);
148 dissect_mpls_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
150 proto_tree *mpls_control_tree = NULL;
154 guint16 res, ppp_proto;
156 if (tvb_reported_length_remaining(tvb, 0) < 4){
158 proto_tree_add_text(tree, tvb, 0, -1, "Error processing Message");
161 ctrl = (tvb_get_guint8(tvb, 0) & 0xF0) >> 4;
162 res = tvb_get_ntohs(tvb, 0) & 0x0FFF;
163 ppp_proto = tvb_get_ntohs(tvb, 2);
165 ti = proto_tree_add_text(tree, tvb, 0, 4, "MPLS PW Control Channel Header");
166 mpls_control_tree = proto_item_add_subtree(ti, ett_mpls_control);
167 if(mpls_control_tree == NULL) return;
169 proto_tree_add_uint_format(mpls_control_tree, hf_mpls_control_control, tvb, 0, 1,
170 ctrl, "Control Channel: 0x%1x", ctrl);
171 proto_tree_add_uint_format(mpls_control_tree, hf_mpls_control_res, tvb, 0, 2,
172 res, "Reserved: 0x%03x", res);
173 proto_tree_add_text(mpls_control_tree, tvb, 2, 2,
174 "PPP DLL Protocol Number: %s (0x%04X)",
175 val_to_str(ppp_proto, ppp_vals, "Unknown"), ppp_proto);
177 next_tvb = tvb_new_subset(tvb, 4, -1, -1);
178 if (!dissector_try_port(ppp_subdissector_table, ppp_proto,
179 next_tvb, pinfo, tree)) {
180 call_dissector(data_handle, next_tvb, pinfo, tree);
187 dissect_mpls(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
196 proto_tree *mpls_tree;
200 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
201 col_set_str(pinfo->cinfo,COL_PROTOCOL, "MPLS");
204 if (check_col(pinfo->cinfo,COL_INFO)) {
205 col_add_fstr(pinfo->cinfo,COL_INFO,"MPLS Label Switched Packet");
208 /* Start Decoding Here. */
209 while (tvb_reported_length_remaining(tvb, offset) > 0) {
210 decode_mpls_label(tvb, offset, &label, &exp, &bos, &ttl);
214 ti = proto_tree_add_item(tree, proto_mpls, tvb, offset, 4, FALSE);
215 mpls_tree = proto_item_add_subtree(ti, ett_mpls);
217 proto_item_append_text(ti, ", Label: %u", label);
218 if (label <= MAX_RESERVED){
219 proto_tree_add_uint_format(mpls_tree, mpls_filter[MPLSF_LABEL], tvb,
220 offset, 3, label, "MPLS Label: %u (%s)",
221 label, val_to_str(label, special_labels,
222 "Reserved - Unknown"));
223 proto_item_append_text(ti, " (%s)", val_to_str(label, special_labels,
224 "Reserved - Unknown"));
226 proto_tree_add_uint_format(mpls_tree, mpls_filter[MPLSF_LABEL], tvb,
227 offset, 3, label, "MPLS Label: %u", label);
230 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_EXP], tvb,
232 proto_item_append_text(ti, ", Exp: %u", exp);
234 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_BOTTOM_OF_STACK], tvb,
236 proto_item_append_text(ti, ", S: %u", bos);
238 proto_tree_add_uint(mpls_tree,mpls_filter[MPLSF_TTL], tvb,
240 proto_item_append_text(ti, ", TTL: %u", ttl);
245 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
247 ipvers = (tvb_get_guint8(tvb, offset) >> 4) & 0x0F;
249 call_dissector(ipv6_handle, next_tvb, pinfo, tree);
250 } else if (ipvers == 4) {
251 call_dissector(ipv4_handle, next_tvb, pinfo, tree);
252 } else if (ipvers == 1) {
253 dissect_mpls_control(next_tvb, pinfo, tree);
255 call_dissector(eth_handle, next_tvb, pinfo, tree);
260 proto_register_mpls(void)
262 static gint *ett[] = {
267 proto_mpls = proto_register_protocol("MultiProtocol Label Switching Header",
269 proto_register_field_array(proto_mpls, mplsf_info, array_length(mplsf_info));
270 proto_register_subtree_array(ett, array_length(ett));
274 proto_reg_handoff_mpls(void)
276 dissector_handle_t mpls_handle;
279 * Get a handle for the IPv4 and IPv6 dissectors and PPP protocol dissector table.
281 ipv4_handle = find_dissector("ip");
282 ipv6_handle = find_dissector("ipv6");
283 eth_handle = find_dissector("eth");
284 data_handle = find_dissector("data");
285 ppp_subdissector_table = find_dissector_table("ppp.protocol");
288 mpls_handle = create_dissector_handle(dissect_mpls, proto_mpls);
289 dissector_add("ethertype", ETHERTYPE_MPLS, mpls_handle);
290 dissector_add("ethertype", ETHERTYPE_MPLS_MULTI, mpls_handle);
291 dissector_add("ppp.protocol", PPP_MPLS_UNI, mpls_handle);
292 dissector_add("ppp.protocol", PPP_MPLS_MULTI, mpls_handle);
293 dissector_add("chdlctype", ETHERTYPE_MPLS, mpls_handle);
294 dissector_add("chdlctype", ETHERTYPE_MPLS_MULTI, mpls_handle);
295 dissector_add("gre.proto", ETHERTYPE_MPLS, mpls_handle);
296 dissector_add("gre.proto", ETHERTYPE_MPLS_MULTI, mpls_handle);