]> The Tcpdump Group git mirrors - tcpdump/blob - print-rsvp.c
initial checkin
[tcpdump] / print-rsvp.c
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[] =
18 "@(#) $Header: /tcpdump/master/tcpdump/print-rsvp.c,v 1.1 2002-10-03 16:01:58 hannes 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
30 #include "interface.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33 #include "ethertype.h"
34
35 /*
36 * RFC 2205 common header
37 *
38 * 0 1 2 3
39 * +-------------+-------------+-------------+-------------+
40 * | Vers | Flags| Msg Type | RSVP Checksum |
41 * +-------------+-------------+-------------+-------------+
42 * | Send_TTL | (Reserved) | RSVP Length |
43 * +-------------+-------------+-------------+-------------+
44 *
45 */
46
47 struct rsvp_common_header {
48 u_char version_flags;
49 u_char msg_type;
50 u_char checksum[2];
51 u_char ttl;
52 u_char reserved;
53 u_char length[2];
54 };
55
56 /*
57 * RFC2205 object header
58 *
59 *
60 * 0 1 2 3
61 * +-------------+-------------+-------------+-------------+
62 * | Length (bytes) | Class-Num | C-Type |
63 * +-------------+-------------+-------------+-------------+
64 * | |
65 * // (Object contents) //
66 * | |
67 * +-------------+-------------+-------------+-------------+
68 */
69
70 struct rsvp_object_header {
71 u_char length[2];
72 u_char class_num;
73 u_char ctype;
74 };
75
76 #define RSVP_VERSION 1
77 #define RSVP_EXTRACT_VERSION(x) (((x)&0xf0)>>4)
78
79 #define RSVP_MSGTYPE_PATH 1
80 #define RSVP_MSGTYPE_RESV 2
81 #define RSVP_MSGTYPE_PATHERR 3
82 #define RSVP_MSGTYPE_RESVERR 4
83 #define RSVP_MSGTYPE_PATHTEAR 5
84 #define RSVP_MSGTYPE_RESVTEAR 6
85 #define RSVP_MSGTYPE_RESVCONF 7
86 #define RSVP_MSGTYPE_AGGREGATE 12
87 #define RSVP_MSGTYPE_ACK 13
88 #define RSVP_MSGTYPE_HELLO_OLD 14 /* ancient Hellos */
89 #define RSVP_MSGTYPE_SREFRESH 15
90 #define RSVP_MSGTYPE_HELLO 20
91
92 static const struct tok rsvp_msg_type_values[] = {
93 { RSVP_MSGTYPE_PATH, "Path" },
94 { RSVP_MSGTYPE_RESV, "Resv" },
95 { RSVP_MSGTYPE_PATHERR, "PathErr" },
96 { RSVP_MSGTYPE_RESVERR, "ResvErr" },
97 { RSVP_MSGTYPE_PATHTEAR, "PathTear" },
98 { RSVP_MSGTYPE_RESVTEAR, "ResvTear" },
99 { RSVP_MSGTYPE_RESVCONF, "ResvConf" },
100 { RSVP_MSGTYPE_AGGREGATE, "Aggregate" },
101 { RSVP_MSGTYPE_ACK, "Acknowledgement" },
102 { RSVP_MSGTYPE_HELLO_OLD, "Hello (Old)" },
103 { RSVP_MSGTYPE_SREFRESH, "Refresh" },
104 { RSVP_MSGTYPE_HELLO, "Hello" },
105 { 0, NULL}
106 };
107
108 #define RSVP_OBJ_SESSION 1
109 #define RSVP_OBJ_RSVP_HOP 3
110 #define RSVP_OBJ_INTEGRITY 4
111 #define RSVP_OBJ_TIME_VALUES 5
112 #define RSVP_OBJ_ERROR_SPEC 6
113 #define RSVP_OBJ_SCOPE 7
114 #define RSVP_OBJ_STYLE 8
115 #define RSVP_OBJ_FLOWSPEC 9
116 #define RSVP_OBJ_FILTERSPEC 10
117 #define RSVP_OBJ_SENDER_TEMPLATE 11
118 #define RSVP_OBJ_SENDER_TSPEC 12
119 #define RSVP_OBJ_ADSPEC 13
120 #define RSVP_OBJ_POLICY_DATA 14
121 #define RSVP_OBJ_CONFIRM 15
122 #define RSVP_OBJ_LABEL 16
123 #define RSVP_OBJ_LABEL_REQ 19
124 #define RSVP_OBJ_ERO 20
125 #define RSVP_OBJ_RRO 21
126 #define RSVP_OBJ_HELLO 22
127 #define RSVP_OBJ_MESSAGE_ID 23
128 #define RSVP_OBJ_MESSAGE_ID_ACK 24
129 #define RSVP_OBJ_MESSAGE_ID_LIST 25
130 #define RSVP_OBJ_RECOVERY_LABEL 34
131 #define RSVP_OBJ_UPSTREAM_LABEL 35
132 #define RSVP_OBJ_DETOUR 63
133 #define RSVP_OBJ_SUGGESTED_LABEL 129
134 #define RSVP_OBJ_PROPERTIES 204
135 #define RSVP_OBJ_FASTREROUTE 205
136 #define RSVP_OBJ_SESSION_ATTTRIBUTE 207
137 #define RSVP_OBJ_RESTART_CAPABILITY 131
138
139 static const struct tok rsvp_obj_values[] = {
140 { RSVP_OBJ_SESSION, "Session" },
141 { RSVP_OBJ_RSVP_HOP, "RSVP Hop" },
142 { RSVP_OBJ_INTEGRITY, "Integrity" },
143 { RSVP_OBJ_TIME_VALUES, "Time Values" },
144 { RSVP_OBJ_ERROR_SPEC, "Error Spec" },
145 { RSVP_OBJ_SCOPE, "Scope" },
146 { RSVP_OBJ_STYLE, "Style" },
147 { RSVP_OBJ_FLOWSPEC, "Flowspec" },
148 { RSVP_OBJ_FILTERSPEC, "FilterSpec" },
149 { RSVP_OBJ_SENDER_TEMPLATE, "Sender Template" },
150 { RSVP_OBJ_SENDER_TSPEC, "Sender TSpec" },
151 { RSVP_OBJ_ADSPEC, "Adspec" },
152 { RSVP_OBJ_POLICY_DATA, "Policy Data" },
153 { RSVP_OBJ_CONFIRM, "Confirm" },
154 { RSVP_OBJ_LABEL, "Label" },
155 { RSVP_OBJ_LABEL_REQ, "Label Request" },
156 { RSVP_OBJ_ERO, "ERO" },
157 { RSVP_OBJ_RRO, "RRO" },
158 { RSVP_OBJ_HELLO, "Hello" },
159 { RSVP_OBJ_MESSAGE_ID, "Message ID" },
160 { RSVP_OBJ_MESSAGE_ID_ACK, "Message ID Ack" },
161 { RSVP_OBJ_MESSAGE_ID_LIST, "Message ID List" },
162 { RSVP_OBJ_RECOVERY_LABEL, "Recovery Label" },
163 { RSVP_OBJ_UPSTREAM_LABEL, "Upstream Label" },
164 { RSVP_OBJ_DETOUR, "Detour" },
165 { RSVP_OBJ_SUGGESTED_LABEL, "Suggested Label" },
166 { RSVP_OBJ_PROPERTIES, "Properties" },
167 { RSVP_OBJ_FASTREROUTE, "Fast Re-Route" },
168 { RSVP_OBJ_SESSION_ATTTRIBUTE, "Session Attribute" },
169 { RSVP_OBJ_RESTART_CAPABILITY, "Restart Capability" },
170 { 0, NULL}
171 };
172
173 #define RSVP_CTYPE_IPV4 1
174 #define RSVP_CTYPE_IPV6 2
175 #define RSVP_CTYPE_TUNNEL_IPV4 7
176
177 static const struct tok rsvp_ctype_values[] = {
178 { RSVP_CTYPE_IPV4, "IPv4" },
179 { RSVP_CTYPE_IPV6, "IPv6" },
180 { RSVP_CTYPE_TUNNEL_IPV4, "Tunnel IPv4" },
181 { 0, NULL}
182 };
183
184 #define RSVP_OBJ_XRO_MASK_SUBOBJ(x) ((x)&0x7f)
185 #define RSVP_OBJ_XRO_MASK_LOOSE(x) ((x)&0x80)
186
187 #define RSVP_OBJ_XRO_RES 0
188 #define RSVP_OBJ_XRO_IPV4 1
189 #define RSVP_OBJ_XRO_IPV6 2
190 #define RSVP_OBJ_XRO_ASN 32
191 #define RSVP_OBJ_XRO_MPLS 64
192
193 static const struct tok rsvp_obj_xro_values[] = {
194 { RSVP_OBJ_XRO_RES, "Reserved" },
195 { RSVP_OBJ_XRO_IPV4, "IPv4 prefix" },
196 { RSVP_OBJ_XRO_IPV6, "IPv6 prefix" },
197 { RSVP_OBJ_XRO_ASN, "Autonomous system number" },
198 { RSVP_OBJ_XRO_MPLS, "MPLS label switched path termination" },
199 { 0, NULL}
200 };
201
202 void
203 rsvp_print(register const u_char *pptr, register u_int len) {
204
205 const struct rsvp_common_header *rsvp_com_header;
206 const struct rsvp_object_header *rsvp_obj_header;
207 const u_char *tptr,*obj_tptr;
208 u_short tlen,rsvp_obj_len,rsvp_obj_ctype,obj_tlen;
209
210 tptr=pptr;
211 rsvp_com_header = (const struct rsvp_common_header *)pptr;
212 TCHECK(*rsvp_com_header);
213
214 /*
215 * Sanity checking of the header.
216 */
217 if (RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags) != RSVP_VERSION) {
218 printf("RSVP version %u packet not supported",
219 RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags));
220 return;
221 }
222
223 /* in non-verbose mode just lets print the basic Message Type*/
224 if (vflag < 1) {
225 printf("RSVP %s Message, length: %u",
226 tok2str(rsvp_msg_type_values, "unknown (%u)",rsvp_com_header->msg_type),
227 len);
228 return;
229 }
230
231 /* ok they seem to want to know everything - lets fully decode it */
232
233 printf("RSVP, length: %u",len);
234
235 tlen=EXTRACT_16BITS(rsvp_com_header->length);
236
237 printf("\n\tv: %u, msg-type: %s, length: %u, ttl: %u, checksum: 0x%04x",
238 RSVP_EXTRACT_VERSION(rsvp_com_header->version_flags),
239 tok2str(rsvp_msg_type_values, "unknown, type: %u",rsvp_com_header->msg_type),
240 tlen,
241 rsvp_com_header->ttl,
242 EXTRACT_16BITS(rsvp_com_header->checksum));
243
244 tptr+=sizeof(const struct rsvp_common_header);
245 tlen-=sizeof(const struct rsvp_common_header);
246
247 while(tlen>0) {
248 /* did we capture enough for fully decoding the object header ? */
249 if (!TTEST2(*tptr, sizeof(struct rsvp_object_header)))
250 goto trunc;
251
252 rsvp_obj_header = (const struct rsvp_object_header *)tptr;
253 rsvp_obj_len=EXTRACT_16BITS(rsvp_obj_header->length);
254 rsvp_obj_ctype=rsvp_obj_header->ctype;
255
256 if(rsvp_obj_len % 4 || rsvp_obj_len < 4)
257 return;
258
259 printf("\n\t %s Object (%u), Class-Type: %s (%u), length: %u",
260 tok2str(rsvp_obj_values, "Unknown",rsvp_obj_header->class_num),
261 rsvp_obj_header->class_num,
262 tok2str(rsvp_ctype_values, "Unknown",rsvp_obj_ctype),
263 rsvp_obj_ctype,
264 rsvp_obj_len);
265
266 obj_tptr=tptr+sizeof(struct rsvp_object_header);
267 obj_tlen=rsvp_obj_len-sizeof(struct rsvp_object_header);
268
269 /* did we capture enough for fully decoding the object ? */
270 if (!TTEST2(*tptr, rsvp_obj_len))
271 goto trunc;
272
273 switch(rsvp_obj_header->class_num) {
274 case RSVP_OBJ_LABEL:
275 switch(rsvp_obj_ctype) {
276 case RSVP_CTYPE_IPV4:
277 while(obj_tlen >= 4 ) {
278 printf("\n\t Label: %u", EXTRACT_32BITS(obj_tptr));
279 obj_tlen-=4;
280 obj_tptr+=4;
281 }
282 break;
283 }
284 break;
285 case RSVP_OBJ_LABEL_REQ:
286 switch(rsvp_obj_ctype) {
287 case RSVP_CTYPE_IPV4:
288 while(obj_tlen >= 4 ) {
289 printf("\n\t L3 Protocol ID: %s",
290 tok2str(ethertype_values,
291 "Unknown Protocol 0x%04x",
292 EXTRACT_16BITS(obj_tptr+2)));
293 obj_tlen-=4;
294 obj_tptr+=4;
295 }
296 break;
297 }
298 break;
299 case RSVP_OBJ_RRO:
300 case RSVP_OBJ_ERO:
301 switch(rsvp_obj_ctype) {
302 case RSVP_CTYPE_IPV4:
303 while(obj_tlen >= 4 ) {
304 printf("\n\t Subobject Type: %s",
305 tok2str(rsvp_obj_xro_values,
306 "Unknown %u",
307 RSVP_OBJ_XRO_MASK_SUBOBJ(*obj_tptr)));
308 switch(RSVP_OBJ_XRO_MASK_SUBOBJ(*obj_tptr)) {
309 case RSVP_OBJ_XRO_IPV4:
310 printf(", %s, %s/%u",
311 RSVP_OBJ_XRO_MASK_LOOSE(*obj_tptr) ? "Loose" : "Strict",
312 ipaddr_string(obj_tptr+2),
313 *(obj_tptr+6));
314 }
315 obj_tlen-=*(obj_tptr+1);
316 obj_tptr+=*(obj_tptr+1);
317 }
318 break;
319 }
320 break;
321 /*
322 * FIXME those are the defined objects that lack a decoder
323 * you are welcome to contribute code ;-)
324 */
325 case RSVP_OBJ_SESSION:
326 case RSVP_OBJ_RSVP_HOP:
327 case RSVP_OBJ_INTEGRITY:
328 case RSVP_OBJ_TIME_VALUES:
329 case RSVP_OBJ_ERROR_SPEC:
330 case RSVP_OBJ_SCOPE:
331 case RSVP_OBJ_STYLE:
332 case RSVP_OBJ_FILTERSPEC:
333 case RSVP_OBJ_SENDER_TEMPLATE:
334 case RSVP_OBJ_SENDER_TSPEC:
335 case RSVP_OBJ_ADSPEC:
336 case RSVP_OBJ_POLICY_DATA:
337 case RSVP_OBJ_CONFIRM:
338 case RSVP_OBJ_HELLO:
339 case RSVP_OBJ_MESSAGE_ID:
340 case RSVP_OBJ_MESSAGE_ID_ACK:
341 case RSVP_OBJ_MESSAGE_ID_LIST:
342 case RSVP_OBJ_RECOVERY_LABEL:
343 case RSVP_OBJ_UPSTREAM_LABEL:
344 case RSVP_OBJ_DETOUR:
345 case RSVP_OBJ_SUGGESTED_LABEL:
346 case RSVP_OBJ_PROPERTIES:
347 case RSVP_OBJ_FASTREROUTE:
348 case RSVP_OBJ_SESSION_ATTTRIBUTE:
349 case RSVP_OBJ_RESTART_CAPABILITY:
350 default:
351 if (vflag <= 1)
352 print_unknown_data(obj_tptr,"\n\t ",obj_tlen);
353 break;
354 }
355 /* do we want to see an additionally hexdump ? */
356 if (vflag > 1)
357 print_unknown_data(tptr+sizeof(sizeof(struct rsvp_object_header)),"\n\t ",
358 rsvp_obj_len-sizeof(struct rsvp_object_header));
359
360 tptr+=rsvp_obj_len;
361 tlen-=rsvp_obj_len;
362 }
363 return;
364 trunc:
365 printf("\n\t\t packet exceeded snapshot");
366 }
367
368