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)
24 /* \summary: IPv6 Open Shortest Path First (OSPFv3) printer */
30 #include "netdissect-stdinc.h"
34 #include "netdissect.h"
35 #include "addrtoname.h"
40 #define OSPF_TYPE_HELLO 1 /* Hello */
41 #define OSPF_TYPE_DD 2 /* Database Description */
42 #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
43 #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
44 #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
46 /* Options *_options */
47 #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */
48 #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */
49 #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */
50 #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */
51 #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */
52 #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */
53 /* The field is actually 24-bit (RFC5340 Section A.2). */
54 #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */
55 #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */
56 #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */
60 #define OSPF6_DB_INIT 0x04 /* */
61 #define OSPF6_DB_MORE 0x02
62 #define OSPF6_DB_MASTER 0x01
63 #define OSPF6_DB_M6 0x10 /* IPv6 MTU */
66 #define LS_TYPE_ROUTER 1 /* router link */
67 #define LS_TYPE_NETWORK 2 /* network link */
68 #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */
69 #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */
70 #define LS_TYPE_ASE 5 /* ASE */
71 #define LS_TYPE_GROUP 6 /* Group membership */
72 #define LS_TYPE_NSSA 7 /* NSSA */
73 #define LS_TYPE_LINK 8 /* Link LSA */
74 #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */
75 #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */
76 #define LS_TYPE_GRACE 11 /* Grace LSA */
77 #define LS_TYPE_RI 12 /* Router information */
78 #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */
79 #define LS_TYPE_L1VPN 14 /* L1VPN */
80 #define LS_TYPE_MASK 0x1fff
82 #define LS_SCOPE_LINKLOCAL 0x0000
83 #define LS_SCOPE_AREA 0x2000
84 #define LS_SCOPE_AS 0x4000
85 #define LS_SCOPE_MASK 0x6000
86 #define LS_SCOPE_U 0x8000
88 /* rla_link.link_type */
89 #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
90 #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
91 #define RLA_TYPE_VIRTUAL 4 /* virtual link */
94 #define RLA_FLAG_B 0x01
95 #define RLA_FLAG_E 0x02
96 #define RLA_FLAG_V 0x04
97 #define RLA_FLAG_W 0x08
98 #define RLA_FLAG_N 0x10
100 /* lsa_prefix options */
101 #define LSA_PREFIX_OPT_NU 0x01
102 #define LSA_PREFIX_OPT_LA 0x02
103 #define LSA_PREFIX_OPT_MC 0x04
104 #define LSA_PREFIX_OPT_P 0x08
105 #define LSA_PREFIX_OPT_DN 0x10
107 /* sla_tosmetric breakdown */
108 #define SLA_MASK_TOS 0x7f000000
109 #define SLA_MASK_METRIC 0x00ffffff
110 #define SLA_SHIFT_TOS 24
113 #define ASLA_FLAG_FWDADDR 0x02000000
114 #define ASLA_FLAG_ROUTETAG 0x01000000
115 #define ASLA_MASK_METRIC 0x00ffffff
117 /* RFC6506 Section 4.1 */
118 #define OSPF6_AT_HDRLEN 16U
119 #define OSPF6_AUTH_TYPE_HMAC 0x0001
121 typedef nd_uint32_t rtrid_t
;
123 /* link state advertisement header */
130 nd_uint16_t ls_chksum
;
131 nd_uint16_t ls_length
;
134 /* Length of an IPv6 address, in bytes. */
135 #define IPV6_ADDR_LEN_BYTES (128/8)
138 nd_uint8_t lsa_p_len
;
139 nd_uint8_t lsa_p_opt
;
140 nd_uint16_t lsa_p_metric
;
141 nd_byte lsa_p_prefix
[IPV6_ADDR_LEN_BYTES
]; /* maximum length */
144 /* link state advertisement */
146 struct lsa6_hdr ls_hdr
;
148 /* Link state types */
150 /* Router links advertisements */
156 #define rla_flags rla_flgandopt.flg
157 #define rla_options rla_flgandopt.opt
159 nd_uint8_t link_type
;
161 nd_uint16_t link_metric
;
162 nd_uint32_t link_ifid
;
163 nd_uint32_t link_nifid
;
165 } rla_link
[1]; /* may repeat */
168 /* Network links advertisements */
170 nd_uint32_t nla_options
;
171 rtrid_t nla_router
[1]; /* may repeat */
174 /* Inter Area Prefix LSA */
176 nd_uint32_t inter_ap_metric
;
177 struct lsa6_prefix inter_ap_prefix
[1];
180 /* AS external links advertisements */
182 nd_uint32_t asla_metric
;
183 struct lsa6_prefix asla_prefix
[1];
184 /* some optional fields follow */
188 /* Summary links advertisements */
191 nd_uint32_t sla_tosmetric
[1]; /* may repeat */
194 /* Multicast group membership */
196 nd_uint32_t mcla_vtype
;
209 #define llsa_priority llsa_priandopt.pri
210 #define llsa_options llsa_priandopt.opt
212 nd_uint32_t llsa_nprefix
;
213 struct lsa6_prefix llsa_prefix
[1];
216 /* Intra-Area-Prefix */
218 nd_uint16_t intra_ap_nprefix
;
219 nd_uint16_t intra_ap_lstype
;
220 rtrid_t intra_ap_lsid
;
221 rtrid_t intra_ap_rtid
;
222 struct lsa6_prefix intra_ap_prefix
[1];
231 nd_uint8_t ospf6_version
;
232 nd_uint8_t ospf6_type
;
233 nd_uint16_t ospf6_len
;
234 rtrid_t ospf6_routerid
;
235 rtrid_t ospf6_areaid
;
236 nd_uint16_t ospf6_chksum
;
237 nd_uint8_t ospf6_instanceid
;
238 nd_uint8_t ospf6_rsvd
;
242 * The OSPF6 header length is 16 bytes, regardless of how your compiler
243 * might choose to pad the above structure.
245 #define OSPF6HDR_LEN 16
249 nd_uint32_t hello_ifid
;
254 #define hello_priority hello_priandopt.pri
255 #define hello_options hello_priandopt.opt
256 nd_uint16_t hello_helloint
;
257 nd_uint16_t hello_deadint
;
260 rtrid_t hello_neighbor
[1]; /* may repeat */
263 /* Database Description packet */
265 nd_uint32_t db_options
;
270 struct lsa6_hdr db_lshdr
[1]; /* may repeat */
273 /* Link State Request */
281 /* Link State Update */
283 nd_uint32_t lsu_count
;
284 struct lsa6 lsu_lsa
[1]; /* may repeat */
288 static const struct tok ospf6_option_values
[] = {
289 { OSPF6_OPTION_V6
, "V6" },
290 { OSPF6_OPTION_E
, "External" },
291 { OSPF6_OPTION_MC
, "Deprecated" },
292 { OSPF6_OPTION_N
, "NSSA" },
293 { OSPF6_OPTION_R
, "Router" },
294 { OSPF6_OPTION_DC
, "Demand Circuit" },
295 { OSPF6_OPTION_AF
, "AFs Support" },
296 { OSPF6_OPTION_L
, "LLS" },
297 { OSPF6_OPTION_AT
, "Authentication Trailer" },
301 static const struct tok ospf6_rla_flag_values
[] = {
302 { RLA_FLAG_B
, "ABR" },
303 { RLA_FLAG_E
, "External" },
304 { RLA_FLAG_V
, "Virtual-Link Endpoint" },
305 { RLA_FLAG_W
, "Wildcard Receiver" },
306 { RLA_FLAG_N
, "NSSA Translator" },
310 static const struct tok ospf6_asla_flag_values
[] = {
311 { ASLA_FLAG_EXTERNAL
, "External Type 2" },
312 { ASLA_FLAG_FWDADDR
, "Forwarding" },
313 { ASLA_FLAG_ROUTETAG
, "Tag" },
317 static const struct tok ospf6_type_values
[] = {
318 { OSPF_TYPE_HELLO
, "Hello" },
319 { OSPF_TYPE_DD
, "Database Description" },
320 { OSPF_TYPE_LS_REQ
, "LS-Request" },
321 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
322 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
326 static const struct tok ospf6_lsa_values
[] = {
327 { LS_TYPE_ROUTER
, "Router" },
328 { LS_TYPE_NETWORK
, "Network" },
329 { LS_TYPE_INTER_AP
, "Inter-Area Prefix" },
330 { LS_TYPE_INTER_AR
, "Inter-Area Router" },
331 { LS_TYPE_ASE
, "External" },
332 { LS_TYPE_GROUP
, "Deprecated" },
333 { LS_TYPE_NSSA
, "NSSA" },
334 { LS_TYPE_LINK
, "Link" },
335 { LS_TYPE_INTRA_AP
, "Intra-Area Prefix" },
336 { LS_TYPE_INTRA_ATE
, "Intra-Area TE" },
337 { LS_TYPE_GRACE
, "Grace" },
338 { LS_TYPE_RI
, "Router Information" },
339 { LS_TYPE_INTER_ASTE
, "Inter-AS-TE" },
340 { LS_TYPE_L1VPN
, "Layer 1 VPN" },
344 static const struct tok ospf6_ls_scope_values
[] = {
345 { LS_SCOPE_LINKLOCAL
, "Link Local" },
346 { LS_SCOPE_AREA
, "Area Local" },
347 { LS_SCOPE_AS
, "Domain Wide" },
351 static const struct tok ospf6_dd_flag_values
[] = {
352 { OSPF6_DB_INIT
, "Init" },
353 { OSPF6_DB_MORE
, "More" },
354 { OSPF6_DB_MASTER
, "Master" },
355 { OSPF6_DB_M6
, "IPv6 MTU" },
359 static const struct tok ospf6_lsa_prefix_option_values
[] = {
360 { LSA_PREFIX_OPT_NU
, "No Unicast" },
361 { LSA_PREFIX_OPT_LA
, "Local address" },
362 { LSA_PREFIX_OPT_MC
, "Deprecated" },
363 { LSA_PREFIX_OPT_P
, "Propagate" },
364 { LSA_PREFIX_OPT_DN
, "Down" },
368 static const struct tok ospf6_auth_type_str
[] = {
369 { OSPF6_AUTH_TYPE_HMAC
, "HMAC" },
374 ospf6_print_ls_type(netdissect_options
*ndo
,
375 u_int ls_type
, const rtrid_t
*ls_stateid
)
377 ND_PRINT("\n\t %s LSA (%u), %s Scope%s, LSA-ID %s",
378 tok2str(ospf6_lsa_values
, "Unknown", ls_type
& LS_TYPE_MASK
),
379 ls_type
& LS_TYPE_MASK
,
380 tok2str(ospf6_ls_scope_values
, "Unknown", ls_type
& LS_SCOPE_MASK
),
381 ls_type
&0x8000 ? ", transitive" : "", /* U-bit */
382 GET_IPADDR_STRING((const u_char
*)ls_stateid
));
386 ospf6_print_lshdr(netdissect_options
*ndo
,
387 const struct lsa6_hdr
*lshp
, const u_char
*dataend
)
389 if ((const u_char
*)(lshp
+ 1) > dataend
)
391 ND_TCHECK_4(lshp
->ls_router
);
393 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
394 GET_IPADDR_STRING(lshp
->ls_router
),
395 GET_BE_U_4(lshp
->ls_seq
),
396 GET_BE_U_2(lshp
->ls_age
),
397 GET_BE_U_2(lshp
->ls_length
)-(u_int
)sizeof(struct lsa6_hdr
));
399 ospf6_print_ls_type(ndo
, GET_BE_U_2(lshp
->ls_type
),
408 ospf6_print_lsaprefix(netdissect_options
*ndo
,
409 const uint8_t *tptr
, u_int lsa_length
)
411 const struct lsa6_prefix
*lsapp
= (const struct lsa6_prefix
*)tptr
;
415 if (lsa_length
< sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
)
417 lsa_length
-= sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
;
418 ND_TCHECK_LEN(lsapp
, sizeof(*lsapp
) - IPV6_ADDR_LEN_BYTES
);
419 wordlen
= (GET_U_1(lsapp
->lsa_p_len
) + 31) / 32;
420 if (wordlen
* 4 > sizeof(nd_ipv6
)) {
421 ND_PRINT(" bogus prefixlen /%u", GET_U_1(lsapp
->lsa_p_len
));
424 if (lsa_length
< wordlen
* 4)
426 lsa_length
-= wordlen
* 4;
427 ND_TCHECK_LEN(lsapp
->lsa_p_prefix
, wordlen
* 4);
428 memset(prefix
, 0, sizeof(prefix
));
429 memcpy(prefix
, lsapp
->lsa_p_prefix
, wordlen
* 4);
430 ND_PRINT("\n\t\t%s/%u", ip6addr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
431 GET_U_1(lsapp
->lsa_p_len
));
432 if (GET_U_1(lsapp
->lsa_p_opt
)) {
433 ND_PRINT(", Options [%s]",
434 bittok2str(ospf6_lsa_prefix_option_values
,
435 "none", GET_U_1(lsapp
->lsa_p_opt
)));
437 ND_PRINT(", metric %u", GET_BE_U_2(lsapp
->lsa_p_metric
));
438 return sizeof(*lsapp
) - IPV6_ADDR_LEN_BYTES
+ wordlen
* 4;
446 * Print a single link state advertisement. If truncated return 1, else 0.
449 ospf6_print_lsa(netdissect_options
*ndo
,
450 const struct lsa6
*lsap
, const u_char
*dataend
)
452 const struct rlalink6
*rlp
;
454 const struct tos_metric
*tosp
;
458 const struct aslametric
*almp
;
459 const struct mcla
*mcp
;
461 const struct llsa
*llsap
;
462 const struct lsa6_prefix
*lsapp
;
468 u_int length
, lsa_length
;
472 if (ospf6_print_lshdr(ndo
, &lsap
->ls_hdr
, dataend
))
474 ND_TCHECK_2(lsap
->ls_hdr
.ls_length
);
475 length
= GET_BE_U_2(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
) || (const u_char
*)lsap
+ length
> dataend
)
485 lsa_length
= length
- sizeof(struct lsa6_hdr
);
486 tptr
= (const uint8_t *)lsap
+sizeof(struct lsa6_hdr
);
488 switch (GET_BE_U_2(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 ND_TCHECK_4(lsap
->lsa_un
.un_rla
.rla_options
);
494 ND_PRINT("\n\t Options [%s]",
495 bittok2str(ospf6_option_values
, "none",
496 GET_BE_U_4(lsap
->lsa_un
.un_rla
.rla_options
)));
497 ND_PRINT(", RLA-Flags [%s]",
498 bittok2str(ospf6_rla_flag_values
, "none",
499 GET_U_1(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 (GET_U_1(rlp
->link_type
)) {
509 case RLA_TYPE_VIRTUAL
:
510 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID %s"
511 "\n\t Neighbor Interface-ID %s, Interface %s",
512 GET_IPADDR_STRING(rlp
->link_nrtid
),
513 GET_IPADDR_STRING(rlp
->link_nifid
),
514 GET_IPADDR_STRING(rlp
->link_ifid
));
517 case RLA_TYPE_ROUTER
:
518 ND_PRINT("\n\t Neighbor Router-ID %s"
519 "\n\t Neighbor Interface-ID %s, Interface %s",
520 GET_IPADDR_STRING(rlp
->link_nrtid
),
521 GET_IPADDR_STRING(rlp
->link_nifid
),
522 GET_IPADDR_STRING(rlp
->link_ifid
));
525 case RLA_TYPE_TRANSIT
:
526 ND_PRINT("\n\t Neighbor Network-ID %s"
527 "\n\t Neighbor Interface-ID %s, Interface %s",
528 GET_IPADDR_STRING(rlp
->link_nrtid
),
529 GET_IPADDR_STRING(rlp
->link_nifid
),
530 GET_IPADDR_STRING(rlp
->link_ifid
));
534 ND_PRINT("\n\t Unknown Router Links Type 0x%02x",
535 GET_U_1(rlp
->link_type
));
538 ND_PRINT(", metric %u", GET_BE_U_2(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 ND_TCHECK_4(lsap
->lsa_un
.un_nla
.nla_options
);
548 ND_PRINT("\n\t Options [%s]",
549 bittok2str(ospf6_option_values
, "none",
550 GET_BE_U_4(lsap
->lsa_un
.un_nla
.nla_options
)));
552 ND_PRINT("\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 ND_PRINT("\n\t\t%s", GET_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 ND_TCHECK_4(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
569 ND_PRINT(", metric %u",
570 GET_BE_U_4(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
) & SLA_MASK_METRIC
);
572 tptr
= (const uint8_t *)lsap
->lsa_un
.un_inter_ap
.inter_ap_prefix
;
573 while (lsa_length
!= 0) {
574 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
578 * ospf6_print_lsaprefix() will return -1 if
579 * the length is too high, so this will not
582 lsa_length
-= bytelen
;
587 case LS_TYPE_ASE
| LS_SCOPE_AS
:
588 if (lsa_length
< sizeof (lsap
->lsa_un
.un_asla
.asla_metric
))
590 lsa_length
-= sizeof (lsap
->lsa_un
.un_asla
.asla_metric
);
591 ND_TCHECK_4(lsap
->lsa_un
.un_asla
.asla_metric
);
592 flags32
= GET_BE_U_4(lsap
->lsa_un
.un_asla
.asla_metric
);
593 ND_PRINT("\n\t Flags [%s]",
594 bittok2str(ospf6_asla_flag_values
, "none", flags32
));
595 ND_PRINT(" metric %u",
596 GET_BE_U_4(lsap
->lsa_un
.un_asla
.asla_metric
) &
599 tptr
= (const uint8_t *)lsap
->lsa_un
.un_asla
.asla_prefix
;
600 lsapp
= (const struct lsa6_prefix
*)tptr
;
601 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
605 * ospf6_print_lsaprefix() will return -1 if
606 * the length is too high, so this will not
609 lsa_length
-= bytelen
;
612 if ((flags32
& ASLA_FLAG_FWDADDR
) != 0) {
613 if (lsa_length
< sizeof (nd_ipv6
))
615 lsa_length
-= sizeof (nd_ipv6
);
617 ND_PRINT(" forward %s",
618 GET_IP6ADDR_STRING(tptr
));
619 tptr
+= sizeof(nd_ipv6
);
622 if ((flags32
& ASLA_FLAG_ROUTETAG
) != 0) {
623 if (lsa_length
< sizeof (uint32_t))
625 lsa_length
-= sizeof (uint32_t);
628 GET_IPADDR_STRING(tptr
));
629 tptr
+= sizeof(uint32_t);
632 if (GET_U_1(lsapp
->lsa_p_metric
)) {
633 if (lsa_length
< sizeof (uint32_t))
635 lsa_length
-= sizeof (uint32_t);
637 ND_PRINT(" RefLSID: %s",
638 GET_IPADDR_STRING(tptr
));
639 tptr
+= sizeof(uint32_t);
645 llsap
= &lsap
->lsa_un
.un_llsa
;
646 if (lsa_length
< sizeof (llsap
->llsa_priandopt
))
648 lsa_length
-= sizeof (llsap
->llsa_priandopt
);
649 ND_TCHECK_SIZE(&llsap
->llsa_priandopt
);
650 ND_PRINT("\n\t Options [%s]",
651 bittok2str(ospf6_option_values
, "none",
652 GET_BE_U_4(llsap
->llsa_options
)));
654 if (lsa_length
< sizeof (llsap
->llsa_lladdr
) + sizeof (llsap
->llsa_nprefix
))
656 lsa_length
-= sizeof (llsap
->llsa_lladdr
) + sizeof (llsap
->llsa_nprefix
);
657 ND_TCHECK_4(llsap
->llsa_nprefix
);
658 prefixes
= GET_BE_U_4(llsap
->llsa_nprefix
);
659 ND_PRINT("\n\t Priority %u, Link-local address %s, Prefixes %u:",
660 GET_U_1(llsap
->llsa_priority
),
661 GET_IP6ADDR_STRING(llsap
->llsa_lladdr
),
664 tptr
= (const uint8_t *)llsap
->llsa_prefix
;
665 while (prefixes
> 0) {
666 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
671 * ospf6_print_lsaprefix() will return -1 if
672 * the length is too high, so this will not
675 lsa_length
-= bytelen
;
680 case LS_TYPE_INTRA_AP
| LS_SCOPE_AREA
:
681 /* Intra-Area-Prefix LSA */
682 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
))
684 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
685 ND_TCHECK_4(lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
686 ospf6_print_ls_type(ndo
,
687 GET_BE_U_2(lsap
->lsa_un
.un_intra_ap
.intra_ap_lstype
),
688 &lsap
->lsa_un
.un_intra_ap
.intra_ap_lsid
);
690 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
))
692 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
693 ND_TCHECK_2(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
694 prefixes
= GET_BE_U_2(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
695 ND_PRINT("\n\t Prefixes %u:", prefixes
);
697 tptr
= (const uint8_t *)lsap
->lsa_un
.un_intra_ap
.intra_ap_prefix
;
698 while (prefixes
> 0) {
699 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
704 * ospf6_print_lsaprefix() will return -1 if
705 * the length is too high, so this will not
708 lsa_length
-= bytelen
;
713 case LS_TYPE_GRACE
| LS_SCOPE_LINKLOCAL
:
714 if (ospf_grace_lsa_print(ndo
, tptr
, lsa_length
) == -1) {
719 case LS_TYPE_INTRA_ATE
| LS_SCOPE_LINKLOCAL
:
720 if (ospf_te_lsa_print(ndo
, tptr
, lsa_length
) == -1) {
726 if(!print_unknown_data(ndo
,tptr
,
740 ospf6_decode_v3(netdissect_options
*ndo
,
741 const struct ospf6hdr
*op
,
742 const u_char
*dataend
)
745 const struct lsr6
*lsrp
;
746 const struct lsa6_hdr
*lshp
;
747 const struct lsa6
*lsap
;
750 switch (GET_U_1(op
->ospf6_type
)) {
752 case OSPF_TYPE_HELLO
: {
753 const struct hello6
*hellop
= (const struct hello6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
755 ND_TCHECK_4(hellop
->hello_options
);
756 ND_PRINT("\n\tOptions [%s]",
757 bittok2str(ospf6_option_values
, "none",
758 GET_BE_U_4(hellop
->hello_options
)));
760 ND_TCHECK_2(hellop
->hello_deadint
);
761 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
762 GET_BE_U_2(hellop
->hello_helloint
),
763 GET_BE_U_2(hellop
->hello_deadint
),
764 GET_IPADDR_STRING(hellop
->hello_ifid
),
765 GET_U_1(hellop
->hello_priority
));
767 ND_TCHECK_4(hellop
->hello_dr
);
768 if (GET_BE_U_4(hellop
->hello_dr
) != 0)
769 ND_PRINT("\n\t Designated Router %s",
770 GET_IPADDR_STRING(hellop
->hello_dr
));
771 ND_TCHECK_4(hellop
->hello_bdr
);
772 if (GET_BE_U_4(hellop
->hello_bdr
) != 0)
773 ND_PRINT(", Backup Designated Router %s",
774 GET_IPADDR_STRING(hellop
->hello_bdr
));
775 if (ndo
->ndo_vflag
> 1) {
776 ND_PRINT("\n\t Neighbor List:");
777 ap
= hellop
->hello_neighbor
;
778 while ((const u_char
*)ap
< dataend
) {
780 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
788 const struct dd6
*ddp
= (const struct dd6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
790 ND_TCHECK_4(ddp
->db_options
);
791 ND_PRINT("\n\tOptions [%s]",
792 bittok2str(ospf6_option_values
, "none",
793 GET_BE_U_4(ddp
->db_options
)));
794 ND_TCHECK_1(ddp
->db_flags
);
795 ND_PRINT(", DD Flags [%s]",
796 bittok2str(ospf6_dd_flag_values
,"none",GET_U_1(ddp
->db_flags
)));
798 ND_TCHECK_4(ddp
->db_seq
);
799 ND_PRINT(", MTU %u, DD-Sequence 0x%08x",
800 GET_BE_U_2(ddp
->db_mtu
),
801 GET_BE_U_4(ddp
->db_seq
));
802 if (ndo
->ndo_vflag
> 1) {
803 /* Print all the LS adv's */
804 lshp
= ddp
->db_lshdr
;
805 while ((const u_char
*)lshp
< dataend
) {
806 if (ospf6_print_lshdr(ndo
, lshp
++, dataend
))
813 case OSPF_TYPE_LS_REQ
:
814 if (ndo
->ndo_vflag
> 1) {
815 lsrp
= (const struct lsr6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
816 while ((const u_char
*)lsrp
< dataend
) {
817 ND_TCHECK_SIZE(lsrp
);
818 ND_PRINT("\n\t Advertising Router %s",
819 GET_IPADDR_STRING(lsrp
->ls_router
));
820 ospf6_print_ls_type(ndo
,
821 GET_BE_U_2(lsrp
->ls_type
),
828 case OSPF_TYPE_LS_UPDATE
:
829 if (ndo
->ndo_vflag
> 1) {
830 const struct lsu6
*lsup
= (const struct lsu6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
832 ND_TCHECK_4(lsup
->lsu_count
);
833 i
= GET_BE_U_4(lsup
->lsu_count
);
834 lsap
= lsup
->lsu_lsa
;
835 while ((const u_char
*)lsap
< dataend
&& i
--) {
836 if (ospf6_print_lsa(ndo
, lsap
, dataend
))
838 lsap
= (const struct lsa6
*)((const u_char
*)lsap
+
839 GET_BE_U_2(lsap
->ls_hdr
.ls_length
));
844 case OSPF_TYPE_LS_ACK
:
845 if (ndo
->ndo_vflag
> 1) {
846 lshp
= (const struct lsa6_hdr
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
847 while ((const u_char
*)lshp
< dataend
) {
848 if (ospf6_print_lshdr(ndo
, lshp
++, dataend
))
862 /* RFC5613 Section 2.2 (w/o the TLVs) */
864 ospf6_print_lls(netdissect_options
*ndo
,
865 const u_char
*cp
, const u_int len
)
871 if (len
< OSPF_LLS_HDRLEN
)
875 ND_PRINT("\n\tLLS Checksum 0x%04x", GET_BE_U_2(cp
));
877 /* LLS Data Length */
879 llsdatalen
= GET_BE_U_2(cp
);
880 ND_PRINT(", Data Length %u", llsdatalen
);
881 if (llsdatalen
< OSPF_LLS_HDRLEN
|| llsdatalen
> len
)
885 ND_TCHECK_LEN(cp
, llsdatalen
- OSPF_LLS_HDRLEN
);
886 /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
893 /* RFC6506 Section 4.1 */
895 ospf6_decode_at(netdissect_options
*ndo
,
896 const u_char
*cp
, const u_int len
)
898 uint16_t authdatalen
;
902 if (len
< OSPF6_AT_HDRLEN
)
904 /* Authentication Type */
906 ND_PRINT("\n\tAuthentication Type %s",
907 tok2str(ospf6_auth_type_str
, "unknown (0x%04x)", GET_BE_U_2(cp
)));
911 authdatalen
= GET_BE_U_2(cp
);
912 ND_PRINT(", Length %u", authdatalen
);
913 if (authdatalen
< OSPF6_AT_HDRLEN
|| authdatalen
> len
)
919 /* Security Association ID */
921 ND_PRINT(", SAID %u", GET_BE_U_2(cp
));
923 /* Cryptographic Sequence Number (High-Order 32 Bits) */
925 ND_PRINT(", CSN 0x%08x", GET_BE_U_4(cp
));
927 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
929 ND_PRINT(":%08x", GET_BE_U_4(cp
));
931 /* Authentication Data */
932 ND_TCHECK_LEN(cp
, authdatalen
- OSPF6_AT_HDRLEN
);
933 if (ndo
->ndo_vflag
> 1)
934 print_unknown_data(ndo
,cp
, "\n\tAuthentication Data ", authdatalen
- OSPF6_AT_HDRLEN
);
941 /* The trailing data may include LLS and/or AT data (in this specific order).
942 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
943 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
944 * any other packet type, thus decode the AT data regardless of the AT-bit.
947 ospf6_decode_v3_trailer(netdissect_options
*ndo
,
948 const struct ospf6hdr
*op
, const u_char
*cp
, const unsigned len
)
955 type
= GET_U_1(op
->ospf6_type
);
956 if (type
== OSPF_TYPE_HELLO
) {
957 const struct hello6
*hellop
= (const struct hello6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
958 ND_TCHECK_4(hellop
->hello_options
);
959 if (GET_BE_U_4(hellop
->hello_options
) & OSPF6_OPTION_L
)
961 } else if (type
== OSPF_TYPE_DD
) {
962 const struct dd6
*ddp
= (const struct dd6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
963 ND_TCHECK_4(ddp
->db_options
);
964 if (GET_BE_U_4(ddp
->db_options
) & OSPF6_OPTION_L
)
967 if ((lls_hello
|| lls_dd
) && (llslen
= ospf6_print_lls(ndo
, cp
, len
)) < 0)
969 return ospf6_decode_at(ndo
, cp
+ llslen
, len
- llslen
);
976 ospf6_print(netdissect_options
*ndo
,
977 const u_char
*bp
, u_int length
)
979 const struct ospf6hdr
*op
;
980 const u_char
*dataend
;
984 ndo
->ndo_protocol
= "ospf3";
985 op
= (const struct ospf6hdr
*)bp
;
987 /* If the type is valid translate it, or just print the type */
988 /* value. If it's not valid, say so and return */
989 ND_TCHECK_1(op
->ospf6_type
);
990 cp
= tok2str(ospf6_type_values
, "unknown packet type (%u)",
991 GET_U_1(op
->ospf6_type
));
992 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf6_version
), cp
,
998 if(!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
1002 /* OSPFv3 data always comes first and optional trailing data may follow. */
1003 ND_TCHECK_2(op
->ospf6_len
);
1004 datalen
= GET_BE_U_2(op
->ospf6_len
);
1005 if (datalen
> length
) {
1006 ND_PRINT(" [len %u]", datalen
);
1009 dataend
= bp
+ datalen
;
1011 ND_TCHECK_4(op
->ospf6_routerid
);
1012 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf6_routerid
));
1014 ND_TCHECK_4(op
->ospf6_areaid
);
1015 if (GET_BE_U_4(op
->ospf6_areaid
) != 0)
1016 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf6_areaid
));
1018 ND_PRINT(", Backbone Area");
1019 ND_TCHECK_1(op
->ospf6_instanceid
);
1020 if (GET_U_1(op
->ospf6_instanceid
))
1021 ND_PRINT(", Instance %u", GET_U_1(op
->ospf6_instanceid
));
1023 /* Do rest according to version. */
1024 switch (GET_U_1(op
->ospf6_version
)) {
1027 /* ospf version 3 */
1028 if (ospf6_decode_v3(ndo
, op
, dataend
) ||
1029 ospf6_decode_v3_trailer(ndo
, op
, dataend
, length
- datalen
))
1032 } /* end switch on version */
1036 nd_print_trunc(ndo
);