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