Add compat_macros.h to the tarball
[obnox/wireshark/wip.git] / packet-ldp.c
1 /* packet-ldp.c
2  * Routines for LDP (RFC 3036) packet disassembly
3  *
4  * $Id: packet-ldp.c,v 1.43 2002/08/28 21:00:20 jmayer Exp $
5  *
6  * Copyright (c) November 2000 by Richard Sharpe <rsharpe@ns.aus.com>
7  *
8  * CRLDP (RFC3212) is now supported
9  *   - (c) 2002 Michael Rozhavsky <mike[AT]tochna.technion.ac.il>
10  *
11  * Ethereal - Network traffic analyzer
12  * By Gerald Combs <gerald@ethereal.com>
13  * Copyright 1999 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #include <time.h>
38 #include <glib.h>
39 #include <string.h>
40 #include <epan/packet.h>
41 #include <epan/resolv.h>
42 #include "prefs.h"
43 #include "afn.h"
44
45 #include "packet-frame.h"
46
47 #define TCP_PORT_LDP 646
48 #define UDP_PORT_LDP 646
49
50 void proto_reg_handoff_ldp(void);
51
52 static int proto_ldp = -1;
53
54 /* Delete the following if you do not use it, or add to it if you need */
55 static int hf_ldp_req = -1;
56 static int hf_ldp_rsp = -1;
57 static int hf_ldp_version = -1;
58 static int hf_ldp_pdu_len = -1;
59 static int hf_ldp_lsr = -1;
60 static int hf_ldp_ls_id = -1;
61 static int hf_ldp_msg_ubit = -1;
62 static int hf_ldp_msg_type = -1;
63 static int hf_ldp_msg_len = -1;
64 static int hf_ldp_msg_id = -1;
65 static int hf_ldp_msg_vendor_id = -1;
66 static int hf_ldp_msg_experiment_id = -1;
67 static int hf_ldp_tlv_value = -1;
68 static int hf_ldp_tlv_type = -1;
69 static int hf_ldp_tlv_unknown = -1;
70 static int hf_ldp_tlv_len = -1;
71 static int hf_ldp_tlv_val_hold = -1;
72 static int hf_ldp_tlv_val_target = -1;
73 static int hf_ldp_tlv_val_request = -1;
74 static int hf_ldp_tlv_val_res = -1;
75 static int hf_ldp_tlv_ipv4_taddr = -1;
76 static int hf_ldp_tlv_config_seqno = -1;
77 static int hf_ldp_tlv_ipv6_taddr = -1;
78 static int hf_ldp_tlv_fec_wc = -1;
79 static int hf_ldp_tlv_fec_af = -1;
80 static int hf_ldp_tlv_fec_len = -1;
81 static int hf_ldp_tlv_fec_pfval = -1;
82 static int hf_ldp_tlv_fec_hoval = -1;
83 static int hf_ldp_tlv_addrl_addr_family = -1;
84 static int hf_ldp_tlv_addrl_addr = -1;
85 static int hf_ldp_tlv_hc_value = -1;
86 static int hf_ldp_tlv_pv_lsrid = -1;
87 static int hf_ldp_tlv_generic_label = -1;
88 static int hf_ldp_tlv_atm_label_vbits = -1;
89 static int hf_ldp_tlv_atm_label_vpi = -1;
90 static int hf_ldp_tlv_atm_label_vci = -1;
91 static int hf_ldp_tlv_fr_label_len = -1;
92 static int hf_ldp_tlv_fr_label_dlci = -1;
93 static int hf_ldp_tlv_status_ebit = -1;
94 static int hf_ldp_tlv_status_fbit = -1;
95 static int hf_ldp_tlv_status_data = -1;
96 static int hf_ldp_tlv_status_msg_id = -1;
97 static int hf_ldp_tlv_status_msg_type = -1;
98 static int hf_ldp_tlv_extstatus_data = -1;
99 static int hf_ldp_tlv_returned_version = -1;
100 static int hf_ldp_tlv_returned_pdu_len = -1;
101 static int hf_ldp_tlv_returned_lsr = -1;
102 static int hf_ldp_tlv_returned_ls_id = -1;
103 static int hf_ldp_tlv_returned_msg_ubit = -1;
104 static int hf_ldp_tlv_returned_msg_type = -1;
105 static int hf_ldp_tlv_returned_msg_len = -1;
106 static int hf_ldp_tlv_returned_msg_id = -1;
107 static int hf_ldp_tlv_mac = -1;
108 static int hf_ldp_tlv_sess_ver = -1;
109 static int hf_ldp_tlv_sess_ka = -1;
110 static int hf_ldp_tlv_sess_advbit = -1;
111 static int hf_ldp_tlv_sess_ldetbit = -1;
112 static int hf_ldp_tlv_sess_pvlim = -1;
113 static int hf_ldp_tlv_sess_mxpdu = -1;
114 static int hf_ldp_tlv_sess_rxlsr = -1;
115 static int hf_ldp_tlv_sess_rxls = -1;
116 static int hf_ldp_tlv_sess_atm_merge = -1;
117 static int hf_ldp_tlv_sess_atm_lr = -1;
118 static int hf_ldp_tlv_sess_atm_dir = -1;
119 static int hf_ldp_tlv_sess_atm_minvpi = -1;
120 static int hf_ldp_tlv_sess_atm_maxvpi = -1;
121 static int hf_ldp_tlv_sess_atm_minvci = -1;
122 static int hf_ldp_tlv_sess_atm_maxvci = -1;
123 static int hf_ldp_tlv_sess_fr_merge = -1;
124 static int hf_ldp_tlv_sess_fr_lr = -1;
125 static int hf_ldp_tlv_sess_fr_dir = -1;
126 static int hf_ldp_tlv_sess_fr_len = -1;
127 static int hf_ldp_tlv_sess_fr_mindlci = -1;
128 static int hf_ldp_tlv_sess_fr_maxdlci = -1;
129 static int hf_ldp_tlv_lbl_req_msg_id = -1;
130 static int hf_ldp_tlv_vendor_id = -1;
131 static int hf_ldp_tlv_experiment_id = -1;
132 static int hf_ldp_tlv_fec_vc_controlword = -1;
133 static int hf_ldp_tlv_fec_vc_vctype = -1;
134 static int hf_ldp_tlv_fec_vc_infolength = -1;
135 static int hf_ldp_tlv_fec_vc_groupid = -1;
136 static int hf_ldp_tlv_fec_vc_vcid = -1;
137 static int hf_ldp_tlv_fec_vc_intparam_length = -1;
138 static int hf_ldp_tlv_fec_vc_intparam_mtu = -1;
139 static int hf_ldp_tlv_fec_vc_intparam_id = -1;
140 static int hf_ldp_tlv_fec_vc_intparam_maxcatmcells = -1;
141 static int hf_ldp_tlv_fec_vc_intparam_desc = -1;
142 static int hf_ldp_tlv_fec_vc_intparam_cembytes = -1;
143 static int hf_ldp_tlv_fec_vc_intparam_vpnid_oui = -1;
144 static int hf_ldp_tlv_fec_vc_intparam_vpnid_index = -1;
145 static int hf_ldp_tlv_lspid_act_flg = -1;
146 static int hf_ldp_tlv_lspid_cr_lsp = -1;
147 static int hf_ldp_tlv_lspid_ldpid = -1;
148 static int hf_ldp_tlv_er_hop_loose = -1;
149 static int hf_ldp_tlv_er_hop_prelen = -1;
150 static int hf_ldp_tlv_er_hop_prefix4 = -1;
151 static int hf_ldp_tlv_er_hop_prefix6 = -1;
152 static int hf_ldp_tlv_er_hop_as = -1;
153 static int hf_ldp_tlv_er_hop_cr_lsp = -1;
154 static int hf_ldp_tlv_er_hop_ldpid = -1;
155 static int hf_ldp_tlv_flags_reserv = -1;
156 static int hf_ldp_tlv_flags_weight = -1;
157 static int hf_ldp_tlv_flags_ebs = -1;
158 static int hf_ldp_tlv_flags_cbs = -1;
159 static int hf_ldp_tlv_flags_cdr = -1;
160 static int hf_ldp_tlv_flags_pbs = -1;
161 static int hf_ldp_tlv_flags_pdr = -1;
162 static int hf_ldp_tlv_frequency = -1;
163 static int hf_ldp_tlv_pdr = -1;
164 static int hf_ldp_tlv_pbs = -1;
165 static int hf_ldp_tlv_cdr = -1;
166 static int hf_ldp_tlv_cbs = -1;
167 static int hf_ldp_tlv_ebs = -1;
168 static int hf_ldp_tlv_weight = -1;
169 static int hf_ldp_tlv_set_prio = -1;
170 static int hf_ldp_tlv_hold_prio = -1;
171 static int hf_ldp_tlv_route_pinning = -1;
172 static int hf_ldp_tlv_resource_class = -1;
173 static int ett_ldp = -1;
174 static int ett_ldp_header = -1;
175 static int ett_ldp_ldpid = -1;
176 static int ett_ldp_message = -1;
177 static int ett_ldp_tlv = -1;
178 static int ett_ldp_tlv_val = -1;
179 static int ett_ldp_fec = -1;
180 static int ett_ldp_fec_vc_interfaceparam = -1;
181
182 static int tcp_port = 0;
183 static int udp_port = 0;
184
185 /* desegmentation of LDP over TCP */
186 static gboolean ldp_desegment = FALSE;
187
188 /* Add your functions here */
189
190 static int global_ldp_tcp_port = TCP_PORT_LDP;
191 static int global_ldp_udp_port = UDP_PORT_LDP;
192
193 /*
194  * The following define all the TLV types I know about
195  */
196
197 #define TLV_FEC                    0x0100
198 #define TLV_ADDRESS_LIST           0x0101
199 #define TLV_HOP_COUNT              0x0103
200 #define TLV_PATH_VECTOR            0x0104
201 #define TLV_GENERIC_LABEL          0x0200
202 #define TLV_ATM_LABEL              0x0201
203 #define TLV_FRAME_LABEL            0x0202
204 #define TLV_STATUS                 0x0300
205 #define TLV_EXTENDED_STATUS        0x0301
206 #define TLV_RETURNED_PDU           0x0302
207 #define TLV_RETURNED_MESSAGE       0x0303
208 #define TLV_COMMON_HELLO_PARMS     0x0400
209 #define TLV_IPV4_TRANSPORT_ADDRESS 0x0401
210 #define TLV_CONFIGURATION_SEQNO    0x0402
211 #define TLV_IPV6_TRANSPORT_ADDRESS 0x0403
212 #define TLV_MAC                    0x0404
213 #define TLV_COMMON_SESSION_PARMS   0x0500
214 #define TLV_ATM_SESSION_PARMS      0x0501
215 #define TLV_FRAME_RELAY_SESSION_PARMS 0x0502
216 #define TLV_LABEL_REQUEST_MESSAGE_ID 0x0600
217 #define TLV_ER                     0x0800
218 #define TLV_ER_HOP_IPV4            0x0801
219 #define TLV_ER_HOP_IPV6            0x0802
220 #define TLV_ER_HOP_AS              0x0803
221 #define TLV_ER_HOP_LSPID           0x0804
222 #define TLV_TRAFFIC_PARAM          0x0810
223 #define TLV_PREEMPTION             0x0820
224 #define TLV_LSPID                  0x0821
225 #define TLV_RESOURCE_CLASS         0x0822
226 #define TLV_ROUTE_PINNING          0x0823
227
228 #define TLV_VENDOR_PRIVATE_START   0x3E00
229 #define TLV_VENDOR_PRIVATE_END     0x3EFF
230 #define TLV_EXPERIMENTAL_START     0x3F00
231 #define TLV_EXPERIMENTAL_END       0x3FFF
232
233 static const value_string tlv_type_names[] = {
234   { TLV_FEC,                       "Forwarding Equivalence Classes TLV" },
235   { TLV_ADDRESS_LIST,              "Address List TLV"},
236   { TLV_HOP_COUNT,                 "Hop Count TLV"},
237   { TLV_PATH_VECTOR,               "Path Vector TLV"},
238   { TLV_GENERIC_LABEL,             "Generic Label TLV"},
239   { TLV_ATM_LABEL,                 "ATM Label TLV"},
240   { TLV_FRAME_LABEL,               "Frame Label TLV"},
241   { TLV_STATUS,                    "Status TLV"},
242   { TLV_EXTENDED_STATUS,           "Extended Status TLV"},
243   { TLV_RETURNED_PDU,              "Returned PDU TLV"},
244   { TLV_RETURNED_MESSAGE,          "Returned Message TLV"},
245   { TLV_COMMON_HELLO_PARMS,        "Common Hello Parameters TLV"},
246   { TLV_IPV4_TRANSPORT_ADDRESS,    "IPv4 Transport Address TLV"},
247   { TLV_CONFIGURATION_SEQNO,       "Configuration Sequence Number TLV"},
248   { TLV_IPV6_TRANSPORT_ADDRESS,    "IPv6 Transport Address TLV"},
249   { TLV_MAC,                       "MAC TLV"},
250   { TLV_COMMON_SESSION_PARMS,      "Common Session Parameters TLV"},
251   { TLV_ATM_SESSION_PARMS,         "ATM Session Parameters TLV"},
252   { TLV_FRAME_RELAY_SESSION_PARMS, "Frame Relay Session Parameters TLV"},
253   { TLV_LABEL_REQUEST_MESSAGE_ID,  "Label Request Message ID TLV"},
254   { TLV_LSPID,                     "LSP ID TLV"},
255   { TLV_ER,                        "Explicit route TLV"},
256   { TLV_ER_HOP_IPV4,               "ER hop IPv4 prefix TLV"},
257   { TLV_ER_HOP_IPV6,               "ER hop IPv6 prefix TLV"},
258   { TLV_ER_HOP_AS,                 "ER hop Autonomous system number prefix TLV"},
259   { TLV_TRAFFIC_PARAM,             "Traffic parameters TLV"},
260   { TLV_PREEMPTION,                "Preemption TLV"},
261   { TLV_ER_HOP_LSPID,              "ER hop LSPID prefix TLV"},
262   { TLV_RESOURCE_CLASS,            "Resource Class (Color) TLV"},
263   { TLV_ROUTE_PINNING,             "Route Pinning TLV"},
264   { TLV_VENDOR_PRIVATE_START,   "Vendor Private TLV"},
265   { TLV_EXPERIMENTAL_START,     "Experimental TLV"},
266   { 0, NULL}
267 };
268
269 /*
270  * The following define all the message types I know about
271  */
272
273 #define LDP_NOTIFICATION       0x0001
274 #define LDP_HELLO              0x0100
275 #define LDP_INITIALIZATION     0x0200
276 #define LDP_KEEPALIVE          0x0201
277 #define LDP_ADDRESS            0x0300
278 #define LDP_ADDRESS_WITHDRAWAL 0x0301
279 #define LDP_LABEL_MAPPING      0x0400
280 #define LDP_LABEL_REQUEST      0x0401
281 #define LDP_LABEL_WITHDRAWAL   0x0402
282 #define LDP_LABEL_RELEASE      0x0403
283 #define LDP_LABEL_ABORT_REQUEST 0x0404
284 #define LDP_VENDOR_PRIVATE_START 0x3E00
285 #define LDP_VENDOR_PRIVATE_END   0x3EFF
286 #define LDP_EXPERIMENTAL_MESSAGE_START 0x3F00
287 #define LDP_EXPERIMENTAL_MESSAGE_END   0x3FFF
288
289 static const value_string ldp_message_types[] = {
290   {LDP_NOTIFICATION,             "Notification Message"},
291   {LDP_HELLO,                    "Hello Message"},
292   {LDP_INITIALIZATION,           "Initialization Message"},
293   {LDP_KEEPALIVE,                "Keep Alive Message"},
294   {LDP_ADDRESS,                  "Address Message"},
295   {LDP_ADDRESS_WITHDRAWAL,       "Address Withdrawal Message"},
296   {LDP_LABEL_MAPPING,            "Label Mapping Message"},
297   {LDP_LABEL_REQUEST,            "Label Request Message"},
298   {LDP_LABEL_WITHDRAWAL,         "Label Withdrawal Message"},
299   {LDP_LABEL_RELEASE,            "Label Release Message"},
300   {LDP_LABEL_ABORT_REQUEST,      "Label Abort Request Message"},
301   {LDP_VENDOR_PRIVATE_START,     "Vendor-Private Message"},
302   {LDP_EXPERIMENTAL_MESSAGE_START,     "Experimental Message"},
303   {0, NULL}
304 };
305
306 static const true_false_string ldp_message_ubit = {
307   "Unknown bit set",
308   "Unknown bit not set"
309 };
310
311 static const true_false_string hello_targeted_vals = {
312   "Targeted Hello",
313   "Link Hello"
314 };
315
316 static const value_string tlv_unknown_vals[] = {
317   {0, "Known TLV, do not Forward"},
318   {1, "Known TLV, do Forward"},
319   {2, "Unknown TLV, do not Forward"},
320   {3, "Unknown TLV, do Forward"},
321   {0, NULL}
322 };
323
324 #define WILDCARD_FEC    1
325 #define PREFIX_FEC      2
326 #define HOST_FEC        3
327 #define CRLSP_FEC       4
328 #define VC_FEC          0x80    /* draft-martini-l2circuit-trans-mpls */
329
330 static const value_string fec_types[] = {
331   {WILDCARD_FEC, "Wildcard FEC"},
332   {PREFIX_FEC, "Prefix FEC"},
333   {HOST_FEC, "Host Address FEC"},
334   {CRLSP_FEC, "CR LSP FEC"},
335   {VC_FEC, "Virtual Circuit FEC"},
336   {0, NULL}
337 };
338
339
340 static const value_string fec_vc_types_vals[] = {
341   {0x0001, "Frame Relay DLCI"},
342   {0x0002, "ATM VCC transport"},
343   {0x0003, "ATM VPC transport"},
344   {0x0004, "Ethernet VLAN"},
345   {0x0005, "Ethernet"},
346   {0x0006, "HDLC"},
347   {0x0007, "PPP"},
348   {0x0009, "ATM VCC cell transport"},
349   {0x8008, "CEM"},
350   {0x000A, "ATM VPC cell transport"},
351   {0x000B, "Ethernet VPLS"},
352   {0, NULL}
353 };
354
355
356 #define FEC_VC_INTERFACEPARAM_MTU          0x01
357 #define FEC_VC_INTERFACEPARAM_MAXCATMCELLS 0x02
358 #define FEC_VC_INTERFACEPARAM_DESCRIPTION  0x03
359 #define FEC_VC_INTERFACEPARAM_CEMBYTES     0x04
360 #define FEC_VC_INTERFACEPARAM_CEMOPTIONS   0x05
361 #define FEC_VC_INTERFACEPARAM_VPNID        0x06
362
363
364 static const value_string fec_vc_interfaceparm[] = {
365   {FEC_VC_INTERFACEPARAM_MTU, "MTU"},
366   {FEC_VC_INTERFACEPARAM_MAXCATMCELLS, "Max Concatenated ATM cells"},
367   {FEC_VC_INTERFACEPARAM_DESCRIPTION, "Interface Description"},
368   {FEC_VC_INTERFACEPARAM_CEMBYTES, "CEM Payload Bytes"},
369   {FEC_VC_INTERFACEPARAM_CEMOPTIONS, "CEM options"},
370   {FEC_VC_INTERFACEPARAM_VPNID, "VPN Id"}
371 };
372
373 static const true_false_string fec_vc_cbit = {
374   "Contorl Word Present",
375   "Control Word NOT Present"
376 };
377
378
379
380 static const value_string tlv_atm_merge_vals[] = {
381   {0, "Merge not supported"},
382   {1, "VP merge supported"},
383   {2, "VC merge supported"},
384   {3, "VP & VC merge supported"},
385   {0, NULL}
386 };
387
388 static const value_string tlv_atm_vbits_vals[] = {
389   {0, "VPI & VCI Significant"},
390   {1, "Only VPI Significant"},
391   {2, "Only VCI Significant"},
392   {3, "VPI & VCI not Significant, nonsense"},
393   {0, NULL}
394 };
395
396 static const value_string tlv_fr_merge_vals[] = {
397   {0, "Merge not supported"},
398   {1, "Merge supported"},
399   {2, "Unspecified"},
400   {3, "Unspecified"},
401   {0, NULL}
402 };
403
404 static const value_string tlv_fr_len_vals[] = {
405   {0, "10 bits"},
406   {1, "Reserved"},
407   {2, "23 bits"},
408   {3, "Reserved"},
409   {0, NULL}
410 };
411
412 static const value_string ldp_act_flg_vals[] = {
413   {0, "indicates initial LSP setup"},
414   {1, "indicates modify LSP"},
415   {0, NULL}
416 };
417
418 static const value_string route_pinning_vals[] = {
419   {0, "route pinning is not requested"},
420   {1, "route pinning is requested"},
421   {0, NULL}
422 };
423
424 static const value_string ldp_loose_vals[] = {
425   {0, "strict hop"},
426   {1, "loose hop"},
427   {0, NULL}
428 };
429
430 static const true_false_string tlv_negotiable = {
431   "Negotiable",
432   "Not negotiable"
433 };
434
435 static const value_string freq_values[] = {
436   {0, "Unspecified"},
437   {1, "Frequent"},
438   {2, "VeryFrequent"},
439   {0, NULL}
440 };
441
442 static const true_false_string tlv_atm_dirbit = {
443   "Bidirectional capability",
444   "Unidirectional capability"
445 };
446
447 static const true_false_string hello_requested_vals = {
448   "Source requests periodic hellos",
449   "Source does not request periodic hellos"
450 };
451
452 static const true_false_string tlv_sess_advbit_vals = {
453   "Downstream On Demand proposed",
454   "Downstream Unsolicited proposed"
455 };
456
457 static const true_false_string tlv_sess_ldetbit_vals = {
458   "Loop Detection Enabled",
459   "Loop Detection Disabled"
460 };
461
462 static const true_false_string tlv_status_ebit = {
463   "Fatal Error Notification",
464   "Advisory Notification"
465 };
466
467 static const true_false_string tlv_status_fbit = {
468   "Notification should be Forwarded",
469   "Notification should NOT be Forwarded"
470 };
471
472 static const value_string tlv_status_data[] = {
473   {0, "Success"},
474   {1, "Bad LDP Identifier"},
475   {2, "Bad Protocol Version"},
476   {3, "Bad PDU Length"},
477   {4, "Unknown Message Type"},
478   {5, "Bad Message Length"},
479   {6, "Unknown TLV"},
480   {7, "Bad TLV Length"},
481   {8, "Malformed TLV Value"},
482   {9, "Hold Timer Expired"},
483   {10, "Shutdown"},
484   {11, "Loop Detected"},
485   {12, "Unknown FEC"},
486   {13, "No Route"},
487   {14, "No Label Resources"},
488   {15, "Label Resources / Available"},
489   {16, "Session Rejected / No Hello"},
490   {17, "Session Rejected / Parameters Advertisement Mode"},
491   {18, "Session Rejected / Parameters Max PDU Length"},
492   {19, "Session Rejected / Parameters Label Range"},
493   {20, "KeepAlive Timer Expired"},
494   {21, "Label Request Aborted"},
495   {22, "Missing Message Parameters"},
496   {23, "Unsoported Address Family"},
497   {24, "Session Rejected / Bad KeepAlive Time"},
498   {25, "Internal Error"},
499   {0x01000001,"Unexpected Diff-Serv TLV"},
500   {0x01000002,"Unsupported PHB"},
501   {0x01000003,"Invalid EXP<->PHB Mapping"},
502   {0x01000004,"Unsupported PSC"},
503   {0x01000005,"Per-LSP context allocation failure"},
504   {0x04000001,"Bad Explicit Routing TLV Error"},
505   {0x04000002,"Bad Strict Node Error"},
506   {0x04000003,"Bad Strict Node Error"},
507   {0x04000004,"Bad Initial ER-Hop Error"},
508   {0x04000005,"Resource Unavailable"},
509   {0x04000006,"Traffic Parameters Unavailable"},
510   {0x04000007,"LSP Preempted"},
511   {0x04000008,"Modify Request Not Supported"},
512   {0x20000001,"Illegal C-Bit"},
513   {0x20000002,"Wrong C-Bit"},
514   {0, NULL}
515 };
516
517 /* Dissect FEC TLV */
518
519 static void
520 dissect_tlv_fec(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
521 {
522         proto_tree *ti=NULL, *val_tree=NULL, *fec_tree=NULL, *vcintparam_tree=NULL;
523         guint16 family, ix=1, ax;
524         guint8  addr_size=0, *addr, implemented, prefix_len_octets, prefix_len, host_len, vc_len;
525         guint8  intparam_len;
526         void *str_handler=NULL;
527         char *str;
528
529         if (tree) {
530                 ti=proto_tree_add_text(tree, tvb, offset, rem, "FEC Elements");
531                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
532                 if(val_tree == NULL) return;
533
534                 while (rem > 0){
535                         switch (tvb_get_guint8(tvb, offset)) {
536                         case WILDCARD_FEC:
537                         case CRLSP_FEC:
538                                 ti = proto_tree_add_text(val_tree, tvb, offset, 1, "FEC Element %u", ix);
539                                 fec_tree = proto_item_add_subtree(ti, ett_ldp_fec);
540                                 if(fec_tree == NULL) return;
541                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_wc,tvb, offset, 1, FALSE);
542                                 rem -= 1;
543                                 offset += 1;
544                                 break;
545
546                         case PREFIX_FEC:
547                                 if( rem < 4 ){/*not enough*/
548                                         proto_tree_add_text(val_tree, tvb, offset, rem, "Error in FEC Element %u", ix);
549                                         return;
550                                 }
551                                 family=tvb_get_ntohs(tvb, offset+1);
552                                 prefix_len=tvb_get_guint8(tvb, offset+3);
553                                 prefix_len_octets=(prefix_len+7)/8;
554
555                                 implemented=1;
556                                 switch(family) {
557                                         case AFNUM_INET: /*IPv4*/
558                                                 addr_size=4;
559                                                 str_handler=ip_to_str;
560                                                 break;
561                                         case AFNUM_INET6: /*IPv6*/
562                                                 addr_size=16;
563                                                 str_handler=ip6_to_str;
564                                                 break;
565                                         default:
566                                                 implemented=0;
567                                                 break;
568                                 }
569
570                                 if( !implemented ) {
571                                         guint16 noctets;
572
573                                         noctets= rem>4+prefix_len_octets?4+prefix_len_octets:rem;
574                                         proto_tree_add_text(val_tree, tvb, offset, noctets,"Support for Address Family not implemented");
575                                         offset+=noctets;
576                                         rem-=noctets;
577                                         break;
578                                 }
579
580                                 if( rem < 4+MIN(addr_size, prefix_len_octets) ){
581                                         proto_tree_add_text(val_tree, tvb, offset, rem, "Error in FEC Element %u", ix);
582                                         return;
583                                 }
584
585                                 /*Add a subtree for this*/
586                                 ti = proto_tree_add_text(val_tree, tvb, offset, 4+MIN(addr_size, prefix_len_octets), "FEC Element %u", ix);
587                                 fec_tree = proto_item_add_subtree(ti, ett_ldp_fec);
588                                 if(fec_tree == NULL) return;
589                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_wc, tvb, offset, 1, FALSE);
590                                 offset += 1;
591
592                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_af, tvb, offset, 2, FALSE);
593                                 offset += 2;
594
595                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_len, tvb, offset, 1, FALSE);
596                                 offset += 1;
597
598
599                                 if( addr_size < prefix_len_octets) {
600                                         offset+=addr_size;
601                                         rem-=addr_size;
602                                         proto_tree_add_text(fec_tree, tvb, offset-1, 1, "Invalid prefix %u length for family %s", prefix_len, val_to_str(family, afn_vals, "Unknown Family"));
603                                         break;
604                                 }
605
606                                 if( (addr=g_malloc0(addr_size)) == NULL ){
607                                         /*big big trouble, no mem or bad addr_size*/
608                                         fprintf(stderr, "packet-ldp: dissect_tlv_fec() malloc failed\n");
609                                         return;
610                                 }
611
612                                 for(ax=0; ax+1 <= prefix_len_octets; ax++)
613                                         addr[ax]=tvb_get_guint8(tvb, offset+ax);
614                                 if( prefix_len % 8 )
615                                         addr[ax-1] = addr[ax-1]&(0xFF<<(8-prefix_len%8));
616
617                                 str = (* (char* (*)(guint8 *))str_handler)(addr);
618                                 proto_tree_add_string_format(fec_tree, hf_ldp_tlv_fec_pfval, tvb, offset, prefix_len_octets, str, "Prefix: %s", str);
619
620                                 offset += prefix_len_octets;
621                                 rem -= 4+prefix_len_octets;
622                                 g_free(addr);
623                                 break;
624
625                         case HOST_FEC:
626                                 if( rem < 4 ){/*not enough*/
627                                         proto_tree_add_text(val_tree, tvb, offset, rem, "Error in FEC Element %u", ix);
628                                         return;
629                                 }
630                                 family=tvb_get_ntohs(tvb, offset+1);
631                                 host_len=tvb_get_guint8(tvb, offset+3);
632
633                                 implemented=1;
634                                 switch(family) {
635                                         case AFNUM_INET: /*IPv4*/
636                                                 addr_size=4;
637                                                 str_handler=ip_to_str;
638                                                 break;
639                                         case AFNUM_INET6: /*IPv6*/
640                                                 addr_size=16;
641                                                 str_handler=ip6_to_str;
642                                                 break;
643                                         default:
644                                                 implemented=0;
645                                                 break;
646                                 }
647
648                                 if( !implemented ) {
649                                         guint16 noctets;
650
651                                         noctets= rem>4+host_len?4+host_len:rem;
652                                         proto_tree_add_text(val_tree, tvb, offset, noctets,"Support for Address Family not implemented");
653                                         offset+=noctets;
654                                         rem-=noctets;
655                                         break;
656                                 }
657
658                                 if( rem < 4+addr_size ){
659                                         proto_tree_add_text(val_tree, tvb, offset, rem, "Error in FEC Element %u", ix);
660                                         return;
661                                 }
662
663                                 /*Add a subtree for this*/
664                                 ti = proto_tree_add_text(val_tree, tvb, offset, 4+addr_size, "FEC Element %u", ix);
665                                 fec_tree = proto_item_add_subtree(ti, ett_ldp_fec);
666                                 if(fec_tree == NULL) return;
667                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_wc, tvb, offset, 1, FALSE);
668                                 offset += 1;
669
670                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_af, tvb, offset, 2, FALSE);
671                                 offset += 2;
672
673                                 proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_len, tvb, offset, 1, FALSE);
674                                 offset += 1;
675
676
677                                 if( addr_size != host_len) {
678                                         offset+=addr_size;
679                                         rem-=addr_size;
680                                         proto_tree_add_text(fec_tree, tvb, offset-1, 1, "Invalid address length %u length for family %s", host_len, val_to_str(family, afn_vals, "Unknown Family"));
681                                         break;
682                                 }
683
684                                 if( (addr=g_malloc0(addr_size)) == NULL ){
685                                         /*big big xtrouble, no mem or bad addr_size*/
686                                         fprintf(stderr, "packet-ldp: dissect_tlv_fec() malloc failed\n");
687                                         return;
688                                 }
689
690                                 for(ax=0; ax+1 <= host_len; ax++)
691                                         addr[ax]=tvb_get_guint8(tvb, offset+ax);
692
693                                 str = (* (char* (*)(guint8 *))str_handler)(addr);
694                                 proto_tree_add_string_format(fec_tree, hf_ldp_tlv_fec_hoval, tvb, offset, host_len, str, "Address: %s", str);
695
696                                 offset += host_len;
697                                 rem -= 4+host_len;
698                                 g_free(addr);
699                                 break;
700
701                         case VC_FEC:
702                           if( rem < 8 ){/*not enough bytes for a minimal VC_FEC*/
703                             proto_tree_add_text(val_tree, tvb, offset, rem, "Error in FEC Element %u", ix);
704                             return;
705                           }
706                           vc_len = tvb_get_guint8 (tvb, offset+3);
707
708
709                           ti = proto_tree_add_text(val_tree, tvb, offset, 8+vc_len, "FEC Element %u", ix);
710                           fec_tree = proto_item_add_subtree(ti, ett_ldp_fec);
711                           if(fec_tree == NULL) return;
712                           proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_wc, tvb, offset, 1, FALSE);
713                           proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_vc_controlword, tvb, offset+1, 1, FALSE);
714                           proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_vc_vctype, tvb, offset+1, 2, FALSE);
715                           proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_vc_infolength, tvb, offset+3,1,FALSE);
716                           proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_vc_groupid,tvb, offset +4, 4, FALSE);
717                           rem -=8;
718                           offset +=8;
719
720                           if ( (vc_len > 3) && ( rem > 3 ) ) { /* there is enough room for vcid */
721                             proto_tree_add_item(fec_tree, hf_ldp_tlv_fec_vc_vcid,tvb, offset, 4, FALSE);
722                             proto_item_append_text (ti," VCID: %u",tvb_get_ntohl(tvb,offset));
723
724                           } else {
725                             proto_tree_add_text(val_tree,tvb,offset +4, 8 +vc_len, "VC FEC size format error");
726                             return;
727                           }
728                           rem -= 4;
729                           vc_len -= 4;
730                           offset += 4;
731
732                           while ( (vc_len > 1) && (rem > 1) ) { /* enough to include id and length */
733                             intparam_len = tvb_get_guint8(tvb, offset+1);
734                             ti = proto_tree_add_text(fec_tree, tvb, offset, intparam_len, "Interface Paramameter");
735                             vcintparam_tree = proto_item_add_subtree(ti, ett_ldp_fec_vc_interfaceparam);
736                             if(vcintparam_tree == NULL) return;
737                             proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_id,tvb,offset,1,FALSE);
738                             proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_length,tvb, offset+1, 1, FALSE);
739                             if ( (vc_len -intparam_len) <0 && (rem -intparam_len) <0 ) { /* error condition */
740                               proto_tree_add_text(vcintparam_tree, tvb, offset +2, MIN(vc_len,rem), "malformed data");
741                               return;
742                             }
743                             switch (tvb_get_guint8(tvb, offset)) {
744                             case FEC_VC_INTERFACEPARAM_MTU:
745                               proto_item_append_text(ti,": MTU %u", tvb_get_ntohs(tvb,offset+2));
746                               proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_mtu,tvb, offset+2, 2, FALSE);
747                               break;
748                             case FEC_VC_INTERFACEPARAM_MAXCATMCELLS:
749                               proto_item_append_text(ti,": Max ATM Concat Cells %u", tvb_get_ntohs(tvb,offset+2));
750                               proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_maxcatmcells,tvb, offset+2, 2, FALSE);
751                               break;
752                             case FEC_VC_INTERFACEPARAM_DESCRIPTION:
753                               proto_item_append_text(ti,": Description");
754                               proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_desc,tvb, offset+2, (intparam_len -2), FALSE);
755                               break;
756                             case FEC_VC_INTERFACEPARAM_CEMBYTES:
757                               proto_item_append_text(ti,": CEM Payload Bytes %u", tvb_get_ntohs(tvb,offset+2));
758                               proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_cembytes,tvb, offset+2, 2, FALSE);
759                               break;
760                             case FEC_VC_INTERFACEPARAM_VPNID:
761                               /* draft-lasserre-tls-mpls-00.txt */
762                               proto_item_append_text(ti,": VPN Id");
763                               proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_vpnid_oui, tvb, offset+2, 3, FALSE);
764                               proto_tree_add_item(vcintparam_tree,hf_ldp_tlv_fec_vc_intparam_vpnid_index, tvb, offset+5, 4, FALSE);
765                               break;
766                             case FEC_VC_INTERFACEPARAM_CEMOPTIONS:
767                                 /* draft-malis-sonet-ces-mpls CEM options still undefined */
768                             default: /* unknown */
769                               proto_item_append_text(ti," unknown");
770                               proto_tree_add_text(vcintparam_tree,tvb, offset+2, (intparam_len -2), "Unknown data");
771
772                               return;
773                             }
774                             rem -= intparam_len;
775                             vc_len -= intparam_len;
776                             offset += intparam_len;
777                           }
778                           break;
779
780                         default:  /* Unknown */
781                         /* XXX - do all FEC's have a length that's a multiple of 4? */
782                         /* Hmmm, don't think so. Will check. RJS. */
783                         /* If we don't know its structure, we have to exit */
784                                 ti = proto_tree_add_text(val_tree, tvb, offset, 4, "FEC Element %u", ix);
785                                 fec_tree = proto_item_add_subtree(ti, ett_ldp_fec);
786                                 if(fec_tree == NULL) return;
787                                 proto_tree_add_text(fec_tree, tvb, offset, rem, "Unknown FEC TLV type");
788                                 return;
789                         }
790                         ix++;
791                 }
792         }
793 }
794
795 /* Dissect Address List TLV */
796
797 static void
798 dissect_tlv_address_list(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
799 {
800         proto_tree *ti = NULL, *val_tree = NULL;
801         guint16 family, ix;
802         guint8  addr_size, *addr;
803         void *str_handler;
804         char *str;
805
806         if (tree) {
807                 if( rem < 2 ) {
808                         proto_tree_add_text(tree, tvb, offset, rem,
809                             "Error processing Address List TLV: length is %d, should be >= 2",
810                             rem);
811                         return;
812                 }
813
814                 family=tvb_get_ntohs(tvb, offset);
815                 proto_tree_add_item(tree, hf_ldp_tlv_addrl_addr_family, tvb,
816                                          offset, 2, FALSE);
817                 switch(family) {
818                         case AFNUM_INET: /*IPv4*/
819                                 addr_size=4;
820                                 str_handler=ip_to_str;
821                                 break;
822                         case AFNUM_INET6: /*IPv6*/
823                                 addr_size=16;
824                                 str_handler=ip6_to_str;
825                                 break;
826                         default:
827                                 proto_tree_add_text(tree, tvb, offset+2, rem-2,
828                                  "Support for Address Family not implemented");
829                                 return;
830                 }
831
832                 offset+=2; rem-=2;
833                 ti=proto_tree_add_text(tree, tvb, offset, rem, "Addresses");
834                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
835
836                 if(val_tree == NULL) return;
837                 if( (addr=g_malloc(addr_size)) == NULL ){
838                         /*big big trouble*/
839                         fprintf(stderr, "packet-ldp: dissect_tlv_address_list() malloc failed\n");
840                         return;
841                 }
842
843                 for(ix=1; rem >= addr_size; ix++, offset += addr_size,
844                                                          rem -= addr_size) {
845                         if( (tvb_memcpy(tvb, addr, offset, addr_size))
846                                                          == NULL)
847                                 break;
848
849                         str = (* (char* (*)(guint8 *))str_handler)(addr);
850                         proto_tree_add_string_format(val_tree,
851                             hf_ldp_tlv_addrl_addr, tvb, offset, addr_size, str,
852                             "Address %u: %s", ix, str);
853                 }
854                 if(rem)
855                         proto_tree_add_text(val_tree, tvb, offset, rem,
856                             "Error processing TLV: Extra data at end of address list");
857                 g_free(addr);
858         }
859 }
860
861 /* Dissect Path Vector TLV */
862
863 static void
864 dissect_tlv_path_vector(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
865 {
866         proto_tree *ti = NULL, *val_tree = NULL;
867         guint8  ix;
868         guint32 addr;
869
870         if (tree) {
871                 ti=proto_tree_add_text(tree, tvb, offset, rem, "LSR IDs");
872                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
873
874                 if(val_tree == NULL) return;
875
876                 for(ix=1; rem >= 4; ix++, offset += 4, rem -= 4) {
877                         tvb_memcpy(tvb, (guint8 *)&addr, offset, 4);
878                         proto_tree_add_ipv4_format(val_tree,
879                             hf_ldp_tlv_pv_lsrid, tvb, offset, 4,
880                             addr, "LSR Id %u: %s", ix,
881                             ip_to_str((guint8 *)&addr));
882                 }
883                 if(rem)
884                         proto_tree_add_text(val_tree, tvb, offset, rem,
885                             "Error processing TLV: Extra data at end of path vector");
886         }
887 }
888
889 /* Dissect ATM Label TLV */
890
891 static void
892 dissect_tlv_atm_label(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
893 {
894         proto_tree *ti = NULL, *val_tree = NULL;
895         guint16 id;
896
897         if(tree) {
898                 if(rem != 4){
899                         proto_tree_add_text(tree, tvb, offset, rem,
900                             "Error processing ATM Label TLV: length is %d, should be 4",
901                             rem);
902                         return;
903                 }
904                 ti=proto_tree_add_text(tree, tvb, offset, rem, "ATM Label");
905                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
906                 if(val_tree == NULL) return;
907
908                 proto_tree_add_item(val_tree, hf_ldp_tlv_atm_label_vbits, tvb, offset, 1, FALSE);
909
910                 id=tvb_get_ntohs(tvb, offset)&0x0FFF;
911                 proto_tree_add_uint_format(val_tree, hf_ldp_tlv_atm_label_vpi, tvb, offset, 2, id, "VPI: %u", id);
912
913                 id=tvb_get_ntohs(tvb, offset+2);
914                 proto_tree_add_uint_format(val_tree, hf_ldp_tlv_atm_label_vci, tvb, offset+2, 2, id, "VCI: %u", id);
915         }
916 }
917
918 /* Dissect FRAME RELAY Label TLV */
919
920 static void
921 dissect_tlv_frame_label(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
922 {
923         proto_tree *ti = NULL, *val_tree = NULL;
924         guint8  len;
925         guint32 id;
926
927         if(tree) {
928                 if(rem != 4){
929                         proto_tree_add_text(tree, tvb, offset, rem,
930                             "Error processing Frame Relay Label TLV: length is %d, should be 4",
931                             rem);
932                         return;
933                 }
934                 ti=proto_tree_add_text(tree, tvb, offset, rem, "Frame Relay Label");
935                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
936                 if(val_tree == NULL) return;
937
938                 len=(guint8)(tvb_get_ntohs(tvb, offset)>>7) & 0x03;
939                 proto_tree_add_uint_format(val_tree, hf_ldp_tlv_fr_label_len, tvb, offset, 2, len, "Number of DLCI bits: %s (%u)", val_to_str(len, tlv_fr_len_vals, "Unknown Length"), len);
940
941                 id=tvb_get_ntoh24(tvb, offset+1)&0x7FFFFF;
942                 proto_tree_add_uint_format(val_tree,
943                 hf_ldp_tlv_fr_label_dlci, tvb, offset+1, 3, id, "DLCI: %u", id);
944         }
945 }
946
947 /* Dissect STATUS TLV */
948
949 static void
950 dissect_tlv_status(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
951 {
952         proto_tree *ti = NULL, *val_tree = NULL;
953         guint32 data;
954
955         if(tree) {
956                 if(rem != 10){
957                         proto_tree_add_text(tree, tvb, offset, rem,
958                             "Error processing Status TLV: length is %d, should be 10",
959                             rem);
960                         return;
961                 }
962
963                 ti=proto_tree_add_text(tree, tvb, offset, rem, "Status");
964                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
965                 if(val_tree == NULL) return;
966
967                 proto_tree_add_item(val_tree, hf_ldp_tlv_status_ebit, tvb, offset, 1, FALSE);
968                 proto_tree_add_item(val_tree, hf_ldp_tlv_status_fbit, tvb, offset, 1, FALSE);
969
970                 data=tvb_get_ntohl(tvb, offset)&0x3FFFFFFF;
971                 proto_tree_add_uint_format(val_tree, hf_ldp_tlv_status_data, tvb, offset, 4, data, "Status Data: %s (0x%X)", val_to_str(data, tlv_status_data, "Unknown Status Data"), data);
972
973                 proto_tree_add_item(val_tree, hf_ldp_tlv_status_msg_id, tvb, offset+4, 4, FALSE);
974                 proto_tree_add_item(val_tree, hf_ldp_tlv_status_msg_type, tvb, offset+8, 2, FALSE);
975         }
976 }
977
978 /* Dissect Returned PDU TLV */
979
980 static void
981 dissect_tlv_returned_pdu(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
982 {
983         proto_tree *ti = NULL, *val_tree = NULL;
984
985         if(tree) {
986                 if(rem < 10){
987                         proto_tree_add_text(tree, tvb, offset, rem,
988                             "Error processing Returned PDU TLV: length is %d, should be >= 10",
989                             rem);
990                         return;
991                 }
992                 ti=proto_tree_add_text(tree, tvb, offset, rem, "Returned PDU");
993                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
994                 if(val_tree == NULL) return;
995
996                 proto_tree_add_item(val_tree, hf_ldp_tlv_returned_version, tvb, offset, 2, FALSE);
997                 proto_tree_add_item(val_tree, hf_ldp_tlv_returned_pdu_len, tvb, offset+2, 2, FALSE);
998                 proto_tree_add_item(val_tree, hf_ldp_tlv_returned_lsr, tvb, offset+4, 4, FALSE);
999                 proto_tree_add_item(val_tree, hf_ldp_tlv_returned_ls_id, tvb, offset+8, 2, FALSE);
1000                 offset += 10;
1001                 rem -= 10;
1002
1003                 if( rem > 0 ) {
1004                 /*XXX - dissect returned pdu data*/
1005                         proto_tree_add_text(val_tree, tvb, offset, rem, "Returned PDU Data");
1006                 }
1007         }
1008 }
1009
1010 /* Dissect Returned MESSAGE TLV */
1011
1012 static void
1013 dissect_tlv_returned_message(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1014 {
1015         proto_tree *ti = NULL, *val_tree = NULL;
1016         guint16 type;
1017
1018         if(tree) {
1019                 if(rem < 4){
1020                         proto_tree_add_text(tree, tvb, offset, rem,
1021                             "Error processing Returned Message TLV: length is %d, should be >= 4",
1022                             rem);
1023                         return;
1024                 }
1025                 ti=proto_tree_add_text(tree, tvb, offset, rem, "Returned Message");
1026                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
1027                 if(val_tree == NULL) return;
1028
1029                 proto_tree_add_item(val_tree, hf_ldp_tlv_returned_msg_ubit, tvb, offset, 1, FALSE);
1030
1031                 type=tvb_get_ntohs(tvb, offset)&0x7FFF;
1032                 proto_tree_add_uint_format(val_tree, hf_ldp_tlv_returned_msg_type, tvb, offset, 2, type, "Message Type: %s (0x%X)", val_to_str(type, ldp_message_types,"Unknown Message Type"), type);
1033
1034                 proto_tree_add_item(val_tree, hf_ldp_tlv_returned_msg_len, tvb, offset+2, 2, FALSE);
1035                 offset += 4;
1036                 rem -= 4;
1037
1038                 if( rem >= 4  ) { /*have msg_id*/
1039                         proto_tree_add_item(val_tree, hf_ldp_tlv_returned_msg_id, tvb, offset, 4, FALSE);
1040                         offset += 4;
1041                         rem -= 4;
1042                 }
1043
1044                 if( rem > 0 ) {
1045                 /*XXX - dissect returned msg parameters*/
1046                         proto_tree_add_text(val_tree, tvb, offset, rem, "Returned Message Parameters");
1047                 }
1048         }
1049 }
1050
1051 /* Dissect the common hello params */
1052
1053 static void
1054 #if 0
1055 dissect_tlv_common_hello_parms(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1056 #else
1057 dissect_tlv_common_hello_parms(tvbuff_t *tvb, guint offset, proto_tree *tree)
1058 #endif
1059 {
1060 #if 0
1061         proto_tree *ti = NULL;
1062 #endif
1063         proto_tree *val_tree = NULL;
1064
1065         if (tree) {
1066 #if 0
1067                 ti = proto_tree_add_item(tree, hf_ldp_tlv_value, tvb, offset, rem, FALSE);
1068                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1069                 if(val_tree == NULL) return;
1070 #else
1071                 val_tree=tree;
1072 #endif
1073                 proto_tree_add_item(val_tree, hf_ldp_tlv_val_hold, tvb, offset, 2, FALSE);
1074                 proto_tree_add_item(val_tree, hf_ldp_tlv_val_target, tvb, offset + 2, 2, FALSE);
1075                 proto_tree_add_item(val_tree, hf_ldp_tlv_val_request, tvb, offset + 2, 2, FALSE);
1076                 proto_tree_add_item(val_tree, hf_ldp_tlv_val_res, tvb, offset + 2, 2, FALSE);
1077         }
1078 }
1079
1080 /* Dissect MAC TLV */
1081
1082 static void
1083 dissect_tlv_mac(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1084 {
1085         proto_tree *ti = NULL, *val_tree = NULL;
1086         guint8  ix;
1087         const guint8 *mac;
1088
1089         if (tree) {
1090                 ti=proto_tree_add_text(tree, tvb, offset, rem, "MAC addresses");
1091                 val_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
1092
1093                 if(val_tree == NULL) return;
1094
1095                 for(ix=1; rem >= 6; ix++, offset += 6, rem -= 6) {
1096                         mac = tvb_get_ptr(tvb, offset, 6);
1097                         proto_tree_add_ether(val_tree,
1098                              hf_ldp_tlv_mac, tvb, offset, 6, mac);
1099                 }
1100                 if(rem)
1101                         proto_tree_add_text(val_tree, tvb, offset, rem,
1102                             "Error processing TLV: Extra data at end of path vector");
1103         }
1104 }
1105
1106
1107
1108 /* Dissect the common session params */
1109
1110 static void
1111 dissect_tlv_common_session_parms(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1112 {
1113         proto_tree *ti = NULL, *val_tree = NULL;
1114
1115         if (tree != NULL) {
1116                 if( rem != 14) { /*length of Comm Sess Parms tlv*/
1117                         proto_tree_add_text(tree, tvb, offset, rem,
1118                             "Error processing Common Session Parameters TLV: length is %d, should be 14",
1119                             rem);
1120                         return;
1121                 }
1122                 ti = proto_tree_add_text(tree, tvb, offset, rem, "Parameters");
1123                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1124
1125                 if(val_tree != NULL) {
1126                         /*Protocol Version*/
1127                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_ver, tvb,offset, 2, FALSE);
1128
1129                         /*KeepAlive Time*/
1130                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_ka, tvb,offset + 2, 2, FALSE);
1131
1132                         /*A bit*/
1133                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_advbit,tvb, offset + 4, 1, FALSE);
1134
1135                         /*D bit*/
1136                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_ldetbit,tvb, offset + 4, 1, FALSE);
1137
1138                         /*Path Vector Limit*/
1139                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_pvlim,tvb, offset + 5, 1, FALSE);
1140
1141                         /*Max PDU Length*/
1142                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_mxpdu,tvb, offset + 6, 2, FALSE);
1143
1144                         /*Rx LSR*/
1145                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_rxlsr,tvb, offset + 8, 4, FALSE);
1146
1147                         /*Rx LS*/
1148                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_rxls,tvb, offset + 12, 2, FALSE);
1149                 }
1150         }
1151 }
1152
1153 /* Dissect the atm session params */
1154
1155 static void
1156 dissect_tlv_atm_session_parms(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1157 {
1158         proto_tree *ti = NULL, *val_tree = NULL, *lbl_tree = NULL;
1159         guint8 numlr, ix;
1160         guint16 id;
1161
1162         if (tree != NULL) {
1163                 if(rem < 4) {
1164                         proto_tree_add_text(tree, tvb, offset, rem,
1165                             "Error processing ATM Parameters TLV: length is %d, should be >= 4",
1166                             rem);
1167                         return;
1168                 }
1169
1170                 ti = proto_tree_add_text(tree, tvb, offset, rem,"ATM Parameters");
1171                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1172
1173                 if(val_tree != NULL) {
1174                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_atm_merge,tvb, offset, 1, FALSE);
1175
1176                         /*get the number of label ranges*/
1177                         numlr=(tvb_get_guint8(tvb, offset)>>2) & 0x0F;
1178                         proto_tree_add_uint_format(val_tree, hf_ldp_tlv_sess_atm_lr,
1179                         tvb, offset, 1, numlr, "Number of Label Range components: %u",
1180                         numlr);
1181
1182                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_atm_dir,tvb, offset, 1, FALSE);
1183
1184                         /*move into range components*/
1185                         offset += 4;
1186                         rem -= 4;
1187                         ti = proto_tree_add_text(val_tree, tvb, offset, rem,"ATM Label Range Components");
1188
1189                         if(numlr) {
1190                                 val_tree=proto_item_add_subtree(ti,ett_ldp_tlv_val);
1191                                 if( ! val_tree ) return;
1192                         }
1193                         /*now dissect ranges*/
1194                         for(ix=1; numlr > 0 && rem >= 8; ix++, rem-=8, numlr--) {
1195                                 ti=proto_tree_add_text(val_tree, tvb, offset, 8,
1196                                  "ATM Label Range Component %u", ix);
1197                                 lbl_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
1198
1199                                 if( lbl_tree == NULL ) break;
1200
1201                                 id=tvb_get_ntohs(tvb, offset)&0x0FFF;
1202                                 proto_tree_add_uint_format(lbl_tree,
1203                                     hf_ldp_tlv_sess_atm_minvpi,
1204                                     tvb, offset, 2,
1205                                     id, "Minimum VPI: %u", id);
1206                                 id=tvb_get_ntohs(tvb, offset+4)&0x0FFF;
1207                                 proto_tree_add_uint_format(lbl_tree,
1208                                     hf_ldp_tlv_sess_atm_maxvpi,
1209                                     tvb, (offset+4), 2, id,
1210                                     "Maximum VPI: %u", id);
1211
1212                                 id=tvb_get_ntohs(tvb, offset+2);
1213                                 proto_tree_add_uint_format(lbl_tree,
1214                                     hf_ldp_tlv_sess_atm_minvci,
1215                                     tvb, offset+2, 2,
1216                                     id, "Minimum VCI: %u", id);
1217                                 id=tvb_get_ntohs(tvb, offset+6);
1218                                 proto_tree_add_uint_format(lbl_tree,
1219                                     hf_ldp_tlv_sess_atm_maxvci,
1220                                     tvb, offset+6, 2,
1221                                     id, "Maximum VCI: %u", id);
1222
1223                                 offset += 8;
1224                         }
1225                         if( rem || numlr)
1226                                 proto_tree_add_text(val_tree, tvb, offset, rem,
1227                                     "Error processing TLV: Extra data at end of TLV");
1228                 }
1229         }
1230 }
1231
1232 /* Dissect the frame relay session params */
1233
1234 static void
1235 dissect_tlv_frame_relay_session_parms(tvbuff_t *tvb, guint offset,proto_tree *tree, int rem)
1236 {
1237         proto_tree *ti = NULL, *val_tree = NULL, *lbl_tree = NULL;
1238         guint8 numlr, ix, len;
1239         guint32 id;
1240
1241         if (tree != NULL) {
1242                 if(rem < 4) {
1243                         proto_tree_add_text(tree, tvb, offset, rem,
1244                             "Error processing Frame Relay Parameters TLV: length is %d, should be >= 4",
1245                             rem);
1246                         return;
1247                 }
1248
1249                 ti = proto_tree_add_text(tree, tvb, offset, rem,
1250                                                  "Frame Relay Parameters");
1251                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1252
1253                 if(val_tree != NULL) {
1254                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_fr_merge,
1255                                 tvb, offset, 1, FALSE);
1256
1257                         /*get the number of label ranges*/
1258                         numlr=(tvb_get_guint8(tvb, offset)>>2) & 0x0F;
1259                         proto_tree_add_uint_format(val_tree, hf_ldp_tlv_sess_fr_lr,
1260                         tvb, offset, 1, numlr, "Number of Label Range components: %u",
1261                         numlr);
1262
1263                         proto_tree_add_item(val_tree, hf_ldp_tlv_sess_fr_dir,
1264                                  tvb, offset, 1, FALSE);
1265
1266                         /*move into range components*/
1267                         offset += 4;
1268                         rem -= 4;
1269                         ti = proto_tree_add_text(val_tree, tvb, offset, rem,
1270                                  "Frame Relay Label Range Components");
1271
1272                         if(numlr) {
1273                                 val_tree=proto_item_add_subtree(ti,
1274                                                          ett_ldp_tlv_val);
1275                                 if( ! val_tree ) return;
1276                         }
1277
1278                         /*now dissect ranges*/
1279                         for(ix=1; numlr > 0 && rem >= 8; ix++, rem-=8, numlr--) {
1280                                 ti=proto_tree_add_text(val_tree, tvb, offset, 8,
1281                                 "Frame Relay Label Range Component %u", ix);
1282                                 lbl_tree=proto_item_add_subtree(ti, ett_ldp_tlv_val);
1283
1284                                 if( lbl_tree == NULL ) break;
1285
1286                                 len=(guint8)(tvb_get_ntohs(tvb, offset)>>7) & 0x03;
1287                                 proto_tree_add_uint_format(lbl_tree, hf_ldp_tlv_sess_fr_len, tvb, offset, 2, len, "Number of DLCI bits: %s (%u)", val_to_str(len, tlv_fr_len_vals, "Unknown Length"), len);
1288
1289                                 id=tvb_get_ntoh24(tvb, offset+1)&0x7FFFFF;
1290                                 proto_tree_add_uint_format(lbl_tree,
1291                         hf_ldp_tlv_sess_fr_mindlci, tvb, offset+1, 3, id, "Minimum DLCI %u", id);
1292                                 id=tvb_get_ntoh24(tvb, offset+5)&0x7FFFFF;
1293                                 proto_tree_add_uint_format(lbl_tree,
1294                         hf_ldp_tlv_sess_fr_maxdlci, tvb, offset+5, 3, id, "Maximum DLCI %u", id);
1295
1296                                 offset += 8;
1297                         }
1298
1299                         if( rem || numlr)
1300                                 proto_tree_add_text(val_tree, tvb, offset, rem,
1301                                  "Error processing TLV: Extra data at end of TLV");
1302                 }
1303         }
1304 }
1305
1306
1307 static void
1308 dissect_tlv_lspid(tvbuff_t *tvb, guint offset,proto_tree *tree, int rem)
1309 {
1310         proto_tree *ti = NULL, *val_tree = NULL;
1311
1312         if (tree != NULL) {
1313                 if(rem != 8) {
1314                         proto_tree_add_text(tree, tvb, offset, rem,
1315                             "Error processing LSP ID TLV: length is %d, should be 8",
1316                             rem);
1317                         return;
1318                 }
1319
1320                 ti = proto_tree_add_text(tree, tvb, offset, rem,
1321                                                 "LSP ID");
1322                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1323
1324                 if(val_tree != NULL) {
1325                         proto_tree_add_item(val_tree, hf_ldp_tlv_lspid_act_flg,
1326                                            tvb, offset, 2, FALSE);
1327                         offset += 2;
1328                         proto_tree_add_item(val_tree, hf_ldp_tlv_lspid_cr_lsp,
1329                                            tvb, offset, 2, FALSE);
1330                         offset += 2;
1331                         proto_tree_add_item(val_tree, hf_ldp_tlv_lspid_ldpid,
1332                                            tvb, offset, 4, FALSE);
1333                 }
1334         }
1335 }
1336
1337 static void
1338 dissect_tlv_er_hop_ipv4(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1339 {
1340         proto_tree *ti = NULL, *val_tree = NULL;
1341
1342
1343         if (tree != NULL) {
1344                 if(rem != 8) {
1345                         proto_tree_add_text(tree, tvb, offset, rem,
1346                             "Error processing ER HOP IPv4 TLV: length is %d, should be 8",
1347                             rem);
1348                         return;
1349                 }
1350                 ti = proto_tree_add_text(tree, tvb, offset, rem, "ER HOP IPv4");
1351                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1352
1353                 if(val_tree != NULL) {
1354                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_loose,
1355                                            tvb, offset, 3, FALSE);
1356                         offset += 3;
1357                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_prelen,
1358                                            tvb, offset, 1, FALSE);
1359                         offset ++;
1360                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_prefix4,
1361                                            tvb, offset, 4, FALSE);
1362                 }
1363         }
1364 }
1365
1366 static void
1367 dissect_tlv_er_hop_ipv6(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1368 {
1369         proto_tree *ti = NULL, *val_tree = NULL;
1370
1371         if (tree != NULL) {
1372                 if(rem != 20) {
1373                         proto_tree_add_text(tree, tvb, offset, rem,
1374                             "Error processing ER HOP IPv6 TLV: length is %d, should be 20",
1375                             rem);
1376                         return;
1377                 }
1378                 ti = proto_tree_add_text(tree, tvb, offset, rem, "ER HOP IPv6");
1379                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1380
1381                 if(val_tree != NULL) {
1382                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_loose,
1383                                            tvb, offset, 3, FALSE);
1384                         offset += 3;
1385                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_prelen,
1386                                           tvb, offset, 1, FALSE);
1387                         offset ++;
1388                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_prefix6,
1389                                            tvb, offset, 16, FALSE);
1390                 }
1391         }
1392 }
1393
1394 static void
1395 dissect_tlv_er_hop_as(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1396 {
1397         proto_tree *ti = NULL, *val_tree = NULL;
1398
1399         if (tree != NULL) {
1400                 if(rem != 4) {
1401                         proto_tree_add_text(tree, tvb, offset, rem,
1402                             "Error processing ER HOP AS TLV: length is %d, should be 4",
1403                             rem);
1404                         return;
1405                 }
1406                 ti = proto_tree_add_text(tree, tvb, offset, rem, "ER HOP AS");
1407                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1408
1409                 if(val_tree != NULL) {
1410                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_loose,
1411                                            tvb, offset, 2, FALSE);
1412                         offset += 2;
1413                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_as,
1414                                            tvb, offset, 2, FALSE);
1415                 }
1416         }
1417 }
1418
1419 static void
1420 dissect_tlv_er_hop_lspid(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1421 {
1422         proto_tree *ti = NULL, *val_tree = NULL;
1423
1424         if (tree != NULL) {
1425                 if(rem != 8) {
1426                         proto_tree_add_text(tree, tvb, offset, rem,
1427                             "Error processing ER HOP LSPID TLV: length is %d, should be 8",
1428                             rem);
1429                         return;
1430                 }
1431                 ti = proto_tree_add_text(tree, tvb, offset, rem, "ER HOP LSPID");
1432                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1433
1434                 if(val_tree != NULL) {
1435                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_loose,
1436                                            tvb, offset, 2, FALSE);
1437                         offset += 2;
1438                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_cr_lsp,
1439                                            tvb, offset, 2, FALSE);
1440                         offset += 2;
1441                         proto_tree_add_item(val_tree, hf_ldp_tlv_er_hop_ldpid,
1442                                            tvb, offset, 4, FALSE);
1443                 }
1444         }
1445 }
1446
1447 static void
1448 dissect_tlv_traffic(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1449 {
1450         proto_tree *ti = NULL, *val_tree = NULL;
1451         guint8  val_8;
1452         float   val_f;
1453         proto_item *pi;
1454
1455         if (tree != NULL) {
1456                 if(rem != 24) {
1457                         proto_tree_add_text(tree, tvb, offset, rem,
1458                             "Error processing Traffic Parameters TLV: length is %d, should be 24",
1459                             rem);
1460                         return;
1461                 }
1462                 ti = proto_tree_add_text(tree, tvb, offset, rem, "Traffic parameters");
1463                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1464
1465                 if(val_tree != NULL) {
1466                         /* flags */
1467                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_reserv, tvb, offset, 1, FALSE);
1468                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_weight, tvb, offset, 1, FALSE);
1469                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_ebs, tvb, offset, 1, FALSE);
1470                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_cbs, tvb, offset, 1, FALSE);
1471                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_cdr, tvb, offset, 1, FALSE);
1472                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_pbs, tvb, offset, 1, FALSE);
1473                         proto_tree_add_item(val_tree, hf_ldp_tlv_flags_pdr, tvb, offset, 1, FALSE);
1474
1475                         offset ++;
1476                         /* frequency */
1477                         proto_tree_add_item(val_tree, hf_ldp_tlv_frequency, tvb, offset, 1, FALSE);
1478                         offset ++;
1479
1480                         /* reserver byte */
1481                         offset ++;
1482
1483                         /* weight */
1484                         pi = proto_tree_add_item(val_tree, hf_ldp_tlv_weight, tvb, offset, 1, FALSE);
1485                         val_8 = tvb_get_guint8(tvb, offset);
1486                         if (val_8 == 0)
1487                                 proto_item_set_text(pi, "Weight: Not applicable");
1488                         offset ++;
1489
1490                         /* PDR */
1491                         val_f = tvb_get_ntohieee_float (tvb, offset);
1492                         proto_tree_add_double_format(val_tree, hf_ldp_tlv_pdr, tvb, offset,
1493                                                     4, val_f, "PDR: %.10g Bps", val_f);
1494                         offset += 4;
1495                         /* PBS */
1496                         val_f = tvb_get_ntohieee_float (tvb, offset);
1497                         proto_tree_add_double_format(val_tree, hf_ldp_tlv_pbs, tvb, offset,
1498                                                     4, val_f, "PBS: %.10g Bytes", val_f);
1499                         offset += 4;
1500
1501                         /* CDR */
1502                         val_f = tvb_get_ntohieee_float (tvb, offset);
1503                         proto_tree_add_double_format(val_tree, hf_ldp_tlv_cdr, tvb, offset,
1504                                                     4, val_f, "CDR: %.10g Bps", val_f);
1505                         offset += 4;
1506
1507                         /* CBS */
1508                         val_f = tvb_get_ntohieee_float (tvb, offset);
1509                         proto_tree_add_double_format(val_tree, hf_ldp_tlv_cbs, tvb, offset,
1510                                                     4, val_f, "CBS: %.10g Bytes", val_f);
1511                         offset += 4;
1512
1513                         /* EBS */
1514                         val_f = tvb_get_ntohieee_float (tvb, offset);
1515                         proto_tree_add_double_format(val_tree, hf_ldp_tlv_ebs, tvb, offset,
1516                                                     4, val_f, "EBS: %.10g Bytes", val_f);
1517
1518                 }
1519         }
1520 }
1521
1522 static void
1523 dissect_tlv_route_pinning(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1524 {
1525         proto_tree *ti = NULL, *val_tree = NULL;
1526
1527         if (tree != NULL) {
1528                 if(rem != 4) {
1529                         proto_tree_add_text(tree, tvb, offset, rem,
1530                             "Error processing Route Pinning TLV: length is %d, should be 4",
1531                             rem);
1532                         return;
1533                 }
1534                 ti = proto_tree_add_text(tree, tvb, offset, rem, "Route Pinning");
1535                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1536
1537                 if(val_tree != NULL) {
1538                         proto_tree_add_item(val_tree, hf_ldp_tlv_route_pinning,
1539                                            tvb, offset, 4, FALSE);
1540                 }
1541         }
1542 }
1543
1544
1545 static void
1546 dissect_tlv_resource_class(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1547 {
1548         proto_tree *ti = NULL, *val_tree = NULL;
1549
1550         if (tree != NULL) {
1551                 if(rem != 4) {
1552                         proto_tree_add_text(tree, tvb, offset, rem,
1553                             "Error processing Resource Class TLV: length is %d, should be 4",
1554                             rem);
1555                         return;
1556                 }
1557                 ti = proto_tree_add_text(tree, tvb, offset, rem, "Resource Class");
1558                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1559
1560                 if(val_tree != NULL) {
1561                         proto_tree_add_item(val_tree, hf_ldp_tlv_resource_class,
1562                                            tvb, offset, 4, FALSE);
1563                 }
1564         }
1565 }
1566
1567
1568 static void
1569 dissect_tlv_preemption(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1570 {
1571         proto_tree *ti = NULL, *val_tree = NULL;
1572
1573         if (tree != NULL) {
1574                 if(rem != 4) {
1575                         proto_tree_add_text(tree, tvb, offset, rem,
1576                             "Error processing Preemption TLV: length is %d, should be 4",
1577                             rem);
1578                         return;
1579                 }
1580                 ti = proto_tree_add_text(tree, tvb, offset, rem, "Preemption");
1581                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1582
1583                 if(val_tree != NULL) {
1584                         proto_tree_add_item(val_tree, hf_ldp_tlv_set_prio,
1585                                            tvb, offset, 1, FALSE);
1586                         offset += 1;
1587                         proto_tree_add_item(val_tree, hf_ldp_tlv_hold_prio,
1588                                            tvb, offset, 1, FALSE);
1589                 }
1590         }
1591 }
1592
1593 static int
1594 dissect_tlv(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem);
1595
1596 static void
1597 dissect_tlv_er(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1598 {
1599         proto_tree *ti = NULL, *val_tree = NULL;
1600         int len;
1601
1602         if (tree != NULL) {
1603                 ti = proto_tree_add_text(tree, tvb, offset, rem, "Explicit route");
1604                 val_tree = proto_item_add_subtree(ti, ett_ldp_tlv_val);
1605
1606                 if(val_tree != NULL) {
1607                         len = 0;
1608                         while (rem > 0) {
1609                                 len = dissect_tlv (tvb, offset, val_tree, rem);
1610                                 offset += len;
1611                                 rem -= len;
1612                         }
1613                 }
1614         }
1615 }
1616
1617
1618 /* Dissect a TLV and return the number of bytes consumed ... */
1619
1620 static int
1621 dissect_tlv(tvbuff_t *tvb, guint offset, proto_tree *tree, int rem)
1622 {
1623         guint16 type, typebak;
1624         int length;
1625         proto_tree *ti = NULL, *tlv_tree = NULL;
1626
1627         length=tvb_reported_length_remaining(tvb, offset);
1628         rem=MIN(rem, length);
1629
1630         if( rem < 4 ) {/*chk for minimum header*/
1631                 if(tree)
1632                         proto_tree_add_text(tree, tvb, offset, rem,
1633                             "Error processing TLV: length is %d, should be >= 4",
1634                             rem);
1635                 return rem;
1636         }
1637         type = tvb_get_ntohs(tvb, offset) & 0x3FFF;
1638
1639         length = tvb_get_ntohs(tvb, offset + 2),
1640         rem -= 4; /*do not count header*/
1641         length = MIN(length, rem);  /* Don't go haywire if a problem ... */
1642
1643         if (tree != NULL) {
1644                 /*chk for vendor-private*/
1645                 if(type>=TLV_VENDOR_PRIVATE_START && type<=TLV_VENDOR_PRIVATE_END){
1646                         typebak=type;           /*keep type*/
1647                         type=TLV_VENDOR_PRIVATE_START;
1648
1649                 /*chk for experimental*/
1650                 } else if(type>=TLV_EXPERIMENTAL_START && type<=TLV_EXPERIMENTAL_END){
1651                         typebak=type;           /*keep type*/
1652                         type=TLV_EXPERIMENTAL_START;
1653                 }
1654
1655                 ti = proto_tree_add_text(tree, tvb, offset, length + 4, "%s",
1656                         val_to_str(type, tlv_type_names, "Unknown TLV type (0x%04X)"));
1657                 tlv_tree = proto_item_add_subtree(ti, ett_ldp_tlv);
1658                 if(tlv_tree == NULL) return length+4;
1659
1660                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_unknown, tvb, offset, 1, FALSE);
1661
1662                 proto_tree_add_uint_format(tlv_tree, hf_ldp_tlv_type, tvb, offset, 2, type, "TLV Type: %s (0x%X)", val_to_str(type, tlv_type_names, "Unknown TLV type"), type );
1663
1664                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_len, tvb, offset + 2, 2, FALSE);
1665
1666                 switch (type) {
1667
1668                 case TLV_FEC:
1669                         dissect_tlv_fec(tvb, offset + 4, tlv_tree, length);
1670                         break;
1671
1672                 case TLV_ADDRESS_LIST:
1673                         dissect_tlv_address_list(tvb, offset + 4, tlv_tree, length);
1674                         break;
1675
1676                 case TLV_HOP_COUNT:
1677                         if( length != 1 ) /*error, only one byte*/
1678                                 proto_tree_add_text(tlv_tree, tvb, offset + 4,length,
1679                                     "Error processing Hop Count TLV: length is %d, should be 1",
1680                                     length);
1681                         else
1682                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_hc_value, tvb,offset + 4, length, FALSE);
1683                         break;
1684
1685                 case TLV_PATH_VECTOR:
1686                         dissect_tlv_path_vector(tvb, offset + 4, tlv_tree, length);
1687                         break;
1688
1689                 case TLV_GENERIC_LABEL:
1690                         if( length != 4 ) /*error, need only label*/
1691                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1692                                     "Error processing Generic Label TLV: length is %d, should be 4",
1693                                     length);
1694                         else {
1695                                 guint32 label=tvb_get_ntohl(tvb, offset+4) & 0x000FFFFF;
1696
1697                                 proto_tree_add_uint_format(tlv_tree, hf_ldp_tlv_generic_label,
1698                                         tvb, offset+4, length, label, "Generic Label: %u", label);
1699                         }
1700                         break;
1701
1702                 case TLV_ATM_LABEL:
1703                         dissect_tlv_atm_label(tvb, offset + 4, tlv_tree, length);
1704                         break;
1705
1706                 case TLV_FRAME_LABEL:
1707                         dissect_tlv_frame_label(tvb, offset + 4, tlv_tree, length);
1708                         break;
1709
1710                 case TLV_STATUS:
1711                         dissect_tlv_status(tvb, offset + 4, tlv_tree, length);
1712                         break;
1713
1714                 case TLV_EXTENDED_STATUS:
1715                         if( length != 4 ) /*error, need only status_code(guint32)*/
1716                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1717                                     "Error processing Extended Status TLV: length is %d, should be 4",
1718                                     length);
1719                         else {
1720                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_extstatus_data, tvb, offset + 4, length, FALSE);
1721                         }
1722                         break;
1723
1724                 case TLV_RETURNED_PDU:
1725                         dissect_tlv_returned_pdu(tvb, offset + 4, tlv_tree, length);
1726                         break;
1727
1728                 case TLV_RETURNED_MESSAGE:
1729                         dissect_tlv_returned_message(tvb, offset + 4, tlv_tree, length);
1730                         break;
1731
1732                 case TLV_COMMON_HELLO_PARMS:
1733 #if 0
1734                         dissect_tlv_common_hello_parms(tvb, offset + 4, tlv_tree, length);
1735 #else
1736                         dissect_tlv_common_hello_parms(tvb, offset + 4, tlv_tree);
1737 #endif
1738                         break;
1739
1740                 case TLV_IPV4_TRANSPORT_ADDRESS:
1741                         if( length != 4 ) /*error, need only ipv4*/
1742                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1743                                     "Error processing IPv4 Transport Address TLV: length is %d, should be 4",
1744                                     length);
1745                         else {
1746                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_ipv4_taddr, tvb, offset + 4, 4, FALSE);
1747                         }
1748                         break;
1749
1750                 case TLV_CONFIGURATION_SEQNO:
1751                         if( length != 4 ) /*error, need only seq_num(guint32)*/
1752                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1753                                     "Error processing Configuration Sequence Number TLV: length is %d, should be 4",
1754                                     length);
1755                         else {
1756                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_config_seqno, tvb, offset + 4, 4, FALSE);
1757                         }
1758                         break;
1759
1760                 case TLV_IPV6_TRANSPORT_ADDRESS:
1761                         if( length != 16 ) /*error, need only ipv6*/
1762                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1763                                     "Error processing IPv6 Transport Address TLV: length is %d, should be 16",
1764                                     length);
1765                         else {
1766                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_ipv6_taddr, tvb, offset + 4, 16, FALSE);
1767                         }
1768                         break;
1769
1770                 case TLV_MAC: /* draft-lasserre-vkompella-ppvpn-vpls-02.txt */
1771                         dissect_tlv_mac(tvb, offset + 4, tlv_tree, length);
1772                         break;
1773
1774                 case TLV_COMMON_SESSION_PARMS:
1775                         dissect_tlv_common_session_parms(tvb, offset + 4, tlv_tree, length);
1776                         break;
1777
1778                 case TLV_ATM_SESSION_PARMS:
1779                         dissect_tlv_atm_session_parms(tvb, offset + 4, tlv_tree, length);
1780                         break;
1781
1782                 case TLV_FRAME_RELAY_SESSION_PARMS:
1783                         dissect_tlv_frame_relay_session_parms(tvb, offset + 4, tlv_tree, length);
1784                         break;
1785
1786                 case TLV_LABEL_REQUEST_MESSAGE_ID:
1787                         if( length != 4 ) /*error, need only one msgid*/
1788                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1789                                     "Error processing Label Request Message ID TLV: length is %d, should be 4",
1790                                     length);
1791                         else
1792                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_lbl_req_msg_id, tvb,offset + 4,length, FALSE);
1793                         break;
1794
1795                 case TLV_LSPID:
1796                         dissect_tlv_lspid(tvb, offset + 4, tlv_tree, length);
1797                         break;
1798
1799                 case TLV_ER:
1800                         dissect_tlv_er(tvb, offset + 4, tlv_tree, length);
1801                         break;
1802
1803                 case TLV_ER_HOP_IPV4:
1804                         dissect_tlv_er_hop_ipv4(tvb, offset + 4, tlv_tree, length);
1805                         break;
1806
1807                 case TLV_ER_HOP_IPV6:
1808                         dissect_tlv_er_hop_ipv6(tvb, offset +4, tlv_tree, length);
1809                         break;
1810
1811                 case TLV_ER_HOP_AS:
1812                         dissect_tlv_er_hop_as(tvb, offset + 4, tlv_tree, length);
1813                         break;
1814
1815                 case TLV_ER_HOP_LSPID:
1816                         dissect_tlv_er_hop_lspid(tvb, offset +4, tlv_tree, length);
1817                         break;
1818
1819                 case TLV_TRAFFIC_PARAM:
1820                         dissect_tlv_traffic(tvb, offset +4, tlv_tree, length);
1821                         break;
1822
1823                 case TLV_PREEMPTION:
1824                         dissect_tlv_preemption(tvb, offset +4, tlv_tree, length);
1825                         break;
1826
1827                 case TLV_RESOURCE_CLASS:
1828                         dissect_tlv_resource_class(tvb, offset +4, tlv_tree, length);
1829                         break;
1830
1831                 case TLV_ROUTE_PINNING:
1832                         dissect_tlv_route_pinning(tvb, offset +4, tlv_tree, length);
1833                         break;
1834
1835                 case TLV_VENDOR_PRIVATE_START:
1836                         if( length < 4 ) /*error, at least Vendor ID*/
1837                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1838                                     "Error processing Vendor Private Start TLV: length is %d, should be >= 4",
1839                                     length);
1840                         else {
1841                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_vendor_id, tvb,offset + 4, 4, FALSE);
1842                                 if( length > 4 )  /*have data*/
1843                                         proto_tree_add_text(tlv_tree, tvb, offset + 8, length-4,"Data");
1844                         }
1845                         break;
1846
1847                 case TLV_EXPERIMENTAL_START:
1848                         if( length < 4 ) /*error, at least Experiment ID*/
1849                                 proto_tree_add_text(tlv_tree, tvb, offset + 4, length,
1850                                     "Error processing Experimental Start TLV: length is %d, should be >= 4",
1851                                     length);
1852                         else {
1853                                 proto_tree_add_item(tlv_tree, hf_ldp_tlv_experiment_id, tvb,offset + 4, 4, FALSE);
1854                                 if( length > 4 )  /*have data*/
1855                                         proto_tree_add_text(tlv_tree, tvb, offset + 8, length-4,"Data");
1856                         }
1857                         break;
1858
1859                 default:
1860                         proto_tree_add_item(tlv_tree, hf_ldp_tlv_value, tvb, offset + 4, length, FALSE);
1861                         break;
1862                 }
1863         }
1864
1865         return length + 4;  /* Length of the value field + header */
1866 }
1867
1868
1869 /* Dissect a Message and return the number of bytes consumed ... */
1870
1871 static int
1872 dissect_msg(tvbuff_t *tvb, guint offset, packet_info *pinfo, proto_tree *tree)
1873 {
1874         guint16 type, typebak;
1875         guint8  extra=0;
1876         int length, rem, ao=0, co;
1877         proto_tree *ti = NULL, *msg_tree = NULL;
1878
1879         rem=tvb_reported_length_remaining(tvb, offset);
1880
1881         if( rem < 8 ) {/*chk for minimum header = type + length + msg_id*/
1882                 if( check_col(pinfo->cinfo, COL_INFO) )
1883                         col_append_fstr(pinfo->cinfo, COL_INFO, "Bad Message");
1884                 if(tree)
1885                         proto_tree_add_text(tree, tvb, offset, rem,
1886                             "Error processing Message: length is %d, should be >= 8",
1887                             rem);
1888                 return rem;
1889         }
1890         type = tvb_get_ntohs(tvb, offset) & 0x7FFF;
1891
1892         /*chk for vendor-private*/
1893         if(type>=LDP_VENDOR_PRIVATE_START && type<=LDP_VENDOR_PRIVATE_END){
1894                 typebak=type;           /*keep type*/
1895                 type=LDP_VENDOR_PRIVATE_START;
1896                 extra=4;
1897         /*chk for experimental*/
1898         } else if(type>=LDP_EXPERIMENTAL_MESSAGE_START && type<=LDP_EXPERIMENTAL_MESSAGE_END){
1899                 typebak=type;           /*keep type*/
1900                 type=LDP_EXPERIMENTAL_MESSAGE_START;
1901                 extra=4;
1902         }
1903
1904         if( (length = tvb_get_ntohs(tvb, offset + 2)) < (4+extra) ) {/*not enough data for type*/
1905                 if( check_col(pinfo->cinfo, COL_INFO) )
1906                         col_append_fstr(pinfo->cinfo, COL_INFO, "Bad Message Length ");
1907                 if(tree)
1908                         proto_tree_add_text(tree, tvb, offset, rem,
1909                             "Error processing Message Length: length is %d, should be >= %u",
1910                             length, 4+extra);
1911                 return rem;
1912         }
1913         rem -= 4;
1914         length = MIN(length, rem);  /* Don't go haywire if a problem ... */
1915
1916         if( check_col(pinfo->cinfo, COL_INFO) ){
1917                 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str(type, ldp_message_types, "Unknown Message (0x%04X)"));
1918         }
1919
1920         if( tree ){
1921                 ti = proto_tree_add_text(tree, tvb, offset, length + 4, "%s",
1922                         val_to_str(type, ldp_message_types, "Unknown Message type (0x%04X)"));
1923                 msg_tree = proto_item_add_subtree(ti, ett_ldp_message);
1924                 if(msg_tree == NULL) return length+4;
1925
1926                 proto_tree_add_item(msg_tree, hf_ldp_msg_ubit, tvb, offset, 1, FALSE);
1927
1928                 type=tvb_get_ntohs(tvb, offset)&0x7FFF;
1929                 proto_tree_add_uint_format(msg_tree, hf_ldp_msg_type, tvb, offset, 2, type, "Message Type: %s (0x%X)", val_to_str(type, ldp_message_types,"Unknown Message Type"), type);
1930
1931                 proto_tree_add_item(msg_tree, hf_ldp_msg_len, tvb, offset+2, 2, FALSE);
1932                 proto_tree_add_item(msg_tree, hf_ldp_msg_id, tvb, offset+4, 4, FALSE);
1933                 if(extra){
1934                         int hf_tmp=0;
1935
1936                         switch(type){
1937                                 case LDP_VENDOR_PRIVATE_START:
1938                                         hf_tmp=hf_ldp_msg_vendor_id;
1939                                         break;
1940                                 case LDP_EXPERIMENTAL_MESSAGE_START:
1941                                         hf_tmp=hf_ldp_msg_experiment_id;
1942                                         break;
1943                         }
1944                         proto_tree_add_item(msg_tree, hf_tmp, tvb, offset+8, extra, FALSE);
1945                 }
1946         }
1947
1948         offset += (8+extra);
1949         length -= (4+extra);
1950
1951         if( tree )
1952                 while( (length-ao) > 0 ) {
1953                         co=dissect_tlv(tvb, offset, msg_tree, length-ao);
1954                         offset += co;
1955                         ao += co;
1956                 }
1957
1958         return length+8+extra;
1959 }
1960
1961 /* Dissect a PDU */
1962 static void
1963 dissect_ldp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1964 {
1965         int offset = 0, co;
1966         int rem, length;
1967         proto_tree *ti=NULL, *pdu_tree = NULL;
1968
1969         if (check_col(pinfo->cinfo, COL_PROTOCOL))
1970                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LDP");
1971
1972         if (check_col(pinfo->cinfo, COL_INFO))
1973                 col_clear(pinfo->cinfo, COL_INFO);
1974
1975         if( tree ){
1976                 ti=proto_tree_add_item(tree, proto_ldp, tvb, 0, -1, FALSE);
1977                 pdu_tree = proto_item_add_subtree(ti, ett_ldp);
1978
1979                 proto_tree_add_item(pdu_tree, hf_ldp_version, tvb, offset, 2, FALSE);
1980         }
1981
1982         length = tvb_get_ntohs(tvb, offset+2);
1983         if( tree )
1984                 proto_tree_add_uint(pdu_tree, hf_ldp_pdu_len, tvb, offset+2, 2, length);
1985
1986         length += 4;    /* add the version and type sizes */
1987         rem = tvb_reported_length_remaining(tvb, offset);
1988         if (length < rem)
1989                 tvb_set_reported_length(tvb, length);
1990
1991         if( tree ){
1992                 proto_tree_add_item(pdu_tree, hf_ldp_lsr, tvb, offset+4, 4, FALSE);
1993                 proto_tree_add_item(pdu_tree, hf_ldp_ls_id, tvb, offset+8, 2, FALSE);
1994         }
1995         offset += 10;
1996
1997         while( tvb_reported_length_remaining(tvb, offset) > 0 ) {
1998                 co=dissect_msg(tvb, offset, pinfo, pdu_tree);
1999                 offset += co;
2000         }
2001 }
2002
2003 static int
2004 dissect_ldp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2005 {
2006         /*
2007          * Make sure the first PDU has a version number of 1;
2008          * if not, reject this, so we don't get confused by
2009          * packets that happen to be going to or from the
2010          * LDP port but that aren't LDP packets.
2011          */
2012         if (!tvb_bytes_exist(tvb, 0, 2)) {
2013                 /*
2014                  * Not enough information to tell.
2015                  */
2016                 return 0;
2017         }
2018         if (tvb_get_ntohs(tvb, 0) != 1) {
2019                 /*
2020                  * Not version 1.
2021                  */
2022                 return 0;
2023         }
2024
2025         dissect_ldp_pdu(tvb, pinfo, tree);
2026
2027         /*
2028          * XXX - return minimum of this and the length of the PDU?
2029          */
2030         return tvb_length(tvb);
2031 }
2032
2033 static int
2034 dissect_ldp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2035 {
2036         volatile gboolean first = TRUE;
2037         volatile int offset = 0;
2038         int length_remaining;
2039         guint16 plen;
2040         int length;
2041         tvbuff_t *next_tvb;
2042
2043         while (tvb_reported_length_remaining(tvb, offset) != 0) {
2044                 length_remaining = tvb_length_remaining(tvb, offset);
2045
2046                 /*
2047                  * Make sure the first PDU has a version number of 1;
2048                  * if not, reject this, so we don't get confused by
2049                  * packets that happen to be going to or from the
2050                  * LDP port but that aren't LDP packets.
2051                  *
2052                  * XXX - this means we can't handle an LDP PDU of which
2053                  * only one byte appears in a TCP segment.  If that's
2054                  * a problem, we'll either have to completely punt on
2055                  * rejecting non-LDP packets, or will have to assume
2056                  * that if we have only one byte, it's an LDP packet.
2057                  */
2058                 if (first) {
2059                         if (length_remaining < 2) {
2060                                 /*
2061                                  * Not enough information to tell.
2062                                  */
2063                                 return 0;
2064                         }
2065                         if (tvb_get_ntohs(tvb, offset) != 1) {
2066                                 /*
2067                                  * Not version 1.
2068                                  */
2069                                 return 0;
2070                         }
2071                         first = FALSE;
2072                 }
2073
2074                 /*
2075                  * Can we do reassembly?
2076                  */
2077                 if (ldp_desegment && pinfo->can_desegment) {
2078                         /*
2079                          * Yes - is the LDP header split across segment
2080                          * boundaries?
2081                          */
2082                         if (length_remaining < 4) {
2083                                 /*
2084                                  * Yes.  Tell the TCP dissector where
2085                                  * the data for this message starts in
2086                                  * the data it handed us, and how many
2087                                  * more bytes we need, and return.
2088                                  */
2089                                 pinfo->desegment_offset = offset;
2090                                 pinfo->desegment_len = 4 - length_remaining;
2091                                 return -pinfo->desegment_len;
2092                         }
2093                 }
2094
2095                 /*
2096                  * Get the length of the rest of the LDP packet.
2097                  * XXX - check for a version of 1 first?
2098                  */
2099                 plen = tvb_get_ntohs(tvb, offset + 2);
2100
2101                 /*
2102                  * Can we do reassembly?
2103                  */
2104                 if (ldp_desegment && pinfo->can_desegment) {
2105                         /*
2106                          * Yes - is the LDP packet split across segment
2107                          * boundaries?
2108                          */
2109                         if (length_remaining < plen + 4) {
2110                                 /*
2111                                  * Yes.  Tell the TCP dissector where the
2112                                  * data for this message starts in the data
2113                                  * it handed us, and how many more bytes we
2114                                  * need, and return.
2115                                  */
2116                                 pinfo->desegment_offset = offset;
2117                                 pinfo->desegment_len =
2118                                     (plen + 4) - length_remaining;
2119                                 return -pinfo->desegment_len;
2120                         }
2121                 }
2122
2123                 /*
2124                  * Construct a tvbuff containing the amount of the payload
2125                  * we have available.  Make its reported length the
2126                  * amount of data in the DNS-over-TCP packet.
2127                  *
2128                  * XXX - if reassembly isn't enabled. the subdissector
2129                  * will throw a BoundsError exception, rather than a
2130                  * ReportedBoundsError exception.  We really want
2131                  * a tvbuff where the length is "length", the reported
2132                  * length is "plen + 4", and the "if the snapshot length
2133                  * were infinite" length is the minimum of the
2134                  * reported length of the tvbuff handed to us and "plen+4",
2135                  * with a new type of exception thrown if the offset is
2136                  * within the reported length but beyond that third length,
2137                  * with that exception getting the "Unreassembled Packet"
2138                  * error.
2139                  */
2140                 length = length_remaining;
2141                 if (length > plen + 4)
2142                         length = plen + 4;
2143                 next_tvb = tvb_new_subset(tvb, offset, length, plen + 4);
2144
2145                 /*
2146                  * Dissect the LDP packet.
2147                  *
2148                  * Catch the ReportedBoundsError exception; if this
2149                  * particular message happens to get a ReportedBoundsError
2150                  * exception, that doesn't mean that we should stop
2151                  * dissecting LDP messages within this frame or chunk of
2152                  * reassembled data.
2153                  *
2154                  * If it gets a BoundsError, we can stop, as there's nothing
2155                  * more to see, so we just re-throw it.
2156                  */
2157                 TRY {
2158                         dissect_ldp_pdu(next_tvb, pinfo, tree);
2159                 }
2160                 CATCH(BoundsError) {
2161                         RETHROW;
2162                 }
2163                 CATCH(ReportedBoundsError) {
2164                         show_reported_bounds_error(tvb, pinfo, tree);
2165                 }
2166                 ENDTRY;
2167
2168                 /*
2169                  * Skip the LDP header and the payload.
2170                  */
2171                 offset += plen + 4;
2172         }
2173         return tvb_length(tvb);
2174 }
2175
2176 /* Register all the bits needed with the filtering engine */
2177
2178 void
2179 proto_register_ldp(void)
2180 {
2181   static hf_register_info hf[] = {
2182     { &hf_ldp_req,
2183       /* Change the following to the type you need */
2184       { "Request", "ldp.req", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
2185
2186     { &hf_ldp_rsp,
2187       { "Response", "ldp.rsp", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "", HFILL }},
2188
2189     { &hf_ldp_version,
2190       { "Version", "ldp.hdr.version", FT_UINT16, BASE_DEC, NULL, 0x0, "LDP Version Number", HFILL }},
2191
2192     { &hf_ldp_pdu_len,
2193       { "PDU Length", "ldp.hdr.pdu_len", FT_UINT16, BASE_DEC, NULL, 0x0, "LDP PDU Length", HFILL }},
2194
2195     { &hf_ldp_lsr,
2196       { "LSR ID", "ldp.hdr.ldpid.lsr", FT_IPv4, BASE_HEX, NULL, 0x0, "LDP Label Space Router ID", HFILL }},
2197
2198     { &hf_ldp_ls_id,
2199       { "Label Space ID", "ldp.hdr.ldpid.lsid", FT_UINT16, BASE_DEC, NULL, 0, "LDP Label Space ID", HFILL }},
2200
2201     { &hf_ldp_msg_ubit,
2202       { "U bit", "ldp.msg.ubit", FT_BOOLEAN, 8, TFS(&ldp_message_ubit), 0x80, "Unknown Message Bit", HFILL }},
2203
2204     { &hf_ldp_msg_type,
2205       { "Message Type", "ldp.msg.type", FT_UINT16, BASE_HEX, VALS(ldp_message_types), 0x7FFF, "LDP message type", HFILL }},
2206
2207     { &hf_ldp_msg_len,
2208       { "Message Length", "ldp.msg.len", FT_UINT16, BASE_DEC, NULL, 0x0, "LDP Message Length (excluding message type and len)", HFILL }},
2209
2210     { &hf_ldp_msg_id,
2211       { "Message ID", "ldp.msg.id", FT_UINT32, BASE_HEX, NULL, 0x0, "LDP Message ID", HFILL }},
2212
2213     { &hf_ldp_msg_vendor_id,
2214       { "Vendor ID", "ldp.msg.vendor.id", FT_UINT32, BASE_HEX, NULL, 0x0, "LDP Vendor-private Message ID", HFILL }},
2215
2216     { &hf_ldp_msg_experiment_id,
2217       { "Experiment ID", "ldp.msg.experiment.id", FT_UINT32, BASE_HEX, NULL, 0x0, "LDP Experimental Message ID", HFILL }},
2218
2219     { &hf_ldp_tlv_unknown,
2220       { "TLV Unknown bits", "ldp.msg.tlv.unknown", FT_UINT8, BASE_HEX, VALS(tlv_unknown_vals), 0xC0, "TLV Unknown bits Field", HFILL }},
2221
2222     { &hf_ldp_tlv_type,
2223       { "TLV Type", "ldp.msg.tlv.type", FT_UINT16, BASE_HEX, VALS(tlv_type_names), 0x3FFF, "TLV Type Field", HFILL }},
2224
2225     { &hf_ldp_tlv_len,
2226       {"TLV Length", "ldp.msg.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0, "TLV Length Field", HFILL }},
2227
2228     { &hf_ldp_tlv_value,
2229       { "TLV Value", "ldp.msg.tlv.value", FT_BYTES, BASE_NONE, NULL, 0x0, "TLV Value Bytes", HFILL }},
2230
2231     { &hf_ldp_tlv_val_hold,
2232       { "Hold Time", "ldp.msg.tlv.hello.hold", FT_UINT16, BASE_DEC, NULL, 0x0, "Hello Common Parameters Hold Time", HFILL }},
2233
2234     { &hf_ldp_tlv_val_target,
2235       { "Targeted Hello", "ldp.msg.tlv.hello.targeted", FT_BOOLEAN, 16, TFS(&hello_targeted_vals), 0x8000, "Hello Common Parameters Targeted Bit", HFILL }},
2236
2237     { &hf_ldp_tlv_val_request,
2238       { "Hello Requested", "ldp,msg.tlv.hello.requested", FT_BOOLEAN, 16, TFS(&hello_requested_vals), 0x4000, "Hello Common Parameters Hello Requested Bit", HFILL }},
2239
2240     { &hf_ldp_tlv_val_res,
2241       { "Reserved", "ldp.msg.tlv.hello.res", FT_UINT16, BASE_HEX, NULL, 0x3FFF, "Hello Common Parameters Reserved Field", HFILL }},
2242
2243     { &hf_ldp_tlv_ipv4_taddr,
2244       { "IPv4 Transport Address", "ldp.msg.tlv.ipv4.taddr", FT_IPv4, BASE_DEC, NULL, 0x0, "IPv4 Transport Address", HFILL }},
2245
2246     { &hf_ldp_tlv_config_seqno,
2247       { "Configuration Sequence Number", "ldp.msg.tlv.hello.cnf_seqno", FT_UINT32, BASE_DEC, NULL, 0x0, "Hello Configuration Sequence Number", HFILL }},
2248
2249     { &hf_ldp_tlv_ipv6_taddr,
2250       { "IPv6 Transport Address", "ldp.msg.tlv.ipv6.taddr", FT_IPv6, BASE_DEC, NULL, 0x0, "IPv6 Transport Address", HFILL }},
2251
2252     { &hf_ldp_tlv_fec_wc,
2253       { "FEC Element Type", "ldp.msg.tlv.fec.type", FT_UINT8, BASE_DEC, VALS(fec_types), 0x0, "Forwarding Equivalence Class Element Types", HFILL }},
2254
2255     { &hf_ldp_tlv_fec_af,
2256       { "FEC Element Address Type", "ldp.msg.tlv.fec.af", FT_UINT16, BASE_DEC, VALS(afn_vals), 0x0, "Forwarding Equivalence Class Element Address Family", HFILL }},
2257
2258     { &hf_ldp_tlv_fec_len,
2259       { "FEC Element Length", "ldp.msg.tlv.fec.len", FT_UINT8, BASE_DEC, NULL, 0x0, "Forwarding Equivalence Class Element Length", HFILL }},
2260
2261     { &hf_ldp_tlv_fec_pfval,
2262       { "FEC Element Prefix Value", "ldp.msg.tlv.fec.pfval", FT_STRING, BASE_NONE, NULL, 0x0, "Forwarding Equivalence Class Element Prefix", HFILL }},
2263
2264     { &hf_ldp_tlv_fec_hoval,
2265       { "FEC Element Host Address Value", "ldp.msg.tlv.fec.hoval", FT_STRING, BASE_NONE, NULL, 0x0, "Forwarding Equivalence Class Element Address", HFILL }},
2266
2267     { &hf_ldp_tlv_addrl_addr_family,
2268       { "Address Family", "ldp.msg.tlv.addrl.addr_family", FT_UINT16, BASE_DEC, VALS(afn_vals), 0x0, "Address Family List", HFILL }},
2269
2270     { &hf_ldp_tlv_addrl_addr,
2271       { "Address", "ldp.msg.tlv.addrl.addr", FT_STRING, BASE_NONE, NULL, 0x0, "Address", HFILL }},
2272
2273     { &hf_ldp_tlv_hc_value,
2274       { "Hop Count Value", "ldp.msg.tlv.hc.value", FT_UINT8, BASE_DEC, NULL, 0x0, "Hop Count", HFILL }},
2275
2276     { &hf_ldp_tlv_pv_lsrid,
2277       { "LSR Id", "ldp.msg.tlv.pv.lsrid", FT_IPv4, BASE_DEC, NULL, 0x0, "Path Vector LSR Id", HFILL }},
2278
2279     { &hf_ldp_tlv_sess_ver,
2280       { "Session Protocol Version", "ldp.msg.tlv.sess.ver", FT_UINT16, BASE_DEC, NULL, 0x0, "Common Session Parameters Protocol Version", HFILL }},
2281
2282     { &hf_ldp_tlv_sess_ka,
2283       { "Session KeepAlive Time", "ldp.msg.tlv.sess.ka", FT_UINT16, BASE_DEC, NULL, 0x0, "Common Session Parameters KeepAlive Time", HFILL }},
2284
2285     { &hf_ldp_tlv_sess_advbit,
2286       { "Session Label Advertisement Discipline", "ldp.msg.tlv.sess.advbit",
2287  FT_BOOLEAN, 8, TFS(&tlv_sess_advbit_vals), 0x80,
2288         "Common Session Parameters Label Advertisement Discipline", HFILL }},
2289
2290     { &hf_ldp_tlv_sess_ldetbit,
2291       { "Session Loop Detection", "ldp.msg.tlv.sess.ldetbit", FT_BOOLEAN, 8, TFS(&tlv_sess_ldetbit_vals), 0x40, "Common Session Parameters Loop Detection", HFILL }},
2292
2293     { &hf_ldp_tlv_sess_pvlim,
2294       { "Session Path Vector Limit", "ldp.msg.tlv.sess.pvlim", FT_UINT8, BASE_DEC, NULL, 0x0, "Common Session Parameters Path Vector Limit", HFILL }},
2295
2296     { &hf_ldp_tlv_sess_mxpdu,
2297       { "Session Max PDU Length", "ldp.msg.tlv.sess.mxpdu", FT_UINT16, BASE_DEC, NULL, 0x0, "Common Session Parameters Max PDU Length", HFILL }},
2298
2299     { &hf_ldp_tlv_sess_rxlsr,
2300       { "Session Receiver LSR Identifier", "ldp.msg.tlv.sess.rxlsr", FT_IPv4, BASE_DEC, NULL, 0x0, "Common Session Parameters LSR Identifier", HFILL }},
2301
2302     { &hf_ldp_tlv_sess_rxls,
2303       { "Session Receiver Label Space Identifier", "ldp.msg.tlv.sess.rxlsr", FT_UINT16, BASE_DEC, NULL, 0x0, "Common Session Parameters Receiver Label Space Identifier", HFILL }},
2304
2305     { &hf_ldp_tlv_sess_atm_merge,
2306       { "Session ATM Merge Parameter", "ldp.msg.tlv.sess.atm.merge", FT_UINT8, BASE_DEC, VALS(tlv_atm_merge_vals), 0xC0, "Merge ATM Session Parameters", HFILL }},
2307
2308     { &hf_ldp_tlv_sess_atm_lr,
2309       { "Number of ATM Label Ranges", "ldp.msg.tlv.sess.atm.lr", FT_UINT8, BASE_DEC, NULL, 0x3C, "Number of Label Ranges", HFILL }},
2310
2311     { &hf_ldp_tlv_sess_atm_dir,
2312       { "Directionality", "ldp.msg.tlv.sess.atm.dir", FT_BOOLEAN, 8, TFS(&tlv_atm_dirbit), 0x02, "Lablel Directionality", HFILL }},
2313
2314     { &hf_ldp_tlv_sess_atm_minvpi,
2315       { "Minimum VPI", "ldp.msg.tlv.sess.atm.minvpi", FT_UINT16, BASE_DEC, NULL, 0x0FFF, "Minimum VPI", HFILL }},
2316
2317     { &hf_ldp_tlv_sess_atm_minvci,
2318       { "Minimum VCI", "ldp.msg.tlv.sess.atm.minvci", FT_UINT16, BASE_DEC, NULL, 0x0, "Minimum VCI", HFILL }},
2319
2320     { &hf_ldp_tlv_sess_atm_maxvpi,
2321       { "Maximum VPI", "ldp.msg.tlv.sess.atm.maxvpi", FT_UINT16, BASE_DEC, NULL, 0x0FFF, "Maximum VPI", HFILL }},
2322
2323     { &hf_ldp_tlv_sess_atm_maxvci,
2324       { "Maximum VCI", "ldp.msg.tlv.sess.atm.maxvci", FT_UINT16, BASE_DEC, NULL, 0x0, "Maximum VCI", HFILL }},
2325
2326     { &hf_ldp_tlv_sess_fr_merge,
2327       { "Session Frame Relay Merge Parameter", "ldp.msg.tlv.sess.fr.merge", FT_UINT8, BASE_DEC, VALS(tlv_fr_merge_vals), 0xC0, "Merge Frame Relay Session Parameters", HFILL }},
2328
2329     { &hf_ldp_tlv_sess_fr_lr,
2330       { "Number of Frame Relay Label Ranges", "ldp.msg.tlv.sess.fr.lr", FT_UINT8, BASE_DEC, NULL, 0x3C, "Number of Label Ranges", HFILL }},
2331
2332     { &hf_ldp_tlv_sess_fr_dir,
2333       { "Directionality", "ldp.msg.tlv.sess.fr.dir", FT_BOOLEAN, 8, TFS(&tlv_atm_dirbit), 0x02, "Lablel Directionality", HFILL }},
2334
2335     { &hf_ldp_tlv_sess_fr_len,
2336       { "Number of DLCI bits", "ldp.msg.tlv.sess.fr.len", FT_UINT16, BASE_DEC, VALS(tlv_fr_len_vals), 0x0180, "DLCI Number of bits", HFILL }},
2337
2338     { &hf_ldp_tlv_sess_fr_mindlci,
2339       { "Minimum DLCI", "ldp.msg.tlv.sess.fr.mindlci", FT_UINT24, BASE_DEC, NULL, 0x7FFFFF, "Minimum DLCI", HFILL }},
2340
2341     { &hf_ldp_tlv_sess_fr_maxdlci,
2342       { "Maximum DLCI", "ldp.msg.tlv.sess.fr.maxdlci", FT_UINT24, BASE_DEC, NULL, 0x7FFFFF, "Maximum DLCI", HFILL }},
2343
2344     { &hf_ldp_tlv_lbl_req_msg_id,
2345       { "Label Request Message ID", "ldp.tlv.lbl_req_msg_id", FT_UINT32, BASE_HEX, NULL, 0x0, "Label Request Message to be aborted", HFILL }},
2346
2347     { &hf_ldp_tlv_vendor_id,
2348       { "Vendor ID", "ldp.msg.tlv.vendor_id", FT_UINT32, BASE_HEX, NULL, 0, "IEEE 802 Assigned Vendor ID", HFILL }},
2349
2350     { &hf_ldp_tlv_experiment_id,
2351       { "Experiment ID", "ldp.msg.tlv.experiment_id", FT_UINT32, BASE_HEX, NULL, 0, "Experiment ID", HFILL }},
2352
2353     { &hf_ldp_tlv_generic_label,
2354       { "Generic Label", "ldp.msg.tlv.generic.label", FT_UINT32, BASE_HEX, NULL, 0x000FFFFF, "Generic Label", HFILL }},
2355
2356     { &hf_ldp_tlv_atm_label_vbits,
2357       { "V-bits", "ldp.msg.tlv.atm.label.vbits", FT_UINT8, BASE_HEX, VALS(tlv_atm_vbits_vals), 0x30, "ATM Label V Bits", HFILL }},
2358
2359     { &hf_ldp_tlv_atm_label_vpi,
2360       { "VPI", "ldp.msg.tlv.atm.label.vpi", FT_UINT16, BASE_DEC, NULL, 0x0FFF, "ATM Label VPI", HFILL }},
2361
2362     { &hf_ldp_tlv_atm_label_vci,
2363       { "VCI", "ldp.msg.tlv.atm.label.vci", FT_UINT16, BASE_DEC, NULL, 0, "ATM Label VCI", HFILL }},
2364
2365     { &hf_ldp_tlv_fr_label_len,
2366       { "Number of DLCI bits", "ldp.msg.tlv.fr.label.len", FT_UINT16, BASE_DEC, VALS(tlv_fr_len_vals), 0x0180, "DLCI Number of bits", HFILL }},
2367
2368     { &hf_ldp_tlv_fr_label_dlci,
2369       { "DLCI", "ldp.msg.tlv.fr.label.dlci", FT_UINT24, BASE_DEC, NULL, 0x7FFFFF, "FRAME RELAY Label DLCI", HFILL }},
2370
2371     { &hf_ldp_tlv_status_ebit,
2372       { "E Bit", "ldp.msg.tlv.status.ebit", FT_BOOLEAN, 8, TFS(&tlv_status_ebit), 0x80, "Fatal Error Bit", HFILL }},
2373
2374     { &hf_ldp_tlv_status_fbit,
2375       { "F Bit", "ldp.msg.tlv.status.fbit", FT_BOOLEAN, 8, TFS(&tlv_status_fbit), 0x40, "Forward Bit", HFILL }},
2376
2377     { &hf_ldp_tlv_status_data,
2378       { "Status Data", "ldp.msg.tlv.status.data", FT_UINT32, BASE_HEX, VALS(tlv_status_data), 0x3FFFFFFF, "Status Data", HFILL }},
2379
2380     { &hf_ldp_tlv_status_msg_id,
2381       { "Message ID", "ldp.msg.tlv.status.msg.id", FT_UINT32, BASE_HEX, NULL, 0x0, "Identifies peer message to which Status TLV refers", HFILL }},
2382
2383     { &hf_ldp_tlv_status_msg_type,
2384       { "Message Type", "ldp.msg.tlv.status.msg.type", FT_UINT16, BASE_HEX, VALS(ldp_message_types), 0x0, "Type of peer message to which Status TLV refers", HFILL }},
2385
2386     { &hf_ldp_tlv_extstatus_data,
2387       { "Extended Status Data", "ldp.msg.tlv.extstatus.data", FT_UINT32, BASE_HEX, NULL, 0x0, "Extended Status Data", HFILL }},
2388
2389     { &hf_ldp_tlv_returned_version,
2390       { "Returned PDU Version", "ldp.msg.tlv.returned.version", FT_UINT16, BASE_DEC, NULL, 0x0, "LDP Version Number", HFILL }},
2391
2392     { &hf_ldp_tlv_returned_pdu_len,
2393       { "Returned PDU Length", "ldp.msg.tlv.returned.pdu_len", FT_UINT16, BASE_DEC, NULL, 0x0, "LDP PDU Length", HFILL }},
2394
2395     { &hf_ldp_tlv_returned_lsr,
2396       { "Returned PDU LSR ID", "ldp.msg.tlv.returned.ldpid.lsr", FT_IPv4, BASE_DEC, NULL, 0x0, "LDP Label Space Router ID", HFILL }},
2397
2398     { &hf_ldp_tlv_returned_ls_id,
2399       { "Returned PDU Label Space ID", "ldp.msg.tlv.returned.ldpid.lsid", FT_UINT16, BASE_HEX, NULL, 0x0, "LDP Label Space ID", HFILL }},
2400
2401     { &hf_ldp_tlv_returned_msg_ubit,
2402       { "Returned Message Unknown bit", "ldp.msg.tlv.returned.msg.ubit", FT_UINT8, BASE_HEX, TFS(&ldp_message_ubit), 0x80, "Message Unknown bit", HFILL }},
2403
2404     { &hf_ldp_tlv_returned_msg_type,
2405       { "Returned Message Type", "ldp.msg.tlv.returned.msg.type", FT_UINT16, BASE_HEX, VALS(ldp_message_types), 0x7FFF, "LDP message type", HFILL }},
2406
2407     { &hf_ldp_tlv_returned_msg_len,
2408       { "Returned Message Length", "ldp.msg.tlv.returned.msg.len", FT_UINT16, BASE_DEC, NULL, 0x0, "LDP Message Length (excluding message type and len)", HFILL }},
2409
2410     { &hf_ldp_tlv_returned_msg_id,
2411       { "Returned Message ID", "ldp.msg.tlv.returned.msg.id", FT_UINT32, BASE_HEX, NULL, 0x0, "LDP Message ID", HFILL }},
2412
2413     { &hf_ldp_tlv_mac,
2414       { "MAC address", "ldp.msg.tlv.mac", FT_ETHER, BASE_NONE, NULL, 0x0, "MAC address", HFILL}},
2415
2416     {&hf_ldp_tlv_fec_vc_controlword,
2417      {"C-bit", "ldp.msg.tlv.fec.vc.controlword", FT_BOOLEAN, 8, TFS(&fec_vc_cbit), 0x80, "Control Word Present", HFILL }},
2418
2419     {&hf_ldp_tlv_fec_vc_vctype,
2420      {"VC Type", "ldp.msg.tlv.fec.vc.vctype", FT_UINT16, BASE_HEX, VALS(fec_vc_types_vals), 0x7FFF, "Virtual Circuit Type", HFILL }},
2421
2422     {&hf_ldp_tlv_fec_vc_infolength,
2423      {"VC Info Length", "ldp.msg.tlv.fec.vc.infolength", FT_UINT8, BASE_DEC, NULL, 0x0, "VC FEC Info Length", HFILL }},
2424
2425     {&hf_ldp_tlv_fec_vc_groupid,
2426      {"Group ID", "ldp.msg.tlv.fec.vc.groupid", FT_UINT32, BASE_DEC, NULL, 0x0, "VC FEC Group ID", HFILL }},
2427
2428     {&hf_ldp_tlv_fec_vc_vcid,
2429      {"VC ID", "ldp.msg.tlv.fec.vc.vcid", FT_UINT32, BASE_DEC, NULL, 0x0, "VC FEC VCID", HFILL }},
2430
2431     {&hf_ldp_tlv_fec_vc_intparam_length,
2432      {"Length", "ldp.msg.tlv.fec.vc.intparam.length", FT_UINT8, BASE_DEC, NULL, 0x0, "VC FEC Interface Paramater Length", HFILL }},
2433
2434     {&hf_ldp_tlv_fec_vc_intparam_mtu,
2435      {"MTU", "ldp.msg.tlv.fec.vc.intparam.mtu", FT_UINT16, BASE_DEC, NULL, 0x0, "VC FEC Interface Paramater MTU", HFILL }},
2436
2437     {&hf_ldp_tlv_fec_vc_intparam_id,
2438      {"ID", "ldp.msg.tlv.fec.vc.intparam.id", FT_UINT8, BASE_HEX, VALS(fec_vc_interfaceparm), 0x0, "VC FEC Interface Paramater ID", HFILL }},
2439
2440     {&hf_ldp_tlv_fec_vc_intparam_maxcatmcells,
2441      {"Number of Cells", "ldp.msg.tlv.fec.vc.intparam.maxatm", FT_UINT16, BASE_DEC, NULL, 0x0, "VC FEC Interface Param Max ATM Concat Cells", HFILL }},
2442
2443     { &hf_ldp_tlv_fec_vc_intparam_desc,
2444       { "Description", "ldp.msg.tlv.fec.vc.intparam.desc", FT_STRING, BASE_DEC, NULL, 0, "VC FEC Interface Description", HFILL }},
2445
2446     { &hf_ldp_tlv_fec_vc_intparam_cembytes,
2447      {"Payload Bytes", "ldp.msg.tlv.fec.vc.intparam.cembytes", FT_UINT16, BASE_DEC, NULL, 0x0, "VC FEC Interface Param CEM Payload Bytes", HFILL }},
2448
2449     { &hf_ldp_tlv_fec_vc_intparam_vpnid_oui,
2450       { "VPN OUI", "ldp.msg.tlv.fec.vc.intparam.vpnid.oui", FT_UINT24, BASE_HEX, NULL, 0x0, "VC FEC Interface Param VPN OUI", HFILL }},
2451
2452     { &hf_ldp_tlv_fec_vc_intparam_vpnid_index,
2453       { "VPN Index", "ldp.msg.tlv.fec.vc.intparam.vpnid.index", FT_UINT32, BASE_HEX, NULL, 0x0, "VC FEC Interface Param VPN Index", HFILL }},
2454
2455     { &hf_ldp_tlv_lspid_act_flg,
2456       { "Action Indicator Flag", "ldp.msg.tlv.lspid.actflg", FT_UINT16, BASE_HEX, VALS(ldp_act_flg_vals), 0x000F, "Action Indicator Flag", HFILL}},
2457
2458     { &hf_ldp_tlv_lspid_cr_lsp,
2459       { "Local CR-LSP ID", "ldp.msg.tlv.lspid.locallspid", FT_UINT16, BASE_HEX, NULL, 0x0, "Local CR-LSP ID", HFILL}},
2460
2461     { &hf_ldp_tlv_lspid_ldpid,
2462       { "Ingress LSR Router ID", "ldp.msg.tlv.lspid.lsrid", FT_IPv4, BASE_DEC, NULL, 0x0, "Ingress LSR Router ID", HFILL}},
2463
2464     { &hf_ldp_tlv_er_hop_loose,
2465       { "Loose route bit", "ldp.msg.tlv.er_hop.loose", FT_UINT24, BASE_HEX, VALS(ldp_loose_vals), 0x800000, "Loose route bit", HFILL}},
2466
2467     { &hf_ldp_tlv_er_hop_prelen,
2468       { "Prefix length", "ldp.msg.tlv.er_hop.prefixlen", FT_UINT8, BASE_DEC, NULL, 0x0, "Prefix len", HFILL}},
2469
2470     { &hf_ldp_tlv_er_hop_prefix4,
2471       { "IPv4 Address", "ldp.msg.tlv.er_hop.prefix4", FT_IPv4, BASE_DEC, NULL, 0x0, "IPv4 Address", HFILL}},
2472    { &hf_ldp_tlv_er_hop_prefix6,
2473      { "IPv6 Address", "ldp.msg.tlv.er_hop.prefix6", FT_IPv6, BASE_DEC, NULL, 0x0, "IPv6 Address", HFILL}},
2474
2475     { &hf_ldp_tlv_er_hop_as,
2476       { "AS Number", "ldp.msg.tlv.er_hop.as", FT_UINT16, BASE_DEC, NULL, 0x0, "AS Number", HFILL}},
2477
2478     { &hf_ldp_tlv_er_hop_cr_lsp,
2479       { "Local CR-LSP ID", "ldp.msg.tlv.er_hop.locallspid", FT_UINT16, BASE_DEC, NULL, 0x0, "Local CR-LSP ID", HFILL}},
2480
2481     { &hf_ldp_tlv_er_hop_ldpid,
2482       { "Local CR-LSP ID", "ldp.msg.tlv.er_hop.lsrid", FT_IPv4, BASE_DEC, NULL, 0x0, "Local CR-LSP ID", HFILL}},
2483
2484     { &hf_ldp_tlv_flags_reserv,
2485       { "Reserved", "ldp.msg.tlv.flags_reserv", FT_UINT8, BASE_HEX, NULL, 0xC0, "Reserved", HFILL}},
2486
2487     { &hf_ldp_tlv_flags_pdr,
2488       { "PDR", "ldp.msg.tlv.flags_pdr", FT_BOOLEAN, 8, TFS(&tlv_negotiable), 0x1, "PDR negotiability flag", HFILL}},
2489
2490     { &hf_ldp_tlv_flags_pbs,
2491       { "PBS", "ldp.msg.tlv.flags_pbs", FT_BOOLEAN, 8, TFS(&tlv_negotiable), 0x2, "PBS negotiability flag", HFILL}},
2492
2493     { &hf_ldp_tlv_flags_cdr,
2494       { "CDR", "ldp.msg.tlv.flags_cdr", FT_BOOLEAN, 8, TFS(&tlv_negotiable), 0x4, "CDR negotiability flag", HFILL}},
2495
2496     { &hf_ldp_tlv_flags_cbs,
2497       { "CBS", "ldp.msg.tlv.flags_cbs", FT_BOOLEAN, 8, TFS(&tlv_negotiable), 0x8, "CBS negotiability flag", HFILL}},
2498
2499     { &hf_ldp_tlv_flags_ebs,
2500       { "EBS", "ldp.msg.tlv.flags_ebs", FT_BOOLEAN, 8, TFS(&tlv_negotiable), 0x10, "EBS negotiability flag", HFILL}},
2501
2502     { &hf_ldp_tlv_flags_weight,
2503       { "Weight", "ldp.msg.tlv.flags_weight", FT_BOOLEAN, 8, TFS(&tlv_negotiable), 0x20, "Weight negotiability flag", HFILL}},
2504
2505     { &hf_ldp_tlv_frequency,
2506       { "Frequency", "ldp.msg.tlv.frequency", FT_UINT8, BASE_DEC, VALS(freq_values), 0, "Frequency", HFILL}},
2507
2508     { &hf_ldp_tlv_weight,
2509       { "Weight", "ldp.msg.tlv.weight", FT_UINT8, BASE_DEC, NULL, 0, "Weight of the CR-LSP", HFILL}},
2510
2511     { &hf_ldp_tlv_pdr,
2512       { "PDR", "ldp.msg.tlv.pdr", FT_DOUBLE, BASE_NONE, NULL, 0, "Peak Data Rate", HFILL}},
2513
2514     { &hf_ldp_tlv_pbs,
2515       { "PBS", "ldp.msg.tlv.pbs", FT_DOUBLE, BASE_NONE, NULL, 0, "Peak Burst Size", HFILL}},
2516
2517     { &hf_ldp_tlv_cdr,
2518       { "CDR", "ldp.msg.tlv.cdr", FT_DOUBLE, BASE_NONE, NULL, 0, "Committed Data Rate", HFILL}},
2519
2520     { &hf_ldp_tlv_cbs,
2521       { "CBS", "ldp.msg.tlv.cbs", FT_DOUBLE, BASE_NONE, NULL, 0, "Committed Burst Size", HFILL}},
2522
2523     { &hf_ldp_tlv_ebs,
2524       { "EBS", "ldp.msg.tlv.ebs", FT_DOUBLE, BASE_NONE, NULL, 0, "Excess Burst Size", HFILL}},
2525
2526     { &hf_ldp_tlv_set_prio,
2527       { "Set Prio", "ldp.msg.tlv.set_prio", FT_UINT8, BASE_DEC, NULL, 0, "LSP setup priority", HFILL}},
2528
2529     { &hf_ldp_tlv_hold_prio,
2530       { "Hold Prio", "ldp.msg.tlv.hold_prio", FT_UINT8, BASE_DEC, NULL, 0, "LSP hold priority", HFILL}},
2531
2532     { &hf_ldp_tlv_route_pinning,
2533       { "Route Pinning", "ldp.msg.tlv.route_pinning", FT_UINT32, BASE_DEC, VALS(route_pinning_vals), 0x80000000, "Route Pinning", HFILL}},
2534
2535     { &hf_ldp_tlv_resource_class,
2536       { "Resource Class", "ldp.msg.tlv.resource_class", FT_UINT32, BASE_HEX, NULL, 0, "Resource Class (Color)", HFILL}},
2537
2538   };
2539
2540   static gint *ett[] = {
2541     &ett_ldp,
2542     &ett_ldp_header,
2543     &ett_ldp_ldpid,
2544     &ett_ldp_message,
2545     &ett_ldp_tlv,
2546     &ett_ldp_tlv_val,
2547     &ett_ldp_fec,
2548     &ett_ldp_fec_vc_interfaceparam
2549   };
2550   module_t *ldp_module;
2551
2552   proto_ldp = proto_register_protocol("Label Distribution Protocol",
2553                                        "LDP", "ldp");
2554
2555   proto_register_field_array(proto_ldp, hf, array_length(hf));
2556   proto_register_subtree_array(ett, array_length(ett));
2557
2558   /* Register our configuration options for , particularly our port */
2559
2560   ldp_module = prefs_register_protocol(proto_ldp, proto_reg_handoff_ldp);
2561
2562   prefs_register_uint_preference(ldp_module, "tcp.port", "LDP TCP Port",
2563                                  "Set the TCP port for messages (if other"
2564                                  " than the default of 646)",
2565                                  10, &global_ldp_tcp_port);
2566
2567   prefs_register_uint_preference(ldp_module, "udp.port", "LDP UDP Port",
2568                                  "Set the UDP port for messages (if other"
2569                                  " than the default of 646)",
2570                                  10, &global_ldp_udp_port);
2571
2572   prefs_register_bool_preference(ldp_module, "desegment_ldp_messages",
2573     "Desegment all LDP messages spanning multiple TCP segments",
2574     "Whether the LDP dissector should desegment all messages spanning multiple TCP segments",
2575     &ldp_desegment);
2576 }
2577
2578 /* The registration hand-off routine */
2579 void
2580 proto_reg_handoff_ldp(void)
2581 {
2582   static gboolean ldp_prefs_initialized = FALSE;
2583   static dissector_handle_t ldp_tcp_handle, ldp_handle;
2584
2585   if (!ldp_prefs_initialized) {
2586
2587     ldp_tcp_handle = new_create_dissector_handle(dissect_ldp_tcp, proto_ldp);
2588     ldp_handle = new_create_dissector_handle(dissect_ldp, proto_ldp);
2589
2590     ldp_prefs_initialized = TRUE;
2591
2592   }
2593   else {
2594
2595     dissector_delete("tcp.port", tcp_port, ldp_tcp_handle);
2596     dissector_delete("udp.port", udp_port, ldp_handle);
2597
2598   }
2599
2600   /* Set our port number for future use */
2601
2602   tcp_port = global_ldp_tcp_port;
2603   udp_port = global_ldp_udp_port;
2604
2605   dissector_add("tcp.port", global_ldp_tcp_port, ldp_tcp_handle);
2606   dissector_add("udp.port", global_ldp_udp_port, ldp_handle);
2607
2608 }