xref: /freebsd/contrib/tcpdump/print-rsvp.c (revision 4f29da19bd44f0e99f021510460a81bf754c21d2)
1 /*
2  * Redistribution and use in source and binary forms, with or without
3  * modification, are permitted provided that: (1) source code
4  * distributions retain the above copyright notice and this paragraph
5  * in its entirety, and (2) distributions including binary code include
6  * the above copyright notice and this paragraph in its entirety in
7  * the documentation or other materials provided with the distribution.
8  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11  * FOR A PARTICULAR PURPOSE.
12  *
13  * Original code by Hannes Gredler (hannes@juniper.net)
14  */
15 
16 #ifndef lint
17 static const char rcsid[] _U_ =
18     "@(#) $Header: /tcpdump/master/tcpdump/print-rsvp.c,v 1.33.2.3 2005/06/16 00:50:12 guy Exp $";
19 #endif
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <tcpdump-stdinc.h>
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include "interface.h"
32 #include "extract.h"
33 #include "addrtoname.h"
34 #include "ethertype.h"
35 #include "gmpls.h"
36 
37 /*
38  * RFC 2205 common header
39  *
40  *               0             1              2             3
41  *        +-------------+-------------+-------------+-------------+
42  *        | Vers | Flags|  Msg Type   |       RSVP Checksum       |
43  *        +-------------+-------------+-------------+-------------+
44  *        |  Send_TTL   | (Reserved)  |        RSVP Length        |
45  *        +-------------+-------------+-------------+-------------+
46  *
47  */
48 
49 struct rsvp_common_header {
50     u_int8_t version_flags;
51     u_int8_t msg_type;
52     u_int8_t checksum[2];
53     u_int8_t ttl;
54     u_int8_t reserved;
55     u_int8_t length[2];
56 };
57 
58 /*
59  * RFC2205 object header
60  *
61  *
62  *               0             1              2             3
63  *        +-------------+-------------+-------------+-------------+
64  *        |       Length (bytes)      |  Class-Num  |   C-Type    |
65  *        +-------------+-------------+-------------+-------------+
66  *        |                                                       |
67  *        //                  (Object contents)                   //
68  *        |                                                       |
69  *        +-------------+-------------+-------------+-------------+
70  */
71 
72 struct rsvp_object_header {
73     u_int8_t length[2];
74     u_int8_t class_num;
75     u_int8_t ctype;
76 };
77 
78 #define RSVP_VERSION            1
79 #define	RSVP_EXTRACT_VERSION(x) (((x)&0xf0)>>4)
80 #define	RSVP_EXTRACT_FLAGS(x)   ((x)&0x0f)
81 
82 #define	RSVP_MSGTYPE_PATH       1
83 #define	RSVP_MSGTYPE_RESV       2
84 #define	RSVP_MSGTYPE_PATHERR    3
85 #define	RSVP_MSGTYPE_RESVERR    4
86 #define	RSVP_MSGTYPE_PATHTEAR   5
87 #define	RSVP_MSGTYPE_RESVTEAR   6
88 #define	RSVP_MSGTYPE_RESVCONF   7
89 #define RSVP_MSGTYPE_AGGREGATE  12
90 #define RSVP_MSGTYPE_ACK        13
91 #define RSVP_MSGTYPE_HELLO_OLD  14      /* ancient Hellos */
92 #define RSVP_MSGTYPE_SREFRESH   15
93 #define	RSVP_MSGTYPE_HELLO      20
94 
95 static const struct tok rsvp_msg_type_values[] = {
96     { RSVP_MSGTYPE_PATH,	"Path" },
97     { RSVP_MSGTYPE_RESV,	"Resv" },
98     { RSVP_MSGTYPE_PATHERR,	"PathErr" },
99     { RSVP_MSGTYPE_RESVERR,	"ResvErr" },
100     { RSVP_MSGTYPE_PATHTEAR,	"PathTear" },
101     { RSVP_MSGTYPE_RESVTEAR,	"ResvTear" },
102     { RSVP_MSGTYPE_RESVCONF,	"ResvConf" },
103     { RSVP_MSGTYPE_AGGREGATE,	"Aggregate" },
104     { RSVP_MSGTYPE_ACK,	        "Acknowledgement" },
105     { RSVP_MSGTYPE_HELLO_OLD,	"Hello (Old)" },
106     { RSVP_MSGTYPE_SREFRESH,	"Refresh" },
107     { RSVP_MSGTYPE_HELLO,	"Hello" },
108     { 0, NULL}
109 };
110 
111 static const struct tok rsvp_header_flag_values[] = {
112     { 0x01,	              "Refresh reduction capable" }, /* rfc2961 */
113     { 0, NULL}
114 };
115 
116 #define	RSVP_OBJ_SESSION            1   /* rfc2205 */
117 #define	RSVP_OBJ_RSVP_HOP           3   /* rfc2205, rfc3473 */
118 #define	RSVP_OBJ_INTEGRITY          4
119 #define	RSVP_OBJ_TIME_VALUES        5   /* rfc2205 */
120 #define	RSVP_OBJ_ERROR_SPEC         6
121 #define	RSVP_OBJ_SCOPE              7
122 #define	RSVP_OBJ_STYLE              8   /* rfc2205 */
123 #define	RSVP_OBJ_FLOWSPEC           9   /* rfc2215 */
124 #define	RSVP_OBJ_FILTERSPEC         10  /* rfc2215 */
125 #define	RSVP_OBJ_SENDER_TEMPLATE    11
126 #define	RSVP_OBJ_SENDER_TSPEC       12  /* rfc2215 */
127 #define	RSVP_OBJ_ADSPEC             13  /* rfc2215 */
128 #define	RSVP_OBJ_POLICY_DATA        14
129 #define	RSVP_OBJ_CONFIRM            15  /* rfc2205 */
130 #define	RSVP_OBJ_LABEL              16  /* rfc3209 */
131 #define	RSVP_OBJ_LABEL_REQ          19  /* rfc3209 */
132 #define	RSVP_OBJ_ERO                20  /* rfc3209 */
133 #define	RSVP_OBJ_RRO                21  /* rfc3209 */
134 #define	RSVP_OBJ_HELLO              22  /* rfc3209 */
135 #define	RSVP_OBJ_MESSAGE_ID         23
136 #define	RSVP_OBJ_MESSAGE_ID_ACK     24
137 #define	RSVP_OBJ_MESSAGE_ID_LIST    25
138 #define	RSVP_OBJ_RECOVERY_LABEL     34  /* rfc3473 */
139 #define	RSVP_OBJ_UPSTREAM_LABEL     35  /* rfc3473 */
140 #define	RSVP_OBJ_LABEL_SET          36  /* rfc3473 */
141 #define	RSVP_OBJ_PROTECTION         37  /* rfc3473 */
142 #define	RSVP_OBJ_DETOUR             63  /* draft-ietf-mpls-rsvp-lsp-fastreroute-01 */
143 #define	RSVP_OBJ_CLASSTYPE          125 /* draft-ietf-tewg-diff-te-proto-07 */
144 #define	RSVP_OBJ_SUGGESTED_LABEL    129 /* rfc3473 */
145 #define	RSVP_OBJ_ACCEPT_LABEL_SET   130 /* rfc3473 */
146 #define	RSVP_OBJ_RESTART_CAPABILITY 131 /* rfc3473 */
147 #define	RSVP_OBJ_NOTIFY_REQ         195 /* rfc3473 */
148 #define	RSVP_OBJ_ADMIN_STATUS       196 /* rfc3473 */
149 #define	RSVP_OBJ_PROPERTIES         204 /* juniper proprietary */
150 #define	RSVP_OBJ_FASTREROUTE        205 /* draft-ietf-mpls-rsvp-lsp-fastreroute-01 */
151 #define	RSVP_OBJ_SESSION_ATTRIBUTE  207 /* rfc3209 */
152 #define RSVP_OBJ_CALL_ID            230 /* rfc3474 */
153 #define RSVP_OBJ_CALL_OPS           236 /* rfc3474 */
154 
155 static const struct tok rsvp_obj_values[] = {
156     { RSVP_OBJ_SESSION,            "Session" },
157     { RSVP_OBJ_RSVP_HOP,           "RSVP Hop" },
158     { RSVP_OBJ_INTEGRITY,          "Integrity" },
159     { RSVP_OBJ_TIME_VALUES,        "Time Values" },
160     { RSVP_OBJ_ERROR_SPEC,         "Error Spec" },
161     { RSVP_OBJ_SCOPE,              "Scope" },
162     { RSVP_OBJ_STYLE,              "Style" },
163     { RSVP_OBJ_FLOWSPEC,           "Flowspec" },
164     { RSVP_OBJ_FILTERSPEC,         "FilterSpec" },
165     { RSVP_OBJ_SENDER_TEMPLATE,    "Sender Template" },
166     { RSVP_OBJ_SENDER_TSPEC,       "Sender TSpec" },
167     { RSVP_OBJ_ADSPEC,             "Adspec" },
168     { RSVP_OBJ_POLICY_DATA,        "Policy Data" },
169     { RSVP_OBJ_CONFIRM,            "Confirm" },
170     { RSVP_OBJ_LABEL,              "Label" },
171     { RSVP_OBJ_LABEL_REQ,          "Label Request" },
172     { RSVP_OBJ_ERO,                "ERO" },
173     { RSVP_OBJ_RRO,                "RRO" },
174     { RSVP_OBJ_HELLO,              "Hello" },
175     { RSVP_OBJ_MESSAGE_ID,         "Message ID" },
176     { RSVP_OBJ_MESSAGE_ID_ACK,     "Message ID Ack" },
177     { RSVP_OBJ_MESSAGE_ID_LIST,    "Message ID List" },
178     { RSVP_OBJ_RECOVERY_LABEL,     "Recovery Label" },
179     { RSVP_OBJ_UPSTREAM_LABEL,     "Upstream Label" },
180     { RSVP_OBJ_LABEL_SET,          "Label Set" },
181     { RSVP_OBJ_ACCEPT_LABEL_SET,   "Acceptable Label Set" },
182     { RSVP_OBJ_DETOUR,             "Detour" },
183     { RSVP_OBJ_CLASSTYPE,          "Class Type" },
184     { RSVP_OBJ_SUGGESTED_LABEL,    "Suggested Label" },
185     { RSVP_OBJ_PROPERTIES,         "Properties" },
186     { RSVP_OBJ_FASTREROUTE,        "Fast Re-Route" },
187     { RSVP_OBJ_SESSION_ATTRIBUTE,  "Session Attribute" },
188     { RSVP_OBJ_CALL_ID,            "Call-ID" },
189     { RSVP_OBJ_CALL_OPS,           "Call Capability" },
190     { RSVP_OBJ_RESTART_CAPABILITY, "Restart Capability" },
191     { RSVP_OBJ_NOTIFY_REQ,         "Notify Request" },
192     { RSVP_OBJ_PROTECTION,         "Protection" },
193     { RSVP_OBJ_ADMIN_STATUS,       "Administrative Status" },
194     { 0, NULL}
195 };
196 
197 #define	RSVP_CTYPE_IPV4        1
198 #define	RSVP_CTYPE_IPV6        2
199 #define	RSVP_CTYPE_TUNNEL_IPV4 7
200 #define	RSVP_CTYPE_TUNNEL_IPV6 8
201 #define RSVP_CTYPE_1           1
202 #define RSVP_CTYPE_2           2
203 #define RSVP_CTYPE_3           3
204 #define RSVP_CTYPE_4           4
205 
206 /*
207  * the ctypes are not globally unique so for
208  * translating it to strings we build a table based
209  * on objects offsetted by the ctype
210  */
211 
212 static const struct tok rsvp_ctype_values[] = {
213     { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_IPV4,	             "IPv4" },
214     { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_IPV6,	             "IPv6" },
215     { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_3,	             "IPv4 plus opt. TLVs" },
216     { 256*RSVP_OBJ_RSVP_HOP+RSVP_CTYPE_4,	             "IPv6 plus opt. TLVs" },
217     { 256*RSVP_OBJ_NOTIFY_REQ+RSVP_CTYPE_IPV4,	             "IPv4" },
218     { 256*RSVP_OBJ_NOTIFY_REQ+RSVP_CTYPE_IPV6,	             "IPv6" },
219     { 256*RSVP_OBJ_CONFIRM+RSVP_CTYPE_IPV4,	             "IPv4" },
220     { 256*RSVP_OBJ_CONFIRM+RSVP_CTYPE_IPV6,	             "IPv6" },
221     { 256*RSVP_OBJ_TIME_VALUES+RSVP_CTYPE_1,	             "1" },
222     { 256*RSVP_OBJ_FLOWSPEC+RSVP_CTYPE_1,	             "obsolete" },
223     { 256*RSVP_OBJ_FLOWSPEC+RSVP_CTYPE_2,	             "IntServ" },
224     { 256*RSVP_OBJ_SENDER_TSPEC+RSVP_CTYPE_2,	             "IntServ" },
225     { 256*RSVP_OBJ_ADSPEC+RSVP_CTYPE_2,	                     "IntServ" },
226     { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_IPV4,	             "IPv4" },
227     { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_IPV6,	             "IPv6" },
228     { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_3,	             "IPv6 Flow-label" },
229     { 256*RSVP_OBJ_FILTERSPEC+RSVP_CTYPE_TUNNEL_IPV4,	     "Tunnel IPv4" },
230     { 256*RSVP_OBJ_SESSION+RSVP_CTYPE_IPV4,	             "IPv4" },
231     { 256*RSVP_OBJ_SESSION+RSVP_CTYPE_IPV6,	             "IPv6" },
232     { 256*RSVP_OBJ_SESSION+RSVP_CTYPE_TUNNEL_IPV4,           "Tunnel IPv4" },
233     { 256*RSVP_OBJ_SENDER_TEMPLATE+RSVP_CTYPE_IPV4,          "IPv4" },
234     { 256*RSVP_OBJ_SENDER_TEMPLATE+RSVP_CTYPE_IPV6,          "IPv6" },
235     { 256*RSVP_OBJ_SENDER_TEMPLATE+RSVP_CTYPE_TUNNEL_IPV4,   "Tunnel IPv4" },
236     { 256*RSVP_OBJ_MESSAGE_ID+RSVP_CTYPE_1,                  "1" },
237     { 256*RSVP_OBJ_MESSAGE_ID_ACK+RSVP_CTYPE_1,              "1" },
238     { 256*RSVP_OBJ_MESSAGE_ID_LIST+RSVP_CTYPE_1,             "1" },
239     { 256*RSVP_OBJ_STYLE+RSVP_CTYPE_1,                       "1" },
240     { 256*RSVP_OBJ_HELLO+RSVP_CTYPE_1,                       "Hello Request" },
241     { 256*RSVP_OBJ_HELLO+RSVP_CTYPE_2,                       "Hello Ack" },
242     { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_1,	             "without label range" },
243     { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_2,	             "with ATM label range" },
244     { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_3,                   "with FR label range" },
245     { 256*RSVP_OBJ_LABEL_REQ+RSVP_CTYPE_4,                   "Generalized Label" },
246     { 256*RSVP_OBJ_LABEL+RSVP_CTYPE_1,                       "Label" },
247     { 256*RSVP_OBJ_LABEL+RSVP_CTYPE_2,                       "Generalized Label" },
248     { 256*RSVP_OBJ_LABEL+RSVP_CTYPE_3,                       "Waveband Switching" },
249     { 256*RSVP_OBJ_SUGGESTED_LABEL+RSVP_CTYPE_1,             "Label" },
250     { 256*RSVP_OBJ_SUGGESTED_LABEL+RSVP_CTYPE_2,             "Generalized Label" },
251     { 256*RSVP_OBJ_SUGGESTED_LABEL+RSVP_CTYPE_3,             "Waveband Switching" },
252     { 256*RSVP_OBJ_UPSTREAM_LABEL+RSVP_CTYPE_1,              "Label" },
253     { 256*RSVP_OBJ_UPSTREAM_LABEL+RSVP_CTYPE_2,              "Generalized Label" },
254     { 256*RSVP_OBJ_UPSTREAM_LABEL+RSVP_CTYPE_3,              "Waveband Switching" },
255     { 256*RSVP_OBJ_RECOVERY_LABEL+RSVP_CTYPE_1,              "Label" },
256     { 256*RSVP_OBJ_RECOVERY_LABEL+RSVP_CTYPE_2,              "Generalized Label" },
257     { 256*RSVP_OBJ_RECOVERY_LABEL+RSVP_CTYPE_3,              "Waveband Switching" },
258     { 256*RSVP_OBJ_ERO+RSVP_CTYPE_IPV4,                      "IPv4" },
259     { 256*RSVP_OBJ_RRO+RSVP_CTYPE_IPV4,                      "IPv4" },
260     { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_IPV4,               "IPv4" },
261     { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_IPV6,               "IPv6" },
262     { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_3,                  "IPv4 plus opt. TLVs" },
263     { 256*RSVP_OBJ_ERROR_SPEC+RSVP_CTYPE_4,                  "IPv6 plus opt. TLVs" },
264     { 256*RSVP_OBJ_RESTART_CAPABILITY+RSVP_CTYPE_1,          "IPv4" },
265     { 256*RSVP_OBJ_SESSION_ATTRIBUTE+RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" },
266     { 256*RSVP_OBJ_FASTREROUTE+RSVP_CTYPE_TUNNEL_IPV4,       "Tunnel IPv4" },
267     { 256*RSVP_OBJ_DETOUR+RSVP_CTYPE_TUNNEL_IPV4,            "Tunnel IPv4" },
268     { 256*RSVP_OBJ_PROPERTIES+RSVP_CTYPE_1,                  "1" },
269     { 256*RSVP_OBJ_CLASSTYPE+RSVP_CTYPE_1,                   "1" },
270     { 0, NULL}
271 };
272 
273 #define RSVP_OBJ_XRO_MASK_SUBOBJ(x)   ((x)&0x7f)
274 #define RSVP_OBJ_XRO_MASK_LOOSE(x)    ((x)&0x80)
275 
276 #define	RSVP_OBJ_XRO_RES       0
277 #define	RSVP_OBJ_XRO_IPV4      1
278 #define	RSVP_OBJ_XRO_IPV6      2
279 #define	RSVP_OBJ_XRO_ASN       32
280 #define	RSVP_OBJ_XRO_MPLS      64
281 
282 static const struct tok rsvp_obj_xro_values[] = {
283     { RSVP_OBJ_XRO_RES,	      "Reserved" },
284     { RSVP_OBJ_XRO_IPV4,      "IPv4 prefix" },
285     { RSVP_OBJ_XRO_IPV6,      "IPv6 prefix" },
286     { RSVP_OBJ_XRO_ASN,       "Autonomous system number" },
287     { RSVP_OBJ_XRO_MPLS,      "MPLS label switched path termination" },
288     { 0, NULL}
289 };
290 
291 /* draft-ietf-mpls-rsvp-lsp-fastreroute-02.txt */
292 static const struct tok rsvp_obj_rro_flag_values[] = {
293     { 0x01,	              "Local protection available" },
294     { 0x02,                   "Local protection in use" },
295     { 0x04,                   "Bandwidth protection" },
296     { 0x08,                   "Node protection" },
297     { 0, NULL}
298 };
299 
300 static const struct tok rsvp_resstyle_values[] = {
301     { 17,	              "Wildcard Filter" },
302     { 10,                     "Fixed Filter" },
303     { 18,                     "Shared Explicit" },
304     { 0, NULL}
305 };
306 
307 #define RSVP_OBJ_INTSERV_GUARANTEED_SERV 2
308 #define RSVP_OBJ_INTSERV_CONTROLLED_LOAD 5
309 
310 static const struct tok rsvp_intserv_service_type_values[] = {
311     { 1,                                "Default/Global Information" },
312     { RSVP_OBJ_INTSERV_GUARANTEED_SERV, "Guaranteed Service" },
313     { RSVP_OBJ_INTSERV_CONTROLLED_LOAD,	"Controlled Load" },
314     { 0, NULL}
315 };
316 
317 static const struct tok rsvp_intserv_parameter_id_values[] = {
318     { 4,                     "IS hop cnt" },
319     { 6,                     "Path b/w estimate" },
320     { 8,                     "Minimum path latency" },
321     { 10,                    "Composed MTU" },
322     { 127,                   "Token Bucket TSpec" },
323     { 130,                   "Guaranteed Service RSpec" },
324     { 133,                   "End-to-end composed value for C" },
325     { 134,                   "End-to-end composed value for D" },
326     { 135,                   "Since-last-reshaping point composed C" },
327     { 136,                   "Since-last-reshaping point composed D" },
328     { 0, NULL}
329 };
330 
331 static struct tok rsvp_session_attribute_flag_values[] = {
332     { 0x01,	              "Local Protection desired" },
333     { 0x02,                   "Label Recording desired" },
334     { 0x04,                   "SE Style desired" },
335     { 0x08,                   "Bandwidth protection desired" }, /* draft-ietf-mpls-rsvp-lsp-fastreroute-02.txt */
336     { 0x10,                   "Node protection desired" },      /* draft-ietf-mpls-rsvp-lsp-fastreroute-02.txt */
337     { 0, NULL}
338 };
339 
340 static struct tok rsvp_obj_prop_tlv_values[] = {
341     { 0x01,                   "Cos" },
342     { 0x02,                   "Metric 1" },
343     { 0x04,                   "Metric 2" },
344     { 0x08,                   "CCC Status" },
345     { 0x10,                   "Path Type" },
346     { 0, NULL}
347 };
348 
349 #define RSVP_OBJ_ERROR_SPEC_CODE_ROUTING 24
350 #define RSVP_OBJ_ERROR_SPEC_CODE_NOTIFY  25
351 #define RSVP_OBJ_ERROR_SPEC_CODE_DIFFSERV_TE 125
352 
353 static struct tok rsvp_obj_error_code_values[] = {
354     { RSVP_OBJ_ERROR_SPEC_CODE_ROUTING, "Routing Problem" },
355     { RSVP_OBJ_ERROR_SPEC_CODE_NOTIFY,  "Notify Error" },
356     { RSVP_OBJ_ERROR_SPEC_CODE_DIFFSERV_TE, "Diffserv TE Error" },
357     { 0, NULL}
358 };
359 
360 static struct tok rsvp_obj_error_code_routing_values[] = {
361     { 1,                      "Bad EXPLICIT_ROUTE object" },
362     { 2,                      "Bad strict node" },
363     { 3,                      "Bad loose node" },
364     { 4,                      "Bad initial subobject" },
365     { 5,                      "No route available toward destination" },
366     { 6,                      "Unacceptable label value" },
367     { 7,                      "RRO indicated routing loops" },
368     { 8,                      "non-RSVP-capable router in the path" },
369     { 9,                      "MPLS label allocation failure" },
370     { 10,                     "Unsupported L3PID" },
371     { 0, NULL}
372 };
373 
374 static struct tok rsvp_obj_error_code_diffserv_te_values[] = {
375     { 1,                      "Unexpected CLASSTYPE object" },
376     { 2,                      "Unsupported Class-Type" },
377     { 3,                      "Invalid Class-Type value" },
378     { 4,                      "Class-Type and setup priority do not form a configured TE-Class" },
379     { 5,                      "Class-Type and holding priority do not form a configured TE-Class" },
380     { 6,                      "Inconsistency between signaled PSC and signaled Class-Type" },
381     { 7,                      "Inconsistency between signaled PHBs and signaled Class-Type" },
382     { 0, NULL}
383 };
384 
385 #define FALSE 0
386 #define TRUE  1
387 
388 
389 static int rsvp_intserv_print(const u_char *, u_short);
390 
391 /*
392  * this is a dissector for all the intserv defined
393  * specs as defined per rfc2215
394  * it is called from various rsvp objects;
395  * returns the amount of bytes being processed
396  */
397 static int
398 rsvp_intserv_print(const u_char *tptr, u_short obj_tlen) {
399 
400     int parameter_id,parameter_length;
401     union {
402 	float f;
403 	u_int32_t i;
404     } bw;
405 
406     if (obj_tlen < 4)
407         return 0;
408     parameter_id = *(tptr);
409     parameter_length = EXTRACT_16BITS(tptr+2)<<2; /* convert wordcount to bytecount */
410 
411     printf("\n\t      Parameter ID: %s (%u), length: %u, Flags: [0x%02x]",
412            tok2str(rsvp_intserv_parameter_id_values,"unknown",parameter_id),
413            parameter_id,
414            parameter_length,
415            *(tptr+1));
416 
417     if (obj_tlen < parameter_length+4)
418         return 0;
419     switch(parameter_id) { /* parameter_id */
420 
421     case 4:
422        /*
423         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
424         * |    4 (e)      |    (f)        |           1 (g)               |
425         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
426         * |        IS hop cnt (32-bit unsigned integer)                   |
427         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
428         */
429         if (parameter_length == 4)
430             printf("\n\t\tIS hop count: %u", EXTRACT_32BITS(tptr+4));
431         break;
432 
433     case 6:
434        /*
435         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
436         * |    6 (h)      |    (i)        |           1 (j)               |
437         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
438         * |  Path b/w estimate  (32-bit IEEE floating point number)       |
439         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
440         */
441         if (parameter_length == 4) {
442             bw.i = EXTRACT_32BITS(tptr+4);
443             printf("\n\t\tPath b/w estimate: %.10g Mbps", bw.f/125000);
444         }
445         break;
446 
447     case 8:
448        /*
449         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
450         * |     8 (k)     |    (l)        |           1 (m)               |
451         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
452         * |        Minimum path latency (32-bit integer)                  |
453         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
454         */
455         if (parameter_length == 4) {
456             printf("\n\t\tMinimum path latency: ");
457             if (EXTRACT_32BITS(tptr+4) == 0xffffffff)
458                 printf("don't care");
459             else
460                 printf("%u", EXTRACT_32BITS(tptr+4));
461         }
462         break;
463 
464     case 10:
465 
466        /*
467         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
468         * |     10 (n)    |      (o)      |           1 (p)               |
469         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
470         * |      Composed MTU (32-bit unsigned integer)                   |
471         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
472         */
473         if (parameter_length == 4)
474             printf("\n\t\tComposed MTU: %u bytes", EXTRACT_32BITS(tptr+4));
475         break;
476     case 127:
477        /*
478         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
479         * |   127 (e)     |    0 (f)      |             5 (g)             |
480         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
481         * |  Token Bucket Rate [r] (32-bit IEEE floating point number)    |
482         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
483         * |  Token Bucket Size [b] (32-bit IEEE floating point number)    |
484         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
485         * |  Peak Data Rate [p] (32-bit IEEE floating point number)       |
486         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
487         * |  Minimum Policed Unit [m] (32-bit integer)                    |
488         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
489         * |  Maximum Packet Size [M]  (32-bit integer)                    |
490         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
491         */
492 
493         if (parameter_length == 20) {
494             bw.i = EXTRACT_32BITS(tptr+4);
495             printf("\n\t\tToken Bucket Rate: %.10g Mbps", bw.f/125000);
496             bw.i = EXTRACT_32BITS(tptr+8);
497             printf("\n\t\tToken Bucket Size: %.10g bytes", bw.f);
498             bw.i = EXTRACT_32BITS(tptr+12);
499             printf("\n\t\tPeak Data Rate: %.10g Mbps", bw.f/125000);
500             printf("\n\t\tMinimum Policed Unit: %u bytes", EXTRACT_32BITS(tptr+16));
501             printf("\n\t\tMaximum Packet Size: %u bytes", EXTRACT_32BITS(tptr+20));
502         }
503         break;
504 
505     case 130:
506        /*
507         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
508         * |     130 (h)   |    0 (i)      |            2 (j)              |
509         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510         * |  Rate [R]  (32-bit IEEE floating point number)                |
511         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512         * |  Slack Term [S]  (32-bit integer)                             |
513         * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
514         */
515 
516         if (parameter_length == 8) {
517             bw.i = EXTRACT_32BITS(tptr+4);
518             printf("\n\t\tRate: %.10g Mbps", bw.f/125000);
519             printf("\n\t\tSlack Term: %u", EXTRACT_32BITS(tptr+8));
520         }
521         break;
522 
523     case 133:
524     case 134:
525     case 135:
526     case 136:
527         if (parameter_length == 4)
528             printf("\n\t\tValue: %u", EXTRACT_32BITS(tptr+4));
529         break;
530 
531     default:
532         if (vflag <= 1)
533             print_unknown_data(tptr+4,"\n\t\t",parameter_length);
534     }
535     return (parameter_length+4); /* header length 4 bytes */
536 }
537 
538 static int
539 rsvp_obj_print (const u_char *tptr, const char *ident, u_int tlen) {
540 
541     const struct rsvp_object_header *rsvp_obj_header;
542     const u_char *obj_tptr;
543     u_short rsvp_obj_len,rsvp_obj_ctype,obj_tlen,intserv_serv_tlen;
544     int hexdump,processed,padbytes,error_code,error_value,i;
545     union {
546 	float f;
547 	u_int32_t i;
548     } bw;
549     u_int8_t namelen;
550 
551     while(tlen>=sizeof(struct rsvp_object_header)) {
552         /* did we capture enough for fully decoding the object header ? */
553         if (!TTEST2(*tptr, sizeof(struct rsvp_object_header)))
554             goto trunc;
555 
556         rsvp_obj_header = (const struct rsvp_object_header *)tptr;
557         rsvp_obj_len=EXTRACT_16BITS(rsvp_obj_header->length);
558         rsvp_obj_ctype=rsvp_obj_header->ctype;
559 
560         if(rsvp_obj_len % 4) {
561             printf("%sERROR: object header size %u not a multiple of 4", ident, rsvp_obj_len);
562             return -1;
563         }
564         if(rsvp_obj_len < sizeof(struct rsvp_object_header)) {
565             printf("%sERROR: object header too short %u < %lu", ident, rsvp_obj_len,
566                    (unsigned long)sizeof(const struct rsvp_object_header));
567             return -1;
568         }
569 
570         printf("%s%s Object (%u) Flags: [%s",
571                ident,
572                tok2str(rsvp_obj_values,
573                        "Unknown",
574                        rsvp_obj_header->class_num),
575                rsvp_obj_header->class_num,
576                ((rsvp_obj_header->class_num)&0x80) ? "ignore" : "reject");
577 
578         if (rsvp_obj_header->class_num > 128)
579             printf(" %s",
580                    ((rsvp_obj_header->class_num)&0x40) ? "and forward" : "silently");
581 
582         printf(" if unknown], Class-Type: %s (%u), length: %u",
583                tok2str(rsvp_ctype_values,
584                        "Unknown",
585                        ((rsvp_obj_header->class_num)<<8)+rsvp_obj_ctype),
586                rsvp_obj_ctype,
587                rsvp_obj_len);
588 
589         if(tlen < rsvp_obj_len) {
590             printf("%sERROR: object goes past end of objects TLV", ident);
591             return -1;
592         }
593 
594         obj_tptr=tptr+sizeof(struct rsvp_object_header);
595         obj_tlen=rsvp_obj_len-sizeof(struct rsvp_object_header);
596 
597         /* did we capture enough for fully decoding the object ? */
598         if (!TTEST2(*tptr, rsvp_obj_len))
599             return -1;
600         hexdump=FALSE;
601 
602         switch(rsvp_obj_header->class_num) {
603         case RSVP_OBJ_SESSION:
604             switch(rsvp_obj_ctype) {
605             case RSVP_CTYPE_IPV4:
606                 if (obj_tlen < 8)
607                     return -1;
608                 printf("%s  IPv4 DestAddress: %s, Protocol ID: 0x%02x",
609                        ident,
610                        ipaddr_string(obj_tptr),
611                        *(obj_tptr+4));
612                 printf("%s  Flags: [0x%02x], DestPort %u",
613                        ident,
614                        *(obj_tptr+5),
615                        EXTRACT_16BITS(obj_tptr+6));
616                 obj_tlen-=8;
617                 obj_tptr+=8;
618                 break;
619 #ifdef INET6
620             case RSVP_CTYPE_IPV6:
621                 if (obj_tlen < 20)
622                     return -1;
623                 printf("%s  IPv6 DestAddress: %s, Protocol ID: 0x%02x",
624                        ident,
625                        ip6addr_string(obj_tptr),
626                        *(obj_tptr+16));
627                 printf("%s  Flags: [0x%02x], DestPort %u",
628                        ident,
629                        *(obj_tptr+17),
630                        EXTRACT_16BITS(obj_tptr+18));
631                 obj_tlen-=20;
632                 obj_tptr+=20;
633                 break;
634 
635             case RSVP_CTYPE_TUNNEL_IPV6:
636                 if (obj_tlen < 36)
637                     return -1;
638                 printf("%s  IPv6 Tunnel EndPoint: %s, Tunnel ID: 0x%04x, Extended Tunnel ID: %s",
639                        ident,
640                        ip6addr_string(obj_tptr),
641                        EXTRACT_16BITS(obj_tptr+18),
642                        ip6addr_string(obj_tptr+20));
643                 obj_tlen-=36;
644                 obj_tptr+=36;
645                 break;
646 #endif
647             case RSVP_CTYPE_TUNNEL_IPV4:
648                 if (obj_tlen < 12)
649                     return -1;
650                 printf("%s  IPv4 Tunnel EndPoint: %s, Tunnel ID: 0x%04x, Extended Tunnel ID: %s",
651                        ident,
652                        ipaddr_string(obj_tptr),
653                        EXTRACT_16BITS(obj_tptr+6),
654                        ipaddr_string(obj_tptr+8));
655                 obj_tlen-=12;
656                 obj_tptr+=12;
657                 break;
658             default:
659                 hexdump=TRUE;
660             }
661             break;
662 
663         case RSVP_OBJ_CONFIRM:
664             switch(rsvp_obj_ctype) {
665             case RSVP_CTYPE_IPV4:
666                 if (obj_tlen < 4)
667                     return -1;
668                 printf("%s  IPv4 Receiver Address: %s",
669                        ident,
670                        ipaddr_string(obj_tptr));
671                 obj_tlen-=4;
672                 obj_tptr+=4;
673                 break;
674 #ifdef INET6
675             case RSVP_CTYPE_IPV6:
676                 if (obj_tlen < 16)
677                     return -1;
678                 printf("%s  IPv6 Receiver Address: %s",
679                        ident,
680                        ip6addr_string(obj_tptr));
681                 obj_tlen-=16;
682                 obj_tptr+=16;
683                 break;
684 #endif
685             default:
686                 hexdump=TRUE;
687             }
688             break;
689 
690         case RSVP_OBJ_NOTIFY_REQ:
691             switch(rsvp_obj_ctype) {
692             case RSVP_CTYPE_IPV4:
693                 if (obj_tlen < 4)
694                     return -1;
695                 printf("%s  IPv4 Notify Node Address: %s",
696                        ident,
697                        ipaddr_string(obj_tptr));
698                 obj_tlen-=4;
699                 obj_tptr+=4;
700                 break;
701 #ifdef INET6
702             case RSVP_CTYPE_IPV6:
703                 if (obj_tlen < 16)
704                     return-1;
705                 printf("%s  IPv6 Notify Node Address: %s",
706                        ident,
707                        ip6addr_string(obj_tptr));
708                 obj_tlen-=16;
709                 obj_tptr+=16;
710                 break;
711 #endif
712             default:
713                 hexdump=TRUE;
714             }
715             break;
716 
717         case RSVP_OBJ_SUGGESTED_LABEL: /* fall through */
718         case RSVP_OBJ_UPSTREAM_LABEL:  /* fall through */
719         case RSVP_OBJ_RECOVERY_LABEL:  /* fall through */
720         case RSVP_OBJ_LABEL:
721             switch(rsvp_obj_ctype) {
722             case RSVP_CTYPE_1:
723                 while(obj_tlen >= 4 ) {
724                     printf("%s  Label: %u", ident, EXTRACT_32BITS(obj_tptr));
725                     obj_tlen-=4;
726                     obj_tptr+=4;
727                 }
728                 break;
729             case RSVP_CTYPE_2:
730                 if (obj_tlen < 4)
731                     return-1;
732                 printf("%s  Generalized Label: %u",
733                        ident,
734                        EXTRACT_32BITS(obj_tptr));
735                 obj_tlen-=4;
736                 obj_tptr+=4;
737                 break;
738             case RSVP_CTYPE_3:
739                 if (obj_tlen < 12)
740                     return-1;
741                 printf("%s  Waveband ID: %u%s  Start Label: %u, Stop Label: %u",
742                        ident,
743                        EXTRACT_32BITS(obj_tptr),
744                        ident,
745                        EXTRACT_32BITS(obj_tptr+4),
746                        EXTRACT_32BITS(obj_tptr+8));
747                 obj_tlen-=12;
748                 obj_tptr+=12;
749                 break;
750             default:
751                 hexdump=TRUE;
752             }
753             break;
754 
755         case RSVP_OBJ_STYLE:
756             switch(rsvp_obj_ctype) {
757             case RSVP_CTYPE_1:
758                 if (obj_tlen < 4)
759                     return-1;
760                 printf("%s  Reservation Style: %s, Flags: [0x%02x]",
761                        ident,
762                        tok2str(rsvp_resstyle_values,
763                                "Unknown",
764                                EXTRACT_24BITS(obj_tptr+1)),
765                        *(obj_tptr));
766                 obj_tlen-=4;
767                 obj_tptr+=4;
768                 break;
769             default:
770                 hexdump=TRUE;
771             }
772             break;
773 
774         case RSVP_OBJ_SENDER_TEMPLATE:
775             switch(rsvp_obj_ctype) {
776             case RSVP_CTYPE_IPV4:
777                 if (obj_tlen < 8)
778                     return-1;
779                 printf("%s  Source Address: %s, Source Port: %u",
780                        ident,
781                        ipaddr_string(obj_tptr),
782                        EXTRACT_16BITS(obj_tptr+6));
783                 obj_tlen-=8;
784                 obj_tptr+=8;
785                 break;
786 #ifdef INET6
787             case RSVP_CTYPE_IPV6:
788                 if (obj_tlen < 20)
789                     return-1;
790                 printf("%s  Source Address: %s, Source Port: %u",
791                        ident,
792                        ip6addr_string(obj_tptr),
793                        EXTRACT_16BITS(obj_tptr+18));
794                 obj_tlen-=20;
795                 obj_tptr+=20;
796                 break;
797 #endif
798             case RSVP_CTYPE_TUNNEL_IPV4:
799                 if (obj_tlen < 8)
800                     return-1;
801                 printf("%s  IPv4 Tunnel Sender Address: %s, LSP-ID: 0x%04x",
802                        ident,
803                        ipaddr_string(obj_tptr),
804                        EXTRACT_16BITS(obj_tptr+6));
805                 obj_tlen-=8;
806                 obj_tptr+=8;
807                 break;
808             default:
809                 hexdump=TRUE;
810             }
811             break;
812 
813         case RSVP_OBJ_LABEL_REQ:
814             switch(rsvp_obj_ctype) {
815             case RSVP_CTYPE_1:
816                 while(obj_tlen >= 4 ) {
817                     printf("%s  L3 Protocol ID: %s",
818                            ident,
819                            tok2str(ethertype_values,
820                                    "Unknown Protocol (0x%04x)",
821                                    EXTRACT_16BITS(obj_tptr+2)));
822                     obj_tlen-=4;
823                     obj_tptr+=4;
824                 }
825                 break;
826             case RSVP_CTYPE_2:
827                 if (obj_tlen < 12)
828                     return-1;
829                 printf("%s  L3 Protocol ID: %s",
830                        ident,
831                        tok2str(ethertype_values,
832                                "Unknown Protocol (0x%04x)",
833                                EXTRACT_16BITS(obj_tptr+2)));
834                 printf(",%s merge capability",((*(obj_tptr+4))&0x80) ? "no" : "" );
835                 printf("%s  Minimum VPI/VCI: %u/%u",
836                        ident,
837                        (EXTRACT_16BITS(obj_tptr+4))&0xfff,
838                        (EXTRACT_16BITS(obj_tptr+6))&0xfff);
839                 printf("%s  Maximum VPI/VCI: %u/%u",
840                        ident,
841                        (EXTRACT_16BITS(obj_tptr+8))&0xfff,
842                        (EXTRACT_16BITS(obj_tptr+10))&0xfff);
843                 obj_tlen-=12;
844                 obj_tptr+=12;
845                 break;
846             case RSVP_CTYPE_3:
847                 if (obj_tlen < 12)
848                     return-1;
849                 printf("%s  L3 Protocol ID: %s",
850                        ident,
851                        tok2str(ethertype_values,
852                                "Unknown Protocol (0x%04x)",
853                                EXTRACT_16BITS(obj_tptr+2)));
854                 printf("%s  Minimum/Maximum DLCI: %u/%u, %s%s bit DLCI",
855                        ident,
856                        (EXTRACT_32BITS(obj_tptr+4))&0x7fffff,
857                        (EXTRACT_32BITS(obj_tptr+8))&0x7fffff,
858                        (((EXTRACT_16BITS(obj_tptr+4)>>7)&3) == 0 ) ? "10" : "",
859                        (((EXTRACT_16BITS(obj_tptr+4)>>7)&3) == 2 ) ? "23" : "");
860                 obj_tlen-=12;
861                 obj_tptr+=12;
862                 break;
863             case RSVP_CTYPE_4:
864                 if (obj_tlen < 8)
865                     return-1;
866                 printf("%s  LSP Encoding Type: %s (%u)",
867                        ident,
868                        tok2str(gmpls_encoding_values,
869                                "Unknown",
870                                *obj_tptr),
871 		       *obj_tptr);
872                 printf("%s  Switching Type: %s (%u), Payload ID: %s (0x%04x)",
873                        ident,
874                        tok2str(gmpls_switch_cap_values,
875                                "Unknown",
876                                *(obj_tptr+1)),
877 		       *(obj_tptr+1),
878                        tok2str(gmpls_payload_values,
879                                "Unknown",
880                                EXTRACT_16BITS(obj_tptr+2)),
881 		       EXTRACT_16BITS(obj_tptr+2));
882                 obj_tlen-=8;
883                 obj_tptr+=8;
884                 break;
885             default:
886                 hexdump=TRUE;
887             }
888             break;
889 
890         case RSVP_OBJ_RRO:
891         case RSVP_OBJ_ERO:
892             switch(rsvp_obj_ctype) {
893             case RSVP_CTYPE_IPV4:
894                 while(obj_tlen >= 4 ) {
895                     printf("%s  Subobject Type: %s, length %u",
896                            ident,
897                            tok2str(rsvp_obj_xro_values,
898                                    "Unknown %u",
899                                    RSVP_OBJ_XRO_MASK_SUBOBJ(*obj_tptr)),
900                            *(obj_tptr+1));
901 
902                     if (*(obj_tptr+1) == 0) { /* prevent infinite loops */
903                         printf("%s  ERROR: zero length ERO subtype",ident);
904                         break;
905                     }
906 
907                     switch(RSVP_OBJ_XRO_MASK_SUBOBJ(*obj_tptr)) {
908                     case RSVP_OBJ_XRO_IPV4:
909                         printf(", %s, %s/%u, Flags: [%s]",
910                                RSVP_OBJ_XRO_MASK_LOOSE(*obj_tptr) ? "Loose" : "Strict",
911                                ipaddr_string(obj_tptr+2),
912                                *(obj_tptr+6),
913                                bittok2str(rsvp_obj_rro_flag_values,
914                                    "none",
915                                    *(obj_tptr+7))); /* rfc3209 says that this field is rsvd. */
916                     }
917                     obj_tlen-=*(obj_tptr+1);
918                     obj_tptr+=*(obj_tptr+1);
919                 }
920                 break;
921             default:
922                 hexdump=TRUE;
923             }
924             break;
925 
926         case RSVP_OBJ_HELLO:
927             switch(rsvp_obj_ctype) {
928             case RSVP_CTYPE_1:
929             case RSVP_CTYPE_2:
930                 if (obj_tlen < 8)
931                     return-1;
932                 printf("%s  Source Instance: 0x%08x, Destination Instance: 0x%08x",
933                        ident,
934                        EXTRACT_32BITS(obj_tptr),
935                        EXTRACT_32BITS(obj_tptr+4));
936                 obj_tlen-=8;
937                 obj_tptr+=8;
938                 break;
939             default:
940                 hexdump=TRUE;
941             }
942             break;
943 
944         case RSVP_OBJ_RESTART_CAPABILITY:
945             switch(rsvp_obj_ctype) {
946             case RSVP_CTYPE_1:
947                 if (obj_tlen < 8)
948                     return-1;
949                 printf("%s  Restart  Time: %ums, Recovery Time: %ums",
950                        ident,
951                        EXTRACT_32BITS(obj_tptr),
952                        EXTRACT_32BITS(obj_tptr+4));
953                 obj_tlen-=8;
954                 obj_tptr+=8;
955                 break;
956             default:
957                 hexdump=TRUE;
958             }
959             break;
960 
961         case RSVP_OBJ_SESSION_ATTRIBUTE:
962             switch(rsvp_obj_ctype) {
963             case RSVP_CTYPE_TUNNEL_IPV4:
964                 if (obj_tlen < 4)
965                     return-1;
966                 namelen = *(obj_tptr+3);
967                 if (obj_tlen < 4+namelen)
968                     return-1;
969                 printf("%s  Session Name: ", ident);
970                 for (i = 0; i < namelen; i++)
971                     safeputchar(*(obj_tptr+4+i));
972                 printf("%s  Setup Priority: %u, Holding Priority: %u, Flags: [%s]",
973                        ident,
974                        (int)*obj_tptr,
975                        (int)*(obj_tptr+1),
976                        tok2str(rsvp_session_attribute_flag_values,
977                                   "none",
978                                   *(obj_tptr+2)));
979 
980                 obj_tlen-=4+*(obj_tptr+3);
981                 obj_tptr+=4+*(obj_tptr+3);
982                 break;
983             default:
984                 hexdump=TRUE;
985             }
986             break;
987 
988         case RSVP_OBJ_RSVP_HOP:
989             switch(rsvp_obj_ctype) {
990             case RSVP_CTYPE_3: /* fall through - FIXME add TLV parser */
991             case RSVP_CTYPE_IPV4:
992                 if (obj_tlen < 8)
993                     return-1;
994                 printf("%s  Previous/Next Interface: %s, Logical Interface Handle: 0x%08x",
995                        ident,
996                        ipaddr_string(obj_tptr),
997                        EXTRACT_32BITS(obj_tptr+4));
998                 obj_tlen-=8;
999                 obj_tptr+=8;
1000                 hexdump=TRUE; /* unless we have a TLV parser lets just hexdump */
1001                 break;
1002 #ifdef INET6
1003             case RSVP_CTYPE_4: /* fall through - FIXME add TLV parser */
1004             case RSVP_CTYPE_IPV6:
1005                 if (obj_tlen < 20)
1006                     return-1;
1007                 printf("%s  Previous/Next Interface: %s, Logical Interface Handle: 0x%08x",
1008                        ident,
1009                        ip6addr_string(obj_tptr),
1010                        EXTRACT_32BITS(obj_tptr+16));
1011                 obj_tlen-=20;
1012                 obj_tptr+=20;
1013                 hexdump=TRUE; /* unless we have a TLV parser lets just hexdump */
1014                 break;
1015 #endif
1016             default:
1017                 hexdump=TRUE;
1018             }
1019             break;
1020 
1021         case RSVP_OBJ_TIME_VALUES:
1022             switch(rsvp_obj_ctype) {
1023             case RSVP_CTYPE_1:
1024                 if (obj_tlen < 4)
1025                     return-1;
1026                 printf("%s  Refresh Period: %ums",
1027                        ident,
1028                        EXTRACT_32BITS(obj_tptr));
1029                 obj_tlen-=4;
1030                 obj_tptr+=4;
1031                 break;
1032             default:
1033                 hexdump=TRUE;
1034             }
1035             break;
1036 
1037         /* those three objects do share the same semantics */
1038         case RSVP_OBJ_SENDER_TSPEC:
1039         case RSVP_OBJ_ADSPEC:
1040         case RSVP_OBJ_FLOWSPEC:
1041             switch(rsvp_obj_ctype) {
1042             case RSVP_CTYPE_2:
1043                 if (obj_tlen < 4)
1044                     return-1;
1045                 printf("%s  Msg-Version: %u, length: %u",
1046                        ident,
1047                        (*obj_tptr & 0xf0) >> 4,
1048                        EXTRACT_16BITS(obj_tptr+2)<<2);
1049                 obj_tptr+=4; /* get to the start of the service header */
1050                 obj_tlen-=4;
1051 
1052                 while (obj_tlen >= 4) {
1053                     intserv_serv_tlen=EXTRACT_16BITS(obj_tptr+2)<<2;
1054                     printf("%s  Service Type: %s (%u), break bit %s set, Service length: %u",
1055                            ident,
1056                            tok2str(rsvp_intserv_service_type_values,"unknown",*(obj_tptr)),
1057                            *(obj_tptr),
1058                            (*(obj_tptr+1)&0x80) ? "" : "not",
1059                            intserv_serv_tlen);
1060 
1061                     obj_tptr+=4; /* get to the start of the parameter list */
1062                     obj_tlen-=4;
1063 
1064                     while (intserv_serv_tlen>=4) {
1065                         processed = rsvp_intserv_print(obj_tptr, obj_tlen);
1066                         if (processed == 0)
1067                             break;
1068                         obj_tlen-=processed;
1069                         intserv_serv_tlen-=processed;
1070                         obj_tptr+=processed;
1071                     }
1072                 }
1073                 break;
1074             default:
1075                 hexdump=TRUE;
1076             }
1077             break;
1078 
1079         case RSVP_OBJ_FILTERSPEC:
1080             switch(rsvp_obj_ctype) {
1081             case RSVP_CTYPE_IPV4:
1082                 if (obj_tlen < 8)
1083                     return-1;
1084                 printf("%s  Source Address: %s, Source Port: %u",
1085                        ident,
1086                        ipaddr_string(obj_tptr),
1087                        EXTRACT_16BITS(obj_tptr+6));
1088                 obj_tlen-=8;
1089                 obj_tptr+=8;
1090                 break;
1091 #ifdef INET6
1092             case RSVP_CTYPE_IPV6:
1093                 if (obj_tlen < 20)
1094                     return-1;
1095                 printf("%s  Source Address: %s, Source Port: %u",
1096                        ident,
1097                        ip6addr_string(obj_tptr),
1098                        EXTRACT_16BITS(obj_tptr+18));
1099                 obj_tlen-=20;
1100                 obj_tptr+=20;
1101                 break;
1102             case RSVP_CTYPE_3:
1103                 if (obj_tlen < 20)
1104                     return-1;
1105                 printf("%s  Source Address: %s, Flow Label: %u",
1106                        ident,
1107                        ip6addr_string(obj_tptr),
1108                        EXTRACT_24BITS(obj_tptr+17));
1109                 obj_tlen-=20;
1110                 obj_tptr+=20;
1111                 break;
1112             case RSVP_CTYPE_TUNNEL_IPV6:
1113                 if (obj_tlen < 20)
1114                     return-1;
1115                 printf("%s  Source Address: %s, LSP-ID: 0x%04x",
1116                        ident,
1117                        ipaddr_string(obj_tptr),
1118                        EXTRACT_16BITS(obj_tptr+18));
1119                 obj_tlen-=20;
1120                 obj_tptr+=20;
1121                 break;
1122 #endif
1123             case RSVP_CTYPE_TUNNEL_IPV4:
1124                 if (obj_tlen < 8)
1125                     return-1;
1126                 printf("%s  Source Address: %s, LSP-ID: 0x%04x",
1127                        ident,
1128                        ipaddr_string(obj_tptr),
1129                        EXTRACT_16BITS(obj_tptr+6));
1130                 obj_tlen-=8;
1131                 obj_tptr+=8;
1132                 break;
1133             default:
1134                 hexdump=TRUE;
1135             }
1136             break;
1137 
1138         case RSVP_OBJ_FASTREROUTE:
1139             switch(rsvp_obj_ctype) {
1140             case RSVP_CTYPE_TUNNEL_IPV4:
1141                 if (obj_tlen < 16)
1142                     return-1;
1143                 bw.i = EXTRACT_32BITS(obj_tptr+4);
1144                 printf("%s  Setup Priority: %u, Holding Priority: %u, Hop-limit: %u, Bandwidth: %.10g Mbps",
1145                        ident,
1146                        (int)*obj_tptr,
1147                        (int)*(obj_tptr+1),
1148                        (int)*(obj_tptr+2),
1149                         bw.f*8/1000000);
1150                 printf("%s  Include Colors: 0x%08x, Exclude Colors: 0x%08x",
1151                        ident,
1152                        EXTRACT_32BITS(obj_tptr+8),
1153                        EXTRACT_32BITS(obj_tptr+12));
1154                 obj_tlen-=16;
1155                 obj_tptr+=16;
1156                 break;
1157             default:
1158                 hexdump=TRUE;
1159             }
1160             break;
1161 
1162         case RSVP_OBJ_DETOUR:
1163             switch(rsvp_obj_ctype) {
1164             case RSVP_CTYPE_TUNNEL_IPV4:
1165                 while(obj_tlen >= 8) {
1166                     printf("%s  PLR-ID: %s, Avoid-Node-ID: %s",
1167                            ident,
1168                            ipaddr_string(obj_tptr),
1169                            ipaddr_string(obj_tptr+4));
1170                     obj_tlen-=8;
1171                     obj_tptr+=8;
1172                 }
1173                 break;
1174             default:
1175                 hexdump=TRUE;
1176             }
1177             break;
1178 
1179         case RSVP_OBJ_CLASSTYPE:
1180             switch(rsvp_obj_ctype) {
1181             case RSVP_CTYPE_1:
1182                 printf("%s  Class Type: %u",
1183                        ident,
1184                        EXTRACT_32BITS(obj_tptr)&0x7);
1185                 obj_tlen-=4;
1186                 obj_tptr+=4;
1187                 break;
1188             default:
1189                 hexdump=TRUE;
1190             }
1191             break;
1192 
1193         case RSVP_OBJ_ERROR_SPEC:
1194             switch(rsvp_obj_ctype) {
1195             case RSVP_CTYPE_3: /* fall through - FIXME add TLV parser */
1196             case RSVP_CTYPE_IPV4:
1197                 if (obj_tlen < 8)
1198                     return-1;
1199                 error_code=*(obj_tptr+5);
1200                 error_value=EXTRACT_16BITS(obj_tptr+6);
1201                 printf("%s  Error Node Address: %s, Flags: [0x%02x]%s  Error Code: %s (%u)",
1202                        ident,
1203                        ipaddr_string(obj_tptr),
1204                        *(obj_tptr+4),
1205                        ident,
1206                        tok2str(rsvp_obj_error_code_values,"unknown",error_code),
1207                        error_code);
1208                 switch (error_code) {
1209                 case RSVP_OBJ_ERROR_SPEC_CODE_ROUTING:
1210                     printf(", Error Value: %s (%u)",
1211                            tok2str(rsvp_obj_error_code_routing_values,"unknown",error_value),
1212                            error_value);
1213                     break;
1214                 case RSVP_OBJ_ERROR_SPEC_CODE_DIFFSERV_TE:
1215                     printf(", Error Value: %s (%u)",
1216                            tok2str(rsvp_obj_error_code_diffserv_te_values,"unknown",error_value),
1217                            error_value);
1218                     break;
1219                 default:
1220                     printf(", Unknown Error Value (%u)", error_value);
1221                     break;
1222                 }
1223                 obj_tlen-=8;
1224                 obj_tptr+=8;
1225                 break;
1226 #ifdef INET6
1227             case RSVP_CTYPE_4: /* fall through - FIXME add TLV parser */
1228             case RSVP_CTYPE_IPV6:
1229                 if (obj_tlen < 20)
1230                     return-1;
1231                 error_code=*(obj_tptr+17);
1232                 error_value=EXTRACT_16BITS(obj_tptr+18);
1233                 printf("%s  Error Node Address: %s, Flags: [0x%02x]%s  Error Code: %s (%u)",
1234                        ident,
1235                        ip6addr_string(obj_tptr),
1236                        *(obj_tptr+16),
1237                        ident,
1238                        tok2str(rsvp_obj_error_code_values,"unknown",error_code),
1239                        error_code);
1240 
1241                 switch (error_code) {
1242                 case RSVP_OBJ_ERROR_SPEC_CODE_ROUTING:
1243                     printf(", Error Value: %s (%u)",
1244                            tok2str(rsvp_obj_error_code_routing_values,"unknown",error_value),
1245 			   error_value);
1246                     break;
1247                 default:
1248                     break;
1249                 }
1250                 obj_tlen-=20;
1251                 obj_tptr+=20;
1252                 break;
1253 #endif
1254             default:
1255                 hexdump=TRUE;
1256             }
1257             break;
1258 
1259         case RSVP_OBJ_PROPERTIES:
1260             switch(rsvp_obj_ctype) {
1261             case RSVP_CTYPE_1:
1262                 if (obj_tlen < 4)
1263                     return-1;
1264                 padbytes = EXTRACT_16BITS(obj_tptr+2);
1265                 printf("%s  TLV count: %u, padding bytes: %u",
1266                        ident,
1267                        EXTRACT_16BITS(obj_tptr),
1268                        padbytes);
1269                 obj_tlen-=4;
1270                 obj_tptr+=4;
1271                 /* loop through as long there is anything longer than the TLV header (2) */
1272                 while(obj_tlen >= 2 + padbytes) {
1273                     printf("%s    %s TLV (0x%02x), length: %u", /* length includes header */
1274                            ident,
1275                            tok2str(rsvp_obj_prop_tlv_values,"unknown",*obj_tptr),
1276                            *obj_tptr,
1277                            *(obj_tptr+1));
1278                     if (obj_tlen < *(obj_tptr+1))
1279                         return-1;
1280                     if (*(obj_tptr+1) < 2)
1281                         return -1;
1282                     print_unknown_data(obj_tptr+2,"\n\t\t",*(obj_tptr+1)-2);
1283                     obj_tlen-=*(obj_tptr+1);
1284                     obj_tptr+=*(obj_tptr+1);
1285                 }
1286                 break;
1287             default:
1288                 hexdump=TRUE;
1289             }
1290             break;
1291 
1292         case RSVP_OBJ_MESSAGE_ID:     /* fall through */
1293         case RSVP_OBJ_MESSAGE_ID_ACK: /* fall through */
1294         case RSVP_OBJ_MESSAGE_ID_LIST:
1295             switch(rsvp_obj_ctype) {
1296             case RSVP_CTYPE_1:
1297                 if (obj_tlen < 8)
1298                     return-1;
1299                 printf("%s  Flags [0x%02x], epoch: %u",
1300                        ident,
1301                        *obj_tptr,
1302                        EXTRACT_24BITS(obj_tptr+1));
1303                 obj_tlen-=4;
1304                 obj_tptr+=4;
1305                 /* loop through as long there are no messages left */
1306                 while(obj_tlen >= 4) {
1307                     printf("%s    Message-ID 0x%08x (%u)",
1308                            ident,
1309                            EXTRACT_32BITS(obj_tptr),
1310                            EXTRACT_32BITS(obj_tptr));
1311                     obj_tlen-=4;
1312                     obj_tptr+=4;
1313                 }
1314                 break;
1315             default:
1316                 hexdump=TRUE;
1317             }
1318             break;
1319 
1320         /*
1321          *  FIXME those are the defined objects that lack a decoder
1322          *  you are welcome to contribute code ;-)
1323          */
1324 
1325         case RSVP_OBJ_INTEGRITY:
1326         case RSVP_OBJ_SCOPE:
1327         case RSVP_OBJ_POLICY_DATA:
1328         case RSVP_OBJ_LABEL_SET:
1329         case RSVP_OBJ_ACCEPT_LABEL_SET:
1330         case RSVP_OBJ_PROTECTION:
1331         default:
1332             if (vflag <= 1)
1333                 print_unknown_data(obj_tptr,"\n\t    ",obj_tlen); /* FIXME indentation */
1334             break;
1335         }
1336         /* do we also want to see a hex dump ? */
1337         if (vflag > 1 || hexdump==TRUE)
1338             print_unknown_data(tptr+sizeof(sizeof(struct rsvp_object_header)),"\n\t    ", /* FIXME indentation */
1339                                rsvp_obj_len-sizeof(struct rsvp_object_header));
1340 
1341         tptr+=rsvp_obj_len;
1342         tlen-=rsvp_obj_len;
1343     }
1344     return 0;
1345 trunc:
1346     printf("\n\t\t packet exceeded snapshot");
1347     return -1;
1348 }
1349 
1350 
1351 void
1352 rsvp_print(register const u_char *pptr, register u_int len) {
1353 
1354     const struct rsvp_common_header *rsvp_com_header;
1355     const u_char *tptr,*subtptr;
1356     u_short tlen,subtlen;
1357 
1358     tptr=pptr;
1359 
1360     rsvp_com_header = (const struct rsvp_common_header *)pptr;
1361     TCHECK(*rsvp_com_header);
1362 
1363     /*
1364      * Sanity checking of the header.
1365      */
1366     if (RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags) != RSVP_VERSION) {
1367 	printf("ERROR: RSVP version %u packet not supported",
1368                RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags));
1369 	return;
1370     }
1371 
1372     /* in non-verbose mode just lets print the basic Message Type*/
1373     if (vflag < 1) {
1374         printf("RSVPv%u %s Message, length: %u",
1375                RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags),
1376                tok2str(rsvp_msg_type_values, "unknown (%u)",rsvp_com_header->msg_type),
1377                len);
1378         return;
1379     }
1380 
1381     /* ok they seem to want to know everything - lets fully decode it */
1382 
1383     tlen=EXTRACT_16BITS(rsvp_com_header->length);
1384 
1385     printf("\n\tRSVPv%u %s Message (%u), Flags: [%s], length: %u, ttl: %u, checksum: 0x%04x",
1386            RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags),
1387            tok2str(rsvp_msg_type_values, "unknown, type: %u",rsvp_com_header->msg_type),
1388            rsvp_com_header->msg_type,
1389            bittok2str(rsvp_header_flag_values,"none",RSVP_EXTRACT_FLAGS(rsvp_com_header->version_flags)),
1390            tlen,
1391            rsvp_com_header->ttl,
1392            EXTRACT_16BITS(rsvp_com_header->checksum));
1393 
1394     if (tlen < sizeof(const struct rsvp_common_header)) {
1395         printf("ERROR: common header too short %u < %lu", tlen,
1396                (unsigned long)sizeof(const struct rsvp_common_header));
1397         return;
1398     }
1399 
1400     tptr+=sizeof(const struct rsvp_common_header);
1401     tlen-=sizeof(const struct rsvp_common_header);
1402 
1403     switch(rsvp_com_header->msg_type) {
1404 
1405     case RSVP_MSGTYPE_AGGREGATE:
1406         while(tlen > 0) {
1407             subtptr=tptr;
1408             rsvp_com_header = (const struct rsvp_common_header *)subtptr;
1409             TCHECK(*rsvp_com_header);
1410 
1411             /*
1412              * Sanity checking of the header.
1413              */
1414             if (RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags) != RSVP_VERSION) {
1415                 printf("ERROR: RSVP version %u packet not supported",
1416                        RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags));
1417                 return;
1418             }
1419             subtlen=EXTRACT_16BITS(rsvp_com_header->length);
1420 
1421             printf("\n\t  RSVPv%u %s Message (%u), Flags: [%s], length: %u, ttl: %u, checksum: 0x%04x",
1422                    RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags),
1423                    tok2str(rsvp_msg_type_values, "unknown, type: %u",rsvp_com_header->msg_type),
1424                    rsvp_com_header->msg_type,
1425                    bittok2str(rsvp_header_flag_values,"none",RSVP_EXTRACT_FLAGS(rsvp_com_header->version_flags)),
1426                    subtlen,
1427                    rsvp_com_header->ttl,
1428                    EXTRACT_16BITS(rsvp_com_header->checksum));
1429 
1430             if (subtlen < sizeof(const struct rsvp_common_header)) {
1431                 printf("ERROR: common header too short %u < %lu", subtlen,
1432                        (unsigned long)sizeof(const struct rsvp_common_header));
1433                 return;
1434             }
1435 
1436             if (tlen < subtlen) {
1437                 printf("ERROR: common header too large %u > %u", subtlen,
1438                        tlen);
1439                 return;
1440             }
1441 
1442             subtptr+=sizeof(const struct rsvp_common_header);
1443             subtlen-=sizeof(const struct rsvp_common_header);
1444 
1445             if (rsvp_obj_print(subtptr,"\n\t    ", subtlen) == -1)
1446                 return;
1447 
1448             tptr+=subtlen+sizeof(const struct rsvp_common_header);
1449             tlen-=subtlen+sizeof(const struct rsvp_common_header);
1450         }
1451 
1452         break;
1453 
1454     case RSVP_MSGTYPE_PATH:
1455     case RSVP_MSGTYPE_RESV:
1456     case RSVP_MSGTYPE_PATHERR:
1457     case RSVP_MSGTYPE_RESVERR:
1458     case RSVP_MSGTYPE_PATHTEAR:
1459     case RSVP_MSGTYPE_RESVTEAR:
1460     case RSVP_MSGTYPE_RESVCONF:
1461     case RSVP_MSGTYPE_HELLO_OLD:
1462     case RSVP_MSGTYPE_HELLO:
1463     case RSVP_MSGTYPE_ACK:
1464     case RSVP_MSGTYPE_SREFRESH:
1465         if (rsvp_obj_print(tptr,"\n\t  ", tlen) == -1)
1466             return;
1467         break;
1468 
1469     default:
1470         print_unknown_data(tptr,"\n\t    ",tlen);
1471         break;
1472     }
1473 
1474     return;
1475 trunc:
1476     printf("\n\t\t packet exceeded snapshot");
1477 }
1478