]> The Tcpdump Group git mirrors - tcpdump/blob - print-bfd.c
Merge branch 'master' of git+ssh://bpf.tcpdump.org/tcpdump/master/git/tcpdump
[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 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19
20 #include <tcpdump-stdinc.h>
21
22 #include "interface.h"
23 #include "extract.h"
24
25 #include "udp.h"
26
27 /*
28 * Control packet, BFDv0, draft-katz-ward-bfd-01.txt
29 *
30 * 0 1 2 3
31 * 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
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * |Vers | Diag |H|D|P|F| Rsvd | Detect Mult | Length |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | My Discriminator |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Your Discriminator |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | Desired Min TX Interval |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Required Min RX Interval |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | Required Min Echo RX Interval |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 */
46
47 /*
48 * Control packet, BFDv1, draft-ietf-bfd-base-02.txt
49 *
50 * 0 1 2 3
51 * 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
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * |Vers | Diag |Sta|P|F|C|A|D|R| Detect Mult | Length |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * | My Discriminator |
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * | Your Discriminator |
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 * | Desired Min TX Interval |
60 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 * | Required Min RX Interval |
62 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63 * | Required Min Echo RX Interval |
64 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 */
66
67 struct bfd_header_t {
68 uint8_t version_diag;
69 uint8_t flags;
70 uint8_t detect_time_multiplier;
71 uint8_t length;
72 uint8_t my_discriminator[4];
73 uint8_t your_discriminator[4];
74 uint8_t desired_min_tx_interval[4];
75 uint8_t required_min_rx_interval[4];
76 uint8_t required_min_echo_interval[4];
77 };
78
79 /*
80 * An optional Authentication Header may be present
81 *
82 * 0 1 2 3
83 * 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
84 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 * | Auth Type | Auth Len | Authentication Data... |
86 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87 */
88
89 struct bfd_auth_header_t {
90 uint8_t auth_type;
91 uint8_t auth_len;
92 uint8_t auth_data;
93 };
94
95 static const struct tok bfd_v1_authentication_values[] = {
96 { 0, "Reserved" },
97 { 1, "Simple Password" },
98 { 2, "Keyed MD5" },
99 { 3, "Meticulous Keyed MD5" },
100 { 4, "Keyed SHA1" },
101 { 5, "Meticulous Keyed SHA1" },
102 { 0, NULL }
103 };
104
105 #define BFD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
106 #define BFD_EXTRACT_DIAG(x) ((x)&0x1f)
107
108 static const struct tok bfd_port_values[] = {
109 { BFD_CONTROL_PORT, "Control" },
110 { BFD_ECHO_PORT, "Echo" },
111 { 0, NULL }
112 };
113
114
115 static const struct tok bfd_diag_values[] = {
116 { 0, "No Diagnostic" },
117 { 1, "Control Detection Time Expired" },
118 { 2, "Echo Function Failed" },
119 { 3, "Neighbor Signaled Session Down" },
120 { 4, "Forwarding Plane Reset" },
121 { 5, "Path Down" },
122 { 6, "Concatenated Path Down" },
123 { 7, "Administratively Down" },
124 { 8, "Reverse Concatenated Path Down" },
125 { 0, NULL }
126 };
127
128 static const struct tok bfd_v0_flag_values[] = {
129 { 0x80, "I Hear You" },
130 { 0x40, "Demand" },
131 { 0x20, "Poll" },
132 { 0x10, "Final" },
133 { 0x08, "Reserved" },
134 { 0x04, "Reserved" },
135 { 0x02, "Reserved" },
136 { 0x01, "Reserved" },
137 { 0, NULL }
138 };
139
140 #define BFD_FLAG_AUTH 0x04
141
142 static const struct tok bfd_v1_flag_values[] = {
143 { 0x20, "Poll" },
144 { 0x10, "Final" },
145 { 0x08, "Control Plane Independent" },
146 { BFD_FLAG_AUTH, "Authentication Present" },
147 { 0x02, "Demand" },
148 { 0x01, "Reserved" },
149 { 0, NULL }
150 };
151
152 static const struct tok bfd_v1_state_values[] = {
153 { 0, "AdminDown" },
154 { 1, "Down" },
155 { 2, "Init" },
156 { 3, "Up" },
157 { 0, NULL }
158 };
159
160 void
161 bfd_print(netdissect_options *ndo, register const u_char *pptr,
162 register u_int len, register u_int port)
163 {
164 const struct bfd_header_t *bfd_header;
165 const struct bfd_auth_header_t *bfd_auth_header;
166 uint8_t version = 0;
167
168 bfd_header = (const struct bfd_header_t *)pptr;
169 if (port == BFD_CONTROL_PORT) {
170 ND_TCHECK(*bfd_header);
171 version = BFD_EXTRACT_VERSION(bfd_header->version_diag);
172 } else if (port == BFD_ECHO_PORT) {
173 /* Echo is BFD v1 only */
174 version = 1;
175 }
176 switch ((port << 8) | version) {
177
178 /* BFDv0 */
179 case (BFD_CONTROL_PORT << 8):
180 if (ndo->ndo_vflag < 1)
181 {
182 ND_PRINT((ndo, "BFDv%u, %s, Flags: [%s], length: %u",
183 version,
184 tok2str(bfd_port_values, "unknown (%u)", port),
185 bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
186 len));
187 return;
188 }
189
190 ND_PRINT((ndo, "BFDv%u, length: %u\n\t%s, Flags: [%s], Diagnostic: %s (0x%02x)",
191 version,
192 len,
193 tok2str(bfd_port_values, "unknown (%u)", port),
194 bittok2str(bfd_v0_flag_values, "none", bfd_header->flags),
195 tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
196 BFD_EXTRACT_DIAG(bfd_header->version_diag)));
197
198 ND_PRINT((ndo, "\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
199 bfd_header->detect_time_multiplier,
200 bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
201 bfd_header->length));
202
203
204 ND_PRINT((ndo, "\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator)));
205 ND_PRINT((ndo, ", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator)));
206 ND_PRINT((ndo, "\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000));
207 ND_PRINT((ndo, "\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000));
208 ND_PRINT((ndo, "\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000));
209 break;
210
211 /* BFDv1 */
212 case (BFD_CONTROL_PORT << 8 | 1):
213 if (ndo->ndo_vflag < 1)
214 {
215 ND_PRINT((ndo, "BFDv%u, %s, State %s, Flags: [%s], length: %u",
216 version,
217 tok2str(bfd_port_values, "unknown (%u)", port),
218 tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
219 bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
220 len));
221 return;
222 }
223
224 ND_PRINT((ndo, "BFDv%u, length: %u\n\t%s, State %s, Flags: [%s], Diagnostic: %s (0x%02x)",
225 version,
226 len,
227 tok2str(bfd_port_values, "unknown (%u)", port),
228 tok2str(bfd_v1_state_values, "unknown (%u)", (bfd_header->flags & 0xc0) >> 6),
229 bittok2str(bfd_v1_flag_values, "none", bfd_header->flags & 0x3f),
230 tok2str(bfd_diag_values,"unknown",BFD_EXTRACT_DIAG(bfd_header->version_diag)),
231 BFD_EXTRACT_DIAG(bfd_header->version_diag)));
232
233 ND_PRINT((ndo, "\n\tDetection Timer Multiplier: %u (%u ms Detection time), BFD Length: %u",
234 bfd_header->detect_time_multiplier,
235 bfd_header->detect_time_multiplier * EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000,
236 bfd_header->length));
237
238
239 ND_PRINT((ndo, "\n\tMy Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->my_discriminator)));
240 ND_PRINT((ndo, ", Your Discriminator: 0x%08x", EXTRACT_32BITS(bfd_header->your_discriminator)));
241 ND_PRINT((ndo, "\n\t Desired min Tx Interval: %4u ms", EXTRACT_32BITS(bfd_header->desired_min_tx_interval)/1000));
242 ND_PRINT((ndo, "\n\t Required min Rx Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_rx_interval)/1000));
243 ND_PRINT((ndo, "\n\t Required min Echo Interval: %4u ms", EXTRACT_32BITS(bfd_header->required_min_echo_interval)/1000));
244
245 if (bfd_header->flags & BFD_FLAG_AUTH) {
246 pptr += sizeof (const struct bfd_header_t);
247 bfd_auth_header = (const struct bfd_auth_header_t *)pptr;
248 ND_TCHECK2(*bfd_auth_header, sizeof(const struct bfd_auth_header_t));
249 ND_PRINT((ndo, "\n\t%s (%u) Authentication, length %u present",
250 tok2str(bfd_v1_authentication_values,"Unknown",bfd_auth_header->auth_type),
251 bfd_auth_header->auth_type,
252 bfd_auth_header->auth_len));
253 }
254 break;
255
256 /* BFDv0 */
257 case (BFD_ECHO_PORT << 8): /* not yet supported - fall through */
258 /* BFDv1 */
259 case (BFD_ECHO_PORT << 8 | 1):
260
261 default:
262 ND_PRINT((ndo, "BFD, %s, length: %u",
263 tok2str(bfd_port_values, "unknown (%u)", port),
264 len));
265 if (ndo->ndo_vflag >= 1) {
266 if(!print_unknown_data(ndo, pptr,"\n\t",len))
267 return;
268 }
269 break;
270 }
271 return;
272
273 trunc:
274 ND_PRINT((ndo, "[|BFD]"));
275 }
276 /*
277 * Local Variables:
278 * c-style: whitesmith
279 * c-basic-offset: 8
280 * End:
281 */