]>
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.39 2003-10-03 13:20:46 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 Advertising Router: %s, seq 0x%08x, age %us",
148 ipaddr_string(&lsap
->ls_hdr
.ls_router
),
149 EXTRACT_32BITS(&lsap
->ls_hdr
.ls_seq
),
150 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_age
));
152 switch (lsap
->ls_hdr
.ls_type
) {
153 /* the LSA header for opaque LSAs was slightly changed */
154 case LS_TYPE_OPAQUE_LL
:
155 case LS_TYPE_OPAQUE_AL
:
156 case LS_TYPE_OPAQUE_DW
:
158 printf("\n\t %s LSA (%d), Opaque-Type: %u, Opaque-ID: %u",
159 tok2str(lsa_values
,"unknown",lsap
->ls_hdr
.ls_type
),
160 (lsap
->ls_hdr
.ls_type
),
161 *(&lsap
->ls_hdr
.opaque_type
),
162 EXTRACT_24BITS(&lsap
->ls_hdr
.opaque_id
));
165 /* all other LSA types use regular style LSA headers */
167 printf("\n\t %s LSA (%d), LSA-ID: %s",
168 tok2str(lsa_values
,"unknown",lsap
->ls_hdr
.ls_type
),
169 lsap
->ls_hdr
.ls_type
,
170 ipaddr_string(&lsap
->ls_hdr
.ls_stateid
));
174 printf("\n\t Options: %s", bittok2str(ospf_option_values
,"none",lsap
->ls_hdr
.ls_options
));
176 TCHECK(lsap
->ls_hdr
.ls_length
);
177 ls_end
= (u_char
*)lsap
+ EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
);
178 switch (lsap
->ls_hdr
.ls_type
) {
181 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
182 printf("\n\t Router LSA Options: %s", bittok2str(ospf_rla_flag_values
,"unknown (%u)",lsap
->lsa_un
.un_rla
.rla_flags
));
184 TCHECK(lsap
->lsa_un
.un_rla
.rla_count
);
185 j
= EXTRACT_16BITS(&lsap
->lsa_un
.un_rla
.rla_count
);
186 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
187 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
190 switch (rlp
->link_type
) {
192 case RLA_TYPE_VIRTUAL
:
193 printf("\n\t Virtual Link: Neighbor-Router-ID: %s, Interface-IP: %s",
194 ipaddr_string(&rlp
->link_id
),
195 ipaddr_string(&rlp
->link_data
));
198 case RLA_TYPE_ROUTER
:
199 printf("\n\t Neighbor-Router-ID: %s, Interface-IP: %s",
200 ipaddr_string(&rlp
->link_id
),
201 ipaddr_string(&rlp
->link_data
));
204 case RLA_TYPE_TRANSIT
:
205 printf("\n\t Neighbor-Network-ID: %s, Interface-IP: %s",
206 ipaddr_string(&rlp
->link_id
),
207 ipaddr_string(&rlp
->link_data
));
211 printf("\n\t Stub-Network: %s, mask: %s",
212 ipaddr_string(&rlp
->link_id
),
213 ipaddr_string(&rlp
->link_data
));
217 printf("\n\t unknown Router Links Type (%u)",
221 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp
->link_tos0metric
));
222 tosp
= (struct tos_metric
*)
223 ((sizeof rlp
->link_tos0metric
) + (u_char
*) rlp
);
224 for (k
= 0; k
< (int) rlp
->link_toscount
; ++k
, ++tosp
) {
226 printf(", tos %d, metric: %d",
228 EXTRACT_16BITS(&tosp
->tos_metric
));
230 rlp
= (struct rlalink
*)((u_char
*)(rlp
+ 1) +
231 ((rlp
->link_toscount
) * sizeof(*tosp
)));
235 case LS_TYPE_NETWORK
:
236 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
237 printf("\n\t mask %s rtrs",
238 ipaddr_string(&lsap
->lsa_un
.un_nla
.nla_mask
));
239 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
240 while ((u_char
*)ap
< ls_end
) {
242 printf(" %s", ipaddr_string(ap
));
248 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
249 printf("\n\t mask %s",
250 ipaddr_string(&lsap
->lsa_un
.un_sla
.sla_mask
));
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
);
270 case LS_TYPE_SUM_ABR
:
271 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
272 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
273 /* suppress tos if its not supported */
274 if(!((lsap
->ls_hdr
.ls_options
)&OSPF_OPTION_T
)) {
275 printf(", metric: %u", EXTRACT_32BITS(lp
)&SLA_MASK_METRIC
);
278 while ((u_char
*)lp
< ls_end
) {
279 register u_int32_t ul
;
282 ul
= EXTRACT_32BITS(lp
);
283 printf(", tos %d metric %d",
284 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
285 ul
& SLA_MASK_METRIC
);
291 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
292 printf("\n\t mask %s",
293 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
295 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
296 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
297 while ((u_char
*)almp
< ls_end
) {
298 register u_int32_t ul
;
300 TCHECK(almp
->asla_tosmetric
);
301 ul
= EXTRACT_32BITS(&almp
->asla_tosmetric
);
302 printf(", type %d, tos %d metric:",
303 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1,
304 (ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
);
305 if ((ul
& ASLA_MASK_METRIC
)==0xffffff)
308 printf(" %d", (ul
& ASLA_MASK_METRIC
));
310 TCHECK(almp
->asla_forward
);
311 if (almp
->asla_forward
.s_addr
) {
312 printf(", forward %s",
313 ipaddr_string(&almp
->asla_forward
));
315 TCHECK(almp
->asla_tag
);
316 if (almp
->asla_tag
.s_addr
) {
318 ipaddr_string(&almp
->asla_tag
));
325 /* Multicast extensions as of 23 July 1991 */
326 mcp
= lsap
->lsa_un
.un_mcla
;
327 while ((u_char
*)mcp
< ls_end
) {
328 TCHECK(mcp
->mcla_vid
);
329 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
331 case MCLA_VERTEX_ROUTER
:
332 printf("\n\t Router Router-ID %s",
333 ipaddr_string(&mcp
->mcla_vid
));
336 case MCLA_VERTEX_NETWORK
:
337 printf("\n\t Network Designated Router %s",
338 ipaddr_string(&mcp
->mcla_vid
));
342 printf("\n\t unknown VertexType (%u)",
343 EXTRACT_32BITS(&mcp
->mcla_vtype
));
351 * FIXME those are the defined LSAs that lack a decoder
352 * you are welcome to contribute code ;-)
355 case LS_TYPE_OPAQUE_LL
:
356 case LS_TYPE_OPAQUE_AL
:
357 case LS_TYPE_OPAQUE_DW
:
361 if(!print_unknown_data((u_char
*)lsap
->lsa_un
.un_unknown
,
362 "\n\t ", EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
)-sizeof(struct lsa_hdr
)))
368 /* do we want to see an additionally hexdump ? */
370 if(!print_unknown_data((u_char
*)lsap
->lsa_un
.un_unknown
,
371 "\n\t ", EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
)-sizeof(struct lsa_hdr
)))
381 ospf_decode_v2(register const struct ospfhdr
*op
,
382 register const u_char
*dataend
)
384 register const struct in_addr
*ap
;
385 register const struct lsr
*lsrp
;
386 register const struct lsa_hdr
*lshp
;
387 register const struct lsa
*lsap
;
388 register int lsa_count
;
390 switch (op
->ospf_type
) {
394 * Rob Coltun's special monitoring packets;
399 case OSPF_TYPE_HELLO
:
400 TCHECK(op
->ospf_hello
.hello_deadint
);
401 printf("\n\t Hello Timer: %us, Dead Timer %us, mask: %s, Priority: %u",
402 EXTRACT_16BITS(&op
->ospf_hello
.hello_helloint
),
403 EXTRACT_32BITS(&op
->ospf_hello
.hello_deadint
),
404 ipaddr_string(&op
->ospf_hello
.hello_mask
),
405 op
->ospf_hello
.hello_priority
);
407 printf("\n\t Options: %s",
408 bittok2str(ospf_option_values
,"none",op
->ospf_hello
.hello_options
));
410 TCHECK(op
->ospf_hello
.hello_dr
);
411 if (op
->ospf_hello
.hello_dr
.s_addr
!= 0)
412 printf("\n\t Designated Router %s",
413 ipaddr_string(&op
->ospf_hello
.hello_dr
));
415 TCHECK(op
->ospf_hello
.hello_bdr
);
416 if (op
->ospf_hello
.hello_bdr
.s_addr
!= 0)
417 printf(", Backup Designated Router %s",
418 ipaddr_string(&op
->ospf_hello
.hello_bdr
));
420 ap
= op
->ospf_hello
.hello_neighbor
;
421 if ((u_char
*)ap
< dataend
)
422 printf("\n\t Neighbor List:");
423 while ((u_char
*)ap
< dataend
) {
425 printf("\n\t %s", ipaddr_string(ap
));
431 TCHECK(op
->ospf_db
.db_options
);
432 printf("\n\t Options: %s",
433 bittok2str(ospf_option_values
,"none",op
->ospf_db
.db_options
));
434 TCHECK(op
->ospf_db
.db_flags
);
435 printf("\n\t DD Flags: %s",
436 bittok2str(ospf_dd_flag_values
,"none",op
->ospf_db
.db_flags
));
439 /* Print all the LS adv's */
440 lshp
= op
->ospf_db
.db_lshdr
;
441 while (!ospf_print_lshdr(lshp
)) {
447 case OSPF_TYPE_LS_REQ
:
449 while ((u_char
*)lsrp
< dataend
) {
452 printf("\n\t %s LSA (%d), LSA-ID: %s, Advertising Router: %s",
453 tok2str(lsa_values
,"unknown",lsrp
->ls_type
),
455 ipaddr_string(&lsrp
->ls_stateid
),
456 ipaddr_string(&lsrp
->ls_router
));
461 case OSPF_TYPE_LS_UPDATE
:
462 lsap
= op
->ospf_lsu
.lsu_lsa
;
463 TCHECK(op
->ospf_lsu
.lsu_count
);
464 lsa_count
= EXTRACT_32BITS(&op
->ospf_lsu
.lsu_count
);
465 printf(", %d LSA%s",lsa_count
, lsa_count
> 1 ? "s" : "");
466 while (lsa_count
--) {
467 if (ospf_print_lsa(lsap
))
469 lsap
= (struct lsa
*)((u_char
*)lsap
+
470 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
));
474 case OSPF_TYPE_LS_ACK
:
475 lshp
= op
->ospf_lsa
.lsa_lshdr
;
476 while (!ospf_print_lshdr(lshp
)) {
482 printf("v2 type (%d)", op
->ospf_type
);
491 ospf_print(register const u_char
*bp
, register u_int length
,
492 register const u_char
*bp2
)
494 register const struct ospfhdr
*op
;
495 register const struct ip
*ip
;
496 register const u_char
*dataend
;
497 register const char *cp
;
499 op
= (struct ospfhdr
*)bp
;
500 ip
= (struct ip
*)bp2
;
502 /* XXX Before we do anything else, strip off the MD5 trailer */
503 TCHECK(op
->ospf_authtype
);
504 if (EXTRACT_16BITS(&op
->ospf_authtype
) == OSPF_AUTH_MD5
) {
505 length
-= OSPF_AUTH_MD5_LEN
;
506 snapend
-= OSPF_AUTH_MD5_LEN
;
509 /* If the type is valid translate it, or just print the type */
510 /* value. If it's not valid, say so and return */
511 TCHECK(op
->ospf_type
);
512 cp
= tok2str(type2str
, "unknown LS-Type %d", op
->ospf_type
);
513 printf("OSPFv%d %s length: %d", op
->ospf_version
, cp
, length
);
517 if(!vflag
) /* non verbose - so lets bail out here */
520 TCHECK(op
->ospf_len
);
521 if (length
!= EXTRACT_16BITS(&op
->ospf_len
)) {
522 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf_len
));
525 dataend
= bp
+ length
;
527 TCHECK(op
->ospf_routerid
);
528 printf("\n\tRouter-ID: %s", ipaddr_string(&op
->ospf_routerid
));
530 TCHECK(op
->ospf_areaid
);
531 if (op
->ospf_areaid
.s_addr
!= 0)
532 printf(", Area %s", ipaddr_string(&op
->ospf_areaid
));
534 printf(", Backbone Area");
537 /* Print authentication data (should we really do this?) */
538 TCHECK2(op
->ospf_authdata
[0], sizeof(op
->ospf_authdata
));
540 printf(", Authentication Type: %s (%u)",
541 tok2str(ospf_authtype_values
,"unknown",EXTRACT_16BITS(&op
->ospf_authtype
)),
542 EXTRACT_16BITS(&op
->ospf_authtype
));
544 switch (EXTRACT_16BITS(&op
->ospf_authtype
)) {
549 case OSPF_AUTH_SIMPLE
:
550 (void)fn_printn(op
->ospf_authdata
,
551 sizeof(op
->ospf_authdata
), NULL
);
556 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
557 *((op
->ospf_authdata
)+2),
558 *((op
->ospf_authdata
)+3),
559 EXTRACT_32BITS((op
->ospf_authdata
)+4));
566 /* Do rest according to version. */
567 switch (op
->ospf_version
) {
571 if (ospf_decode_v2(op
, dataend
))
576 printf(" ospf [version %d]", op
->ospf_version
);
578 } /* end switch on version */