]> The Tcpdump Group git mirrors - tcpdump/blob - print-bfd.c
add tracefiles for infinite loop testing
[tcpdump] / print-bfd.c
1 /*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
12 *
13 * Original code by Hannes Gredler (hannes@juniper.net)
14 */
15
16 #ifndef lint
17 static const char rcsid[] _U_ =
18 "@(#) $Header: /tcpdump/master/tcpdump/print-bfd.c,v 1.3.2.2 2003-11-16 08:51:12 guy Exp $";
19 #endif
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <tcpdump-stdinc.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "interface.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33
34 #include "udp.h"
35
36 /*
37 * Control packet, draft-katz-ward-bfd-01.txt
38 *
39 * 0 1 2 3
40 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | My Discriminator |
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Your Discriminator |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Desired Min TX Interval |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | Required Min RX Interval |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * | Required Min Echo RX Interval |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 */
55
56 struct bfd_header_t {
57 u_int8_t version_diag;
58 u_int8_t flags;
59 u_int8_t detect_time_multiplier;
60 u_int8_t length;
61 u_int8_t my_discriminator[4];
62 u_int8_t your_discriminator[4];
63 u_int8_t desired_min_tx_interval[4];
64 u_int8_t required_min_rx_interval[4];
65 u_int8_t required_min_echo_interval[4];
66 };
67
68 #define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
69 #define BFD_EXTRACT_DIAG(x) ((x)&0x1f)
70
71 static const struct tok bfd_port_values[] = {
72 { BFD_CONTROL_PORT, "Control" },
73 { BFD_ECHO_PORT, "Echo" },
74 { 0, NULL }
75 };
76
77
78 static const struct tok bfd_diag_values[] = {
79 { 0, "No Diagnostic" },
80 { 1, "Control Detection Time Expired" },
81 { 2, "Echo Function Failed" },
82 { 3, "Neighbor Signaled Session Down" },
83 { 4, "Forwarding Plane Reset" },
84 { 5, "Path Down" },
85 { 6, "Concatenated Path Down" },
86 { 7, "Administratively Down" },
87 { 0, NULL }
88 };
89
90 static const struct tok bfd_flag_values[] = {
91 { 0x80, "I Hear You" },
92 { 0x40, "Demand" },
93 { 0x20, "Poll" },
94 { 0x10, "Final" },
95 { 0x08, "Reserved" },
96 { 0x04, "Reserved" },
97 { 0x02, "Reserved" },
98 { 0x01, "Reserved" },
99 { 0, NULL }
100 };
101
102 void
103 bfd_print(register const u_char *pptr, register u_int len, register u_int port)
104 {
105 const struct bfd_header_t *bfd_header;
106
107 bfd_header = (const struct bfd_header_t *)pptr;
108 TCHECK(*bfd_header);
109
110 switch (port) {
111
112 case BFD_CONTROL_PORT:
113 if (vflag < 1 )
114 {
115 printf("BFDv%u, %s, Flags: [%s], length: %u",
116 BFD_EXTRACT_VERSION(bfd_header->version_diag),
117 tok2str(bfd_port_values, "unknown (%u)", port),
118 bittok2str(bfd_flag_values, "none", bfd_header->flags),
119 len);
120 return;
121 }
122
123 printf("BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)",
124 BFD_EXTRACT_VERSION(bfd_header->version_diag),
125 len,
126 tok2str(bfd_port_values, "unknown (%u)", port),
127 bittok2str(bfd_flag_values, "none", bfd_header->flags),
128 tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
129 BFD_EXTRACT_DIAG(bfd_header->version_diag));
130
131 printf("\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
132 bfd_header->detect_time_multiplier,
133 bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
134 bfd_header->length);
135
136
137 printf("\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator));
138 printf(", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator));
139 printf("\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000);
140 printf("\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000);
141 printf("\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000);
142 break;
143
144 case BFD_ECHO_PORT: /* not yet supported - fall through */
145
146 default:
147 printf("BFD, %s, length: %u",
148 tok2str(bfd_port_values, "unknown (%u)", port),
149 len);
150 if (vflag >= 1) {
151 if(!print_unknown_data(pptr,"\n\t",len))
152 return;
153 }
154 break;
155 }
156 return;
157
158 trunc:
159 printf("[|BFD]");
160 }