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