2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
25 static const char rcsid
[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.44 2003-10-22 17:08:45 hannes Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
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" },
57 static struct tok ospf_authtype_values
[] = {
58 { OSPF_AUTH_NONE
, "none" },
59 { OSPF_AUTH_NONE
, "simple" },
60 { OSPF_AUTH_MD5
, "MD5" },
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" },
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" },
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" },
96 static struct tok ospf_dd_flag_values
[] = {
97 { OSPF_DB_INIT
, "Init" },
98 { OSPF_DB_MORE
, "More" },
99 { OSPF_DB_MASTER
, "Master" },
103 static struct tok lsa_opaque_values
[] = {
104 { LS_OPAQUE_TYPE_TE
, "Traffic Engineering" },
105 { LS_OPAQUE_TYPE_GRACE
, "Graceful restart" },
109 static struct tok lsa_opaque_te_tlv_values
[] = {
110 { LS_OPAQUE_TE_TLV_ROUTER
, "Router Address" },
111 { LS_OPAQUE_TE_TLV_LINK
, "Link" },
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" },
132 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */
133 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */
135 static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values
[] = {
136 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP
, "Point-to-point" },
137 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA
, "Multi-Access" },
141 static char tstr
[] = " [|ospf]";
144 #define inline __inline
147 static int ospf_print_lshdr(const struct lsa_hdr
*);
148 static int ospf_print_lsa(const struct lsa
*);
149 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
152 ospf_print_lshdr(register const struct lsa_hdr
*lshp
) {
154 TCHECK(lshp
->ls_type
);
155 TCHECK(lshp
->ls_options
);
157 printf("\n\t Advertising Router: %s, seq 0x%08x, age %us, length: %u",
158 ipaddr_string(&lshp
->ls_router
),
159 EXTRACT_32BITS(&lshp
->ls_seq
),
160 EXTRACT_16BITS(&lshp
->ls_age
),
161 EXTRACT_16BITS(&lshp
->ls_length
)-sizeof(struct lsa_hdr
));
163 switch (lshp
->ls_type
) {
164 /* the LSA header for opaque LSAs was slightly changed */
165 case LS_TYPE_OPAQUE_LL
:
166 case LS_TYPE_OPAQUE_AL
:
167 case LS_TYPE_OPAQUE_DW
:
168 printf("\n\t %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u",
169 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
172 tok2str(lsa_opaque_values
,
174 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
)),
175 *(&lshp
->un_lsa_id
.opaque_field
.opaque_type
),
176 EXTRACT_24BITS(&lshp
->un_lsa_id
.opaque_field
.opaque_id
)
181 /* all other LSA types use regular style LSA headers */
183 printf("\n\t %s LSA (%d), LSA-ID: %s",
184 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
186 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
190 printf("\n\t Options: [%s]", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
198 * Print a single link state advertisement. If truncated return 1, else 0.
201 ospf_print_lsa(register const struct lsa
*lsap
)
203 register const u_char
*ls_end
;
204 register const struct rlalink
*rlp
;
205 register const struct tos_metric
*tosp
;
206 register const struct in_addr
*ap
;
207 register const struct aslametric
*almp
;
208 register const struct mcla
*mcp
;
209 register const u_int32_t
*lp
;
210 register int j
, k
,ls_length
, tlv_type
, tlv_length
, subtlv_type
, subtlv_length
, priority_level
;
211 const u_int8_t
*tptr
;
213 union { /* int to float conversion buffer for several subTLVs */
218 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
219 ls_length
= EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
)-sizeof(struct lsa_hdr
);
221 ospf_print_lshdr(&lsap
->ls_hdr
);
223 TCHECK(lsap
->ls_hdr
.ls_length
);
224 ls_end
= (u_char
*)lsap
+ EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
);
226 switch (lsap
->ls_hdr
.ls_type
) {
229 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
230 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values
,"none",lsap
->lsa_un
.un_rla
.rla_flags
));
232 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
233 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
234 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
235 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
238 switch (rlp
->link_type
) {
240 case RLA_TYPE_VIRTUAL
:
241 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
242 ipaddr_string(&rlp
->link_id
),
243 ipaddr_string(&rlp
->link_data
));
246 case RLA_TYPE_ROUTER
:
247 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
248 ipaddr_string(&rlp
->link_id
),
249 ipaddr_string(&rlp
->link_data
));
252 case RLA_TYPE_TRANSIT
:
253 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
254 ipaddr_string(&rlp
->link_id
),
255 ipaddr_string(&rlp
->link_data
));
259 printf("\n\t Stub Network: %s, Mask: %s",
260 ipaddr_string(&rlp
->link_id
),
261 ipaddr_string(&rlp
->link_data
));
265 printf("\n\t Unknown Router Link Type (%u)",
269 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp
->link_tos0metric
));
270 tosp
= (struct tos_metric
*)
271 ((sizeof rlp
->link_tos0metric
) + (u_char
*) rlp
);
272 for (k
= 0; k
< (int) rlp
->link_toscount
; ++k
, ++tosp
) {
274 printf(", tos %d, metric: %d",
276 EXTRACT_16BITS(&tosp
->tos_metric
));
278 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
279 ((rlp
->link_toscount
) * sizeof(*tosp
)));
283 case LS_TYPE_NETWORK
:
284 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
285 printf("\n\t Mask %s\n\t Connected Routers:",
286 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
287 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
288 while ((u_char
*)ap
< ls_end
) {
290 printf("\n\t %s", ipaddr_string(ap
));
296 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
297 printf("\n\t Mask %s",
298 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
299 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
300 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
301 /* suppress tos if its not supported */
302 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
303 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
306 while ((u_char
*)lp
< ls_end
) {
307 register u_int32_t ul
;
310 ul
= EXTRACT_32BITS(lp
);
311 printf(", tos %d metric %d",
312 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
313 ul
& SLA_MASK_METRIC
);
318 case LS_TYPE_SUM_ABR
:
319 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
320 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
321 /* suppress tos if its not supported */
322 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
323 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
326 while ((u_char
*)lp
< ls_end
) {
327 register u_int32_t ul
;
330 ul
= EXTRACT_32BITS(lp
);
331 printf(", tos %d metric %d",
332 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
333 ul
& SLA_MASK_METRIC
);
339 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
340 printf("\n\t Mask %s",
341 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
343 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
344 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
345 while ((u_char
*)almp
< ls_end
) {
346 register u_int32_t ul
;
348 TCHECK(almp
->asla_tosmetric
);
349 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
350 printf(", type %d, tos %d metric:",
351 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1,
352 (ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
353 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
356 printf(" %d", (ul
& ASLA_MASK_METRIC
));
358 TCHECK(almp
->asla_forward
);
359 if (almp
->asla_forward
.s_addr
) {
360 printf(", forward %s",
361 ipaddr_string(&almp
->asla_forward
));
363 TCHECK(almp
->asla_tag
);
364 if (almp
->asla_tag
.s_addr
) {
366 ipaddr_string(&almp
->asla_tag
));
373 /* Multicast extensions as of 23 July 1991 */
374 mcp
= lsap
->lsa_un
.un_mcla
;
375 while ((u_char
*)mcp
< ls_end
) {
376 TCHECK(mcp
->mcla_vid
);
377 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
379 case MCLA_VERTEX_ROUTER
:
380 printf("\n\t Router Router-ID %s",
381 ipaddr_string(&mcp
->mcla_vid
));
384 case MCLA_VERTEX_NETWORK
:
385 printf("\n\t Network Designated Router %s",
386 ipaddr_string(&mcp
->mcla_vid
));
390 printf("\n\t unknown VertexType (%u)",
391 EXTRACT_32BITS(&mcp
->mcla_vtype
));
398 case LS_TYPE_OPAQUE_LL
: /* fall through */
399 case LS_TYPE_OPAQUE_AL
:
400 case LS_TYPE_OPAQUE_DW
:
402 switch (*(&lsap
->ls_hdr
.un_lsa_id
.opaque_field
.opaque_type
)) {
403 case LS_OPAQUE_TYPE_TE
:
404 if (!TTEST2(*tptr
, 4))
407 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
);
409 while (ls_length
> 0) {
410 tlv_type
= EXTRACT_16BITS(tptr
);
411 tlv_length
= EXTRACT_16BITS(tptr
+2);
412 ls_length
-=(tlv_length
+4);
415 printf("\n\t %s TLV (%u), length: %u",
416 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
421 case LS_OPAQUE_TE_TLV_LINK
:
422 while (tlv_length
> 0) {
423 if (!TTEST2(*tptr
, 4))
425 subtlv_type
= EXTRACT_16BITS(tptr
);
426 subtlv_length
= EXTRACT_16BITS(tptr
+2);
430 printf("\n\t %s subTLV (%u), length: %u",
431 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
435 if (!TTEST2(*tptr
, subtlv_length
))
437 switch(subtlv_type
) {
438 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
439 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
441 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID
:
442 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID
:
443 printf(", %s (0x%08x)",
445 EXTRACT_32BITS(tptr
));
446 if (subtlv_length
== 8) /* draft-ietf-ccamp-ospf-gmpls-extensions */
447 printf(", %s (0x%08x)",
448 ipaddr_string(tptr
+4),
449 EXTRACT_32BITS(tptr
+4));
451 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
452 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
453 printf(", %s", ipaddr_string(tptr
));
455 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW
:
456 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW
:
457 bw
.i
= EXTRACT_32BITS(tptr
);
458 printf(", %.3f Mbps", bw
.f
*8/1000000 );
460 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW
:
461 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
462 bw
.i
= EXTRACT_32BITS(tptr
+priority_level
*4);
463 printf("\n\t\tpriority level %d: %.3f Mbps",
468 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
469 printf(", Metric %u", EXTRACT_32BITS(tptr
));
471 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
472 printf(", %s, Priority %u",
473 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
476 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR
:
477 printf("\n\t\tInterface Switching Capability: %s",
478 tok2str(gmpls_switch_cap_values
, "Unknown", *(tptr
)));
479 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
480 tok2str(gmpls_encoding_values
, "Unknown", *(tptr
+1)));
481 for (priority_level
= 0; priority_level
< 8; priority_level
++) {
482 bw
.i
= EXTRACT_32BITS(tptr
+4+(priority_level
*4));
483 printf("\n\t\t priority level %d: %.3f Mbps",
488 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
490 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
494 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
495 count_srlg
= subtlv_length
/ 4;
497 printf("\n\t\t Shared risk group: ");
498 while (count_srlg
> 0) {
499 bw
.i
= EXTRACT_32BITS(tptr
);
510 if(!print_unknown_data(tptr
,"\n\t\t",subtlv_length
))
515 /* in OSPF everything has to be 32-bit aligned, including TLVs */
516 if (subtlv_length
%4 != 0)
517 subtlv_length
+=4-(subtlv_length
%4);
519 tlv_length
-=subtlv_length
;
525 case LS_OPAQUE_TE_TLV_ROUTER
:
526 printf(", %s", ipaddr_string(tptr
));
531 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
543 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
544 "\n\t ", EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
)-sizeof(struct lsa_hdr
)))
550 /* do we want to see an additionally hexdump ? */
552 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
553 "\n\t ", EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
)-sizeof(struct lsa_hdr
))) {
563 ospf_decode_v2(register const struct ospfhdr
*op
,
564 register const u_char
*dataend
)
566 register const struct in_addr
*ap
;
567 register const struct lsr
*lsrp
;
568 register const struct lsa_hdr
*lshp
;
569 register const struct lsa
*lsap
;
570 register u_int32_t lsa_count
,lsa_count_max
;
572 switch (op
->ospf_type
) {
576 * Rob Coltun's special monitoring packets;
581 case OSPF_TYPE_HELLO
:
582 printf("\n\tOptions: [%s]",
583 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
585 TCHECK(op
->ospf_hello
.hello_deadint
);
586 printf("\n\t Hello Timer: %us, Dead Timer %us, Mask: %s, Priority: %u",
587 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
588 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
589 ipaddr_string(&op
->ospf_hello
.hello_mask
),
590 op
->ospf_hello
.hello_priority
);
592 TCHECK(op
->ospf_hello
.hello_dr
);
593 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
594 printf("\n\t Designated Router %s",
595 ipaddr_string(&op
->ospf_hello
.hello_dr
));
597 TCHECK(op
->ospf_hello
.hello_bdr
);
598 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
599 printf(", Backup Designated Router %s",
600 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
602 ap
= op
->ospf_hello
.hello_neighbor
;
603 if ((u_char
*)ap
< dataend
)
604 printf("\n\t Neighbor List:");
605 while ((u_char
*)ap
< dataend
) {
607 printf("\n\t %s", ipaddr_string(ap
));
613 TCHECK(op
->ospf_db
.db_options
);
614 printf("\n\tOptions: [%s]",
615 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
616 TCHECK(op
->ospf_db
.db_flags
);
617 printf(", DD Flags: [%s]",
618 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
621 /* Print all the LS adv's */
622 lshp
= op
->ospf_db
.db_lshdr
;
623 while (!ospf_print_lshdr(lshp
)) {
629 case OSPF_TYPE_LS_REQ
:
631 while ((u_char
*)lsrp
< dataend
) {
634 printf("\n\t Advertising Router: %s, %s LSA (%u)",
635 ipaddr_string(&lsrp
->ls_router
),
636 tok2str(lsa_values
,"unknown",EXTRACT_32BITS(lsrp
->ls_type
)),
637 EXTRACT_32BITS(&lsrp
->ls_type
));
639 switch (EXTRACT_32BITS(lsrp
->ls_type
)) {
640 /* the LSA header for opaque LSAs was slightly changed */
641 case LS_TYPE_OPAQUE_LL
:
642 case LS_TYPE_OPAQUE_AL
:
643 case LS_TYPE_OPAQUE_DW
:
644 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
645 tok2str(lsa_opaque_values
, "unknown",lsrp
->un_ls_stateid
.opaque_field
.opaque_type
),
646 lsrp
->un_ls_stateid
.opaque_field
.opaque_type
,
647 EXTRACT_24BITS(&lsrp
->un_ls_stateid
.opaque_field
.opaque_id
));
650 printf(", LSA-ID: %s",
651 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
659 case OSPF_TYPE_LS_UPDATE
:
660 lsap
= op
->ospf_lsu
.lsu_lsa
;
661 TCHECK(op
->ospf_lsu
.lsu_count
);
662 lsa_count_max
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
663 printf(", %d LSA%s",lsa_count_max
, lsa_count_max
> 1 ? "s" : "");
664 for (lsa_count
=1;lsa_count
<= lsa_count_max
;lsa_count
++) {
665 printf("\n\t LSA #%u",lsa_count
);
666 if (ospf_print_lsa(lsap
))
668 lsap
= (struct lsa
*)((u_char
*)lsap
+
669 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
));
673 case OSPF_TYPE_LS_ACK
:
674 lshp
= op
->ospf_lsa
.lsa_lshdr
;
675 while (!ospf_print_lshdr(lshp
)) {
681 printf("v2 type (%d)", op
->ospf_type
);
690 ospf_print(register const u_char
*bp
, register u_int length
,
691 register const u_char
*bp2
)
693 register const struct ospfhdr
*op
;
694 register const struct ip
*ip
;
695 register const u_char
*dataend
;
696 register const char *cp
;
698 op
= (struct ospfhdr
*)bp
;
699 ip
= (struct ip
*)bp2
;
701 /* XXX Before we do anything else, strip off the MD5 trailer */
702 TCHECK(op
->ospf_authtype
);
703 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
704 length
-= OSPF_AUTH_MD5_LEN
;
705 snapend
-= OSPF_AUTH_MD5_LEN
;
708 /* If the type is valid translate it, or just print the type */
709 /* value. If it's not valid, say so and return */
710 TCHECK(op
->ospf_type
);
711 cp
= tok2str(type2str
, "unknown LS-type", op
->ospf_type
);
712 printf("OSPFv%u, %s (%u), length: %u",
720 if(!vflag
) /* non verbose - so lets bail out here */
723 TCHECK(op
->ospf_len
);
724 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
725 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
728 dataend
= bp
+ length
;
730 TCHECK(op
->ospf_routerid
);
731 printf("\n\tRouter-ID: %s", ipaddr_string(&op
->ospf_routerid
));
733 TCHECK(op
->ospf_areaid
);
734 if (op
->ospf_areaid
.s_addr
!= 0)
735 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
737 printf(", Backbone Area");
740 /* Print authentication data (should we really do this?) */
741 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
743 printf(", Authentication Type: %s (%u)",
744 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
745 EXTRACT_16BITS(&op
->ospf_authtype
));
747 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
752 case OSPF_AUTH_SIMPLE
:
753 (void)fn_printn(op
->ospf_authdata
,
754 sizeof(op
->ospf_authdata
), NULL
);
759 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
760 *((op
->ospf_authdata
)+2),
761 *((op
->ospf_authdata
)+3),
762 EXTRACT_32BITS((op
->ospf_authdata
)+4));
769 /* Do rest according to version. */
770 switch (op
->ospf_version
) {
774 if (ospf_decode_v2(op
, dataend
))
779 printf(" ospf [version %d]", op
->ospf_version
);
781 } /* end switch on version */