]> The Tcpdump Group git mirrors - tcpdump/blob - print-ospf.c
9eeadfc5fb2a5fb5f8d5f6eeb491711d5fbbcaeb
[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.44 2003-10-22 17:08: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 Advertising Router: %s, seq 0x%08x, age %us, length: %u",
158 ipaddr_string(&lshp->ls_router),
159 EXTRACT_32BITS(&lshp->ls_seq),
160 EXTRACT_16BITS(&lshp->ls_age),
161 EXTRACT_16BITS(&lshp->ls_length)-sizeof(struct lsa_hdr));
162
163 switch (lshp->ls_type) {
164 /* the LSA header for opaque LSAs was slightly changed */
165 case LS_TYPE_OPAQUE_LL:
166 case LS_TYPE_OPAQUE_AL:
167 case LS_TYPE_OPAQUE_DW:
168 printf("\n\t %s LSA (%d), Opaque-Type: %s LSA (%u), Opaque-ID: %u",
169 tok2str(lsa_values,"unknown",lshp->ls_type),
170 lshp->ls_type,
171
172 tok2str(lsa_opaque_values,
173 "unknown",
174 *(&lshp->un_lsa_id.opaque_field.opaque_type)),
175 *(&lshp->un_lsa_id.opaque_field.opaque_type),
176 EXTRACT_24BITS(&lshp->un_lsa_id.opaque_field.opaque_id)
177
178 );
179 break;
180
181 /* all other LSA types use regular style LSA headers */
182 default:
183 printf("\n\t %s LSA (%d), LSA-ID: %s",
184 tok2str(lsa_values,"unknown",lshp->ls_type),
185 lshp->ls_type,
186 ipaddr_string(&lshp->un_lsa_id.lsa_id));
187 break;
188 }
189
190 printf("\n\t Options: [%s]", bittok2str(ospf_option_values,"none",lshp->ls_options));
191
192 return (0);
193 trunc:
194 return (1);
195 }
196
197 /*
198 * Print a single link state advertisement. If truncated return 1, else 0.
199 */
200 static int
201 ospf_print_lsa(register const struct lsa *lsap)
202 {
203 register const u_char *ls_end;
204 register const struct rlalink *rlp;
205 register const struct tos_metric *tosp;
206 register const struct in_addr *ap;
207 register const struct aslametric *almp;
208 register const struct mcla *mcp;
209 register const u_int32_t *lp;
210 register int j, k,ls_length, tlv_type, tlv_length, subtlv_type, subtlv_length, priority_level;
211 const u_int8_t *tptr;
212 int count_srlg;
213 union { /* int to float conversion buffer for several subTLVs */
214 float f;
215 u_int32_t i;
216 } bw;
217
218 tptr = (u_int8_t *)lsap->lsa_un.un_unknown; /* squelch compiler warnings */
219 ls_length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length)-sizeof(struct lsa_hdr);
220
221 ospf_print_lshdr(&lsap->ls_hdr);
222
223 TCHECK(lsap->ls_hdr.ls_length);
224 ls_end = (u_char *)lsap + EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
225
226 switch (lsap->ls_hdr.ls_type) {
227
228 case LS_TYPE_ROUTER:
229 TCHECK(lsap->lsa_un.un_rla.rla_flags);
230 printf("\n\t Router LSA Options: [%s]", bittok2str(ospf_rla_flag_values,"none",lsap->lsa_un.un_rla.rla_flags));
231
232 TCHECK(lsap->lsa_un.un_rla.rla_count);
233 j = EXTRACT_16BITS(&lsap->lsa_un.un_rla.rla_count);
234 TCHECK(lsap->lsa_un.un_rla.rla_link);
235 rlp = lsap->lsa_un.un_rla.rla_link;
236 while (j--) {
237 TCHECK(*rlp);
238 switch (rlp->link_type) {
239
240 case RLA_TYPE_VIRTUAL:
241 printf("\n\t Virtual Link: Neighbor Router-ID: %s, Interface Address: %s",
242 ipaddr_string(&rlp->link_id),
243 ipaddr_string(&rlp->link_data));
244 break;
245
246 case RLA_TYPE_ROUTER:
247 printf("\n\t Neighbor Router-ID: %s, Interface Address: %s",
248 ipaddr_string(&rlp->link_id),
249 ipaddr_string(&rlp->link_data));
250 break;
251
252 case RLA_TYPE_TRANSIT:
253 printf("\n\t Neighbor Network-ID: %s, Interface Address: %s",
254 ipaddr_string(&rlp->link_id),
255 ipaddr_string(&rlp->link_data));
256 break;
257
258 case RLA_TYPE_STUB:
259 printf("\n\t Stub Network: %s, Mask: %s",
260 ipaddr_string(&rlp->link_id),
261 ipaddr_string(&rlp->link_data));
262 break;
263
264 default:
265 printf("\n\t Unknown Router Link Type (%u)",
266 rlp->link_type);
267 return (0);
268 }
269 printf(", tos 0, metric: %d", EXTRACT_16BITS(&rlp->link_tos0metric));
270 tosp = (struct tos_metric *)
271 ((sizeof rlp->link_tos0metric) + (u_char *) rlp);
272 for (k = 0; k < (int) rlp->link_toscount; ++k, ++tosp) {
273 TCHECK(*tosp);
274 printf(", tos %d, metric: %d",
275 tosp->tos_type,
276 EXTRACT_16BITS(&tosp->tos_metric));
277 }
278 rlp = (struct rlalink *)((u_char *)(rlp + 1) +
279 ((rlp->link_toscount) * sizeof(*tosp)));
280 }
281 break;
282
283 case LS_TYPE_NETWORK:
284 TCHECK(lsap->lsa_un.un_nla.nla_mask);
285 printf("\n\t Mask %s\n\t Connected Routers:",
286 ipaddr_string(&lsap->lsa_un.un_nla.nla_mask));
287 ap = lsap->lsa_un.un_nla.nla_router;
288 while ((u_char *)ap < ls_end) {
289 TCHECK(*ap);
290 printf("\n\t %s", ipaddr_string(ap));
291 ++ap;
292 }
293 break;
294
295 case LS_TYPE_SUM_IP:
296 TCHECK(lsap->lsa_un.un_nla.nla_mask);
297 printf("\n\t Mask %s",
298 ipaddr_string(&lsap->lsa_un.un_sla.sla_mask));
299 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
300 lp = lsap->lsa_un.un_sla.sla_tosmetric;
301 /* suppress tos if its not supported */
302 if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) {
303 printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC);
304 break;
305 }
306 while ((u_char *)lp < ls_end) {
307 register u_int32_t ul;
308
309 TCHECK(*lp);
310 ul = EXTRACT_32BITS(lp);
311 printf(", tos %d metric %d",
312 (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
313 ul & SLA_MASK_METRIC);
314 ++lp;
315 }
316 break;
317
318 case LS_TYPE_SUM_ABR:
319 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
320 lp = lsap->lsa_un.un_sla.sla_tosmetric;
321 /* suppress tos if its not supported */
322 if(!((lsap->ls_hdr.ls_options)&OSPF_OPTION_T)) {
323 printf(", metric: %u", EXTRACT_32BITS(lp)&SLA_MASK_METRIC);
324 break;
325 }
326 while ((u_char *)lp < ls_end) {
327 register u_int32_t ul;
328
329 TCHECK(*lp);
330 ul = EXTRACT_32BITS(lp);
331 printf(", tos %d metric %d",
332 (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS,
333 ul & SLA_MASK_METRIC);
334 ++lp;
335 }
336 break;
337
338 case LS_TYPE_ASE:
339 TCHECK(lsap->lsa_un.un_nla.nla_mask);
340 printf("\n\t Mask %s",
341 ipaddr_string(&lsap->lsa_un.un_asla.asla_mask));
342
343 TCHECK(lsap->lsa_un.un_sla.sla_tosmetric);
344 almp = lsap->lsa_un.un_asla.asla_metric;
345 while ((u_char *)almp < ls_end) {
346 register u_int32_t ul;
347
348 TCHECK(almp->asla_tosmetric);
349 ul = EXTRACT_32BITS(&almp->asla_tosmetric);
350 printf(", type %d, tos %d metric:",
351 (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1,
352 (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS);
353 if ((ul & ASLA_MASK_METRIC)==0xffffff)
354 printf(" infinite");
355 else
356 printf(" %d", (ul & ASLA_MASK_METRIC));
357
358 TCHECK(almp->asla_forward);
359 if (almp->asla_forward.s_addr) {
360 printf(", forward %s",
361 ipaddr_string(&almp->asla_forward));
362 }
363 TCHECK(almp->asla_tag);
364 if (almp->asla_tag.s_addr) {
365 printf(", tag %s",
366 ipaddr_string(&almp->asla_tag));
367 }
368 ++almp;
369 }
370 break;
371
372 case LS_TYPE_GROUP:
373 /* Multicast extensions as of 23 July 1991 */
374 mcp = lsap->lsa_un.un_mcla;
375 while ((u_char *)mcp < ls_end) {
376 TCHECK(mcp->mcla_vid);
377 switch (EXTRACT_32BITS(&mcp->mcla_vtype)) {
378
379 case MCLA_VERTEX_ROUTER:
380 printf("\n\t Router Router-ID %s",
381 ipaddr_string(&mcp->mcla_vid));
382 break;
383
384 case MCLA_VERTEX_NETWORK:
385 printf("\n\t Network Designated Router %s",
386 ipaddr_string(&mcp->mcla_vid));
387 break;
388
389 default:
390 printf("\n\t unknown VertexType (%u)",
391 EXTRACT_32BITS(&mcp->mcla_vtype));
392 break;
393 }
394 ++mcp;
395 }
396 break;
397
398 case LS_TYPE_OPAQUE_LL: /* fall through */
399 case LS_TYPE_OPAQUE_AL:
400 case LS_TYPE_OPAQUE_DW:
401
402 switch (*(&lsap->ls_hdr.un_lsa_id.opaque_field.opaque_type)) {
403 case LS_OPAQUE_TYPE_TE:
404 if (!TTEST2(*tptr, 4))
405 goto trunc;
406
407 tptr = (u_int8_t *)(&lsap->lsa_un.un_te_lsa_tlv.type);
408
409 while (ls_length > 0) {
410 tlv_type = EXTRACT_16BITS(tptr);
411 tlv_length = EXTRACT_16BITS(tptr+2);
412 ls_length-=(tlv_length+4);
413 tptr+=4;
414
415 printf("\n\t %s TLV (%u), length: %u",
416 tok2str(lsa_opaque_te_tlv_values,"unknown",tlv_type),
417 tlv_type,
418 tlv_length);
419
420 switch(tlv_type) {
421 case LS_OPAQUE_TE_TLV_LINK:
422 while (tlv_length > 0) {
423 if (!TTEST2(*tptr, 4))
424 goto trunc;
425 subtlv_type = EXTRACT_16BITS(tptr);
426 subtlv_length = EXTRACT_16BITS(tptr+2);
427 tlv_length-=4;
428 tptr+=4;
429
430 printf("\n\t %s subTLV (%u), length: %u",
431 tok2str(lsa_opaque_te_link_tlv_subtlv_values,"unknown",subtlv_type),
432 subtlv_type,
433 subtlv_length);
434
435 if (!TTEST2(*tptr, subtlv_length))
436 goto trunc;
437 switch(subtlv_type) {
438 case LS_OPAQUE_TE_LINK_SUBTLV_ADMIN_GROUP:
439 printf(", 0x%08x", EXTRACT_32BITS(tptr));
440 break;
441 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_ID:
442 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_LOCAL_REMOTE_ID:
443 printf(", %s (0x%08x)",
444 ipaddr_string(tptr),
445 EXTRACT_32BITS(tptr));
446 if (subtlv_length == 8) /* draft-ietf-ccamp-ospf-gmpls-extensions */
447 printf(", %s (0x%08x)",
448 ipaddr_string(tptr+4),
449 EXTRACT_32BITS(tptr+4));
450 break;
451 case LS_OPAQUE_TE_LINK_SUBTLV_LOCAL_IP:
452 case LS_OPAQUE_TE_LINK_SUBTLV_REMOTE_IP:
453 printf(", %s", ipaddr_string(tptr));
454 break;
455 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_BW:
456 case LS_OPAQUE_TE_LINK_SUBTLV_MAX_RES_BW:
457 bw.i = EXTRACT_32BITS(tptr);
458 printf(", %.3f Mbps", bw.f*8/1000000 );
459 break;
460 case LS_OPAQUE_TE_LINK_SUBTLV_UNRES_BW:
461 for (priority_level = 0; priority_level < 8; priority_level++) {
462 bw.i = EXTRACT_32BITS(tptr+priority_level*4);
463 printf("\n\t\tpriority level %d: %.3f Mbps",
464 priority_level,
465 bw.f*8/1000000 );
466 }
467 break;
468 case LS_OPAQUE_TE_LINK_SUBTLV_TE_METRIC:
469 printf(", Metric %u", EXTRACT_32BITS(tptr));
470 break;
471 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_PROTECTION_TYPE:
472 printf(", %s, Priority %u",
473 bittok2str(gmpls_link_prot_values, "none", *tptr),
474 *(tptr+1));
475 break;
476 case LS_OPAQUE_TE_LINK_SUBTLV_INTF_SW_CAP_DESCR:
477 printf("\n\t\tInterface Switching Capability: %s",
478 tok2str(gmpls_switch_cap_values, "Unknown", *(tptr)));
479 printf("\n\t\tLSP Encoding: %s\n\t\tMax LSP Bandwidth:",
480 tok2str(gmpls_encoding_values, "Unknown", *(tptr+1)));
481 for (priority_level = 0; priority_level < 8; priority_level++) {
482 bw.i = EXTRACT_32BITS(tptr+4+(priority_level*4));
483 printf("\n\t\t priority level %d: %.3f Mbps",
484 priority_level,
485 bw.f*8/1000000 );
486 }
487 break;
488 case LS_OPAQUE_TE_LINK_SUBTLV_LINK_TYPE:
489 printf(", %s (%u)",
490 tok2str(lsa_opaque_te_tlv_link_type_sub_tlv_values,"unknown",*tptr),
491 *tptr);
492 break;
493
494 case LS_OPAQUE_TE_LINK_SUBTLV_SHARED_RISK_GROUP:
495 count_srlg = subtlv_length / 4;
496 if (count_srlg != 0)
497 printf("\n\t\t Shared risk group: ");
498 while (count_srlg > 0) {
499 bw.i = EXTRACT_32BITS(tptr);
500 printf("%d",bw.i);
501 tptr+=4;
502 count_srlg--;
503 if (count_srlg > 0)
504 printf(", ");
505 }
506 break;
507
508 default:
509 if (vflag <= 1) {
510 if(!print_unknown_data(tptr,"\n\t\t",subtlv_length))
511 return(0);
512 }
513 break;
514 }
515 /* in OSPF everything has to be 32-bit aligned, including TLVs */
516 if (subtlv_length%4 != 0)
517 subtlv_length+=4-(subtlv_length%4);
518
519 tlv_length-=subtlv_length;
520 tptr+=subtlv_length;
521
522 }
523 break;
524
525 case LS_OPAQUE_TE_TLV_ROUTER:
526 printf(", %s", ipaddr_string(tptr));
527 break;
528
529 default:
530 if (vflag <= 1) {
531 if(!print_unknown_data(tptr,"\n\t ",tlv_length))
532 return(0);
533 }
534 break;
535 }
536 tptr+=tlv_length;
537 }
538 break;
539 }
540 break;
541 default:
542 if (vflag <= 1) {
543 if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown,
544 "\n\t ", EXTRACT_16BITS(&lsap->ls_hdr.ls_length)-sizeof(struct lsa_hdr)))
545 return(0);
546 }
547 break;
548 }
549
550 /* do we want to see an additionally hexdump ? */
551 if (vflag> 1)
552 if(!print_unknown_data((u_int8_t *)lsap->lsa_un.un_unknown,
553 "\n\t ", EXTRACT_16BITS(&lsap->ls_hdr.ls_length)-sizeof(struct lsa_hdr))) {
554 return(0);
555 }
556
557 return (0);
558 trunc:
559 return (1);
560 }
561
562 static int
563 ospf_decode_v2(register const struct ospfhdr *op,
564 register const u_char *dataend)
565 {
566 register const struct in_addr *ap;
567 register const struct lsr *lsrp;
568 register const struct lsa_hdr *lshp;
569 register const struct lsa *lsap;
570 register u_int32_t lsa_count,lsa_count_max;
571
572 switch (op->ospf_type) {
573
574 case OSPF_TYPE_UMD:
575 /*
576 * Rob Coltun's special monitoring packets;
577 * do nothing
578 */
579 break;
580
581 case OSPF_TYPE_HELLO:
582 printf("\n\tOptions: [%s]",
583 bittok2str(ospf_option_values,"none",op->ospf_hello.hello_options));
584
585 TCHECK(op->ospf_hello.hello_deadint);
586 printf("\n\t Hello Timer: %us, Dead Timer %us, Mask: %s, Priority: %u",
587 EXTRACT_16BITS(&op->ospf_hello.hello_helloint),
588 EXTRACT_32BITS(&op->ospf_hello.hello_deadint),
589 ipaddr_string(&op->ospf_hello.hello_mask),
590 op->ospf_hello.hello_priority);
591
592 TCHECK(op->ospf_hello.hello_dr);
593 if (op->ospf_hello.hello_dr.s_addr != 0)
594 printf("\n\t Designated Router %s",
595 ipaddr_string(&op->ospf_hello.hello_dr));
596
597 TCHECK(op->ospf_hello.hello_bdr);
598 if (op->ospf_hello.hello_bdr.s_addr != 0)
599 printf(", Backup Designated Router %s",
600 ipaddr_string(&op->ospf_hello.hello_bdr));
601
602 ap = op->ospf_hello.hello_neighbor;
603 if ((u_char *)ap < dataend)
604 printf("\n\t Neighbor List:");
605 while ((u_char *)ap < dataend) {
606 TCHECK(*ap);
607 printf("\n\t %s", ipaddr_string(ap));
608 ++ap;
609 }
610 break; /* HELLO */
611
612 case OSPF_TYPE_DD:
613 TCHECK(op->ospf_db.db_options);
614 printf("\n\tOptions: [%s]",
615 bittok2str(ospf_option_values,"none",op->ospf_db.db_options));
616 TCHECK(op->ospf_db.db_flags);
617 printf(", DD Flags: [%s]",
618 bittok2str(ospf_dd_flag_values,"none",op->ospf_db.db_flags));
619
620 if (vflag) {
621 /* Print all the LS adv's */
622 lshp = op->ospf_db.db_lshdr;
623 while (!ospf_print_lshdr(lshp)) {
624 ++lshp;
625 }
626 }
627 break;
628
629 case OSPF_TYPE_LS_REQ:
630 lsrp = op->ospf_lsr;
631 while ((u_char *)lsrp < dataend) {
632 TCHECK(*lsrp);
633
634 printf("\n\t Advertising Router: %s, %s LSA (%u)",
635 ipaddr_string(&lsrp->ls_router),
636 tok2str(lsa_values,"unknown",EXTRACT_32BITS(lsrp->ls_type)),
637 EXTRACT_32BITS(&lsrp->ls_type));
638
639 switch (EXTRACT_32BITS(lsrp->ls_type)) {
640 /* the LSA header for opaque LSAs was slightly changed */
641 case LS_TYPE_OPAQUE_LL:
642 case LS_TYPE_OPAQUE_AL:
643 case LS_TYPE_OPAQUE_DW:
644 printf(", Opaque-Type: %s LSA (%u), Opaque-ID: %u",
645 tok2str(lsa_opaque_values, "unknown",lsrp->un_ls_stateid.opaque_field.opaque_type),
646 lsrp->un_ls_stateid.opaque_field.opaque_type,
647 EXTRACT_24BITS(&lsrp->un_ls_stateid.opaque_field.opaque_id));
648 break;
649 default:
650 printf(", LSA-ID: %s",
651 ipaddr_string(&lsrp->un_ls_stateid.ls_stateid));
652 break;
653 }
654
655 ++lsrp;
656 }
657 break;
658
659 case OSPF_TYPE_LS_UPDATE:
660 lsap = op->ospf_lsu.lsu_lsa;
661 TCHECK(op->ospf_lsu.lsu_count);
662 lsa_count_max = EXTRACT_32BITS(&op->ospf_lsu.lsu_count);
663 printf(", %d LSA%s",lsa_count_max, lsa_count_max > 1 ? "s" : "");
664 for (lsa_count=1;lsa_count <= lsa_count_max;lsa_count++) {
665 printf("\n\t LSA #%u",lsa_count);
666 if (ospf_print_lsa(lsap))
667 goto trunc;
668 lsap = (struct lsa *)((u_char *)lsap +
669 EXTRACT_16BITS(&lsap->ls_hdr.ls_length));
670 }
671 break;
672
673 case OSPF_TYPE_LS_ACK:
674 lshp = op->ospf_lsa.lsa_lshdr;
675 while (!ospf_print_lshdr(lshp)) {
676 ++lshp;
677 }
678 break;
679
680 default:
681 printf("v2 type (%d)", op->ospf_type);
682 break;
683 }
684 return (0);
685 trunc:
686 return (1);
687 }
688
689 void
690 ospf_print(register const u_char *bp, register u_int length,
691 register const u_char *bp2)
692 {
693 register const struct ospfhdr *op;
694 register const struct ip *ip;
695 register const u_char *dataend;
696 register const char *cp;
697
698 op = (struct ospfhdr *)bp;
699 ip = (struct ip *)bp2;
700
701 /* XXX Before we do anything else, strip off the MD5 trailer */
702 TCHECK(op->ospf_authtype);
703 if (EXTRACT_16BITS(&op->ospf_authtype) == OSPF_AUTH_MD5) {
704 length -= OSPF_AUTH_MD5_LEN;
705 snapend -= OSPF_AUTH_MD5_LEN;
706 }
707
708 /* If the type is valid translate it, or just print the type */
709 /* value. If it's not valid, say so and return */
710 TCHECK(op->ospf_type);
711 cp = tok2str(type2str, "unknown LS-type", op->ospf_type);
712 printf("OSPFv%u, %s (%u), length: %u",
713 op->ospf_version,
714 cp,
715 op->ospf_type,
716 length);
717 if (*cp == 'u')
718 return;
719
720 if(!vflag) /* non verbose - so lets bail out here */
721 return;
722
723 TCHECK(op->ospf_len);
724 if (length != EXTRACT_16BITS(&op->ospf_len)) {
725 printf(" [len %d]", EXTRACT_16BITS(&op->ospf_len));
726 return;
727 }
728 dataend = bp + length;
729
730 TCHECK(op->ospf_routerid);
731 printf("\n\tRouter-ID: %s", ipaddr_string(&op->ospf_routerid));
732
733 TCHECK(op->ospf_areaid);
734 if (op->ospf_areaid.s_addr != 0)
735 printf(", Area %s", ipaddr_string(&op->ospf_areaid));
736 else
737 printf(", Backbone Area");
738
739 if (vflag) {
740 /* Print authentication data (should we really do this?) */
741 TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata));
742
743 printf(", Authentication Type: %s (%u)",
744 tok2str(ospf_authtype_values,"unknown",EXTRACT_16BITS(&op->ospf_authtype)),
745 EXTRACT_16BITS(&op->ospf_authtype));
746
747 switch (EXTRACT_16BITS(&op->ospf_authtype)) {
748
749 case OSPF_AUTH_NONE:
750 break;
751
752 case OSPF_AUTH_SIMPLE:
753 (void)fn_printn(op->ospf_authdata,
754 sizeof(op->ospf_authdata), NULL);
755 printf("\"");
756 break;
757
758 case OSPF_AUTH_MD5:
759 printf("\n\tKey-ID: %u, Auth-Length: %u, Crypto Sequence Number: 0x%08x",
760 *((op->ospf_authdata)+2),
761 *((op->ospf_authdata)+3),
762 EXTRACT_32BITS((op->ospf_authdata)+4));
763 break;
764
765 default:
766 return;
767 }
768 }
769 /* Do rest according to version. */
770 switch (op->ospf_version) {
771
772 case 2:
773 /* ospf version 2 */
774 if (ospf_decode_v2(op, dataend))
775 goto trunc;
776 break;
777
778 default:
779 printf(" ospf [version %d]", op->ospf_version);
780 break;
781 } /* end switch on version */
782
783 return;
784 trunc:
785 fputs(tstr, stdout);
786 }