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 uint32_t rtrid_t;
123 /* link state advertisement header */
134 /* Length of an IPv6 address, in bytes. */
135 #define IPV6_ADDR_LEN_BYTES (128/8)
140 uint16_t lsa_p_metric;
141 uint8_t 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
160 uint8_t link_zero[1];
161 uint16_t link_metric;
165 } rla_link[1]; /* may repeat */
168 /* Network links advertisements */
170 uint32_t nla_options;
171 rtrid_t nla_router[1]; /* may repeat */
174 /* Inter Area Prefix LSA */
176 uint32_t inter_ap_metric;
177 struct lsa6_prefix inter_ap_prefix[1];
180 /* AS external links advertisements */
182 uint32_t asla_metric;
183 struct lsa6_prefix asla_prefix[1];
184 /* some optional fields follow */
188 /* Summary links advertisements */
190 struct in_addr sla_mask;
191 uint32_t sla_tosmetric[1]; /* may repeat */
194 /* Multicast group membership */
197 struct in_addr mcla_vid;
209 #define llsa_priority llsa_priandopt.pri
210 #define llsa_options llsa_priandopt.opt
211 struct in6_addr llsa_lladdr;
212 uint32_t llsa_nprefix;
213 struct lsa6_prefix llsa_prefix[1];
216 /* Intra-Area-Prefix */
218 uint16_t intra_ap_nprefix;
219 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 uint8_t ospf6_version;
234 rtrid_t ospf6_routerid;
235 rtrid_t ospf6_areaid;
236 uint16_t ospf6_chksum;
237 uint8_t ospf6_instanceid;
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
254 #define hello_priority hello_priandopt.pri
255 #define hello_options hello_priandopt.opt
256 uint16_t hello_helloint;
257 uint16_t hello_deadint;
260 rtrid_t hello_neighbor[1]; /* may repeat */
263 /* Database Description packet */
270 struct lsa6_hdr db_lshdr[1]; /* may repeat */
273 /* Link State Request */
281 /* Link State Update */
284 struct lsa6 lsu_lsa[1]; /* may repeat */
287 static const char tstr[] = " [|ospf3]";
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, "Wildcard Receiver" },
307 { RLA_FLAG_N, "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" },
369 static const struct tok ospf6_auth_type_str[] = {
370 { OSPF6_AUTH_TYPE_HMAC, "HMAC" },
375 ospf6_print_ls_type(netdissect_options *ndo,
376 register u_int ls_type, register const rtrid_t *ls_stateid)
378 ND_PRINT((ndo, "\n\t %s LSA (%d), %s Scope%s, LSA-ID %s",
379 tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK),
380 ls_type & LS_TYPE_MASK,
381 tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK),
382 ls_type &0x8000 ? ", transitive" : "", /* U-bit */
383 ipaddr_string(ndo, ls_stateid)));
387 ospf6_print_lshdr(netdissect_options *ndo,
388 register const struct lsa6_hdr *lshp, const u_char *dataend)
390 if ((const u_char *)(lshp + 1) > dataend)
392 ND_TCHECK(lshp->ls_type);
393 ND_TCHECK(lshp->ls_seq);
395 ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
396 ipaddr_string(ndo, &lshp->ls_router),
397 EXTRACT_32BITS(&lshp->ls_seq),
398 EXTRACT_16BITS(&lshp->ls_age),
399 EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr)));
401 ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
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;
414 struct in6_addr prefix;
416 if (lsa_length < sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES)
418 lsa_length -= sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES;
419 ND_TCHECK2(*lsapp, sizeof (*lsapp) - IPV6_ADDR_LEN_BYTES);
420 wordlen = (lsapp->lsa_p_len + 31) / 32;
421 if (wordlen * 4 > sizeof(struct in6_addr)) {
422 ND_PRINT((ndo, " bogus prefixlen /%d", lsapp->lsa_p_len));
425 if (lsa_length < wordlen * 4)
427 lsa_length -= wordlen * 4;
428 ND_TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
429 memset(&prefix, 0, sizeof(prefix));
430 memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
431 ND_PRINT((ndo, "\n\t\t%s/%d", ip6addr_string(ndo, &prefix),
433 if (lsapp->lsa_p_opt) {
434 ND_PRINT((ndo, ", Options [%s]",
435 bittok2str(ospf6_lsa_prefix_option_values,
436 "none", lsapp->lsa_p_opt)));
438 ND_PRINT((ndo, ", metric %u", EXTRACT_16BITS(&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 register const struct lsa6 *lsap, const u_char *dataend)
453 register const struct rlalink6 *rlp;
455 register const struct tos_metric *tosp;
457 register const rtrid_t *ap;
459 register const struct aslametric *almp;
460 register const struct mcla *mcp;
462 register const struct llsa *llsap;
463 register const struct lsa6_prefix *lsapp;
465 register const uint32_t *lp;
467 register u_int prefixes;
468 register int bytelen;
469 register u_int length, lsa_length;
473 if (ospf6_print_lshdr(ndo, &lsap->ls_hdr, dataend))
475 ND_TCHECK(lsap->ls_hdr.ls_length);
476 length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
479 * The LSA length includes the length of the header;
480 * it must have a value that's at least that length.
481 * If it does, find the length of what follows the
484 if (length < sizeof(struct lsa6_hdr) || (const u_char *)lsap + length > dataend)
486 lsa_length = length - sizeof(struct lsa6_hdr);
487 tptr = (const uint8_t *)lsap+sizeof(struct lsa6_hdr);
489 switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
490 case LS_TYPE_ROUTER | LS_SCOPE_AREA:
491 if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
493 lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
494 ND_TCHECK(lsap->lsa_un.un_rla.rla_options);
495 ND_PRINT((ndo, "\n\t Options [%s]",
496 bittok2str(ospf6_option_values, "none",
497 EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options))));
498 ND_PRINT((ndo, ", RLA-Flags [%s]",
499 bittok2str(ospf6_rla_flag_values, "none",
500 lsap->lsa_un.un_rla.rla_flags)));
502 rlp = lsap->lsa_un.un_rla.rla_link;
503 while (lsa_length != 0) {
504 if (lsa_length < sizeof (*rlp))
506 lsa_length -= sizeof (*rlp);
508 switch (rlp->link_type) {
510 case RLA_TYPE_VIRTUAL:
511 ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID %s"
512 "\n\t Neighbor Interface-ID %s, Interface %s",
513 ipaddr_string(ndo, &rlp->link_nrtid),
514 ipaddr_string(ndo, &rlp->link_nifid),
515 ipaddr_string(ndo, &rlp->link_ifid)));
518 case RLA_TYPE_ROUTER:
519 ND_PRINT((ndo, "\n\t Neighbor Router-ID %s"
520 "\n\t Neighbor Interface-ID %s, Interface %s",
521 ipaddr_string(ndo, &rlp->link_nrtid),
522 ipaddr_string(ndo, &rlp->link_nifid),
523 ipaddr_string(ndo, &rlp->link_ifid)));
526 case RLA_TYPE_TRANSIT:
527 ND_PRINT((ndo, "\n\t Neighbor Network-ID %s"
528 "\n\t Neighbor Interface-ID %s, Interface %s",
529 ipaddr_string(ndo, &rlp->link_nrtid),
530 ipaddr_string(ndo, &rlp->link_nifid),
531 ipaddr_string(ndo, &rlp->link_ifid)));
535 ND_PRINT((ndo, "\n\t Unknown Router Links Type 0x%02x",
539 ND_PRINT((ndo, ", metric %d", EXTRACT_16BITS(&rlp->link_metric)));
544 case LS_TYPE_NETWORK | LS_SCOPE_AREA:
545 if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
547 lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
548 ND_TCHECK(lsap->lsa_un.un_nla.nla_options);
549 ND_PRINT((ndo, "\n\t Options [%s]",
550 bittok2str(ospf6_option_values, "none",
551 EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options))));
553 ND_PRINT((ndo, "\n\t Connected Routers:"));
554 ap = lsap->lsa_un.un_nla.nla_router;
555 while (lsa_length != 0) {
556 if (lsa_length < sizeof (*ap))
558 lsa_length -= sizeof (*ap);
560 ND_PRINT((ndo, "\n\t\t%s", ipaddr_string(ndo, ap)));
565 case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
566 if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
568 lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
569 ND_TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
570 ND_PRINT((ndo, ", metric %u",
571 EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC));
573 tptr = (const uint8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
574 while (lsa_length != 0) {
575 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
578 lsa_length -= bytelen;
583 case LS_TYPE_ASE | LS_SCOPE_AS:
584 if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
586 lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
587 ND_TCHECK(lsap->lsa_un.un_asla.asla_metric);
588 flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
589 ND_PRINT((ndo, "\n\t Flags [%s]",
590 bittok2str(ospf6_asla_flag_values, "none", flags32)));
591 ND_PRINT((ndo, " metric %u",
592 EXTRACT_32BITS(&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);
600 lsa_length -= bytelen;
603 if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
604 const struct in6_addr *fwdaddr6;
606 fwdaddr6 = (const struct in6_addr *)tptr;
607 if (lsa_length < sizeof (*fwdaddr6))
609 lsa_length -= sizeof (*fwdaddr6);
610 ND_TCHECK(*fwdaddr6);
611 ND_PRINT((ndo, " forward %s",
612 ip6addr_string(ndo, fwdaddr6)));
613 tptr += sizeof(*fwdaddr6);
616 if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
617 if (lsa_length < sizeof (uint32_t))
619 lsa_length -= sizeof (uint32_t);
620 ND_TCHECK(*(const uint32_t *)tptr);
621 ND_PRINT((ndo, " tag %s",
622 ipaddr_string(ndo, (const uint32_t *)tptr)));
623 tptr += sizeof(uint32_t);
626 if (lsapp->lsa_p_metric) {
627 if (lsa_length < sizeof (uint32_t))
629 lsa_length -= sizeof (uint32_t);
630 ND_TCHECK(*(const uint32_t *)tptr);
631 ND_PRINT((ndo, " RefLSID: %s",
632 ipaddr_string(ndo, (const uint32_t *)tptr)));
633 tptr += sizeof(uint32_t);
639 llsap = &lsap->lsa_un.un_llsa;
640 if (lsa_length < sizeof (llsap->llsa_priandopt))
642 lsa_length -= sizeof (llsap->llsa_priandopt);
643 ND_TCHECK(llsap->llsa_priandopt);
644 ND_PRINT((ndo, "\n\t Options [%s]",
645 bittok2str(ospf6_option_values, "none",
646 EXTRACT_32BITS(&llsap->llsa_options))));
648 if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
650 lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
651 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
652 ND_PRINT((ndo, "\n\t Priority %d, Link-local address %s, Prefixes %d:",
653 llsap->llsa_priority,
654 ip6addr_string(ndo, &llsap->llsa_lladdr),
657 tptr = (const uint8_t *)llsap->llsa_prefix;
658 while (prefixes > 0) {
659 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
663 lsa_length -= bytelen;
668 case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
669 /* Intra-Area-Prefix LSA */
670 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
672 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
673 ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
674 ospf6_print_ls_type(ndo,
675 EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
676 &lsap->lsa_un.un_intra_ap.intra_ap_lsid);
678 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
680 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
681 ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
682 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
683 ND_PRINT((ndo, "\n\t Prefixes %d:", prefixes));
685 tptr = (const uint8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
686 while (prefixes > 0) {
687 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
691 lsa_length -= bytelen;
696 case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
697 if (ospf_print_grace_lsa(ndo, tptr, lsa_length) == -1) {
702 case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
703 if (ospf_print_te_lsa(ndo, tptr, lsa_length) == -1) {
709 if(!print_unknown_data(ndo,tptr,
723 ospf6_decode_v3(netdissect_options *ndo,
724 register const struct ospf6hdr *op,
725 register const u_char *dataend)
727 register const rtrid_t *ap;
728 register const struct lsr6 *lsrp;
729 register const struct lsa6_hdr *lshp;
730 register const struct lsa6 *lsap;
733 switch (op->ospf6_type) {
735 case OSPF_TYPE_HELLO: {
736 register const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
738 ND_PRINT((ndo, "\n\tOptions [%s]",
739 bittok2str(ospf6_option_values, "none",
740 EXTRACT_32BITS(&hellop->hello_options))));
742 ND_TCHECK(hellop->hello_deadint);
743 ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
744 EXTRACT_16BITS(&hellop->hello_helloint),
745 EXTRACT_16BITS(&hellop->hello_deadint),
746 ipaddr_string(ndo, &hellop->hello_ifid),
747 hellop->hello_priority));
749 ND_TCHECK(hellop->hello_dr);
750 if (EXTRACT_32BITS(&hellop->hello_dr) != 0)
751 ND_PRINT((ndo, "\n\t Designated Router %s",
752 ipaddr_string(ndo, &hellop->hello_dr)));
753 ND_TCHECK(hellop->hello_bdr);
754 if (EXTRACT_32BITS(&hellop->hello_bdr) != 0)
755 ND_PRINT((ndo, ", Backup Designated Router %s",
756 ipaddr_string(ndo, &hellop->hello_bdr)));
757 if (ndo->ndo_vflag > 1) {
758 ND_PRINT((ndo, "\n\t Neighbor List:"));
759 ap = hellop->hello_neighbor;
760 while ((const u_char *)ap < dataend) {
762 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
770 register const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
772 ND_TCHECK(ddp->db_options);
773 ND_PRINT((ndo, "\n\tOptions [%s]",
774 bittok2str(ospf6_option_values, "none",
775 EXTRACT_32BITS(&ddp->db_options))));
776 ND_TCHECK(ddp->db_flags);
777 ND_PRINT((ndo, ", DD Flags [%s]",
778 bittok2str(ospf6_dd_flag_values,"none",ddp->db_flags)));
780 ND_TCHECK(ddp->db_seq);
781 ND_PRINT((ndo, ", MTU %u, DD-Sequence 0x%08x",
782 EXTRACT_16BITS(&ddp->db_mtu),
783 EXTRACT_32BITS(&ddp->db_seq)));
784 if (ndo->ndo_vflag > 1) {
785 /* Print all the LS adv's */
786 lshp = ddp->db_lshdr;
787 while ((const u_char *)lshp < dataend) {
788 if (ospf6_print_lshdr(ndo, lshp++, dataend))
795 case OSPF_TYPE_LS_REQ:
796 if (ndo->ndo_vflag > 1) {
797 lsrp = (const struct lsr6 *)((const uint8_t *)op + OSPF6HDR_LEN);
798 while ((const u_char *)lsrp < dataend) {
800 ND_PRINT((ndo, "\n\t Advertising Router %s",
801 ipaddr_string(ndo, &lsrp->ls_router)));
802 ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lsrp->ls_type),
809 case OSPF_TYPE_LS_UPDATE:
810 if (ndo->ndo_vflag > 1) {
811 register const struct lsu6 *lsup = (const struct lsu6 *)((const uint8_t *)op + OSPF6HDR_LEN);
813 ND_TCHECK(lsup->lsu_count);
814 i = EXTRACT_32BITS(&lsup->lsu_count);
815 lsap = lsup->lsu_lsa;
816 while ((const u_char *)lsap < dataend && i--) {
817 if (ospf6_print_lsa(ndo, lsap, dataend))
819 lsap = (const struct lsa6 *)((const u_char *)lsap +
820 EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
825 case OSPF_TYPE_LS_ACK:
826 if (ndo->ndo_vflag > 1) {
827 lshp = (const struct lsa6_hdr *)((const uint8_t *)op + OSPF6HDR_LEN);
828 while ((const u_char *)lshp < dataend) {
829 if (ospf6_print_lshdr(ndo, lshp++, dataend))
843 /* RFC5613 Section 2.2 (w/o the TLVs) */
845 ospf6_print_lls(netdissect_options *ndo,
846 const u_char *cp, const u_int len)
852 if (len < OSPF_LLS_HDRLEN)
856 ND_PRINT((ndo, "\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp)));
858 /* LLS Data Length */
860 llsdatalen = EXTRACT_16BITS(cp);
861 ND_PRINT((ndo, ", Data Length %u", llsdatalen));
862 if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len)
866 ND_TCHECK2(*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 */
887 ND_PRINT((ndo, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_16BITS(cp))));
891 authdatalen = EXTRACT_16BITS(cp);
892 ND_PRINT((ndo, ", Length %u", authdatalen));
893 if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len)
899 /* Security Association ID */
901 ND_PRINT((ndo, ", SAID %u", EXTRACT_16BITS(cp)));
903 /* Cryptographic Sequence Number (High-Order 32 Bits) */
905 ND_PRINT((ndo, ", CSN 0x%08x", EXTRACT_32BITS(cp)));
907 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
909 ND_PRINT((ndo, ":%08x", EXTRACT_32BITS(cp)));
911 /* Authentication Data */
912 ND_TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN);
913 if (ndo->ndo_vflag > 1)
914 print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN);
921 /* The trailing data may include LLS and/or AT data (in this specific order).
922 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
923 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
924 * any other packet type, thus decode the AT data regardless of the AT-bit.
927 ospf6_decode_v3_trailer(netdissect_options *ndo,
928 const struct ospf6hdr *op, const u_char *cp, const unsigned len)
934 if (op->ospf6_type == OSPF_TYPE_HELLO) {
935 const struct hello6 *hellop = (const struct hello6 *)((const uint8_t *)op + OSPF6HDR_LEN);
936 if (EXTRACT_32BITS(&hellop->hello_options) & OSPF6_OPTION_L)
938 } else if (op->ospf6_type == OSPF_TYPE_DD) {
939 const struct dd6 *ddp = (const struct dd6 *)((const uint8_t *)op + OSPF6HDR_LEN);
940 if (EXTRACT_32BITS(&ddp->db_options) & OSPF6_OPTION_L)
943 if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0)
945 return ospf6_decode_at(ndo, cp + llslen, len - llslen);
952 ospf6_print(netdissect_options *ndo,
953 register const u_char *bp, register u_int length)
955 register const struct ospf6hdr *op;
956 register const u_char *dataend;
957 register const char *cp;
960 op = (const struct ospf6hdr *)bp;
962 /* If the type is valid translate it, or just print the type */
963 /* value. If it's not valid, say so and return */
964 ND_TCHECK(op->ospf6_type);
965 cp = tok2str(ospf6_type_values, "unknown packet type (%u)", op->ospf6_type);
966 ND_PRINT((ndo, "OSPFv%u, %s, length %d", op->ospf6_version, cp, length));
971 if(!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
975 /* OSPFv3 data always comes first and optional trailing data may follow. */
976 ND_TCHECK(op->ospf6_len);
977 datalen = EXTRACT_16BITS(&op->ospf6_len);
978 if (datalen > length) {
979 ND_PRINT((ndo, " [len %d]", datalen));
982 dataend = bp + datalen;
984 ND_TCHECK(op->ospf6_routerid);
985 ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf6_routerid)));
987 ND_TCHECK(op->ospf6_areaid);
988 if (EXTRACT_32BITS(&op->ospf6_areaid) != 0)
989 ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf6_areaid)));
991 ND_PRINT((ndo, ", Backbone Area"));
992 ND_TCHECK(op->ospf6_instanceid);
993 if (op->ospf6_instanceid)
994 ND_PRINT((ndo, ", Instance %u", op->ospf6_instanceid));
996 /* Do rest according to version. */
997 switch (op->ospf6_version) {
1000 /* ospf version 3 */
1001 if (ospf6_decode_v3(ndo, op, dataend) ||
1002 ospf6_decode_v3_trailer(ndo, op, dataend, length - datalen))
1005 } /* end switch on version */
1009 ND_PRINT((ndo, "%s", tstr));