]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
- bugfix: rework the AS_PATH decoder per draft-ietf-idr-rfc3065bis:
[tcpdump] / print-ospf.c
1 /*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
22 */
23
24 #ifndef lint
25 static const char rcsid[] _U_ =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.49 2004-01-08 22:08:40 hannes Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h"
40 #include "gmpls.h"
41
42 #include "ospf.h"
43
44 #include "ip.h"
45
46 static struct tok ospf_option_values[] = {
47 { OSPF_OPTION_T, "TOS" },
48 { OSPF_OPTION_E, "External" },
49 { OSPF_OPTION_MC, "Multicast" },
50 { OSPF_OPTION_NP, "NSSA" },
51 { OSPF_OPTION_EA, "Advertise External" },
52 { OSPF_OPTION_DC, "Demand Circuit" },
53 { OSPF_OPTION_O, "Opaque" },
54 { 0, NULL }
55 };
56
57 static struct tok ospf_authtype_values[] = {
58 { OSPF_AUTH_NONE, "none" },
59 { OSPF_AUTH_NONE, "simple" },
60 { OSPF_AUTH_MD5, "MD5" },
61 { 0, NULL }
62 };
63
64 static struct tok ospf_rla_flag_values[] = {
65 { RLA_FLAG_B, "ABR" },
66 { RLA_FLAG_E, "ASBR" },
67 { RLA_FLAG_W1, "Virtual" },
68 { RLA_FLAG_W2, "W2" },
69 { 0, NULL }
70 };
71
72 static struct tok type2str[] = {
73 { OSPF_TYPE_UMD, "UMD" },
74 { OSPF_TYPE_HELLO, "Hello" },
75 { OSPF_TYPE_DD, "Database Description" },
76 { OSPF_TYPE_LS_REQ, "LS-Request" },
77 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
78 { OSPF_TYPE_LS_ACK, "LS-Ack" },
79 { 0, NULL }
80 };
81
82 static struct tok lsa_values[] = {
83 { LS_TYPE_ROUTER, "Router" },
84 { LS_TYPE_NETWORK, "Network" },
85 { LS_TYPE_SUM_IP, "Summary" },
86 { LS_TYPE_SUM_ABR, "ASBR Summary" },
87 { LS_TYPE_ASE, "External" },
88 { LS_TYPE_GROUP, "Multicast Group" },
89 { LS_TYPE_NSSA, "NSSA" },
90 { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
91 { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
92 { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
93 { 0, NULL }
94 };
95
96 static struct tok ospf_dd_flag_values[] = {
97 { OSPF_DB_INIT, "Init" },
98 { OSPF_DB_MORE, "More" },
99 { OSPF_DB_MASTER, "Master" },
100 { 0, NULL }
101 };
102
103 static struct tok lsa_opaque_values[] = {
104 { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
105 { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
106 { 0, NULL }
107 };
108
109 static struct tok lsa_opaque_te_tlv_values[] = {
110 { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
111 { LS_OPAQUE_TE_TLV_LINK, "Link" },
112 { 0, NULL }
113 };
114
115 static struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
116 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
129 { 0, NULL }
130 };
131
132 static struct tok lsa_opaque_grace_tlv_values[] = {
133 { LS_OPAQUE_GRACE_TLV_PERIOD, "Grace Period" },
134 { LS_OPAQUE_GRACE_TLV_REASON, "Graceful restart Reason" },
135 { LS_OPAQUE_GRACE_TLV_INT_ADDRESS, "IPv4 interface address" },
136 { 0, NULL }
137 };
138
139 static struct tok lsa_opaque_grace_tlv_reason_values[] = {
140 { LS_OPAQUE_GRACE_TLV_REASON_UNKNOWN, "Unknown" },
141 { LS_OPAQUE_GRACE_TLV_REASON_SW_RESTART, "Software Restart" },
142 { LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE, "Software Reload/Upgrade" },
143 { LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH, "Control Processor Switch" },
144 { 0, NULL }
145 };
146
147 static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
148 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
149 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
150 { 0, NULL }
151 };
152
153 static char tstr[] = " [|ospf]";
154
155 #ifdef WIN32
156 #define inline __inline
157 #endif /* WIN32 */
158
159 static int ospf_print_lshdr(const struct lsa_hdr *);
160 static const u_char *ospf_print_lsa(const struct lsa *);
161 static int ospf_decode_v2(const struct ospfhdr *, const u_char *);
162
163 static int
164 ospf_print_lshdr(register const struct lsa_hdr *lshp)
165 {
166 u_int ls_length;
167
168 TCHECK(lshp->ls_length);
169 ls_length = EXTRACT_16BITS(&lshp->ls_length);
170 if (ls_length < sizeof(struct lsa_hdr)) {
171 printf("\n\t Bogus length %u < %lu", ls_length,
172 (unsigned long)sizeof(struct lsa_hdr));
173 return(-1);
174 }
175
176 TCHECK(lshp->ls_seq); /* XXX - ls_length check checked this */
177 printf("\n\t Advertising Router: %s, seq 0x%08x, age %us, length: %u",
178 ipaddr_string(&lshp->ls_router),
179 EXTRACT_32BITS(&lshp->ls_seq),
180 EXTRACT_16BITS(&lshp->ls_age),
181 ls_length-(u_int)sizeof(struct lsa_hdr));
182
183 TCHECK(lshp->ls_type); /* XXX - ls_length check checked this */
184 switch (lshp->ls_type) {
185 /* the LSA header for opaque LSAs was slightly changed */
186 case LS_TYPE_OPAQUE_LL:
187 case LS_TYPE_OPAQUE_AL:
188 case LS_TYPE_OPAQUE_DW:
189 printf("\n\t %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u",
190 tok2str(lsa_values,"unknown",lshp->ls_type),
191 lshp->ls_type,
192
193 tok2str(lsa_opaque_values,
194 "unknown",
195 *(&lshp->un_lsa_id.opaque_field.opaque_type)),
196 *(&lshp->un_lsa_id.opaque_field.opaque_type),
197 EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
198
199 );
200 break;
201
202 /* all other LSA types use regular style LSA headers */
203 default:
204 printf("\n\t %s LSA (%d), LSA-ID: %s",
205 tok2str(lsa_values,"unknown",lshp->ls_type),
206 lshp->ls_type,
207 ipaddr_string(&lshp->un_lsa_id.lsa_id));
208 break;
209 }
210
211 TCHECK(lshp->ls_options); /* XXX - ls_length check checked this */
212 printf("\n\t Options: [%s]", bittok2str(ospf_option_values,"none",lshp->ls_options));
213
214 return (ls_length);
215 trunc:
216 return (-1);
217 }
218
219 /*
220 * Print a single link state advertisement. If truncated or if LSA length
221 * field is less than the length of the LSA header, return NULl, else
222 * return pointer to data past end of LSA.
223 */
224 static const u_int8_t *
225 ospf_print_lsa(register const struct lsa *lsap)
226 {
227 register const u_int8_t *ls_end;
228 register const struct rlalink *rlp;
229 register const struct tos_metric *tosp;
230 register const struct in_addr *ap;
231 register const struct aslametric *almp;
232 register const struct mcla *mcp;
233 register const u_int32_t *lp;
234 register int j, k, tlv_type, tlv_length, subtlv_type, subtlv_length, priority_level;
235 register int ls_length;
236 const u_int8_t *tptr;
237 int count_srlg;
238 union { /* int to float conversion buffer for several subTLVs */
239 float f;
240 u_int32_t i;
241 } bw;
242
243 tptr = (u_int8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
244 ls_length = ospf_print_lshdr(&lsap->ls_hdr);
245 if (ls_length == -1)
246 return(NULL);
247 ls_end = (u_int8_t *)lsap + ls_length;
248 ls_length -= sizeof(struct lsa_hdr);
249
250 switch (lsap->ls_hdr.ls_type) {
251
252 case LS_TYPE_ROUTER:
253 TCHECK(lsap->lsa_un.un_rla.rla_flags);
254 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values,"none",lsap->lsa_un.un_rla.rla_flags));
255
256 TCHECK(lsap->lsa_un.un_rla.rla_count);
257 j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
258 TCHECK(lsap->lsa_un.un_rla.rla_link);
259 rlp = lsap->lsa_un.un_rla.rla_link;
260 while (j--) {
261 TCHECK(*rlp);
262 switch (rlp->link_type) {
263
264 case RLA_TYPE_VIRTUAL:
265 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
266 ipaddr_string(&rlp->link_id),
267 ipaddr_string(&rlp->link_data));
268 break;
269
270 case RLA_TYPE_ROUTER:
271 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
272 ipaddr_string(&rlp->link_id),
273 ipaddr_string(&rlp->link_data));
274 break;
275
276 case RLA_TYPE_TRANSIT:
277 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
278 ipaddr_string(&rlp->link_id),
279 ipaddr_string(&rlp->link_data));
280 break;
281
282 case RLA_TYPE_STUB:
283 printf("\n\t Stub Network: %s, Mask: %s",
284 ipaddr_string(&rlp->link_id),
285 ipaddr_string(&rlp->link_data));
286 break;
287
288 default:
289 printf("\n\t Unknown Router Link Type (%u)",
290 rlp->link_type);
291 return (ls_end);
292 }
293 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp->link_tos0metric));
294 tosp = (struct tos_metric *)
295 ((sizeof rlp->link_tos0metric) + (u_char *) rlp);
296 for (k = 0; k < (int) rlp->link_toscount; ++k, ++tosp) {
297 TCHECK(*tosp);
298 printf(", tos %d, metric: %d",
299 tosp->tos_type,
300 EXTRACT_16BITS(&tosp->tos_metric));
301 }
302 rlp = (struct rlalink *)((u_char *)(rlp + 1) +
303 ((rlp->link_toscount) * sizeof(*tosp)));
304 }
305 break;
306
307 case LS_TYPE_NETWORK:
308 TCHECK(lsap->lsa_un.un_nla.nla_mask);
309 printf("\n\t Mask %s\n\t Connected Routers:",
310 ipaddr_string(&lsap->lsa_un.un_nla.nla_mask));
311 ap = lsap->lsa_un.un_nla.nla_router;
312 while ((u_char *)ap < ls_end) {
313 TCHECK(*ap);
314 printf("\n\t %s", ipaddr_string(ap));
315 ++ap;
316 }
317 break;
318
319 case LS_TYPE_SUM_IP:
320 TCHECK(lsap->lsa_un.un_nla.nla_mask);
321 printf("\n\t Mask %s",
322 ipaddr_string(&lsap->lsa_un.un_sla.sla_mask));
323 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
324 lp = lsap->lsa_un.un_sla.sla_tosmetric;
325 /* suppress tos if its not supported */
326 if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) {
327 printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC);
328 break;
329 }
330 while ((u_char *)lp < ls_end) {
331 register u_int32_t ul;
332
333 TCHECK(*lp);
334 ul = EXTRACT_32BITS(lp);
335 printf(", tos %d metric %d",
336 (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
337 ul & SLA_MASK_METRIC);
338 ++lp;
339 }
340 break;
341
342 case LS_TYPE_SUM_ABR:
343 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
344 lp = lsap->lsa_un.un_sla.sla_tosmetric;
345 /* suppress tos if its not supported */
346 if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) {
347 printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC);
348 break;
349 }
350 while ((u_char *)lp < ls_end) {
351 register u_int32_t ul;
352
353 TCHECK(*lp);
354 ul = EXTRACT_32BITS(lp);
355 printf(", tos %d metric %d",
356 (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
357 ul & SLA_MASK_METRIC);
358 ++lp;
359 }
360 break;
361
362 case LS_TYPE_ASE:
363 TCHECK(lsap->lsa_un.un_nla.nla_mask);
364 printf("\n\t Mask %s",
365 ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
366
367 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
368 almp = lsap->lsa_un.un_asla.asla_metric;
369 while ((u_char *)almp < ls_end) {
370 register u_int32_t ul;
371
372 TCHECK(almp->asla_tosmetric);
373 ul = EXTRACT_32BITS(&almp->asla_tosmetric);
374 printf(", type %d, tos %d metric:",
375 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
376 (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
377 if ((ul & ASLA_MASK_METRIC)==0xffffff)
378 printf(" infinite");
379 else
380 printf(" %d", (ul & ASLA_MASK_METRIC));
381
382 TCHECK(almp->asla_forward);
383 if (almp->asla_forward.s_addr) {
384 printf(", forward %s",
385 ipaddr_string(&almp->asla_forward));
386 }
387 TCHECK(almp->asla_tag);
388 if (almp->asla_tag.s_addr) {
389 printf(", tag %s",
390 ipaddr_string(&almp->asla_tag));
391 }
392 ++almp;
393 }
394 break;
395
396 case LS_TYPE_GROUP:
397 /* Multicast extensions as of 23 July 1991 */
398 mcp = lsap->lsa_un.un_mcla;
399 while ((u_char *)mcp < ls_end) {
400 TCHECK(mcp->mcla_vid);
401 switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
402
403 case MCLA_VERTEX_ROUTER:
404 printf("\n\t Router Router-ID %s",
405 ipaddr_string(&mcp->mcla_vid));
406 break;
407
408 case MCLA_VERTEX_NETWORK:
409 printf("\n\t Network Designated Router %s",
410 ipaddr_string(&mcp->mcla_vid));
411 break;
412
413 default:
414 printf("\n\t unknown VertexType (%u)",
415 EXTRACT_32BITS(&mcp->mcla_vtype));
416 break;
417 }
418 ++mcp;
419 }
420 break;
421
422 case LS_TYPE_OPAQUE_LL: /* fall through */
423 case LS_TYPE_OPAQUE_AL:
424 case LS_TYPE_OPAQUE_DW:
425
426 switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
427 case LS_OPAQUE_TYPE_GRACE:
428 tptr = (u_int8_t *)(&lsap->lsa_un.un_grace_tlv.type);
429
430 while (ls_length != 0) {
431 if (!TTEST2(*tptr, 4))
432 goto trunc;
433 if (ls_length < 4) {
434 printf("\n\t Remaining LS length %u < 4", ls_length);
435 return(ls_end);
436 }
437 tlv_type = EXTRACT_16BITS(tptr);
438 tlv_length = EXTRACT_16BITS(tptr+2);
439 tptr+=4;
440 ls_length-=4;
441
442 printf("\n\t %s TLV (%u), length: %u, value: ",
443 tok2str(lsa_opaque_grace_tlv_values,"unknown",tlv_type),
444 tlv_type,
445 tlv_length);
446
447 if (tlv_length > ls_length) {
448 printf("\n\t Bogus length %u > %u", tlv_length,
449 ls_length);
450 return(ls_end);
451 }
452 ls_length-=tlv_length;
453 switch(tlv_type) {
454
455 case LS_OPAQUE_GRACE_TLV_PERIOD:
456 if (tlv_length != 4) {
457 printf("\n\t Bogus length %u != 4", tlv_length);
458 return(ls_end);
459 }
460 printf("%us",EXTRACT_32BITS(tptr));
461 break;
462 case LS_OPAQUE_GRACE_TLV_REASON:
463 if (tlv_length != 1) {
464 printf("\n\t Bogus length %u != 1", tlv_length);
465 return(ls_end);
466 }
467 printf("%s (%u)",
468 tok2str(lsa_opaque_grace_tlv_reason_values, "Unknown", *tptr),
469 *tptr);
470 break;
471 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS:
472 if (tlv_length != 4) {
473 printf("\n\t Bogus length %u != 4", tlv_length);
474 return(ls_end);
475 }
476 printf("%s", ipaddr_string(tptr));
477 break;
478 default:
479 if (vflag <= 1) {
480 if(!print_unknown_data(tptr,"\n\t ",tlv_length))
481 return(ls_end);
482 }
483 break;
484
485 }
486 tptr+=tlv_length;
487 }
488
489 break;
490 case LS_OPAQUE_TYPE_TE:
491 tptr = (u_int8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type);
492
493 while (ls_length != 0) {
494 if (!TTEST2(*tptr, 4))
495 goto trunc;
496 if (ls_length < 4) {
497 printf("\n\t Remaining LS length %u < 4", ls_length);
498 return(ls_end);
499 }
500 tlv_type = EXTRACT_16BITS(tptr);
501 tlv_length = EXTRACT_16BITS(tptr+2);
502 tptr+=4;
503 ls_length-=4;
504
505 printf("\n\t %s TLV (%u), length: %u",
506 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
507 tlv_type,
508 tlv_length);
509
510 if (tlv_length > ls_length) {
511 printf("\n\t Bogus length %u > %u", tlv_length,
512 ls_length);
513 return(ls_end);
514 }
515 ls_length-=tlv_length;
516 switch(tlv_type) {
517 case LS_OPAQUE_TE_TLV_LINK:
518 while (tlv_length != 0) {
519 if (tlv_length < 4) {
520 printf("\n\t Remaining TLV length %u < 4",
521 tlv_length);
522 return(ls_end);
523 }
524 if (!TTEST2(*tptr, 4))
525 goto trunc;
526 subtlv_type = EXTRACT_16BITS(tptr);
527 subtlv_length = EXTRACT_16BITS(tptr+2);
528 tptr+=4;
529 tlv_length-=4;
530
531 printf("\n\t %s subTLV (%u), length: %u",
532 tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
533 subtlv_type,
534 subtlv_length);
535
536 if (!TTEST2(*tptr, subtlv_length))
537 goto trunc;
538 switch(subtlv_type) {
539 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
540 printf(", 0x%08x", EXTRACT_32BITS(tptr));
541 break;
542 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
543 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
544 printf(", %s (0x%08x)",
545 ipaddr_string(tptr),
546 EXTRACT_32BITS(tptr));
547 if (subtlv_length == 8) /* draft-ietf-ccamp-ospf-gmpls-extensions */
548 printf(", %s (0x%08x)",
549 ipaddr_string(tptr+4),
550 EXTRACT_32BITS(tptr+4));
551 break;
552 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
553 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
554 printf(", %s", ipaddr_string(tptr));
555 break;
556 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
557 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
558 bw.i = EXTRACT_32BITS(tptr);
559 printf(", %.3f Mbps", bw.f*8/1000000 );
560 break;
561 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
562 for (priority_level = 0; priority_level < 8; priority_level++) {
563 bw.i = EXTRACT_32BITS(tptr+priority_level*4);
564 printf("\n\t\tpriority level %d: %.3f Mbps",
565 priority_level,
566 bw.f*8/1000000 );
567 }
568 break;
569 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
570 printf(", Metric %u", EXTRACT_32BITS(tptr));
571 break;
572 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
573 printf(", %s, Priority %u",
574 bittok2str(gmpls_link_prot_values, "none", *tptr),
575 *(tptr+1));
576 break;
577 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
578 printf("\n\t\tInterface Switching Capability: %s",
579 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
580 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
581 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
582 for (priority_level = 0; priority_level < 8; priority_level++) {
583 bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
584 printf("\n\t\t priority level %d: %.3f Mbps",
585 priority_level,
586 bw.f*8/1000000 );
587 }
588 break;
589 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
590 printf(", %s (%u)",
591 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
592 *tptr);
593 break;
594
595 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
596 count_srlg = subtlv_length / 4;
597 if (count_srlg != 0)
598 printf("\n\t\t Shared risk group: ");
599 while (count_srlg > 0) {
600 bw.i = EXTRACT_32BITS(tptr);
601 printf("%d",bw.i);
602 tptr+=4;
603 count_srlg--;
604 if (count_srlg > 0)
605 printf(", ");
606 }
607 break;
608
609 default:
610 if (vflag <= 1) {
611 if(!print_unknown_data(tptr,"\n\t\t",subtlv_length))
612 return(ls_end);
613 }
614 break;
615 }
616 /* in OSPF everything has to be 32-bit aligned, including TLVs */
617 if (subtlv_length%4 != 0)
618 subtlv_length+=4-(subtlv_length%4);
619
620 tlv_length-=subtlv_length;
621 tptr+=subtlv_length;
622
623 }
624 break;
625
626 case LS_OPAQUE_TE_TLV_ROUTER:
627 printf(", %s", ipaddr_string(tptr));
628 break;
629
630 default:
631 if (vflag <= 1) {
632 if(!print_unknown_data(tptr,"\n\t ",tlv_length))
633 return(ls_end);
634 }
635 break;
636 }
637 tptr+=tlv_length;
638 }
639 break;
640 }
641 break;
642 default:
643 if (vflag <= 1) {
644 if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown,
645 "\n\t ", ls_length))
646 return(ls_end);
647 }
648 break;
649 }
650
651 /* do we want to see an additionally hexdump ? */
652 if (vflag> 1)
653 if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown,
654 "\n\t ", ls_length)) {
655 return(ls_end);
656 }
657
658 return (ls_end);
659 trunc:
660 return (NULL);
661 }
662
663 static int
664 ospf_decode_v2(register const struct ospfhdr *op,
665 register const u_char *dataend)
666 {
667 register const struct in_addr *ap;
668 register const struct lsr *lsrp;
669 register const struct lsa_hdr *lshp;
670 register const struct lsa *lsap;
671 register u_int32_t lsa_count,lsa_count_max;
672
673 switch (op->ospf_type) {
674
675 case OSPF_TYPE_UMD:
676 /*
677 * Rob Coltun's special monitoring packets;
678 * do nothing
679 */
680 break;
681
682 case OSPF_TYPE_HELLO:
683 printf("\n\tOptions: [%s]",
684 bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options));
685
686 TCHECK(op->ospf_hello.hello_deadint);
687 printf("\n\t Hello Timer: %us, Dead Timer %us, Mask: %s, Priority: %u",
688 EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
689 EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
690 ipaddr_string(&op->ospf_hello.hello_mask),
691 op->ospf_hello.hello_priority);
692
693 TCHECK(op->ospf_hello.hello_dr);
694 if (op->ospf_hello.hello_dr.s_addr != 0)
695 printf("\n\t Designated Router %s",
696 ipaddr_string(&op->ospf_hello.hello_dr));
697
698 TCHECK(op->ospf_hello.hello_bdr);
699 if (op->ospf_hello.hello_bdr.s_addr != 0)
700 printf(", Backup Designated Router %s",
701 ipaddr_string(&op->ospf_hello.hello_bdr));
702
703 ap = op->ospf_hello.hello_neighbor;
704 if ((u_char *)ap < dataend)
705 printf("\n\t Neighbor List:");
706 while ((u_char *)ap < dataend) {
707 TCHECK(*ap);
708 printf("\n\t %s", ipaddr_string(ap));
709 ++ap;
710 }
711 break; /* HELLO */
712
713 case OSPF_TYPE_DD:
714 TCHECK(op->ospf_db.db_options);
715 printf("\n\tOptions: [%s]",
716 bittok2str(ospf_option_values,"none",op->ospf_db.db_options));
717 TCHECK(op->ospf_db.db_flags);
718 printf(", DD Flags: [%s]",
719 bittok2str(ospf_dd_flag_values,"none",op->ospf_db.db_flags));
720
721 if (vflag) {
722 /* Print all the LS adv's */
723 lshp = op->ospf_db.db_lshdr;
724 while (ospf_print_lshdr(lshp) != -1) {
725 ++lshp;
726 }
727 }
728 break;
729
730 case OSPF_TYPE_LS_REQ:
731 lsrp = op->ospf_lsr;
732 while ((u_char *)lsrp < dataend) {
733 TCHECK(*lsrp);
734
735 printf("\n\t Advertising Router: %s, %s LSA (%u)",
736 ipaddr_string(&lsrp->ls_router),
737 tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
738 EXTRACT_32BITS(&lsrp->ls_type));
739
740 switch (EXTRACT_32BITS(lsrp->ls_type)) {
741 /* the LSA header for opaque LSAs was slightly changed */
742 case LS_TYPE_OPAQUE_LL:
743 case LS_TYPE_OPAQUE_AL:
744 case LS_TYPE_OPAQUE_DW:
745 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
746 tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
747 lsrp->un_ls_stateid.opaque_field.opaque_type,
748 EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id));
749 break;
750 default:
751 printf(", LSA-ID: %s",
752 ipaddr_string(&lsrp->un_ls_stateid.ls_stateid));
753 break;
754 }
755
756 ++lsrp;
757 }
758 break;
759
760 case OSPF_TYPE_LS_UPDATE:
761 lsap = op->ospf_lsu.lsu_lsa;
762 TCHECK(op->ospf_lsu.lsu_count);
763 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
764 printf(", %d LSA%s",lsa_count_max, lsa_count_max > 1 ? "s" : "");
765 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
766 printf("\n\t LSA #%u",lsa_count);
767 lsap = (const struct lsa *)ospf_print_lsa(lsap);
768 if (lsap == NULL)
769 goto trunc;
770 }
771 break;
772
773 case OSPF_TYPE_LS_ACK:
774 lshp = op->ospf_lsa.lsa_lshdr;
775 while (ospf_print_lshdr(lshp) != -1) {
776 ++lshp;
777 }
778 break;
779
780 default:
781 printf("v2 type (%d)", op->ospf_type);
782 break;
783 }
784 return (0);
785 trunc:
786 return (1);
787 }
788
789 void
790 ospf_print(register const u_char *bp, register u_int length,
791 register const u_char *bp2)
792 {
793 register const struct ospfhdr *op;
794 register const struct ip *ip;
795 register const u_char *dataend;
796 register const char *cp;
797
798 op = (struct ospfhdr *)bp;
799 ip = (struct ip *)bp2;
800
801 /* XXX Before we do anything else, strip off the MD5 trailer */
802 TCHECK(op->ospf_authtype);
803 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
804 length -= OSPF_AUTH_MD5_LEN;
805 snapend -= OSPF_AUTH_MD5_LEN;
806 }
807
808 /* If the type is valid translate it, or just print the type */
809 /* value. If it's not valid, say so and return */
810 TCHECK(op->ospf_type);
811 cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
812 printf("OSPFv%u, %s (%u), length: %u",
813 op->ospf_version,
814 cp,
815 op->ospf_type,
816 length);
817 if (*cp == 'u')
818 return;
819
820 if(!vflag) /* non verbose - so lets bail out here */
821 return;
822
823 TCHECK(op->ospf_len);
824 if (length != EXTRACT_16BITS(&op->ospf_len)) {
825 printf(" [len %d]", EXTRACT_16BITS(&op->ospf_len));
826 return;
827 }
828 dataend = bp + length;
829
830 TCHECK(op->ospf_routerid);
831 printf("\n\tRouter-ID: %s", ipaddr_string(&op->ospf_routerid));
832
833 TCHECK(op->ospf_areaid);
834 if (op->ospf_areaid.s_addr != 0)
835 printf(", Area %s", ipaddr_string(&op->ospf_areaid));
836 else
837 printf(", Backbone Area");
838
839 if (vflag) {
840 /* Print authentication data (should we really do this?) */
841 TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
842
843 printf(", Authentication Type: %s (%u)",
844 tok2str(ospf_authtype_values,"unknown",EXTRACT_16BITS(&op->ospf_authtype)),
845 EXTRACT_16BITS(&op->ospf_authtype));
846
847 switch (EXTRACT_16BITS(&op->ospf_authtype)) {
848
849 case OSPF_AUTH_NONE:
850 break;
851
852 case OSPF_AUTH_SIMPLE:
853 (void)fn_printn(op->ospf_authdata,
854 sizeof(op->ospf_authdata), NULL);
855 printf("\"");
856 break;
857
858 case OSPF_AUTH_MD5:
859 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
860 *((op->ospf_authdata)+2),
861 *((op->ospf_authdata)+3),
862 EXTRACT_32BITS((op->ospf_authdata)+4));
863 break;
864
865 default:
866 return;
867 }
868 }
869 /* Do rest according to version. */
870 switch (op->ospf_version) {
871
872 case 2:
873 /* ospf version 2 */
874 if (ospf_decode_v2(op, dataend))
875 goto trunc;
876 break;
877
878 default:
879 printf(" ospf [version %d]", op->ospf_version);
880 break;
881 } /* end switch on version */
882
883 return;
884 trunc:
885 fputs(tstr, stdout);
886 }