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
[] _U_
=
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.49 2004-01-08 22:08:40 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 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" },
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" },
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" },
153 static char tstr
[] = " [|ospf]";
156 #define inline __inline
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
*);
164 ospf_print_lshdr(register const struct lsa_hdr
*lshp
)
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
));
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
));
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
),
193 tok2str(lsa_opaque_values
,
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
)
202 /* all other LSA types use regular style LSA headers */
204 printf("\n\t %s LSA (%d), LSA-ID: %s",
205 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
207 ipaddr_string(&lshp
->un_lsa_id
.lsa_id
));
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
));
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.
224 static const u_int8_t
*
225 ospf_print_lsa(register const struct lsa
*lsap
)
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
;
238 union { /* int to float conversion buffer for several subTLVs */
243 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_unknown
; /* squelch compiler warnings */
244 ls_length
= ospf_print_lshdr(&lsap
->ls_hdr
);
247 ls_end
= (u_int8_t
*)lsap
+ ls_length
;
248 ls_length
-= sizeof(struct lsa_hdr
);
250 switch (lsap
->ls_hdr
.ls_type
) {
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
));
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
;
262 switch (rlp
->link_type
) {
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
));
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
));
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
));
283 printf("\n\t Stub Network: %s, Mask: %s",
284 ipaddr_string(&rlp
->link_id
),
285 ipaddr_string(&rlp
->link_data
));
289 printf("\n\t Unknown Router Link Type (%u)",
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
) {
298 printf(", tos %d, metric: %d",
300 EXTRACT_16BITS(&tosp
->tos_metric
));
302 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
303 ((rlp
->link_toscount
) * sizeof(*tosp
)));
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
) {
314 printf("\n\t %s", ipaddr_string(ap
));
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
);
330 while ((u_char
*)lp
< ls_end
) {
331 register u_int32_t ul
;
334 ul
= EXTRACT_32BITS(lp
);
335 printf(", tos %d metric %d",
336 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
337 ul
& SLA_MASK_METRIC
);
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
);
350 while ((u_char
*)lp
< ls_end
) {
351 register u_int32_t ul
;
354 ul
= EXTRACT_32BITS(lp
);
355 printf(", tos %d metric %d",
356 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
357 ul
& SLA_MASK_METRIC
);
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
));
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
;
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)
380 printf(" %d", (ul
& ASLA_MASK_METRIC
));
382 TCHECK(almp
->asla_forward
);
383 if (almp
->asla_forward
.s_addr
) {
384 printf(", forward %s",
385 ipaddr_string(&almp
->asla_forward
));
387 TCHECK(almp
->asla_tag
);
388 if (almp
->asla_tag
.s_addr
) {
390 ipaddr_string(&almp
->asla_tag
));
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
)) {
403 case MCLA_VERTEX_ROUTER
:
404 printf("\n\t Router Router-ID %s",
405 ipaddr_string(&mcp
->mcla_vid
));
408 case MCLA_VERTEX_NETWORK
:
409 printf("\n\t Network Designated Router %s",
410 ipaddr_string(&mcp
->mcla_vid
));
414 printf("\n\t unknown VertexType (%u)",
415 EXTRACT_32BITS(&mcp
->mcla_vtype
));
422 case LS_TYPE_OPAQUE_LL
: /* fall through */
423 case LS_TYPE_OPAQUE_AL
:
424 case LS_TYPE_OPAQUE_DW
:
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
);
430 while (ls_length
!= 0) {
431 if (!TTEST2(*tptr
, 4))
434 printf("\n\t Remaining LS length %u < 4", ls_length
);
437 tlv_type
= EXTRACT_16BITS(tptr
);
438 tlv_length
= EXTRACT_16BITS(tptr
+2);
442 printf("\n\t %s TLV (%u), length: %u, value: ",
443 tok2str(lsa_opaque_grace_tlv_values
,"unknown",tlv_type
),
447 if (tlv_length
> ls_length
) {
448 printf("\n\t Bogus length %u > %u", tlv_length
,
452 ls_length
-=tlv_length
;
455 case LS_OPAQUE_GRACE_TLV_PERIOD
:
456 if (tlv_length
!= 4) {
457 printf("\n\t Bogus length %u != 4", tlv_length
);
460 printf("%us",EXTRACT_32BITS(tptr
));
462 case LS_OPAQUE_GRACE_TLV_REASON
:
463 if (tlv_length
!= 1) {
464 printf("\n\t Bogus length %u != 1", tlv_length
);
468 tok2str(lsa_opaque_grace_tlv_reason_values
, "Unknown", *tptr
),
471 case LS_OPAQUE_GRACE_TLV_INT_ADDRESS
:
472 if (tlv_length
!= 4) {
473 printf("\n\t Bogus length %u != 4", tlv_length
);
476 printf("%s", ipaddr_string(tptr
));
480 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
490 case LS_OPAQUE_TYPE_TE
:
491 tptr
= (u_int8_t
*)(&lsap
->lsa_un
.un_te_lsa_tlv
.type
);
493 while (ls_length
!= 0) {
494 if (!TTEST2(*tptr
, 4))
497 printf("\n\t Remaining LS length %u < 4", ls_length
);
500 tlv_type
= EXTRACT_16BITS(tptr
);
501 tlv_length
= EXTRACT_16BITS(tptr
+2);
505 printf("\n\t %s TLV (%u), length: %u",
506 tok2str(lsa_opaque_te_tlv_values
,"unknown",tlv_type
),
510 if (tlv_length
> ls_length
) {
511 printf("\n\t Bogus length %u > %u", tlv_length
,
515 ls_length
-=tlv_length
;
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",
524 if (!TTEST2(*tptr
, 4))
526 subtlv_type
= EXTRACT_16BITS(tptr
);
527 subtlv_length
= EXTRACT_16BITS(tptr
+2);
531 printf("\n\t %s subTLV (%u), length: %u",
532 tok2str(lsa_opaque_te_link_tlv_subtlv_values
,"unknown",subtlv_type
),
536 if (!TTEST2(*tptr
, subtlv_length
))
538 switch(subtlv_type
) {
539 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP
:
540 printf(", 0x%08x", EXTRACT_32BITS(tptr
));
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)",
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));
552 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP
:
553 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP
:
554 printf(", %s", ipaddr_string(tptr
));
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 );
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",
569 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC
:
570 printf(", Metric %u", EXTRACT_32BITS(tptr
));
572 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE
:
573 printf(", %s, Priority %u",
574 bittok2str(gmpls_link_prot_values
, "none", *tptr
),
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",
589 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE
:
591 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values
,"unknown",*tptr
),
595 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP
:
596 count_srlg
= subtlv_length
/ 4;
598 printf("\n\t\t Shared risk group: ");
599 while (count_srlg
> 0) {
600 bw
.i
= EXTRACT_32BITS(tptr
);
611 if(!print_unknown_data(tptr
,"\n\t\t",subtlv_length
))
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);
620 tlv_length
-=subtlv_length
;
626 case LS_OPAQUE_TE_TLV_ROUTER
:
627 printf(", %s", ipaddr_string(tptr
));
632 if(!print_unknown_data(tptr
,"\n\t ",tlv_length
))
644 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
651 /* do we want to see an additionally hexdump ? */
653 if(!print_unknown_data((u_int8_t
*)lsap
->lsa_un
.un_unknown
,
654 "\n\t ", ls_length
)) {
664 ospf_decode_v2(register const struct ospfhdr
*op
,
665 register const u_char
*dataend
)
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
;
673 switch (op
->ospf_type
) {
677 * Rob Coltun's special monitoring packets;
682 case OSPF_TYPE_HELLO
:
683 printf("\n\tOptions: [%s]",
684 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
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
);
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
));
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
));
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
) {
708 printf("\n\t %s", ipaddr_string(ap
));
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
));
722 /* Print all the LS adv's */
723 lshp
= op
->ospf_db
.db_lshdr
;
724 while (ospf_print_lshdr(lshp
) != -1) {
730 case OSPF_TYPE_LS_REQ
:
732 while ((u_char
*)lsrp
< dataend
) {
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
));
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
));
751 printf(", LSA-ID: %s",
752 ipaddr_string(&lsrp
->un_ls_stateid
.ls_stateid
));
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
);
773 case OSPF_TYPE_LS_ACK
:
774 lshp
= op
->ospf_lsa
.lsa_lshdr
;
775 while (ospf_print_lshdr(lshp
) != -1) {
781 printf("v2 type (%d)", op
->ospf_type
);
790 ospf_print(register const u_char
*bp
, register u_int length
,
791 register const u_char
*bp2
)
793 register const struct ospfhdr
*op
;
794 register const struct ip
*ip
;
795 register const u_char
*dataend
;
796 register const char *cp
;
798 op
= (struct ospfhdr
*)bp
;
799 ip
= (struct ip
*)bp2
;
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
;
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",
820 if(!vflag
) /* non verbose - so lets bail out here */
823 TCHECK(op
->ospf_len
);
824 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
825 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
828 dataend
= bp
+ length
;
830 TCHECK(op
->ospf_routerid
);
831 printf("\n\tRouter-ID: %s", ipaddr_string(&op
->ospf_routerid
));
833 TCHECK(op
->ospf_areaid
);
834 if (op
->ospf_areaid
.s_addr
!= 0)
835 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
837 printf(", Backbone Area");
840 /* Print authentication data (should we really do this?) */
841 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
843 printf(", Authentication Type: %s (%u)",
844 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
845 EXTRACT_16BITS(&op
->ospf_authtype
));
847 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
852 case OSPF_AUTH_SIMPLE
:
853 (void)fn_printn(op
->ospf_authdata
,
854 sizeof(op
->ospf_authdata
), NULL
);
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));
869 /* Do rest according to version. */
870 switch (op
->ospf_version
) {
874 if (ospf_decode_v2(op
, dataend
))
879 printf(" ospf [version %d]", op
->ospf_version
);
881 } /* end switch on version */