]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf6.c
OSPFv3: fix SEGV on SPARCv9 (concurs with 8f6bca3)
[tcpdump] / print-ospf6.c
1 /*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 *
21 * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu)
22 */
23
24 #define NETDISSECT_REWORKED
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <tcpdump-stdinc.h>
30
31 #include <string.h>
32
33 #include "interface.h"
34 #include "addrtoname.h"
35 #include "extract.h"
36
37 #include "ospf.h"
38
39 #define OSPF_TYPE_HELLO 1 /* Hello */
40 #define OSPF_TYPE_DD 2 /* Database Description */
41 #define OSPF_TYPE_LS_REQ 3 /* Link State Request */
42 #define OSPF_TYPE_LS_UPDATE 4 /* Link State Update */
43 #define OSPF_TYPE_LS_ACK 5 /* Link State Ack */
44
45 /* Options *_options */
46 #define OSPF6_OPTION_V6 0x01 /* V6 bit: A bit for peeping tom */
47 #define OSPF6_OPTION_E 0x02 /* E bit: External routes advertised */
48 #define OSPF6_OPTION_MC 0x04 /* MC bit: Multicast capable */
49 #define OSPF6_OPTION_N 0x08 /* N bit: For type-7 LSA */
50 #define OSPF6_OPTION_R 0x10 /* R bit: Router bit */
51 #define OSPF6_OPTION_DC 0x20 /* DC bit: Demand circuits */
52 /* The field is actually 24-bit (RFC5340 Section A.2). */
53 #define OSPF6_OPTION_AF 0x0100 /* AF bit: Multiple address families */
54 #define OSPF6_OPTION_L 0x0200 /* L bit: Link-local signaling (LLS) */
55 #define OSPF6_OPTION_AT 0x0400 /* AT bit: Authentication trailer */
56
57
58 /* db_flags */
59 #define OSPF6_DB_INIT 0x04 /* */
60 #define OSPF6_DB_MORE 0x02
61 #define OSPF6_DB_MASTER 0x01
62 #define OSPF6_DB_M6 0x10 /* IPv6 MTU */
63
64 /* ls_type */
65 #define LS_TYPE_ROUTER 1 /* router link */
66 #define LS_TYPE_NETWORK 2 /* network link */
67 #define LS_TYPE_INTER_AP 3 /* Inter-Area-Prefix */
68 #define LS_TYPE_INTER_AR 4 /* Inter-Area-Router */
69 #define LS_TYPE_ASE 5 /* ASE */
70 #define LS_TYPE_GROUP 6 /* Group membership */
71 #define LS_TYPE_NSSA 7 /* NSSA */
72 #define LS_TYPE_LINK 8 /* Link LSA */
73 #define LS_TYPE_INTRA_AP 9 /* Intra-Area-Prefix */
74 #define LS_TYPE_INTRA_ATE 10 /* Intra-Area-TE */
75 #define LS_TYPE_GRACE 11 /* Grace LSA */
76 #define LS_TYPE_RI 12 /* Router information */
77 #define LS_TYPE_INTER_ASTE 13 /* Inter-AS-TE */
78 #define LS_TYPE_L1VPN 14 /* L1VPN */
79 #define LS_TYPE_MASK 0x1fff
80
81 #define LS_SCOPE_LINKLOCAL 0x0000
82 #define LS_SCOPE_AREA 0x2000
83 #define LS_SCOPE_AS 0x4000
84 #define LS_SCOPE_MASK 0x6000
85 #define LS_SCOPE_U 0x8000
86
87 /* rla_link.link_type */
88 #define RLA_TYPE_ROUTER 1 /* point-to-point to another router */
89 #define RLA_TYPE_TRANSIT 2 /* connection to transit network */
90 #define RLA_TYPE_VIRTUAL 4 /* virtual link */
91
92 /* rla_flags */
93 #define RLA_FLAG_B 0x01
94 #define RLA_FLAG_E 0x02
95 #define RLA_FLAG_V 0x04
96 #define RLA_FLAG_W 0x08
97 #define RLA_FLAG_N 0x10
98
99 /* lsa_prefix options */
100 #define LSA_PREFIX_OPT_NU 0x01
101 #define LSA_PREFIX_OPT_LA 0x02
102 #define LSA_PREFIX_OPT_MC 0x04
103 #define LSA_PREFIX_OPT_P 0x08
104 #define LSA_PREFIX_OPT_DN 0x10
105
106 /* sla_tosmetric breakdown */
107 #define SLA_MASK_TOS 0x7f000000
108 #define SLA_MASK_METRIC 0x00ffffff
109 #define SLA_SHIFT_TOS 24
110
111 /* asla_metric */
112 #define ASLA_FLAG_FWDADDR 0x02000000
113 #define ASLA_FLAG_ROUTETAG 0x01000000
114 #define ASLA_MASK_METRIC 0x00ffffff
115
116 /* RFC6506 Section 4.1 */
117 #define OSPF6_AT_HDRLEN 16U
118 #define OSPF6_AUTH_TYPE_HMAC 0x0001
119
120 typedef u_int32_t rtrid_t;
121
122 /* link state advertisement header */
123 struct lsa6_hdr {
124 u_int16_t ls_age;
125 u_int16_t ls_type;
126 rtrid_t ls_stateid;
127 rtrid_t ls_router;
128 u_int32_t ls_seq;
129 u_int16_t ls_chksum;
130 u_int16_t ls_length;
131 };
132
133 struct lsa6_prefix {
134 u_int8_t lsa_p_len;
135 u_int8_t lsa_p_opt;
136 u_int16_t lsa_p_metric;
137 u_int8_t lsa_p_prefix[4];
138 };
139
140 /* link state advertisement */
141 struct lsa6 {
142 struct lsa6_hdr ls_hdr;
143
144 /* Link state types */
145 union {
146 /* Router links advertisements */
147 struct {
148 union {
149 u_int8_t flg;
150 u_int32_t opt;
151 } rla_flgandopt;
152 #define rla_flags rla_flgandopt.flg
153 #define rla_options rla_flgandopt.opt
154 struct rlalink6 {
155 u_int8_t link_type;
156 u_int8_t link_zero[1];
157 u_int16_t link_metric;
158 u_int32_t link_ifid;
159 u_int32_t link_nifid;
160 rtrid_t link_nrtid;
161 } rla_link[1]; /* may repeat */
162 } un_rla;
163
164 /* Network links advertisements */
165 struct {
166 u_int32_t nla_options;
167 rtrid_t nla_router[1]; /* may repeat */
168 } un_nla;
169
170 /* Inter Area Prefix LSA */
171 struct {
172 u_int32_t inter_ap_metric;
173 struct lsa6_prefix inter_ap_prefix[1];
174 } un_inter_ap;
175
176 /* AS external links advertisements */
177 struct {
178 u_int32_t asla_metric;
179 struct lsa6_prefix asla_prefix[1];
180 /* some optional fields follow */
181 } un_asla;
182
183 #if 0
184 /* Summary links advertisements */
185 struct {
186 struct in_addr sla_mask;
187 u_int32_t sla_tosmetric[1]; /* may repeat */
188 } un_sla;
189
190 /* Multicast group membership */
191 struct mcla {
192 u_int32_t mcla_vtype;
193 struct in_addr mcla_vid;
194 } un_mcla[1];
195 #endif
196
197 /* Type 7 LSA */
198
199 /* Link LSA */
200 struct llsa {
201 union {
202 u_int8_t pri;
203 u_int32_t opt;
204 } llsa_priandopt;
205 #define llsa_priority llsa_priandopt.pri
206 #define llsa_options llsa_priandopt.opt
207 struct in6_addr llsa_lladdr;
208 u_int32_t llsa_nprefix;
209 struct lsa6_prefix llsa_prefix[1];
210 } un_llsa;
211
212 /* Intra-Area-Prefix */
213 struct {
214 u_int16_t intra_ap_nprefix;
215 u_int16_t intra_ap_lstype;
216 rtrid_t intra_ap_lsid;
217 rtrid_t intra_ap_rtid;
218 struct lsa6_prefix intra_ap_prefix[1];
219 } un_intra_ap;
220 } lsa_un;
221 };
222
223 /*
224 * the main header
225 */
226 struct ospf6hdr {
227 u_int8_t ospf6_version;
228 u_int8_t ospf6_type;
229 u_int16_t ospf6_len;
230 rtrid_t ospf6_routerid;
231 rtrid_t ospf6_areaid;
232 u_int16_t ospf6_chksum;
233 u_int8_t ospf6_instanceid;
234 u_int8_t ospf6_rsvd;
235 union {
236
237 /* Hello packet */
238 struct {
239 u_int32_t hello_ifid;
240 union {
241 u_int8_t pri;
242 u_int32_t opt;
243 } hello_priandopt;
244 #define hello_priority hello_priandopt.pri
245 #define hello_options hello_priandopt.opt
246 u_int16_t hello_helloint;
247 u_int16_t hello_deadint;
248 rtrid_t hello_dr;
249 rtrid_t hello_bdr;
250 rtrid_t hello_neighbor[1]; /* may repeat */
251 } un_hello;
252
253 /* Database Description packet */
254 struct {
255 u_int32_t db_options;
256 u_int16_t db_mtu;
257 u_int8_t db_mbz;
258 u_int8_t db_flags;
259 u_int32_t db_seq;
260 struct lsa6_hdr db_lshdr[1]; /* may repeat */
261 } un_db;
262
263 /* Link State Request */
264 struct lsr6 {
265 u_int16_t ls_mbz;
266 u_int16_t ls_type;
267 rtrid_t ls_stateid;
268 rtrid_t ls_router;
269 } un_lsr[1]; /* may repeat */
270
271 /* Link State Update */
272 struct {
273 u_int32_t lsu_count;
274 struct lsa6 lsu_lsa[1]; /* may repeat */
275 } un_lsu;
276
277 /* Link State Acknowledgement */
278 struct {
279 struct lsa6_hdr lsa_lshdr[1]; /* may repeat */
280 } un_lsa ;
281 } ospf6_un ;
282 };
283
284 #define ospf6_hello ospf6_un.un_hello
285 #define ospf6_db ospf6_un.un_db
286 #define ospf6_lsr ospf6_un.un_lsr
287 #define ospf6_lsu ospf6_un.un_lsu
288 #define ospf6_lsa ospf6_un.un_lsa
289
290 static const char tstr[] = " [|ospf3]";
291
292 static const struct tok ospf6_option_values[] = {
293 { OSPF6_OPTION_V6, "V6" },
294 { OSPF6_OPTION_E, "External" },
295 { OSPF6_OPTION_MC, "Deprecated" },
296 { OSPF6_OPTION_N, "NSSA" },
297 { OSPF6_OPTION_R, "Router" },
298 { OSPF6_OPTION_DC, "Demand Circuit" },
299 { OSPF6_OPTION_AF, "AFs Support" },
300 { OSPF6_OPTION_L, "LLS" },
301 { OSPF6_OPTION_AT, "Authentication Trailer" },
302 { 0, NULL }
303 };
304
305 static const struct tok ospf6_rla_flag_values[] = {
306 { RLA_FLAG_B, "ABR" },
307 { RLA_FLAG_E, "External" },
308 { RLA_FLAG_V, "Virtual-Link Endpoint" },
309 { RLA_FLAG_W, "Wildcard Receiver" },
310 { RLA_FLAG_N, "NSSA Translator" },
311 { 0, NULL }
312 };
313
314 static const struct tok ospf6_asla_flag_values[] = {
315 { ASLA_FLAG_EXTERNAL, "External Type 2" },
316 { ASLA_FLAG_FWDADDR, "Forwarding" },
317 { ASLA_FLAG_ROUTETAG, "Tag" },
318 { 0, NULL }
319 };
320
321 static const struct tok ospf6_type_values[] = {
322 { OSPF_TYPE_HELLO, "Hello" },
323 { OSPF_TYPE_DD, "Database Description" },
324 { OSPF_TYPE_LS_REQ, "LS-Request" },
325 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
326 { OSPF_TYPE_LS_ACK, "LS-Ack" },
327 { 0, NULL }
328 };
329
330 static const struct tok ospf6_lsa_values[] = {
331 { LS_TYPE_ROUTER, "Router" },
332 { LS_TYPE_NETWORK, "Network" },
333 { LS_TYPE_INTER_AP, "Inter-Area Prefix" },
334 { LS_TYPE_INTER_AR, "Inter-Area Router" },
335 { LS_TYPE_ASE, "External" },
336 { LS_TYPE_GROUP, "Deprecated" },
337 { LS_TYPE_NSSA, "NSSA" },
338 { LS_TYPE_LINK, "Link" },
339 { LS_TYPE_INTRA_AP, "Intra-Area Prefix" },
340 { LS_TYPE_INTRA_ATE, "Intra-Area TE" },
341 { LS_TYPE_GRACE, "Grace" },
342 { LS_TYPE_RI, "Router Information" },
343 { LS_TYPE_INTER_ASTE, "Inter-AS-TE" },
344 { LS_TYPE_L1VPN, "Layer 1 VPN" },
345 { 0, NULL }
346 };
347
348 static const struct tok ospf6_ls_scope_values[] = {
349 { LS_SCOPE_LINKLOCAL, "Link Local" },
350 { LS_SCOPE_AREA, "Area Local" },
351 { LS_SCOPE_AS, "Domain Wide" },
352 { 0, NULL }
353 };
354
355 static const struct tok ospf6_dd_flag_values[] = {
356 { OSPF6_DB_INIT, "Init" },
357 { OSPF6_DB_MORE, "More" },
358 { OSPF6_DB_MASTER, "Master" },
359 { OSPF6_DB_M6, "IPv6 MTU" },
360 { 0, NULL }
361 };
362
363 static const struct tok ospf6_lsa_prefix_option_values[] = {
364 { LSA_PREFIX_OPT_NU, "No Unicast" },
365 { LSA_PREFIX_OPT_LA, "Local address" },
366 { LSA_PREFIX_OPT_MC, "Deprecated" },
367 { LSA_PREFIX_OPT_P, "Propagate" },
368 { LSA_PREFIX_OPT_DN, "Down" },
369 { 0, NULL }
370 };
371
372 static const struct tok ospf6_auth_type_str[] = {
373 { OSPF6_AUTH_TYPE_HMAC, "HMAC" },
374 { 0, NULL }
375 };
376
377 static void
378 ospf6_print_ls_type(netdissect_options *ndo,
379 register u_int ls_type, register const rtrid_t *ls_stateid)
380 {
381 ND_PRINT((ndo, "\n\t %s LSA (%d), %s Scope%s, LSA-ID %s",
382 tok2str(ospf6_lsa_values, "Unknown", ls_type & LS_TYPE_MASK),
383 ls_type & LS_TYPE_MASK,
384 tok2str(ospf6_ls_scope_values, "Unknown", ls_type & LS_SCOPE_MASK),
385 ls_type &0x8000 ? ", transitive" : "", /* U-bit */
386 ipaddr_string(ndo, ls_stateid)));
387 }
388
389 static int
390 ospf6_print_lshdr(netdissect_options *ndo,
391 register const struct lsa6_hdr *lshp, const u_char *dataend)
392 {
393 if ((u_char *)(lshp + 1) > dataend)
394 goto trunc;
395 ND_TCHECK(lshp->ls_type);
396 ND_TCHECK(lshp->ls_seq);
397
398 ND_PRINT((ndo, "\n\t Advertising Router %s, seq 0x%08x, age %us, length %u",
399 ipaddr_string(ndo, &lshp->ls_router),
400 EXTRACT_32BITS(&lshp->ls_seq),
401 EXTRACT_16BITS(&lshp->ls_age),
402 EXTRACT_16BITS(&lshp->ls_length)-(u_int)sizeof(struct lsa6_hdr)));
403
404 ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
405
406 return (0);
407 trunc:
408 return (1);
409 }
410
411 static int
412 ospf6_print_lsaprefix(netdissect_options *ndo,
413 const u_int8_t *tptr, u_int lsa_length)
414 {
415 const struct lsa6_prefix *lsapp = (struct lsa6_prefix *)tptr;
416 u_int wordlen;
417 struct in6_addr prefix;
418
419 if (lsa_length < sizeof (*lsapp) - 4)
420 goto trunc;
421 lsa_length -= sizeof (*lsapp) - 4;
422 ND_TCHECK2(*lsapp, sizeof (*lsapp) - 4);
423 wordlen = (lsapp->lsa_p_len + 31) / 32;
424 if (wordlen * 4 > sizeof(struct in6_addr)) {
425 ND_PRINT((ndo, " bogus prefixlen /%d", lsapp->lsa_p_len));
426 goto trunc;
427 }
428 if (lsa_length < wordlen * 4)
429 goto trunc;
430 lsa_length -= wordlen * 4;
431 ND_TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
432 memset(&prefix, 0, sizeof(prefix));
433 memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
434 ND_PRINT((ndo, "\n\t\t%s/%d", ip6addr_string(ndo, &prefix),
435 lsapp->lsa_p_len));
436 if (lsapp->lsa_p_opt) {
437 ND_PRINT((ndo, ", Options [%s]",
438 bittok2str(ospf6_lsa_prefix_option_values,
439 "none", lsapp->lsa_p_opt)));
440 }
441 ND_PRINT((ndo, ", metric %u", EXTRACT_16BITS(&lsapp->lsa_p_metric)));
442 return sizeof(*lsapp) - 4 + wordlen * 4;
443
444 trunc:
445 return -1;
446 }
447
448
449 /*
450 * Print a single link state advertisement. If truncated return 1, else 0.
451 */
452 static int
453 ospf6_print_lsa(netdissect_options *ndo,
454 register const struct lsa6 *lsap, const u_char *dataend)
455 {
456 register const struct rlalink6 *rlp;
457 #if 0
458 register const struct tos_metric *tosp;
459 #endif
460 register const rtrid_t *ap;
461 #if 0
462 register const struct aslametric *almp;
463 register const struct mcla *mcp;
464 #endif
465 register const struct llsa *llsap;
466 register const struct lsa6_prefix *lsapp;
467 #if 0
468 register const u_int32_t *lp;
469 #endif
470 register u_int prefixes;
471 register int bytelen;
472 register u_int length, lsa_length;
473 u_int32_t flags32;
474 const u_int8_t *tptr;
475
476 if (ospf6_print_lshdr(ndo, &lsap->ls_hdr, dataend))
477 return (1);
478 ND_TCHECK(lsap->ls_hdr.ls_length);
479 length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
480
481 /*
482 * The LSA length includes the length of the header;
483 * it must have a value that's at least that length.
484 * If it does, find the length of what follows the
485 * header.
486 */
487 if (length < sizeof(struct lsa6_hdr) || (u_char *)lsap + length > dataend)
488 return (1);
489 lsa_length = length - sizeof(struct lsa6_hdr);
490 tptr = (u_int8_t *)lsap+sizeof(struct lsa6_hdr);
491
492 switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
493 case LS_TYPE_ROUTER | LS_SCOPE_AREA:
494 if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
495 return (1);
496 lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
497 ND_TCHECK(lsap->lsa_un.un_rla.rla_options);
498 ND_PRINT((ndo, "\n\t Options [%s]",
499 bittok2str(ospf6_option_values, "none",
500 EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options))));
501 ND_PRINT((ndo, ", RLA-Flags [%s]",
502 bittok2str(ospf6_rla_flag_values, "none",
503 lsap->lsa_un.un_rla.rla_flags)));
504
505 rlp = lsap->lsa_un.un_rla.rla_link;
506 while (lsa_length != 0) {
507 if (lsa_length < sizeof (*rlp))
508 return (1);
509 lsa_length -= sizeof (*rlp);
510 ND_TCHECK(*rlp);
511 switch (rlp->link_type) {
512
513 case RLA_TYPE_VIRTUAL:
514 ND_PRINT((ndo, "\n\t Virtual Link: Neighbor Router-ID %s"
515 "\n\t Neighbor Interface-ID %s, Interface %s",
516 ipaddr_string(ndo, &rlp->link_nrtid),
517 ipaddr_string(ndo, &rlp->link_nifid),
518 ipaddr_string(ndo, &rlp->link_ifid)));
519 break;
520
521 case RLA_TYPE_ROUTER:
522 ND_PRINT((ndo, "\n\t Neighbor Router-ID %s"
523 "\n\t Neighbor Interface-ID %s, Interface %s",
524 ipaddr_string(ndo, &rlp->link_nrtid),
525 ipaddr_string(ndo, &rlp->link_nifid),
526 ipaddr_string(ndo, &rlp->link_ifid)));
527 break;
528
529 case RLA_TYPE_TRANSIT:
530 ND_PRINT((ndo, "\n\t Neighbor Network-ID %s"
531 "\n\t Neighbor Interface-ID %s, Interface %s",
532 ipaddr_string(ndo, &rlp->link_nrtid),
533 ipaddr_string(ndo, &rlp->link_nifid),
534 ipaddr_string(ndo, &rlp->link_ifid)));
535 break;
536
537 default:
538 ND_PRINT((ndo, "\n\t Unknown Router Links Type 0x%02x",
539 rlp->link_type));
540 return (0);
541 }
542 ND_PRINT((ndo, ", metric %d", EXTRACT_16BITS(&rlp->link_metric)));
543 rlp++;
544 }
545 break;
546
547 case LS_TYPE_NETWORK | LS_SCOPE_AREA:
548 if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
549 return (1);
550 lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
551 ND_TCHECK(lsap->lsa_un.un_nla.nla_options);
552 ND_PRINT((ndo, "\n\t Options [%s]",
553 bittok2str(ospf6_option_values, "none",
554 EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options))));
555
556 ND_PRINT((ndo, "\n\t Connected Routers:"));
557 ap = lsap->lsa_un.un_nla.nla_router;
558 while (lsa_length != 0) {
559 if (lsa_length < sizeof (*ap))
560 return (1);
561 lsa_length -= sizeof (*ap);
562 ND_TCHECK(*ap);
563 ND_PRINT((ndo, "\n\t\t%s", ipaddr_string(ndo, ap)));
564 ++ap;
565 }
566 break;
567
568 case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
569 if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
570 return (1);
571 lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
572 ND_TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
573 ND_PRINT((ndo, ", metric %u",
574 EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC));
575
576 tptr = (u_int8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
577 while (lsa_length != 0) {
578 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
579 if (bytelen < 0)
580 goto trunc;
581 lsa_length -= bytelen;
582 tptr += bytelen;
583 }
584 break;
585
586 case LS_TYPE_ASE | LS_SCOPE_AS:
587 if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
588 return (1);
589 lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
590 ND_TCHECK(lsap->lsa_un.un_asla.asla_metric);
591 flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
592 ND_PRINT((ndo, "\n\t Flags [%s]",
593 bittok2str(ospf6_asla_flag_values, "none", flags32)));
594 ND_PRINT((ndo, " metric %u",
595 EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
596 ASLA_MASK_METRIC));
597
598 tptr = (u_int8_t *)lsap->lsa_un.un_asla.asla_prefix;
599 lsapp = (struct lsa6_prefix *)tptr;
600 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
601 if (bytelen < 0)
602 goto trunc;
603 lsa_length -= bytelen;
604 tptr += bytelen;
605
606 if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
607 struct in6_addr *fwdaddr6;
608
609 fwdaddr6 = (struct in6_addr *)tptr;
610 if (lsa_length < sizeof (*fwdaddr6))
611 return (1);
612 lsa_length -= sizeof (*fwdaddr6);
613 ND_TCHECK(*fwdaddr6);
614 ND_PRINT((ndo, " forward %s",
615 ip6addr_string(ndo, fwdaddr6)));
616 tptr += sizeof(*fwdaddr6);
617 }
618
619 if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
620 if (lsa_length < sizeof (u_int32_t))
621 return (1);
622 lsa_length -= sizeof (u_int32_t);
623 ND_TCHECK(*(u_int32_t *)tptr);
624 ND_PRINT((ndo, " tag %s",
625 ipaddr_string(ndo, (u_int32_t *)tptr)));
626 tptr += sizeof(u_int32_t);
627 }
628
629 if (lsapp->lsa_p_metric) {
630 if (lsa_length < sizeof (u_int32_t))
631 return (1);
632 lsa_length -= sizeof (u_int32_t);
633 ND_TCHECK(*(u_int32_t *)tptr);
634 ND_PRINT((ndo, " RefLSID: %s",
635 ipaddr_string(ndo, (u_int32_t *)tptr)));
636 tptr += sizeof(u_int32_t);
637 }
638 break;
639
640 case LS_TYPE_LINK:
641 /* Link LSA */
642 llsap = &lsap->lsa_un.un_llsa;
643 if (lsa_length < sizeof (llsap->llsa_priandopt))
644 return (1);
645 lsa_length -= sizeof (llsap->llsa_priandopt);
646 ND_TCHECK(llsap->llsa_priandopt);
647 ND_PRINT((ndo, "\n\t Options [%s]",
648 bittok2str(ospf6_option_values, "none",
649 EXTRACT_32BITS(&llsap->llsa_options))));
650
651 if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
652 return (1);
653 lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
654 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
655 ND_PRINT((ndo, "\n\t Priority %d, Link-local address %s, Prefixes %d:",
656 llsap->llsa_priority,
657 ip6addr_string(ndo, &llsap->llsa_lladdr),
658 prefixes));
659
660 tptr = (u_int8_t *)llsap->llsa_prefix;
661 while (prefixes > 0) {
662 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
663 if (bytelen < 0)
664 goto trunc;
665 prefixes--;
666 lsa_length -= bytelen;
667 tptr += bytelen;
668 }
669 break;
670
671 case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
672 /* Intra-Area-Prefix LSA */
673 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
674 return (1);
675 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
676 ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
677 ospf6_print_ls_type(ndo,
678 EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
679 &lsap->lsa_un.un_intra_ap.intra_ap_lsid);
680
681 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
682 return (1);
683 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
684 ND_TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
685 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
686 ND_PRINT((ndo, "\n\t Prefixes %d:", prefixes));
687
688 tptr = (u_int8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
689 while (prefixes > 0) {
690 bytelen = ospf6_print_lsaprefix(ndo, tptr, lsa_length);
691 if (bytelen < 0)
692 goto trunc;
693 prefixes--;
694 lsa_length -= bytelen;
695 tptr += bytelen;
696 }
697 break;
698
699 case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
700 if (ospf_print_grace_lsa(ndo, tptr, lsa_length) == -1) {
701 return 1;
702 }
703 break;
704
705 case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
706 if (ospf_print_te_lsa(ndo, tptr, lsa_length) == -1) {
707 return 1;
708 }
709 break;
710
711 default:
712 if(!print_unknown_data(ndo,tptr,
713 "\n\t ",
714 lsa_length)) {
715 return (1);
716 }
717 break;
718 }
719
720 return (0);
721 trunc:
722 return (1);
723 }
724
725 static int
726 ospf6_decode_v3(netdissect_options *ndo,
727 register const struct ospf6hdr *op,
728 register const u_char *dataend)
729 {
730 register const rtrid_t *ap;
731 register const struct lsr6 *lsrp;
732 register const struct lsa6_hdr *lshp;
733 register const struct lsa6 *lsap;
734 register int i;
735
736 switch (op->ospf6_type) {
737
738 case OSPF_TYPE_HELLO:
739 ND_PRINT((ndo, "\n\tOptions [%s]",
740 bittok2str(ospf6_option_values, "none",
741 EXTRACT_32BITS(&op->ospf6_hello.hello_options))));
742
743 ND_TCHECK(op->ospf6_hello.hello_deadint);
744 ND_PRINT((ndo, "\n\t Hello Timer %us, Dead Timer %us, Interface-ID %s, Priority %u",
745 EXTRACT_16BITS(&op->ospf6_hello.hello_helloint),
746 EXTRACT_16BITS(&op->ospf6_hello.hello_deadint),
747 ipaddr_string(ndo, &op->ospf6_hello.hello_ifid),
748 op->ospf6_hello.hello_priority));
749
750 ND_TCHECK(op->ospf6_hello.hello_dr);
751 if (EXTRACT_32BITS(&op->ospf6_hello.hello_dr) != 0)
752 ND_PRINT((ndo, "\n\t Designated Router %s",
753 ipaddr_string(ndo, &op->ospf6_hello.hello_dr)));
754 ND_TCHECK(op->ospf6_hello.hello_bdr);
755 if (EXTRACT_32BITS(&op->ospf6_hello.hello_bdr) != 0)
756 ND_PRINT((ndo, ", Backup Designated Router %s",
757 ipaddr_string(ndo, &op->ospf6_hello.hello_bdr)));
758 if (ndo->ndo_vflag > 1) {
759 ND_PRINT((ndo, "\n\t Neighbor List:"));
760 ap = op->ospf6_hello.hello_neighbor;
761 while ((u_char *)ap < dataend) {
762 ND_TCHECK(*ap);
763 ND_PRINT((ndo, "\n\t %s", ipaddr_string(ndo, ap)));
764 ++ap;
765 }
766 }
767 break; /* HELLO */
768
769 case OSPF_TYPE_DD:
770 ND_TCHECK(op->ospf6_db.db_options);
771 ND_PRINT((ndo, "\n\tOptions [%s]",
772 bittok2str(ospf6_option_values, "none",
773 EXTRACT_32BITS(&op->ospf6_db.db_options))));
774 ND_TCHECK(op->ospf6_db.db_flags);
775 ND_PRINT((ndo, ", DD Flags [%s]",
776 bittok2str(ospf6_dd_flag_values,"none",op->ospf6_db.db_flags)));
777
778 ND_TCHECK(op->ospf6_db.db_seq);
779 ND_PRINT((ndo, ", MTU %u, DD-Sequence 0x%08x",
780 EXTRACT_16BITS(&op->ospf6_db.db_mtu),
781 EXTRACT_32BITS(&op->ospf6_db.db_seq)));
782 if (ndo->ndo_vflag > 1) {
783 /* Print all the LS adv's */
784 lshp = op->ospf6_db.db_lshdr;
785 while ((u_char *)lshp < dataend) {
786 if (ospf6_print_lshdr(ndo, lshp++, dataend))
787 goto trunc;
788 }
789 }
790 break;
791
792 case OSPF_TYPE_LS_REQ:
793 if (ndo->ndo_vflag > 1) {
794 lsrp = op->ospf6_lsr;
795 while ((u_char *)lsrp < dataend) {
796 ND_TCHECK(*lsrp);
797 ND_PRINT((ndo, "\n\t Advertising Router %s",
798 ipaddr_string(ndo, &lsrp->ls_router)));
799 ospf6_print_ls_type(ndo, EXTRACT_16BITS(&lsrp->ls_type),
800 &lsrp->ls_stateid);
801 ++lsrp;
802 }
803 }
804 break;
805
806 case OSPF_TYPE_LS_UPDATE:
807 if (ndo->ndo_vflag > 1) {
808 lsap = op->ospf6_lsu.lsu_lsa;
809 ND_TCHECK(op->ospf6_lsu.lsu_count);
810 i = EXTRACT_32BITS(&op->ospf6_lsu.lsu_count);
811 while ((u_char *)lsap < dataend && i--) {
812 if (ospf6_print_lsa(ndo, lsap, dataend))
813 goto trunc;
814 lsap = (struct lsa6 *)((u_char *)lsap +
815 EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
816 }
817 }
818 break;
819
820
821 case OSPF_TYPE_LS_ACK:
822 if (ndo->ndo_vflag > 1) {
823 lshp = op->ospf6_lsa.lsa_lshdr;
824 while ((u_char *)lshp < dataend) {
825 if (ospf6_print_lshdr(ndo, lshp++, dataend))
826 goto trunc;
827 }
828 }
829 break;
830
831 default:
832 break;
833 }
834 return (0);
835 trunc:
836 return (1);
837 }
838
839 /* RFC5613 Section 2.2 (w/o the TLVs) */
840 static int
841 ospf6_print_lls(netdissect_options *ndo,
842 const u_char *cp, const u_int len)
843 {
844 uint16_t llsdatalen;
845
846 if (len == 0)
847 return 0;
848 if (len < OSPF_LLS_HDRLEN)
849 goto trunc;
850 /* Checksum */
851 ND_TCHECK2(*cp, 2);
852 ND_PRINT((ndo, "\n\tLLS Checksum 0x%04x", EXTRACT_16BITS(cp)));
853 cp += 2;
854 /* LLS Data Length */
855 ND_TCHECK2(*cp, 2);
856 llsdatalen = EXTRACT_16BITS(cp);
857 ND_PRINT((ndo, ", Data Length %u", llsdatalen));
858 if (llsdatalen < OSPF_LLS_HDRLEN || llsdatalen > len)
859 goto trunc;
860 cp += 2;
861 /* LLS TLVs */
862 ND_TCHECK2(*cp, llsdatalen - OSPF_LLS_HDRLEN);
863 /* FIXME: code in print-ospf.c can be reused to decode the TLVs */
864
865 return llsdatalen;
866 trunc:
867 return -1;
868 }
869
870 /* RFC6506 Section 4.1 */
871 static int
872 ospf6_decode_at(netdissect_options *ndo,
873 const u_char *cp, const u_int len)
874 {
875 uint16_t authdatalen;
876
877 if (len == 0)
878 return 0;
879 if (len < OSPF6_AT_HDRLEN)
880 goto trunc;
881 /* Authentication Type */
882 ND_TCHECK2(*cp, 2);
883 ND_PRINT((ndo, "\n\tAuthentication Type %s", tok2str(ospf6_auth_type_str, "unknown (0x%04x)", EXTRACT_16BITS(cp))));
884 cp += 2;
885 /* Auth Data Len */
886 ND_TCHECK2(*cp, 2);
887 authdatalen = EXTRACT_16BITS(cp);
888 ND_PRINT((ndo, ", Length %u", authdatalen));
889 if (authdatalen < OSPF6_AT_HDRLEN || authdatalen > len)
890 goto trunc;
891 cp += 2;
892 /* Reserved */
893 ND_TCHECK2(*cp, 2);
894 cp += 2;
895 /* Security Association ID */
896 ND_TCHECK2(*cp, 2);
897 ND_PRINT((ndo, ", SAID %u", EXTRACT_16BITS(cp)));
898 cp += 2;
899 /* Cryptographic Sequence Number (High-Order 32 Bits) */
900 ND_TCHECK2(*cp, 4);
901 ND_PRINT((ndo, ", CSN 0x%08x", EXTRACT_32BITS(cp)));
902 cp += 4;
903 /* Cryptographic Sequence Number (Low-Order 32 Bits) */
904 ND_TCHECK2(*cp, 4);
905 ND_PRINT((ndo, ":%08x", EXTRACT_32BITS(cp)));
906 cp += 4;
907 /* Authentication Data */
908 ND_TCHECK2(*cp, authdatalen - OSPF6_AT_HDRLEN);
909 if (ndo->ndo_vflag > 1)
910 print_unknown_data(ndo,cp, "\n\tAuthentication Data ", authdatalen - OSPF6_AT_HDRLEN);
911 return 0;
912
913 trunc:
914 return 1;
915 }
916
917 /* The trailing data may include LLS and/or AT data (in this specific order).
918 * LLS data may be present only in Hello and DBDesc packets with the L-bit set.
919 * AT data may be present in Hello and DBDesc packets with the AT-bit set or in
920 * any other packet type, thus decode the AT data regardless of the AT-bit.
921 */
922 static int
923 ospf6_decode_v3_trailer(netdissect_options *ndo,
924 const struct ospf6hdr *op, const u_char *cp, const unsigned len)
925 {
926 int llslen = 0;
927 u_char lls_hello = op->ospf6_type == OSPF_TYPE_HELLO &&
928 EXTRACT_32BITS(&op->ospf6_hello.hello_options) & OSPF6_OPTION_L;
929 u_char lls_dd = op->ospf6_type == OSPF_TYPE_DD &&
930 EXTRACT_32BITS(&op->ospf6_db.db_options) & OSPF6_OPTION_L;
931
932 if ((lls_hello || lls_dd) && (llslen = ospf6_print_lls(ndo, cp, len)) < 0)
933 goto trunc;
934 return ospf6_decode_at(ndo, cp + llslen, len - llslen);
935
936 trunc:
937 return 1;
938 }
939
940 void
941 ospf6_print(netdissect_options *ndo,
942 register const u_char *bp, register u_int length)
943 {
944 register const struct ospf6hdr *op;
945 register const u_char *dataend;
946 register const char *cp;
947 uint16_t datalen;
948
949 op = (struct ospf6hdr *)bp;
950
951 /* If the type is valid translate it, or just print the type */
952 /* value. If it's not valid, say so and return */
953 ND_TCHECK(op->ospf6_type);
954 cp = tok2str(ospf6_type_values, "unknown packet type (%u)", op->ospf6_type);
955 ND_PRINT((ndo, "OSPFv%u, %s, length %d", op->ospf6_version, cp, length));
956 if (*cp == 'u') {
957 return;
958 }
959
960 if(!ndo->ndo_vflag) { /* non verbose - so lets bail out here */
961 return;
962 }
963
964 /* OSPFv3 data always comes first and optional trailing data may follow. */
965 ND_TCHECK(op->ospf6_len);
966 datalen = EXTRACT_16BITS(&op->ospf6_len);
967 if (datalen > length) {
968 ND_PRINT((ndo, " [len %d]", datalen));
969 return;
970 }
971 dataend = bp + datalen;
972
973 ND_TCHECK(op->ospf6_routerid);
974 ND_PRINT((ndo, "\n\tRouter-ID %s", ipaddr_string(ndo, &op->ospf6_routerid)));
975
976 ND_TCHECK(op->ospf6_areaid);
977 if (EXTRACT_32BITS(&op->ospf6_areaid) != 0)
978 ND_PRINT((ndo, ", Area %s", ipaddr_string(ndo, &op->ospf6_areaid)));
979 else
980 ND_PRINT((ndo, ", Backbone Area"));
981 ND_TCHECK(op->ospf6_instanceid);
982 if (op->ospf6_instanceid)
983 ND_PRINT((ndo, ", Instance %u", op->ospf6_instanceid));
984
985 /* Do rest according to version. */
986 switch (op->ospf6_version) {
987
988 case 3:
989 /* ospf version 3 */
990 if (ospf6_decode_v3(ndo, op, dataend) ||
991 ospf6_decode_v3_trailer(ndo, op, dataend, length - datalen))
992 goto trunc;
993 break;
994 } /* end switch on version */
995
996 return;
997 trunc:
998 ND_PRINT((ndo, "%s", tstr));
999 }