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)
28 #include <tcpdump-stdinc.h>
33 #include "interface.h"
34 #include "addrtoname.h"
39 #define OSPF_TYPE_HELLO 1 /* Hello */
40 #define OSPF_TYPE_DD 2 /* Database Description */
41 #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
42 #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
43 #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
45 /* Options *_options */
46 #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */
47 #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */
48 #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */
49 #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */
50 #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */
51 #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */
52 /* The field is actually 24-bit (RFC5340 Section A.2). */
53 #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */
54 #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */
55 #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */
59 #define OSPF6_DB_INIT 0x04 /* */
60 #define OSPF6_DB_MORE 0x02
61 #define OSPF6_DB_MASTER 0x01
62 #define OSPF6_DB_M6 0x10 /* IPv6 MTU */
65 #define LS_TYPE_ROUTER 1 /* router link */
66 #define LS_TYPE_NETWORK 2 /* network link */
67 #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */
68 #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */
69 #define LS_TYPE_ASE 5 /* ASE */
70 #define LS_TYPE_GROUP 6 /* Group membership */
71 #define LS_TYPE_NSSA 7 /* NSSA */
72 #define LS_TYPE_LINK 8 /* Link LSA */
73 #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */
74 #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */
75 #define LS_TYPE_GRACE 11 /* Grace LSA */
76 #define LS_TYPE_RI 12 /* Router information */
77 #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */
78 #define LS_TYPE_L1VPN 14 /* L1VPN */
79 #define LS_TYPE_MASK 0x1fff
81 #define LS_SCOPE_LINKLOCAL 0x0000
82 #define LS_SCOPE_AREA 0x2000
83 #define LS_SCOPE_AS 0x4000
84 #define LS_SCOPE_MASK 0x6000
85 #define LS_SCOPE_U 0x8000
87 /* rla_link.link_type */
88 #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
89 #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
90 #define RLA_TYPE_VIRTUAL 4 /* virtual link */
93 #define RLA_FLAG_B 0x01
94 #define RLA_FLAG_E 0x02
95 #define RLA_FLAG_V 0x04
96 #define RLA_FLAG_W 0x08
97 #define RLA_FLAG_N 0x10
99 /* lsa_prefix options */
100 #define LSA_PREFIX_OPT_NU 0x01
101 #define LSA_PREFIX_OPT_LA 0x02
102 #define LSA_PREFIX_OPT_MC 0x04
103 #define LSA_PREFIX_OPT_P 0x08
104 #define LSA_PREFIX_OPT_DN 0x10
106 /* sla_tosmetric breakdown */
107 #define SLA_MASK_TOS 0x7f000000
108 #define SLA_MASK_METRIC 0x00ffffff
109 #define SLA_SHIFT_TOS 24
112 #define ASLA_FLAG_FWDADDR 0x02000000
113 #define ASLA_FLAG_ROUTETAG 0x01000000
114 #define ASLA_MASK_METRIC 0x00ffffff
116 /* RFC6506 Section 4.1 */
117 #define OSPF6_AT_HDRLEN 16U
118 #define OSPF6_AUTH_TYPE_HMAC 0x0001
120 typedef u_int32_t rtrid_t
;
122 /* link state advertisement header */
136 u_int16_t lsa_p_metric
;
137 u_int8_t lsa_p_prefix
[4];
140 /* link state advertisement */
142 struct lsa6_hdr ls_hdr
;
144 /* Link state types */
146 /* Router links advertisements */
152 #define rla_flags rla_flgandopt.flg
153 #define rla_options rla_flgandopt.opt
156 u_int8_t link_zero
[1];
157 u_int16_t link_metric
;
159 u_int32_t link_nifid
;
161 } rla_link
[1]; /* may repeat */
164 /* Network links advertisements */
166 u_int32_t nla_options
;
167 rtrid_t nla_router
[1]; /* may repeat */
170 /* Inter Area Prefix LSA */
172 u_int32_t inter_ap_metric
;
173 struct lsa6_prefix inter_ap_prefix
[1];
176 /* AS external links advertisements */
178 u_int32_t asla_metric
;
179 struct lsa6_prefix asla_prefix
[1];
180 /* some optional fields follow */
184 /* Summary links advertisements */
186 struct in_addr sla_mask
;
187 u_int32_t sla_tosmetric
[1]; /* may repeat */
190 /* Multicast group membership */
192 u_int32_t mcla_vtype
;
193 struct in_addr mcla_vid
;
205 #define llsa_priority llsa_priandopt.pri
206 #define llsa_options llsa_priandopt.opt
207 struct in6_addr llsa_lladdr
;
208 u_int32_t llsa_nprefix
;
209 struct lsa6_prefix llsa_prefix
[1];
212 /* Intra-Area-Prefix */
214 u_int16_t intra_ap_nprefix
;
215 u_int16_t intra_ap_lstype
;
216 rtrid_t intra_ap_lsid
;
217 rtrid_t intra_ap_rtid
;
218 struct lsa6_prefix intra_ap_prefix
[1];
227 u_int8_t ospf6_version
;
230 rtrid_t ospf6_routerid
;
231 rtrid_t ospf6_areaid
;
232 u_int16_t ospf6_chksum
;
233 u_int8_t ospf6_instanceid
;
239 u_int32_t hello_ifid
;
244 #define hello_priority hello_priandopt.pri
245 #define hello_options hello_priandopt.opt
246 u_int16_t hello_helloint
;
247 u_int16_t hello_deadint
;
250 rtrid_t hello_neighbor
[1]; /* may repeat */
253 /* Database Description packet */
255 u_int32_t db_options
;
260 struct lsa6_hdr db_lshdr
[1]; /* may repeat */
263 /* Link State Request */
269 } un_lsr
[1]; /* may repeat */
271 /* Link State Update */
274 struct lsa6 lsu_lsa
[1]; /* may repeat */
277 /* Link State Acknowledgement */
279 struct lsa6_hdr lsa_lshdr
[1]; /* may repeat */
284 #define ospf6_hello ospf6_un.un_hello
285 #define ospf6_db ospf6_un.un_db
286 #define ospf6_lsr ospf6_un.un_lsr
287 #define ospf6_lsu ospf6_un.un_lsu
288 #define ospf6_lsa ospf6_un.un_lsa
290 static const char tstr
[] = " [|ospf3]";
292 static const struct tok ospf6_option_values
[] = {
293 { OSPF6_OPTION_V6
, "V6" },
294 { OSPF6_OPTION_E
, "External" },
295 { OSPF6_OPTION_MC
, "Deprecated" },
296 { OSPF6_OPTION_N
, "NSSA" },
297 { OSPF6_OPTION_R
, "Router" },
298 { OSPF6_OPTION_DC
, "Demand Circuit" },
299 { OSPF6_OPTION_AF
, "AFs Support" },
300 { OSPF6_OPTION_L
, "LLS" },
301 { OSPF6_OPTION_AT
, "Authentication Trailer" },
305 static const struct tok ospf6_rla_flag_values
[] = {
306 { RLA_FLAG_B
, "ABR" },
307 { RLA_FLAG_E
, "External" },
308 { RLA_FLAG_V
, "Virtual-Link Endpoint" },
309 { RLA_FLAG_W
, "Wildcard Receiver" },
310 { RLA_FLAG_N
, "NSSA Translator" },
314 static const struct tok ospf6_asla_flag_values
[] = {
315 { ASLA_FLAG_EXTERNAL
, "External Type 2" },
316 { ASLA_FLAG_FWDADDR
, "Forwarding" },
317 { ASLA_FLAG_ROUTETAG
, "Tag" },
321 static const struct tok ospf6_type_values
[] = {
322 { OSPF_TYPE_HELLO
, "Hello" },
323 { OSPF_TYPE_DD
, "Database Description" },
324 { OSPF_TYPE_LS_REQ
, "LS-Request" },
325 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
326 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
330 static const struct tok ospf6_lsa_values
[] = {
331 { LS_TYPE_ROUTER
, "Router" },
332 { LS_TYPE_NETWORK
, "Network" },
333 { LS_TYPE_INTER_AP
, "Inter-Area Prefix" },
334 { LS_TYPE_INTER_AR
, "Inter-Area Router" },
335 { LS_TYPE_ASE
, "External" },
336 { LS_TYPE_GROUP
, "Deprecated" },
337 { LS_TYPE_NSSA
, "NSSA" },
338 { LS_TYPE_LINK
, "Link" },
339 { LS_TYPE_INTRA_AP
, "Intra-Area Prefix" },
340 { LS_TYPE_INTRA_ATE
, "Intra-Area TE" },
341 { LS_TYPE_GRACE
, "Grace" },
342 { LS_TYPE_RI
, "Router Information" },
343 { LS_TYPE_INTER_ASTE
, "Inter-AS-TE" },
344 { LS_TYPE_L1VPN
, "Layer 1 VPN" },
348 static const struct tok ospf6_ls_scope_values
[] = {
349 { LS_SCOPE_LINKLOCAL
, "Link Local" },
350 { LS_SCOPE_AREA
, "Area Local" },
351 { LS_SCOPE_AS
, "Domain Wide" },
355 static const struct tok ospf6_dd_flag_values
[] = {
356 { OSPF6_DB_INIT
, "Init" },
357 { OSPF6_DB_MORE
, "More" },
358 { OSPF6_DB_MASTER
, "Master" },
359 { OSPF6_DB_M6
, "IPv6 MTU" },
363 static const struct tok ospf6_lsa_prefix_option_values
[] = {
364 { LSA_PREFIX_OPT_NU
, "No Unicast" },
365 { LSA_PREFIX_OPT_LA
, "Local address" },
366 { LSA_PREFIX_OPT_MC
, "Deprecated" },
367 { LSA_PREFIX_OPT_P
, "Propagate" },
368 { LSA_PREFIX_OPT_DN
, "Down" },
372 static const struct tok ospf6_auth_type_str
[] = {
373 { OSPF6_AUTH_TYPE_HMAC
, "HMAC" },
378 ospf6_print_ls_type(register u_int ls_type
, register const rtrid_t
*ls_stateid
)
380 printf("\n\t %s LSA (%d), %s Scope%s, LSA-ID %s",
381 tok2str(ospf6_lsa_values
, "Unknown", ls_type
& LS_TYPE_MASK
),
382 ls_type
& LS_TYPE_MASK
,
383 tok2str(ospf6_ls_scope_values
, "Unknown", ls_type
& LS_SCOPE_MASK
),
384 ls_type
&0x8000 ? ", transitive" : "", /* U-bit */
385 ipaddr_string(ls_stateid
));
389 ospf6_print_lshdr(register const struct lsa6_hdr
*lshp
, const u_char
*dataend
)
391 if ((u_char
*)(lshp
+ 1) > dataend
)
393 TCHECK(lshp
->ls_type
);
394 TCHECK(lshp
->ls_seq
);
396 printf("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
397 ipaddr_string(&lshp
->ls_router
),
398 EXTRACT_32BITS(&lshp
->ls_seq
),
399 EXTRACT_16BITS(&lshp
->ls_age
),
400 EXTRACT_16BITS(&lshp
->ls_length
)-(u_int
)sizeof(struct lsa6_hdr
));
402 ospf6_print_ls_type(EXTRACT_16BITS(&lshp
->ls_type
), &lshp
->ls_stateid
);
410 ospf6_print_lsaprefix(const u_int8_t
*tptr
, u_int lsa_length
)
412 const struct lsa6_prefix
*lsapp
= (struct lsa6_prefix
*)tptr
;
414 struct in6_addr prefix
;
416 if (lsa_length
< sizeof (*lsapp
) - 4)
418 lsa_length
-= sizeof (*lsapp
) - 4;
419 TCHECK2(*lsapp
, sizeof (*lsapp
) - 4);
420 wordlen
= (lsapp
->lsa_p_len
+ 31) / 32;
421 if (wordlen
* 4 > sizeof(struct in6_addr
)) {
422 printf(" bogus prefixlen /%d", lsapp
->lsa_p_len
);
425 if (lsa_length
< wordlen
* 4)
427 lsa_length
-= wordlen
* 4;
428 TCHECK2(lsapp
->lsa_p_prefix
, wordlen
* 4);
429 memset(&prefix
, 0, sizeof(prefix
));
430 memcpy(&prefix
, lsapp
->lsa_p_prefix
, wordlen
* 4);
431 printf("\n\t\t%s/%d", ip6addr_string(&prefix
),
433 if (lsapp
->lsa_p_opt
) {
434 printf(", Options [%s]",
435 bittok2str(ospf6_lsa_prefix_option_values
,
436 "none", lsapp
->lsa_p_opt
));
438 printf(", metric %u", EXTRACT_16BITS(&lsapp
->lsa_p_metric
));
439 return sizeof(*lsapp
) - 4 + wordlen
* 4;
447 * Print a single link state advertisement. If truncated return 1, else 0.
450 ospf6_print_lsa(register const struct lsa6
*lsap
, const u_char
*dataend
)
452 register const struct rlalink6
*rlp
;
454 register const struct tos_metric
*tosp
;
456 register const rtrid_t
*ap
;
458 register const struct aslametric
*almp
;
459 register const struct mcla
*mcp
;
461 register const struct llsa
*llsap
;
462 register const struct lsa6_prefix
*lsapp
;
464 register const u_int32_t
*lp
;
466 register u_int prefixes
;
467 register int bytelen
;
468 register u_int length
, lsa_length
;
470 const u_int8_t
*tptr
;
472 if (ospf6_print_lshdr(&lsap
->ls_hdr
, dataend
))
474 TCHECK(lsap
->ls_hdr
.ls_length
);
475 length
= EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
);
478 * The LSA length includes the length of the header;
479 * it must have a value that's at least that length.
480 * If it does, find the length of what follows the
483 if (length
< sizeof(struct lsa6_hdr
) || (u_char
*)lsap
+ length
> dataend
)
485 lsa_length
= length
- sizeof(struct lsa6_hdr
);
486 tptr
= (u_int8_t
*)lsap
+sizeof(struct lsa6_hdr
);
488 switch (EXTRACT_16BITS(&lsap
->ls_hdr
.ls_type
)) {
489 case LS_TYPE_ROUTER
| LS_SCOPE_AREA
:
490 if (lsa_length
< sizeof (lsap
->lsa_un
.un_rla
.rla_options
))
492 lsa_length
-= sizeof (lsap
->lsa_un
.un_rla
.rla_options
);
493 TCHECK(lsap
->lsa_un
.un_rla
.rla_options
);
494 printf("\n\t Options [%s]",
495 bittok2str(ospf6_option_values
, "none",
496 EXTRACT_32BITS(&lsap
->lsa_un
.un_rla
.rla_options
)));
497 printf(", RLA-Flags [%s]",
498 bittok2str(ospf6_rla_flag_values
, "none",
499 lsap
->lsa_un
.un_rla
.rla_flags
));
501 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
502 while (lsa_length
!= 0) {
503 if (lsa_length
< sizeof (*rlp
))
505 lsa_length
-= sizeof (*rlp
);
507 switch (rlp
->link_type
) {
509 case RLA_TYPE_VIRTUAL
:
510 printf("\n\t Virtual Link: Neighbor Router-ID %s"
511 "\n\t Neighbor Interface-ID %s, Interface %s",
512 ipaddr_string(&rlp
->link_nrtid
),
513 ipaddr_string(&rlp
->link_nifid
),
514 ipaddr_string(&rlp
->link_ifid
));
517 case RLA_TYPE_ROUTER
:
518 printf("\n\t Neighbor Router-ID %s"
519 "\n\t Neighbor Interface-ID %s, Interface %s",
520 ipaddr_string(&rlp
->link_nrtid
),
521 ipaddr_string(&rlp
->link_nifid
),
522 ipaddr_string(&rlp
->link_ifid
));
525 case RLA_TYPE_TRANSIT
:
526 printf("\n\t Neighbor Network-ID %s"
527 "\n\t Neighbor Interface-ID %s, Interface %s",
528 ipaddr_string(&rlp
->link_nrtid
),
529 ipaddr_string(&rlp
->link_nifid
),
530 ipaddr_string(&rlp
->link_ifid
));
534 printf("\n\t Unknown Router Links Type 0x%02x",
538 printf(", metric %d", EXTRACT_16BITS(&rlp
->link_metric
));
543 case LS_TYPE_NETWORK
| LS_SCOPE_AREA
:
544 if (lsa_length
< sizeof (lsap
->lsa_un
.un_nla
.nla_options
))
546 lsa_length
-= sizeof (lsap
->lsa_un
.un_nla
.nla_options
);
547 TCHECK(lsap
->lsa_un
.un_nla
.nla_options
);
548 printf("\n\t Options [%s]",
549 bittok2str(ospf6_option_values
, "none",
550 EXTRACT_32BITS(&lsap
->lsa_un
.un_nla
.nla_options
)));
552 printf("\n\t Connected Routers:");
553 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
554 while (lsa_length
!= 0) {
555 if (lsa_length
< sizeof (*ap
))
557 lsa_length
-= sizeof (*ap
);
559 printf("\n\t\t%s", ipaddr_string(ap
));
564 case LS_TYPE_INTER_AP
| LS_SCOPE_AREA
:
565 if (lsa_length
< sizeof (lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
))
567 lsa_length
-= sizeof (lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
568 TCHECK(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
569 printf(", metric %u",
570 EXTRACT_32BITS(&lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
) & SLA_MASK_METRIC
);
572 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_inter_ap
.inter_ap_prefix
;
573 while (lsa_length
!= 0) {
574 bytelen
= ospf6_print_lsaprefix(tptr
, lsa_length
);
577 lsa_length
-= bytelen
;
582 case LS_TYPE_ASE
| LS_SCOPE_AS
:
583 if (lsa_length
< sizeof (lsap
->lsa_un
.un_asla
.asla_metric
))
585 lsa_length
-= sizeof (lsap
->lsa_un
.un_asla
.asla_metric
);
586 TCHECK(lsap
->lsa_un
.un_asla
.asla_metric
);
587 flags32
= EXTRACT_32BITS(&lsap
->lsa_un
.un_asla
.asla_metric
);
588 printf("\n\t Flags [%s]",
589 bittok2str(ospf6_asla_flag_values
, "none", flags32
));
591 EXTRACT_32BITS(&lsap
->lsa_un
.un_asla
.asla_metric
) &
594 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_asla
.asla_prefix
;
595 lsapp
= (struct lsa6_prefix
*)tptr
;
596 bytelen
= ospf6_print_lsaprefix(tptr
, lsa_length
);
599 lsa_length
-= bytelen
;
602 if ((flags32
& ASLA_FLAG_FWDADDR
) != 0) {
603 struct in6_addr
*fwdaddr6
;
605 fwdaddr6
= (struct in6_addr
*)tptr
;
606 if (lsa_length
< sizeof (*fwdaddr6
))
608 lsa_length
-= sizeof (*fwdaddr6
);
610 printf(" forward %s",
611 ip6addr_string(fwdaddr6
));
612 tptr
+= sizeof(*fwdaddr6
);
615 if ((flags32
& ASLA_FLAG_ROUTETAG
) != 0) {
616 if (lsa_length
< sizeof (u_int32_t
))
618 lsa_length
-= sizeof (u_int32_t
);
619 TCHECK(*(u_int32_t
*)tptr
);
621 ipaddr_string((u_int32_t
*)tptr
));
622 tptr
+= sizeof(u_int32_t
);
625 if (lsapp
->lsa_p_metric
) {
626 if (lsa_length
< sizeof (u_int32_t
))
628 lsa_length
-= sizeof (u_int32_t
);
629 TCHECK(*(u_int32_t
*)tptr
);
630 printf(" RefLSID: %s",
631 ipaddr_string((u_int32_t
*)tptr
));
632 tptr
+= sizeof(u_int32_t
);
638 llsap
= &lsap
->lsa_un
.un_llsa
;
639 if (lsa_length
< sizeof (llsap
->llsa_priandopt
))
641 lsa_length
-= sizeof (llsap
->llsa_priandopt
);
642 TCHECK(llsap
->llsa_priandopt
);
643 printf("\n\t Options [%s]",
644 bittok2str(ospf6_option_values
, "none",
645 EXTRACT_32BITS(&llsap
->llsa_options
)));
647 if (lsa_length
< sizeof (llsap
->llsa_lladdr
) + sizeof (llsap
->llsa_nprefix
))
649 lsa_length
-= sizeof (llsap
->llsa_lladdr
) + sizeof (llsap
->llsa_nprefix
);
650 prefixes
= EXTRACT_32BITS(&llsap
->llsa_nprefix
);
651 printf("\n\t Priority %d, Link-local address %s, Prefixes %d:",
652 llsap
->llsa_priority
,
653 ip6addr_string(&llsap
->llsa_lladdr
),
656 tptr
= (u_int8_t
*)llsap
->llsa_prefix
;
657 while (prefixes
> 0) {
658 bytelen
= ospf6_print_lsaprefix(tptr
, lsa_length
);
662 lsa_length
-= bytelen
;
667 case LS_TYPE_INTRA_AP
| LS_SCOPE_AREA
:
668 /* Intra-Area-Prefix LSA */
669 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
))
671 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
672 TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
674 EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_lstype
),
675 &lsap
->lsa_un
.un_intra_ap
.intra_ap_lsid
);
677 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
))
679 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
680 TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
681 prefixes
= EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
682 printf("\n\t Prefixes %d:", prefixes
);
684 tptr
= (u_int8_t
*)lsap
->lsa_un
.un_intra_ap
.intra_ap_prefix
;
685 while (prefixes
> 0) {
686 bytelen
= ospf6_print_lsaprefix(tptr
, lsa_length
);
690 lsa_length
-= bytelen
;
695 case LS_TYPE_GRACE
| LS_SCOPE_LINKLOCAL
:
696 if (ospf_print_grace_lsa(tptr
, lsa_length
) == -1) {
701 case LS_TYPE_INTRA_ATE
| LS_SCOPE_LINKLOCAL
:
702 if (ospf_print_te_lsa(tptr
, lsa_length
) == -1) {
708 if(!print_unknown_data(gndo
,tptr
,
722 ospf6_decode_v3(register const struct ospf6hdr
*op
,
723 register const u_char
*dataend
)
725 register const rtrid_t
*ap
;
726 register const struct lsr6
*lsrp
;
727 register const struct lsa6_hdr
*lshp
;
728 register const struct lsa6
*lsap
;
731 switch (op
->ospf6_type
) {
733 case OSPF_TYPE_HELLO
:
734 printf("\n\tOptions [%s]",
735 bittok2str(ospf6_option_values
, "none",
736 EXTRACT_32BITS(&op
->ospf6_hello
.hello_options
)));
738 TCHECK(op
->ospf6_hello
.hello_deadint
);
739 printf("\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
740 EXTRACT_16BITS(&op
->ospf6_hello
.hello_helloint
),
741 EXTRACT_16BITS(&op
->ospf6_hello
.hello_deadint
),
742 ipaddr_string(&op
->ospf6_hello
.hello_ifid
),
743 op
->ospf6_hello
.hello_priority
);
745 TCHECK(op
->ospf6_hello
.hello_dr
);
746 if (op
->ospf6_hello
.hello_dr
!= 0)
747 printf("\n\t Designated Router %s",
748 ipaddr_string(&op
->ospf6_hello
.hello_dr
));
749 TCHECK(op
->ospf6_hello
.hello_bdr
);
750 if (op
->ospf6_hello
.hello_bdr
!= 0)
751 printf(", Backup Designated Router %s",
752 ipaddr_string(&op
->ospf6_hello
.hello_bdr
));
754 printf("\n\t Neighbor List:");
755 ap
= op
->ospf6_hello
.hello_neighbor
;
756 while ((u_char
*)ap
< dataend
) {
758 printf("\n\t %s", ipaddr_string(ap
));
765 TCHECK(op
->ospf6_db
.db_options
);
766 printf("\n\tOptions [%s]",
767 bittok2str(ospf6_option_values
, "none",
768 EXTRACT_32BITS(&op
->ospf6_db
.db_options
)));
769 TCHECK(op
->ospf6_db
.db_flags
);
770 printf(", DD Flags [%s]",
771 bittok2str(ospf6_dd_flag_values
,"none",op
->ospf6_db
.db_flags
));
773 TCHECK(op
->ospf6_db
.db_seq
);
774 printf(", MTU %u, DD-Sequence 0x%08x",
775 EXTRACT_16BITS(&op
->ospf6_db
.db_mtu
),
776 EXTRACT_32BITS(&op
->ospf6_db
.db_seq
));
778 /* Print all the LS adv's */
779 lshp
= op
->ospf6_db
.db_lshdr
;
780 while ((u_char
*)lshp
< dataend
) {
781 if (ospf6_print_lshdr(lshp
++, dataend
))
787 case OSPF_TYPE_LS_REQ
:
789 lsrp
= op
->ospf6_lsr
;
790 while ((u_char
*)lsrp
< dataend
) {
792 printf("\n\t Advertising Router %s",
793 ipaddr_string(&lsrp
->ls_router
));
794 ospf6_print_ls_type(EXTRACT_16BITS(&lsrp
->ls_type
),
801 case OSPF_TYPE_LS_UPDATE
:
803 lsap
= op
->ospf6_lsu
.lsu_lsa
;
804 TCHECK(op
->ospf6_lsu
.lsu_count
);
805 i
= EXTRACT_32BITS(&op
->ospf6_lsu
.lsu_count
);
806 while ((u_char
*)lsap
< dataend
&& i
--) {
807 if (ospf6_print_lsa(lsap
, dataend
))
809 lsap
= (struct lsa6
*)((u_char
*)lsap
+
810 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
));
816 case OSPF_TYPE_LS_ACK
:
818 lshp
= op
->ospf6_lsa
.lsa_lshdr
;
819 while ((u_char
*)lshp
< dataend
) {
820 if (ospf6_print_lshdr(lshp
++, dataend
))
834 /* RFC5613 Section 2.2 (w/o the TLVs) */
836 ospf6_print_lls(const u_char
*cp
, const u_int len
)
842 if (len
< OSPF_LLS_HDRLEN
)
846 printf("\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp
));
848 /* LLS Data Length */
850 llsdatalen
= EXTRACT_16BITS(cp
);
851 printf(", Data Length %u", llsdatalen
);
852 if (llsdatalen
< OSPF_LLS_HDRLEN
|| llsdatalen
> len
)
856 TCHECK2(*cp
, llsdatalen
- OSPF_LLS_HDRLEN
);
857 /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
864 /* RFC6506 Section 4.1 */
866 ospf6_decode_at(const u_char
*cp
, const u_int len
)
868 uint16_t authdatalen
;
872 if (len
< OSPF6_AT_HDRLEN
)
874 /* Authentication Type */
876 printf("\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str
, "unknown (0x%04x)", EXTRACT_16BITS(cp
)));
880 authdatalen
= EXTRACT_16BITS(cp
);
881 printf(", Length %u", authdatalen
);
882 if (authdatalen
< OSPF6_AT_HDRLEN
|| authdatalen
> len
)
888 /* Security Association ID */
890 printf(", SAID %u", EXTRACT_16BITS(cp
));
892 /* Cryptographic Sequence Number (High-Order 32 Bits) */
894 printf(", CSN 0x%08x", EXTRACT_32BITS(cp
));
896 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
898 printf(":%08x", EXTRACT_32BITS(cp
));
900 /* Authentication Data */
901 TCHECK2(*cp
, authdatalen
- OSPF6_AT_HDRLEN
);
903 print_unknown_data(gndo
,cp
, "\n\tAuthentication Data ", authdatalen
- OSPF6_AT_HDRLEN
);
910 /* The trailing data may include LLS and/or AT data (in this specific order).
911 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
912 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
913 * any other packet type, thus decode the AT data regardless of the AT-bit.
916 ospf6_decode_v3_trailer(const struct ospf6hdr
*op
, const u_char
*cp
, const unsigned len
)
919 u_char lls_hello
= op
->ospf6_type
== OSPF_TYPE_HELLO
&&
920 op
->ospf6_hello
.hello_options
& OSPF6_OPTION_L
;
921 u_char lls_dd
= op
->ospf6_type
== OSPF_TYPE_DD
&&
922 op
->ospf6_db
.db_options
& OSPF6_OPTION_L
;
924 if ((lls_hello
|| lls_dd
) && (llslen
= ospf6_print_lls(cp
, len
)) < 0)
926 return ospf6_decode_at(cp
+ llslen
, len
- llslen
);
933 ospf6_print(register const u_char
*bp
, register u_int length
)
935 register const struct ospf6hdr
*op
;
936 register const u_char
*dataend
;
937 register const char *cp
;
940 op
= (struct ospf6hdr
*)bp
;
942 /* If the type is valid translate it, or just print the type */
943 /* value. If it's not valid, say so and return */
944 TCHECK(op
->ospf6_type
);
945 cp
= tok2str(ospf6_type_values
, "unknown packet type (%u)", op
->ospf6_type
);
946 printf("OSPFv%u, %s, length %d", op
->ospf6_version
, cp
, length
);
951 if(!vflag
) { /* non verbose - so lets bail out here */
955 /* OSPFv3 data always comes first and optional trailing data may follow. */
956 TCHECK(op
->ospf6_len
);
957 datalen
= EXTRACT_16BITS(&op
->ospf6_len
);
958 if (datalen
> length
) {
959 printf(" [len %d]", datalen
);
962 dataend
= bp
+ datalen
;
964 TCHECK(op
->ospf6_routerid
);
965 printf("\n\tRouter-ID %s", ipaddr_string(&op
->ospf6_routerid
));
967 TCHECK(op
->ospf6_areaid
);
968 if (op
->ospf6_areaid
!= 0)
969 printf(", Area %s", ipaddr_string(&op
->ospf6_areaid
));
971 printf(", Backbone Area");
972 TCHECK(op
->ospf6_instanceid
);
973 if (op
->ospf6_instanceid
)
974 printf(", Instance %u", op
->ospf6_instanceid
);
976 /* Do rest according to version. */
977 switch (op
->ospf6_version
) {
981 if (ospf6_decode_v3(op
, dataend
) ||
982 ospf6_decode_v3_trailer(op
, dataend
, length
- datalen
))
985 } /* end switch on version */