]>
The Tcpdump Group git mirrors - tcpdump/blob - print-ospf6.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-ospf6.c,v 1.1 1999-10-30 05:11:19 itojun Exp $ (LBL)";
29 #include <sys/param.h>
31 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <netinet/in_systm.h>
35 #include <netinet/ip.h>
36 #include <netinet/ip_var.h>
42 #include "interface.h"
43 #include "addrtoname.h"
52 static const struct bits ospf6_option_bits
[] = {
53 { OSPF6_OPTION_V6
, "V6" },
54 { OSPF6_OPTION_E
, "E" },
55 { OSPF6_OPTION_MC
, "MC" },
56 { OSPF6_OPTION_N
, "N" },
57 { OSPF6_OPTION_R
, "R" },
58 { OSPF6_OPTION_DC
, "DC" },
62 static const struct bits ospf6_rla_flag_bits
[] = {
70 static struct tok type2str
[] = {
71 { OSPF_TYPE_UMD
, "umd" },
72 { OSPF_TYPE_HELLO
, "hello" },
73 { OSPF_TYPE_DB
, "dd" },
74 { OSPF_TYPE_LSR
, "ls_req" },
75 { OSPF_TYPE_LSU
, "ls_upd" },
76 { OSPF_TYPE_LSA
, "ls_ack" },
80 static char tstr
[] = " [|ospf]";
83 static inline void ospf6_print_seqage(u_int32_t
, time_t);
84 static inline void ospf6_print_bits(const struct bits
*, u_char
);
85 static void ospf6_print_ls_type(u_int
, const rtrid_t
*,
86 const rtrid_t
*, const char *);
87 static int ospf6_print_lshdr(const struct lsa_hdr
*);
88 static int ospf6_print_lsa(const struct lsa
*);
89 static int ospf6_decode_v3(const struct ospf6hdr
*, const u_char
*);
92 ospf6_print_seqage(register u_int32_t seq
, register time_t us
)
94 register time_t sec
= us
% 60;
95 register time_t mins
= (us
/ 60) % 60;
96 register time_t hour
= us
/ 3600;
98 printf(" S %X age ", seq
);
100 printf("%u:%02u:%02u",
101 (u_int32_t
) hour
, (u_int32_t
) mins
, (u_int32_t
) sec
);
103 printf("%u:%02u", (u_int32_t
) mins
, (u_int32_t
) sec
);
105 printf("%u", (u_int32_t
) sec
);
110 ospf6_print_bits(register const struct bits
*bp
, register u_char options
)
112 register char sep
= ' ';
115 if (options
& bp
->bit
) {
116 printf("%c%s", sep
, bp
->str
);
119 } while ((++bp
)->bit
);
123 ospf6_print_ls_type(register u_int ls_type
,
124 register const rtrid_t
*ls_stateid
,
125 register const rtrid_t
*ls_router
, register const char *fmt
)
129 switch (ls_type
& LS_SCOPE_MASK
) {
130 case LS_SCOPE_LINKLOCAL
:
131 scope
= "linklocal-";
144 switch (ls_type
& LS_TYPE_MASK
) {
146 printf(" %srtr %s", scope
, ipaddr_string(ls_router
));
149 case LS_TYPE_NETWORK
:
150 printf(" %snet dr %s if %s", scope
,
151 ipaddr_string(ls_router
),
152 ipaddr_string(ls_stateid
));
155 case LS_TYPE_INTER_AP
:
156 printf(" %sinter-area-prefix %s abr %s", scope
,
157 ipaddr_string(ls_stateid
),
158 ipaddr_string(ls_router
));
161 case LS_TYPE_INTER_AR
:
162 printf(" %sinter-area-router %s rtr %s", scope
,
163 ipaddr_string(ls_router
),
164 ipaddr_string(ls_stateid
));
168 printf(" %sase %s asbr %s", scope
,
169 ipaddr_string(ls_stateid
),
170 ipaddr_string(ls_router
));
174 printf(" %sgroup %s rtr %s", scope
,
175 ipaddr_string(ls_stateid
),
176 ipaddr_string(ls_router
));
180 printf(" %stype7 %s rtr %s", scope
,
181 ipaddr_string(ls_stateid
),
182 ipaddr_string(ls_router
));
186 printf(" %slink %s rtr %s", scope
,
187 ipaddr_string(ls_stateid
),
188 ipaddr_string(ls_router
));
191 case LS_TYPE_INTRA_AP
:
192 printf(" %sintra-area-prefix %s rtr %s", scope
,
193 ipaddr_string(ls_stateid
),
194 ipaddr_string(ls_router
));
198 printf(" %s", scope
);
199 printf(fmt
, ls_type
);
206 ospf6_print_lshdr(register const struct lsa_hdr
*lshp
)
209 TCHECK(lshp
->ls_type
);
210 printf(" {"); /* } (ctags) */
212 TCHECK(lshp
->ls_seq
);
213 ospf6_print_seqage(ntohl(lshp
->ls_seq
), ntohs(lshp
->ls_age
));
214 ospf6_print_ls_type(ntohs(lshp
->ls_type
), &lshp
->ls_stateid
,
215 &lshp
->ls_router
, "ls_type %d");
223 ospf6_print_lsaprefix(register const struct lsa_prefix
*lsapp
)
226 struct in6_addr prefix
;
229 k
= (lsapp
->lsa_p_len
+ 31) / 32;
230 if (k
* 4 > sizeof(struct in6_addr
)) {
231 printf("??prefixlen %d??", lsapp
->lsa_p_len
);
234 memset(&prefix
, 0, sizeof(prefix
));
235 memcpy(&prefix
, lsapp
->lsa_p_prefix
, k
* 4);
236 printf(" %s/%d", ip6addr_string(&prefix
),
238 if (lsapp
->lsa_p_opt
)
239 printf("(opt=%x)", lsapp
->lsa_p_opt
);
240 return sizeof(*lsapp
) - 4 + k
* 4;
248 * Print a single link state advertisement. If truncated return 1, else 0.
251 ospf6_print_lsa(register const struct lsa
*lsap
)
253 register const u_char
*ls_end
;
254 register const struct rlalink
*rlp
;
256 register const struct tos_metric
*tosp
;
258 register const rtrid_t
*ap
;
260 register const struct aslametric
*almp
;
261 register const struct mcla
*mcp
;
263 register const struct llsa
*llsap
;
264 register const struct lsa_prefix
*lsapp
;
266 register const u_int32_t
*lp
;
270 if (ospf6_print_lshdr(&lsap
->ls_hdr
))
272 TCHECK(lsap
->ls_hdr
.ls_length
);
273 ls_end
= (u_char
*)lsap
+ ntohs(lsap
->ls_hdr
.ls_length
);
274 switch (ntohs(lsap
->ls_hdr
.ls_type
)) {
275 case LS_TYPE_ROUTER
| LS_SCOPE_AREA
:
276 TCHECK(lsap
->lsa_un
.un_rla
.rla_flags
);
277 ospf6_print_bits(ospf6_rla_flag_bits
,
278 lsap
->lsa_un
.un_rla
.rla_flags
);
279 TCHECK(lsap
->lsa_un
.un_rla
.rla_options
);
280 ospf6_print_bits(ospf6_option_bits
,
281 ntohl(lsap
->lsa_un
.un_rla
.rla_options
));
283 TCHECK(lsap
->lsa_un
.un_rla
.rla_link
);
284 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
285 while (rlp
+ sizeof(*rlp
) <= (struct rlalink
*)ls_end
) {
287 printf(" {"); /* } (ctags) */
288 switch (rlp
->link_type
) {
290 case RLA_TYPE_VIRTUAL
:
294 case RLA_TYPE_ROUTER
:
295 printf(" nbrid %s nbrif %s if %s",
296 ipaddr_string(&rlp
->link_nrtid
),
297 ipaddr_string(&rlp
->link_nifid
),
298 ipaddr_string(&rlp
->link_ifid
));
301 case RLA_TYPE_TRANSIT
:
302 printf(" dr %s drif %s if %s",
303 ipaddr_string(&rlp
->link_nrtid
),
304 ipaddr_string(&rlp
->link_nifid
),
305 ipaddr_string(&rlp
->link_ifid
));
310 printf(" ??RouterLinksType 0x%02x?? }",
314 printf(" metric %d", ntohs(rlp
->link_metric
));
321 case LS_TYPE_NETWORK
| LS_SCOPE_AREA
:
322 TCHECK(lsap
->lsa_un
.un_nla
.nla_options
);
323 ospf6_print_bits(ospf6_option_bits
,
324 ntohl(lsap
->lsa_un
.un_nla
.nla_options
));
326 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
327 while ((u_char
*)ap
< ls_end
) {
329 printf(" %s", ipaddr_string(ap
));
334 case LS_TYPE_INTER_AP
| LS_SCOPE_AREA
:
335 TCHECK(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
337 (u_int32_t
)ntohl(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
) & SLA_MASK_METRIC
);
338 lsapp
= lsap
->lsa_un
.un_inter_ap
.inter_ap_prefix
;
339 while (lsapp
+ sizeof(lsapp
) <= (struct lsa_prefix
*)ls_end
) {
340 k
= ospf6_print_lsaprefix(lsapp
);
343 lsapp
= (struct lsa_prefix
*)(((u_char
*)lsapp
) + k
);
348 case LS_TYPE_SUM_ABR
:
349 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
350 lp
= lsap
->lsa_un
.un_sla
.sla_tosmetric
;
351 while ((u_char
*)lp
< ls_end
) {
352 register u_int32_t ul
;
356 printf(" tos %d metric %d",
357 (ul
& SLA_MASK_TOS
) >> SLA_SHIFT_TOS
,
358 ul
& SLA_MASK_METRIC
);
364 TCHECK(lsap
->lsa_un
.un_nla
.nla_mask
);
366 ipaddr_string(&lsap
->lsa_un
.un_asla
.asla_mask
));
368 TCHECK(lsap
->lsa_un
.un_sla
.sla_tosmetric
);
369 almp
= lsap
->lsa_un
.un_asla
.asla_metric
;
370 while ((u_char
*)almp
< ls_end
) {
371 register u_int32_t ul
;
373 TCHECK(almp
->asla_tosmetric
);
374 ul
= ntohl(almp
->asla_tosmetric
);
375 printf(" type %d tos %d metric %d",
376 (ul
& ASLA_FLAG_EXTERNAL
) ? 2 : 1,
377 (ul
& ASLA_MASK_TOS
) >> ASLA_SHIFT_TOS
,
378 (ul
& ASLA_MASK_METRIC
));
379 TCHECK(almp
->asla_forward
);
380 if (almp
->asla_forward
.s_addr
) {
381 printf(" forward %s",
382 ipaddr_string(&almp
->asla_forward
));
384 TCHECK(almp
->asla_tag
);
385 if (almp
->asla_tag
.s_addr
) {
387 ipaddr_string(&almp
->asla_tag
));
394 /* Multicast extensions as of 23 July 1991 */
395 mcp
= lsap
->lsa_un
.un_mcla
;
396 while ((u_char
*)mcp
< ls_end
) {
397 TCHECK(mcp
->mcla_vid
);
398 switch (ntohl(mcp
->mcla_vtype
)) {
400 case MCLA_VERTEX_ROUTER
:
401 printf(" rtr rtrid %s",
402 ipaddr_string(&mcp
->mcla_vid
));
405 case MCLA_VERTEX_NETWORK
:
407 ipaddr_string(&mcp
->mcla_vid
));
411 printf(" ??VertexType %u??",
412 (u_int32_t
)ntohl(mcp
->mcla_vtype
));
421 llsap
= &lsap
->lsa_un
.un_llsa
;
422 TCHECK(llsap
->llsa_options
);
423 ospf6_print_bits(ospf6_option_bits
, ntohl(llsap
->llsa_options
));
424 TCHECK(llsap
->llsa_nprefix
);
425 printf(" pri %d lladdr %s npref %d", llsap
->llsa_priority
,
426 ip6addr_string(&llsap
->llsa_lladdr
),
427 (u_int32_t
)ntohl(llsap
->llsa_nprefix
));
428 lsapp
= llsap
->llsa_prefix
;
429 for (j
= 0; j
< ntohl(llsap
->llsa_nprefix
); j
++) {
430 k
= ospf6_print_lsaprefix(lsapp
);
433 lsapp
= (struct lsa_prefix
*)(((u_char
*)lsapp
) + k
);
437 case LS_TYPE_INTRA_AP
| LS_SCOPE_AREA
:
438 /* Intra-Area-Prefix LSA */
439 TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
441 ntohs(lsap
->lsa_un
.un_intra_ap
.intra_ap_lstype
),
442 &lsap
->lsa_un
.un_intra_ap
.intra_ap_lsid
,
443 &lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
,
445 TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
447 ntohs(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
));
449 lsapp
= lsap
->lsa_un
.un_intra_ap
.intra_ap_prefix
;
451 j
< ntohs(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
453 k
= ospf6_print_lsaprefix(lsapp
);
456 lsapp
= (struct lsa_prefix
*)(((u_char
*)lsapp
) + k
);
461 printf(" ??LinkStateType 0x%04x??",
462 ntohs(lsap
->ls_hdr
.ls_type
));
474 ospf6_decode_v3(register const struct ospf6hdr
*op
,
475 register const u_char
*dataend
)
477 register const rtrid_t
*ap
;
478 register const struct lsr
*lsrp
;
479 register const struct lsa_hdr
*lshp
;
480 register const struct lsa
*lsap
;
484 switch (op
->ospf6_type
) {
488 * Rob Coltun's special monitoring packets;
493 case OSPF_TYPE_HELLO
:
495 TCHECK(op
->ospf6_hello
.hello_deadint
);
496 ospf6_print_bits(ospf6_option_bits
,
497 ntohl(op
->ospf6_hello
.hello_options
));
498 printf(" ifid %s pri %d int %d dead %u",
499 ipaddr_string(&op
->ospf6_hello
.hello_ifid
),
500 op
->ospf6_hello
.hello_priority
,
501 ntohs(op
->ospf6_hello
.hello_helloint
),
502 ntohs(op
->ospf6_hello
.hello_deadint
));
504 TCHECK(op
->ospf6_hello
.hello_dr
);
505 if (op
->ospf6_hello
.hello_dr
!= 0)
507 ipaddr_string(&op
->ospf6_hello
.hello_dr
));
508 TCHECK(op
->ospf6_hello
.hello_bdr
);
509 if (op
->ospf6_hello
.hello_bdr
!= 0)
511 ipaddr_string(&op
->ospf6_hello
.hello_bdr
));
514 ap
= op
->ospf6_hello
.hello_neighbor
;
515 while ((u_char
*)ap
< dataend
) {
517 printf(" %s", ipaddr_string(ap
));
524 TCHECK(op
->ospf6_db
.db_options
);
525 ospf6_print_bits(ospf6_option_bits
,
526 ntohl(op
->ospf6_db
.db_options
));
528 TCHECK(op
->ospf6_db
.db_flags
);
529 if (op
->ospf6_db
.db_flags
& OSPF6_DB_INIT
) {
533 if (op
->ospf6_db
.db_flags
& OSPF6_DB_MORE
) {
537 if (op
->ospf6_db
.db_flags
& OSPF6_DB_MASTER
) {
541 TCHECK(op
->ospf6_db
.db_seq
);
542 printf(" mtu %u S %X", ntohs(op
->ospf6_db
.db_mtu
),
543 (u_int32_t
)ntohl(op
->ospf6_db
.db_seq
));
546 /* Print all the LS adv's */
547 lshp
= op
->ospf6_db
.db_lshdr
;
549 while (!ospf6_print_lshdr(lshp
)) {
559 lsrp
= op
->ospf6_lsr
;
560 while ((u_char
*)lsrp
< dataend
) {
562 printf(" {"); /* } (ctags) */
563 ospf6_print_ls_type(ntohs(lsrp
->ls_type
),
576 lsap
= op
->ospf6_lsu
.lsu_lsa
;
577 TCHECK(op
->ospf6_lsu
.lsu_count
);
578 i
= ntohl(op
->ospf6_lsu
.lsu_count
);
580 if (ospf6_print_lsa(lsap
))
582 lsap
= (struct lsa
*)((u_char
*)lsap
+
583 ntohs(lsap
->ls_hdr
.ls_length
));
591 lshp
= op
->ospf6_lsa
.lsa_lshdr
;
593 while (!ospf6_print_lshdr(lshp
)) {
602 printf("v3 type %d", op
->ospf6_type
);
611 ospf6_print(register const u_char
*bp
, register u_int length
)
613 register const struct ospf6hdr
*op
;
614 register const u_char
*dataend
;
615 register const char *cp
;
617 op
= (struct ospf6hdr
*)bp
;
619 /* If the type is valid translate it, or just print the type */
620 /* value. If it's not valid, say so and return */
621 TCHECK(op
->ospf6_type
);
622 cp
= tok2str(type2str
, "type%d", op
->ospf6_type
);
623 printf(" OSPFv%d-%s %d:", op
->ospf6_version
, cp
, length
);
627 TCHECK(op
->ospf6_len
);
628 if (length
!= ntohs(op
->ospf6_len
)) {
629 printf(" [len %d]", ntohs(op
->ospf6_len
));
632 dataend
= bp
+ length
;
634 /* Print the routerid if it is not the same as the source */
635 TCHECK(op
->ospf6_routerid
);
636 printf(" rtrid %s", ipaddr_string(&op
->ospf6_routerid
));
638 TCHECK(op
->ospf6_areaid
);
639 if (op
->ospf6_areaid
!= 0)
640 printf(" area %s", ipaddr_string(&op
->ospf6_areaid
));
643 TCHECK(op
->ospf6_instanceid
);
644 if (op
->ospf6_instanceid
)
645 printf(" instance %u", op
->ospf6_instanceid
);
647 /* Do rest according to version. */
648 switch (op
->ospf6_version
) {
652 if (ospf6_decode_v3(op
, dataend
))
657 printf(" ospf [version %d]", op
->ospf6_version
);
659 } /* end switch on version */