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-ospf6.c,v 1.13 2003/11/16 09:36:31 guy Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
38 #include "interface.h"
39 #include "addrtoname.h"
49 static const struct bits ospf6_option_bits
[] = {
50 { OSPF6_OPTION_V6
, "V6" },
51 { OSPF6_OPTION_E
, "E" },
52 { OSPF6_OPTION_MC
, "MC" },
53 { OSPF6_OPTION_N
, "N" },
54 { OSPF6_OPTION_R
, "R" },
55 { OSPF6_OPTION_DC
, "DC" },
59 static const struct bits ospf6_rla_flag_bits
[] = {
67 static const struct bits ospf6_asla_flag_bits
[] = {
68 { ASLA_FLAG_EXTERNAL
, "E" },
69 { ASLA_FLAG_FWDADDR
, "F" },
70 { ASLA_FLAG_ROUTETAG
, "T" },
74 static struct tok type2str
[] = {
75 { OSPF_TYPE_UMD
, "umd" },
76 { OSPF_TYPE_HELLO
, "hello" },
77 { OSPF_TYPE_DB
, "dd" },
78 { OSPF_TYPE_LSR
, "ls_req" },
79 { OSPF_TYPE_LSU
, "ls_upd" },
80 { OSPF_TYPE_LSA
, "ls_ack" },
84 static char tstr
[] = " [|ospf]";
87 #define inline __inline
91 static inline void ospf6_print_seqage(u_int32_t
, time_t);
92 static inline void ospf6_print_bits(const struct bits
*, u_char
);
93 static void ospf6_print_ls_type(u_int
, const rtrid_t
*,
94 const rtrid_t
*, const char *);
95 static int ospf6_print_lshdr(const struct lsa_hdr
*);
96 static int ospf6_print_lsa(const struct lsa
*);
97 static int ospf6_decode_v3(const struct ospf6hdr
*, const u_char
*);
100 ospf6_print_seqage(register u_int32_t seq
, register time_t us
)
102 register time_t sec
= us
% 60;
103 register time_t mins
= (us
/ 60) % 60;
104 register time_t hour
= us
/ 3600;
106 printf(" S %X age ", seq
);
108 printf("%u:%02u:%02u",
109 (u_int32_t
) hour
, (u_int32_t
) mins
, (u_int32_t
) sec
);
111 printf("%u:%02u", (u_int32_t
) mins
, (u_int32_t
) sec
);
113 printf("%u", (u_int32_t
) sec
);
118 ospf6_print_bits(register const struct bits
*bp
, register u_char options
)
120 register char sep
= ' ';
123 if (options
& bp
->bit
) {
124 printf("%c%s", sep
, bp
->str
);
127 } while ((++bp
)->bit
);
131 ospf6_print_ls_type(register u_int ls_type
,
132 register const rtrid_t
*ls_stateid
,
133 register const rtrid_t
*ls_router
, register const char *fmt
)
137 switch (ls_type
& LS_SCOPE_MASK
) {
138 case LS_SCOPE_LINKLOCAL
:
139 scope
= "linklocal-";
152 switch (ls_type
& LS_TYPE_MASK
) {
154 printf(" %srtr %s", scope
, ipaddr_string(ls_router
));
157 case LS_TYPE_NETWORK
:
158 printf(" %snet dr %s if %s", scope
,
159 ipaddr_string(ls_router
),
160 ipaddr_string(ls_stateid
));
163 case LS_TYPE_INTER_AP
:
164 printf(" %sinter-area-prefix %s abr %s", scope
,
165 ipaddr_string(ls_stateid
),
166 ipaddr_string(ls_router
));
169 case LS_TYPE_INTER_AR
:
170 printf(" %sinter-area-router %s rtr %s", scope
,
171 ipaddr_string(ls_router
),
172 ipaddr_string(ls_stateid
));
176 printf(" %sase %s asbr %s", scope
,
177 ipaddr_string(ls_stateid
),
178 ipaddr_string(ls_router
));
182 printf(" %sgroup %s rtr %s", scope
,
183 ipaddr_string(ls_stateid
),
184 ipaddr_string(ls_router
));
188 printf(" %stype7 %s rtr %s", scope
,
189 ipaddr_string(ls_stateid
),
190 ipaddr_string(ls_router
));
194 printf(" %slink %s rtr %s", scope
,
195 ipaddr_string(ls_stateid
),
196 ipaddr_string(ls_router
));
199 case LS_TYPE_INTRA_AP
:
200 printf(" %sintra-area-prefix %s rtr %s", scope
,
201 ipaddr_string(ls_stateid
),
202 ipaddr_string(ls_router
));
206 printf(" %s", scope
);
207 printf(fmt
, ls_type
);
214 ospf6_print_lshdr(register const struct lsa_hdr
*lshp
)
217 TCHECK(lshp
->ls_type
);
218 printf(" {"); /* } (ctags) */
220 TCHECK(lshp
->ls_seq
);
221 ospf6_print_seqage(EXTRACT_32BITS(&lshp
->ls_seq
), EXTRACT_16BITS(&lshp
->ls_age
));
222 ospf6_print_ls_type(EXTRACT_16BITS(&lshp
->ls_type
), &lshp
->ls_stateid
,
223 &lshp
->ls_router
, "ls_type %d");
231 ospf6_print_lsaprefix(register const struct lsa_prefix
*lsapp
)
234 struct in6_addr prefix
;
237 k
= (lsapp
->lsa_p_len
+ 31) / 32;
238 if (k
* 4 > sizeof(struct in6_addr
)) {
239 printf("??prefixlen %d??", lsapp
->lsa_p_len
);
242 memset(&prefix
, 0, sizeof(prefix
));
243 memcpy(&prefix
, lsapp
->lsa_p_prefix
, k
* 4);
244 printf(" %s/%d", ip6addr_string(&prefix
),
246 if (lsapp
->lsa_p_opt
)
247 printf("(opt=%x)", lsapp
->lsa_p_opt
);
248 if (lsapp
->lsa_p_mbz
)
249 printf("(mbz=%x)", EXTRACT_16BITS(&lsapp
->lsa_p_mbz
)); /* XXX */
250 return sizeof(*lsapp
) - 4 + k
* 4;
258 * Print a single link state advertisement. If truncated return 1, else 0.
261 ospf6_print_lsa(register const struct lsa
*lsap
)
263 register const u_char
*ls_end
, *ls_opt
;
264 register const struct rlalink
*rlp
;
266 register const struct tos_metric
*tosp
;
268 register const rtrid_t
*ap
;
270 register const struct aslametric
*almp
;
271 register const struct mcla
*mcp
;
273 register const struct llsa
*llsap
;
274 register const struct lsa_prefix
*lsapp
;
276 register const u_int32_t
*lp
;
282 if (ospf6_print_lshdr(&lsap
->ls_hdr
))
284 TCHECK(lsap
->ls_hdr
.ls_length
);
285 ls_end
= (u_char
*)lsap
+ EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
);
286 switch (EXTRACT_16BITS(&lsap
->ls_hdr
.ls_type
)) {
287 case LS_TYPE_ROUTER
| LS_SCOPE_AREA
:
288 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
289 ospf6_print_bits(ospf6_rla_flag_bits
,
290 lsap
->lsa_un
.un_rla
.rla_flags
);
291 TCHECK(lsap
->lsa_un
.un_rla
.rla_options
);
292 ospf6_print_bits(ospf6_option_bits
,
293 EXTRACT_32BITS(&lsap
->lsa_un
.un_rla
.rla_options
));
295 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
296 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
297 while (rlp
+ sizeof(*rlp
) <= (struct rlalink
*)ls_end
) {
299 printf(" {"); /* } (ctags) */
300 switch (rlp
->link_type
) {
302 case RLA_TYPE_VIRTUAL
:
306 case RLA_TYPE_ROUTER
:
307 printf(" nbrid %s nbrif %s if %s",
308 ipaddr_string(&rlp
->link_nrtid
),
309 ipaddr_string(&rlp
->link_nifid
),
310 ipaddr_string(&rlp
->link_ifid
));
313 case RLA_TYPE_TRANSIT
:
314 printf(" dr %s drif %s if %s",
315 ipaddr_string(&rlp
->link_nrtid
),
316 ipaddr_string(&rlp
->link_nifid
),
317 ipaddr_string(&rlp
->link_ifid
));
322 printf(" ??RouterLinksType 0x%02x?? }",
326 printf(" metric %d", EXTRACT_16BITS(&rlp
->link_metric
));
333 case LS_TYPE_NETWORK
| LS_SCOPE_AREA
:
334 TCHECK(lsap
->lsa_un
.un_nla
.nla_options
);
335 ospf6_print_bits(ospf6_option_bits
,
336 EXTRACT_32BITS(&lsap
->lsa_un
.un_nla
.nla_options
));
338 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
339 while ((u_char
*)ap
< ls_end
) {
341 printf(" %s", ipaddr_string(ap
));
346 case LS_TYPE_INTER_AP
| LS_SCOPE_AREA
:
347 TCHECK(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
349 EXTRACT_32BITS(&lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
) & SLA_MASK_METRIC
);
350 lsapp
= lsap
->lsa_un
.un_inter_ap
.inter_ap_prefix
;
351 while (lsapp
+ sizeof(lsapp
) <= (struct lsa_prefix
*)ls_end
) {
352 k
= ospf6_print_lsaprefix(lsapp
);
355 lsapp
= (struct lsa_prefix
*)(((u_char
*)lsapp
) + k
);
358 case LS_SCOPE_AS
| LS_TYPE_ASE
:
359 TCHECK(lsap
->lsa_un
.un_asla
.asla_metric
);
360 flags32
= EXTRACT_32BITS(&lsap
->lsa_un
.un_asla
.asla_metric
);
361 ospf6_print_bits(ospf6_asla_flag_bits
, flags32
);
363 EXTRACT_32BITS(&lsap
->lsa_un
.un_asla
.asla_metric
) &
365 lsapp
= lsap
->lsa_un
.un_asla
.asla_prefix
;
366 k
= ospf6_print_lsaprefix(lsapp
);
369 if ((ls_opt
= (u_char
*)(((u_char
*)lsapp
) + k
)) < ls_end
) {
370 struct in6_addr
*fwdaddr6
;
372 if ((flags32
& ASLA_FLAG_FWDADDR
) != 0) {
373 fwdaddr6
= (struct in6_addr
*)ls_opt
;
375 printf(" forward %s",
376 ip6addr_string(fwdaddr6
));
378 ls_opt
+= sizeof(struct in6_addr
);
381 if ((flags32
& ASLA_FLAG_ROUTETAG
) != 0) {
382 TCHECK(*(u_int32_t
*)ls_opt
);
384 ipaddr_string((u_int32_t
*)ls_opt
));
386 ls_opt
+= sizeof(u_int32_t
);
389 if (lsapp
->lsa_p_mbz
) {
390 TCHECK(*(u_int32_t
*)ls_opt
);
391 printf(" RefLSID: %s",
392 ipaddr_string((u_int32_t
*)ls_opt
));
394 ls_opt
+= sizeof(u_int32_t
);
399 case LS_TYPE_SUM_ABR
:
400 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
401 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
402 while ((u_char
*)lp
< ls_end
) {
403 register u_int32_t ul
;
406 ul
= EXTRACT_32BITS(lp
);
407 printf(" tos %d metric %d",
408 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
409 ul
& SLA_MASK_METRIC
);
415 /* Multicast extensions as of 23 July 1991 */
416 mcp
= lsap
->lsa_un
.un_mcla
;
417 while ((u_char
*)mcp
< ls_end
) {
418 TCHECK(mcp
->mcla_vid
);
419 switch (EXTRACT_32BITS(&mcp
->mcla_vtype
)) {
421 case MCLA_VERTEX_ROUTER
:
422 printf(" rtr rtrid %s",
423 ipaddr_string(&mcp
->mcla_vid
));
426 case MCLA_VERTEX_NETWORK
:
428 ipaddr_string(&mcp
->mcla_vid
));
432 printf(" ??VertexType %u??",
433 EXTRACT_32BITS(&mcp
->mcla_vtype
));
442 llsap
= &lsap
->lsa_un
.un_llsa
;
443 TCHECK(llsap
->llsa_options
);
444 ospf6_print_bits(ospf6_option_bits
, EXTRACT_32BITS(&llsap
->llsa_options
));
445 TCHECK(llsap
->llsa_nprefix
);
446 printf(" pri %d lladdr %s npref %d", llsap
->llsa_priority
,
447 ip6addr_string(&llsap
->llsa_lladdr
),
448 EXTRACT_32BITS(&llsap
->llsa_nprefix
));
449 lsapp
= llsap
->llsa_prefix
;
450 for (j
= 0; j
< EXTRACT_32BITS(&llsap
->llsa_nprefix
); j
++) {
451 k
= ospf6_print_lsaprefix(lsapp
);
454 lsapp
= (struct lsa_prefix
*)(((u_char
*)lsapp
) + k
);
458 case LS_TYPE_INTRA_AP
| LS_SCOPE_AREA
:
459 /* Intra-Area-Prefix LSA */
460 TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
462 EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_lstype
),
463 &lsap
->lsa_un
.un_intra_ap
.intra_ap_lsid
,
464 &lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
,
466 TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
468 EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
));
470 lsapp
= lsap
->lsa_un
.un_intra_ap
.intra_ap_prefix
;
472 j
< EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
474 k
= ospf6_print_lsaprefix(lsapp
);
477 lsapp
= (struct lsa_prefix
*)(((u_char
*)lsapp
) + k
);
482 printf(" ??LinkStateType 0x%04x??",
483 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_type
));
495 ospf6_decode_v3(register const struct ospf6hdr
*op
,
496 register const u_char
*dataend
)
498 register const rtrid_t
*ap
;
499 register const struct lsr
*lsrp
;
500 register const struct lsa_hdr
*lshp
;
501 register const struct lsa
*lsap
;
505 switch (op
->ospf6_type
) {
509 * Rob Coltun's special monitoring packets;
514 case OSPF_TYPE_HELLO
:
516 TCHECK(op
->ospf6_hello
.hello_deadint
);
517 ospf6_print_bits(ospf6_option_bits
,
518 EXTRACT_32BITS(&op
->ospf6_hello
.hello_options
));
519 printf(" ifid %s pri %d int %d dead %u",
520 ipaddr_string(&op
->ospf6_hello
.hello_ifid
),
521 op
->ospf6_hello
.hello_priority
,
522 EXTRACT_16BITS(&op
->ospf6_hello
.hello_helloint
),
523 EXTRACT_16BITS(&op
->ospf6_hello
.hello_deadint
));
525 TCHECK(op
->ospf6_hello
.hello_dr
);
526 if (op
->ospf6_hello
.hello_dr
!= 0)
528 ipaddr_string(&op
->ospf6_hello
.hello_dr
));
529 TCHECK(op
->ospf6_hello
.hello_bdr
);
530 if (op
->ospf6_hello
.hello_bdr
!= 0)
532 ipaddr_string(&op
->ospf6_hello
.hello_bdr
));
535 ap
= op
->ospf6_hello
.hello_neighbor
;
536 while ((u_char
*)ap
< dataend
) {
538 printf(" %s", ipaddr_string(ap
));
545 TCHECK(op
->ospf6_db
.db_options
);
546 ospf6_print_bits(ospf6_option_bits
,
547 EXTRACT_32BITS(&op
->ospf6_db
.db_options
));
549 TCHECK(op
->ospf6_db
.db_flags
);
550 if (op
->ospf6_db
.db_flags
& OSPF6_DB_INIT
) {
554 if (op
->ospf6_db
.db_flags
& OSPF6_DB_MORE
) {
558 if (op
->ospf6_db
.db_flags
& OSPF6_DB_MASTER
) {
562 TCHECK(op
->ospf6_db
.db_seq
);
563 printf(" mtu %u S %X", EXTRACT_16BITS(&op
->ospf6_db
.db_mtu
),
564 EXTRACT_32BITS(&op
->ospf6_db
.db_seq
));
567 /* Print all the LS adv's */
568 lshp
= op
->ospf6_db
.db_lshdr
;
570 while (!ospf6_print_lshdr(lshp
)) {
580 lsrp
= op
->ospf6_lsr
;
581 while ((u_char
*)lsrp
< dataend
) {
583 printf(" {"); /* } (ctags) */
584 ospf6_print_ls_type(EXTRACT_16BITS(&lsrp
->ls_type
),
597 lsap
= op
->ospf6_lsu
.lsu_lsa
;
598 TCHECK(op
->ospf6_lsu
.lsu_count
);
599 i
= EXTRACT_32BITS(&op
->ospf6_lsu
.lsu_count
);
601 if (ospf6_print_lsa(lsap
))
603 lsap
= (struct lsa
*)((u_char
*)lsap
+
604 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
));
612 lshp
= op
->ospf6_lsa
.lsa_lshdr
;
614 while (!ospf6_print_lshdr(lshp
)) {
623 printf("v3 type %d", op
->ospf6_type
);
632 ospf6_print(register const u_char
*bp
, register u_int length
)
634 register const struct ospf6hdr
*op
;
635 register const u_char
*dataend
;
636 register const char *cp
;
638 op
= (struct ospf6hdr
*)bp
;
640 /* If the type is valid translate it, or just print the type */
641 /* value. If it's not valid, say so and return */
642 TCHECK(op
->ospf6_type
);
643 cp
= tok2str(type2str
, "type%d", op
->ospf6_type
);
644 printf("OSPFv%d-%s %d:", op
->ospf6_version
, cp
, length
);
648 TCHECK(op
->ospf6_len
);
649 if (length
!= EXTRACT_16BITS(&op
->ospf6_len
)) {
650 printf(" [len %d]", EXTRACT_16BITS(&op
->ospf6_len
));
653 dataend
= bp
+ length
;
655 /* Print the routerid if it is not the same as the source */
656 TCHECK(op
->ospf6_routerid
);
657 printf(" rtrid %s", ipaddr_string(&op
->ospf6_routerid
));
659 TCHECK(op
->ospf6_areaid
);
660 if (op
->ospf6_areaid
!= 0)
661 printf(" area %s", ipaddr_string(&op
->ospf6_areaid
));
664 TCHECK(op
->ospf6_instanceid
);
665 if (op
->ospf6_instanceid
)
666 printf(" instance %u", op
->ospf6_instanceid
);
668 /* Do rest according to version. */
669 switch (op
->ospf6_version
) {
673 if (ospf6_decode_v3(op
, dataend
))
678 printf(" ospf [version %d]", op
->ospf6_version
);
680 } /* end switch on version */