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_Nt 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
106 #define LSA_PREFIX_OPT_N 0x20
108 /* sla_tosmetric breakdown */
109 #define SLA_MASK_TOS 0x7f000000
110 #define SLA_MASK_METRIC 0x00ffffff
111 #define SLA_SHIFT_TOS 24
114 #define ASLA_FLAG_FWDADDR 0x02000000
115 #define ASLA_FLAG_ROUTETAG 0x01000000
116 #define ASLA_MASK_METRIC 0x00ffffff
118 /* RFC6506 Section 4.1 */
119 #define OSPF6_AT_HDRLEN 16U
120 #define OSPF6_AUTH_TYPE_HMAC 0x0001
122 typedef nd_uint32_t rtrid_t
;
124 /* link state advertisement header */
131 nd_uint16_t ls_chksum
;
132 nd_uint16_t ls_length
;
135 /* Length of an IPv6 address, in bytes. */
136 #define IPV6_ADDR_LEN_BYTES (128/8)
139 nd_uint8_t lsa_p_len
;
140 nd_uint8_t lsa_p_opt
;
141 nd_uint16_t lsa_p_metric
;
142 nd_byte lsa_p_prefix
[IPV6_ADDR_LEN_BYTES
]; /* maximum length */
145 /* link state advertisement */
147 struct lsa6_hdr ls_hdr
;
149 /* Link state types */
151 /* Router links advertisements */
157 #define rla_flags rla_flgandopt.flg
158 #define rla_options rla_flgandopt.opt
160 nd_uint8_t link_type
;
162 nd_uint16_t link_metric
;
163 nd_uint32_t link_ifid
;
164 nd_uint32_t link_nifid
;
166 } rla_link
[1]; /* may repeat */
169 /* Network links advertisements */
171 nd_uint32_t nla_options
;
172 rtrid_t nla_router
[1]; /* may repeat */
175 /* Inter Area Prefix LSA */
177 nd_uint32_t inter_ap_metric
;
178 struct lsa6_prefix inter_ap_prefix
[1];
181 /* AS external links advertisements */
183 nd_uint32_t asla_metric
;
184 struct lsa6_prefix asla_prefix
[1];
185 /* some optional fields follow */
189 /* Summary links advertisements */
192 nd_uint32_t sla_tosmetric
[1]; /* may repeat */
195 /* Multicast group membership */
197 nd_uint32_t mcla_vtype
;
210 #define llsa_priority llsa_priandopt.pri
211 #define llsa_options llsa_priandopt.opt
213 nd_uint32_t llsa_nprefix
;
214 struct lsa6_prefix llsa_prefix
[1];
217 /* Intra-Area-Prefix */
219 nd_uint16_t intra_ap_nprefix
;
220 nd_uint16_t intra_ap_lstype
;
221 rtrid_t intra_ap_lsid
;
222 rtrid_t intra_ap_rtid
;
223 struct lsa6_prefix intra_ap_prefix
[1];
232 nd_uint8_t ospf6_version
;
233 nd_uint8_t ospf6_type
;
234 nd_uint16_t ospf6_len
;
235 rtrid_t ospf6_routerid
;
236 rtrid_t ospf6_areaid
;
237 nd_uint16_t ospf6_chksum
;
238 nd_uint8_t ospf6_instanceid
;
239 nd_uint8_t ospf6_rsvd
;
243 * The OSPF6 header length is 16 bytes, regardless of how your compiler
244 * might choose to pad the above structure.
246 #define OSPF6HDR_LEN 16
250 nd_uint32_t hello_ifid
;
255 #define hello_priority hello_priandopt.pri
256 #define hello_options hello_priandopt.opt
257 nd_uint16_t hello_helloint
;
258 nd_uint16_t hello_deadint
;
261 rtrid_t hello_neighbor
[1]; /* may repeat */
264 /* Database Description packet */
266 nd_uint32_t db_options
;
271 struct lsa6_hdr db_lshdr
[1]; /* may repeat */
274 /* Link State Request */
282 /* Link State Update */
284 nd_uint32_t lsu_count
;
285 struct lsa6 lsu_lsa
[1]; /* may repeat */
289 static const struct tok ospf6_option_values
[] = {
290 { OSPF6_OPTION_V6
, "V6" },
291 { OSPF6_OPTION_E
, "External" },
292 { OSPF6_OPTION_MC
, "Deprecated" },
293 { OSPF6_OPTION_N
, "NSSA" },
294 { OSPF6_OPTION_R
, "Router" },
295 { OSPF6_OPTION_DC
, "Demand Circuit" },
296 { OSPF6_OPTION_AF
, "AFs Support" },
297 { OSPF6_OPTION_L
, "LLS" },
298 { OSPF6_OPTION_AT
, "Authentication Trailer" },
302 static const struct tok ospf6_rla_flag_values
[] = {
303 { RLA_FLAG_B
, "ABR" },
304 { RLA_FLAG_E
, "External" },
305 { RLA_FLAG_V
, "Virtual-Link Endpoint" },
306 { RLA_FLAG_W
, "Deprecated" },
307 { RLA_FLAG_Nt
, "NSSA Translator" },
311 static const struct tok ospf6_asla_flag_values
[] = {
312 { ASLA_FLAG_EXTERNAL
, "External Type 2" },
313 { ASLA_FLAG_FWDADDR
, "Forwarding" },
314 { ASLA_FLAG_ROUTETAG
, "Tag" },
318 static const struct tok ospf6_type_values
[] = {
319 { OSPF_TYPE_HELLO
, "Hello" },
320 { OSPF_TYPE_DD
, "Database Description" },
321 { OSPF_TYPE_LS_REQ
, "LS-Request" },
322 { OSPF_TYPE_LS_UPDATE
, "LS-Update" },
323 { OSPF_TYPE_LS_ACK
, "LS-Ack" },
327 static const struct tok ospf6_lsa_values
[] = {
328 { LS_TYPE_ROUTER
, "Router" },
329 { LS_TYPE_NETWORK
, "Network" },
330 { LS_TYPE_INTER_AP
, "Inter-Area Prefix" },
331 { LS_TYPE_INTER_AR
, "Inter-Area Router" },
332 { LS_TYPE_ASE
, "External" },
333 { LS_TYPE_GROUP
, "Deprecated" },
334 { LS_TYPE_NSSA
, "NSSA" },
335 { LS_TYPE_LINK
, "Link" },
336 { LS_TYPE_INTRA_AP
, "Intra-Area Prefix" },
337 { LS_TYPE_INTRA_ATE
, "Intra-Area TE" },
338 { LS_TYPE_GRACE
, "Grace" },
339 { LS_TYPE_RI
, "Router Information" },
340 { LS_TYPE_INTER_ASTE
, "Inter-AS-TE" },
341 { LS_TYPE_L1VPN
, "Layer 1 VPN" },
345 static const struct tok ospf6_ls_scope_values
[] = {
346 { LS_SCOPE_LINKLOCAL
, "Link Local" },
347 { LS_SCOPE_AREA
, "Area Local" },
348 { LS_SCOPE_AS
, "Domain Wide" },
352 static const struct tok ospf6_dd_flag_values
[] = {
353 { OSPF6_DB_INIT
, "Init" },
354 { OSPF6_DB_MORE
, "More" },
355 { OSPF6_DB_MASTER
, "Master" },
356 { OSPF6_DB_M6
, "IPv6 MTU" },
360 static const struct tok ospf6_lsa_prefix_option_values
[] = {
361 { LSA_PREFIX_OPT_NU
, "No Unicast" },
362 { LSA_PREFIX_OPT_LA
, "Local address" },
363 { LSA_PREFIX_OPT_MC
, "Deprecated" },
364 { LSA_PREFIX_OPT_P
, "Propagate" },
365 { LSA_PREFIX_OPT_DN
, "Down" },
366 { LSA_PREFIX_OPT_N
, "N-bit" },
370 static const struct tok ospf6_auth_type_str
[] = {
371 { OSPF6_AUTH_TYPE_HMAC
, "HMAC" },
376 ospf6_print_ls_type(netdissect_options
*ndo
,
377 u_int ls_type
, const rtrid_t
*ls_stateid
)
379 ND_PRINT("\n\t %s LSA (%u), %s Scope%s, LSA-ID %s",
380 tok2str(ospf6_lsa_values
, "Unknown", ls_type
& LS_TYPE_MASK
),
381 ls_type
& LS_TYPE_MASK
,
382 tok2str(ospf6_ls_scope_values
, "Unknown", ls_type
& LS_SCOPE_MASK
),
383 ls_type
&0x8000 ? ", transitive" : "", /* U-bit */
384 GET_IPADDR_STRING((const u_char
*)ls_stateid
));
388 ospf6_print_lshdr(netdissect_options
*ndo
,
389 const struct lsa6_hdr
*lshp
, const u_char
*dataend
)
391 if ((const u_char
*)(lshp
+ 1) > dataend
)
394 ND_PRINT("\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
395 GET_IPADDR_STRING(lshp
->ls_router
),
396 GET_BE_U_4(lshp
->ls_seq
),
397 GET_BE_U_2(lshp
->ls_age
),
398 GET_BE_U_2(lshp
->ls_length
)-(u_int
)sizeof(struct lsa6_hdr
));
400 ospf6_print_ls_type(ndo
, GET_BE_U_2(lshp
->ls_type
),
409 ospf6_print_lsaprefix(netdissect_options
*ndo
,
410 const uint8_t *tptr
, u_int lsa_length
)
412 const struct lsa6_prefix
*lsapp
= (const struct lsa6_prefix
*)tptr
;
416 if (lsa_length
< sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
)
418 lsa_length
-= sizeof (*lsapp
) - IPV6_ADDR_LEN_BYTES
;
419 ND_TCHECK_LEN(lsapp
, sizeof(*lsapp
) - IPV6_ADDR_LEN_BYTES
);
420 wordlen
= (GET_U_1(lsapp
->lsa_p_len
) + 31) / 32;
421 if (wordlen
* 4 > sizeof(nd_ipv6
)) {
422 ND_PRINT(" bogus prefixlen /%u", GET_U_1(lsapp
->lsa_p_len
));
425 if (lsa_length
< wordlen
* 4)
427 lsa_length
-= wordlen
* 4;
428 ND_TCHECK_LEN(lsapp
->lsa_p_prefix
, wordlen
* 4);
429 memset(prefix
, 0, sizeof(prefix
));
430 memcpy(prefix
, lsapp
->lsa_p_prefix
, wordlen
* 4);
431 ND_PRINT("\n\t\t%s/%u", ip6addr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IP6ADDR_STRING() */
432 GET_U_1(lsapp
->lsa_p_len
));
433 if (GET_U_1(lsapp
->lsa_p_opt
)) {
434 ND_PRINT(", Options [%s]",
435 bittok2str(ospf6_lsa_prefix_option_values
,
436 "none", GET_U_1(lsapp
->lsa_p_opt
)));
438 ND_PRINT(", metric %u", GET_BE_U_2(lsapp
->lsa_p_metric
));
439 return sizeof(*lsapp
) - IPV6_ADDR_LEN_BYTES
+ wordlen
* 4;
447 * Print a single link state advertisement. If truncated return 1, else 0.
450 ospf6_print_lsa(netdissect_options
*ndo
,
451 const struct lsa6
*lsap
, const u_char
*dataend
)
453 const struct rlalink6
*rlp
;
455 const struct tos_metric
*tosp
;
459 const struct aslametric
*almp
;
460 const struct mcla
*mcp
;
462 const struct llsa
*llsap
;
463 const struct lsa6_prefix
*lsapp
;
469 u_int length
, lsa_length
;
473 if (ospf6_print_lshdr(ndo
, &lsap
->ls_hdr
, dataend
))
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_PRINT("\n\t Options [%s]",
494 bittok2str(ospf6_option_values
, "none",
495 GET_BE_U_4(lsap
->lsa_un
.un_rla
.rla_options
)));
496 ND_PRINT(", RLA-Flags [%s]",
497 bittok2str(ospf6_rla_flag_values
, "none",
498 GET_U_1(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 (GET_U_1(rlp
->link_type
)) {
508 case RLA_TYPE_VIRTUAL
:
509 ND_PRINT("\n\t Virtual Link: Neighbor Router-ID %s"
510 "\n\t Neighbor Interface-ID %s, Interface %s",
511 GET_IPADDR_STRING(rlp
->link_nrtid
),
512 GET_IPADDR_STRING(rlp
->link_nifid
),
513 GET_IPADDR_STRING(rlp
->link_ifid
));
516 case RLA_TYPE_ROUTER
:
517 ND_PRINT("\n\t Neighbor Router-ID %s"
518 "\n\t Neighbor Interface-ID %s, Interface %s",
519 GET_IPADDR_STRING(rlp
->link_nrtid
),
520 GET_IPADDR_STRING(rlp
->link_nifid
),
521 GET_IPADDR_STRING(rlp
->link_ifid
));
524 case RLA_TYPE_TRANSIT
:
525 ND_PRINT("\n\t Neighbor Network-ID %s"
526 "\n\t Neighbor Interface-ID %s, Interface %s",
527 GET_IPADDR_STRING(rlp
->link_nrtid
),
528 GET_IPADDR_STRING(rlp
->link_nifid
),
529 GET_IPADDR_STRING(rlp
->link_ifid
));
533 ND_PRINT("\n\t Unknown Router Links Type 0x%02x",
534 GET_U_1(rlp
->link_type
));
537 ND_PRINT(", metric %u", GET_BE_U_2(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_PRINT("\n\t Options [%s]",
547 bittok2str(ospf6_option_values
, "none",
548 GET_BE_U_4(lsap
->lsa_un
.un_nla
.nla_options
)));
550 ND_PRINT("\n\t Connected Routers:");
551 ap
= lsap
->lsa_un
.un_nla
.nla_router
;
552 while (lsa_length
!= 0) {
553 if (lsa_length
< sizeof (*ap
))
555 lsa_length
-= sizeof (*ap
);
557 ND_PRINT("\n\t\t%s", GET_IPADDR_STRING(*ap
));
562 case LS_TYPE_INTER_AP
| LS_SCOPE_AREA
:
563 if (lsa_length
< sizeof (lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
))
565 lsa_length
-= sizeof (lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
);
566 ND_PRINT(", metric %u",
567 GET_BE_U_4(lsap
->lsa_un
.un_inter_ap
.inter_ap_metric
) & SLA_MASK_METRIC
);
569 tptr
= (const uint8_t *)lsap
->lsa_un
.un_inter_ap
.inter_ap_prefix
;
570 while (lsa_length
!= 0) {
571 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
575 * ospf6_print_lsaprefix() will return -1 if
576 * the length is too high, so this will not
579 lsa_length
-= bytelen
;
584 case LS_TYPE_ASE
| LS_SCOPE_AS
:
585 if (lsa_length
< sizeof (lsap
->lsa_un
.un_asla
.asla_metric
))
587 lsa_length
-= sizeof (lsap
->lsa_un
.un_asla
.asla_metric
);
588 flags32
= GET_BE_U_4(lsap
->lsa_un
.un_asla
.asla_metric
);
589 ND_PRINT("\n\t Flags [%s]",
590 bittok2str(ospf6_asla_flag_values
, "none", flags32
));
591 ND_PRINT(" metric %u",
592 GET_BE_U_4(lsap
->lsa_un
.un_asla
.asla_metric
) &
595 tptr
= (const uint8_t *)lsap
->lsa_un
.un_asla
.asla_prefix
;
596 lsapp
= (const struct lsa6_prefix
*)tptr
;
597 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
601 * ospf6_print_lsaprefix() will return -1 if
602 * the length is too high, so this will not
605 lsa_length
-= bytelen
;
608 if ((flags32
& ASLA_FLAG_FWDADDR
) != 0) {
609 if (lsa_length
< sizeof (nd_ipv6
))
611 lsa_length
-= sizeof (nd_ipv6
);
612 ND_PRINT(" forward %s",
613 GET_IP6ADDR_STRING(tptr
));
614 tptr
+= sizeof(nd_ipv6
);
617 if ((flags32
& ASLA_FLAG_ROUTETAG
) != 0) {
618 if (lsa_length
< sizeof (uint32_t))
620 lsa_length
-= sizeof (uint32_t);
622 GET_IPADDR_STRING(tptr
));
623 tptr
+= sizeof(uint32_t);
626 if (GET_U_1(lsapp
->lsa_p_metric
)) {
627 if (lsa_length
< sizeof (uint32_t))
629 lsa_length
-= sizeof (uint32_t);
630 ND_PRINT(" RefLSID: %s",
631 GET_IPADDR_STRING(tptr
));
632 tptr
+= sizeof(uint32_t);
638 llsap
= &lsap
->lsa_un
.un_llsa
;
639 if (lsa_length
< sizeof (llsap
->llsa_priandopt
))
641 lsa_length
-= sizeof (llsap
->llsa_priandopt
);
642 ND_TCHECK_SIZE(&llsap
->llsa_priandopt
);
643 ND_PRINT("\n\t Options [%s]",
644 bittok2str(ospf6_option_values
, "none",
645 GET_BE_U_4(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
= GET_BE_U_4(llsap
->llsa_nprefix
);
651 ND_PRINT("\n\t Priority %u, Link-local address %s, Prefixes %u:",
652 GET_U_1(llsap
->llsa_priority
),
653 GET_IP6ADDR_STRING(llsap
->llsa_lladdr
),
656 tptr
= (const uint8_t *)llsap
->llsa_prefix
;
657 while (prefixes
> 0) {
658 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
663 * ospf6_print_lsaprefix() will return -1 if
664 * the length is too high, so this will not
667 lsa_length
-= bytelen
;
672 case LS_TYPE_INTRA_AP
| LS_SCOPE_AREA
:
673 /* Intra-Area-Prefix LSA */
674 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
))
676 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
677 ND_TCHECK_4(lsap
->lsa_un
.un_intra_ap
.intra_ap_rtid
);
678 ospf6_print_ls_type(ndo
,
679 GET_BE_U_2(lsap
->lsa_un
.un_intra_ap
.intra_ap_lstype
),
680 &lsap
->lsa_un
.un_intra_ap
.intra_ap_lsid
);
682 if (lsa_length
< sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
))
684 lsa_length
-= sizeof (lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
685 prefixes
= GET_BE_U_2(lsap
->lsa_un
.un_intra_ap
.intra_ap_nprefix
);
686 ND_PRINT("\n\t Prefixes %u:", prefixes
);
688 tptr
= (const uint8_t *)lsap
->lsa_un
.un_intra_ap
.intra_ap_prefix
;
689 while (prefixes
> 0) {
690 bytelen
= ospf6_print_lsaprefix(ndo
, tptr
, lsa_length
);
695 * ospf6_print_lsaprefix() will return -1 if
696 * the length is too high, so this will not
699 lsa_length
-= bytelen
;
704 case LS_TYPE_GRACE
| LS_SCOPE_LINKLOCAL
:
705 if (ospf_grace_lsa_print(ndo
, tptr
, lsa_length
) == -1) {
710 case LS_TYPE_INTRA_ATE
| LS_SCOPE_LINKLOCAL
:
711 if (ospf_te_lsa_print(ndo
, tptr
, lsa_length
) == -1) {
717 if(!print_unknown_data(ndo
,tptr
,
731 ospf6_decode_v3(netdissect_options
*ndo
,
732 const struct ospf6hdr
*op
,
733 const u_char
*dataend
)
736 const struct lsr6
*lsrp
;
737 const struct lsa6_hdr
*lshp
;
738 const struct lsa6
*lsap
;
741 switch (GET_U_1(op
->ospf6_type
)) {
743 case OSPF_TYPE_HELLO
: {
744 const struct hello6
*hellop
= (const struct hello6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
746 ND_PRINT("\n\tOptions [%s]",
747 bittok2str(ospf6_option_values
, "none",
748 GET_BE_U_4(hellop
->hello_options
)));
750 ND_PRINT("\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
751 GET_BE_U_2(hellop
->hello_helloint
),
752 GET_BE_U_2(hellop
->hello_deadint
),
753 GET_IPADDR_STRING(hellop
->hello_ifid
),
754 GET_U_1(hellop
->hello_priority
));
756 if (GET_BE_U_4(hellop
->hello_dr
) != 0)
757 ND_PRINT("\n\t Designated Router %s",
758 GET_IPADDR_STRING(hellop
->hello_dr
));
759 if (GET_BE_U_4(hellop
->hello_bdr
) != 0)
760 ND_PRINT(", Backup Designated Router %s",
761 GET_IPADDR_STRING(hellop
->hello_bdr
));
762 if (ndo
->ndo_vflag
> 1) {
763 ND_PRINT("\n\t Neighbor List:");
764 ap
= hellop
->hello_neighbor
;
765 while ((const u_char
*)ap
< dataend
) {
767 ND_PRINT("\n\t %s", GET_IPADDR_STRING(*ap
));
775 const struct dd6
*ddp
= (const struct dd6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
777 ND_PRINT("\n\tOptions [%s]",
778 bittok2str(ospf6_option_values
, "none",
779 GET_BE_U_4(ddp
->db_options
)));
780 ND_PRINT(", DD Flags [%s]",
781 bittok2str(ospf6_dd_flag_values
,"none",GET_U_1(ddp
->db_flags
)));
783 ND_PRINT(", MTU %u, DD-Sequence 0x%08x",
784 GET_BE_U_2(ddp
->db_mtu
),
785 GET_BE_U_4(ddp
->db_seq
));
786 if (ndo
->ndo_vflag
> 1) {
787 /* Print all the LS adv's */
788 lshp
= ddp
->db_lshdr
;
789 while ((const u_char
*)lshp
< dataend
) {
790 if (ospf6_print_lshdr(ndo
, lshp
++, dataend
))
797 case OSPF_TYPE_LS_REQ
:
798 if (ndo
->ndo_vflag
> 1) {
799 lsrp
= (const struct lsr6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
800 while ((const u_char
*)lsrp
< dataend
) {
801 ND_TCHECK_SIZE(lsrp
);
802 ND_PRINT("\n\t Advertising Router %s",
803 GET_IPADDR_STRING(lsrp
->ls_router
));
804 ospf6_print_ls_type(ndo
,
805 GET_BE_U_2(lsrp
->ls_type
),
812 case OSPF_TYPE_LS_UPDATE
:
813 if (ndo
->ndo_vflag
> 1) {
814 const struct lsu6
*lsup
= (const struct lsu6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
816 i
= GET_BE_U_4(lsup
->lsu_count
);
817 lsap
= lsup
->lsu_lsa
;
818 while ((const u_char
*)lsap
< dataend
&& i
--) {
819 if (ospf6_print_lsa(ndo
, lsap
, dataend
))
821 lsap
= (const struct lsa6
*)((const u_char
*)lsap
+
822 GET_BE_U_2(lsap
->ls_hdr
.ls_length
));
827 case OSPF_TYPE_LS_ACK
:
828 if (ndo
->ndo_vflag
> 1) {
829 lshp
= (const struct lsa6_hdr
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
830 while ((const u_char
*)lshp
< dataend
) {
831 if (ospf6_print_lshdr(ndo
, lshp
++, dataend
))
845 /* RFC5613 Section 2.2 (w/o the TLVs) */
847 ospf6_print_lls(netdissect_options
*ndo
,
848 const u_char
*cp
, const u_int len
)
854 if (len
< OSPF_LLS_HDRLEN
)
857 ND_PRINT("\n\tLLS Checksum 0x%04x", GET_BE_U_2(cp
));
859 /* LLS Data Length */
860 llsdatalen
= GET_BE_U_2(cp
);
861 ND_PRINT(", Data Length %u", llsdatalen
);
862 if (llsdatalen
< OSPF_LLS_HDRLEN
|| llsdatalen
> len
)
866 ND_TCHECK_LEN(cp
, llsdatalen
- OSPF_LLS_HDRLEN
);
867 /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
874 /* RFC6506 Section 4.1 */
876 ospf6_decode_at(netdissect_options
*ndo
,
877 const u_char
*cp
, const u_int len
)
879 uint16_t authdatalen
;
883 if (len
< OSPF6_AT_HDRLEN
)
885 /* Authentication Type */
886 ND_PRINT("\n\tAuthentication Type %s",
887 tok2str(ospf6_auth_type_str
, "unknown (0x%04x)", GET_BE_U_2(cp
)));
890 authdatalen
= GET_BE_U_2(cp
);
891 ND_PRINT(", Length %u", authdatalen
);
892 if (authdatalen
< OSPF6_AT_HDRLEN
|| authdatalen
> len
)
897 /* Security Association ID */
898 ND_PRINT(", SAID %u", GET_BE_U_2(cp
));
900 /* Cryptographic Sequence Number (High-Order 32 Bits) */
901 ND_PRINT(", CSN 0x%08x", GET_BE_U_4(cp
));
903 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
904 ND_PRINT(":%08x", GET_BE_U_4(cp
));
906 /* Authentication Data */
907 ND_TCHECK_LEN(cp
, authdatalen
- OSPF6_AT_HDRLEN
);
908 if (ndo
->ndo_vflag
> 1)
909 print_unknown_data(ndo
,cp
, "\n\tAuthentication Data ", authdatalen
- OSPF6_AT_HDRLEN
);
916 /* The trailing data may include LLS and/or AT data (in this specific order).
917 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
918 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
919 * any other packet type, thus decode the AT data regardless of the AT-bit.
922 ospf6_decode_v3_trailer(netdissect_options
*ndo
,
923 const struct ospf6hdr
*op
, const u_char
*cp
, const unsigned len
)
930 type
= GET_U_1(op
->ospf6_type
);
931 if (type
== OSPF_TYPE_HELLO
) {
932 const struct hello6
*hellop
= (const struct hello6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
933 if (GET_BE_U_4(hellop
->hello_options
) & OSPF6_OPTION_L
)
935 } else if (type
== OSPF_TYPE_DD
) {
936 const struct dd6
*ddp
= (const struct dd6
*)((const uint8_t *)op
+ OSPF6HDR_LEN
);
937 if (GET_BE_U_4(ddp
->db_options
) & OSPF6_OPTION_L
)
940 if ((lls_hello
|| lls_dd
) && (llslen
= ospf6_print_lls(ndo
, cp
, len
)) < 0)
942 return ospf6_decode_at(ndo
, cp
+ llslen
, len
- llslen
);
949 ospf6_print(netdissect_options
*ndo
,
950 const u_char
*bp
, u_int length
)
952 const struct ospf6hdr
*op
;
953 const u_char
*dataend
;
957 ndo
->ndo_protocol
= "ospf3";
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 cp
= tok2str(ospf6_type_values
, "unknown packet type (%u)",
963 GET_U_1(op
->ospf6_type
));
964 ND_PRINT("OSPFv%u, %s, length %u", GET_U_1(op
->ospf6_version
), cp
,
970 if(!ndo
->ndo_vflag
) { /* non verbose - so lets bail out here */
974 /* OSPFv3 data always comes first and optional trailing data may follow. */
975 datalen
= GET_BE_U_2(op
->ospf6_len
);
976 if (datalen
> length
) {
977 ND_PRINT(" [len %u]", datalen
);
980 dataend
= bp
+ datalen
;
982 ND_PRINT("\n\tRouter-ID %s", GET_IPADDR_STRING(op
->ospf6_routerid
));
984 if (GET_BE_U_4(op
->ospf6_areaid
) != 0)
985 ND_PRINT(", Area %s", GET_IPADDR_STRING(op
->ospf6_areaid
));
987 ND_PRINT(", Backbone Area");
988 if (GET_U_1(op
->ospf6_instanceid
))
989 ND_PRINT(", Instance %u", GET_U_1(op
->ospf6_instanceid
));
991 /* Do rest according to version. */
992 switch (GET_U_1(op
->ospf6_version
)) {
996 if (ospf6_decode_v3(ndo
, op
, dataend
) ||
997 ospf6_decode_v3_trailer(ndo
, op
, dataend
, length
- datalen
))
1000 } /* end switch on version */
1004 nd_print_trunc(ndo
);