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