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>
32 #include "interface.h"
33 #include "addrtoname.h"
38 #define OSPF_TYPE_HELLO 1 /* Hello */
39 #define OSPF_TYPE_DD 2 /* Database Description */
40 #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
41 #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
42 #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
44 /* Options *_options */
45 #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */
46 #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */
47 #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */
48 #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */
49 #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */
50 #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */
51 /* The field is actually 24-bit (RFC5340 Section A.2). */
52 #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */
53 #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */
54 #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */
58 #define OSPF6_DB_INIT 0x04 /* */
59 #define OSPF6_DB_MORE 0x02
60 #define OSPF6_DB_MASTER 0x01
61 #define OSPF6_DB_M6 0x10 /* IPv6 MTU */
64 #define LS_TYPE_ROUTER 1 /* router link */
65 #define LS_TYPE_NETWORK 2 /* network link */
66 #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */
67 #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */
68 #define LS_TYPE_ASE 5 /* ASE */
69 #define LS_TYPE_GROUP 6 /* Group membership */
70 #define LS_TYPE_NSSA 7 /* NSSA */
71 #define LS_TYPE_LINK 8 /* Link LSA */
72 #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */
73 #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */
74 #define LS_TYPE_GRACE 11 /* Grace LSA */
75 #define LS_TYPE_RI 12 /* Router information */
76 #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */
77 #define LS_TYPE_L1VPN 14 /* L1VPN */
78 #define LS_TYPE_MASK 0x1fff
80 #define LS_SCOPE_LINKLOCAL 0x0000
81 #define LS_SCOPE_AREA 0x2000
82 #define LS_SCOPE_AS 0x4000
83 #define LS_SCOPE_MASK 0x6000
84 #define LS_SCOPE_U 0x8000
86 /* rla_link.link_type */
87 #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
88 #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
89 #define RLA_TYPE_VIRTUAL 4 /* virtual link */
92 #define RLA_FLAG_B 0x01
93 #define RLA_FLAG_E 0x02
94 #define RLA_FLAG_V 0x04
95 #define RLA_FLAG_W 0x08
96 #define RLA_FLAG_N 0x10
98 /* lsa_prefix options */
99 #define LSA_PREFIX_OPT_NU 0x01
100 #define LSA_PREFIX_OPT_LA 0x02
101 #define LSA_PREFIX_OPT_MC 0x04
102 #define LSA_PREFIX_OPT_P 0x08
103 #define LSA_PREFIX_OPT_DN 0x10
105 /* sla_tosmetric breakdown */
106 #define SLA_MASK_TOS 0x7f000000
107 #define SLA_MASK_METRIC 0x00ffffff
108 #define SLA_SHIFT_TOS 24
111 #define ASLA_FLAG_FWDADDR 0x02000000
112 #define ASLA_FLAG_ROUTETAG 0x01000000
113 #define ASLA_MASK_METRIC 0x00ffffff
115 /* RFC6506 Section 4.1 */
116 #define OSPF6_AT_HDRLEN 16U
117 #define OSPF6_AUTH_TYPE_HMAC 0x0001
119 typedef uint32_t rtrid_t
;
121 /* link state advertisement header */
132 /* Length of an IPv6 address, in bytes. */
133 #define IPV6_ADDR_LEN_BYTES (128/8)
138 uint16_t lsa_p_metric
;
139 uint8_t lsa_p_prefix
[IPV6_ADDR_LEN_BYTES
]; /* maximum length */
142 /* link state advertisement */
144 struct lsa6_hdr ls_hdr
;
146 /* Link state types */
148 /* Router links advertisements */
154 #define rla_flags rla_flgandopt.flg
155 #define rla_options rla_flgandopt.opt
158 uint8_t link_zero
[1];
159 uint16_t link_metric
;
163 } rla_link
[1]; /* may repeat */
166 /* Network links advertisements */
168 uint32_t nla_options
;
169 rtrid_t nla_router
[1]; /* may repeat */
172 /* Inter Area Prefix LSA */
174 uint32_t inter_ap_metric
;
175 struct lsa6_prefix inter_ap_prefix
[1];
178 /* AS external links advertisements */
180 uint32_t asla_metric
;
181 struct lsa6_prefix asla_prefix
[1];
182 /* some optional fields follow */
186 /* Summary links advertisements */
188 struct in_addr sla_mask
;
189 uint32_t sla_tosmetric
[1]; /* may repeat */
192 /* Multicast group membership */
195 struct in_addr mcla_vid
;
207 #define llsa_priority llsa_priandopt.pri
208 #define llsa_options llsa_priandopt.opt
209 struct in6_addr llsa_lladdr
;
210 uint32_t llsa_nprefix
;
211 struct lsa6_prefix llsa_prefix
[1];
214 /* Intra-Area-Prefix */
216 uint16_t intra_ap_nprefix
;
217 uint16_t intra_ap_lstype
;
218 rtrid_t intra_ap_lsid
;
219 rtrid_t intra_ap_rtid
;
220 struct lsa6_prefix intra_ap_prefix
[1];
229 uint8_t ospf6_version
;
232 rtrid_t ospf6_routerid
;
233 rtrid_t ospf6_areaid
;
234 uint16_t ospf6_chksum
;
235 uint8_t ospf6_instanceid
;
240 * The OSPF6 header length is 16 bytes, regardless of how your compiler
241 * might choose to pad the above structure.
243 #define OSPF6HDR_LEN 16
252 #define hello_priority hello_priandopt.pri
253 #define hello_options hello_priandopt.opt
254 uint16_t hello_helloint
;
255 uint16_t hello_deadint
;
258 rtrid_t hello_neighbor
[1]; /* may repeat */
261 /* Database Description packet */
268 struct lsa6_hdr db_lshdr
[1]; /* may repeat */
271 /* Link State Request */
279 /* Link State Update */
282 struct lsa6 lsu_lsa
[1]; /* may repeat */
285 static const char tstr
[] = " [|ospf3]";
287 static const struct tok ospf6_option_values
[] = {
288 { OSPF6_OPTION_V6
, "V6" },
289 { OSPF6_OPTION_E
, "External" },
290 { OSPF6_OPTION_MC
, "Deprecated" },
291 { OSPF6_OPTION_N
, "NSSA" },
292 { OSPF6_OPTION_R
, "Router" },
293 { OSPF6_OPTION_DC
, "Demand Circuit" },
294 { OSPF6_OPTION_AF
, "AFs Support" },
295 { OSPF6_OPTION_L
, "LLS" },
296 { OSPF6_OPTION_AT
, "Authentication Trailer" },
300 static const struct tok ospf6_rla_flag_values
[] = {
301 { RLA_FLAG_B
, "ABR" },
302 { RLA_FLAG_E
, "External" },
303 { RLA_FLAG_V
, "Virtual-Link Endpoint" },
304 { RLA_FLAG_W
, "Wildcard Receiver" },
305 { RLA_FLAG_N
, "NSSA Translator" },
309 static const struct tok ospf6_asla_flag_values
[] = {
310 { ASLA_FLAG_EXTERNAL
, "External Type 2" },
311 { ASLA_FLAG_FWDADDR
, "Forwarding" },
312 { ASLA_FLAG_ROUTETAG
, "Tag" },
316 static const struct tok ospf6_type_values
[] = {
317 { OSPF_TYPE_HELLO
, "Hello" },
318 { OSPF_TYPE_DD
, "Database Description" },
319 { OSPF_TYPE_LS_REQ
, "LS-Request" },
320 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
321 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
325 static const struct tok ospf6_lsa_values
[] = {
326 { LS_TYPE_ROUTER
, "Router" },
327 { LS_TYPE_NETWORK
, "Network" },
328 { LS_TYPE_INTER_AP
, "Inter-Area Prefix" },
329 { LS_TYPE_INTER_AR
, "Inter-Area Router" },
330 { LS_TYPE_ASE
, "External" },
331 { LS_TYPE_GROUP
, "Deprecated" },
332 { LS_TYPE_NSSA
, "NSSA" },
333 { LS_TYPE_LINK
, "Link" },
334 { LS_TYPE_INTRA_AP
, "Intra-Area Prefix" },
335 { LS_TYPE_INTRA_ATE
, "Intra-Area TE" },
336 { LS_TYPE_GRACE
, "Grace" },
337 { LS_TYPE_RI
, "Router Information" },
338 { LS_TYPE_INTER_ASTE
, "Inter-AS-TE" },
339 { LS_TYPE_L1VPN
, "Layer 1 VPN" },
343 static const struct tok ospf6_ls_scope_values
[] = {
344 { LS_SCOPE_LINKLOCAL
, "Link Local" },
345 { LS_SCOPE_AREA
, "Area Local" },
346 { LS_SCOPE_AS
, "Domain Wide" },
350 static const struct tok ospf6_dd_flag_values
[] = {
351 { OSPF6_DB_INIT
, "Init" },
352 { OSPF6_DB_MORE
, "More" },
353 { OSPF6_DB_MASTER
, "Master" },
354 { OSPF6_DB_M6
, "IPv6 MTU" },
358 static const struct tok ospf6_lsa_prefix_option_values
[] = {
359 { LSA_PREFIX_OPT_NU
, "No Unicast" },
360 { LSA_PREFIX_OPT_LA
, "Local address" },
361 { LSA_PREFIX_OPT_MC
, "Deprecated" },
362 { LSA_PREFIX_OPT_P
, "Propagate" },
363 { LSA_PREFIX_OPT_DN
, "Down" },
367 static const struct tok ospf6_auth_type_str
[] = {
368 { OSPF6_AUTH_TYPE_HMAC
, "HMAC" },
373 ospf6_print_ls_type(netdissect_options
*ndo
,
374 register u_int ls_type
, register const rtrid_t
*ls_stateid
)
376 ND_PRINT((ndo
, "\n\t %s LSA (%d), %s Scope%s, LSA-ID %s",
377 tok2str(ospf6_lsa_values
, "Unknown", ls_type
& LS_TYPE_MASK
),
378 ls_type
& LS_TYPE_MASK
,
379 tok2str(ospf6_ls_scope_values
, "Unknown", ls_type
& LS_SCOPE_MASK
),
380 ls_type
&0x8000 ? ", transitive" : "", /* U-bit */
381 ipaddr_string(ndo
, ls_stateid
)));
385 ospf6_print_lshdr(netdissect_options
*ndo
,
386 register const struct lsa6_hdr
*lshp
, const u_char
*dataend
)
388 if ((const u_char
*)(lshp
+ 1) > dataend
)
390 ND_TCHECK(lshp
->ls_type
);
391 ND_TCHECK(lshp
->ls_seq
);
393 ND_PRINT((ndo
, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
394 ipaddr_string(ndo
, &lshp
->ls_router
),
395 EXTRACT_32BITS(&lshp
->ls_seq
),
396 EXTRACT_16BITS(&lshp
->ls_age
),
397 EXTRACT_16BITS(&lshp
->ls_length
)-(u_int
)sizeof(struct lsa6_hdr
)));
399 ospf6_print_ls_type(ndo
, EXTRACT_16BITS(&lshp
->ls_type
), &lshp
->ls_stateid
);
407 ospf6_print_lsaprefix(netdissect_options
*ndo
,
408 const uint8_t *tptr
, u_int lsa_length
)
410 const struct lsa6_prefix
*lsapp
= (const struct lsa6_prefix
*)tptr
;
412 struct in6_addr prefix
;
414 if (lsa_length
< sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
)
416 lsa_length
-= sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
;
417 ND_TCHECK2(*lsapp
, sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
);
418 wordlen
= (lsapp
->lsa_p_len
+ 31) / 32;
419 if (wordlen
* 4 > sizeof(struct in6_addr
)) {
420 ND_PRINT((ndo
, " bogus prefixlen /%d", lsapp
->lsa_p_len
));
423 if (lsa_length
< wordlen
* 4)
425 lsa_length
-= wordlen
* 4;
426 ND_TCHECK2(lsapp
->lsa_p_prefix
, wordlen
* 4);
427 memset(&prefix
, 0, sizeof(prefix
));
428 memcpy(&prefix
, lsapp
->lsa_p_prefix
, wordlen
* 4);
429 ND_PRINT((ndo
, "\n\t\t%s/%d", ip6addr_string(ndo
, &prefix
),
431 if (lsapp
->lsa_p_opt
) {
432 ND_PRINT((ndo
, ", Options [%s]",
433 bittok2str(ospf6_lsa_prefix_option_values
,
434 "none", lsapp
->lsa_p_opt
)));
436 ND_PRINT((ndo
, ", metric %u", EXTRACT_16BITS(&lsapp
->lsa_p_metric
)));
437 return sizeof(*lsapp
) - IPV6_ADDR_LEN_BYTES
+ wordlen
* 4;
445 * Print a single link state advertisement. If truncated return 1, else 0.
448 ospf6_print_lsa(netdissect_options
*ndo
,
449 register const struct lsa6
*lsap
, const u_char
*dataend
)
451 register const struct rlalink6
*rlp
;
453 register const struct tos_metric
*tosp
;
455 register const rtrid_t
*ap
;
457 register const struct aslametric
*almp
;
458 register const struct mcla
*mcp
;
460 register const struct llsa
*llsap
;
461 register const struct lsa6_prefix
*lsapp
;
463 register const uint32_t *lp
;
465 register u_int prefixes
;
466 register int bytelen
;
467 register u_int length
, lsa_length
;
471 if (ospf6_print_lshdr(ndo
, &lsap
->ls_hdr
, dataend
))
473 ND_TCHECK(lsap
->ls_hdr
.ls_length
);
474 length
= EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
);
477 * The LSA length includes the length of the header;
478 * it must have a value that's at least that length.
479 * If it does, find the length of what follows the
482 if (length
< sizeof(struct lsa6_hdr
) || (const u_char
*)lsap
+ length
> dataend
)
484 lsa_length
= length
- sizeof(struct lsa6_hdr
);
485 tptr
= (const uint8_t *)lsap
+sizeof(struct lsa6_hdr
);
487 switch (EXTRACT_16BITS(&lsap
->ls_hdr
.ls_type
)) {
488 case LS_TYPE_ROUTER
| LS_SCOPE_AREA
:
489 if (lsa_length
< sizeof (lsap
->lsa_un
.un_rla
.rla_options
))
491 lsa_length
-= sizeof (lsap
->lsa_un
.un_rla
.rla_options
);
492 ND_TCHECK(lsap
->lsa_un
.un_rla
.rla_options
);
493 ND_PRINT((ndo
, "\n\t Options [%s]",
494 bittok2str(ospf6_option_values
, "none",
495 EXTRACT_32BITS(&lsap
->lsa_un
.un_rla
.rla_options
))));
496 ND_PRINT((ndo
, ", RLA-Flags [%s]",
497 bittok2str(ospf6_rla_flag_values
, "none",
498 lsap
->lsa_un
.un_rla
.rla_flags
)));
500 rlp
= lsap
->lsa_un
.un_rla
.rla_link
;
501 while (lsa_length
!= 0) {
502 if (lsa_length
< sizeof (*rlp
))
504 lsa_length
-= sizeof (*rlp
);
506 switch (rlp
->link_type
) {
508 case RLA_TYPE_VIRTUAL
:
509 ND_PRINT((ndo
, "\n\t Virtual Link: Neighbor Router-ID %s"
510 "\n\t Neighbor Interface-ID %s, Interface %s",
511 ipaddr_string(ndo
, &rlp
->link_nrtid
),
512 ipaddr_string(ndo
, &rlp
->link_nifid
),
513 ipaddr_string(ndo
, &rlp
->link_ifid
)));
516 case RLA_TYPE_ROUTER
:
517 ND_PRINT((ndo
, "\n\t Neighbor Router-ID %s"
518 "\n\t Neighbor Interface-ID %s, Interface %s",
519 ipaddr_string(ndo
, &rlp
->link_nrtid
),
520 ipaddr_string(ndo
, &rlp
->link_nifid
),
521 ipaddr_string(ndo
, &rlp
->link_ifid
)));
524 case RLA_TYPE_TRANSIT
:
525 ND_PRINT((ndo
, "\n\t Neighbor Network-ID %s"
526 "\n\t Neighbor Interface-ID %s, Interface %s",
527 ipaddr_string(ndo
, &rlp
->link_nrtid
),
528 ipaddr_string(ndo
, &rlp
->link_nifid
),
529 ipaddr_string(ndo
, &rlp
->link_ifid
)));
533 ND_PRINT((ndo
, "\n\t Unknown Router Links Type 0x%02x",
537 ND_PRINT((ndo
, ", metric %d", EXTRACT_16BITS(&rlp
->link_metric
)));
542 case LS_TYPE_NETWORK
| LS_SCOPE_AREA
:
543 if (lsa_length
< sizeof (lsap
->lsa_un
.un_nla
.nla_options
))
545 lsa_length
-= sizeof (lsap
->lsa_un
.un_nla
.nla_options
);
546 ND_TCHECK(lsap
->lsa_un
.un_nla
.nla_options
);
547 ND_PRINT((ndo
, "\n\t Options [%s]",
548 bittok2str(ospf6_option_values
, "none",
549 EXTRACT_32BITS(&lsap
->lsa_un
.un_nla
.nla_options
))));
551 ND_PRINT((ndo
, "\n\t Connected Routers:"));
552 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
553 while (lsa_length
!= 0) {
554 if (lsa_length
< sizeof (*ap
))
556 lsa_length
-= sizeof (*ap
);
558 ND_PRINT((ndo
, "\n\t\t%s", ipaddr_string(ndo
, ap
)));
563 case LS_TYPE_INTER_AP
| LS_SCOPE_AREA
:
564 if (lsa_length
< sizeof (lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
))
566 lsa_length
-= sizeof (lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
567 ND_TCHECK(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
568 ND_PRINT((ndo
, ", metric %u",
569 EXTRACT_32BITS(&lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
) & SLA_MASK_METRIC
));
571 tptr
= (const uint8_t *)lsap
->lsa_un
.un_inter_ap
.inter_ap_prefix
;
572 while (lsa_length
!= 0) {
573 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
576 lsa_length
-= bytelen
;
581 case LS_TYPE_ASE
| LS_SCOPE_AS
:
582 if (lsa_length
< sizeof (lsap
->lsa_un
.un_asla
.asla_metric
))
584 lsa_length
-= sizeof (lsap
->lsa_un
.un_asla
.asla_metric
);
585 ND_TCHECK(lsap
->lsa_un
.un_asla
.asla_metric
);
586 flags32
= EXTRACT_32BITS(&lsap
->lsa_un
.un_asla
.asla_metric
);
587 ND_PRINT((ndo
, "\n\t Flags [%s]",
588 bittok2str(ospf6_asla_flag_values
, "none", flags32
)));
589 ND_PRINT((ndo
, " metric %u",
590 EXTRACT_32BITS(&lsap
->lsa_un
.un_asla
.asla_metric
) &
593 tptr
= (const uint8_t *)lsap
->lsa_un
.un_asla
.asla_prefix
;
594 lsapp
= (const struct lsa6_prefix
*)tptr
;
595 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
598 lsa_length
-= bytelen
;
601 if ((flags32
& ASLA_FLAG_FWDADDR
) != 0) {
602 const struct in6_addr
*fwdaddr6
;
604 fwdaddr6
= (const struct in6_addr
*)tptr
;
605 if (lsa_length
< sizeof (*fwdaddr6
))
607 lsa_length
-= sizeof (*fwdaddr6
);
608 ND_TCHECK(*fwdaddr6
);
609 ND_PRINT((ndo
, " forward %s",
610 ip6addr_string(ndo
, fwdaddr6
)));
611 tptr
+= sizeof(*fwdaddr6
);
614 if ((flags32
& ASLA_FLAG_ROUTETAG
) != 0) {
615 if (lsa_length
< sizeof (uint32_t))
617 lsa_length
-= sizeof (uint32_t);
618 ND_TCHECK(*(const uint32_t *)tptr
);
619 ND_PRINT((ndo
, " tag %s",
620 ipaddr_string(ndo
, (const uint32_t *)tptr
)));
621 tptr
+= sizeof(uint32_t);
624 if (lsapp
->lsa_p_metric
) {
625 if (lsa_length
< sizeof (uint32_t))
627 lsa_length
-= sizeof (uint32_t);
628 ND_TCHECK(*(const uint32_t *)tptr
);
629 ND_PRINT((ndo
, " RefLSID: %s",
630 ipaddr_string(ndo
, (const uint32_t *)tptr
)));
631 tptr
+= sizeof(uint32_t);
637 llsap
= &lsap
->lsa_un
.un_llsa
;
638 if (lsa_length
< sizeof (llsap
->llsa_priandopt
))
640 lsa_length
-= sizeof (llsap
->llsa_priandopt
);
641 ND_TCHECK(llsap
->llsa_priandopt
);
642 ND_PRINT((ndo
, "\n\t Options [%s]",
643 bittok2str(ospf6_option_values
, "none",
644 EXTRACT_32BITS(&llsap
->llsa_options
))));
646 if (lsa_length
< sizeof (llsap
->llsa_lladdr
) + sizeof (llsap
->llsa_nprefix
))
648 lsa_length
-= sizeof (llsap
->llsa_lladdr
) + sizeof (llsap
->llsa_nprefix
);
649 prefixes
= EXTRACT_32BITS(&llsap
->llsa_nprefix
);
650 ND_PRINT((ndo
, "\n\t Priority %d, Link-local address %s, Prefixes %d:",
651 llsap
->llsa_priority
,
652 ip6addr_string(ndo
, &llsap
->llsa_lladdr
),
655 tptr
= (const uint8_t *)llsap
->llsa_prefix
;
656 while (prefixes
> 0) {
657 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
661 lsa_length
-= bytelen
;
666 case LS_TYPE_INTRA_AP
| LS_SCOPE_AREA
:
667 /* Intra-Area-Prefix LSA */
668 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
))
670 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
671 ND_TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
672 ospf6_print_ls_type(ndo
,
673 EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_lstype
),
674 &lsap
->lsa_un
.un_intra_ap
.intra_ap_lsid
);
676 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
))
678 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
679 ND_TCHECK(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
680 prefixes
= EXTRACT_16BITS(&lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
681 ND_PRINT((ndo
, "\n\t Prefixes %d:", prefixes
));
683 tptr
= (const uint8_t *)lsap
->lsa_un
.un_intra_ap
.intra_ap_prefix
;
684 while (prefixes
> 0) {
685 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
689 lsa_length
-= bytelen
;
694 case LS_TYPE_GRACE
| LS_SCOPE_LINKLOCAL
:
695 if (ospf_print_grace_lsa(ndo
, tptr
, lsa_length
) == -1) {
700 case LS_TYPE_INTRA_ATE
| LS_SCOPE_LINKLOCAL
:
701 if (ospf_print_te_lsa(ndo
, tptr
, lsa_length
) == -1) {
707 if(!print_unknown_data(ndo
,tptr
,
721 ospf6_decode_v3(netdissect_options
*ndo
,
722 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 register const struct hello6
*hellop
= (const struct hello6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
736 ND_PRINT((ndo
, "\n\tOptions [%s]",
737 bittok2str(ospf6_option_values
, "none",
738 EXTRACT_32BITS(&hellop
->hello_options
))));
740 ND_TCHECK(hellop
->hello_deadint
);
741 ND_PRINT((ndo
, "\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
742 EXTRACT_16BITS(&hellop
->hello_helloint
),
743 EXTRACT_16BITS(&hellop
->hello_deadint
),
744 ipaddr_string(ndo
, &hellop
->hello_ifid
),
745 hellop
->hello_priority
));
747 ND_TCHECK(hellop
->hello_dr
);
748 if (EXTRACT_32BITS(&hellop
->hello_dr
) != 0)
749 ND_PRINT((ndo
, "\n\t Designated Router %s",
750 ipaddr_string(ndo
, &hellop
->hello_dr
)));
751 ND_TCHECK(hellop
->hello_bdr
);
752 if (EXTRACT_32BITS(&hellop
->hello_bdr
) != 0)
753 ND_PRINT((ndo
, ", Backup Designated Router %s",
754 ipaddr_string(ndo
, &hellop
->hello_bdr
)));
755 if (ndo
->ndo_vflag
> 1) {
756 ND_PRINT((ndo
, "\n\t Neighbor List:"));
757 ap
= hellop
->hello_neighbor
;
758 while ((const u_char
*)ap
< dataend
) {
760 ND_PRINT((ndo
, "\n\t %s", ipaddr_string(ndo
, ap
)));
768 register const struct dd6
*ddp
= (const struct dd6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
770 ND_TCHECK(ddp
->db_options
);
771 ND_PRINT((ndo
, "\n\tOptions [%s]",
772 bittok2str(ospf6_option_values
, "none",
773 EXTRACT_32BITS(&ddp
->db_options
))));
774 ND_TCHECK(ddp
->db_flags
);
775 ND_PRINT((ndo
, ", DD Flags [%s]",
776 bittok2str(ospf6_dd_flag_values
,"none",ddp
->db_flags
)));
778 ND_TCHECK(ddp
->db_seq
);
779 ND_PRINT((ndo
, ", MTU %u, DD-Sequence 0x%08x",
780 EXTRACT_16BITS(&ddp
->db_mtu
),
781 EXTRACT_32BITS(&ddp
->db_seq
)));
782 if (ndo
->ndo_vflag
> 1) {
783 /* Print all the LS adv's */
784 lshp
= ddp
->db_lshdr
;
785 while ((const u_char
*)lshp
< dataend
) {
786 if (ospf6_print_lshdr(ndo
, lshp
++, dataend
))
793 case OSPF_TYPE_LS_REQ
:
794 if (ndo
->ndo_vflag
> 1) {
795 lsrp
= (const struct lsr6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
796 while ((const u_char
*)lsrp
< dataend
) {
798 ND_PRINT((ndo
, "\n\t Advertising Router %s",
799 ipaddr_string(ndo
, &lsrp
->ls_router
)));
800 ospf6_print_ls_type(ndo
, EXTRACT_16BITS(&lsrp
->ls_type
),
807 case OSPF_TYPE_LS_UPDATE
:
808 if (ndo
->ndo_vflag
> 1) {
809 register const struct lsu6
*lsup
= (const struct lsu6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
811 ND_TCHECK(lsup
->lsu_count
);
812 i
= EXTRACT_32BITS(&lsup
->lsu_count
);
813 lsap
= lsup
->lsu_lsa
;
814 while ((const u_char
*)lsap
< dataend
&& i
--) {
815 if (ospf6_print_lsa(ndo
, lsap
, dataend
))
817 lsap
= (const struct lsa6
*)((const u_char
*)lsap
+
818 EXTRACT_16BITS(&lsap
->ls_hdr
.ls_length
));
823 case OSPF_TYPE_LS_ACK
:
824 if (ndo
->ndo_vflag
> 1) {
825 lshp
= (const struct lsa6_hdr
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
826 while ((const u_char
*)lshp
< dataend
) {
827 if (ospf6_print_lshdr(ndo
, lshp
++, dataend
))
841 /* RFC5613 Section 2.2 (w/o the TLVs) */
843 ospf6_print_lls(netdissect_options
*ndo
,
844 const u_char
*cp
, const u_int len
)
850 if (len
< OSPF_LLS_HDRLEN
)
854 ND_PRINT((ndo
, "\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp
)));
856 /* LLS Data Length */
858 llsdatalen
= EXTRACT_16BITS(cp
);
859 ND_PRINT((ndo
, ", Data Length %u", llsdatalen
));
860 if (llsdatalen
< OSPF_LLS_HDRLEN
|| llsdatalen
> len
)
864 ND_TCHECK2(*cp
, llsdatalen
- OSPF_LLS_HDRLEN
);
865 /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
872 /* RFC6506 Section 4.1 */
874 ospf6_decode_at(netdissect_options
*ndo
,
875 const u_char
*cp
, const u_int len
)
877 uint16_t authdatalen
;
881 if (len
< OSPF6_AT_HDRLEN
)
883 /* Authentication Type */
885 ND_PRINT((ndo
, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str
, "unknown (0x%04x)", EXTRACT_16BITS(cp
))));
889 authdatalen
= EXTRACT_16BITS(cp
);
890 ND_PRINT((ndo
, ", Length %u", authdatalen
));
891 if (authdatalen
< OSPF6_AT_HDRLEN
|| authdatalen
> len
)
897 /* Security Association ID */
899 ND_PRINT((ndo
, ", SAID %u", EXTRACT_16BITS(cp
)));
901 /* Cryptographic Sequence Number (High-Order 32 Bits) */
903 ND_PRINT((ndo
, ", CSN 0x%08x", EXTRACT_32BITS(cp
)));
905 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
907 ND_PRINT((ndo
, ":%08x", EXTRACT_32BITS(cp
)));
909 /* Authentication Data */
910 ND_TCHECK2(*cp
, authdatalen
- OSPF6_AT_HDRLEN
);
911 if (ndo
->ndo_vflag
> 1)
912 print_unknown_data(ndo
,cp
, "\n\tAuthentication Data ", authdatalen
- OSPF6_AT_HDRLEN
);
919 /* The trailing data may include LLS and/or AT data (in this specific order).
920 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
921 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
922 * any other packet type, thus decode the AT data regardless of the AT-bit.
925 ospf6_decode_v3_trailer(netdissect_options
*ndo
,
926 const struct ospf6hdr
*op
, const u_char
*cp
, const unsigned len
)
932 if (op
->ospf6_type
== OSPF_TYPE_HELLO
) {
933 const struct hello6
*hellop
= (const struct hello6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
934 if (EXTRACT_32BITS(&hellop
->hello_options
) & OSPF6_OPTION_L
)
936 } else if (op
->ospf6_type
== OSPF_TYPE_DD
) {
937 const struct dd6
*ddp
= (const struct dd6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
938 if (EXTRACT_32BITS(&ddp
->db_options
) & OSPF6_OPTION_L
)
941 if ((lls_hello
|| lls_dd
) && (llslen
= ospf6_print_lls(ndo
, cp
, len
)) < 0)
943 return ospf6_decode_at(ndo
, cp
+ llslen
, len
- llslen
);
950 ospf6_print(netdissect_options
*ndo
,
951 register const u_char
*bp
, register u_int length
)
953 register const struct ospf6hdr
*op
;
954 register const u_char
*dataend
;
955 register const char *cp
;
958 op
= (const struct ospf6hdr
*)bp
;
960 /* If the type is valid translate it, or just print the type */
961 /* value. If it's not valid, say so and return */
962 ND_TCHECK(op
->ospf6_type
);
963 cp
= tok2str(ospf6_type_values
, "unknown packet type (%u)", op
->ospf6_type
);
964 ND_PRINT((ndo
, "OSPFv%u, %s, length %d", op
->ospf6_version
, cp
, length
));
969 if(!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
973 /* OSPFv3 data always comes first and optional trailing data may follow. */
974 ND_TCHECK(op
->ospf6_len
);
975 datalen
= EXTRACT_16BITS(&op
->ospf6_len
);
976 if (datalen
> length
) {
977 ND_PRINT((ndo
, " [len %d]", datalen
));
980 dataend
= bp
+ datalen
;
982 ND_TCHECK(op
->ospf6_routerid
);
983 ND_PRINT((ndo
, "\n\tRouter-ID %s", ipaddr_string(ndo
, &op
->ospf6_routerid
)));
985 ND_TCHECK(op
->ospf6_areaid
);
986 if (EXTRACT_32BITS(&op
->ospf6_areaid
) != 0)
987 ND_PRINT((ndo
, ", Area %s", ipaddr_string(ndo
, &op
->ospf6_areaid
)));
989 ND_PRINT((ndo
, ", Backbone Area"));
990 ND_TCHECK(op
->ospf6_instanceid
);
991 if (op
->ospf6_instanceid
)
992 ND_PRINT((ndo
, ", Instance %u", op
->ospf6_instanceid
));
994 /* Do rest according to version. */
995 switch (op
->ospf6_version
) {
999 if (ospf6_decode_v3(ndo
, op
, dataend
) ||
1000 ospf6_decode_v3_trailer(ndo
, op
, dataend
, length
- datalen
))
1003 } /* end switch on version */
1007 ND_PRINT((ndo
, "%s", tstr
));