]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
bug report [plus partial patch] from Carles Kishimoto Bisbe ckishimo [AT] ac [DOT...
[tcpdump] / print-ospf.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 #ifndef lint
25 static const char rcsid[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-ospf.c,v 1.41 2003-10-20 16:11:45 hannes Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <tcpdump-stdinc.h>
34
35 #include <stdio.h>
36
37 #include "interface.h"
38 #include "addrtoname.h"
39 #include "extract.h"
40 #include "gmpls.h"
41
42 #include "ospf.h"
43
44 #include "ip.h"
45
46 static struct tok ospf_option_values[] = {
47 { OSPF_OPTION_T, "TOS" },
48 { OSPF_OPTION_E, "External" },
49 { OSPF_OPTION_MC, "Multicast" },
50 { OSPF_OPTION_NP, "NSSA" },
51 { OSPF_OPTION_EA, "Advertise External" },
52 { OSPF_OPTION_DC, "Demand Circuit" },
53 { OSPF_OPTION_O, "Opaque" },
54 { 0, NULL }
55 };
56
57 static struct tok ospf_authtype_values[] = {
58 { OSPF_AUTH_NONE, "none" },
59 { OSPF_AUTH_NONE, "simple" },
60 { OSPF_AUTH_MD5, "MD5" },
61 { 0, NULL }
62 };
63
64 static struct tok ospf_rla_flag_values[] = {
65 { RLA_FLAG_B, "ABR" },
66 { RLA_FLAG_E, "ASBR" },
67 { RLA_FLAG_W1, "Virtual" },
68 { RLA_FLAG_W2, "W2" },
69 { 0, NULL }
70 };
71
72 static struct tok type2str[] = {
73 { OSPF_TYPE_UMD, "UMD" },
74 { OSPF_TYPE_HELLO, "Hello" },
75 { OSPF_TYPE_DD, "Database Description" },
76 { OSPF_TYPE_LS_REQ, "LS-Request" },
77 { OSPF_TYPE_LS_UPDATE, "LS-Update" },
78 { OSPF_TYPE_LS_ACK, "LS-Ack" },
79 { 0, NULL }
80 };
81
82 static struct tok lsa_values[] = {
83 { LS_TYPE_ROUTER, "Router" },
84 { LS_TYPE_NETWORK, "Network" },
85 { LS_TYPE_SUM_IP, "Summary" },
86 { LS_TYPE_SUM_ABR, "ASBR Summary" },
87 { LS_TYPE_ASE, "External" },
88 { LS_TYPE_GROUP, "Multicast Group" },
89 { LS_TYPE_NSSA, "NSSA" },
90 { LS_TYPE_OPAQUE_LL, "Link Local Opaque" },
91 { LS_TYPE_OPAQUE_AL, "Area Local Opaque" },
92 { LS_TYPE_OPAQUE_DW, "Domain Wide Opaque" },
93 { 0, NULL }
94 };
95
96 static struct tok ospf_dd_flag_values[] = {
97 { OSPF_DB_INIT, "Init" },
98 { OSPF_DB_MORE, "More" },
99 { OSPF_DB_MASTER, "Master" },
100 { 0, NULL }
101 };
102
103 static struct tok lsa_opaque_values[] = {
104 { LS_OPAQUE_TYPE_TE, "Traffic Engineering" },
105 { LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
106 { 0, NULL }
107 };
108
109 static struct tok lsa_opaque_te_tlv_values[] = {
110 { LS_OPAQUE_TE_TLV_ROUTER, "Router Address" },
111 { LS_OPAQUE_TE_TLV_LINK, "Link" },
112 { 0, NULL }
113 };
114
115 static struct tok lsa_opaque_te_link_tlv_subtlv_values[] = {
116 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE, "Link Type" },
117 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID, "Link ID" },
118 { LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP, "Local Interface IP address" },
119 { LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP, "Remote Interface IP address" },
120 { LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC, "Traffic Engineering Metric" },
121 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW, "Maximum Bandwidth" },
122 { LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW, "Maximum Reservable Bandwidth" },
123 { LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW, "Unreserved Bandwidth" },
124 { LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP, "Administrative Group" },
125 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID, "Link Local/Remote Identifier" },
126 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE, "Link Protection Type" },
127 { LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR, "Interface Switching Capability" },
128 { LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP, "Shared Risk Link Group" },
129 { 0, NULL }
130 };
131
132 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP 1 /* rfc3630 */
133 #define LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA 2 /* rfc3630 */
134
135 static struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
136 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_PTP, "Point-to-point" },
137 { LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE_MA, "Multi-Access" },
138 { 0, NULL }
139 };
140
141 static char tstr[] = " [|ospf]";
142
143 #ifdef WIN32
144 #define inline __inline
145 #endif /* WIN32 */
146
147 static int ospf_print_lshdr(const struct lsa_hdr *);
148 static int ospf_print_lsa(const struct lsa *);
149 static int ospf_decode_v2(const struct ospfhdr *, const u_char *);
150
151 static int
152 ospf_print_lshdr(register const struct lsa_hdr *lshp) {
153
154 TCHECK(lshp->ls_type);
155 TCHECK(lshp->ls_options);
156
157 printf("\n\t %s LSA (%d), LSA-ID: %s, Advertising Router: %s, seq 0x%08x, age %us",
158 tok2str(lsa_values,"unknown",lshp->ls_type),
159 lshp->ls_type,
160 ipaddr_string(&lshp->un_lsa_id.lsa_id),
161 ipaddr_string(&lshp->ls_router),
162 EXTRACT_32BITS(&lshp->ls_seq),
163 EXTRACT_16BITS(&lshp->ls_age));
164 printf("\n\t Options: %s", bittok2str(ospf_option_values,"none",lshp->ls_options));
165
166 return (0);
167 trunc:
168 return (1);
169 }
170
171 /*
172 * Print a single link state advertisement. If truncated return 1, else 0.
173 */
174 static int
175 ospf_print_lsa(register const struct lsa *lsap)
176 {
177 register const u_char *ls_end;
178 register const struct rlalink *rlp;
179 register const struct tos_metric *tosp;
180 register const struct in_addr *ap;
181 register const struct aslametric *almp;
182 register const struct mcla *mcp;
183 register const u_int32_t *lp;
184 register int j, k,ls_length, tlv_type, tlv_length, subtlv_type, subtlv_length, priority_level;
185 const u_int8_t *tptr;
186 union { /* int to float conversion buffer for several subTLVs */
187 float f;
188 u_int32_t i;
189 } bw;
190
191 tptr = (u_int8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
192 ls_length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length)-sizeof(struct lsa_hdr);
193
194 printf(", Advertising Router: %s, seq 0x%08x, age %us, length: %u",
195 ipaddr_string(&lsap->ls_hdr.ls_router),
196 EXTRACT_32BITS(&lsap->ls_hdr.ls_seq),
197 EXTRACT_16BITS(&lsap->ls_hdr.ls_age),
198 ls_length);
199
200 switch (lsap->ls_hdr.ls_type) {
201 /* the LSA header for opaque LSAs was slightly changed */
202 case LS_TYPE_OPAQUE_LL:
203 case LS_TYPE_OPAQUE_AL:
204 case LS_TYPE_OPAQUE_DW:
205
206 printf("\n\t %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u",
207 tok2str(lsa_values,"unknown",lsap->ls_hdr.ls_type),
208 (lsap->ls_hdr.ls_type),
209 tok2str(lsa_opaque_values,
210 "unknown",
211 *(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)),
212 *(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type),
213 EXTRACT_24BITS(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_id));
214 break;
215
216 /* all other LSA types use regular style LSA headers */
217 default:
218 printf("\n\t %s LSA (%d), LSA-ID: %s",
219 tok2str(lsa_values,"unknown",lsap->ls_hdr.ls_type),
220 lsap->ls_hdr.ls_type,
221 ipaddr_string(&lsap->ls_hdr.un_lsa_id.lsa_id));
222 break;
223 }
224
225 printf("\n\t Options: %s", bittok2str(ospf_option_values,"none",lsap->ls_hdr.ls_options));
226
227 TCHECK(lsap->ls_hdr.ls_length);
228 ls_end = (u_char *)lsap + EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
229
230 switch (lsap->ls_hdr.ls_type) {
231
232 case LS_TYPE_ROUTER:
233 TCHECK(lsap->lsa_un.un_rla.rla_flags);
234 printf("\n\t Router LSA Options: %s", bittok2str(ospf_rla_flag_values,"unknown (%u)",lsap->lsa_un.un_rla.rla_flags));
235
236 TCHECK(lsap->lsa_un.un_rla.rla_count);
237 j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
238 TCHECK(lsap->lsa_un.un_rla.rla_link);
239 rlp = lsap->lsa_un.un_rla.rla_link;
240 while (j--) {
241 TCHECK(*rlp);
242 switch (rlp->link_type) {
243
244 case RLA_TYPE_VIRTUAL:
245 printf("\n\t Virtual Link: Neighbor-Router-ID: %s, Interface-IP: %s",
246 ipaddr_string(&rlp->link_id),
247 ipaddr_string(&rlp->link_data));
248 break;
249
250 case RLA_TYPE_ROUTER:
251 printf("\n\t Neighbor-Router-ID: %s, Interface-IP: %s",
252 ipaddr_string(&rlp->link_id),
253 ipaddr_string(&rlp->link_data));
254 break;
255
256 case RLA_TYPE_TRANSIT:
257 printf("\n\t Neighbor-Network-ID: %s, Interface-IP: %s",
258 ipaddr_string(&rlp->link_id),
259 ipaddr_string(&rlp->link_data));
260 break;
261
262 case RLA_TYPE_STUB:
263 printf("\n\t Stub-Network: %s, mask: %s",
264 ipaddr_string(&rlp->link_id),
265 ipaddr_string(&rlp->link_data));
266 break;
267
268 default:
269 printf("\n\t unknown Router Links Type (%u)",
270 rlp->link_type);
271 return (0);
272 }
273 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp->link_tos0metric));
274 tosp = (struct tos_metric *)
275 ((sizeof rlp->link_tos0metric) + (u_char *) rlp);
276 for (k = 0; k < (int) rlp->link_toscount; ++k, ++tosp) {
277 TCHECK(*tosp);
278 printf(", tos %d, metric: %d",
279 tosp->tos_type,
280 EXTRACT_16BITS(&tosp->tos_metric));
281 }
282 rlp = (struct rlalink *)((u_char *)(rlp + 1) +
283 ((rlp->link_toscount) * sizeof(*tosp)));
284 }
285 break;
286
287 case LS_TYPE_NETWORK:
288 TCHECK(lsap->lsa_un.un_nla.nla_mask);
289 printf("\n\t mask %s rtrs",
290 ipaddr_string(&lsap->lsa_un.un_nla.nla_mask));
291 ap = lsap->lsa_un.un_nla.nla_router;
292 while ((u_char *)ap < ls_end) {
293 TCHECK(*ap);
294 printf(" %s", ipaddr_string(ap));
295 ++ap;
296 }
297 break;
298
299 case LS_TYPE_SUM_IP:
300 TCHECK(lsap->lsa_un.un_nla.nla_mask);
301 printf("\n\t mask %s",
302 ipaddr_string(&lsap->lsa_un.un_sla.sla_mask));
303 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
304 lp = lsap->lsa_un.un_sla.sla_tosmetric;
305 /* suppress tos if its not supported */
306 if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) {
307 printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC);
308 break;
309 }
310 while ((u_char *)lp < ls_end) {
311 register u_int32_t ul;
312
313 TCHECK(*lp);
314 ul = EXTRACT_32BITS(lp);
315 printf(", tos %d metric %d",
316 (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
317 ul & SLA_MASK_METRIC);
318 ++lp;
319 }
320 break;
321
322 case LS_TYPE_SUM_ABR:
323 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
324 lp = lsap->lsa_un.un_sla.sla_tosmetric;
325 /* suppress tos if its not supported */
326 if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) {
327 printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC);
328 break;
329 }
330 while ((u_char *)lp < ls_end) {
331 register u_int32_t ul;
332
333 TCHECK(*lp);
334 ul = EXTRACT_32BITS(lp);
335 printf(", tos %d metric %d",
336 (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
337 ul & SLA_MASK_METRIC);
338 ++lp;
339 }
340 break;
341
342 case LS_TYPE_ASE:
343 TCHECK(lsap->lsa_un.un_nla.nla_mask);
344 printf("\n\t mask %s",
345 ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
346
347 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
348 almp = lsap->lsa_un.un_asla.asla_metric;
349 while ((u_char *)almp < ls_end) {
350 register u_int32_t ul;
351
352 TCHECK(almp->asla_tosmetric);
353 ul = EXTRACT_32BITS(&almp->asla_tosmetric);
354 printf(", type %d, tos %d metric:",
355 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
356 (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
357 if ((ul & ASLA_MASK_METRIC)==0xffffff)
358 printf(" infinite");
359 else
360 printf(" %d", (ul & ASLA_MASK_METRIC));
361
362 TCHECK(almp->asla_forward);
363 if (almp->asla_forward.s_addr) {
364 printf(", forward %s",
365 ipaddr_string(&almp->asla_forward));
366 }
367 TCHECK(almp->asla_tag);
368 if (almp->asla_tag.s_addr) {
369 printf(", tag %s",
370 ipaddr_string(&almp->asla_tag));
371 }
372 ++almp;
373 }
374 break;
375
376 case LS_TYPE_GROUP:
377 /* Multicast extensions as of 23 July 1991 */
378 mcp = lsap->lsa_un.un_mcla;
379 while ((u_char *)mcp < ls_end) {
380 TCHECK(mcp->mcla_vid);
381 switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
382
383 case MCLA_VERTEX_ROUTER:
384 printf("\n\t Router Router-ID %s",
385 ipaddr_string(&mcp->mcla_vid));
386 break;
387
388 case MCLA_VERTEX_NETWORK:
389 printf("\n\t Network Designated Router %s",
390 ipaddr_string(&mcp->mcla_vid));
391 break;
392
393 default:
394 printf("\n\t unknown VertexType (%u)",
395 EXTRACT_32BITS(&mcp->mcla_vtype));
396 break;
397 }
398 ++mcp;
399 }
400 break;
401
402 case LS_TYPE_OPAQUE_LL: /* fall through */
403 case LS_TYPE_OPAQUE_AL:
404 case LS_TYPE_OPAQUE_DW:
405
406 switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
407 case LS_OPAQUE_TYPE_TE:
408 if (!TTEST2(*tptr, 4))
409 goto trunc;
410
411 tptr = (u_int8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type);
412
413 while (ls_length > 0) {
414 tlv_type = EXTRACT_16BITS(tptr);
415 tlv_length = EXTRACT_16BITS(tptr+2);
416 ls_length-=(tlv_length+4);
417 tptr+=4;
418
419 printf("\n\t %s TLV (%u), length: %u",
420 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
421 tlv_type,
422 tlv_length);
423
424 switch(tlv_type) {
425 case LS_OPAQUE_TE_TLV_LINK:
426 while (tlv_length > 0) {
427 if (!TTEST2(*tptr, 4))
428 goto trunc;
429 subtlv_type = EXTRACT_16BITS(tptr);
430 subtlv_length = EXTRACT_16BITS(tptr+2);
431 tlv_length-=4;
432 tptr+=4;
433
434 printf("\n\t %s subTLV (%u), length: %u",
435 tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
436 subtlv_type,
437 subtlv_length);
438
439 if (!TTEST2(*tptr, subtlv_length))
440 goto trunc;
441 switch(subtlv_type) {
442 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
443 printf(", 0x%08x", EXTRACT_32BITS(tptr));
444 break;
445 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
446 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
447 printf(", %s (0x%08x)",
448 ipaddr_string(tptr),
449 EXTRACT_32BITS(tptr));
450 if (subtlv_length == 8) /* draft-ietf-ccamp-ospf-gmpls-extensions */
451 printf(", 0x%08x", EXTRACT_32BITS(tptr+4));
452 break;
453 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
454 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
455 printf(", %s", ipaddr_string(tptr));
456 break;
457 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
458 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
459 bw.i = EXTRACT_32BITS(tptr);
460 printf(", %.3f Mbps", bw.f*8/1000000 );
461 break;
462 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
463 for (priority_level = 0; priority_level < 8; priority_level++) {
464 bw.i = EXTRACT_32BITS(tptr+priority_level*4);
465 printf("\n\t\tpriority level %d: %.3f Mbps",
466 priority_level,
467 bw.f*8/1000000 );
468 }
469 break;
470 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
471 printf(", Metric %u", EXTRACT_32BITS(tptr));
472 break;
473 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
474 printf(", %s, Priority %u",
475 bittok2str(gmpls_link_prot_values, "none", *tptr),
476 *(tptr+1));
477 break;
478 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
479 printf("\n\t\tInterface Switching Capability: %s",
480 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
481 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
482 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
483 for (priority_level = 0; priority_level < 8; priority_level++) {
484 bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
485 printf("\n\t\t priority level %d: %.3f Mbps",
486 priority_level,
487 bw.f*8/1000000 );
488 }
489 break;
490 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
491 printf(", %s (%u)",
492 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
493 *tptr);
494 break;
495
496 /*
497 * FIXME those are the defined subTLVs that lack a decoder
498 * you are welcome to contribute code ;-)
499 */
500 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
501
502 default:
503 if (vflag <= 1) {
504 if(!print_unknown_data(tptr,"\n\t\t",subtlv_length))
505 return(0);
506 }
507 break;
508 }
509 /* in OSPF everything has to be 32-bit aligned, including TLVs */
510 if (subtlv_length%4 != 0)
511 subtlv_length+=4-(subtlv_length%4);
512
513 tlv_length-=subtlv_length;
514 tptr+=subtlv_length;
515
516 }
517 break;
518
519 case LS_OPAQUE_TE_TLV_ROUTER:
520 printf(", %s", ipaddr_string(tptr));
521 break;
522
523 default:
524 if (vflag <= 1) {
525 if(!print_unknown_data(tptr,"\n\t ",tlv_length))
526 return(0);
527 }
528 break;
529 }
530 tptr+=tlv_length;
531 }
532 break;
533 }
534 break;
535 default:
536 if (vflag <= 1) {
537 if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown,
538 "\n\t ", EXTRACT_16BITS(&lsap->ls_hdr.ls_length)-sizeof(struct lsa_hdr)))
539 return(0);
540 }
541 break;
542 }
543
544 /* do we want to see an additionally hexdump ? */
545 if (vflag> 1)
546 if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown,
547 "\n\t ", EXTRACT_16BITS(&lsap->ls_hdr.ls_length)-sizeof(struct lsa_hdr))) {
548 return(0);
549 }
550
551 return (0);
552 trunc:
553 return (1);
554 }
555
556 static int
557 ospf_decode_v2(register const struct ospfhdr *op,
558 register const u_char *dataend)
559 {
560 register const struct in_addr *ap;
561 register const struct lsr *lsrp;
562 register const struct lsa_hdr *lshp;
563 register const struct lsa *lsap;
564 register u_int32_t lsa_count,lsa_count_max;
565
566 switch (op->ospf_type) {
567
568 case OSPF_TYPE_UMD:
569 /*
570 * Rob Coltun's special monitoring packets;
571 * do nothing
572 */
573 break;
574
575 case OSPF_TYPE_HELLO:
576 TCHECK(op->ospf_hello.hello_deadint);
577 printf("\n\t Hello Timer: %us, Dead Timer %us, mask: %s, Priority: %u",
578 EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
579 EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
580 ipaddr_string(&op->ospf_hello.hello_mask),
581 op->ospf_hello.hello_priority);
582
583 printf("\n\t Options: %s",
584 bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options));
585
586 TCHECK(op->ospf_hello.hello_dr);
587 if (op->ospf_hello.hello_dr.s_addr != 0)
588 printf("\n\t Designated Router %s",
589 ipaddr_string(&op->ospf_hello.hello_dr));
590
591 TCHECK(op->ospf_hello.hello_bdr);
592 if (op->ospf_hello.hello_bdr.s_addr != 0)
593 printf(", Backup Designated Router %s",
594 ipaddr_string(&op->ospf_hello.hello_bdr));
595
596 ap = op->ospf_hello.hello_neighbor;
597 if ((u_char *)ap < dataend)
598 printf("\n\t Neighbor List:");
599 while ((u_char *)ap < dataend) {
600 TCHECK(*ap);
601 printf("\n\t %s", ipaddr_string(ap));
602 ++ap;
603 }
604 break; /* HELLO */
605
606 case OSPF_TYPE_DD:
607 TCHECK(op->ospf_db.db_options);
608 printf("\n\t Options: %s",
609 bittok2str(ospf_option_values,"none",op->ospf_db.db_options));
610 TCHECK(op->ospf_db.db_flags);
611 printf("\n\t DD Flags: %s",
612 bittok2str(ospf_dd_flag_values,"none",op->ospf_db.db_flags));
613
614 if (vflag) {
615 /* Print all the LS adv's */
616 lshp = op->ospf_db.db_lshdr;
617 while (!ospf_print_lshdr(lshp)) {
618 ++lshp;
619 }
620 }
621 break;
622
623 case OSPF_TYPE_LS_REQ:
624 lsrp = op->ospf_lsr;
625 while ((u_char *)lsrp < dataend) {
626 TCHECK(*lsrp);
627
628 printf("\n\t %s LSA (%d), LSA-ID: %s, Advertising Router: %s",
629 tok2str(lsa_values,"unknown",lsrp->ls_type),
630 lsrp->ls_type,
631 ipaddr_string(&lsrp->ls_stateid),
632 ipaddr_string(&lsrp->ls_router));
633 ++lsrp;
634 }
635 break;
636
637 case OSPF_TYPE_LS_UPDATE:
638 lsap = op->ospf_lsu.lsu_lsa;
639 TCHECK(op->ospf_lsu.lsu_count);
640 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
641 printf(", %d LSA%s",lsa_count_max, lsa_count_max > 1 ? "s" : "");
642 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
643 printf("\n\t LSA #%u",lsa_count);
644 if (ospf_print_lsa(lsap))
645 goto trunc;
646 lsap = (struct lsa *)((u_char *)lsap +
647 EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
648 }
649 break;
650
651 case OSPF_TYPE_LS_ACK:
652 lshp = op->ospf_lsa.lsa_lshdr;
653 while (!ospf_print_lshdr(lshp)) {
654 ++lshp;
655 }
656 break;
657
658 default:
659 printf("v2 type (%d)", op->ospf_type);
660 break;
661 }
662 return (0);
663 trunc:
664 return (1);
665 }
666
667 void
668 ospf_print(register const u_char *bp, register u_int length,
669 register const u_char *bp2)
670 {
671 register const struct ospfhdr *op;
672 register const struct ip *ip;
673 register const u_char *dataend;
674 register const char *cp;
675
676 op = (struct ospfhdr *)bp;
677 ip = (struct ip *)bp2;
678
679 /* XXX Before we do anything else, strip off the MD5 trailer */
680 TCHECK(op->ospf_authtype);
681 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
682 length -= OSPF_AUTH_MD5_LEN;
683 snapend -= OSPF_AUTH_MD5_LEN;
684 }
685
686 /* If the type is valid translate it, or just print the type */
687 /* value. If it's not valid, say so and return */
688 TCHECK(op->ospf_type);
689 cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
690 printf("OSPFv%u, %s (%u), length: %u",
691 op->ospf_version,
692 cp,
693 op->ospf_type,
694 length);
695 if (*cp == 'u')
696 return;
697
698 if(!vflag) /* non verbose - so lets bail out here */
699 return;
700
701 TCHECK(op->ospf_len);
702 if (length != EXTRACT_16BITS(&op->ospf_len)) {
703 printf(" [len %d]", EXTRACT_16BITS(&op->ospf_len));
704 return;
705 }
706 dataend = bp + length;
707
708 TCHECK(op->ospf_routerid);
709 printf("\n\tRouter-ID: %s", ipaddr_string(&op->ospf_routerid));
710
711 TCHECK(op->ospf_areaid);
712 if (op->ospf_areaid.s_addr != 0)
713 printf(", Area %s", ipaddr_string(&op->ospf_areaid));
714 else
715 printf(", Backbone Area");
716
717 if (vflag) {
718 /* Print authentication data (should we really do this?) */
719 TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
720
721 printf(", Authentication Type: %s (%u)",
722 tok2str(ospf_authtype_values,"unknown",EXTRACT_16BITS(&op->ospf_authtype)),
723 EXTRACT_16BITS(&op->ospf_authtype));
724
725 switch (EXTRACT_16BITS(&op->ospf_authtype)) {
726
727 case OSPF_AUTH_NONE:
728 break;
729
730 case OSPF_AUTH_SIMPLE:
731 (void)fn_printn(op->ospf_authdata,
732 sizeof(op->ospf_authdata), NULL);
733 printf("\"");
734 break;
735
736 case OSPF_AUTH_MD5:
737 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
738 *((op->ospf_authdata)+2),
739 *((op->ospf_authdata)+3),
740 EXTRACT_32BITS((op->ospf_authdata)+4));
741 break;
742
743 default:
744 return;
745 }
746 }
747 /* Do rest according to version. */
748 switch (op->ospf_version) {
749
750 case 2:
751 /* ospf version 2 */
752 if (ospf_decode_v2(op, dataend))
753 goto trunc;
754 break;
755
756 default:
757 printf(" ospf [version %d]", op->ospf_version);
758 break;
759 } /* end switch on version */
760
761 return;
762 trunc:
763 fputs(tstr, stdout);
764 }