]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
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.36 2002-12-23 19:57:49 hannes Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
37 #include "interface.h"
38 #include "addrtoname.h"
45 static struct tok ospf_option_values
[] = {
46 { OSPF_OPTION_T
, "TOS" },
47 { OSPF_OPTION_E
, "External" },
48 { OSPF_OPTION_MC
, "Multicast" },
49 { OSPF_OPTION_NP
, "NSSA" },
50 { OSPF_OPTION_EA
, "Advertise External" },
51 { OSPF_OPTION_DC
, "Demand Circuit" },
52 { OSPF_OPTION_O
, "Opaque" },
56 static struct tok ospf_authtype_values
[] = {
57 { OSPF_AUTH_NONE
, "none" },
58 { OSPF_AUTH_NONE
, "simple" },
59 { OSPF_AUTH_MD5
, "MD5" },
63 static struct tok ospf_rla_flag_values
[] = {
64 { RLA_FLAG_B
, "ABR" },
65 { RLA_FLAG_E
, "ASBR" },
66 { RLA_FLAG_W1
, "Virtual" },
67 { RLA_FLAG_W2
, "W2" },
71 static struct tok type2str
[] = {
72 { OSPF_TYPE_UMD
, "UMD" },
73 { OSPF_TYPE_HELLO
, "Hello" },
74 { OSPF_TYPE_DD
, "Database Description" },
75 { OSPF_TYPE_LS_REQ
, "LS-Request" },
76 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
77 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
81 static struct tok lsa_values
[] = {
82 { LS_TYPE_ROUTER
, "Router" },
83 { LS_TYPE_NETWORK
, "Network" },
84 { LS_TYPE_SUM_IP
, "Summary" },
85 { LS_TYPE_SUM_ABR
, "ASBR Summary" },
86 { LS_TYPE_ASE
, "External" },
87 { LS_TYPE_GROUP
, "Multicast Group" },
88 { LS_TYPE_NSSA
, "NSSA" },
89 { LS_TYPE_OPAQUE_LL
, "Link Local Opaque" },
90 { LS_TYPE_OPAQUE_AL
, "Area Local Opaque" },
91 { LS_TYPE_OPAQUE_DW
, "Domain Wide Opaque" },
95 static struct tok ospf_dd_flag_values
[] = {
96 { OSPF_DB_INIT
, "Init" },
97 { OSPF_DB_MORE
, "More" },
98 { OSPF_DB_MASTER
, "Master" },
102 static char tstr
[] = " [|ospf]";
105 #define inline __inline
108 static int ospf_print_lshdr(const struct lsa_hdr
*);
109 static int ospf_print_lsa(const struct lsa
*);
110 static int ospf_decode_v2(const struct ospfhdr
*, const u_char
*);
113 ospf_print_lshdr(register const struct lsa_hdr
*lshp
) {
115 TCHECK(lshp
->ls_type
);
116 TCHECK(lshp
->ls_options
);
118 printf("\n\t %s LSA (%d), LSA-ID: %s, Advertising Router: %s, seq 0x%08x, age %us",
119 tok2str(lsa_values
,"unknown",lshp
->ls_type
),
121 ipaddr_string(&lshp
->ls_stateid
),
122 ipaddr_string(&lshp
->ls_router
),
123 EXTRACT_32BITS(&lshp
->ls_seq
),
124 EXTRACT_16BITS(&lshp
->ls_age
));
125 printf("\n\t Options: %s", bittok2str(ospf_option_values
,"none",lshp
->ls_options
));
133 * Print a single link state advertisement. If truncated return 1, else 0.
136 ospf_print_lsa(register const struct lsa
*lsap
)
138 register const u_char
*ls_end
;
139 register const struct rlalink
*rlp
;
140 register const struct tos_metric
*tosp
;
141 register const struct in_addr
*ap
;
142 register const struct aslametric
*almp
;
143 register const struct mcla
*mcp
;
144 register const u_int32_t
*lp
;
147 printf("\n\t %s LSA (%d), LSA-ID: %s, Advertising Router: %s, seq 0x%08x, age %us",
148 tok2str(lsa_values
,"unknown",lsap
->ls_hdr
.ls_type
),
149 lsap
->ls_hdr
.ls_type
,
150 ipaddr_string(&lsap
->ls_hdr
.ls_stateid
),
151 ipaddr_string(&lsap
->ls_hdr
.ls_router
),
152 EXTRACT_32BITS(&lsap
->ls_hdr
.ls_seq
),
153 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_age
));
154 printf("\n\t Options: %s", bittok2str(ospf_option_values
,"none",lsap
->ls_hdr
.ls_options
));
156 TCHECK(lsap
->ls_hdr
.ls_length
);
157 ls_end
= (u_char
*)lsap
+ EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
);
158 switch (lsap
->ls_hdr
.ls_type
) {
161 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
162 printf("\n\t Router LSA Options: %s", bittok2str(ospf_rla_flag_values
,"unknown (%u)",lsap
->lsa_un
.un_rla
.rla_flags
));
164 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
165 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
166 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
167 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
170 switch (rlp
->link_type
) {
172 case RLA_TYPE_VIRTUAL
:
173 printf("\n\t Virtual Link: Neighbor-Router-ID: %s, Interface-IP: %s",
174 ipaddr_string(&rlp
->link_id
),
175 ipaddr_string(&rlp
->link_data
));
178 case RLA_TYPE_ROUTER
:
179 printf("\n\t Neighbor-Router-ID: %s, Interface-IP: %s",
180 ipaddr_string(&rlp
->link_id
),
181 ipaddr_string(&rlp
->link_data
));
184 case RLA_TYPE_TRANSIT
:
185 printf("\n\t Neighbor-Network-ID: %s, Interface-IP: %s",
186 ipaddr_string(&rlp
->link_id
),
187 ipaddr_string(&rlp
->link_data
));
191 printf("\n\t Stub-Network: %s, mask: %s",
192 ipaddr_string(&rlp
->link_id
),
193 ipaddr_string(&rlp
->link_data
));
197 printf("\n\t unknown Router Links Type (%u)",
201 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp
->link_tos0metric
));
202 tosp
= (struct tos_metric
*)
203 ((sizeof rlp
->link_tos0metric
) + (u_char
*) rlp
);
204 for (k
= 0; k
< (int) rlp
->link_toscount
; ++k
, ++tosp
) {
206 printf(", tos %d, metric: %d",
208 EXTRACT_16BITS(&tosp
->tos_metric
));
210 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
211 ((rlp
->link_toscount
) * sizeof(*tosp
)));
215 case LS_TYPE_NETWORK
:
216 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
217 printf("\n\t mask %s rtrs",
218 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
219 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
220 while ((u_char
*)ap
< ls_end
) {
222 printf(" %s", ipaddr_string(ap
));
228 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
229 printf("\n\t mask %s",
230 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
231 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
232 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
233 /* suppress tos if its not supported */
234 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
235 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
238 while ((u_char
*)lp
< ls_end
) {
239 register u_int32_t ul
;
242 ul
= EXTRACT_32BITS(lp
);
243 printf(", tos %d metric %d",
244 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
245 ul
& SLA_MASK_METRIC
);
250 case LS_TYPE_SUM_ABR
:
251 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
252 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
253 /* suppress tos if its not supported */
254 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
255 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
258 while ((u_char
*)lp
< ls_end
) {
259 register u_int32_t ul
;
262 ul
= EXTRACT_32BITS(lp
);
263 printf(", tos %d metric %d",
264 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
265 ul
& SLA_MASK_METRIC
);
271 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
272 printf("\n\t mask %s",
273 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
275 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
276 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
277 while ((u_char
*)almp
< ls_end
) {
278 register u_int32_t ul
;
280 TCHECK(almp
->asla_tosmetric
);
281 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
282 printf(", type %d, tos %d metric:",
283 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1,
284 (ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
285 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
288 printf(" %d", (ul
& ASLA_MASK_METRIC
));
290 TCHECK(almp
->asla_forward
);
291 if (almp
->asla_forward
.s_addr
) {
292 printf(", forward %s",
293 ipaddr_string(&almp
->asla_forward
));
295 TCHECK(almp
->asla_tag
);
296 if (almp
->asla_tag
.s_addr
) {
298 ipaddr_string(&almp
->asla_tag
));
305 /* Multicast extensions as of 23 July 1991 */
306 mcp
= lsap
->lsa_un
.un_mcla
;
307 while ((u_char
*)mcp
< ls_end
) {
308 TCHECK(mcp
->mcla_vid
);
309 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
311 case MCLA_VERTEX_ROUTER
:
312 printf("\n\t Router Router-ID %s",
313 ipaddr_string(&mcp
->mcla_vid
));
316 case MCLA_VERTEX_NETWORK
:
317 printf("\n\t Network Designated Router %s",
318 ipaddr_string(&mcp
->mcla_vid
));
322 printf("\n\t unknown VertexType (%u)",
323 EXTRACT_32BITS(&mcp
->mcla_vtype
));
336 ospf_decode_v2(register const struct ospfhdr
*op
,
337 register const u_char
*dataend
)
339 register const struct in_addr
*ap
;
340 register const struct lsr
*lsrp
;
341 register const struct lsa_hdr
*lshp
;
342 register const struct lsa
*lsap
;
343 register int lsa_count
;
345 switch (op
->ospf_type
) {
349 * Rob Coltun's special monitoring packets;
354 case OSPF_TYPE_HELLO
:
355 TCHECK(op
->ospf_hello
.hello_deadint
);
356 printf("\n\t Hello Timer: %us, Dead Timer %us, mask: %s, Priority: %u",
357 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
358 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
359 ipaddr_string(&op
->ospf_hello
.hello_mask
),
360 op
->ospf_hello
.hello_priority
);
362 printf("\n\t Options: %s",
363 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
365 TCHECK(op
->ospf_hello
.hello_dr
);
366 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
367 printf("\n\t Designated Router %s",
368 ipaddr_string(&op
->ospf_hello
.hello_dr
));
370 TCHECK(op
->ospf_hello
.hello_bdr
);
371 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
372 printf(", Backup Designated Router %s",
373 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
375 ap
= op
->ospf_hello
.hello_neighbor
;
376 if ((u_char
*)ap
< dataend
)
377 printf("\n\t Neighbor List:");
378 while ((u_char
*)ap
< dataend
) {
380 printf("\n\t %s", ipaddr_string(ap
));
386 TCHECK(op
->ospf_db
.db_options
);
387 printf("\n\t Options: %s",
388 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
389 TCHECK(op
->ospf_db
.db_flags
);
390 printf("\n\t DD Flags: %s",
391 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
394 /* Print all the LS adv's */
395 lshp
= op
->ospf_db
.db_lshdr
;
396 while (!ospf_print_lshdr(lshp
)) {
402 case OSPF_TYPE_LS_REQ
:
404 while ((u_char
*)lsrp
< dataend
) {
407 printf("\n\t %s LSA (%d), LSA-ID: %s, Advertising Router: %s",
408 tok2str(lsa_values
,"unknown",lsrp
->ls_type
),
410 ipaddr_string(&lsrp
->ls_stateid
),
411 ipaddr_string(&lsrp
->ls_router
));
416 case OSPF_TYPE_LS_UPDATE
:
417 lsap
= op
->ospf_lsu
.lsu_lsa
;
418 TCHECK(op
->ospf_lsu
.lsu_count
);
419 lsa_count
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
420 printf(", %d LSA%s",lsa_count
, lsa_count
> 1 ? "s" : "");
421 while (lsa_count
--) {
422 if (ospf_print_lsa(lsap
))
424 lsap
= (struct lsa
*)((u_char
*)lsap
+
425 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
));
429 case OSPF_TYPE_LS_ACK
:
430 lshp
= op
->ospf_lsa
.lsa_lshdr
;
431 while (!ospf_print_lshdr(lshp
)) {
437 printf("v2 type (%d)", op
->ospf_type
);
446 ospf_print(register const u_char
*bp
, register u_int length
,
447 register const u_char
*bp2
)
449 register const struct ospfhdr
*op
;
450 register const struct ip
*ip
;
451 register const u_char
*dataend
;
452 register const char *cp
;
454 op
= (struct ospfhdr
*)bp
;
455 ip
= (struct ip
*)bp2
;
457 /* XXX Before we do anything else, strip off the MD5 trailer */
458 TCHECK(op
->ospf_authtype
);
459 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
460 length
-= OSPF_AUTH_MD5_LEN
;
461 snapend
-= OSPF_AUTH_MD5_LEN
;
464 /* If the type is valid translate it, or just print the type */
465 /* value. If it's not valid, say so and return */
466 TCHECK(op
->ospf_type
);
467 cp
= tok2str(type2str
, "unknown LS-Type %d", op
->ospf_type
);
468 printf("OSPFv%d %s length: %d", op
->ospf_version
, cp
, length
);
472 if(!vflag
) /* non verbose - so lets bail out here */
475 TCHECK(op
->ospf_len
);
476 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
477 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
480 dataend
= bp
+ length
;
482 TCHECK(op
->ospf_routerid
);
483 printf("\n\tRouter-ID: %s", ipaddr_string(&op
->ospf_routerid
));
485 TCHECK(op
->ospf_areaid
);
486 if (op
->ospf_areaid
.s_addr
!= 0)
487 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
489 printf(", Backbone Area");
492 /* Print authentication data (should we really do this?) */
493 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
495 printf(", Authentication Type: %s (%u)",
496 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
497 EXTRACT_16BITS(&op
->ospf_authtype
));
499 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
504 case OSPF_AUTH_SIMPLE
:
505 (void)fn_printn(op
->ospf_authdata
,
506 sizeof(op
->ospf_authdata
), NULL
);
511 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
512 *((op
->ospf_authdata
)+2),
513 *((op
->ospf_authdata
)+3),
514 EXTRACT_32BITS((op
->ospf_authdata
)+4));
521 /* Do rest according to version. */
522 switch (op
->ospf_version
) {
526 if (ospf_decode_v2(op
, dataend
))
531 printf(" ospf [version %d]", op
->ospf_version
);
533 } /* end switch on version */