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